CodeGenModule.h 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  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 "CGVTables.h"
  16. #include "CodeGenTypes.h"
  17. #include "clang/AST/Attr.h"
  18. #include "clang/AST/DeclCXX.h"
  19. #include "clang/AST/DeclObjC.h"
  20. #include "clang/AST/GlobalDecl.h"
  21. #include "clang/AST/Mangle.h"
  22. #include "clang/Basic/ABI.h"
  23. #include "clang/Basic/LangOptions.h"
  24. #include "clang/Basic/Module.h"
  25. #include "llvm/ADT/DenseMap.h"
  26. #include "llvm/ADT/SetVector.h"
  27. #include "llvm/ADT/SmallPtrSet.h"
  28. #include "llvm/ADT/StringMap.h"
  29. #include "llvm/IR/CallingConv.h"
  30. #include "llvm/IR/Module.h"
  31. #include "llvm/IR/ValueHandle.h"
  32. #include "llvm/Transforms/Utils/SpecialCaseList.h"
  33. namespace llvm {
  34. class Module;
  35. class Constant;
  36. class ConstantInt;
  37. class Function;
  38. class GlobalValue;
  39. class DataLayout;
  40. class FunctionType;
  41. class LLVMContext;
  42. class IndexedInstrProfReader;
  43. }
  44. namespace clang {
  45. class TargetCodeGenInfo;
  46. class ASTContext;
  47. class AtomicType;
  48. class FunctionDecl;
  49. class IdentifierInfo;
  50. class ObjCMethodDecl;
  51. class ObjCImplementationDecl;
  52. class ObjCCategoryImplDecl;
  53. class ObjCProtocolDecl;
  54. class ObjCEncodeExpr;
  55. class BlockExpr;
  56. class CharUnits;
  57. class Decl;
  58. class Expr;
  59. class Stmt;
  60. class InitListExpr;
  61. class StringLiteral;
  62. class NamedDecl;
  63. class ValueDecl;
  64. class VarDecl;
  65. class LangOptions;
  66. class CodeGenOptions;
  67. class DiagnosticsEngine;
  68. class AnnotateAttr;
  69. class CXXDestructorDecl;
  70. class Module;
  71. namespace CodeGen {
  72. class CallArgList;
  73. class CodeGenFunction;
  74. class CodeGenTBAA;
  75. class CGCXXABI;
  76. class CGDebugInfo;
  77. class CGObjCRuntime;
  78. class CGOpenCLRuntime;
  79. class CGOpenMPRuntime;
  80. class CGCUDARuntime;
  81. class BlockFieldFlags;
  82. class FunctionArgList;
  83. struct OrderGlobalInits {
  84. unsigned int priority;
  85. unsigned int lex_order;
  86. OrderGlobalInits(unsigned int p, unsigned int l)
  87. : priority(p), lex_order(l) {}
  88. bool operator==(const OrderGlobalInits &RHS) const {
  89. return priority == RHS.priority && lex_order == RHS.lex_order;
  90. }
  91. bool operator<(const OrderGlobalInits &RHS) const {
  92. return std::tie(priority, lex_order) <
  93. std::tie(RHS.priority, RHS.lex_order);
  94. }
  95. };
  96. struct CodeGenTypeCache {
  97. /// void
  98. llvm::Type *VoidTy;
  99. /// i8, i16, i32, and i64
  100. llvm::IntegerType *Int8Ty, *Int16Ty, *Int32Ty, *Int64Ty;
  101. /// float, double
  102. llvm::Type *FloatTy, *DoubleTy;
  103. /// int
  104. llvm::IntegerType *IntTy;
  105. /// intptr_t, size_t, and ptrdiff_t, which we assume are the same size.
  106. union {
  107. llvm::IntegerType *IntPtrTy;
  108. llvm::IntegerType *SizeTy;
  109. llvm::IntegerType *PtrDiffTy;
  110. };
  111. /// void* in address space 0
  112. union {
  113. llvm::PointerType *VoidPtrTy;
  114. llvm::PointerType *Int8PtrTy;
  115. };
  116. /// void** in address space 0
  117. union {
  118. llvm::PointerType *VoidPtrPtrTy;
  119. llvm::PointerType *Int8PtrPtrTy;
  120. };
  121. /// The width of a pointer into the generic address space.
  122. unsigned char PointerWidthInBits;
  123. /// The size and alignment of a pointer into the generic address
  124. /// space.
  125. union {
  126. unsigned char PointerAlignInBytes;
  127. unsigned char PointerSizeInBytes;
  128. unsigned char SizeSizeInBytes; // sizeof(size_t)
  129. };
  130. llvm::CallingConv::ID RuntimeCC;
  131. llvm::CallingConv::ID getRuntimeCC() const { return RuntimeCC; }
  132. };
  133. struct RREntrypoints {
  134. RREntrypoints() { memset(this, 0, sizeof(*this)); }
  135. /// void objc_autoreleasePoolPop(void*);
  136. llvm::Constant *objc_autoreleasePoolPop;
  137. /// void *objc_autoreleasePoolPush(void);
  138. llvm::Constant *objc_autoreleasePoolPush;
  139. };
  140. struct ARCEntrypoints {
  141. ARCEntrypoints() { memset(this, 0, sizeof(*this)); }
  142. /// id objc_autorelease(id);
  143. llvm::Constant *objc_autorelease;
  144. /// id objc_autoreleaseReturnValue(id);
  145. llvm::Constant *objc_autoreleaseReturnValue;
  146. /// void objc_copyWeak(id *dest, id *src);
  147. llvm::Constant *objc_copyWeak;
  148. /// void objc_destroyWeak(id*);
  149. llvm::Constant *objc_destroyWeak;
  150. /// id objc_initWeak(id*, id);
  151. llvm::Constant *objc_initWeak;
  152. /// id objc_loadWeak(id*);
  153. llvm::Constant *objc_loadWeak;
  154. /// id objc_loadWeakRetained(id*);
  155. llvm::Constant *objc_loadWeakRetained;
  156. /// void objc_moveWeak(id *dest, id *src);
  157. llvm::Constant *objc_moveWeak;
  158. /// id objc_retain(id);
  159. llvm::Constant *objc_retain;
  160. /// id objc_retainAutorelease(id);
  161. llvm::Constant *objc_retainAutorelease;
  162. /// id objc_retainAutoreleaseReturnValue(id);
  163. llvm::Constant *objc_retainAutoreleaseReturnValue;
  164. /// id objc_retainAutoreleasedReturnValue(id);
  165. llvm::Constant *objc_retainAutoreleasedReturnValue;
  166. /// id objc_retainBlock(id);
  167. llvm::Constant *objc_retainBlock;
  168. /// void objc_release(id);
  169. llvm::Constant *objc_release;
  170. /// id objc_storeStrong(id*, id);
  171. llvm::Constant *objc_storeStrong;
  172. /// id objc_storeWeak(id*, id);
  173. llvm::Constant *objc_storeWeak;
  174. /// A void(void) inline asm to use to mark that the return value of
  175. /// a call will be immediately retain.
  176. llvm::InlineAsm *retainAutoreleasedReturnValueMarker;
  177. /// void clang.arc.use(...);
  178. llvm::Constant *clang_arc_use;
  179. };
  180. /// This class records statistics on instrumentation based profiling.
  181. struct InstrProfStats {
  182. InstrProfStats() : Visited(0), Missing(0), Mismatched(0) {}
  183. bool isOutOfDate() { return Missing || Mismatched; }
  184. uint32_t Visited;
  185. uint32_t Missing;
  186. uint32_t Mismatched;
  187. };
  188. /// This class organizes the cross-function state that is used while generating
  189. /// LLVM code.
  190. class CodeGenModule : public CodeGenTypeCache {
  191. CodeGenModule(const CodeGenModule &) LLVM_DELETED_FUNCTION;
  192. void operator=(const CodeGenModule &) LLVM_DELETED_FUNCTION;
  193. struct Structor {
  194. Structor() : Priority(0), Initializer(nullptr), AssociatedData(nullptr) {}
  195. Structor(int Priority, llvm::Constant *Initializer,
  196. llvm::Constant *AssociatedData)
  197. : Priority(Priority), Initializer(Initializer),
  198. AssociatedData(AssociatedData) {}
  199. int Priority;
  200. llvm::Constant *Initializer;
  201. llvm::Constant *AssociatedData;
  202. };
  203. typedef std::vector<Structor> CtorList;
  204. ASTContext &Context;
  205. const LangOptions &LangOpts;
  206. const CodeGenOptions &CodeGenOpts;
  207. llvm::Module &TheModule;
  208. DiagnosticsEngine &Diags;
  209. const llvm::DataLayout &TheDataLayout;
  210. const TargetInfo &Target;
  211. std::unique_ptr<CGCXXABI> ABI;
  212. llvm::LLVMContext &VMContext;
  213. CodeGenTBAA *TBAA;
  214. mutable const TargetCodeGenInfo *TheTargetCodeGenInfo;
  215. // This should not be moved earlier, since its initialization depends on some
  216. // of the previous reference members being already initialized and also checks
  217. // if TheTargetCodeGenInfo is NULL
  218. CodeGenTypes Types;
  219. /// Holds information about C++ vtables.
  220. CodeGenVTables VTables;
  221. CGObjCRuntime* ObjCRuntime;
  222. CGOpenCLRuntime* OpenCLRuntime;
  223. CGOpenMPRuntime* OpenMPRuntime;
  224. CGCUDARuntime* CUDARuntime;
  225. CGDebugInfo* DebugInfo;
  226. ARCEntrypoints *ARCData;
  227. llvm::MDNode *NoObjCARCExceptionsMetadata;
  228. RREntrypoints *RRData;
  229. std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader;
  230. InstrProfStats PGOStats;
  231. // A set of references that have only been seen via a weakref so far. This is
  232. // used to remove the weak of the reference if we ever see a direct reference
  233. // or a definition.
  234. llvm::SmallPtrSet<llvm::GlobalValue*, 10> WeakRefReferences;
  235. /// This contains all the decls which have definitions but/ which are deferred
  236. /// for emission and therefore should only be output if they are actually
  237. /// used. If a decl is in this, then it is known to have not been referenced
  238. /// yet.
  239. std::map<StringRef, GlobalDecl> DeferredDecls;
  240. /// This is a list of deferred decls which we have seen that *are* actually
  241. /// referenced. These get code generated when the module is done.
  242. struct DeferredGlobal {
  243. DeferredGlobal(llvm::GlobalValue *GV, GlobalDecl GD) : GV(GV), GD(GD) {}
  244. llvm::AssertingVH<llvm::GlobalValue> GV;
  245. GlobalDecl GD;
  246. };
  247. std::vector<DeferredGlobal> DeferredDeclsToEmit;
  248. void addDeferredDeclToEmit(llvm::GlobalValue *GV, GlobalDecl GD) {
  249. DeferredDeclsToEmit.push_back(DeferredGlobal(GV, GD));
  250. }
  251. /// List of alias we have emitted. Used to make sure that what they point to
  252. /// is defined once we get to the end of the of the translation unit.
  253. std::vector<GlobalDecl> Aliases;
  254. typedef llvm::StringMap<llvm::TrackingVH<llvm::Constant> > ReplacementsTy;
  255. ReplacementsTy Replacements;
  256. /// A queue of (optional) vtables to consider emitting.
  257. std::vector<const CXXRecordDecl*> DeferredVTables;
  258. /// List of global values which are required to be present in the object file;
  259. /// bitcast to i8*. This is used for forcing visibility of symbols which may
  260. /// otherwise be optimized out.
  261. std::vector<llvm::WeakVH> LLVMUsed;
  262. std::vector<llvm::WeakVH> LLVMCompilerUsed;
  263. /// Store the list of global constructors and their respective priorities to
  264. /// be emitted when the translation unit is complete.
  265. CtorList GlobalCtors;
  266. /// Store the list of global destructors and their respective priorities to be
  267. /// emitted when the translation unit is complete.
  268. CtorList GlobalDtors;
  269. /// A map of canonical GlobalDecls to their mangled names.
  270. llvm::DenseMap<GlobalDecl, StringRef> MangledDeclNames;
  271. llvm::StringMap<GlobalDecl, llvm::BumpPtrAllocator> Manglings;
  272. /// Global annotations.
  273. std::vector<llvm::Constant*> Annotations;
  274. /// Map used to get unique annotation strings.
  275. llvm::StringMap<llvm::Constant*> AnnotationStrings;
  276. llvm::StringMap<llvm::Constant*> CFConstantStringMap;
  277. llvm::StringMap<llvm::GlobalVariable *> Constant1ByteStringMap;
  278. llvm::StringMap<llvm::GlobalVariable *> Constant2ByteStringMap;
  279. llvm::StringMap<llvm::GlobalVariable *> Constant4ByteStringMap;
  280. llvm::DenseMap<const Decl*, llvm::Constant *> StaticLocalDeclMap;
  281. llvm::DenseMap<const Decl*, llvm::GlobalVariable*> StaticLocalDeclGuardMap;
  282. llvm::DenseMap<const Expr*, llvm::Constant *> MaterializedGlobalTemporaryMap;
  283. llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap;
  284. llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap;
  285. /// Map used to get unique type descriptor constants for sanitizers.
  286. llvm::DenseMap<QualType, llvm::Constant *> TypeDescriptorMap;
  287. /// Map used to track internal linkage functions declared within
  288. /// extern "C" regions.
  289. typedef llvm::MapVector<IdentifierInfo *,
  290. llvm::GlobalValue *> StaticExternCMap;
  291. StaticExternCMap StaticExternCValues;
  292. /// \brief thread_local variables defined or used in this TU.
  293. std::vector<std::pair<const VarDecl *, llvm::GlobalVariable *> >
  294. CXXThreadLocals;
  295. /// \brief thread_local variables with initializers that need to run
  296. /// before any thread_local variable in this TU is odr-used.
  297. std::vector<llvm::Constant*> CXXThreadLocalInits;
  298. /// Global variables with initializers that need to run before main.
  299. std::vector<llvm::Constant*> CXXGlobalInits;
  300. /// When a C++ decl with an initializer is deferred, null is
  301. /// appended to CXXGlobalInits, and the index of that null is placed
  302. /// here so that the initializer will be performed in the correct
  303. /// order.
  304. llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition;
  305. typedef std::pair<OrderGlobalInits, llvm::Function*> GlobalInitData;
  306. struct GlobalInitPriorityCmp {
  307. bool operator()(const GlobalInitData &LHS,
  308. const GlobalInitData &RHS) const {
  309. return LHS.first.priority < RHS.first.priority;
  310. }
  311. };
  312. /// Global variables with initializers whose order of initialization is set by
  313. /// init_priority attribute.
  314. SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits;
  315. /// Global destructor functions and arguments that need to run on termination.
  316. std::vector<std::pair<llvm::WeakVH,llvm::Constant*> > CXXGlobalDtors;
  317. /// \brief The complete set of modules that has been imported.
  318. llvm::SetVector<clang::Module *> ImportedModules;
  319. /// \brief A vector of metadata strings.
  320. SmallVector<llvm::Value *, 16> LinkerOptionsMetadata;
  321. /// @name Cache for Objective-C runtime types
  322. /// @{
  323. /// Cached reference to the class for constant strings. This value has type
  324. /// int * but is actually an Obj-C class pointer.
  325. llvm::WeakVH CFConstantStringClassRef;
  326. /// Cached reference to the class for constant strings. This value has type
  327. /// int * but is actually an Obj-C class pointer.
  328. llvm::WeakVH ConstantStringClassRef;
  329. /// \brief The LLVM type corresponding to NSConstantString.
  330. llvm::StructType *NSConstantStringType;
  331. /// \brief The type used to describe the state of a fast enumeration in
  332. /// Objective-C's for..in loop.
  333. QualType ObjCFastEnumerationStateType;
  334. /// @}
  335. /// Lazily create the Objective-C runtime
  336. void createObjCRuntime();
  337. void createOpenCLRuntime();
  338. void createOpenMPRuntime();
  339. void createCUDARuntime();
  340. bool isTriviallyRecursive(const FunctionDecl *F);
  341. bool shouldEmitFunction(GlobalDecl GD);
  342. /// @name Cache for Blocks Runtime Globals
  343. /// @{
  344. llvm::Constant *NSConcreteGlobalBlock;
  345. llvm::Constant *NSConcreteStackBlock;
  346. llvm::Constant *BlockObjectAssign;
  347. llvm::Constant *BlockObjectDispose;
  348. llvm::Type *BlockDescriptorType;
  349. llvm::Type *GenericBlockLiteralType;
  350. struct {
  351. int GlobalUniqueCount;
  352. } Block;
  353. /// void @llvm.lifetime.start(i64 %size, i8* nocapture <ptr>)
  354. llvm::Constant *LifetimeStartFn;
  355. /// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>)
  356. llvm::Constant *LifetimeEndFn;
  357. GlobalDecl initializedGlobalDecl;
  358. std::unique_ptr<llvm::SpecialCaseList> SanitizerBlacklist;
  359. const SanitizerOptions &SanOpts;
  360. /// @}
  361. public:
  362. CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts,
  363. llvm::Module &M, const llvm::DataLayout &TD,
  364. DiagnosticsEngine &Diags);
  365. ~CodeGenModule();
  366. void clear();
  367. /// Finalize LLVM code generation.
  368. void Release();
  369. /// Return a reference to the configured Objective-C runtime.
  370. CGObjCRuntime &getObjCRuntime() {
  371. if (!ObjCRuntime) createObjCRuntime();
  372. return *ObjCRuntime;
  373. }
  374. /// Return true iff an Objective-C runtime has been configured.
  375. bool hasObjCRuntime() { return !!ObjCRuntime; }
  376. /// Return a reference to the configured OpenCL runtime.
  377. CGOpenCLRuntime &getOpenCLRuntime() {
  378. assert(OpenCLRuntime != nullptr);
  379. return *OpenCLRuntime;
  380. }
  381. /// Return a reference to the configured OpenMP runtime.
  382. CGOpenMPRuntime &getOpenMPRuntime() {
  383. assert(OpenMPRuntime != nullptr);
  384. return *OpenMPRuntime;
  385. }
  386. /// Return a reference to the configured CUDA runtime.
  387. CGCUDARuntime &getCUDARuntime() {
  388. assert(CUDARuntime != nullptr);
  389. return *CUDARuntime;
  390. }
  391. ARCEntrypoints &getARCEntrypoints() const {
  392. assert(getLangOpts().ObjCAutoRefCount && ARCData != nullptr);
  393. return *ARCData;
  394. }
  395. RREntrypoints &getRREntrypoints() const {
  396. assert(RRData != nullptr);
  397. return *RRData;
  398. }
  399. InstrProfStats &getPGOStats() { return PGOStats; }
  400. llvm::IndexedInstrProfReader *getPGOReader() const { return PGOReader.get(); }
  401. llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) {
  402. return StaticLocalDeclMap[D];
  403. }
  404. void setStaticLocalDeclAddress(const VarDecl *D,
  405. llvm::Constant *C) {
  406. StaticLocalDeclMap[D] = C;
  407. }
  408. llvm::GlobalVariable *getStaticLocalDeclGuardAddress(const VarDecl *D) {
  409. return StaticLocalDeclGuardMap[D];
  410. }
  411. void setStaticLocalDeclGuardAddress(const VarDecl *D,
  412. llvm::GlobalVariable *C) {
  413. StaticLocalDeclGuardMap[D] = C;
  414. }
  415. bool lookupRepresentativeDecl(StringRef MangledName,
  416. GlobalDecl &Result) const;
  417. llvm::Constant *getAtomicSetterHelperFnMap(QualType Ty) {
  418. return AtomicSetterHelperFnMap[Ty];
  419. }
  420. void setAtomicSetterHelperFnMap(QualType Ty,
  421. llvm::Constant *Fn) {
  422. AtomicSetterHelperFnMap[Ty] = Fn;
  423. }
  424. llvm::Constant *getAtomicGetterHelperFnMap(QualType Ty) {
  425. return AtomicGetterHelperFnMap[Ty];
  426. }
  427. void setAtomicGetterHelperFnMap(QualType Ty,
  428. llvm::Constant *Fn) {
  429. AtomicGetterHelperFnMap[Ty] = Fn;
  430. }
  431. llvm::Constant *getTypeDescriptorFromMap(QualType Ty) {
  432. return TypeDescriptorMap[Ty];
  433. }
  434. void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C) {
  435. TypeDescriptorMap[Ty] = C;
  436. }
  437. CGDebugInfo *getModuleDebugInfo() { return DebugInfo; }
  438. llvm::MDNode *getNoObjCARCExceptionsMetadata() {
  439. if (!NoObjCARCExceptionsMetadata)
  440. NoObjCARCExceptionsMetadata =
  441. llvm::MDNode::get(getLLVMContext(),
  442. SmallVector<llvm::Value*,1>());
  443. return NoObjCARCExceptionsMetadata;
  444. }
  445. ASTContext &getContext() const { return Context; }
  446. const LangOptions &getLangOpts() const { return LangOpts; }
  447. const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
  448. llvm::Module &getModule() const { return TheModule; }
  449. DiagnosticsEngine &getDiags() const { return Diags; }
  450. const llvm::DataLayout &getDataLayout() const { return TheDataLayout; }
  451. const TargetInfo &getTarget() const { return Target; }
  452. CGCXXABI &getCXXABI() const { return *ABI; }
  453. llvm::LLVMContext &getLLVMContext() { return VMContext; }
  454. bool shouldUseTBAA() const { return TBAA != nullptr; }
  455. const TargetCodeGenInfo &getTargetCodeGenInfo();
  456. CodeGenTypes &getTypes() { return Types; }
  457. CodeGenVTables &getVTables() { return VTables; }
  458. ItaniumVTableContext &getItaniumVTableContext() {
  459. return VTables.getItaniumVTableContext();
  460. }
  461. MicrosoftVTableContext &getMicrosoftVTableContext() {
  462. return VTables.getMicrosoftVTableContext();
  463. }
  464. llvm::MDNode *getTBAAInfo(QualType QTy);
  465. llvm::MDNode *getTBAAInfoForVTablePtr();
  466. llvm::MDNode *getTBAAStructInfo(QualType QTy);
  467. /// Return the MDNode in the type DAG for the given struct type.
  468. llvm::MDNode *getTBAAStructTypeInfo(QualType QTy);
  469. /// Return the path-aware tag for given base type, access node and offset.
  470. llvm::MDNode *getTBAAStructTagInfo(QualType BaseTy, llvm::MDNode *AccessN,
  471. uint64_t O);
  472. bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor);
  473. bool isPaddedAtomicType(QualType type);
  474. bool isPaddedAtomicType(const AtomicType *type);
  475. /// Decorate the instruction with a TBAA tag. For scalar TBAA, the tag
  476. /// is the same as the type. For struct-path aware TBAA, the tag
  477. /// is different from the type: base type, access type and offset.
  478. /// When ConvertTypeToTag is true, we create a tag based on the scalar type.
  479. void DecorateInstruction(llvm::Instruction *Inst,
  480. llvm::MDNode *TBAAInfo,
  481. bool ConvertTypeToTag = true);
  482. /// Emit the given number of characters as a value of type size_t.
  483. llvm::ConstantInt *getSize(CharUnits numChars);
  484. /// Set the visibility for the given LLVM GlobalValue.
  485. void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const;
  486. /// Set the TLS mode for the given LLVM GlobalVariable for the thread-local
  487. /// variable declaration D.
  488. void setTLSMode(llvm::GlobalVariable *GV, const VarDecl &D) const;
  489. static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) {
  490. switch (V) {
  491. case DefaultVisibility: return llvm::GlobalValue::DefaultVisibility;
  492. case HiddenVisibility: return llvm::GlobalValue::HiddenVisibility;
  493. case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility;
  494. }
  495. llvm_unreachable("unknown visibility!");
  496. }
  497. llvm::Constant *GetAddrOfGlobal(GlobalDecl GD) {
  498. if (isa<CXXConstructorDecl>(GD.getDecl()))
  499. return GetAddrOfCXXConstructor(cast<CXXConstructorDecl>(GD.getDecl()),
  500. GD.getCtorType());
  501. else if (isa<CXXDestructorDecl>(GD.getDecl()))
  502. return GetAddrOfCXXDestructor(cast<CXXDestructorDecl>(GD.getDecl()),
  503. GD.getDtorType());
  504. else if (isa<FunctionDecl>(GD.getDecl()))
  505. return GetAddrOfFunction(GD);
  506. else
  507. return GetAddrOfGlobalVar(cast<VarDecl>(GD.getDecl()));
  508. }
  509. /// Will return a global variable of the given type. If a variable with a
  510. /// different type already exists then a new variable with the right type
  511. /// will be created and all uses of the old variable will be replaced with a
  512. /// bitcast to the new variable.
  513. llvm::GlobalVariable *
  514. CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty,
  515. llvm::GlobalValue::LinkageTypes Linkage);
  516. /// Return the address space of the underlying global variable for D, as
  517. /// determined by its declaration. Normally this is the same as the address
  518. /// space of D's type, but in CUDA, address spaces are associated with
  519. /// declarations, not types.
  520. unsigned GetGlobalVarAddressSpace(const VarDecl *D, unsigned AddrSpace);
  521. /// Return the llvm::Constant for the address of the given global variable.
  522. /// If Ty is non-null and if the global doesn't exist, then it will be greated
  523. /// with the specified type instead of whatever the normal requested type
  524. /// would be.
  525. llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
  526. llvm::Type *Ty = nullptr);
  527. /// Return the address of the given function. If Ty is non-null, then this
  528. /// function will use the specified type if it has to create it.
  529. llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = 0,
  530. bool ForVTable = false,
  531. bool DontDefer = false);
  532. /// Get the address of the RTTI descriptor for the given type.
  533. llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false);
  534. /// Get the address of a uuid descriptor .
  535. llvm::Constant *GetAddrOfUuidDescriptor(const CXXUuidofExpr* E);
  536. /// Get the address of the thunk for the given global decl.
  537. llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk);
  538. /// Get a reference to the target of VD.
  539. llvm::Constant *GetWeakRefReference(const ValueDecl *VD);
  540. /// Returns the offset from a derived class to a class. Returns null if the
  541. /// offset is 0.
  542. llvm::Constant *
  543. GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl,
  544. CastExpr::path_const_iterator PathBegin,
  545. CastExpr::path_const_iterator PathEnd);
  546. /// A pair of helper functions for a __block variable.
  547. class ByrefHelpers : public llvm::FoldingSetNode {
  548. public:
  549. llvm::Constant *CopyHelper;
  550. llvm::Constant *DisposeHelper;
  551. /// The alignment of the field. This is important because
  552. /// different offsets to the field within the byref struct need to
  553. /// have different helper functions.
  554. CharUnits Alignment;
  555. ByrefHelpers(CharUnits alignment) : Alignment(alignment) {}
  556. virtual ~ByrefHelpers();
  557. void Profile(llvm::FoldingSetNodeID &id) const {
  558. id.AddInteger(Alignment.getQuantity());
  559. profileImpl(id);
  560. }
  561. virtual void profileImpl(llvm::FoldingSetNodeID &id) const = 0;
  562. virtual bool needsCopy() const { return true; }
  563. virtual void emitCopy(CodeGenFunction &CGF,
  564. llvm::Value *dest, llvm::Value *src) = 0;
  565. virtual bool needsDispose() const { return true; }
  566. virtual void emitDispose(CodeGenFunction &CGF, llvm::Value *field) = 0;
  567. };
  568. llvm::FoldingSet<ByrefHelpers> ByrefHelpersCache;
  569. /// Fetches the global unique block count.
  570. int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; }
  571. /// Fetches the type of a generic block descriptor.
  572. llvm::Type *getBlockDescriptorType();
  573. /// The type of a generic block literal.
  574. llvm::Type *getGenericBlockLiteralType();
  575. /// \brief Gets or a creats a Microsoft TypeDescriptor.
  576. llvm::Constant *getMSTypeDescriptor(QualType Ty);
  577. /// \brief Gets or a creats a Microsoft CompleteObjectLocator.
  578. llvm::GlobalVariable *getMSCompleteObjectLocator(const CXXRecordDecl *RD,
  579. const VPtrInfo *Info);
  580. /// Gets the address of a block which requires no captures.
  581. llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, const char *);
  582. /// Return a pointer to a constant CFString object for the given string.
  583. llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal);
  584. /// Return a pointer to a constant NSString object for the given string. Or a
  585. /// user defined String object as defined via
  586. /// -fconstant-string-class=class_name option.
  587. llvm::Constant *GetAddrOfConstantString(const StringLiteral *Literal);
  588. /// Return a constant array for the given string.
  589. llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E);
  590. /// Return a pointer to a constant array for the given string literal.
  591. llvm::Constant *GetAddrOfConstantStringFromLiteral(const StringLiteral *S);
  592. /// Return a pointer to a constant array for the given ObjCEncodeExpr node.
  593. llvm::Constant *GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *);
  594. /// Returns a pointer to a character array containing the literal and a
  595. /// terminating '\0' character. The result has pointer to array type.
  596. ///
  597. /// \param GlobalName If provided, the name to use for the global (if one is
  598. /// created).
  599. llvm::Constant *GetAddrOfConstantCString(const std::string &str,
  600. const char *GlobalName = nullptr,
  601. unsigned Alignment = 0);
  602. /// Returns a pointer to a constant global variable for the given file-scope
  603. /// compound literal expression.
  604. llvm::Constant *GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr*E);
  605. /// \brief Returns a pointer to a global variable representing a temporary
  606. /// with static or thread storage duration.
  607. llvm::Constant *GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E,
  608. const Expr *Inner);
  609. /// \brief Retrieve the record type that describes the state of an
  610. /// Objective-C fast enumeration loop (for..in).
  611. QualType getObjCFastEnumerationStateType();
  612. /// Return the address of the constructor of the given type.
  613. llvm::GlobalValue *
  614. GetAddrOfCXXConstructor(const CXXConstructorDecl *ctor, CXXCtorType ctorType,
  615. const CGFunctionInfo *fnInfo = nullptr,
  616. bool DontDefer = false);
  617. /// Return the address of the constructor of the given type.
  618. llvm::GlobalValue *
  619. GetAddrOfCXXDestructor(const CXXDestructorDecl *dtor,
  620. CXXDtorType dtorType,
  621. const CGFunctionInfo *fnInfo = nullptr,
  622. llvm::FunctionType *fnType = nullptr,
  623. bool DontDefer = false);
  624. /// Given a builtin id for a function like "__builtin_fabsf", return a
  625. /// Function* for "fabsf".
  626. llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD,
  627. unsigned BuiltinID);
  628. llvm::Function *getIntrinsic(unsigned IID, ArrayRef<llvm::Type*> Tys = None);
  629. /// Emit code for a single top level declaration.
  630. void EmitTopLevelDecl(Decl *D);
  631. /// Tell the consumer that this variable has been instantiated.
  632. void HandleCXXStaticMemberVarInstantiation(VarDecl *VD);
  633. /// \brief If the declaration has internal linkage but is inside an
  634. /// extern "C" linkage specification, prepare to emit an alias for it
  635. /// to the expected name.
  636. template<typename SomeDecl>
  637. void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
  638. /// Add a global to a list to be added to the llvm.used metadata.
  639. void addUsedGlobal(llvm::GlobalValue *GV);
  640. /// Add a global to a list to be added to the llvm.compiler.used metadata.
  641. void addCompilerUsedGlobal(llvm::GlobalValue *GV);
  642. /// Add a destructor and object to add to the C++ global destructor function.
  643. void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) {
  644. CXXGlobalDtors.push_back(std::make_pair(DtorFn, Object));
  645. }
  646. /// Create a new runtime function with the specified type and name.
  647. llvm::Constant *CreateRuntimeFunction(llvm::FunctionType *Ty,
  648. StringRef Name,
  649. llvm::AttributeSet ExtraAttrs =
  650. llvm::AttributeSet());
  651. /// Create a new runtime global variable with the specified type and name.
  652. llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty,
  653. StringRef Name);
  654. ///@name Custom Blocks Runtime Interfaces
  655. ///@{
  656. llvm::Constant *getNSConcreteGlobalBlock();
  657. llvm::Constant *getNSConcreteStackBlock();
  658. llvm::Constant *getBlockObjectAssign();
  659. llvm::Constant *getBlockObjectDispose();
  660. ///@}
  661. llvm::Constant *getLLVMLifetimeStartFn();
  662. llvm::Constant *getLLVMLifetimeEndFn();
  663. // Make sure that this type is translated.
  664. void UpdateCompletedType(const TagDecl *TD);
  665. llvm::Constant *getMemberPointerConstant(const UnaryOperator *e);
  666. /// Try to emit the initializer for the given declaration as a constant;
  667. /// returns 0 if the expression cannot be emitted as a constant.
  668. llvm::Constant *EmitConstantInit(const VarDecl &D,
  669. CodeGenFunction *CGF = nullptr);
  670. /// Try to emit the given expression as a constant; returns 0 if the
  671. /// expression cannot be emitted as a constant.
  672. llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType,
  673. CodeGenFunction *CGF = nullptr);
  674. /// Emit the given constant value as a constant, in the type's scalar
  675. /// representation.
  676. llvm::Constant *EmitConstantValue(const APValue &Value, QualType DestType,
  677. CodeGenFunction *CGF = nullptr);
  678. /// Emit the given constant value as a constant, in the type's memory
  679. /// representation.
  680. llvm::Constant *EmitConstantValueForMemory(const APValue &Value,
  681. QualType DestType,
  682. CodeGenFunction *CGF = nullptr);
  683. /// Return the result of value-initializing the given type, i.e. a null
  684. /// expression of the given type. This is usually, but not always, an LLVM
  685. /// null constant.
  686. llvm::Constant *EmitNullConstant(QualType T);
  687. /// Return a null constant appropriate for zero-initializing a base class with
  688. /// the given type. This is usually, but not always, an LLVM null constant.
  689. llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record);
  690. /// Emit a general error that something can't be done.
  691. void Error(SourceLocation loc, StringRef error);
  692. /// Print out an error that codegen doesn't support the specified stmt yet.
  693. void ErrorUnsupported(const Stmt *S, const char *Type);
  694. /// Print out an error that codegen doesn't support the specified decl yet.
  695. void ErrorUnsupported(const Decl *D, const char *Type);
  696. /// Set the attributes on the LLVM function for the given decl and function
  697. /// info. This applies attributes necessary for handling the ABI as well as
  698. /// user specified attributes like section.
  699. void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F,
  700. const CGFunctionInfo &FI);
  701. /// Set the LLVM function attributes (sext, zext, etc).
  702. void SetLLVMFunctionAttributes(const Decl *D,
  703. const CGFunctionInfo &Info,
  704. llvm::Function *F);
  705. /// Set the LLVM function attributes which only apply to a function
  706. /// definintion.
  707. void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F);
  708. /// Return true iff the given type uses 'sret' when used as a return type.
  709. bool ReturnTypeUsesSRet(const CGFunctionInfo &FI);
  710. /// Return true iff the given type uses an argument slot when 'sret' is used
  711. /// as a return type.
  712. bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI);
  713. /// Return true iff the given type uses 'fpret' when used as a return type.
  714. bool ReturnTypeUsesFPRet(QualType ResultType);
  715. /// Return true iff the given type uses 'fp2ret' when used as a return type.
  716. bool ReturnTypeUsesFP2Ret(QualType ResultType);
  717. /// Get the LLVM attributes and calling convention to use for a particular
  718. /// function type.
  719. ///
  720. /// \param Info - The function type information.
  721. /// \param TargetDecl - The decl these attributes are being constructed
  722. /// for. If supplied the attributes applied to this decl may contribute to the
  723. /// function attributes and calling convention.
  724. /// \param PAL [out] - On return, the attribute list to use.
  725. /// \param CallingConv [out] - On return, the LLVM calling convention to use.
  726. void ConstructAttributeList(const CGFunctionInfo &Info,
  727. const Decl *TargetDecl,
  728. AttributeListType &PAL,
  729. unsigned &CallingConv,
  730. bool AttrOnCallSite);
  731. StringRef getMangledName(GlobalDecl GD);
  732. StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD);
  733. void EmitTentativeDefinition(const VarDecl *D);
  734. void EmitVTable(CXXRecordDecl *Class, bool DefinitionRequired);
  735. /// Emit the RTTI descriptors for the builtin types.
  736. void EmitFundamentalRTTIDescriptors();
  737. /// \brief Appends Opts to the "Linker Options" metadata value.
  738. void AppendLinkerOptions(StringRef Opts);
  739. /// \brief Appends a detect mismatch command to the linker options.
  740. void AddDetectMismatch(StringRef Name, StringRef Value);
  741. /// \brief Appends a dependent lib to the "Linker Options" metadata value.
  742. void AddDependentLib(StringRef Lib);
  743. llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD);
  744. void setFunctionLinkage(GlobalDecl GD, llvm::Function *F) {
  745. F->setLinkage(getFunctionLinkage(GD));
  746. }
  747. /// \brief Returns the appropriate linkage for the TypeInfo struct for a type.
  748. llvm::GlobalVariable::LinkageTypes getTypeInfoLinkage(QualType Ty);
  749. /// Return the appropriate linkage for the vtable, VTT, and type information
  750. /// of the given class.
  751. llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD);
  752. /// Return the store size, in character units, of the given LLVM type.
  753. CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const;
  754. /// Returns LLVM linkage for a declarator.
  755. llvm::GlobalValue::LinkageTypes
  756. getLLVMLinkageForDeclarator(const DeclaratorDecl *D, GVALinkage Linkage,
  757. bool IsConstantVariable);
  758. /// Returns LLVM linkage for a declarator.
  759. llvm::GlobalValue::LinkageTypes
  760. getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant);
  761. /// Emit all the global annotations.
  762. void EmitGlobalAnnotations();
  763. /// Emit an annotation string.
  764. llvm::Constant *EmitAnnotationString(StringRef Str);
  765. /// Emit the annotation's translation unit.
  766. llvm::Constant *EmitAnnotationUnit(SourceLocation Loc);
  767. /// Emit the annotation line number.
  768. llvm::Constant *EmitAnnotationLineNo(SourceLocation L);
  769. /// Generate the llvm::ConstantStruct which contains the annotation
  770. /// information for a given GlobalValue. The annotation struct is
  771. /// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the
  772. /// GlobalValue being annotated. The second field is the constant string
  773. /// created from the AnnotateAttr's annotation. The third field is a constant
  774. /// string containing the name of the translation unit. The fourth field is
  775. /// the line number in the file of the annotated value declaration.
  776. llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
  777. const AnnotateAttr *AA,
  778. SourceLocation L);
  779. /// Add global annotations that are set on D, for the global GV. Those
  780. /// annotations are emitted during finalization of the LLVM code.
  781. void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
  782. const llvm::SpecialCaseList &getSanitizerBlacklist() const {
  783. return *SanitizerBlacklist;
  784. }
  785. const SanitizerOptions &getSanOpts() const { return SanOpts; }
  786. void addDeferredVTable(const CXXRecordDecl *RD) {
  787. DeferredVTables.push_back(RD);
  788. }
  789. /// Emit code for a singal global function or var decl. Forward declarations
  790. /// are emitted lazily.
  791. void EmitGlobal(GlobalDecl D);
  792. private:
  793. llvm::GlobalValue *GetGlobalValue(StringRef Ref);
  794. llvm::Constant *
  795. GetOrCreateLLVMFunction(StringRef MangledName, llvm::Type *Ty, GlobalDecl D,
  796. bool ForVTable, bool DontDefer = false,
  797. llvm::AttributeSet ExtraAttrs = llvm::AttributeSet());
  798. llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName,
  799. llvm::PointerType *PTy,
  800. const VarDecl *D);
  801. llvm::StringMapEntry<llvm::GlobalVariable *> *
  802. getConstantStringMapEntry(StringRef Str, int CharByteWidth);
  803. /// Set attributes which are common to any form of a global definition (alias,
  804. /// Objective-C method, function, global variable).
  805. ///
  806. /// NOTE: This should only be called for definitions.
  807. void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV);
  808. void setNonAliasAttributes(const Decl *D, llvm::GlobalObject *GO);
  809. /// Set attributes for a global definition.
  810. void setFunctionDefinitionAttributes(const FunctionDecl *D,
  811. llvm::Function *F);
  812. /// Set function attributes for a function declaration.
  813. void SetFunctionAttributes(GlobalDecl GD,
  814. llvm::Function *F,
  815. bool IsIncompleteFunction);
  816. void EmitGlobalDefinition(GlobalDecl D, llvm::GlobalValue *GV = nullptr);
  817. void EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);
  818. void EmitGlobalVarDefinition(const VarDecl *D);
  819. void EmitAliasDefinition(GlobalDecl GD);
  820. void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
  821. void EmitObjCIvarInitializations(ObjCImplementationDecl *D);
  822. // C++ related functions.
  823. bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target,
  824. bool InEveryTU);
  825. bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D);
  826. void EmitNamespace(const NamespaceDecl *D);
  827. void EmitLinkageSpec(const LinkageSpecDecl *D);
  828. void CompleteDIClassType(const CXXMethodDecl* D);
  829. /// Emit a single constructor with the given type from a C++ constructor Decl.
  830. void EmitCXXConstructor(const CXXConstructorDecl *D, CXXCtorType Type);
  831. /// Emit a single destructor with the given type from a C++ destructor Decl.
  832. void EmitCXXDestructor(const CXXDestructorDecl *D, CXXDtorType Type);
  833. /// \brief Emit the function that initializes C++ thread_local variables.
  834. void EmitCXXThreadLocalInitFunc();
  835. /// Emit the function that initializes C++ globals.
  836. void EmitCXXGlobalInitFunc();
  837. /// Emit the function that destroys C++ globals.
  838. void EmitCXXGlobalDtorFunc();
  839. /// Emit the function that initializes the specified global (if PerformInit is
  840. /// true) and registers its destructor.
  841. void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
  842. llvm::GlobalVariable *Addr,
  843. bool PerformInit);
  844. // FIXME: Hardcoding priority here is gross.
  845. void AddGlobalCtor(llvm::Function *Ctor, int Priority = 65535,
  846. llvm::Constant *AssociatedData = 0);
  847. void AddGlobalDtor(llvm::Function *Dtor, int Priority = 65535);
  848. /// Generates a global array of functions and priorities using the given list
  849. /// and name. This array will have appending linkage and is suitable for use
  850. /// as a LLVM constructor or destructor array.
  851. void EmitCtorList(const CtorList &Fns, const char *GlobalName);
  852. /// Emit the RTTI descriptors for the given type.
  853. void EmitFundamentalRTTIDescriptor(QualType Type);
  854. /// Emit any needed decls for which code generation was deferred.
  855. void EmitDeferred();
  856. /// Call replaceAllUsesWith on all pairs in Replacements.
  857. void applyReplacements();
  858. void checkAliases();
  859. /// Emit any vtables which we deferred and still have a use for.
  860. void EmitDeferredVTables();
  861. /// Emit the llvm.used and llvm.compiler.used metadata.
  862. void emitLLVMUsed();
  863. /// \brief Emit the link options introduced by imported modules.
  864. void EmitModuleLinkOptions();
  865. /// \brief Emit aliases for internal-linkage declarations inside "C" language
  866. /// linkage specifications, giving them the "expected" name where possible.
  867. void EmitStaticExternCAliases();
  868. void EmitDeclMetadata();
  869. /// \brief Emit the Clang version as llvm.ident metadata.
  870. void EmitVersionIdentMetadata();
  871. /// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and
  872. /// .gcda files in a way that persists in .bc files.
  873. void EmitCoverageFile();
  874. /// Emits the initializer for a uuidof string.
  875. llvm::Constant *EmitUuidofInitializer(StringRef uuidstr, QualType IIDType);
  876. /// Determine if the given decl can be emitted lazily; this is only relevant
  877. /// for definitions. The given decl must be either a function or var decl.
  878. bool MayDeferGeneration(const ValueDecl *D);
  879. /// Check whether we can use a "simpler", more core exceptions personality
  880. /// function.
  881. void SimplifyPersonality();
  882. };
  883. } // end namespace CodeGen
  884. } // end namespace clang
  885. #endif