CodeGenModule.h 41 KB

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