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