1193326Sed//===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===// 2193326Sed// 3193326Sed// The LLVM Compiler Infrastructure 4193326Sed// 5193326Sed// This file is distributed under the University of Illinois Open Source 6193326Sed// License. See LICENSE.TXT for details. 7193326Sed// 8193326Sed//===----------------------------------------------------------------------===// 9193326Sed// 10193326Sed// This is the internal per-translation-unit state used for llvm translation. 11193326Sed// 12193326Sed//===----------------------------------------------------------------------===// 13193326Sed 14193326Sed#ifndef CLANG_CODEGEN_CODEGENMODULE_H 15193326Sed#define CLANG_CODEGEN_CODEGENMODULE_H 16193326Sed 17249423Sdim#include "CGVTables.h" 18249423Sdim#include "CodeGenTypes.h" 19193326Sed#include "clang/AST/Attr.h" 20193326Sed#include "clang/AST/DeclCXX.h" 21198092Srdivacky#include "clang/AST/DeclObjC.h" 22224145Sdim#include "clang/AST/GlobalDecl.h" 23218893Sdim#include "clang/AST/Mangle.h" 24249423Sdim#include "clang/Basic/ABI.h" 25249423Sdim#include "clang/Basic/LangOptions.h" 26249423Sdim#include "clang/Basic/Module.h" 27193326Sed#include "llvm/ADT/DenseMap.h" 28249423Sdim#include "llvm/ADT/SetVector.h" 29249423Sdim#include "llvm/ADT/SmallPtrSet.h" 30193326Sed#include "llvm/ADT/StringMap.h" 31249423Sdim#include "llvm/IR/CallingConv.h" 32249423Sdim#include "llvm/IR/Module.h" 33193326Sed#include "llvm/Support/ValueHandle.h" 34263508Sdim#include "llvm/Transforms/Utils/SpecialCaseList.h" 35193326Sed 36193326Sednamespace llvm { 37193326Sed class Module; 38193326Sed class Constant; 39224145Sdim class ConstantInt; 40193326Sed class Function; 41193326Sed class GlobalValue; 42243830Sdim class DataLayout; 43193326Sed class FunctionType; 44198092Srdivacky class LLVMContext; 45193326Sed} 46193326Sed 47193326Sednamespace clang { 48202379Srdivacky class TargetCodeGenInfo; 49193326Sed class ASTContext; 50249423Sdim class AtomicType; 51193326Sed class FunctionDecl; 52193326Sed class IdentifierInfo; 53193326Sed class ObjCMethodDecl; 54193326Sed class ObjCImplementationDecl; 55193326Sed class ObjCCategoryImplDecl; 56193326Sed class ObjCProtocolDecl; 57193326Sed class ObjCEncodeExpr; 58193326Sed class BlockExpr; 59203955Srdivacky class CharUnits; 60193326Sed class Decl; 61193326Sed class Expr; 62193326Sed class Stmt; 63234353Sdim class InitListExpr; 64193326Sed class StringLiteral; 65193326Sed class NamedDecl; 66193326Sed class ValueDecl; 67193326Sed class VarDecl; 68193326Sed class LangOptions; 69199482Srdivacky class CodeGenOptions; 70226633Sdim class DiagnosticsEngine; 71193326Sed class AnnotateAttr; 72193326Sed class CXXDestructorDecl; 73218893Sdim class MangleBuffer; 74249423Sdim class Module; 75193326Sed 76193326Sednamespace CodeGen { 77193326Sed 78221345Sdim class CallArgList; 79193326Sed class CodeGenFunction; 80218893Sdim class CodeGenTBAA; 81212904Sdim class CGCXXABI; 82193326Sed class CGDebugInfo; 83193326Sed class CGObjCRuntime; 84226633Sdim class CGOpenCLRuntime; 85226633Sdim class CGCUDARuntime; 86218893Sdim class BlockFieldFlags; 87221345Sdim class FunctionArgList; 88193326Sed 89210299Sed struct OrderGlobalInits { 90210299Sed unsigned int priority; 91210299Sed unsigned int lex_order; 92210299Sed OrderGlobalInits(unsigned int p, unsigned int l) 93210299Sed : priority(p), lex_order(l) {} 94210299Sed 95210299Sed bool operator==(const OrderGlobalInits &RHS) const { 96210299Sed return priority == RHS.priority && 97210299Sed lex_order == RHS.lex_order; 98210299Sed } 99210299Sed 100210299Sed bool operator<(const OrderGlobalInits &RHS) const { 101210299Sed if (priority < RHS.priority) 102210299Sed return true; 103210299Sed 104210299Sed return priority == RHS.priority && lex_order < RHS.lex_order; 105210299Sed } 106210299Sed }; 107218893Sdim 108218893Sdim struct CodeGenTypeCache { 109223017Sdim /// void 110224145Sdim llvm::Type *VoidTy; 111223017Sdim 112234353Sdim /// i8, i16, i32, and i64 113234353Sdim llvm::IntegerType *Int8Ty, *Int16Ty, *Int32Ty, *Int64Ty; 114234353Sdim /// float, double 115234353Sdim llvm::Type *FloatTy, *DoubleTy; 116218893Sdim 117218893Sdim /// int 118224145Sdim llvm::IntegerType *IntTy; 119218893Sdim 120223017Sdim /// intptr_t, size_t, and ptrdiff_t, which we assume are the same size. 121218893Sdim union { 122224145Sdim llvm::IntegerType *IntPtrTy; 123224145Sdim llvm::IntegerType *SizeTy; 124224145Sdim llvm::IntegerType *PtrDiffTy; 125218893Sdim }; 126218893Sdim 127218893Sdim /// void* in address space 0 128218893Sdim union { 129224145Sdim llvm::PointerType *VoidPtrTy; 130224145Sdim llvm::PointerType *Int8PtrTy; 131218893Sdim }; 132218893Sdim 133218893Sdim /// void** in address space 0 134218893Sdim union { 135224145Sdim llvm::PointerType *VoidPtrPtrTy; 136224145Sdim llvm::PointerType *Int8PtrPtrTy; 137218893Sdim }; 138218893Sdim 139219077Sdim /// The width of a pointer into the generic address space. 140218893Sdim unsigned char PointerWidthInBits; 141219077Sdim 142226633Sdim /// The size and alignment of a pointer into the generic address 143226633Sdim /// space. 144226633Sdim union { 145226633Sdim unsigned char PointerAlignInBytes; 146226633Sdim unsigned char PointerSizeInBytes; 147239462Sdim unsigned char SizeSizeInBytes; // sizeof(size_t) 148226633Sdim }; 149249423Sdim 150249423Sdim llvm::CallingConv::ID RuntimeCC; 151249423Sdim llvm::CallingConv::ID getRuntimeCC() const { 152249423Sdim return RuntimeCC; 153249423Sdim } 154218893Sdim }; 155224145Sdim 156224145Sdimstruct RREntrypoints { 157224145Sdim RREntrypoints() { memset(this, 0, sizeof(*this)); } 158224145Sdim /// void objc_autoreleasePoolPop(void*); 159224145Sdim llvm::Constant *objc_autoreleasePoolPop; 160224145Sdim 161224145Sdim /// void *objc_autoreleasePoolPush(void); 162224145Sdim llvm::Constant *objc_autoreleasePoolPush; 163224145Sdim}; 164224145Sdim 165224145Sdimstruct ARCEntrypoints { 166224145Sdim ARCEntrypoints() { memset(this, 0, sizeof(*this)); } 167224145Sdim 168224145Sdim /// id objc_autorelease(id); 169224145Sdim llvm::Constant *objc_autorelease; 170224145Sdim 171224145Sdim /// id objc_autoreleaseReturnValue(id); 172224145Sdim llvm::Constant *objc_autoreleaseReturnValue; 173224145Sdim 174224145Sdim /// void objc_copyWeak(id *dest, id *src); 175224145Sdim llvm::Constant *objc_copyWeak; 176224145Sdim 177224145Sdim /// void objc_destroyWeak(id*); 178224145Sdim llvm::Constant *objc_destroyWeak; 179224145Sdim 180224145Sdim /// id objc_initWeak(id*, id); 181224145Sdim llvm::Constant *objc_initWeak; 182224145Sdim 183224145Sdim /// id objc_loadWeak(id*); 184224145Sdim llvm::Constant *objc_loadWeak; 185224145Sdim 186224145Sdim /// id objc_loadWeakRetained(id*); 187224145Sdim llvm::Constant *objc_loadWeakRetained; 188224145Sdim 189224145Sdim /// void objc_moveWeak(id *dest, id *src); 190224145Sdim llvm::Constant *objc_moveWeak; 191224145Sdim 192224145Sdim /// id objc_retain(id); 193224145Sdim llvm::Constant *objc_retain; 194224145Sdim 195224145Sdim /// id objc_retainAutorelease(id); 196224145Sdim llvm::Constant *objc_retainAutorelease; 197224145Sdim 198224145Sdim /// id objc_retainAutoreleaseReturnValue(id); 199224145Sdim llvm::Constant *objc_retainAutoreleaseReturnValue; 200224145Sdim 201224145Sdim /// id objc_retainAutoreleasedReturnValue(id); 202224145Sdim llvm::Constant *objc_retainAutoreleasedReturnValue; 203224145Sdim 204224145Sdim /// id objc_retainBlock(id); 205224145Sdim llvm::Constant *objc_retainBlock; 206224145Sdim 207224145Sdim /// void objc_release(id); 208224145Sdim llvm::Constant *objc_release; 209224145Sdim 210224145Sdim /// id objc_storeStrong(id*, id); 211224145Sdim llvm::Constant *objc_storeStrong; 212224145Sdim 213224145Sdim /// id objc_storeWeak(id*, id); 214224145Sdim llvm::Constant *objc_storeWeak; 215224145Sdim 216224145Sdim /// A void(void) inline asm to use to mark that the return value of 217224145Sdim /// a call will be immediately retain. 218224145Sdim llvm::InlineAsm *retainAutoreleasedReturnValueMarker; 219249423Sdim 220249423Sdim /// void clang.arc.use(...); 221249423Sdim llvm::Constant *clang_arc_use; 222224145Sdim}; 223249423Sdim 224193326Sed/// CodeGenModule - This class organizes the cross-function state that is used 225193326Sed/// while generating LLVM code. 226218893Sdimclass CodeGenModule : public CodeGenTypeCache { 227243830Sdim CodeGenModule(const CodeGenModule &) LLVM_DELETED_FUNCTION; 228243830Sdim void operator=(const CodeGenModule &) LLVM_DELETED_FUNCTION; 229193326Sed 230198092Srdivacky typedef std::vector<std::pair<llvm::Constant*, int> > CtorList; 231193326Sed 232193326Sed ASTContext &Context; 233234353Sdim const LangOptions &LangOpts; 234199482Srdivacky const CodeGenOptions &CodeGenOpts; 235193326Sed llvm::Module &TheModule; 236251662Sdim DiagnosticsEngine &Diags; 237243830Sdim const llvm::DataLayout &TheDataLayout; 238251662Sdim const TargetInfo &Target; 239251662Sdim CGCXXABI &ABI; 240251662Sdim llvm::LLVMContext &VMContext; 241251662Sdim 242251662Sdim CodeGenTBAA *TBAA; 243251662Sdim 244202379Srdivacky mutable const TargetCodeGenInfo *TheTargetCodeGenInfo; 245251662Sdim 246251662Sdim // This should not be moved earlier, since its initialization depends on some 247251662Sdim // of the previous reference members being already initialized and also checks 248251662Sdim // if TheTargetCodeGenInfo is NULL 249193326Sed CodeGenTypes Types; 250251662Sdim 251206084Srdivacky /// VTables - Holds information about C++ vtables. 252206084Srdivacky CodeGenVTables VTables; 253207619Srdivacky 254226633Sdim CGObjCRuntime* ObjCRuntime; 255226633Sdim CGOpenCLRuntime* OpenCLRuntime; 256226633Sdim CGCUDARuntime* CUDARuntime; 257193326Sed CGDebugInfo* DebugInfo; 258224145Sdim ARCEntrypoints *ARCData; 259234353Sdim llvm::MDNode *NoObjCARCExceptionsMetadata; 260224145Sdim RREntrypoints *RRData; 261193326Sed 262204793Srdivacky // WeakRefReferences - A set of references that have only been seen via 263251662Sdim // a weakref so far. This is used to remove the weak of the reference if we 264251662Sdim // ever see a direct reference or a definition. 265204793Srdivacky llvm::SmallPtrSet<llvm::GlobalValue*, 10> WeakRefReferences; 266204793Srdivacky 267193326Sed /// DeferredDecls - This contains all the decls which have definitions but 268193326Sed /// which are deferred for emission and therefore should only be output if 269193326Sed /// they are actually used. If a decl is in this, then it is known to have 270205408Srdivacky /// not been referenced yet. 271205408Srdivacky llvm::StringMap<GlobalDecl> DeferredDecls; 272193326Sed 273193326Sed /// DeferredDeclsToEmit - This is a list of deferred decls which we have seen 274193326Sed /// that *are* actually referenced. These get code generated when the module 275193326Sed /// is done. 276193326Sed std::vector<GlobalDecl> DeferredDeclsToEmit; 277193326Sed 278263508Sdim /// List of alias we have emitted. Used to make sure that what they point to 279263508Sdim /// is defined once we get to the end of the of the translation unit. 280263508Sdim std::vector<GlobalDecl> Aliases; 281263508Sdim 282263508Sdim typedef llvm::StringMap<llvm::TrackingVH<llvm::Constant> > ReplacementsTy; 283263508Sdim ReplacementsTy Replacements; 284263508Sdim 285249423Sdim /// DeferredVTables - A queue of (optional) vtables to consider emitting. 286249423Sdim std::vector<const CXXRecordDecl*> DeferredVTables; 287249423Sdim 288193326Sed /// LLVMUsed - List of global values which are required to be 289193326Sed /// present in the object file; bitcast to i8*. This is used for 290193326Sed /// forcing visibility of symbols which may otherwise be optimized 291193326Sed /// out. 292193326Sed std::vector<llvm::WeakVH> LLVMUsed; 293193326Sed 294193326Sed /// GlobalCtors - Store the list of global constructors and their respective 295193326Sed /// priorities to be emitted when the translation unit is complete. 296193326Sed CtorList GlobalCtors; 297193326Sed 298193326Sed /// GlobalDtors - Store the list of global destructors and their respective 299193326Sed /// priorities to be emitted when the translation unit is complete. 300193326Sed CtorList GlobalDtors; 301193326Sed 302210299Sed /// MangledDeclNames - A map of canonical GlobalDecls to their mangled names. 303226633Sdim llvm::DenseMap<GlobalDecl, StringRef> MangledDeclNames; 304210299Sed llvm::BumpPtrAllocator MangledNamesAllocator; 305210299Sed 306226633Sdim /// Global annotations. 307193326Sed std::vector<llvm::Constant*> Annotations; 308193326Sed 309226633Sdim /// Map used to get unique annotation strings. 310226633Sdim llvm::StringMap<llvm::Constant*> AnnotationStrings; 311226633Sdim 312193326Sed llvm::StringMap<llvm::Constant*> CFConstantStringMap; 313226633Sdim llvm::StringMap<llvm::GlobalVariable*> ConstantStringMap; 314234353Sdim llvm::DenseMap<const Decl*, llvm::Constant *> StaticLocalDeclMap; 315234353Sdim llvm::DenseMap<const Decl*, llvm::GlobalVariable*> StaticLocalDeclGuardMap; 316263508Sdim llvm::DenseMap<const Expr*, llvm::Constant *> MaterializedGlobalTemporaryMap; 317263508Sdim 318234353Sdim llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap; 319234353Sdim llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap; 320193326Sed 321263508Sdim /// Map used to get unique type descriptor constants for sanitizers. 322263508Sdim llvm::DenseMap<QualType, llvm::Constant *> TypeDescriptorMap; 323263508Sdim 324251662Sdim /// Map used to track internal linkage functions declared within 325251662Sdim /// extern "C" regions. 326251662Sdim typedef llvm::MapVector<IdentifierInfo *, 327251662Sdim llvm::GlobalValue *> StaticExternCMap; 328251662Sdim StaticExternCMap StaticExternCValues; 329251662Sdim 330251662Sdim /// \brief thread_local variables defined or used in this TU. 331251662Sdim std::vector<std::pair<const VarDecl *, llvm::GlobalVariable *> > 332251662Sdim CXXThreadLocals; 333251662Sdim 334251662Sdim /// \brief thread_local variables with initializers that need to run 335251662Sdim /// before any thread_local variable in this TU is odr-used. 336251662Sdim std::vector<llvm::Constant*> CXXThreadLocalInits; 337251662Sdim 338205408Srdivacky /// CXXGlobalInits - Global variables with initializers that need to run 339198092Srdivacky /// before main. 340202379Srdivacky std::vector<llvm::Constant*> CXXGlobalInits; 341212904Sdim 342212904Sdim /// When a C++ decl with an initializer is deferred, null is 343212904Sdim /// appended to CXXGlobalInits, and the index of that null is placed 344212904Sdim /// here so that the initializer will be performed in the correct 345212904Sdim /// order. 346212904Sdim llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition; 347210299Sed 348243830Sdim typedef std::pair<OrderGlobalInits, llvm::Function*> GlobalInitData; 349243830Sdim 350243830Sdim struct GlobalInitPriorityCmp { 351243830Sdim bool operator()(const GlobalInitData &LHS, 352243830Sdim const GlobalInitData &RHS) const { 353243830Sdim return LHS.first.priority < RHS.first.priority; 354243830Sdim } 355243830Sdim }; 356243830Sdim 357210299Sed /// - Global variables with initializers whose order of initialization 358210299Sed /// is set by init_priority attribute. 359243830Sdim SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits; 360198092Srdivacky 361205408Srdivacky /// CXXGlobalDtors - Global destructor functions and arguments that need to 362205408Srdivacky /// run on termination. 363210299Sed std::vector<std::pair<llvm::WeakVH,llvm::Constant*> > CXXGlobalDtors; 364205408Srdivacky 365249423Sdim /// \brief The complete set of modules that has been imported. 366249423Sdim llvm::SetVector<clang::Module *> ImportedModules; 367249423Sdim 368263508Sdim /// \brief A vector of metadata strings. 369263508Sdim SmallVector<llvm::Value *, 16> LinkerOptionsMetadata; 370263508Sdim 371226633Sdim /// @name Cache for Objective-C runtime types 372226633Sdim /// @{ 373226633Sdim 374193326Sed /// CFConstantStringClassRef - Cached reference to the class for constant 375193326Sed /// strings. This value has type int * but is actually an Obj-C class pointer. 376251662Sdim llvm::WeakVH CFConstantStringClassRef; 377198092Srdivacky 378218893Sdim /// ConstantStringClassRef - Cached reference to the class for constant 379207619Srdivacky /// strings. This value has type int * but is actually an Obj-C class pointer. 380251662Sdim llvm::WeakVH ConstantStringClassRef; 381207619Srdivacky 382226633Sdim /// \brief The LLVM type corresponding to NSConstantString. 383226633Sdim llvm::StructType *NSConstantStringType; 384226633Sdim 385226633Sdim /// \brief The type used to describe the state of a fast enumeration in 386226633Sdim /// Objective-C's for..in loop. 387226633Sdim QualType ObjCFastEnumerationStateType; 388226633Sdim 389226633Sdim /// @} 390226633Sdim 391202879Srdivacky /// Lazily create the Objective-C runtime 392202879Srdivacky void createObjCRuntime(); 393202879Srdivacky 394226633Sdim void createOpenCLRuntime(); 395226633Sdim void createCUDARuntime(); 396226633Sdim 397234353Sdim bool isTriviallyRecursive(const FunctionDecl *F); 398263508Sdim bool shouldEmitFunction(GlobalDecl GD); 399212904Sdim 400212904Sdim /// @name Cache for Blocks Runtime Globals 401212904Sdim /// @{ 402212904Sdim 403212904Sdim llvm::Constant *NSConcreteGlobalBlock; 404212904Sdim llvm::Constant *NSConcreteStackBlock; 405212904Sdim 406212904Sdim llvm::Constant *BlockObjectAssign; 407212904Sdim llvm::Constant *BlockObjectDispose; 408212904Sdim 409224145Sdim llvm::Type *BlockDescriptorType; 410224145Sdim llvm::Type *GenericBlockLiteralType; 411218893Sdim 412218893Sdim struct { 413218893Sdim int GlobalUniqueCount; 414218893Sdim } Block; 415249423Sdim 416249423Sdim /// void @llvm.lifetime.start(i64 %size, i8* nocapture <ptr>) 417249423Sdim llvm::Constant *LifetimeStartFn; 418249423Sdim 419249423Sdim /// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>) 420249423Sdim llvm::Constant *LifetimeEndFn; 421249423Sdim 422239462Sdim GlobalDecl initializedGlobalDecl; 423218893Sdim 424263508Sdim llvm::OwningPtr<llvm::SpecialCaseList> SanitizerBlacklist; 425249423Sdim 426249423Sdim const SanitizerOptions &SanOpts; 427249423Sdim 428212904Sdim /// @} 429193326Sedpublic: 430199482Srdivacky CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts, 431251662Sdim llvm::Module &M, const llvm::DataLayout &TD, 432251662Sdim DiagnosticsEngine &Diags); 433193326Sed 434193326Sed ~CodeGenModule(); 435193326Sed 436193326Sed /// Release - Finalize LLVM code generation. 437193326Sed void Release(); 438193326Sed 439193326Sed /// getObjCRuntime() - Return a reference to the configured 440193326Sed /// Objective-C runtime. 441193326Sed CGObjCRuntime &getObjCRuntime() { 442226633Sdim if (!ObjCRuntime) createObjCRuntime(); 443226633Sdim return *ObjCRuntime; 444193326Sed } 445193326Sed 446193326Sed /// hasObjCRuntime() - Return true iff an Objective-C runtime has 447193326Sed /// been configured. 448226633Sdim bool hasObjCRuntime() { return !!ObjCRuntime; } 449193326Sed 450226633Sdim /// getOpenCLRuntime() - Return a reference to the configured OpenCL runtime. 451226633Sdim CGOpenCLRuntime &getOpenCLRuntime() { 452226633Sdim assert(OpenCLRuntime != 0); 453226633Sdim return *OpenCLRuntime; 454226633Sdim } 455226633Sdim 456226633Sdim /// getCUDARuntime() - Return a reference to the configured CUDA runtime. 457226633Sdim CGCUDARuntime &getCUDARuntime() { 458226633Sdim assert(CUDARuntime != 0); 459226633Sdim return *CUDARuntime; 460226633Sdim } 461226633Sdim 462224145Sdim ARCEntrypoints &getARCEntrypoints() const { 463234353Sdim assert(getLangOpts().ObjCAutoRefCount && ARCData != 0); 464224145Sdim return *ARCData; 465224145Sdim } 466224145Sdim 467224145Sdim RREntrypoints &getRREntrypoints() const { 468224145Sdim assert(RRData != 0); 469224145Sdim return *RRData; 470224145Sdim } 471224145Sdim 472234353Sdim llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) { 473234353Sdim return StaticLocalDeclMap[D]; 474207619Srdivacky } 475207619Srdivacky void setStaticLocalDeclAddress(const VarDecl *D, 476234353Sdim llvm::Constant *C) { 477234353Sdim StaticLocalDeclMap[D] = C; 478207619Srdivacky } 479207619Srdivacky 480234353Sdim llvm::GlobalVariable *getStaticLocalDeclGuardAddress(const VarDecl *D) { 481234353Sdim return StaticLocalDeclGuardMap[D]; 482234353Sdim } 483234353Sdim void setStaticLocalDeclGuardAddress(const VarDecl *D, 484234353Sdim llvm::GlobalVariable *C) { 485234353Sdim StaticLocalDeclGuardMap[D] = C; 486234353Sdim } 487234353Sdim 488234353Sdim llvm::Constant *getAtomicSetterHelperFnMap(QualType Ty) { 489234353Sdim return AtomicSetterHelperFnMap[Ty]; 490234353Sdim } 491234353Sdim void setAtomicSetterHelperFnMap(QualType Ty, 492234353Sdim llvm::Constant *Fn) { 493234353Sdim AtomicSetterHelperFnMap[Ty] = Fn; 494234353Sdim } 495234353Sdim 496234353Sdim llvm::Constant *getAtomicGetterHelperFnMap(QualType Ty) { 497234353Sdim return AtomicGetterHelperFnMap[Ty]; 498234353Sdim } 499234353Sdim void setAtomicGetterHelperFnMap(QualType Ty, 500234353Sdim llvm::Constant *Fn) { 501234353Sdim AtomicGetterHelperFnMap[Ty] = Fn; 502234353Sdim } 503234353Sdim 504263508Sdim llvm::Constant *getTypeDescriptor(QualType Ty) { 505263508Sdim return TypeDescriptorMap[Ty]; 506263508Sdim } 507263508Sdim void setTypeDescriptor(QualType Ty, llvm::Constant *C) { 508263508Sdim TypeDescriptorMap[Ty] = C; 509263508Sdim } 510263508Sdim 511221345Sdim CGDebugInfo *getModuleDebugInfo() { return DebugInfo; } 512221345Sdim 513234353Sdim llvm::MDNode *getNoObjCARCExceptionsMetadata() { 514234353Sdim if (!NoObjCARCExceptionsMetadata) 515234353Sdim NoObjCARCExceptionsMetadata = 516234353Sdim llvm::MDNode::get(getLLVMContext(), 517234353Sdim SmallVector<llvm::Value*,1>()); 518234353Sdim return NoObjCARCExceptionsMetadata; 519234353Sdim } 520234353Sdim 521193326Sed ASTContext &getContext() const { return Context; } 522251662Sdim const LangOptions &getLangOpts() const { return LangOpts; } 523199482Srdivacky const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; } 524193326Sed llvm::Module &getModule() const { return TheModule; } 525226633Sdim DiagnosticsEngine &getDiags() const { return Diags; } 526243830Sdim const llvm::DataLayout &getDataLayout() const { return TheDataLayout; } 527251662Sdim const TargetInfo &getTarget() const { return Target; } 528251662Sdim CGCXXABI &getCXXABI() { return ABI; } 529198092Srdivacky llvm::LLVMContext &getLLVMContext() { return VMContext; } 530251662Sdim 531219077Sdim bool shouldUseTBAA() const { return TBAA != 0; } 532219077Sdim 533251662Sdim const TargetCodeGenInfo &getTargetCodeGenInfo(); 534251662Sdim 535251662Sdim CodeGenTypes &getTypes() { return Types; } 536251662Sdim 537251662Sdim CodeGenVTables &getVTables() { return VTables; } 538251662Sdim 539263508Sdim ItaniumVTableContext &getItaniumVTableContext() { 540263508Sdim return VTables.getItaniumVTableContext(); 541263508Sdim } 542263508Sdim 543263508Sdim MicrosoftVTableContext &getMicrosoftVTableContext() { 544263508Sdim return VTables.getMicrosoftVTableContext(); 545263508Sdim } 546263508Sdim 547218893Sdim llvm::MDNode *getTBAAInfo(QualType QTy); 548234353Sdim llvm::MDNode *getTBAAInfoForVTablePtr(); 549243830Sdim llvm::MDNode *getTBAAStructInfo(QualType QTy); 550249423Sdim /// Return the MDNode in the type DAG for the given struct type. 551249423Sdim llvm::MDNode *getTBAAStructTypeInfo(QualType QTy); 552249423Sdim /// Return the path-aware tag for given base type, access node and offset. 553249423Sdim llvm::MDNode *getTBAAStructTagInfo(QualType BaseTy, llvm::MDNode *AccessN, 554249423Sdim uint64_t O); 555193326Sed 556234353Sdim bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor); 557234353Sdim 558249423Sdim bool isPaddedAtomicType(QualType type); 559249423Sdim bool isPaddedAtomicType(const AtomicType *type); 560249423Sdim 561251662Sdim /// Decorate the instruction with a TBAA tag. For scalar TBAA, the tag 562251662Sdim /// is the same as the type. For struct-path aware TBAA, the tag 563251662Sdim /// is different from the type: base type, access type and offset. 564251662Sdim /// When ConvertTypeToTag is true, we create a tag based on the scalar type. 565251662Sdim void DecorateInstruction(llvm::Instruction *Inst, 566251662Sdim llvm::MDNode *TBAAInfo, 567251662Sdim bool ConvertTypeToTag = true); 568218893Sdim 569224145Sdim /// getSize - Emit the given number of characters as a value of type size_t. 570224145Sdim llvm::ConstantInt *getSize(CharUnits numChars); 571224145Sdim 572193326Sed /// setGlobalVisibility - Set the visibility for the given LLVM 573193326Sed /// GlobalValue. 574218893Sdim void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const; 575193326Sed 576239462Sdim /// setTLSMode - Set the TLS mode for the given LLVM GlobalVariable 577239462Sdim /// for the thread-local variable declaration D. 578239462Sdim void setTLSMode(llvm::GlobalVariable *GV, const VarDecl &D) const; 579239462Sdim 580218893Sdim /// TypeVisibilityKind - The kind of global variable that is passed to 581218893Sdim /// setTypeVisibility 582218893Sdim enum TypeVisibilityKind { 583218893Sdim TVK_ForVTT, 584218893Sdim TVK_ForVTable, 585221345Sdim TVK_ForConstructionVTable, 586218893Sdim TVK_ForRTTI, 587218893Sdim TVK_ForRTTIName 588218893Sdim }; 589218893Sdim 590212904Sdim /// setTypeVisibility - Set the visibility for the given global 591212904Sdim /// value which holds information about a type. 592212904Sdim void setTypeVisibility(llvm::GlobalValue *GV, const CXXRecordDecl *D, 593218893Sdim TypeVisibilityKind TVK) const; 594212904Sdim 595218893Sdim static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) { 596218893Sdim switch (V) { 597218893Sdim case DefaultVisibility: return llvm::GlobalValue::DefaultVisibility; 598218893Sdim case HiddenVisibility: return llvm::GlobalValue::HiddenVisibility; 599218893Sdim case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility; 600218893Sdim } 601218893Sdim llvm_unreachable("unknown visibility!"); 602218893Sdim } 603218893Sdim 604204643Srdivacky llvm::Constant *GetAddrOfGlobal(GlobalDecl GD) { 605204643Srdivacky if (isa<CXXConstructorDecl>(GD.getDecl())) 606204643Srdivacky return GetAddrOfCXXConstructor(cast<CXXConstructorDecl>(GD.getDecl()), 607204643Srdivacky GD.getCtorType()); 608204643Srdivacky else if (isa<CXXDestructorDecl>(GD.getDecl())) 609204643Srdivacky return GetAddrOfCXXDestructor(cast<CXXDestructorDecl>(GD.getDecl()), 610204643Srdivacky GD.getDtorType()); 611204643Srdivacky else if (isa<FunctionDecl>(GD.getDecl())) 612204643Srdivacky return GetAddrOfFunction(GD); 613204643Srdivacky else 614204643Srdivacky return GetAddrOfGlobalVar(cast<VarDecl>(GD.getDecl())); 615204643Srdivacky } 616204643Srdivacky 617251662Sdim /// CreateOrReplaceCXXRuntimeVariable - Will return a global variable of the 618251662Sdim /// given type. If a variable with a different type already exists then a new 619218893Sdim /// variable with the right type will be created and all uses of the old 620218893Sdim /// variable will be replaced with a bitcast to the new variable. 621218893Sdim llvm::GlobalVariable * 622226633Sdim CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty, 623218893Sdim llvm::GlobalValue::LinkageTypes Linkage); 624218893Sdim 625239462Sdim /// GetGlobalVarAddressSpace - Return the address space of the underlying 626239462Sdim /// global variable for D, as determined by its declaration. Normally this 627239462Sdim /// is the same as the address space of D's type, but in CUDA, address spaces 628239462Sdim /// are associated with declarations, not types. 629239462Sdim unsigned GetGlobalVarAddressSpace(const VarDecl *D, unsigned AddrSpace); 630239462Sdim 631193326Sed /// GetAddrOfGlobalVar - Return the llvm::Constant for the address of the 632193326Sed /// given global variable. If Ty is non-null and if the global doesn't exist, 633193326Sed /// then it will be greated with the specified type instead of whatever the 634193326Sed /// normal requested type would be. 635193326Sed llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D, 636226633Sdim llvm::Type *Ty = 0); 637193326Sed 638221345Sdim 639193326Sed /// GetAddrOfFunction - Return the address of the given function. If Ty is 640193326Sed /// non-null, then this function will use the specified type if it has to 641193326Sed /// create it. 642193326Sed llvm::Constant *GetAddrOfFunction(GlobalDecl GD, 643226633Sdim llvm::Type *Ty = 0, 644218893Sdim bool ForVTable = false); 645193326Sed 646201361Srdivacky /// GetAddrOfRTTIDescriptor - Get the address of the RTTI descriptor 647201361Srdivacky /// for the given type. 648207619Srdivacky llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false); 649199482Srdivacky 650243830Sdim /// GetAddrOfUuidDescriptor - Get the address of a uuid descriptor . 651243830Sdim llvm::Constant *GetAddrOfUuidDescriptor(const CXXUuidofExpr* E); 652243830Sdim 653206084Srdivacky /// GetAddrOfThunk - Get the address of the thunk for the given global decl. 654206084Srdivacky llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk); 655198092Srdivacky 656204793Srdivacky /// GetWeakRefReference - Get a reference to the target of VD. 657204793Srdivacky llvm::Constant *GetWeakRefReference(const ValueDecl *VD); 658204793Srdivacky 659203955Srdivacky /// GetNonVirtualBaseClassOffset - Returns the offset from a derived class to 660207619Srdivacky /// a class. Returns null if the offset is 0. 661203955Srdivacky llvm::Constant * 662203955Srdivacky GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl, 663212904Sdim CastExpr::path_const_iterator PathBegin, 664212904Sdim CastExpr::path_const_iterator PathEnd); 665218893Sdim 666221345Sdim /// A pair of helper functions for a __block variable. 667221345Sdim class ByrefHelpers : public llvm::FoldingSetNode { 668221345Sdim public: 669221345Sdim llvm::Constant *CopyHelper; 670221345Sdim llvm::Constant *DisposeHelper; 671218893Sdim 672221345Sdim /// The alignment of the field. This is important because 673221345Sdim /// different offsets to the field within the byref struct need to 674221345Sdim /// have different helper functions. 675221345Sdim CharUnits Alignment; 676221345Sdim 677221345Sdim ByrefHelpers(CharUnits alignment) : Alignment(alignment) {} 678221345Sdim virtual ~ByrefHelpers(); 679221345Sdim 680221345Sdim void Profile(llvm::FoldingSetNodeID &id) const { 681221345Sdim id.AddInteger(Alignment.getQuantity()); 682221345Sdim profileImpl(id); 683221345Sdim } 684221345Sdim virtual void profileImpl(llvm::FoldingSetNodeID &id) const = 0; 685221345Sdim 686221345Sdim virtual bool needsCopy() const { return true; } 687221345Sdim virtual void emitCopy(CodeGenFunction &CGF, 688221345Sdim llvm::Value *dest, llvm::Value *src) = 0; 689221345Sdim 690221345Sdim virtual bool needsDispose() const { return true; } 691221345Sdim virtual void emitDispose(CodeGenFunction &CGF, llvm::Value *field) = 0; 692221345Sdim }; 693221345Sdim 694221345Sdim llvm::FoldingSet<ByrefHelpers> ByrefHelpersCache; 695221345Sdim 696219077Sdim /// getUniqueBlockCount - Fetches the global unique block count. 697219077Sdim int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; } 698239462Sdim 699218893Sdim /// getBlockDescriptorType - Fetches the type of a generic block 700218893Sdim /// descriptor. 701224145Sdim llvm::Type *getBlockDescriptorType(); 702218893Sdim 703218893Sdim /// getGenericBlockLiteralType - The type of a generic block literal. 704224145Sdim llvm::Type *getGenericBlockLiteralType(); 705218893Sdim 706218893Sdim /// GetAddrOfGlobalBlock - Gets the address of a block which 707218893Sdim /// requires no captures. 708218893Sdim llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, const char *); 709207619Srdivacky 710193326Sed /// GetAddrOfConstantCFString - Return a pointer to a constant CFString object 711193326Sed /// for the given string. 712193326Sed llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal); 713207619Srdivacky 714218893Sdim /// GetAddrOfConstantString - Return a pointer to a constant NSString object 715218893Sdim /// for the given string. Or a user defined String object as defined via 716218893Sdim /// -fconstant-string-class=class_name option. 717218893Sdim llvm::Constant *GetAddrOfConstantString(const StringLiteral *Literal); 718193326Sed 719234353Sdim /// GetConstantArrayFromStringLiteral - Return a constant array for the given 720234353Sdim /// string. 721234353Sdim llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E); 722234353Sdim 723193326Sed /// GetAddrOfConstantStringFromLiteral - Return a pointer to a constant array 724193326Sed /// for the given string literal. 725193326Sed llvm::Constant *GetAddrOfConstantStringFromLiteral(const StringLiteral *S); 726193326Sed 727193326Sed /// GetAddrOfConstantStringFromObjCEncode - Return a pointer to a constant 728193326Sed /// array for the given ObjCEncodeExpr node. 729193326Sed llvm::Constant *GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *); 730198092Srdivacky 731193326Sed /// GetAddrOfConstantString - Returns a pointer to a character array 732193326Sed /// containing the literal. This contents are exactly that of the given 733193326Sed /// string, i.e. it will not be null terminated automatically; see 734193326Sed /// GetAddrOfConstantCString. Note that whether the result is actually a 735193326Sed /// pointer to an LLVM constant depends on Feature.WriteableStrings. 736193326Sed /// 737193326Sed /// The result has pointer to array type. 738193326Sed /// 739193326Sed /// \param GlobalName If provided, the name to use for the global 740193326Sed /// (if one is created). 741226633Sdim llvm::Constant *GetAddrOfConstantString(StringRef Str, 742226633Sdim const char *GlobalName=0, 743251662Sdim unsigned Alignment=0); 744193326Sed 745193326Sed /// GetAddrOfConstantCString - Returns a pointer to a character array 746193326Sed /// containing the literal and a terminating '\0' character. The result has 747193326Sed /// pointer to array type. 748193326Sed /// 749193326Sed /// \param GlobalName If provided, the name to use for the global (if one is 750193326Sed /// created). 751193326Sed llvm::Constant *GetAddrOfConstantCString(const std::string &str, 752226633Sdim const char *GlobalName=0, 753251662Sdim unsigned Alignment=0); 754234353Sdim 755234353Sdim /// GetAddrOfConstantCompoundLiteral - Returns a pointer to a constant global 756234353Sdim /// variable for the given file-scope compound literal expression. 757234353Sdim llvm::Constant *GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr*E); 758263508Sdim 759263508Sdim /// \brief Returns a pointer to a global variable representing a temporary 760263508Sdim /// with static or thread storage duration. 761263508Sdim llvm::Constant *GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E, 762263508Sdim const Expr *Inner); 763263508Sdim 764226633Sdim /// \brief Retrieve the record type that describes the state of an 765226633Sdim /// Objective-C fast enumeration loop (for..in). 766226633Sdim QualType getObjCFastEnumerationStateType(); 767226633Sdim 768193326Sed /// GetAddrOfCXXConstructor - Return the address of the constructor of the 769193326Sed /// given type. 770221345Sdim llvm::GlobalValue *GetAddrOfCXXConstructor(const CXXConstructorDecl *ctor, 771221345Sdim CXXCtorType ctorType, 772221345Sdim const CGFunctionInfo *fnInfo = 0); 773193326Sed 774193326Sed /// GetAddrOfCXXDestructor - Return the address of the constructor of the 775193326Sed /// given type. 776221345Sdim llvm::GlobalValue *GetAddrOfCXXDestructor(const CXXDestructorDecl *dtor, 777221345Sdim CXXDtorType dtorType, 778263508Sdim const CGFunctionInfo *fnInfo = 0, 779263508Sdim llvm::FunctionType *fnType = 0); 780198092Srdivacky 781193326Sed /// getBuiltinLibFunction - Given a builtin id for a function like 782193326Sed /// "__builtin_fabsf", return a Function* for "fabsf". 783198092Srdivacky llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD, 784198092Srdivacky unsigned BuiltinID); 785193326Sed 786251662Sdim llvm::Function *getIntrinsic(unsigned IID, ArrayRef<llvm::Type*> Tys = None); 787193326Sed 788193326Sed /// EmitTopLevelDecl - Emit code for a single top level declaration. 789193326Sed void EmitTopLevelDecl(Decl *D); 790193326Sed 791234353Sdim /// HandleCXXStaticMemberVarInstantiation - Tell the consumer that this 792234353Sdim // variable has been instantiated. 793234353Sdim void HandleCXXStaticMemberVarInstantiation(VarDecl *VD); 794234353Sdim 795251662Sdim /// \brief If the declaration has internal linkage but is inside an 796251662Sdim /// extern "C" linkage specification, prepare to emit an alias for it 797251662Sdim /// to the expected name. 798251662Sdim template<typename SomeDecl> 799251662Sdim void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV); 800251662Sdim 801193326Sed /// AddUsedGlobal - Add a global which should be forced to be 802193326Sed /// present in the object file; these are emitted to the llvm.used 803193326Sed /// metadata global. 804193326Sed void AddUsedGlobal(llvm::GlobalValue *GV); 805193326Sed 806205408Srdivacky /// AddCXXDtorEntry - Add a destructor and object to add to the C++ global 807205408Srdivacky /// destructor function. 808210299Sed void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) { 809210299Sed CXXGlobalDtors.push_back(std::make_pair(DtorFn, Object)); 810210299Sed } 811205408Srdivacky 812193326Sed /// CreateRuntimeFunction - Create a new runtime function with the specified 813193326Sed /// type and name. 814226633Sdim llvm::Constant *CreateRuntimeFunction(llvm::FunctionType *Ty, 815226633Sdim StringRef Name, 816249423Sdim llvm::AttributeSet ExtraAttrs = 817249423Sdim llvm::AttributeSet()); 818193326Sed /// CreateRuntimeVariable - Create a new runtime global variable with the 819193326Sed /// specified type and name. 820226633Sdim llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty, 821226633Sdim StringRef Name); 822193326Sed 823212904Sdim ///@name Custom Blocks Runtime Interfaces 824212904Sdim ///@{ 825212904Sdim 826212904Sdim llvm::Constant *getNSConcreteGlobalBlock(); 827212904Sdim llvm::Constant *getNSConcreteStackBlock(); 828212904Sdim llvm::Constant *getBlockObjectAssign(); 829212904Sdim llvm::Constant *getBlockObjectDispose(); 830212904Sdim 831212904Sdim ///@} 832212904Sdim 833249423Sdim llvm::Constant *getLLVMLifetimeStartFn(); 834249423Sdim llvm::Constant *getLLVMLifetimeEndFn(); 835249423Sdim 836221345Sdim // UpdateCompleteType - Make sure that this type is translated. 837221345Sdim void UpdateCompletedType(const TagDecl *TD); 838193326Sed 839218893Sdim llvm::Constant *getMemberPointerConstant(const UnaryOperator *e); 840218893Sdim 841234353Sdim /// EmitConstantInit - Try to emit the initializer for the given declaration 842234353Sdim /// as a constant; returns 0 if the expression cannot be emitted as a 843234353Sdim /// constant. 844234353Sdim llvm::Constant *EmitConstantInit(const VarDecl &D, CodeGenFunction *CGF = 0); 845234353Sdim 846193326Sed /// EmitConstantExpr - Try to emit the given expression as a 847193326Sed /// constant; returns 0 if the expression cannot be emitted as a 848193326Sed /// constant. 849193326Sed llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType, 850193326Sed CodeGenFunction *CGF = 0); 851193326Sed 852234353Sdim /// EmitConstantValue - Emit the given constant value as a constant, in the 853234353Sdim /// type's scalar representation. 854234353Sdim llvm::Constant *EmitConstantValue(const APValue &Value, QualType DestType, 855234353Sdim CodeGenFunction *CGF = 0); 856234353Sdim 857234353Sdim /// EmitConstantValueForMemory - Emit the given constant value as a constant, 858234353Sdim /// in the type's memory representation. 859234353Sdim llvm::Constant *EmitConstantValueForMemory(const APValue &Value, 860234353Sdim QualType DestType, 861234353Sdim CodeGenFunction *CGF = 0); 862234353Sdim 863193326Sed /// EmitNullConstant - Return the result of value-initializing the given 864193326Sed /// type, i.e. a null expression of the given type. This is usually, 865193326Sed /// but not always, an LLVM null constant. 866193326Sed llvm::Constant *EmitNullConstant(QualType T); 867193326Sed 868226633Sdim /// EmitNullConstantForBase - Return a null constant appropriate for 869226633Sdim /// zero-initializing a base class with the given type. This is usually, 870226633Sdim /// but not always, an LLVM null constant. 871226633Sdim llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record); 872193326Sed 873221345Sdim /// Error - Emit a general error that something can't be done. 874226633Sdim void Error(SourceLocation loc, StringRef error); 875221345Sdim 876193326Sed /// ErrorUnsupported - Print out an error that codegen doesn't support the 877193326Sed /// specified stmt yet. 878263508Sdim void ErrorUnsupported(const Stmt *S, const char *Type); 879193326Sed 880193326Sed /// ErrorUnsupported - Print out an error that codegen doesn't support the 881193326Sed /// specified decl yet. 882263508Sdim void ErrorUnsupported(const Decl *D, const char *Type); 883193326Sed 884193326Sed /// SetInternalFunctionAttributes - Set the attributes on the LLVM 885193326Sed /// function for the given decl and function info. This applies 886193326Sed /// attributes necessary for handling the ABI as well as user 887193326Sed /// specified attributes like section. 888193326Sed void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F, 889193326Sed const CGFunctionInfo &FI); 890193326Sed 891193326Sed /// SetLLVMFunctionAttributes - Set the LLVM function attributes 892193326Sed /// (sext, zext, etc). 893193326Sed void SetLLVMFunctionAttributes(const Decl *D, 894193326Sed const CGFunctionInfo &Info, 895193326Sed llvm::Function *F); 896193326Sed 897193326Sed /// SetLLVMFunctionAttributesForDefinition - Set the LLVM function attributes 898193326Sed /// which only apply to a function definintion. 899193326Sed void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F); 900193326Sed 901210299Sed /// ReturnTypeUsesSRet - Return true iff the given type uses 'sret' when used 902193326Sed /// as a return type. 903210299Sed bool ReturnTypeUsesSRet(const CGFunctionInfo &FI); 904193326Sed 905234353Sdim /// ReturnTypeUsesFPRet - Return true iff the given type uses 'fpret' when 906234353Sdim /// used as a return type. 907210299Sed bool ReturnTypeUsesFPRet(QualType ResultType); 908210299Sed 909234353Sdim /// ReturnTypeUsesFP2Ret - Return true iff the given type uses 'fp2ret' when 910234353Sdim /// used as a return type. 911234353Sdim bool ReturnTypeUsesFP2Ret(QualType ResultType); 912234353Sdim 913198092Srdivacky /// ConstructAttributeList - Get the LLVM attributes and calling convention to 914198092Srdivacky /// use for a particular function type. 915198092Srdivacky /// 916198092Srdivacky /// \param Info - The function type information. 917198092Srdivacky /// \param TargetDecl - The decl these attributes are being constructed 918198092Srdivacky /// for. If supplied the attributes applied to this decl may contribute to the 919198092Srdivacky /// function attributes and calling convention. 920198092Srdivacky /// \param PAL [out] - On return, the attribute list to use. 921198092Srdivacky /// \param CallingConv [out] - On return, the LLVM calling convention to use. 922193326Sed void ConstructAttributeList(const CGFunctionInfo &Info, 923193326Sed const Decl *TargetDecl, 924198092Srdivacky AttributeListType &PAL, 925249423Sdim unsigned &CallingConv, 926249423Sdim bool AttrOnCallSite); 927193326Sed 928226633Sdim StringRef getMangledName(GlobalDecl GD); 929218893Sdim void getBlockMangledName(GlobalDecl GD, MangleBuffer &Buffer, 930218893Sdim const BlockDecl *BD); 931193326Sed 932193326Sed void EmitTentativeDefinition(const VarDecl *D); 933198092Srdivacky 934208600Srdivacky void EmitVTable(CXXRecordDecl *Class, bool DefinitionRequired); 935208600Srdivacky 936263508Sdim /// EmitFundamentalRTTIDescriptors - Emit the RTTI descriptors for the 937263508Sdim /// builtin types. 938263508Sdim void EmitFundamentalRTTIDescriptors(); 939204643Srdivacky 940263508Sdim /// \brief Appends Opts to the "Linker Options" metadata value. 941263508Sdim void AppendLinkerOptions(StringRef Opts); 942263508Sdim 943263508Sdim /// \brief Appends a detect mismatch command to the linker options. 944263508Sdim void AddDetectMismatch(StringRef Name, StringRef Value); 945263508Sdim 946263508Sdim /// \brief Appends a dependent lib to the "Linker Options" metadata value. 947263508Sdim void AddDependentLib(StringRef Lib); 948263508Sdim 949263508Sdim llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD); 950263508Sdim 951263508Sdim void setFunctionLinkage(GlobalDecl GD, llvm::GlobalValue *V) { 952263508Sdim V->setLinkage(getFunctionLinkage(GD)); 953208600Srdivacky } 954208600Srdivacky 955207619Srdivacky /// getVTableLinkage - Return the appropriate linkage for the vtable, VTT, 956202379Srdivacky /// and type information of the given class. 957218893Sdim llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD); 958203955Srdivacky 959203955Srdivacky /// GetTargetTypeStoreSize - Return the store size, in character units, of 960203955Srdivacky /// the given LLVM type. 961226633Sdim CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const; 962218893Sdim 963218893Sdim /// GetLLVMLinkageVarDefinition - Returns LLVM linkage for a global 964218893Sdim /// variable. 965218893Sdim llvm::GlobalValue::LinkageTypes 966263508Sdim GetLLVMLinkageVarDefinition(const VarDecl *D, bool isConstant); 967218893Sdim 968226633Sdim /// Emit all the global annotations. 969226633Sdim void EmitGlobalAnnotations(); 970226633Sdim 971226633Sdim /// Emit an annotation string. 972249423Sdim llvm::Constant *EmitAnnotationString(StringRef Str); 973226633Sdim 974226633Sdim /// Emit the annotation's translation unit. 975226633Sdim llvm::Constant *EmitAnnotationUnit(SourceLocation Loc); 976226633Sdim 977226633Sdim /// Emit the annotation line number. 978226633Sdim llvm::Constant *EmitAnnotationLineNo(SourceLocation L); 979226633Sdim 980226633Sdim /// EmitAnnotateAttr - Generate the llvm::ConstantStruct which contains the 981226633Sdim /// annotation information for a given GlobalValue. The annotation struct is 982226633Sdim /// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the 983226633Sdim /// GlobalValue being annotated. The second field is the constant string 984226633Sdim /// created from the AnnotateAttr's annotation. The third field is a constant 985226633Sdim /// string containing the name of the translation unit. The fourth field is 986226633Sdim /// the line number in the file of the annotated value declaration. 987226633Sdim llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV, 988226633Sdim const AnnotateAttr *AA, 989226633Sdim SourceLocation L); 990226633Sdim 991226633Sdim /// Add global annotations that are set on D, for the global GV. Those 992226633Sdim /// annotations are emitted during finalization of the LLVM code. 993226633Sdim void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV); 994226633Sdim 995263508Sdim const llvm::SpecialCaseList &getSanitizerBlacklist() const { 996263508Sdim return *SanitizerBlacklist; 997249423Sdim } 998249423Sdim 999249423Sdim const SanitizerOptions &getSanOpts() const { return SanOpts; } 1000249423Sdim 1001249423Sdim void addDeferredVTable(const CXXRecordDecl *RD) { 1002249423Sdim DeferredVTables.push_back(RD); 1003249423Sdim } 1004249423Sdim 1005263508Sdim /// EmitGlobal - Emit code for a singal global function or var decl. Forward 1006263508Sdim /// declarations are emitted lazily. 1007263508Sdim void EmitGlobal(GlobalDecl D); 1008263508Sdim 1009193326Sedprivate: 1010226633Sdim llvm::GlobalValue *GetGlobalValue(StringRef Ref); 1011198092Srdivacky 1012226633Sdim llvm::Constant *GetOrCreateLLVMFunction(StringRef MangledName, 1013226633Sdim llvm::Type *Ty, 1014218893Sdim GlobalDecl D, 1015224145Sdim bool ForVTable, 1016249423Sdim llvm::AttributeSet ExtraAttrs = 1017249423Sdim llvm::AttributeSet()); 1018226633Sdim llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName, 1019226633Sdim llvm::PointerType *PTy, 1020218893Sdim const VarDecl *D, 1021218893Sdim bool UnnamedAddr = false); 1022198092Srdivacky 1023193326Sed /// SetCommonAttributes - Set attributes which are common to any 1024193326Sed /// form of a global definition (alias, Objective-C method, 1025193326Sed /// function, global variable). 1026193326Sed /// 1027193326Sed /// NOTE: This should only be called for definitions. 1028193326Sed void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV); 1029193326Sed 1030193326Sed /// SetFunctionDefinitionAttributes - Set attributes for a global definition. 1031198092Srdivacky void SetFunctionDefinitionAttributes(const FunctionDecl *D, 1032193326Sed llvm::GlobalValue *GV); 1033198092Srdivacky 1034193326Sed /// SetFunctionAttributes - Set function attributes for a function 1035193326Sed /// declaration. 1036203955Srdivacky void SetFunctionAttributes(GlobalDecl GD, 1037193326Sed llvm::Function *F, 1038193326Sed bool IsIncompleteFunction); 1039193326Sed 1040193326Sed void EmitGlobalDefinition(GlobalDecl D); 1041193326Sed 1042193326Sed void EmitGlobalFunctionDefinition(GlobalDecl GD); 1043193326Sed void EmitGlobalVarDefinition(const VarDecl *D); 1044205408Srdivacky void EmitAliasDefinition(GlobalDecl GD); 1045193326Sed void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D); 1046207619Srdivacky void EmitObjCIvarInitializations(ObjCImplementationDecl *D); 1047218893Sdim 1048193326Sed // C++ related functions. 1049198092Srdivacky 1050263508Sdim bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target, 1051263508Sdim bool InEveryTU); 1052204643Srdivacky bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D); 1053204643Srdivacky 1054193326Sed void EmitNamespace(const NamespaceDecl *D); 1055193326Sed void EmitLinkageSpec(const LinkageSpecDecl *D); 1056263508Sdim void CompleteDIClassType(const CXXMethodDecl* D); 1057193326Sed 1058193326Sed /// EmitCXXConstructor - Emit a single constructor with the given type from 1059193326Sed /// a C++ constructor Decl. 1060193326Sed void EmitCXXConstructor(const CXXConstructorDecl *D, CXXCtorType Type); 1061198092Srdivacky 1062193326Sed /// EmitCXXDestructor - Emit a single destructor with the given type from 1063193326Sed /// a C++ destructor Decl. 1064193326Sed void EmitCXXDestructor(const CXXDestructorDecl *D, CXXDtorType Type); 1065198092Srdivacky 1066251662Sdim /// \brief Emit the function that initializes C++ thread_local variables. 1067251662Sdim void EmitCXXThreadLocalInitFunc(); 1068251662Sdim 1069205408Srdivacky /// EmitCXXGlobalInitFunc - Emit the function that initializes C++ globals. 1070198092Srdivacky void EmitCXXGlobalInitFunc(); 1071202379Srdivacky 1072205408Srdivacky /// EmitCXXGlobalDtorFunc - Emit the function that destroys C++ globals. 1073205408Srdivacky void EmitCXXGlobalDtorFunc(); 1074205408Srdivacky 1075234353Sdim /// EmitCXXGlobalVarDeclInitFunc - Emit the function that initializes the 1076234353Sdim /// specified global (if PerformInit is true) and registers its destructor. 1077218893Sdim void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D, 1078234353Sdim llvm::GlobalVariable *Addr, 1079234353Sdim bool PerformInit); 1080202379Srdivacky 1081193326Sed // FIXME: Hardcoding priority here is gross. 1082193326Sed void AddGlobalCtor(llvm::Function *Ctor, int Priority=65535); 1083193326Sed void AddGlobalDtor(llvm::Function *Dtor, int Priority=65535); 1084193326Sed 1085193326Sed /// EmitCtorList - Generates a global array of functions and priorities using 1086193326Sed /// the given list and name. This array will have appending linkage and is 1087193326Sed /// suitable for use as a LLVM constructor or destructor array. 1088193326Sed void EmitCtorList(const CtorList &Fns, const char *GlobalName); 1089193326Sed 1090206084Srdivacky /// EmitFundamentalRTTIDescriptor - Emit the RTTI descriptors for the 1091206084Srdivacky /// given type. 1092206084Srdivacky void EmitFundamentalRTTIDescriptor(QualType Type); 1093206084Srdivacky 1094193326Sed /// EmitDeferred - Emit any needed decls for which code generation 1095193326Sed /// was deferred. 1096249423Sdim void EmitDeferred(); 1097193326Sed 1098263508Sdim /// Call replaceAllUsesWith on all pairs in Replacements. 1099263508Sdim void applyReplacements(); 1100263508Sdim 1101263508Sdim void checkAliases(); 1102263508Sdim 1103249423Sdim /// EmitDeferredVTables - Emit any vtables which we deferred and 1104249423Sdim /// still have a use for. 1105249423Sdim void EmitDeferredVTables(); 1106249423Sdim 1107193326Sed /// EmitLLVMUsed - Emit the llvm.used metadata used to force 1108193326Sed /// references to global which may otherwise be optimized out. 1109249423Sdim void EmitLLVMUsed(); 1110193326Sed 1111249423Sdim /// \brief Emit the link options introduced by imported modules. 1112249423Sdim void EmitModuleLinkOptions(); 1113249423Sdim 1114251662Sdim /// \brief Emit aliases for internal-linkage declarations inside "C" language 1115251662Sdim /// linkage specifications, giving them the "expected" name where possible. 1116251662Sdim void EmitStaticExternCAliases(); 1117251662Sdim 1118210299Sed void EmitDeclMetadata(); 1119210299Sed 1120263508Sdim /// \brief Emit the Clang version as llvm.ident metadata. 1121263508Sdim void EmitVersionIdentMetadata(); 1122263508Sdim 1123223017Sdim /// EmitCoverageFile - Emit the llvm.gcov metadata used to tell LLVM where 1124223017Sdim /// to emit the .gcno and .gcda files in a way that persists in .bc files. 1125223017Sdim void EmitCoverageFile(); 1126223017Sdim 1127243830Sdim /// Emits the initializer for a uuidof string. 1128243830Sdim llvm::Constant *EmitUuidofInitializer(StringRef uuidstr, QualType IIDType); 1129243830Sdim 1130193326Sed /// MayDeferGeneration - Determine if the given decl can be emitted 1131193326Sed /// lazily; this is only relevant for definitions. The given decl 1132193326Sed /// must be either a function or var decl. 1133193326Sed bool MayDeferGeneration(const ValueDecl *D); 1134218893Sdim 1135218893Sdim /// SimplifyPersonality - Check whether we can use a "simpler", more 1136218893Sdim /// core exceptions personality function. 1137218893Sdim void SimplifyPersonality(); 1138193326Sed}; 1139193326Sed} // end namespace CodeGen 1140193326Sed} // end namespace clang 1141193326Sed 1142193326Sed#endif 1143