clang API Documentation

CodeGenModule.h
Go to the documentation of this file.
00001 //===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This is the internal per-translation-unit state used for llvm translation.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
00015 #define LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
00016 
00017 #include "CGVTables.h"
00018 #include "CodeGenTypes.h"
00019 #include "SanitizerMetadata.h"
00020 #include "clang/AST/Attr.h"
00021 #include "clang/AST/DeclCXX.h"
00022 #include "clang/AST/DeclObjC.h"
00023 #include "clang/AST/GlobalDecl.h"
00024 #include "clang/AST/Mangle.h"
00025 #include "clang/Basic/ABI.h"
00026 #include "clang/Basic/LangOptions.h"
00027 #include "clang/Basic/Module.h"
00028 #include "clang/Basic/SanitizerBlacklist.h"
00029 #include "llvm/ADT/DenseMap.h"
00030 #include "llvm/ADT/SetVector.h"
00031 #include "llvm/ADT/SmallPtrSet.h"
00032 #include "llvm/ADT/StringMap.h"
00033 #include "llvm/IR/CallingConv.h"
00034 #include "llvm/IR/Module.h"
00035 #include "llvm/IR/ValueHandle.h"
00036 
00037 namespace llvm {
00038 class Module;
00039 class Constant;
00040 class ConstantInt;
00041 class Function;
00042 class GlobalValue;
00043 class DataLayout;
00044 class FunctionType;
00045 class LLVMContext;
00046 class IndexedInstrProfReader;
00047 }
00048 
00049 namespace clang {
00050 class TargetCodeGenInfo;
00051 class ASTContext;
00052 class AtomicType;
00053 class FunctionDecl;
00054 class IdentifierInfo;
00055 class ObjCMethodDecl;
00056 class ObjCImplementationDecl;
00057 class ObjCCategoryImplDecl;
00058 class ObjCProtocolDecl;
00059 class ObjCEncodeExpr;
00060 class BlockExpr;
00061 class CharUnits;
00062 class Decl;
00063 class Expr;
00064 class Stmt;
00065 class InitListExpr;
00066 class StringLiteral;
00067 class NamedDecl;
00068 class ValueDecl;
00069 class VarDecl;
00070 class LangOptions;
00071 class CodeGenOptions;
00072 class DiagnosticsEngine;
00073 class AnnotateAttr;
00074 class CXXDestructorDecl;
00075 class Module;
00076 class CoverageSourceInfo;
00077 
00078 namespace CodeGen {
00079 
00080 class CallArgList;
00081 class CodeGenFunction;
00082 class CodeGenTBAA;
00083 class CGCXXABI;
00084 class CGDebugInfo;
00085 class CGObjCRuntime;
00086 class CGOpenCLRuntime;
00087 class CGOpenMPRuntime;
00088 class CGCUDARuntime;
00089 class BlockFieldFlags;
00090 class FunctionArgList;
00091 class CoverageMappingModuleGen;
00092 
00093 struct OrderGlobalInits {
00094   unsigned int priority;
00095   unsigned int lex_order;
00096   OrderGlobalInits(unsigned int p, unsigned int l)
00097       : priority(p), lex_order(l) {}
00098 
00099   bool operator==(const OrderGlobalInits &RHS) const {
00100     return priority == RHS.priority && lex_order == RHS.lex_order;
00101   }
00102 
00103   bool operator<(const OrderGlobalInits &RHS) const {
00104     return std::tie(priority, lex_order) <
00105            std::tie(RHS.priority, RHS.lex_order);
00106   }
00107 };
00108 
00109 struct CodeGenTypeCache {
00110   /// void
00111   llvm::Type *VoidTy;
00112 
00113   /// i8, i16, i32, and i64
00114   llvm::IntegerType *Int8Ty, *Int16Ty, *Int32Ty, *Int64Ty;
00115   /// float, double
00116   llvm::Type *FloatTy, *DoubleTy;
00117 
00118   /// int
00119   llvm::IntegerType *IntTy;
00120 
00121   /// intptr_t, size_t, and ptrdiff_t, which we assume are the same size.
00122   union {
00123     llvm::IntegerType *IntPtrTy;
00124     llvm::IntegerType *SizeTy;
00125     llvm::IntegerType *PtrDiffTy;
00126   };
00127 
00128   /// void* in address space 0
00129   union {
00130     llvm::PointerType *VoidPtrTy;
00131     llvm::PointerType *Int8PtrTy;
00132   };
00133 
00134   /// void** in address space 0
00135   union {
00136     llvm::PointerType *VoidPtrPtrTy;
00137     llvm::PointerType *Int8PtrPtrTy;
00138   };
00139 
00140   /// The width of a pointer into the generic address space.
00141   unsigned char PointerWidthInBits;
00142 
00143   /// The size and alignment of a pointer into the generic address
00144   /// space.
00145   union {
00146     unsigned char PointerAlignInBytes;
00147     unsigned char PointerSizeInBytes;
00148     unsigned char SizeSizeInBytes; // sizeof(size_t)
00149   };
00150 
00151   llvm::CallingConv::ID RuntimeCC;
00152   llvm::CallingConv::ID getRuntimeCC() const { return RuntimeCC; }
00153 };
00154 
00155 struct RREntrypoints {
00156   RREntrypoints() { memset(this, 0, sizeof(*this)); }
00157   /// void objc_autoreleasePoolPop(void*);
00158   llvm::Constant *objc_autoreleasePoolPop;
00159 
00160   /// void *objc_autoreleasePoolPush(void);
00161   llvm::Constant *objc_autoreleasePoolPush;
00162 };
00163 
00164 struct ARCEntrypoints {
00165   ARCEntrypoints() { memset(this, 0, sizeof(*this)); }
00166 
00167   /// id objc_autorelease(id);
00168   llvm::Constant *objc_autorelease;
00169 
00170   /// id objc_autoreleaseReturnValue(id);
00171   llvm::Constant *objc_autoreleaseReturnValue;
00172 
00173   /// void objc_copyWeak(id *dest, id *src);
00174   llvm::Constant *objc_copyWeak;
00175 
00176   /// void objc_destroyWeak(id*);
00177   llvm::Constant *objc_destroyWeak;
00178 
00179   /// id objc_initWeak(id*, id);
00180   llvm::Constant *objc_initWeak;
00181 
00182   /// id objc_loadWeak(id*);
00183   llvm::Constant *objc_loadWeak;
00184 
00185   /// id objc_loadWeakRetained(id*);
00186   llvm::Constant *objc_loadWeakRetained;
00187 
00188   /// void objc_moveWeak(id *dest, id *src);
00189   llvm::Constant *objc_moveWeak;
00190 
00191   /// id objc_retain(id);
00192   llvm::Constant *objc_retain;
00193 
00194   /// id objc_retainAutorelease(id);
00195   llvm::Constant *objc_retainAutorelease;
00196 
00197   /// id objc_retainAutoreleaseReturnValue(id);
00198   llvm::Constant *objc_retainAutoreleaseReturnValue;
00199 
00200   /// id objc_retainAutoreleasedReturnValue(id);
00201   llvm::Constant *objc_retainAutoreleasedReturnValue;
00202 
00203   /// id objc_retainBlock(id);
00204   llvm::Constant *objc_retainBlock;
00205 
00206   /// void objc_release(id);
00207   llvm::Constant *objc_release;
00208 
00209   /// id objc_storeStrong(id*, id);
00210   llvm::Constant *objc_storeStrong;
00211 
00212   /// id objc_storeWeak(id*, id);
00213   llvm::Constant *objc_storeWeak;
00214 
00215   /// A void(void) inline asm to use to mark that the return value of
00216   /// a call will be immediately retain.
00217   llvm::InlineAsm *retainAutoreleasedReturnValueMarker;
00218 
00219   /// void clang.arc.use(...);
00220   llvm::Constant *clang_arc_use;
00221 };
00222 
00223 /// This class records statistics on instrumentation based profiling.
00224 class InstrProfStats {
00225   uint32_t VisitedInMainFile;
00226   uint32_t MissingInMainFile;
00227   uint32_t Visited;
00228   uint32_t Missing;
00229   uint32_t Mismatched;
00230 
00231 public:
00232   InstrProfStats()
00233       : VisitedInMainFile(0), MissingInMainFile(0), Visited(0), Missing(0),
00234         Mismatched(0) {}
00235   /// Record that we've visited a function and whether or not that function was
00236   /// in the main source file.
00237   void addVisited(bool MainFile) {
00238     if (MainFile)
00239       ++VisitedInMainFile;
00240     ++Visited;
00241   }
00242   /// Record that a function we've visited has no profile data.
00243   void addMissing(bool MainFile) {
00244     if (MainFile)
00245       ++MissingInMainFile;
00246     ++Missing;
00247   }
00248   /// Record that a function we've visited has mismatched profile data.
00249   void addMismatched(bool MainFile) { ++Mismatched; }
00250   /// Whether or not the stats we've gathered indicate any potential problems.
00251   bool hasDiagnostics() { return Missing || Mismatched; }
00252   /// Report potential problems we've found to \c Diags.
00253   void reportDiagnostics(DiagnosticsEngine &Diags, StringRef MainFile);
00254 };
00255 
00256 /// This class organizes the cross-function state that is used while generating
00257 /// LLVM code.
00258 class CodeGenModule : public CodeGenTypeCache {
00259   CodeGenModule(const CodeGenModule &) LLVM_DELETED_FUNCTION;
00260   void operator=(const CodeGenModule &) LLVM_DELETED_FUNCTION;
00261 
00262   struct Structor {
00263     Structor() : Priority(0), Initializer(nullptr), AssociatedData(nullptr) {}
00264     Structor(int Priority, llvm::Constant *Initializer,
00265              llvm::Constant *AssociatedData)
00266         : Priority(Priority), Initializer(Initializer),
00267           AssociatedData(AssociatedData) {}
00268     int Priority;
00269     llvm::Constant *Initializer;
00270     llvm::Constant *AssociatedData;
00271   };
00272 
00273   typedef std::vector<Structor> CtorList;
00274 
00275   ASTContext &Context;
00276   const LangOptions &LangOpts;
00277   const CodeGenOptions &CodeGenOpts;
00278   llvm::Module &TheModule;
00279   DiagnosticsEngine &Diags;
00280   const llvm::DataLayout &TheDataLayout;
00281   const TargetInfo &Target;
00282   std::unique_ptr<CGCXXABI> ABI;
00283   llvm::LLVMContext &VMContext;
00284 
00285   CodeGenTBAA *TBAA;
00286   
00287   mutable const TargetCodeGenInfo *TheTargetCodeGenInfo;
00288   
00289   // This should not be moved earlier, since its initialization depends on some
00290   // of the previous reference members being already initialized and also checks
00291   // if TheTargetCodeGenInfo is NULL
00292   CodeGenTypes Types;
00293  
00294   /// Holds information about C++ vtables.
00295   CodeGenVTables VTables;
00296 
00297   CGObjCRuntime* ObjCRuntime;
00298   CGOpenCLRuntime* OpenCLRuntime;
00299   CGOpenMPRuntime* OpenMPRuntime;
00300   CGCUDARuntime* CUDARuntime;
00301   CGDebugInfo* DebugInfo;
00302   ARCEntrypoints *ARCData;
00303   llvm::MDNode *NoObjCARCExceptionsMetadata;
00304   RREntrypoints *RRData;
00305   std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader;
00306   InstrProfStats PGOStats;
00307 
00308   // A set of references that have only been seen via a weakref so far. This is
00309   // used to remove the weak of the reference if we ever see a direct reference
00310   // or a definition.
00311   llvm::SmallPtrSet<llvm::GlobalValue*, 10> WeakRefReferences;
00312 
00313   /// This contains all the decls which have definitions but/ which are deferred
00314   /// for emission and therefore should only be output if they are actually
00315   /// used. If a decl is in this, then it is known to have not been referenced
00316   /// yet.
00317   std::map<StringRef, GlobalDecl> DeferredDecls;
00318 
00319   /// This is a list of deferred decls which we have seen that *are* actually
00320   /// referenced. These get code generated when the module is done.
00321   struct DeferredGlobal {
00322     DeferredGlobal(llvm::GlobalValue *GV, GlobalDecl GD) : GV(GV), GD(GD) {}
00323     llvm::AssertingVH<llvm::GlobalValue> GV;
00324     GlobalDecl GD;
00325   };
00326   std::vector<DeferredGlobal> DeferredDeclsToEmit;
00327   void addDeferredDeclToEmit(llvm::GlobalValue *GV, GlobalDecl GD) {
00328     DeferredDeclsToEmit.push_back(DeferredGlobal(GV, GD));
00329   }
00330 
00331   /// List of alias we have emitted. Used to make sure that what they point to
00332   /// is defined once we get to the end of the of the translation unit.
00333   std::vector<GlobalDecl> Aliases;
00334 
00335   typedef llvm::StringMap<llvm::TrackingVH<llvm::Constant> > ReplacementsTy;
00336   ReplacementsTy Replacements;
00337 
00338   /// A queue of (optional) vtables to consider emitting.
00339   std::vector<const CXXRecordDecl*> DeferredVTables;
00340 
00341   /// List of global values which are required to be present in the object file;
00342   /// bitcast to i8*. This is used for forcing visibility of symbols which may
00343   /// otherwise be optimized out.
00344   std::vector<llvm::WeakVH> LLVMUsed;
00345   std::vector<llvm::WeakVH> LLVMCompilerUsed;
00346 
00347   /// Store the list of global constructors and their respective priorities to
00348   /// be emitted when the translation unit is complete.
00349   CtorList GlobalCtors;
00350 
00351   /// Store the list of global destructors and their respective priorities to be
00352   /// emitted when the translation unit is complete.
00353   CtorList GlobalDtors;
00354 
00355   /// An ordered map of canonical GlobalDecls to their mangled names.
00356   llvm::MapVector<GlobalDecl, StringRef> MangledDeclNames;
00357   llvm::StringMap<GlobalDecl, llvm::BumpPtrAllocator> Manglings;
00358 
00359   /// Global annotations.
00360   std::vector<llvm::Constant*> Annotations;
00361 
00362   /// Map used to get unique annotation strings.
00363   llvm::StringMap<llvm::Constant*> AnnotationStrings;
00364 
00365   llvm::StringMap<llvm::Constant*> CFConstantStringMap;
00366 
00367   llvm::DenseMap<llvm::Constant *, llvm::GlobalVariable *> ConstantStringMap;
00368   llvm::DenseMap<const Decl*, llvm::Constant *> StaticLocalDeclMap;
00369   llvm::DenseMap<const Decl*, llvm::GlobalVariable*> StaticLocalDeclGuardMap;
00370   llvm::DenseMap<const Expr*, llvm::Constant *> MaterializedGlobalTemporaryMap;
00371 
00372   llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap;
00373   llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap;
00374 
00375   /// Map used to get unique type descriptor constants for sanitizers.
00376   llvm::DenseMap<QualType, llvm::Constant *> TypeDescriptorMap;
00377 
00378   /// Map used to track internal linkage functions declared within
00379   /// extern "C" regions.
00380   typedef llvm::MapVector<IdentifierInfo *,
00381                           llvm::GlobalValue *> StaticExternCMap;
00382   StaticExternCMap StaticExternCValues;
00383 
00384   /// \brief thread_local variables defined or used in this TU.
00385   std::vector<std::pair<const VarDecl *, llvm::GlobalVariable *> >
00386     CXXThreadLocals;
00387 
00388   /// \brief thread_local variables with initializers that need to run
00389   /// before any thread_local variable in this TU is odr-used.
00390   std::vector<llvm::Function *> CXXThreadLocalInits;
00391   std::vector<llvm::GlobalVariable *> CXXThreadLocalInitVars;
00392 
00393   /// Global variables with initializers that need to run before main.
00394   std::vector<llvm::Function *> CXXGlobalInits;
00395 
00396   /// When a C++ decl with an initializer is deferred, null is
00397   /// appended to CXXGlobalInits, and the index of that null is placed
00398   /// here so that the initializer will be performed in the correct
00399   /// order.
00400   llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition;
00401   
00402   typedef std::pair<OrderGlobalInits, llvm::Function*> GlobalInitData;
00403 
00404   struct GlobalInitPriorityCmp {
00405     bool operator()(const GlobalInitData &LHS,
00406                     const GlobalInitData &RHS) const {
00407       return LHS.first.priority < RHS.first.priority;
00408     }
00409   };
00410 
00411   /// Global variables with initializers whose order of initialization is set by
00412   /// init_priority attribute.
00413   SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits;
00414 
00415   /// Global destructor functions and arguments that need to run on termination.
00416   std::vector<std::pair<llvm::WeakVH,llvm::Constant*> > CXXGlobalDtors;
00417 
00418   /// \brief The complete set of modules that has been imported.
00419   llvm::SetVector<clang::Module *> ImportedModules;
00420 
00421   /// \brief A vector of metadata strings.
00422   SmallVector<llvm::Value *, 16> LinkerOptionsMetadata;
00423 
00424   /// @name Cache for Objective-C runtime types
00425   /// @{
00426 
00427   /// Cached reference to the class for constant strings. This value has type
00428   /// int * but is actually an Obj-C class pointer.
00429   llvm::WeakVH CFConstantStringClassRef;
00430 
00431   /// Cached reference to the class for constant strings. This value has type
00432   /// int * but is actually an Obj-C class pointer.
00433   llvm::WeakVH ConstantStringClassRef;
00434 
00435   /// \brief The LLVM type corresponding to NSConstantString.
00436   llvm::StructType *NSConstantStringType;
00437   
00438   /// \brief The type used to describe the state of a fast enumeration in
00439   /// Objective-C's for..in loop.
00440   QualType ObjCFastEnumerationStateType;
00441   
00442   /// @}
00443 
00444   /// Lazily create the Objective-C runtime
00445   void createObjCRuntime();
00446 
00447   void createOpenCLRuntime();
00448   void createOpenMPRuntime();
00449   void createCUDARuntime();
00450 
00451   bool isTriviallyRecursive(const FunctionDecl *F);
00452   bool shouldEmitFunction(GlobalDecl GD);
00453 
00454   /// @name Cache for Blocks Runtime Globals
00455   /// @{
00456 
00457   llvm::Constant *NSConcreteGlobalBlock;
00458   llvm::Constant *NSConcreteStackBlock;
00459 
00460   llvm::Constant *BlockObjectAssign;
00461   llvm::Constant *BlockObjectDispose;
00462 
00463   llvm::Type *BlockDescriptorType;
00464   llvm::Type *GenericBlockLiteralType;
00465 
00466   struct {
00467     int GlobalUniqueCount;
00468   } Block;
00469 
00470   /// void @llvm.lifetime.start(i64 %size, i8* nocapture <ptr>)
00471   llvm::Constant *LifetimeStartFn;
00472 
00473   /// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>)
00474   llvm::Constant *LifetimeEndFn;
00475 
00476   GlobalDecl initializedGlobalDecl;
00477 
00478   std::unique_ptr<SanitizerMetadata> SanitizerMD;
00479 
00480   /// @}
00481 
00482   llvm::DenseMap<const Decl *, bool> DeferredEmptyCoverageMappingDecls;
00483 
00484   std::unique_ptr<CoverageMappingModuleGen> CoverageMapping;
00485 public:
00486   CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts,
00487                 llvm::Module &M, const llvm::DataLayout &TD,
00488                 DiagnosticsEngine &Diags,
00489                 CoverageSourceInfo *CoverageInfo = nullptr);
00490 
00491   ~CodeGenModule();
00492 
00493   void clear();
00494 
00495   /// Finalize LLVM code generation.
00496   void Release();
00497 
00498   /// Return a reference to the configured Objective-C runtime.
00499   CGObjCRuntime &getObjCRuntime() {
00500     if (!ObjCRuntime) createObjCRuntime();
00501     return *ObjCRuntime;
00502   }
00503 
00504   /// Return true iff an Objective-C runtime has been configured.
00505   bool hasObjCRuntime() { return !!ObjCRuntime; }
00506 
00507   /// Return a reference to the configured OpenCL runtime.
00508   CGOpenCLRuntime &getOpenCLRuntime() {
00509     assert(OpenCLRuntime != nullptr);
00510     return *OpenCLRuntime;
00511   }
00512 
00513   /// Return a reference to the configured OpenMP runtime.
00514   CGOpenMPRuntime &getOpenMPRuntime() {
00515     assert(OpenMPRuntime != nullptr);
00516     return *OpenMPRuntime;
00517   }
00518 
00519   /// Return a reference to the configured CUDA runtime.
00520   CGCUDARuntime &getCUDARuntime() {
00521     assert(CUDARuntime != nullptr);
00522     return *CUDARuntime;
00523   }
00524 
00525   ARCEntrypoints &getARCEntrypoints() const {
00526     assert(getLangOpts().ObjCAutoRefCount && ARCData != nullptr);
00527     return *ARCData;
00528   }
00529 
00530   RREntrypoints &getRREntrypoints() const {
00531     assert(RRData != nullptr);
00532     return *RRData;
00533   }
00534 
00535   InstrProfStats &getPGOStats() { return PGOStats; }
00536   llvm::IndexedInstrProfReader *getPGOReader() const { return PGOReader.get(); }
00537 
00538   CoverageMappingModuleGen *getCoverageMapping() const {
00539     return CoverageMapping.get();
00540   }
00541 
00542   llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) {
00543     return StaticLocalDeclMap[D];
00544   }
00545   void setStaticLocalDeclAddress(const VarDecl *D, 
00546                                  llvm::Constant *C) {
00547     StaticLocalDeclMap[D] = C;
00548   }
00549 
00550   llvm::Constant *
00551   getOrCreateStaticVarDecl(const VarDecl &D,
00552                            llvm::GlobalValue::LinkageTypes Linkage);
00553 
00554   llvm::GlobalVariable *getStaticLocalDeclGuardAddress(const VarDecl *D) {
00555     return StaticLocalDeclGuardMap[D];
00556   }
00557   void setStaticLocalDeclGuardAddress(const VarDecl *D, 
00558                                       llvm::GlobalVariable *C) {
00559     StaticLocalDeclGuardMap[D] = C;
00560   }
00561 
00562   bool lookupRepresentativeDecl(StringRef MangledName,
00563                                 GlobalDecl &Result) const;
00564 
00565   llvm::Constant *getAtomicSetterHelperFnMap(QualType Ty) {
00566     return AtomicSetterHelperFnMap[Ty];
00567   }
00568   void setAtomicSetterHelperFnMap(QualType Ty,
00569                             llvm::Constant *Fn) {
00570     AtomicSetterHelperFnMap[Ty] = Fn;
00571   }
00572 
00573   llvm::Constant *getAtomicGetterHelperFnMap(QualType Ty) {
00574     return AtomicGetterHelperFnMap[Ty];
00575   }
00576   void setAtomicGetterHelperFnMap(QualType Ty,
00577                             llvm::Constant *Fn) {
00578     AtomicGetterHelperFnMap[Ty] = Fn;
00579   }
00580 
00581   llvm::Constant *getTypeDescriptorFromMap(QualType Ty) {
00582     return TypeDescriptorMap[Ty];
00583   }
00584   void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C) {
00585     TypeDescriptorMap[Ty] = C;
00586   }
00587 
00588   CGDebugInfo *getModuleDebugInfo() { return DebugInfo; }
00589 
00590   llvm::MDNode *getNoObjCARCExceptionsMetadata() {
00591     if (!NoObjCARCExceptionsMetadata)
00592       NoObjCARCExceptionsMetadata =
00593         llvm::MDNode::get(getLLVMContext(),
00594                           SmallVector<llvm::Value*,1>());
00595     return NoObjCARCExceptionsMetadata;
00596   }
00597 
00598   ASTContext &getContext() const { return Context; }
00599   const LangOptions &getLangOpts() const { return LangOpts; }
00600   const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
00601   llvm::Module &getModule() const { return TheModule; }
00602   DiagnosticsEngine &getDiags() const { return Diags; }
00603   const llvm::DataLayout &getDataLayout() const { return TheDataLayout; }
00604   const TargetInfo &getTarget() const { return Target; }
00605   const llvm::Triple &getTriple() const;
00606   bool supportsCOMDAT() const;
00607 
00608   CGCXXABI &getCXXABI() const { return *ABI; }
00609   llvm::LLVMContext &getLLVMContext() { return VMContext; }
00610 
00611   bool shouldUseTBAA() const { return TBAA != nullptr; }
00612 
00613   const TargetCodeGenInfo &getTargetCodeGenInfo(); 
00614   
00615   CodeGenTypes &getTypes() { return Types; }
00616  
00617   CodeGenVTables &getVTables() { return VTables; }
00618 
00619   ItaniumVTableContext &getItaniumVTableContext() {
00620     return VTables.getItaniumVTableContext();
00621   }
00622 
00623   MicrosoftVTableContext &getMicrosoftVTableContext() {
00624     return VTables.getMicrosoftVTableContext();
00625   }
00626 
00627   llvm::MDNode *getTBAAInfo(QualType QTy);
00628   llvm::MDNode *getTBAAInfoForVTablePtr();
00629   llvm::MDNode *getTBAAStructInfo(QualType QTy);
00630   /// Return the MDNode in the type DAG for the given struct type.
00631   llvm::MDNode *getTBAAStructTypeInfo(QualType QTy);
00632   /// Return the path-aware tag for given base type, access node and offset.
00633   llvm::MDNode *getTBAAStructTagInfo(QualType BaseTy, llvm::MDNode *AccessN,
00634                                      uint64_t O);
00635 
00636   bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor);
00637 
00638   bool isPaddedAtomicType(QualType type);
00639   bool isPaddedAtomicType(const AtomicType *type);
00640 
00641   /// Decorate the instruction with a TBAA tag. For scalar TBAA, the tag
00642   /// is the same as the type. For struct-path aware TBAA, the tag
00643   /// is different from the type: base type, access type and offset.
00644   /// When ConvertTypeToTag is true, we create a tag based on the scalar type.
00645   void DecorateInstruction(llvm::Instruction *Inst,
00646                            llvm::MDNode *TBAAInfo,
00647                            bool ConvertTypeToTag = true);
00648 
00649   /// Emit the given number of characters as a value of type size_t.
00650   llvm::ConstantInt *getSize(CharUnits numChars);
00651 
00652   /// Set the visibility for the given LLVM GlobalValue.
00653   void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const;
00654 
00655   /// Set the TLS mode for the given LLVM GlobalValue for the thread-local
00656   /// variable declaration D.
00657   void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const;
00658 
00659   static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) {
00660     switch (V) {
00661     case DefaultVisibility:   return llvm::GlobalValue::DefaultVisibility;
00662     case HiddenVisibility:    return llvm::GlobalValue::HiddenVisibility;
00663     case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility;
00664     }
00665     llvm_unreachable("unknown visibility!");
00666   }
00667 
00668   llvm::Constant *GetAddrOfGlobal(GlobalDecl GD) {
00669     if (isa<CXXConstructorDecl>(GD.getDecl()))
00670       return getAddrOfCXXStructor(cast<CXXConstructorDecl>(GD.getDecl()),
00671                                   getFromCtorType(GD.getCtorType()));
00672     else if (isa<CXXDestructorDecl>(GD.getDecl()))
00673       return getAddrOfCXXStructor(cast<CXXDestructorDecl>(GD.getDecl()),
00674                                   getFromDtorType(GD.getDtorType()));
00675     else if (isa<FunctionDecl>(GD.getDecl()))
00676       return GetAddrOfFunction(GD);
00677     else
00678       return GetAddrOfGlobalVar(cast<VarDecl>(GD.getDecl()));
00679   }
00680 
00681   /// Will return a global variable of the given type. If a variable with a
00682   /// different type already exists then a new  variable with the right type
00683   /// will be created and all uses of the old variable will be replaced with a
00684   /// bitcast to the new variable.
00685   llvm::GlobalVariable *
00686   CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty,
00687                                     llvm::GlobalValue::LinkageTypes Linkage);
00688 
00689   llvm::Function *
00690   CreateGlobalInitOrDestructFunction(llvm::FunctionType *ty, const Twine &name,
00691                                      SourceLocation Loc = SourceLocation(),
00692                                      bool TLS = false);
00693 
00694   /// Return the address space of the underlying global variable for D, as
00695   /// determined by its declaration. Normally this is the same as the address
00696   /// space of D's type, but in CUDA, address spaces are associated with
00697   /// declarations, not types.
00698   unsigned GetGlobalVarAddressSpace(const VarDecl *D, unsigned AddrSpace);
00699 
00700   /// Return the llvm::Constant for the address of the given global variable.
00701   /// If Ty is non-null and if the global doesn't exist, then it will be greated
00702   /// with the specified type instead of whatever the normal requested type
00703   /// would be.
00704   llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
00705                                      llvm::Type *Ty = nullptr);
00706 
00707   /// Return the address of the given function. If Ty is non-null, then this
00708   /// function will use the specified type if it has to create it.
00709   llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = 0,
00710                                     bool ForVTable = false,
00711                                     bool DontDefer = false);
00712 
00713   /// Get the address of the RTTI descriptor for the given type.
00714   llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false);
00715 
00716   /// Get the address of a uuid descriptor .
00717   llvm::Constant *GetAddrOfUuidDescriptor(const CXXUuidofExpr* E);
00718 
00719   /// Get the address of the thunk for the given global decl.
00720   llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk);
00721 
00722   /// Get a reference to the target of VD.
00723   llvm::Constant *GetWeakRefReference(const ValueDecl *VD);
00724 
00725   /// Returns the offset from a derived class to  a class. Returns null if the
00726   /// offset is 0.
00727   llvm::Constant *
00728   GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl,
00729                                CastExpr::path_const_iterator PathBegin,
00730                                CastExpr::path_const_iterator PathEnd);
00731 
00732   /// A pair of helper functions for a __block variable.
00733   class ByrefHelpers : public llvm::FoldingSetNode {
00734   public:
00735     llvm::Constant *CopyHelper;
00736     llvm::Constant *DisposeHelper;
00737 
00738     /// The alignment of the field.  This is important because
00739     /// different offsets to the field within the byref struct need to
00740     /// have different helper functions.
00741     CharUnits Alignment;
00742 
00743     ByrefHelpers(CharUnits alignment) : Alignment(alignment) {}
00744     virtual ~ByrefHelpers();
00745 
00746     void Profile(llvm::FoldingSetNodeID &id) const {
00747       id.AddInteger(Alignment.getQuantity());
00748       profileImpl(id);
00749     }
00750     virtual void profileImpl(llvm::FoldingSetNodeID &id) const = 0;
00751 
00752     virtual bool needsCopy() const { return true; }
00753     virtual void emitCopy(CodeGenFunction &CGF,
00754                           llvm::Value *dest, llvm::Value *src) = 0;
00755 
00756     virtual bool needsDispose() const { return true; }
00757     virtual void emitDispose(CodeGenFunction &CGF, llvm::Value *field) = 0;
00758   };
00759 
00760   llvm::FoldingSet<ByrefHelpers> ByrefHelpersCache;
00761 
00762   /// Fetches the global unique block count.
00763   int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; }
00764   
00765   /// Fetches the type of a generic block descriptor.
00766   llvm::Type *getBlockDescriptorType();
00767 
00768   /// The type of a generic block literal.
00769   llvm::Type *getGenericBlockLiteralType();
00770 
00771   /// Gets the address of a block which requires no captures.
00772   llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, const char *);
00773   
00774   /// Return a pointer to a constant CFString object for the given string.
00775   llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal);
00776 
00777   /// Return a pointer to a constant NSString object for the given string. Or a
00778   /// user defined String object as defined via
00779   /// -fconstant-string-class=class_name option.
00780   llvm::Constant *GetAddrOfConstantString(const StringLiteral *Literal);
00781 
00782   /// Return a constant array for the given string.
00783   llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E);
00784 
00785   /// Return a pointer to a constant array for the given string literal.
00786   llvm::GlobalVariable *
00787   GetAddrOfConstantStringFromLiteral(const StringLiteral *S,
00788                                      StringRef Name = ".str");
00789 
00790   /// Return a pointer to a constant array for the given ObjCEncodeExpr node.
00791   llvm::GlobalVariable *
00792   GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *);
00793 
00794   /// Returns a pointer to a character array containing the literal and a
00795   /// terminating '\0' character. The result has pointer to array type.
00796   ///
00797   /// \param GlobalName If provided, the name to use for the global (if one is
00798   /// created).
00799   llvm::GlobalVariable *
00800   GetAddrOfConstantCString(const std::string &Str,
00801                            const char *GlobalName = nullptr,
00802                            unsigned Alignment = 0);
00803 
00804   /// Returns a pointer to a constant global variable for the given file-scope
00805   /// compound literal expression.
00806   llvm::Constant *GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr*E);
00807 
00808   /// \brief Returns a pointer to a global variable representing a temporary
00809   /// with static or thread storage duration.
00810   llvm::Constant *GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E,
00811                                            const Expr *Inner);
00812 
00813   /// \brief Retrieve the record type that describes the state of an
00814   /// Objective-C fast enumeration loop (for..in).
00815   QualType getObjCFastEnumerationStateType();
00816 
00817   // Produce code for this constructor/destructor. This method doesn't try
00818   // to apply any ABI rules about which other constructors/destructors
00819   // are needed or if they are alias to each other.
00820   llvm::Function *codegenCXXStructor(const CXXMethodDecl *MD,
00821                                      StructorType Type);
00822 
00823   /// Return the address of the constructor/destructor of the given type.
00824   llvm::GlobalValue *
00825   getAddrOfCXXStructor(const CXXMethodDecl *MD, StructorType Type,
00826                        const CGFunctionInfo *FnInfo = nullptr,
00827                        llvm::FunctionType *FnType = nullptr,
00828                        bool DontDefer = false);
00829 
00830   /// Given a builtin id for a function like "__builtin_fabsf", return a
00831   /// Function* for "fabsf".
00832   llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD,
00833                                      unsigned BuiltinID);
00834 
00835   llvm::Function *getIntrinsic(unsigned IID, ArrayRef<llvm::Type*> Tys = None);
00836 
00837   /// Emit code for a single top level declaration.
00838   void EmitTopLevelDecl(Decl *D);
00839 
00840   /// \brief Stored a deferred empty coverage mapping for an unused
00841   /// and thus uninstrumented top level declaration.
00842   void AddDeferredUnusedCoverageMapping(Decl *D);
00843 
00844   /// \brief Remove the deferred empty coverage mapping as this
00845   /// declaration is actually instrumented.
00846   void ClearUnusedCoverageMapping(const Decl *D);
00847 
00848   /// \brief Emit all the deferred coverage mappings
00849   /// for the uninstrumented functions.
00850   void EmitDeferredUnusedCoverageMappings();
00851 
00852   /// Tell the consumer that this variable has been instantiated.
00853   void HandleCXXStaticMemberVarInstantiation(VarDecl *VD);
00854 
00855   /// \brief If the declaration has internal linkage but is inside an
00856   /// extern "C" linkage specification, prepare to emit an alias for it
00857   /// to the expected name.
00858   template<typename SomeDecl>
00859   void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
00860 
00861   /// Add a global to a list to be added to the llvm.used metadata.
00862   void addUsedGlobal(llvm::GlobalValue *GV);
00863 
00864   /// Add a global to a list to be added to the llvm.compiler.used metadata.
00865   void addCompilerUsedGlobal(llvm::GlobalValue *GV);
00866 
00867   /// Add a destructor and object to add to the C++ global destructor function.
00868   void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) {
00869     CXXGlobalDtors.push_back(std::make_pair(DtorFn, Object));
00870   }
00871 
00872   /// Create a new runtime function with the specified type and name.
00873   llvm::Constant *CreateRuntimeFunction(llvm::FunctionType *Ty,
00874                                         StringRef Name,
00875                                         llvm::AttributeSet ExtraAttrs =
00876                                           llvm::AttributeSet());
00877   /// Create a new runtime global variable with the specified type and name.
00878   llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty,
00879                                         StringRef Name);
00880 
00881   ///@name Custom Blocks Runtime Interfaces
00882   ///@{
00883 
00884   llvm::Constant *getNSConcreteGlobalBlock();
00885   llvm::Constant *getNSConcreteStackBlock();
00886   llvm::Constant *getBlockObjectAssign();
00887   llvm::Constant *getBlockObjectDispose();
00888 
00889   ///@}
00890 
00891   llvm::Constant *getLLVMLifetimeStartFn();
00892   llvm::Constant *getLLVMLifetimeEndFn();
00893 
00894   // Make sure that this type is translated.
00895   void UpdateCompletedType(const TagDecl *TD);
00896 
00897   llvm::Constant *getMemberPointerConstant(const UnaryOperator *e);
00898 
00899   /// Try to emit the initializer for the given declaration as a constant;
00900   /// returns 0 if the expression cannot be emitted as a constant.
00901   llvm::Constant *EmitConstantInit(const VarDecl &D,
00902                                    CodeGenFunction *CGF = nullptr);
00903 
00904   /// Try to emit the given expression as a constant; returns 0 if the
00905   /// expression cannot be emitted as a constant.
00906   llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType,
00907                                    CodeGenFunction *CGF = nullptr);
00908 
00909   /// Emit the given constant value as a constant, in the type's scalar
00910   /// representation.
00911   llvm::Constant *EmitConstantValue(const APValue &Value, QualType DestType,
00912                                     CodeGenFunction *CGF = nullptr);
00913 
00914   /// Emit the given constant value as a constant, in the type's memory
00915   /// representation.
00916   llvm::Constant *EmitConstantValueForMemory(const APValue &Value,
00917                                              QualType DestType,
00918                                              CodeGenFunction *CGF = nullptr);
00919 
00920   /// Return the result of value-initializing the given type, i.e. a null
00921   /// expression of the given type.  This is usually, but not always, an LLVM
00922   /// null constant.
00923   llvm::Constant *EmitNullConstant(QualType T);
00924 
00925   /// Return a null constant appropriate for zero-initializing a base class with
00926   /// the given type. This is usually, but not always, an LLVM null constant.
00927   llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record);
00928 
00929   /// Emit a general error that something can't be done.
00930   void Error(SourceLocation loc, StringRef error);
00931 
00932   /// Print out an error that codegen doesn't support the specified stmt yet.
00933   void ErrorUnsupported(const Stmt *S, const char *Type);
00934 
00935   /// Print out an error that codegen doesn't support the specified decl yet.
00936   void ErrorUnsupported(const Decl *D, const char *Type);
00937 
00938   /// Set the attributes on the LLVM function for the given decl and function
00939   /// info. This applies attributes necessary for handling the ABI as well as
00940   /// user specified attributes like section.
00941   void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F,
00942                                      const CGFunctionInfo &FI);
00943 
00944   /// Set the LLVM function attributes (sext, zext, etc).
00945   void SetLLVMFunctionAttributes(const Decl *D,
00946                                  const CGFunctionInfo &Info,
00947                                  llvm::Function *F);
00948 
00949   /// Set the LLVM function attributes which only apply to a function
00950   /// definition.
00951   void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F);
00952 
00953   /// Return true iff the given type uses 'sret' when used as a return type.
00954   bool ReturnTypeUsesSRet(const CGFunctionInfo &FI);
00955 
00956   /// Return true iff the given type uses an argument slot when 'sret' is used
00957   /// as a return type.
00958   bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI);
00959 
00960   /// Return true iff the given type uses 'fpret' when used as a return type.
00961   bool ReturnTypeUsesFPRet(QualType ResultType);
00962 
00963   /// Return true iff the given type uses 'fp2ret' when used as a return type.
00964   bool ReturnTypeUsesFP2Ret(QualType ResultType);
00965 
00966   /// Get the LLVM attributes and calling convention to use for a particular
00967   /// function type.
00968   ///
00969   /// \param Info - The function type information.
00970   /// \param TargetDecl - The decl these attributes are being constructed
00971   /// for. If supplied the attributes applied to this decl may contribute to the
00972   /// function attributes and calling convention.
00973   /// \param PAL [out] - On return, the attribute list to use.
00974   /// \param CallingConv [out] - On return, the LLVM calling convention to use.
00975   void ConstructAttributeList(const CGFunctionInfo &Info,
00976                               const Decl *TargetDecl,
00977                               AttributeListType &PAL,
00978                               unsigned &CallingConv,
00979                               bool AttrOnCallSite);
00980 
00981   StringRef getMangledName(GlobalDecl GD);
00982   StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD);
00983 
00984   void EmitTentativeDefinition(const VarDecl *D);
00985 
00986   void EmitVTable(CXXRecordDecl *Class, bool DefinitionRequired);
00987 
00988   /// Emit the RTTI descriptors for the builtin types.
00989   void EmitFundamentalRTTIDescriptors();
00990 
00991   /// \brief Appends Opts to the "Linker Options" metadata value.
00992   void AppendLinkerOptions(StringRef Opts);
00993 
00994   /// \brief Appends a detect mismatch command to the linker options.
00995   void AddDetectMismatch(StringRef Name, StringRef Value);
00996 
00997   /// \brief Appends a dependent lib to the "Linker Options" metadata value.
00998   void AddDependentLib(StringRef Lib);
00999 
01000   llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD);
01001 
01002   void setFunctionLinkage(GlobalDecl GD, llvm::Function *F) {
01003     F->setLinkage(getFunctionLinkage(GD));
01004   }
01005 
01006   /// Return the appropriate linkage for the vtable, VTT, and type information
01007   /// of the given class.
01008   llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD);
01009 
01010   /// Return the store size, in character units, of the given LLVM type.
01011   CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const;
01012   
01013   /// Returns LLVM linkage for a declarator.
01014   llvm::GlobalValue::LinkageTypes
01015   getLLVMLinkageForDeclarator(const DeclaratorDecl *D, GVALinkage Linkage,
01016                               bool IsConstantVariable);
01017 
01018   /// Returns LLVM linkage for a declarator.
01019   llvm::GlobalValue::LinkageTypes
01020   getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant);
01021 
01022   /// Emit all the global annotations.
01023   void EmitGlobalAnnotations();
01024 
01025   /// Emit an annotation string.
01026   llvm::Constant *EmitAnnotationString(StringRef Str);
01027 
01028   /// Emit the annotation's translation unit.
01029   llvm::Constant *EmitAnnotationUnit(SourceLocation Loc);
01030 
01031   /// Emit the annotation line number.
01032   llvm::Constant *EmitAnnotationLineNo(SourceLocation L);
01033 
01034   /// Generate the llvm::ConstantStruct which contains the annotation
01035   /// information for a given GlobalValue. The annotation struct is
01036   /// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the
01037   /// GlobalValue being annotated. The second field is the constant string
01038   /// created from the AnnotateAttr's annotation. The third field is a constant
01039   /// string containing the name of the translation unit. The fourth field is
01040   /// the line number in the file of the annotated value declaration.
01041   llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
01042                                    const AnnotateAttr *AA,
01043                                    SourceLocation L);
01044 
01045   /// Add global annotations that are set on D, for the global GV. Those
01046   /// annotations are emitted during finalization of the LLVM code.
01047   void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
01048 
01049   bool isInSanitizerBlacklist(llvm::Function *Fn, SourceLocation Loc) const;
01050 
01051   bool isInSanitizerBlacklist(llvm::GlobalVariable *GV, SourceLocation Loc,
01052                               QualType Ty,
01053                               StringRef Category = StringRef()) const;
01054 
01055   SanitizerMetadata *getSanitizerMetadata() {
01056     return SanitizerMD.get();
01057   }
01058 
01059   void addDeferredVTable(const CXXRecordDecl *RD) {
01060     DeferredVTables.push_back(RD);
01061   }
01062 
01063   /// Emit code for a singal global function or var decl. Forward declarations
01064   /// are emitted lazily.
01065   void EmitGlobal(GlobalDecl D);
01066 
01067   bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target,
01068                                 bool InEveryTU);
01069   bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D);
01070 
01071   /// Set attributes for a global definition.
01072   void setFunctionDefinitionAttributes(const FunctionDecl *D,
01073                                        llvm::Function *F);
01074 
01075   llvm::GlobalValue *GetGlobalValue(StringRef Ref);
01076 
01077   /// Set attributes which are common to any form of a global definition (alias,
01078   /// Objective-C method, function, global variable).
01079   ///
01080   /// NOTE: This should only be called for definitions.
01081   void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV);
01082 
01083   /// Set attributes which must be preserved by an alias. This includes common
01084   /// attributes (i.e. it includes a call to SetCommonAttributes).
01085   ///
01086   /// NOTE: This should only be called for definitions.
01087   void setAliasAttributes(const Decl *D, llvm::GlobalValue *GV);
01088 
01089   void addReplacement(StringRef Name, llvm::Constant *C);
01090 
01091   /// \brief Emit a code for threadprivate directive.
01092   /// \param D Threadprivate declaration.
01093   void EmitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D);
01094 
01095 private:
01096   llvm::Constant *
01097   GetOrCreateLLVMFunction(StringRef MangledName, llvm::Type *Ty, GlobalDecl D,
01098                           bool ForVTable, bool DontDefer = false,
01099                           bool IsThunk = false,
01100                           llvm::AttributeSet ExtraAttrs = llvm::AttributeSet());
01101 
01102   llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName,
01103                                         llvm::PointerType *PTy,
01104                                         const VarDecl *D);
01105 
01106   void setNonAliasAttributes(const Decl *D, llvm::GlobalObject *GO);
01107 
01108   /// Set function attributes for a function declaration.
01109   void SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
01110                              bool IsIncompleteFunction, bool IsThunk);
01111 
01112   void EmitGlobalDefinition(GlobalDecl D, llvm::GlobalValue *GV = nullptr);
01113 
01114   void EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);
01115   void EmitGlobalVarDefinition(const VarDecl *D);
01116   void EmitAliasDefinition(GlobalDecl GD);
01117   void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
01118   void EmitObjCIvarInitializations(ObjCImplementationDecl *D);
01119   
01120   // C++ related functions.
01121 
01122   void EmitNamespace(const NamespaceDecl *D);
01123   void EmitLinkageSpec(const LinkageSpecDecl *D);
01124   void CompleteDIClassType(const CXXMethodDecl* D);
01125 
01126   /// \brief Emit the function that initializes C++ thread_local variables.
01127   void EmitCXXThreadLocalInitFunc();
01128 
01129   /// Emit the function that initializes C++ globals.
01130   void EmitCXXGlobalInitFunc();
01131 
01132   /// Emit the function that destroys C++ globals.
01133   void EmitCXXGlobalDtorFunc();
01134 
01135   /// Emit the function that initializes the specified global (if PerformInit is
01136   /// true) and registers its destructor.
01137   void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
01138                                     llvm::GlobalVariable *Addr,
01139                                     bool PerformInit);
01140 
01141   void EmitPointerToInitFunc(const VarDecl *VD, llvm::GlobalVariable *Addr,
01142                              llvm::Function *InitFunc, InitSegAttr *ISA);
01143 
01144   // FIXME: Hardcoding priority here is gross.
01145   void AddGlobalCtor(llvm::Function *Ctor, int Priority = 65535,
01146                      llvm::Constant *AssociatedData = 0);
01147   void AddGlobalDtor(llvm::Function *Dtor, int Priority = 65535);
01148 
01149   /// Generates a global array of functions and priorities using the given list
01150   /// and name. This array will have appending linkage and is suitable for use
01151   /// as a LLVM constructor or destructor array.
01152   void EmitCtorList(const CtorList &Fns, const char *GlobalName);
01153 
01154   /// Emit the RTTI descriptors for the given type.
01155   void EmitFundamentalRTTIDescriptor(QualType Type);
01156 
01157   /// Emit any needed decls for which code generation was deferred.
01158   void EmitDeferred();
01159 
01160   /// Call replaceAllUsesWith on all pairs in Replacements.
01161   void applyReplacements();
01162 
01163   void checkAliases();
01164 
01165   /// Emit any vtables which we deferred and still have a use for.
01166   void EmitDeferredVTables();
01167 
01168   /// Emit the llvm.used and llvm.compiler.used metadata.
01169   void emitLLVMUsed();
01170 
01171   /// \brief Emit the link options introduced by imported modules.
01172   void EmitModuleLinkOptions();
01173 
01174   /// \brief Emit aliases for internal-linkage declarations inside "C" language
01175   /// linkage specifications, giving them the "expected" name where possible.
01176   void EmitStaticExternCAliases();
01177 
01178   void EmitDeclMetadata();
01179 
01180   /// \brief Emit the Clang version as llvm.ident metadata.
01181   void EmitVersionIdentMetadata();
01182 
01183   /// Emits target specific Metadata for global declarations.
01184   void EmitTargetMetadata();
01185 
01186   /// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and
01187   /// .gcda files in a way that persists in .bc files.
01188   void EmitCoverageFile();
01189 
01190   /// Emits the initializer for a uuidof string.
01191   llvm::Constant *EmitUuidofInitializer(StringRef uuidstr);
01192 
01193   /// Determine if the given decl can be emitted lazily; this is only relevant
01194   /// for definitions. The given decl must be either a function or var decl.
01195   bool MayDeferGeneration(const ValueDecl *D);
01196 
01197   /// Check whether we can use a "simpler", more core exceptions personality
01198   /// function.
01199   void SimplifyPersonality();
01200 };
01201 }  // end namespace CodeGen
01202 }  // end namespace clang
01203 
01204 #endif