CodeGenModule.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. //===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This is the internal per-translation-unit state used for llvm translation.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef CLANG_CODEGEN_CODEGENMODULE_H
  14. #define CLANG_CODEGEN_CODEGENMODULE_H
  15. #include "clang/Basic/ABI.h"
  16. #include "clang/Basic/LangOptions.h"
  17. #include "clang/AST/Attr.h"
  18. #include "clang/AST/DeclCXX.h"
  19. #include "clang/AST/DeclObjC.h"
  20. #include "clang/AST/Mangle.h"
  21. #include "CGBlocks.h"
  22. #include "CGCall.h"
  23. #include "CGVTables.h"
  24. #include "CodeGenTypes.h"
  25. #include "GlobalDecl.h"
  26. #include "llvm/Module.h"
  27. #include "llvm/ADT/DenseMap.h"
  28. #include "llvm/ADT/StringMap.h"
  29. #include "llvm/ADT/StringSet.h"
  30. #include "llvm/ADT/SmallPtrSet.h"
  31. #include "llvm/Support/ValueHandle.h"
  32. namespace llvm {
  33. class Module;
  34. class Constant;
  35. class Function;
  36. class GlobalValue;
  37. class TargetData;
  38. class FunctionType;
  39. class LLVMContext;
  40. }
  41. namespace clang {
  42. class TargetCodeGenInfo;
  43. class ASTContext;
  44. class FunctionDecl;
  45. class IdentifierInfo;
  46. class ObjCMethodDecl;
  47. class ObjCImplementationDecl;
  48. class ObjCCategoryImplDecl;
  49. class ObjCProtocolDecl;
  50. class ObjCEncodeExpr;
  51. class BlockExpr;
  52. class CharUnits;
  53. class Decl;
  54. class Expr;
  55. class Stmt;
  56. class StringLiteral;
  57. class NamedDecl;
  58. class ValueDecl;
  59. class VarDecl;
  60. class LangOptions;
  61. class CodeGenOptions;
  62. class Diagnostic;
  63. class AnnotateAttr;
  64. class CXXDestructorDecl;
  65. class MangleBuffer;
  66. namespace CodeGen {
  67. class CodeGenFunction;
  68. class CodeGenTBAA;
  69. class CGCXXABI;
  70. class CGDebugInfo;
  71. class CGObjCRuntime;
  72. struct OrderGlobalInits {
  73. unsigned int priority;
  74. unsigned int lex_order;
  75. OrderGlobalInits(unsigned int p, unsigned int l)
  76. : priority(p), lex_order(l) {}
  77. bool operator==(const OrderGlobalInits &RHS) const {
  78. return priority == RHS.priority &&
  79. lex_order == RHS.lex_order;
  80. }
  81. bool operator<(const OrderGlobalInits &RHS) const {
  82. if (priority < RHS.priority)
  83. return true;
  84. return priority == RHS.priority && lex_order < RHS.lex_order;
  85. }
  86. };
  87. /// CodeGenModule - This class organizes the cross-function state that is used
  88. /// while generating LLVM code.
  89. class CodeGenModule : public BlockModule {
  90. CodeGenModule(const CodeGenModule&); // DO NOT IMPLEMENT
  91. void operator=(const CodeGenModule&); // DO NOT IMPLEMENT
  92. typedef std::vector<std::pair<llvm::Constant*, int> > CtorList;
  93. ASTContext &Context;
  94. const LangOptions &Features;
  95. const CodeGenOptions &CodeGenOpts;
  96. llvm::Module &TheModule;
  97. const llvm::TargetData &TheTargetData;
  98. mutable const TargetCodeGenInfo *TheTargetCodeGenInfo;
  99. Diagnostic &Diags;
  100. CGCXXABI &ABI;
  101. CodeGenTypes Types;
  102. CodeGenTBAA *TBAA;
  103. /// VTables - Holds information about C++ vtables.
  104. CodeGenVTables VTables;
  105. friend class CodeGenVTables;
  106. CGObjCRuntime* Runtime;
  107. CGDebugInfo* DebugInfo;
  108. // WeakRefReferences - A set of references that have only been seen via
  109. // a weakref so far. This is used to remove the weak of the reference if we ever
  110. // see a direct reference or a definition.
  111. llvm::SmallPtrSet<llvm::GlobalValue*, 10> WeakRefReferences;
  112. /// DeferredDecls - This contains all the decls which have definitions but
  113. /// which are deferred for emission and therefore should only be output if
  114. /// they are actually used. If a decl is in this, then it is known to have
  115. /// not been referenced yet.
  116. llvm::StringMap<GlobalDecl> DeferredDecls;
  117. /// DeferredDeclsToEmit - This is a list of deferred decls which we have seen
  118. /// that *are* actually referenced. These get code generated when the module
  119. /// is done.
  120. std::vector<GlobalDecl> DeferredDeclsToEmit;
  121. /// LLVMUsed - List of global values which are required to be
  122. /// present in the object file; bitcast to i8*. This is used for
  123. /// forcing visibility of symbols which may otherwise be optimized
  124. /// out.
  125. std::vector<llvm::WeakVH> LLVMUsed;
  126. /// GlobalCtors - Store the list of global constructors and their respective
  127. /// priorities to be emitted when the translation unit is complete.
  128. CtorList GlobalCtors;
  129. /// GlobalDtors - Store the list of global destructors and their respective
  130. /// priorities to be emitted when the translation unit is complete.
  131. CtorList GlobalDtors;
  132. /// MangledDeclNames - A map of canonical GlobalDecls to their mangled names.
  133. llvm::DenseMap<GlobalDecl, llvm::StringRef> MangledDeclNames;
  134. llvm::BumpPtrAllocator MangledNamesAllocator;
  135. std::vector<llvm::Constant*> Annotations;
  136. llvm::StringMap<llvm::Constant*> CFConstantStringMap;
  137. llvm::StringMap<llvm::Constant*> ConstantStringMap;
  138. llvm::DenseMap<const Decl*, llvm::Value*> StaticLocalDeclMap;
  139. /// CXXGlobalInits - Global variables with initializers that need to run
  140. /// before main.
  141. std::vector<llvm::Constant*> CXXGlobalInits;
  142. /// When a C++ decl with an initializer is deferred, null is
  143. /// appended to CXXGlobalInits, and the index of that null is placed
  144. /// here so that the initializer will be performed in the correct
  145. /// order.
  146. llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition;
  147. /// - Global variables with initializers whose order of initialization
  148. /// is set by init_priority attribute.
  149. llvm::SmallVector<std::pair<OrderGlobalInits, llvm::Function*>, 8>
  150. PrioritizedCXXGlobalInits;
  151. /// CXXGlobalDtors - Global destructor functions and arguments that need to
  152. /// run on termination.
  153. std::vector<std::pair<llvm::WeakVH,llvm::Constant*> > CXXGlobalDtors;
  154. /// CFConstantStringClassRef - Cached reference to the class for constant
  155. /// strings. This value has type int * but is actually an Obj-C class pointer.
  156. llvm::Constant *CFConstantStringClassRef;
  157. /// ConstantStringClassRef - Cached reference to the class for constant
  158. /// strings. This value has type int * but is actually an Obj-C class pointer.
  159. llvm::Constant *ConstantStringClassRef;
  160. /// Lazily create the Objective-C runtime
  161. void createObjCRuntime();
  162. llvm::LLVMContext &VMContext;
  163. /// @name Cache for Blocks Runtime Globals
  164. /// @{
  165. const VarDecl *NSConcreteGlobalBlockDecl;
  166. const VarDecl *NSConcreteStackBlockDecl;
  167. llvm::Constant *NSConcreteGlobalBlock;
  168. llvm::Constant *NSConcreteStackBlock;
  169. const FunctionDecl *BlockObjectAssignDecl;
  170. const FunctionDecl *BlockObjectDisposeDecl;
  171. llvm::Constant *BlockObjectAssign;
  172. llvm::Constant *BlockObjectDispose;
  173. /// @}
  174. public:
  175. CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts,
  176. llvm::Module &M, const llvm::TargetData &TD, Diagnostic &Diags);
  177. ~CodeGenModule();
  178. /// Release - Finalize LLVM code generation.
  179. void Release();
  180. /// getObjCRuntime() - Return a reference to the configured
  181. /// Objective-C runtime.
  182. CGObjCRuntime &getObjCRuntime() {
  183. if (!Runtime) createObjCRuntime();
  184. return *Runtime;
  185. }
  186. /// hasObjCRuntime() - Return true iff an Objective-C runtime has
  187. /// been configured.
  188. bool hasObjCRuntime() { return !!Runtime; }
  189. /// getCXXABI() - Return a reference to the configured C++ ABI.
  190. CGCXXABI &getCXXABI() { return ABI; }
  191. llvm::Value *getStaticLocalDeclAddress(const VarDecl *VD) {
  192. return StaticLocalDeclMap[VD];
  193. }
  194. void setStaticLocalDeclAddress(const VarDecl *D,
  195. llvm::GlobalVariable *GV) {
  196. StaticLocalDeclMap[D] = GV;
  197. }
  198. CGDebugInfo *getDebugInfo() { return DebugInfo; }
  199. ASTContext &getContext() const { return Context; }
  200. const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
  201. const LangOptions &getLangOptions() const { return Features; }
  202. llvm::Module &getModule() const { return TheModule; }
  203. CodeGenTypes &getTypes() { return Types; }
  204. CodeGenVTables &getVTables() { return VTables; }
  205. Diagnostic &getDiags() const { return Diags; }
  206. const llvm::TargetData &getTargetData() const { return TheTargetData; }
  207. llvm::LLVMContext &getLLVMContext() { return VMContext; }
  208. const TargetCodeGenInfo &getTargetCodeGenInfo();
  209. bool isTargetDarwin() const;
  210. llvm::MDNode *getTBAAInfo(QualType QTy);
  211. static void DecorateInstruction(llvm::Instruction *Inst,
  212. llvm::MDNode *TBAAInfo);
  213. /// setGlobalVisibility - Set the visibility for the given LLVM
  214. /// GlobalValue.
  215. void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D,
  216. bool IsForDefinition) const;
  217. /// setTypeVisibility - Set the visibility for the given global
  218. /// value which holds information about a type.
  219. void setTypeVisibility(llvm::GlobalValue *GV, const CXXRecordDecl *D,
  220. bool IsForRTTI, bool IsForDefinition) const;
  221. llvm::Constant *GetAddrOfGlobal(GlobalDecl GD) {
  222. if (isa<CXXConstructorDecl>(GD.getDecl()))
  223. return GetAddrOfCXXConstructor(cast<CXXConstructorDecl>(GD.getDecl()),
  224. GD.getCtorType());
  225. else if (isa<CXXDestructorDecl>(GD.getDecl()))
  226. return GetAddrOfCXXDestructor(cast<CXXDestructorDecl>(GD.getDecl()),
  227. GD.getDtorType());
  228. else if (isa<FunctionDecl>(GD.getDecl()))
  229. return GetAddrOfFunction(GD);
  230. else
  231. return GetAddrOfGlobalVar(cast<VarDecl>(GD.getDecl()));
  232. }
  233. /// GetAddrOfGlobalVar - Return the llvm::Constant for the address of the
  234. /// given global variable. If Ty is non-null and if the global doesn't exist,
  235. /// then it will be greated with the specified type instead of whatever the
  236. /// normal requested type would be.
  237. llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
  238. const llvm::Type *Ty = 0);
  239. /// GetAddrOfFunction - Return the address of the given function. If Ty is
  240. /// non-null, then this function will use the specified type if it has to
  241. /// create it.
  242. llvm::Constant *GetAddrOfFunction(GlobalDecl GD,
  243. const llvm::Type *Ty = 0);
  244. /// GetAddrOfRTTIDescriptor - Get the address of the RTTI descriptor
  245. /// for the given type.
  246. llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false);
  247. /// GetAddrOfThunk - Get the address of the thunk for the given global decl.
  248. llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk);
  249. /// GetWeakRefReference - Get a reference to the target of VD.
  250. llvm::Constant *GetWeakRefReference(const ValueDecl *VD);
  251. /// GetNonVirtualBaseClassOffset - Returns the offset from a derived class to
  252. /// a class. Returns null if the offset is 0.
  253. llvm::Constant *
  254. GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl,
  255. CastExpr::path_const_iterator PathBegin,
  256. CastExpr::path_const_iterator PathEnd);
  257. /// GetStringForStringLiteral - Return the appropriate bytes for a string
  258. /// literal, properly padded to match the literal type. If only the address of
  259. /// a constant is needed consider using GetAddrOfConstantStringLiteral.
  260. std::string GetStringForStringLiteral(const StringLiteral *E);
  261. /// GetAddrOfConstantCFString - Return a pointer to a constant CFString object
  262. /// for the given string.
  263. llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal);
  264. /// GetAddrOfConstantString - Return a pointer to a constant NSString object
  265. /// for the given string. Or a user defined String object as defined via
  266. /// -fconstant-string-class=class_name option.
  267. llvm::Constant *GetAddrOfConstantString(const StringLiteral *Literal);
  268. /// GetAddrOfConstantStringFromLiteral - Return a pointer to a constant array
  269. /// for the given string literal.
  270. llvm::Constant *GetAddrOfConstantStringFromLiteral(const StringLiteral *S);
  271. /// GetAddrOfConstantStringFromObjCEncode - Return a pointer to a constant
  272. /// array for the given ObjCEncodeExpr node.
  273. llvm::Constant *GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *);
  274. /// GetAddrOfConstantString - Returns a pointer to a character array
  275. /// containing the literal. This contents are exactly that of the given
  276. /// string, i.e. it will not be null terminated automatically; see
  277. /// GetAddrOfConstantCString. Note that whether the result is actually a
  278. /// pointer to an LLVM constant depends on Feature.WriteableStrings.
  279. ///
  280. /// The result has pointer to array type.
  281. ///
  282. /// \param GlobalName If provided, the name to use for the global
  283. /// (if one is created).
  284. llvm::Constant *GetAddrOfConstantString(const std::string& str,
  285. const char *GlobalName=0);
  286. /// GetAddrOfConstantCString - Returns a pointer to a character array
  287. /// containing the literal and a terminating '\0' character. The result has
  288. /// pointer to array type.
  289. ///
  290. /// \param GlobalName If provided, the name to use for the global (if one is
  291. /// created).
  292. llvm::Constant *GetAddrOfConstantCString(const std::string &str,
  293. const char *GlobalName=0);
  294. /// GetAddrOfCXXConstructor - Return the address of the constructor of the
  295. /// given type.
  296. llvm::GlobalValue *GetAddrOfCXXConstructor(const CXXConstructorDecl *D,
  297. CXXCtorType Type);
  298. /// GetAddrOfCXXDestructor - Return the address of the constructor of the
  299. /// given type.
  300. llvm::GlobalValue *GetAddrOfCXXDestructor(const CXXDestructorDecl *D,
  301. CXXDtorType Type);
  302. /// getBuiltinLibFunction - Given a builtin id for a function like
  303. /// "__builtin_fabsf", return a Function* for "fabsf".
  304. llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD,
  305. unsigned BuiltinID);
  306. llvm::Function *getIntrinsic(unsigned IID, const llvm::Type **Tys = 0,
  307. unsigned NumTys = 0);
  308. /// EmitTopLevelDecl - Emit code for a single top level declaration.
  309. void EmitTopLevelDecl(Decl *D);
  310. /// AddUsedGlobal - Add a global which should be forced to be
  311. /// present in the object file; these are emitted to the llvm.used
  312. /// metadata global.
  313. void AddUsedGlobal(llvm::GlobalValue *GV);
  314. void AddAnnotation(llvm::Constant *C) { Annotations.push_back(C); }
  315. /// AddCXXDtorEntry - Add a destructor and object to add to the C++ global
  316. /// destructor function.
  317. void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) {
  318. CXXGlobalDtors.push_back(std::make_pair(DtorFn, Object));
  319. }
  320. /// CreateRuntimeFunction - Create a new runtime function with the specified
  321. /// type and name.
  322. llvm::Constant *CreateRuntimeFunction(const llvm::FunctionType *Ty,
  323. llvm::StringRef Name);
  324. /// CreateRuntimeVariable - Create a new runtime global variable with the
  325. /// specified type and name.
  326. llvm::Constant *CreateRuntimeVariable(const llvm::Type *Ty,
  327. llvm::StringRef Name);
  328. ///@name Custom Blocks Runtime Interfaces
  329. ///@{
  330. llvm::Constant *getNSConcreteGlobalBlock();
  331. llvm::Constant *getNSConcreteStackBlock();
  332. llvm::Constant *getBlockObjectAssign();
  333. llvm::Constant *getBlockObjectDispose();
  334. ///@}
  335. void UpdateCompletedType(const TagDecl *TD) {
  336. // Make sure that this type is translated.
  337. Types.UpdateCompletedType(TD);
  338. }
  339. /// EmitConstantExpr - Try to emit the given expression as a
  340. /// constant; returns 0 if the expression cannot be emitted as a
  341. /// constant.
  342. llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType,
  343. CodeGenFunction *CGF = 0);
  344. /// EmitNullConstant - Return the result of value-initializing the given
  345. /// type, i.e. a null expression of the given type. This is usually,
  346. /// but not always, an LLVM null constant.
  347. llvm::Constant *EmitNullConstant(QualType T);
  348. llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
  349. const AnnotateAttr *AA, unsigned LineNo);
  350. /// ErrorUnsupported - Print out an error that codegen doesn't support the
  351. /// specified stmt yet.
  352. /// \param OmitOnError - If true, then this error should only be emitted if no
  353. /// other errors have been reported.
  354. void ErrorUnsupported(const Stmt *S, const char *Type,
  355. bool OmitOnError=false);
  356. /// ErrorUnsupported - Print out an error that codegen doesn't support the
  357. /// specified decl yet.
  358. /// \param OmitOnError - If true, then this error should only be emitted if no
  359. /// other errors have been reported.
  360. void ErrorUnsupported(const Decl *D, const char *Type,
  361. bool OmitOnError=false);
  362. /// SetInternalFunctionAttributes - Set the attributes on the LLVM
  363. /// function for the given decl and function info. This applies
  364. /// attributes necessary for handling the ABI as well as user
  365. /// specified attributes like section.
  366. void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F,
  367. const CGFunctionInfo &FI);
  368. /// SetLLVMFunctionAttributes - Set the LLVM function attributes
  369. /// (sext, zext, etc).
  370. void SetLLVMFunctionAttributes(const Decl *D,
  371. const CGFunctionInfo &Info,
  372. llvm::Function *F);
  373. /// SetLLVMFunctionAttributesForDefinition - Set the LLVM function attributes
  374. /// which only apply to a function definintion.
  375. void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F);
  376. /// ReturnTypeUsesSRet - Return true iff the given type uses 'sret' when used
  377. /// as a return type.
  378. bool ReturnTypeUsesSRet(const CGFunctionInfo &FI);
  379. /// ReturnTypeUsesSret - Return true iff the given type uses 'fpret' when used
  380. /// as a return type.
  381. bool ReturnTypeUsesFPRet(QualType ResultType);
  382. /// ConstructAttributeList - Get the LLVM attributes and calling convention to
  383. /// use for a particular function type.
  384. ///
  385. /// \param Info - The function type information.
  386. /// \param TargetDecl - The decl these attributes are being constructed
  387. /// for. If supplied the attributes applied to this decl may contribute to the
  388. /// function attributes and calling convention.
  389. /// \param PAL [out] - On return, the attribute list to use.
  390. /// \param CallingConv [out] - On return, the LLVM calling convention to use.
  391. void ConstructAttributeList(const CGFunctionInfo &Info,
  392. const Decl *TargetDecl,
  393. AttributeListType &PAL,
  394. unsigned &CallingConv);
  395. llvm::StringRef getMangledName(GlobalDecl GD);
  396. void getBlockMangledName(GlobalDecl GD, MangleBuffer &Buffer,
  397. const BlockDecl *BD);
  398. void EmitTentativeDefinition(const VarDecl *D);
  399. void EmitVTable(CXXRecordDecl *Class, bool DefinitionRequired);
  400. llvm::GlobalVariable::LinkageTypes
  401. getFunctionLinkage(const FunctionDecl *FD);
  402. void setFunctionLinkage(const FunctionDecl *FD, llvm::GlobalValue *V) {
  403. V->setLinkage(getFunctionLinkage(FD));
  404. }
  405. /// getVTableLinkage - Return the appropriate linkage for the vtable, VTT,
  406. /// and type information of the given class.
  407. static llvm::GlobalVariable::LinkageTypes
  408. getVTableLinkage(const CXXRecordDecl *RD);
  409. /// GetTargetTypeStoreSize - Return the store size, in character units, of
  410. /// the given LLVM type.
  411. CharUnits GetTargetTypeStoreSize(const llvm::Type *Ty) const;
  412. /// GetLLVMLinkageVarDefinition - Returns LLVM linkage for a global
  413. /// variable.
  414. llvm::GlobalValue::LinkageTypes
  415. GetLLVMLinkageVarDefinition(const VarDecl *D,
  416. llvm::GlobalVariable *GV);
  417. std::vector<const CXXRecordDecl*> DeferredVTables;
  418. private:
  419. llvm::GlobalValue *GetGlobalValue(llvm::StringRef Ref);
  420. llvm::Constant *GetOrCreateLLVMFunction(llvm::StringRef MangledName,
  421. const llvm::Type *Ty,
  422. GlobalDecl D);
  423. llvm::Constant *GetOrCreateLLVMGlobal(llvm::StringRef MangledName,
  424. const llvm::PointerType *PTy,
  425. const VarDecl *D);
  426. /// SetCommonAttributes - Set attributes which are common to any
  427. /// form of a global definition (alias, Objective-C method,
  428. /// function, global variable).
  429. ///
  430. /// NOTE: This should only be called for definitions.
  431. void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV);
  432. /// SetFunctionDefinitionAttributes - Set attributes for a global definition.
  433. void SetFunctionDefinitionAttributes(const FunctionDecl *D,
  434. llvm::GlobalValue *GV);
  435. /// SetFunctionAttributes - Set function attributes for a function
  436. /// declaration.
  437. void SetFunctionAttributes(GlobalDecl GD,
  438. llvm::Function *F,
  439. bool IsIncompleteFunction);
  440. /// EmitGlobal - Emit code for a singal global function or var decl. Forward
  441. /// declarations are emitted lazily.
  442. void EmitGlobal(GlobalDecl D);
  443. void EmitGlobalDefinition(GlobalDecl D);
  444. void EmitGlobalFunctionDefinition(GlobalDecl GD);
  445. void EmitGlobalVarDefinition(const VarDecl *D);
  446. void EmitAliasDefinition(GlobalDecl GD);
  447. void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
  448. void EmitObjCIvarInitializations(ObjCImplementationDecl *D);
  449. // C++ related functions.
  450. bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target);
  451. bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D);
  452. void EmitNamespace(const NamespaceDecl *D);
  453. void EmitLinkageSpec(const LinkageSpecDecl *D);
  454. /// EmitCXXConstructors - Emit constructors (base, complete) from a
  455. /// C++ constructor Decl.
  456. void EmitCXXConstructors(const CXXConstructorDecl *D);
  457. /// EmitCXXConstructor - Emit a single constructor with the given type from
  458. /// a C++ constructor Decl.
  459. void EmitCXXConstructor(const CXXConstructorDecl *D, CXXCtorType Type);
  460. /// EmitCXXDestructors - Emit destructors (base, complete) from a
  461. /// C++ destructor Decl.
  462. void EmitCXXDestructors(const CXXDestructorDecl *D);
  463. /// EmitCXXDestructor - Emit a single destructor with the given type from
  464. /// a C++ destructor Decl.
  465. void EmitCXXDestructor(const CXXDestructorDecl *D, CXXDtorType Type);
  466. /// EmitCXXGlobalInitFunc - Emit the function that initializes C++ globals.
  467. void EmitCXXGlobalInitFunc();
  468. /// EmitCXXGlobalDtorFunc - Emit the function that destroys C++ globals.
  469. void EmitCXXGlobalDtorFunc();
  470. void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
  471. llvm::GlobalVariable *Addr);
  472. // FIXME: Hardcoding priority here is gross.
  473. void AddGlobalCtor(llvm::Function *Ctor, int Priority=65535);
  474. void AddGlobalDtor(llvm::Function *Dtor, int Priority=65535);
  475. /// EmitCtorList - Generates a global array of functions and priorities using
  476. /// the given list and name. This array will have appending linkage and is
  477. /// suitable for use as a LLVM constructor or destructor array.
  478. void EmitCtorList(const CtorList &Fns, const char *GlobalName);
  479. void EmitAnnotations(void);
  480. /// EmitFundamentalRTTIDescriptor - Emit the RTTI descriptors for the
  481. /// given type.
  482. void EmitFundamentalRTTIDescriptor(QualType Type);
  483. /// EmitFundamentalRTTIDescriptors - Emit the RTTI descriptors for the
  484. /// builtin types.
  485. void EmitFundamentalRTTIDescriptors();
  486. /// EmitDeferred - Emit any needed decls for which code generation
  487. /// was deferred.
  488. void EmitDeferred(void);
  489. /// EmitLLVMUsed - Emit the llvm.used metadata used to force
  490. /// references to global which may otherwise be optimized out.
  491. void EmitLLVMUsed(void);
  492. void EmitDeclMetadata();
  493. /// MayDeferGeneration - Determine if the given decl can be emitted
  494. /// lazily; this is only relevant for definitions. The given decl
  495. /// must be either a function or var decl.
  496. bool MayDeferGeneration(const ValueDecl *D);
  497. /// SimplifyPersonality - Check whether we can use a "simpler", more
  498. /// core exceptions personality function.
  499. void SimplifyPersonality();
  500. };
  501. } // end namespace CodeGen
  502. } // end namespace clang
  503. #endif