1 //===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This is the internal per-translation-unit state used for llvm translation. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H 14 #define LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H 15 16 #include "CGVTables.h" 17 #include "CodeGenTypeCache.h" 18 #include "CodeGenTypes.h" 19 #include "SanitizerMetadata.h" 20 #include "clang/AST/DeclCXX.h" 21 #include "clang/AST/DeclObjC.h" 22 #include "clang/AST/DeclOpenMP.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/NoSanitizeList.h" 29 #include "clang/Basic/TargetInfo.h" 30 #include "clang/Basic/XRayLists.h" 31 #include "clang/Lex/PreprocessorOptions.h" 32 #include "llvm/ADT/DenseMap.h" 33 #include "llvm/ADT/SetVector.h" 34 #include "llvm/ADT/SmallPtrSet.h" 35 #include "llvm/ADT/StringMap.h" 36 #include "llvm/IR/Module.h" 37 #include "llvm/IR/ValueHandle.h" 38 #include "llvm/Transforms/Utils/SanitizerStats.h" 39 40 namespace llvm { 41 class Module; 42 class Constant; 43 class ConstantInt; 44 class Function; 45 class GlobalValue; 46 class DataLayout; 47 class FunctionType; 48 class LLVMContext; 49 class IndexedInstrProfReader; 50 } 51 52 namespace clang { 53 class ASTContext; 54 class AtomicType; 55 class FunctionDecl; 56 class IdentifierInfo; 57 class ObjCImplementationDecl; 58 class ObjCEncodeExpr; 59 class BlockExpr; 60 class CharUnits; 61 class Decl; 62 class Expr; 63 class Stmt; 64 class StringLiteral; 65 class NamedDecl; 66 class ValueDecl; 67 class VarDecl; 68 class LangOptions; 69 class CodeGenOptions; 70 class HeaderSearchOptions; 71 class DiagnosticsEngine; 72 class AnnotateAttr; 73 class CXXDestructorDecl; 74 class Module; 75 class CoverageSourceInfo; 76 class InitSegAttr; 77 78 namespace CodeGen { 79 80 class CodeGenFunction; 81 class CodeGenTBAA; 82 class CGCXXABI; 83 class CGDebugInfo; 84 class CGObjCRuntime; 85 class CGOpenCLRuntime; 86 class CGOpenMPRuntime; 87 class CGCUDARuntime; 88 class CoverageMappingModuleGen; 89 class TargetCodeGenInfo; 90 91 enum ForDefinition_t : bool { 92 NotForDefinition = false, 93 ForDefinition = true 94 }; 95 96 struct OrderGlobalInitsOrStermFinalizers { 97 unsigned int priority; 98 unsigned int lex_order; 99 OrderGlobalInitsOrStermFinalizers(unsigned int p, unsigned int l) 100 : priority(p), lex_order(l) {} 101 102 bool operator==(const OrderGlobalInitsOrStermFinalizers &RHS) const { 103 return priority == RHS.priority && lex_order == RHS.lex_order; 104 } 105 106 bool operator<(const OrderGlobalInitsOrStermFinalizers &RHS) const { 107 return std::tie(priority, lex_order) < 108 std::tie(RHS.priority, RHS.lex_order); 109 } 110 }; 111 112 struct ObjCEntrypoints { 113 ObjCEntrypoints() { memset(this, 0, sizeof(*this)); } 114 115 /// void objc_alloc(id); 116 llvm::FunctionCallee objc_alloc; 117 118 /// void objc_allocWithZone(id); 119 llvm::FunctionCallee objc_allocWithZone; 120 121 /// void objc_alloc_init(id); 122 llvm::FunctionCallee objc_alloc_init; 123 124 /// void objc_autoreleasePoolPop(void*); 125 llvm::FunctionCallee objc_autoreleasePoolPop; 126 127 /// void objc_autoreleasePoolPop(void*); 128 /// Note this method is used when we are using exception handling 129 llvm::FunctionCallee objc_autoreleasePoolPopInvoke; 130 131 /// void *objc_autoreleasePoolPush(void); 132 llvm::Function *objc_autoreleasePoolPush; 133 134 /// id objc_autorelease(id); 135 llvm::Function *objc_autorelease; 136 137 /// id objc_autorelease(id); 138 /// Note this is the runtime method not the intrinsic. 139 llvm::FunctionCallee objc_autoreleaseRuntimeFunction; 140 141 /// id objc_autoreleaseReturnValue(id); 142 llvm::Function *objc_autoreleaseReturnValue; 143 144 /// void objc_copyWeak(id *dest, id *src); 145 llvm::Function *objc_copyWeak; 146 147 /// void objc_destroyWeak(id*); 148 llvm::Function *objc_destroyWeak; 149 150 /// id objc_initWeak(id*, id); 151 llvm::Function *objc_initWeak; 152 153 /// id objc_loadWeak(id*); 154 llvm::Function *objc_loadWeak; 155 156 /// id objc_loadWeakRetained(id*); 157 llvm::Function *objc_loadWeakRetained; 158 159 /// void objc_moveWeak(id *dest, id *src); 160 llvm::Function *objc_moveWeak; 161 162 /// id objc_retain(id); 163 llvm::Function *objc_retain; 164 165 /// id objc_retain(id); 166 /// Note this is the runtime method not the intrinsic. 167 llvm::FunctionCallee objc_retainRuntimeFunction; 168 169 /// id objc_retainAutorelease(id); 170 llvm::Function *objc_retainAutorelease; 171 172 /// id objc_retainAutoreleaseReturnValue(id); 173 llvm::Function *objc_retainAutoreleaseReturnValue; 174 175 /// id objc_retainAutoreleasedReturnValue(id); 176 llvm::Function *objc_retainAutoreleasedReturnValue; 177 178 /// id objc_retainBlock(id); 179 llvm::Function *objc_retainBlock; 180 181 /// void objc_release(id); 182 llvm::Function *objc_release; 183 184 /// void objc_release(id); 185 /// Note this is the runtime method not the intrinsic. 186 llvm::FunctionCallee objc_releaseRuntimeFunction; 187 188 /// void objc_storeStrong(id*, id); 189 llvm::Function *objc_storeStrong; 190 191 /// id objc_storeWeak(id*, id); 192 llvm::Function *objc_storeWeak; 193 194 /// id objc_unsafeClaimAutoreleasedReturnValue(id); 195 llvm::Function *objc_unsafeClaimAutoreleasedReturnValue; 196 197 /// A void(void) inline asm to use to mark that the return value of 198 /// a call will be immediately retain. 199 llvm::InlineAsm *retainAutoreleasedReturnValueMarker; 200 201 /// void clang.arc.use(...); 202 llvm::Function *clang_arc_use; 203 204 /// void clang.arc.noop.use(...); 205 llvm::Function *clang_arc_noop_use; 206 }; 207 208 /// This class records statistics on instrumentation based profiling. 209 class InstrProfStats { 210 uint32_t VisitedInMainFile; 211 uint32_t MissingInMainFile; 212 uint32_t Visited; 213 uint32_t Missing; 214 uint32_t Mismatched; 215 216 public: 217 InstrProfStats() 218 : VisitedInMainFile(0), MissingInMainFile(0), Visited(0), Missing(0), 219 Mismatched(0) {} 220 /// Record that we've visited a function and whether or not that function was 221 /// in the main source file. 222 void addVisited(bool MainFile) { 223 if (MainFile) 224 ++VisitedInMainFile; 225 ++Visited; 226 } 227 /// Record that a function we've visited has no profile data. 228 void addMissing(bool MainFile) { 229 if (MainFile) 230 ++MissingInMainFile; 231 ++Missing; 232 } 233 /// Record that a function we've visited has mismatched profile data. 234 void addMismatched(bool MainFile) { ++Mismatched; } 235 /// Whether or not the stats we've gathered indicate any potential problems. 236 bool hasDiagnostics() { return Missing || Mismatched; } 237 /// Report potential problems we've found to \c Diags. 238 void reportDiagnostics(DiagnosticsEngine &Diags, StringRef MainFile); 239 }; 240 241 /// A pair of helper functions for a __block variable. 242 class BlockByrefHelpers : public llvm::FoldingSetNode { 243 // MSVC requires this type to be complete in order to process this 244 // header. 245 public: 246 llvm::Constant *CopyHelper; 247 llvm::Constant *DisposeHelper; 248 249 /// The alignment of the field. This is important because 250 /// different offsets to the field within the byref struct need to 251 /// have different helper functions. 252 CharUnits Alignment; 253 254 BlockByrefHelpers(CharUnits alignment) 255 : CopyHelper(nullptr), DisposeHelper(nullptr), Alignment(alignment) {} 256 BlockByrefHelpers(const BlockByrefHelpers &) = default; 257 virtual ~BlockByrefHelpers(); 258 259 void Profile(llvm::FoldingSetNodeID &id) const { 260 id.AddInteger(Alignment.getQuantity()); 261 profileImpl(id); 262 } 263 virtual void profileImpl(llvm::FoldingSetNodeID &id) const = 0; 264 265 virtual bool needsCopy() const { return true; } 266 virtual void emitCopy(CodeGenFunction &CGF, Address dest, Address src) = 0; 267 268 virtual bool needsDispose() const { return true; } 269 virtual void emitDispose(CodeGenFunction &CGF, Address field) = 0; 270 }; 271 272 /// This class organizes the cross-function state that is used while generating 273 /// LLVM code. 274 class CodeGenModule : public CodeGenTypeCache { 275 CodeGenModule(const CodeGenModule &) = delete; 276 void operator=(const CodeGenModule &) = delete; 277 278 public: 279 struct Structor { 280 Structor() : Priority(0), Initializer(nullptr), AssociatedData(nullptr) {} 281 Structor(int Priority, llvm::Constant *Initializer, 282 llvm::Constant *AssociatedData) 283 : Priority(Priority), Initializer(Initializer), 284 AssociatedData(AssociatedData) {} 285 int Priority; 286 llvm::Constant *Initializer; 287 llvm::Constant *AssociatedData; 288 }; 289 290 typedef std::vector<Structor> CtorList; 291 292 private: 293 ASTContext &Context; 294 const LangOptions &LangOpts; 295 const HeaderSearchOptions &HeaderSearchOpts; // Only used for debug info. 296 const PreprocessorOptions &PreprocessorOpts; // Only used for debug info. 297 const CodeGenOptions &CodeGenOpts; 298 unsigned NumAutoVarInit = 0; 299 llvm::Module &TheModule; 300 DiagnosticsEngine &Diags; 301 const TargetInfo &Target; 302 std::unique_ptr<CGCXXABI> ABI; 303 llvm::LLVMContext &VMContext; 304 std::string ModuleNameHash; 305 306 std::unique_ptr<CodeGenTBAA> TBAA; 307 308 mutable std::unique_ptr<TargetCodeGenInfo> TheTargetCodeGenInfo; 309 310 // This should not be moved earlier, since its initialization depends on some 311 // of the previous reference members being already initialized and also checks 312 // if TheTargetCodeGenInfo is NULL 313 CodeGenTypes Types; 314 315 /// Holds information about C++ vtables. 316 CodeGenVTables VTables; 317 318 std::unique_ptr<CGObjCRuntime> ObjCRuntime; 319 std::unique_ptr<CGOpenCLRuntime> OpenCLRuntime; 320 std::unique_ptr<CGOpenMPRuntime> OpenMPRuntime; 321 std::unique_ptr<CGCUDARuntime> CUDARuntime; 322 std::unique_ptr<CGDebugInfo> DebugInfo; 323 std::unique_ptr<ObjCEntrypoints> ObjCData; 324 llvm::MDNode *NoObjCARCExceptionsMetadata = nullptr; 325 std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader; 326 InstrProfStats PGOStats; 327 std::unique_ptr<llvm::SanitizerStatReport> SanStats; 328 329 // A set of references that have only been seen via a weakref so far. This is 330 // used to remove the weak of the reference if we ever see a direct reference 331 // or a definition. 332 llvm::SmallPtrSet<llvm::GlobalValue*, 10> WeakRefReferences; 333 334 /// This contains all the decls which have definitions but/ which are deferred 335 /// for emission and therefore should only be output if they are actually 336 /// used. If a decl is in this, then it is known to have not been referenced 337 /// yet. 338 llvm::DenseMap<StringRef, GlobalDecl> DeferredDecls; 339 340 /// This is a list of deferred decls which we have seen that *are* actually 341 /// referenced. These get code generated when the module is done. 342 std::vector<GlobalDecl> DeferredDeclsToEmit; 343 void addDeferredDeclToEmit(GlobalDecl GD) { 344 DeferredDeclsToEmit.emplace_back(GD); 345 } 346 347 /// List of alias we have emitted. Used to make sure that what they point to 348 /// is defined once we get to the end of the of the translation unit. 349 std::vector<GlobalDecl> Aliases; 350 351 /// List of multiversion functions to be emitted. This list is processed in 352 /// conjunction with other deferred symbols and is used to ensure that 353 /// multiversion function resolvers and ifuncs are defined and emitted. 354 std::vector<GlobalDecl> MultiVersionFuncs; 355 356 typedef llvm::StringMap<llvm::TrackingVH<llvm::Constant> > ReplacementsTy; 357 ReplacementsTy Replacements; 358 359 /// List of global values to be replaced with something else. Used when we 360 /// want to replace a GlobalValue but can't identify it by its mangled name 361 /// anymore (because the name is already taken). 362 llvm::SmallVector<std::pair<llvm::GlobalValue *, llvm::Constant *>, 8> 363 GlobalValReplacements; 364 365 /// Variables for which we've emitted globals containing their constant 366 /// values along with the corresponding globals, for opportunistic reuse. 367 llvm::DenseMap<const VarDecl*, llvm::GlobalVariable*> InitializerConstants; 368 369 /// Set of global decls for which we already diagnosed mangled name conflict. 370 /// Required to not issue a warning (on a mangling conflict) multiple times 371 /// for the same decl. 372 llvm::DenseSet<GlobalDecl> DiagnosedConflictingDefinitions; 373 374 /// A queue of (optional) vtables to consider emitting. 375 std::vector<const CXXRecordDecl*> DeferredVTables; 376 377 /// A queue of (optional) vtables that may be emitted opportunistically. 378 std::vector<const CXXRecordDecl *> OpportunisticVTables; 379 380 /// List of global values which are required to be present in the object file; 381 /// bitcast to i8*. This is used for forcing visibility of symbols which may 382 /// otherwise be optimized out. 383 std::vector<llvm::WeakTrackingVH> LLVMUsed; 384 std::vector<llvm::WeakTrackingVH> LLVMCompilerUsed; 385 386 /// Store the list of global constructors and their respective priorities to 387 /// be emitted when the translation unit is complete. 388 CtorList GlobalCtors; 389 390 /// Store the list of global destructors and their respective priorities to be 391 /// emitted when the translation unit is complete. 392 CtorList GlobalDtors; 393 394 /// An ordered map of canonical GlobalDecls to their mangled names. 395 llvm::MapVector<GlobalDecl, StringRef> MangledDeclNames; 396 llvm::StringMap<GlobalDecl, llvm::BumpPtrAllocator> Manglings; 397 398 /// Global annotations. 399 std::vector<llvm::Constant*> Annotations; 400 401 /// Map used to get unique annotation strings. 402 llvm::StringMap<llvm::Constant*> AnnotationStrings; 403 404 /// Used for uniquing of annotation arguments. 405 llvm::DenseMap<unsigned, llvm::Constant *> AnnotationArgs; 406 407 llvm::StringMap<llvm::GlobalVariable *> CFConstantStringMap; 408 409 llvm::DenseMap<llvm::Constant *, llvm::GlobalVariable *> ConstantStringMap; 410 llvm::DenseMap<const UnnamedGlobalConstantDecl *, llvm::GlobalVariable *> 411 UnnamedGlobalConstantDeclMap; 412 llvm::DenseMap<const Decl*, llvm::Constant *> StaticLocalDeclMap; 413 llvm::DenseMap<const Decl*, llvm::GlobalVariable*> StaticLocalDeclGuardMap; 414 llvm::DenseMap<const Expr*, llvm::Constant *> MaterializedGlobalTemporaryMap; 415 416 llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap; 417 llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap; 418 419 /// Map used to get unique type descriptor constants for sanitizers. 420 llvm::DenseMap<QualType, llvm::Constant *> TypeDescriptorMap; 421 422 /// Map used to track internal linkage functions declared within 423 /// extern "C" regions. 424 typedef llvm::MapVector<IdentifierInfo *, 425 llvm::GlobalValue *> StaticExternCMap; 426 StaticExternCMap StaticExternCValues; 427 428 /// thread_local variables defined or used in this TU. 429 std::vector<const VarDecl *> CXXThreadLocals; 430 431 /// thread_local variables with initializers that need to run 432 /// before any thread_local variable in this TU is odr-used. 433 std::vector<llvm::Function *> CXXThreadLocalInits; 434 std::vector<const VarDecl *> CXXThreadLocalInitVars; 435 436 /// Global variables with initializers that need to run before main. 437 std::vector<llvm::Function *> CXXGlobalInits; 438 439 /// When a C++ decl with an initializer is deferred, null is 440 /// appended to CXXGlobalInits, and the index of that null is placed 441 /// here so that the initializer will be performed in the correct 442 /// order. Once the decl is emitted, the index is replaced with ~0U to ensure 443 /// that we don't re-emit the initializer. 444 llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition; 445 446 typedef std::pair<OrderGlobalInitsOrStermFinalizers, llvm::Function *> 447 GlobalInitData; 448 449 struct GlobalInitPriorityCmp { 450 bool operator()(const GlobalInitData &LHS, 451 const GlobalInitData &RHS) const { 452 return LHS.first.priority < RHS.first.priority; 453 } 454 }; 455 456 /// Global variables with initializers whose order of initialization is set by 457 /// init_priority attribute. 458 SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits; 459 460 /// Global destructor functions and arguments that need to run on termination. 461 /// When UseSinitAndSterm is set, it instead contains sterm finalizer 462 /// functions, which also run on unloading a shared library. 463 typedef std::tuple<llvm::FunctionType *, llvm::WeakTrackingVH, 464 llvm::Constant *> 465 CXXGlobalDtorsOrStermFinalizer_t; 466 SmallVector<CXXGlobalDtorsOrStermFinalizer_t, 8> 467 CXXGlobalDtorsOrStermFinalizers; 468 469 typedef std::pair<OrderGlobalInitsOrStermFinalizers, llvm::Function *> 470 StermFinalizerData; 471 472 struct StermFinalizerPriorityCmp { 473 bool operator()(const StermFinalizerData &LHS, 474 const StermFinalizerData &RHS) const { 475 return LHS.first.priority < RHS.first.priority; 476 } 477 }; 478 479 /// Global variables with sterm finalizers whose order of initialization is 480 /// set by init_priority attribute. 481 SmallVector<StermFinalizerData, 8> PrioritizedCXXStermFinalizers; 482 483 /// The complete set of modules that has been imported. 484 llvm::SetVector<clang::Module *> ImportedModules; 485 486 /// The set of modules for which the module initializers 487 /// have been emitted. 488 llvm::SmallPtrSet<clang::Module *, 16> EmittedModuleInitializers; 489 490 /// A vector of metadata strings for linker options. 491 SmallVector<llvm::MDNode *, 16> LinkerOptionsMetadata; 492 493 /// A vector of metadata strings for dependent libraries for ELF. 494 SmallVector<llvm::MDNode *, 16> ELFDependentLibraries; 495 496 /// @name Cache for Objective-C runtime types 497 /// @{ 498 499 /// Cached reference to the class for constant strings. This value has type 500 /// int * but is actually an Obj-C class pointer. 501 llvm::WeakTrackingVH CFConstantStringClassRef; 502 503 /// The type used to describe the state of a fast enumeration in 504 /// Objective-C's for..in loop. 505 QualType ObjCFastEnumerationStateType; 506 507 /// @} 508 509 /// Lazily create the Objective-C runtime 510 void createObjCRuntime(); 511 512 void createOpenCLRuntime(); 513 void createOpenMPRuntime(); 514 void createCUDARuntime(); 515 516 bool isTriviallyRecursive(const FunctionDecl *F); 517 bool shouldEmitFunction(GlobalDecl GD); 518 bool shouldOpportunisticallyEmitVTables(); 519 /// Map used to be sure we don't emit the same CompoundLiteral twice. 520 llvm::DenseMap<const CompoundLiteralExpr *, llvm::GlobalVariable *> 521 EmittedCompoundLiterals; 522 523 /// Map of the global blocks we've emitted, so that we don't have to re-emit 524 /// them if the constexpr evaluator gets aggressive. 525 llvm::DenseMap<const BlockExpr *, llvm::Constant *> EmittedGlobalBlocks; 526 527 /// @name Cache for Blocks Runtime Globals 528 /// @{ 529 530 llvm::Constant *NSConcreteGlobalBlock = nullptr; 531 llvm::Constant *NSConcreteStackBlock = nullptr; 532 533 llvm::FunctionCallee BlockObjectAssign = nullptr; 534 llvm::FunctionCallee BlockObjectDispose = nullptr; 535 536 llvm::Type *BlockDescriptorType = nullptr; 537 llvm::Type *GenericBlockLiteralType = nullptr; 538 539 struct { 540 int GlobalUniqueCount; 541 } Block; 542 543 GlobalDecl initializedGlobalDecl; 544 545 /// @} 546 547 /// void @llvm.lifetime.start(i64 %size, i8* nocapture <ptr>) 548 llvm::Function *LifetimeStartFn = nullptr; 549 550 /// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>) 551 llvm::Function *LifetimeEndFn = nullptr; 552 553 std::unique_ptr<SanitizerMetadata> SanitizerMD; 554 555 llvm::MapVector<const Decl *, bool> DeferredEmptyCoverageMappingDecls; 556 557 std::unique_ptr<CoverageMappingModuleGen> CoverageMapping; 558 559 /// Mapping from canonical types to their metadata identifiers. We need to 560 /// maintain this mapping because identifiers may be formed from distinct 561 /// MDNodes. 562 typedef llvm::DenseMap<QualType, llvm::Metadata *> MetadataTypeMap; 563 MetadataTypeMap MetadataIdMap; 564 MetadataTypeMap VirtualMetadataIdMap; 565 MetadataTypeMap GeneralizedMetadataIdMap; 566 567 public: 568 CodeGenModule(ASTContext &C, const HeaderSearchOptions &headersearchopts, 569 const PreprocessorOptions &ppopts, 570 const CodeGenOptions &CodeGenOpts, llvm::Module &M, 571 DiagnosticsEngine &Diags, 572 CoverageSourceInfo *CoverageInfo = nullptr); 573 574 ~CodeGenModule(); 575 576 void clear(); 577 578 /// Finalize LLVM code generation. 579 void Release(); 580 581 /// Return true if we should emit location information for expressions. 582 bool getExpressionLocationsEnabled() const; 583 584 /// Return a reference to the configured Objective-C runtime. 585 CGObjCRuntime &getObjCRuntime() { 586 if (!ObjCRuntime) createObjCRuntime(); 587 return *ObjCRuntime; 588 } 589 590 /// Return true iff an Objective-C runtime has been configured. 591 bool hasObjCRuntime() { return !!ObjCRuntime; } 592 593 const std::string &getModuleNameHash() const { return ModuleNameHash; } 594 595 /// Return a reference to the configured OpenCL runtime. 596 CGOpenCLRuntime &getOpenCLRuntime() { 597 assert(OpenCLRuntime != nullptr); 598 return *OpenCLRuntime; 599 } 600 601 /// Return a reference to the configured OpenMP runtime. 602 CGOpenMPRuntime &getOpenMPRuntime() { 603 assert(OpenMPRuntime != nullptr); 604 return *OpenMPRuntime; 605 } 606 607 /// Return a reference to the configured CUDA runtime. 608 CGCUDARuntime &getCUDARuntime() { 609 assert(CUDARuntime != nullptr); 610 return *CUDARuntime; 611 } 612 613 ObjCEntrypoints &getObjCEntrypoints() const { 614 assert(ObjCData != nullptr); 615 return *ObjCData; 616 } 617 618 // Version checking functions, used to implement ObjC's @available: 619 // i32 @__isOSVersionAtLeast(i32, i32, i32) 620 llvm::FunctionCallee IsOSVersionAtLeastFn = nullptr; 621 // i32 @__isPlatformVersionAtLeast(i32, i32, i32, i32) 622 llvm::FunctionCallee IsPlatformVersionAtLeastFn = nullptr; 623 624 InstrProfStats &getPGOStats() { return PGOStats; } 625 llvm::IndexedInstrProfReader *getPGOReader() const { return PGOReader.get(); } 626 627 CoverageMappingModuleGen *getCoverageMapping() const { 628 return CoverageMapping.get(); 629 } 630 631 llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) { 632 return StaticLocalDeclMap[D]; 633 } 634 void setStaticLocalDeclAddress(const VarDecl *D, 635 llvm::Constant *C) { 636 StaticLocalDeclMap[D] = C; 637 } 638 639 llvm::Constant * 640 getOrCreateStaticVarDecl(const VarDecl &D, 641 llvm::GlobalValue::LinkageTypes Linkage); 642 643 llvm::GlobalVariable *getStaticLocalDeclGuardAddress(const VarDecl *D) { 644 return StaticLocalDeclGuardMap[D]; 645 } 646 void setStaticLocalDeclGuardAddress(const VarDecl *D, 647 llvm::GlobalVariable *C) { 648 StaticLocalDeclGuardMap[D] = C; 649 } 650 651 Address createUnnamedGlobalFrom(const VarDecl &D, llvm::Constant *Constant, 652 CharUnits Align); 653 654 bool lookupRepresentativeDecl(StringRef MangledName, 655 GlobalDecl &Result) const; 656 657 llvm::Constant *getAtomicSetterHelperFnMap(QualType Ty) { 658 return AtomicSetterHelperFnMap[Ty]; 659 } 660 void setAtomicSetterHelperFnMap(QualType Ty, 661 llvm::Constant *Fn) { 662 AtomicSetterHelperFnMap[Ty] = Fn; 663 } 664 665 llvm::Constant *getAtomicGetterHelperFnMap(QualType Ty) { 666 return AtomicGetterHelperFnMap[Ty]; 667 } 668 void setAtomicGetterHelperFnMap(QualType Ty, 669 llvm::Constant *Fn) { 670 AtomicGetterHelperFnMap[Ty] = Fn; 671 } 672 673 llvm::Constant *getTypeDescriptorFromMap(QualType Ty) { 674 return TypeDescriptorMap[Ty]; 675 } 676 void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C) { 677 TypeDescriptorMap[Ty] = C; 678 } 679 680 CGDebugInfo *getModuleDebugInfo() { return DebugInfo.get(); } 681 682 llvm::MDNode *getNoObjCARCExceptionsMetadata() { 683 if (!NoObjCARCExceptionsMetadata) 684 NoObjCARCExceptionsMetadata = llvm::MDNode::get(getLLVMContext(), None); 685 return NoObjCARCExceptionsMetadata; 686 } 687 688 ASTContext &getContext() const { return Context; } 689 const LangOptions &getLangOpts() const { return LangOpts; } 690 const HeaderSearchOptions &getHeaderSearchOpts() 691 const { return HeaderSearchOpts; } 692 const PreprocessorOptions &getPreprocessorOpts() 693 const { return PreprocessorOpts; } 694 const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; } 695 llvm::Module &getModule() const { return TheModule; } 696 DiagnosticsEngine &getDiags() const { return Diags; } 697 const llvm::DataLayout &getDataLayout() const { 698 return TheModule.getDataLayout(); 699 } 700 const TargetInfo &getTarget() const { return Target; } 701 const llvm::Triple &getTriple() const { return Target.getTriple(); } 702 bool supportsCOMDAT() const; 703 void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO); 704 705 CGCXXABI &getCXXABI() const { return *ABI; } 706 llvm::LLVMContext &getLLVMContext() { return VMContext; } 707 708 bool shouldUseTBAA() const { return TBAA != nullptr; } 709 710 const TargetCodeGenInfo &getTargetCodeGenInfo(); 711 712 CodeGenTypes &getTypes() { return Types; } 713 714 CodeGenVTables &getVTables() { return VTables; } 715 716 ItaniumVTableContext &getItaniumVTableContext() { 717 return VTables.getItaniumVTableContext(); 718 } 719 720 MicrosoftVTableContext &getMicrosoftVTableContext() { 721 return VTables.getMicrosoftVTableContext(); 722 } 723 724 CtorList &getGlobalCtors() { return GlobalCtors; } 725 CtorList &getGlobalDtors() { return GlobalDtors; } 726 727 /// getTBAATypeInfo - Get metadata used to describe accesses to objects of 728 /// the given type. 729 llvm::MDNode *getTBAATypeInfo(QualType QTy); 730 731 /// getTBAAAccessInfo - Get TBAA information that describes an access to 732 /// an object of the given type. 733 TBAAAccessInfo getTBAAAccessInfo(QualType AccessType); 734 735 /// getTBAAVTablePtrAccessInfo - Get the TBAA information that describes an 736 /// access to a virtual table pointer. 737 TBAAAccessInfo getTBAAVTablePtrAccessInfo(llvm::Type *VTablePtrType); 738 739 llvm::MDNode *getTBAAStructInfo(QualType QTy); 740 741 /// getTBAABaseTypeInfo - Get metadata that describes the given base access 742 /// type. Return null if the type is not suitable for use in TBAA access tags. 743 llvm::MDNode *getTBAABaseTypeInfo(QualType QTy); 744 745 /// getTBAAAccessTagInfo - Get TBAA tag for a given memory access. 746 llvm::MDNode *getTBAAAccessTagInfo(TBAAAccessInfo Info); 747 748 /// mergeTBAAInfoForCast - Get merged TBAA information for the purposes of 749 /// type casts. 750 TBAAAccessInfo mergeTBAAInfoForCast(TBAAAccessInfo SourceInfo, 751 TBAAAccessInfo TargetInfo); 752 753 /// mergeTBAAInfoForConditionalOperator - Get merged TBAA information for the 754 /// purposes of conditional operator. 755 TBAAAccessInfo mergeTBAAInfoForConditionalOperator(TBAAAccessInfo InfoA, 756 TBAAAccessInfo InfoB); 757 758 /// mergeTBAAInfoForMemoryTransfer - Get merged TBAA information for the 759 /// purposes of memory transfer calls. 760 TBAAAccessInfo mergeTBAAInfoForMemoryTransfer(TBAAAccessInfo DestInfo, 761 TBAAAccessInfo SrcInfo); 762 763 /// getTBAAInfoForSubobject - Get TBAA information for an access with a given 764 /// base lvalue. 765 TBAAAccessInfo getTBAAInfoForSubobject(LValue Base, QualType AccessType) { 766 if (Base.getTBAAInfo().isMayAlias()) 767 return TBAAAccessInfo::getMayAliasInfo(); 768 return getTBAAAccessInfo(AccessType); 769 } 770 771 bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor); 772 773 bool isPaddedAtomicType(QualType type); 774 bool isPaddedAtomicType(const AtomicType *type); 775 776 /// DecorateInstructionWithTBAA - Decorate the instruction with a TBAA tag. 777 void DecorateInstructionWithTBAA(llvm::Instruction *Inst, 778 TBAAAccessInfo TBAAInfo); 779 780 /// Adds !invariant.barrier !tag to instruction 781 void DecorateInstructionWithInvariantGroup(llvm::Instruction *I, 782 const CXXRecordDecl *RD); 783 784 /// Emit the given number of characters as a value of type size_t. 785 llvm::ConstantInt *getSize(CharUnits numChars); 786 787 /// Set the visibility for the given LLVM GlobalValue. 788 void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const; 789 790 void setDSOLocal(llvm::GlobalValue *GV) const; 791 792 void setDLLImportDLLExport(llvm::GlobalValue *GV, GlobalDecl D) const; 793 void setDLLImportDLLExport(llvm::GlobalValue *GV, const NamedDecl *D) const; 794 /// Set visibility, dllimport/dllexport and dso_local. 795 /// This must be called after dllimport/dllexport is set. 796 void setGVProperties(llvm::GlobalValue *GV, GlobalDecl GD) const; 797 void setGVProperties(llvm::GlobalValue *GV, const NamedDecl *D) const; 798 799 void setGVPropertiesAux(llvm::GlobalValue *GV, const NamedDecl *D) const; 800 801 /// Set the TLS mode for the given LLVM GlobalValue for the thread-local 802 /// variable declaration D. 803 void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const; 804 805 /// Get LLVM TLS mode from CodeGenOptions. 806 llvm::GlobalVariable::ThreadLocalMode GetDefaultLLVMTLSModel() const; 807 808 static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) { 809 switch (V) { 810 case DefaultVisibility: return llvm::GlobalValue::DefaultVisibility; 811 case HiddenVisibility: return llvm::GlobalValue::HiddenVisibility; 812 case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility; 813 } 814 llvm_unreachable("unknown visibility!"); 815 } 816 817 llvm::Constant *GetAddrOfGlobal(GlobalDecl GD, 818 ForDefinition_t IsForDefinition 819 = NotForDefinition); 820 821 /// Will return a global variable of the given type. If a variable with a 822 /// different type already exists then a new variable with the right type 823 /// will be created and all uses of the old variable will be replaced with a 824 /// bitcast to the new variable. 825 llvm::GlobalVariable * 826 CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty, 827 llvm::GlobalValue::LinkageTypes Linkage, 828 unsigned Alignment); 829 830 llvm::Function *CreateGlobalInitOrCleanUpFunction( 831 llvm::FunctionType *ty, const Twine &name, const CGFunctionInfo &FI, 832 SourceLocation Loc = SourceLocation(), bool TLS = false, 833 llvm::GlobalVariable::LinkageTypes Linkage = 834 llvm::GlobalVariable::InternalLinkage); 835 836 /// Return the AST address space of the underlying global variable for D, as 837 /// determined by its declaration. Normally this is the same as the address 838 /// space of D's type, but in CUDA, address spaces are associated with 839 /// declarations, not types. If D is nullptr, return the default address 840 /// space for global variable. 841 /// 842 /// For languages without explicit address spaces, if D has default address 843 /// space, target-specific global or constant address space may be returned. 844 LangAS GetGlobalVarAddressSpace(const VarDecl *D); 845 846 /// Return the AST address space of constant literal, which is used to emit 847 /// the constant literal as global variable in LLVM IR. 848 /// Note: This is not necessarily the address space of the constant literal 849 /// in AST. For address space agnostic language, e.g. C++, constant literal 850 /// in AST is always in default address space. 851 LangAS GetGlobalConstantAddressSpace() const; 852 853 /// Return the llvm::Constant for the address of the given global variable. 854 /// If Ty is non-null and if the global doesn't exist, then it will be created 855 /// with the specified type instead of whatever the normal requested type 856 /// would be. If IsForDefinition is true, it is guaranteed that an actual 857 /// global with type Ty will be returned, not conversion of a variable with 858 /// the same mangled name but some other type. 859 llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D, 860 llvm::Type *Ty = nullptr, 861 ForDefinition_t IsForDefinition 862 = NotForDefinition); 863 864 /// Return the address of the given function. If Ty is non-null, then this 865 /// function will use the specified type if it has to create it. 866 llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = nullptr, 867 bool ForVTable = false, 868 bool DontDefer = false, 869 ForDefinition_t IsForDefinition 870 = NotForDefinition); 871 872 // Return the function body address of the given function. 873 llvm::Constant *GetFunctionStart(const ValueDecl *Decl); 874 875 /// Get the address of the RTTI descriptor for the given type. 876 llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false); 877 878 /// Get the address of a GUID. 879 ConstantAddress GetAddrOfMSGuidDecl(const MSGuidDecl *GD); 880 881 /// Get the address of a UnnamedGlobalConstant 882 ConstantAddress 883 GetAddrOfUnnamedGlobalConstantDecl(const UnnamedGlobalConstantDecl *GCD); 884 885 /// Get the address of a template parameter object. 886 ConstantAddress 887 GetAddrOfTemplateParamObject(const TemplateParamObjectDecl *TPO); 888 889 /// Get the address of the thunk for the given global decl. 890 llvm::Constant *GetAddrOfThunk(StringRef Name, llvm::Type *FnTy, 891 GlobalDecl GD); 892 893 /// Get a reference to the target of VD. 894 ConstantAddress GetWeakRefReference(const ValueDecl *VD); 895 896 /// Returns the assumed alignment of an opaque pointer to the given class. 897 CharUnits getClassPointerAlignment(const CXXRecordDecl *CD); 898 899 /// Returns the minimum object size for an object of the given class type 900 /// (or a class derived from it). 901 CharUnits getMinimumClassObjectSize(const CXXRecordDecl *CD); 902 903 /// Returns the minimum object size for an object of the given type. 904 CharUnits getMinimumObjectSize(QualType Ty) { 905 if (CXXRecordDecl *RD = Ty->getAsCXXRecordDecl()) 906 return getMinimumClassObjectSize(RD); 907 return getContext().getTypeSizeInChars(Ty); 908 } 909 910 /// Returns the assumed alignment of a virtual base of a class. 911 CharUnits getVBaseAlignment(CharUnits DerivedAlign, 912 const CXXRecordDecl *Derived, 913 const CXXRecordDecl *VBase); 914 915 /// Given a class pointer with an actual known alignment, and the 916 /// expected alignment of an object at a dynamic offset w.r.t that 917 /// pointer, return the alignment to assume at the offset. 918 CharUnits getDynamicOffsetAlignment(CharUnits ActualAlign, 919 const CXXRecordDecl *Class, 920 CharUnits ExpectedTargetAlign); 921 922 CharUnits 923 computeNonVirtualBaseClassOffset(const CXXRecordDecl *DerivedClass, 924 CastExpr::path_const_iterator Start, 925 CastExpr::path_const_iterator End); 926 927 /// Returns the offset from a derived class to a class. Returns null if the 928 /// offset is 0. 929 llvm::Constant * 930 GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl, 931 CastExpr::path_const_iterator PathBegin, 932 CastExpr::path_const_iterator PathEnd); 933 934 llvm::FoldingSet<BlockByrefHelpers> ByrefHelpersCache; 935 936 /// Fetches the global unique block count. 937 int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; } 938 939 /// Fetches the type of a generic block descriptor. 940 llvm::Type *getBlockDescriptorType(); 941 942 /// The type of a generic block literal. 943 llvm::Type *getGenericBlockLiteralType(); 944 945 /// Gets the address of a block which requires no captures. 946 llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, StringRef Name); 947 948 /// Returns the address of a block which requires no caputres, or null if 949 /// we've yet to emit the block for BE. 950 llvm::Constant *getAddrOfGlobalBlockIfEmitted(const BlockExpr *BE) { 951 return EmittedGlobalBlocks.lookup(BE); 952 } 953 954 /// Notes that BE's global block is available via Addr. Asserts that BE 955 /// isn't already emitted. 956 void setAddrOfGlobalBlock(const BlockExpr *BE, llvm::Constant *Addr); 957 958 /// Return a pointer to a constant CFString object for the given string. 959 ConstantAddress GetAddrOfConstantCFString(const StringLiteral *Literal); 960 961 /// Return a pointer to a constant NSString object for the given string. Or a 962 /// user defined String object as defined via 963 /// -fconstant-string-class=class_name option. 964 ConstantAddress GetAddrOfConstantString(const StringLiteral *Literal); 965 966 /// Return a constant array for the given string. 967 llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E); 968 969 /// Return a pointer to a constant array for the given string literal. 970 ConstantAddress 971 GetAddrOfConstantStringFromLiteral(const StringLiteral *S, 972 StringRef Name = ".str"); 973 974 /// Return a pointer to a constant array for the given ObjCEncodeExpr node. 975 ConstantAddress 976 GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *); 977 978 /// Returns a pointer to a character array containing the literal and a 979 /// terminating '\0' character. The result has pointer to array type. 980 /// 981 /// \param GlobalName If provided, the name to use for the global (if one is 982 /// created). 983 ConstantAddress 984 GetAddrOfConstantCString(const std::string &Str, 985 const char *GlobalName = nullptr); 986 987 /// Returns a pointer to a constant global variable for the given file-scope 988 /// compound literal expression. 989 ConstantAddress GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr*E); 990 991 /// If it's been emitted already, returns the GlobalVariable corresponding to 992 /// a compound literal. Otherwise, returns null. 993 llvm::GlobalVariable * 994 getAddrOfConstantCompoundLiteralIfEmitted(const CompoundLiteralExpr *E); 995 996 /// Notes that CLE's GlobalVariable is GV. Asserts that CLE isn't already 997 /// emitted. 998 void setAddrOfConstantCompoundLiteral(const CompoundLiteralExpr *CLE, 999 llvm::GlobalVariable *GV); 1000 1001 /// Returns a pointer to a global variable representing a temporary 1002 /// with static or thread storage duration. 1003 ConstantAddress GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E, 1004 const Expr *Inner); 1005 1006 /// Retrieve the record type that describes the state of an 1007 /// Objective-C fast enumeration loop (for..in). 1008 QualType getObjCFastEnumerationStateType(); 1009 1010 // Produce code for this constructor/destructor. This method doesn't try 1011 // to apply any ABI rules about which other constructors/destructors 1012 // are needed or if they are alias to each other. 1013 llvm::Function *codegenCXXStructor(GlobalDecl GD); 1014 1015 /// Return the address of the constructor/destructor of the given type. 1016 llvm::Constant * 1017 getAddrOfCXXStructor(GlobalDecl GD, const CGFunctionInfo *FnInfo = nullptr, 1018 llvm::FunctionType *FnType = nullptr, 1019 bool DontDefer = false, 1020 ForDefinition_t IsForDefinition = NotForDefinition) { 1021 return cast<llvm::Constant>(getAddrAndTypeOfCXXStructor(GD, FnInfo, FnType, 1022 DontDefer, 1023 IsForDefinition) 1024 .getCallee()); 1025 } 1026 1027 llvm::FunctionCallee getAddrAndTypeOfCXXStructor( 1028 GlobalDecl GD, const CGFunctionInfo *FnInfo = nullptr, 1029 llvm::FunctionType *FnType = nullptr, bool DontDefer = false, 1030 ForDefinition_t IsForDefinition = NotForDefinition); 1031 1032 /// Given a builtin id for a function like "__builtin_fabsf", return a 1033 /// Function* for "fabsf". 1034 llvm::Constant *getBuiltinLibFunction(const FunctionDecl *FD, 1035 unsigned BuiltinID); 1036 1037 llvm::Function *getIntrinsic(unsigned IID, ArrayRef<llvm::Type*> Tys = None); 1038 1039 /// Emit code for a single top level declaration. 1040 void EmitTopLevelDecl(Decl *D); 1041 1042 /// Stored a deferred empty coverage mapping for an unused 1043 /// and thus uninstrumented top level declaration. 1044 void AddDeferredUnusedCoverageMapping(Decl *D); 1045 1046 /// Remove the deferred empty coverage mapping as this 1047 /// declaration is actually instrumented. 1048 void ClearUnusedCoverageMapping(const Decl *D); 1049 1050 /// Emit all the deferred coverage mappings 1051 /// for the uninstrumented functions. 1052 void EmitDeferredUnusedCoverageMappings(); 1053 1054 /// Emit an alias for "main" if it has no arguments (needed for wasm). 1055 void EmitMainVoidAlias(); 1056 1057 /// Tell the consumer that this variable has been instantiated. 1058 void HandleCXXStaticMemberVarInstantiation(VarDecl *VD); 1059 1060 /// If the declaration has internal linkage but is inside an 1061 /// extern "C" linkage specification, prepare to emit an alias for it 1062 /// to the expected name. 1063 template<typename SomeDecl> 1064 void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV); 1065 1066 /// Add a global to a list to be added to the llvm.used metadata. 1067 void addUsedGlobal(llvm::GlobalValue *GV); 1068 1069 /// Add a global to a list to be added to the llvm.compiler.used metadata. 1070 void addCompilerUsedGlobal(llvm::GlobalValue *GV); 1071 1072 /// Add a global to a list to be added to the llvm.compiler.used metadata. 1073 void addUsedOrCompilerUsedGlobal(llvm::GlobalValue *GV); 1074 1075 /// Add a destructor and object to add to the C++ global destructor function. 1076 void AddCXXDtorEntry(llvm::FunctionCallee DtorFn, llvm::Constant *Object) { 1077 CXXGlobalDtorsOrStermFinalizers.emplace_back(DtorFn.getFunctionType(), 1078 DtorFn.getCallee(), Object); 1079 } 1080 1081 /// Add an sterm finalizer to the C++ global cleanup function. 1082 void AddCXXStermFinalizerEntry(llvm::FunctionCallee DtorFn) { 1083 CXXGlobalDtorsOrStermFinalizers.emplace_back(DtorFn.getFunctionType(), 1084 DtorFn.getCallee(), nullptr); 1085 } 1086 1087 /// Add an sterm finalizer to its own llvm.global_dtors entry. 1088 void AddCXXStermFinalizerToGlobalDtor(llvm::Function *StermFinalizer, 1089 int Priority) { 1090 AddGlobalDtor(StermFinalizer, Priority); 1091 } 1092 1093 void AddCXXPrioritizedStermFinalizerEntry(llvm::Function *StermFinalizer, 1094 int Priority) { 1095 OrderGlobalInitsOrStermFinalizers Key(Priority, 1096 PrioritizedCXXStermFinalizers.size()); 1097 PrioritizedCXXStermFinalizers.push_back( 1098 std::make_pair(Key, StermFinalizer)); 1099 } 1100 1101 /// Create or return a runtime function declaration with the specified type 1102 /// and name. If \p AssumeConvergent is true, the call will have the 1103 /// convergent attribute added. 1104 llvm::FunctionCallee 1105 CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, 1106 llvm::AttributeList ExtraAttrs = llvm::AttributeList(), 1107 bool Local = false, bool AssumeConvergent = false); 1108 1109 /// Create a new runtime global variable with the specified type and name. 1110 llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty, 1111 StringRef Name); 1112 1113 ///@name Custom Blocks Runtime Interfaces 1114 ///@{ 1115 1116 llvm::Constant *getNSConcreteGlobalBlock(); 1117 llvm::Constant *getNSConcreteStackBlock(); 1118 llvm::FunctionCallee getBlockObjectAssign(); 1119 llvm::FunctionCallee getBlockObjectDispose(); 1120 1121 ///@} 1122 1123 llvm::Function *getLLVMLifetimeStartFn(); 1124 llvm::Function *getLLVMLifetimeEndFn(); 1125 1126 // Make sure that this type is translated. 1127 void UpdateCompletedType(const TagDecl *TD); 1128 1129 llvm::Constant *getMemberPointerConstant(const UnaryOperator *e); 1130 1131 /// Emit type info if type of an expression is a variably modified 1132 /// type. Also emit proper debug info for cast types. 1133 void EmitExplicitCastExprType(const ExplicitCastExpr *E, 1134 CodeGenFunction *CGF = nullptr); 1135 1136 /// Return the result of value-initializing the given type, i.e. a null 1137 /// expression of the given type. This is usually, but not always, an LLVM 1138 /// null constant. 1139 llvm::Constant *EmitNullConstant(QualType T); 1140 1141 /// Return a null constant appropriate for zero-initializing a base class with 1142 /// the given type. This is usually, but not always, an LLVM null constant. 1143 llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record); 1144 1145 /// Emit a general error that something can't be done. 1146 void Error(SourceLocation loc, StringRef error); 1147 1148 /// Print out an error that codegen doesn't support the specified stmt yet. 1149 void ErrorUnsupported(const Stmt *S, const char *Type); 1150 1151 /// Print out an error that codegen doesn't support the specified decl yet. 1152 void ErrorUnsupported(const Decl *D, const char *Type); 1153 1154 /// Set the attributes on the LLVM function for the given decl and function 1155 /// info. This applies attributes necessary for handling the ABI as well as 1156 /// user specified attributes like section. 1157 void SetInternalFunctionAttributes(GlobalDecl GD, llvm::Function *F, 1158 const CGFunctionInfo &FI); 1159 1160 /// Set the LLVM function attributes (sext, zext, etc). 1161 void SetLLVMFunctionAttributes(GlobalDecl GD, const CGFunctionInfo &Info, 1162 llvm::Function *F, bool IsThunk); 1163 1164 /// Set the LLVM function attributes which only apply to a function 1165 /// definition. 1166 void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F); 1167 1168 /// Set the LLVM function attributes that represent floating point 1169 /// environment. 1170 void setLLVMFunctionFEnvAttributes(const FunctionDecl *D, llvm::Function *F); 1171 1172 /// Return true iff the given type uses 'sret' when used as a return type. 1173 bool ReturnTypeUsesSRet(const CGFunctionInfo &FI); 1174 1175 /// Return true iff the given type uses an argument slot when 'sret' is used 1176 /// as a return type. 1177 bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI); 1178 1179 /// Return true iff the given type uses 'fpret' when used as a return type. 1180 bool ReturnTypeUsesFPRet(QualType ResultType); 1181 1182 /// Return true iff the given type uses 'fp2ret' when used as a return type. 1183 bool ReturnTypeUsesFP2Ret(QualType ResultType); 1184 1185 /// Get the LLVM attributes and calling convention to use for a particular 1186 /// function type. 1187 /// 1188 /// \param Name - The function name. 1189 /// \param Info - The function type information. 1190 /// \param CalleeInfo - The callee information these attributes are being 1191 /// constructed for. If valid, the attributes applied to this decl may 1192 /// contribute to the function attributes and calling convention. 1193 /// \param Attrs [out] - On return, the attribute list to use. 1194 /// \param CallingConv [out] - On return, the LLVM calling convention to use. 1195 void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info, 1196 CGCalleeInfo CalleeInfo, 1197 llvm::AttributeList &Attrs, unsigned &CallingConv, 1198 bool AttrOnCallSite, bool IsThunk); 1199 1200 /// Adds attributes to F according to our CodeGenOptions and LangOptions, as 1201 /// though we had emitted it ourselves. We remove any attributes on F that 1202 /// conflict with the attributes we add here. 1203 /// 1204 /// This is useful for adding attrs to bitcode modules that you want to link 1205 /// with but don't control, such as CUDA's libdevice. When linking with such 1206 /// a bitcode library, you might want to set e.g. its functions' 1207 /// "unsafe-fp-math" attribute to match the attr of the functions you're 1208 /// codegen'ing. Otherwise, LLVM will interpret the bitcode module's lack of 1209 /// unsafe-fp-math attrs as tantamount to unsafe-fp-math=false, and then LLVM 1210 /// will propagate unsafe-fp-math=false up to every transitive caller of a 1211 /// function in the bitcode library! 1212 /// 1213 /// With the exception of fast-math attrs, this will only make the attributes 1214 /// on the function more conservative. But it's unsafe to call this on a 1215 /// function which relies on particular fast-math attributes for correctness. 1216 /// It's up to you to ensure that this is safe. 1217 void addDefaultFunctionDefinitionAttributes(llvm::Function &F); 1218 1219 /// Like the overload taking a `Function &`, but intended specifically 1220 /// for frontends that want to build on Clang's target-configuration logic. 1221 void addDefaultFunctionDefinitionAttributes(llvm::AttrBuilder &attrs); 1222 1223 StringRef getMangledName(GlobalDecl GD); 1224 StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD); 1225 const GlobalDecl getMangledNameDecl(StringRef); 1226 1227 void EmitTentativeDefinition(const VarDecl *D); 1228 1229 void EmitExternalDeclaration(const VarDecl *D); 1230 1231 void EmitVTable(CXXRecordDecl *Class); 1232 1233 void RefreshTypeCacheForClass(const CXXRecordDecl *Class); 1234 1235 /// Appends Opts to the "llvm.linker.options" metadata value. 1236 void AppendLinkerOptions(StringRef Opts); 1237 1238 /// Appends a detect mismatch command to the linker options. 1239 void AddDetectMismatch(StringRef Name, StringRef Value); 1240 1241 /// Appends a dependent lib to the appropriate metadata value. 1242 void AddDependentLib(StringRef Lib); 1243 1244 1245 llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD); 1246 1247 void setFunctionLinkage(GlobalDecl GD, llvm::Function *F) { 1248 F->setLinkage(getFunctionLinkage(GD)); 1249 } 1250 1251 /// Return the appropriate linkage for the vtable, VTT, and type information 1252 /// of the given class. 1253 llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD); 1254 1255 /// Return the store size, in character units, of the given LLVM type. 1256 CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const; 1257 1258 /// Returns LLVM linkage for a declarator. 1259 llvm::GlobalValue::LinkageTypes 1260 getLLVMLinkageForDeclarator(const DeclaratorDecl *D, GVALinkage Linkage, 1261 bool IsConstantVariable); 1262 1263 /// Returns LLVM linkage for a declarator. 1264 llvm::GlobalValue::LinkageTypes 1265 getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant); 1266 1267 /// Emit all the global annotations. 1268 void EmitGlobalAnnotations(); 1269 1270 /// Emit an annotation string. 1271 llvm::Constant *EmitAnnotationString(StringRef Str); 1272 1273 /// Emit the annotation's translation unit. 1274 llvm::Constant *EmitAnnotationUnit(SourceLocation Loc); 1275 1276 /// Emit the annotation line number. 1277 llvm::Constant *EmitAnnotationLineNo(SourceLocation L); 1278 1279 /// Emit additional args of the annotation. 1280 llvm::Constant *EmitAnnotationArgs(const AnnotateAttr *Attr); 1281 1282 /// Generate the llvm::ConstantStruct which contains the annotation 1283 /// information for a given GlobalValue. The annotation struct is 1284 /// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the 1285 /// GlobalValue being annotated. The second field is the constant string 1286 /// created from the AnnotateAttr's annotation. The third field is a constant 1287 /// string containing the name of the translation unit. The fourth field is 1288 /// the line number in the file of the annotated value declaration. 1289 llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV, 1290 const AnnotateAttr *AA, 1291 SourceLocation L); 1292 1293 /// Add global annotations that are set on D, for the global GV. Those 1294 /// annotations are emitted during finalization of the LLVM code. 1295 void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV); 1296 1297 bool isInNoSanitizeList(SanitizerMask Kind, llvm::Function *Fn, 1298 SourceLocation Loc) const; 1299 1300 bool isInNoSanitizeList(llvm::GlobalVariable *GV, SourceLocation Loc, 1301 QualType Ty, StringRef Category = StringRef()) const; 1302 1303 /// Imbue XRay attributes to a function, applying the always/never attribute 1304 /// lists in the process. Returns true if we did imbue attributes this way, 1305 /// false otherwise. 1306 bool imbueXRayAttrs(llvm::Function *Fn, SourceLocation Loc, 1307 StringRef Category = StringRef()) const; 1308 1309 /// Returns true if function at the given location should be excluded from 1310 /// profile instrumentation. 1311 bool isProfileInstrExcluded(llvm::Function *Fn, SourceLocation Loc) const; 1312 1313 SanitizerMetadata *getSanitizerMetadata() { 1314 return SanitizerMD.get(); 1315 } 1316 1317 void addDeferredVTable(const CXXRecordDecl *RD) { 1318 DeferredVTables.push_back(RD); 1319 } 1320 1321 /// Emit code for a single global function or var decl. Forward declarations 1322 /// are emitted lazily. 1323 void EmitGlobal(GlobalDecl D); 1324 1325 bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D); 1326 1327 llvm::GlobalValue *GetGlobalValue(StringRef Ref); 1328 1329 /// Set attributes which are common to any form of a global definition (alias, 1330 /// Objective-C method, function, global variable). 1331 /// 1332 /// NOTE: This should only be called for definitions. 1333 void SetCommonAttributes(GlobalDecl GD, llvm::GlobalValue *GV); 1334 1335 void addReplacement(StringRef Name, llvm::Constant *C); 1336 1337 void addGlobalValReplacement(llvm::GlobalValue *GV, llvm::Constant *C); 1338 1339 /// Emit a code for threadprivate directive. 1340 /// \param D Threadprivate declaration. 1341 void EmitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D); 1342 1343 /// Emit a code for declare reduction construct. 1344 void EmitOMPDeclareReduction(const OMPDeclareReductionDecl *D, 1345 CodeGenFunction *CGF = nullptr); 1346 1347 /// Emit a code for declare mapper construct. 1348 void EmitOMPDeclareMapper(const OMPDeclareMapperDecl *D, 1349 CodeGenFunction *CGF = nullptr); 1350 1351 /// Emit a code for requires directive. 1352 /// \param D Requires declaration 1353 void EmitOMPRequiresDecl(const OMPRequiresDecl *D); 1354 1355 /// Emit a code for the allocate directive. 1356 /// \param D The allocate declaration 1357 void EmitOMPAllocateDecl(const OMPAllocateDecl *D); 1358 1359 /// Returns whether the given record has hidden LTO visibility and therefore 1360 /// may participate in (single-module) CFI and whole-program vtable 1361 /// optimization. 1362 bool HasHiddenLTOVisibility(const CXXRecordDecl *RD); 1363 1364 /// Returns whether the given record has public std LTO visibility 1365 /// and therefore may not participate in (single-module) CFI and whole-program 1366 /// vtable optimization. 1367 bool HasLTOVisibilityPublicStd(const CXXRecordDecl *RD); 1368 1369 /// Returns the vcall visibility of the given type. This is the scope in which 1370 /// a virtual function call could be made which ends up being dispatched to a 1371 /// member function of this class. This scope can be wider than the visibility 1372 /// of the class itself when the class has a more-visible dynamic base class. 1373 /// The client should pass in an empty Visited set, which is used to prevent 1374 /// redundant recursive processing. 1375 llvm::GlobalObject::VCallVisibility 1376 GetVCallVisibilityLevel(const CXXRecordDecl *RD, 1377 llvm::DenseSet<const CXXRecordDecl *> &Visited); 1378 1379 /// Emit type metadata for the given vtable using the given layout. 1380 void EmitVTableTypeMetadata(const CXXRecordDecl *RD, 1381 llvm::GlobalVariable *VTable, 1382 const VTableLayout &VTLayout); 1383 1384 /// Generate a cross-DSO type identifier for MD. 1385 llvm::ConstantInt *CreateCrossDsoCfiTypeId(llvm::Metadata *MD); 1386 1387 /// Create a metadata identifier for the given type. This may either be an 1388 /// MDString (for external identifiers) or a distinct unnamed MDNode (for 1389 /// internal identifiers). 1390 llvm::Metadata *CreateMetadataIdentifierForType(QualType T); 1391 1392 /// Create a metadata identifier that is intended to be used to check virtual 1393 /// calls via a member function pointer. 1394 llvm::Metadata *CreateMetadataIdentifierForVirtualMemPtrType(QualType T); 1395 1396 /// Create a metadata identifier for the generalization of the given type. 1397 /// This may either be an MDString (for external identifiers) or a distinct 1398 /// unnamed MDNode (for internal identifiers). 1399 llvm::Metadata *CreateMetadataIdentifierGeneralized(QualType T); 1400 1401 /// Create and attach type metadata to the given function. 1402 void CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, 1403 llvm::Function *F); 1404 1405 /// Whether this function's return type has no side effects, and thus may 1406 /// be trivially discarded if it is unused. 1407 bool MayDropFunctionReturn(const ASTContext &Context, QualType ReturnType); 1408 1409 /// Returns whether this module needs the "all-vtables" type identifier. 1410 bool NeedAllVtablesTypeId() const; 1411 1412 /// Create and attach type metadata for the given vtable. 1413 void AddVTableTypeMetadata(llvm::GlobalVariable *VTable, CharUnits Offset, 1414 const CXXRecordDecl *RD); 1415 1416 /// Return a vector of most-base classes for RD. This is used to implement 1417 /// control flow integrity checks for member function pointers. 1418 /// 1419 /// A most-base class of a class C is defined as a recursive base class of C, 1420 /// including C itself, that does not have any bases. 1421 std::vector<const CXXRecordDecl *> 1422 getMostBaseClasses(const CXXRecordDecl *RD); 1423 1424 /// Get the declaration of std::terminate for the platform. 1425 llvm::FunctionCallee getTerminateFn(); 1426 1427 llvm::SanitizerStatReport &getSanStats(); 1428 1429 llvm::Value * 1430 createOpenCLIntToSamplerConversion(const Expr *E, CodeGenFunction &CGF); 1431 1432 /// OpenCL v1.2 s5.6.4.6 allows the compiler to store kernel argument 1433 /// information in the program executable. The argument information stored 1434 /// includes the argument name, its type, the address and access qualifiers 1435 /// used. This helper can be used to generate metadata for source code kernel 1436 /// function as well as generated implicitly kernels. If a kernel is generated 1437 /// implicitly null value has to be passed to the last two parameters, 1438 /// otherwise all parameters must have valid non-null values. 1439 /// \param FN is a pointer to IR function being generated. 1440 /// \param FD is a pointer to function declaration if any. 1441 /// \param CGF is a pointer to CodeGenFunction that generates this function. 1442 void GenOpenCLArgMetadata(llvm::Function *FN, 1443 const FunctionDecl *FD = nullptr, 1444 CodeGenFunction *CGF = nullptr); 1445 1446 /// Get target specific null pointer. 1447 /// \param T is the LLVM type of the null pointer. 1448 /// \param QT is the clang QualType of the null pointer. 1449 llvm::Constant *getNullPointer(llvm::PointerType *T, QualType QT); 1450 1451 CharUnits getNaturalTypeAlignment(QualType T, 1452 LValueBaseInfo *BaseInfo = nullptr, 1453 TBAAAccessInfo *TBAAInfo = nullptr, 1454 bool forPointeeType = false); 1455 CharUnits getNaturalPointeeTypeAlignment(QualType T, 1456 LValueBaseInfo *BaseInfo = nullptr, 1457 TBAAAccessInfo *TBAAInfo = nullptr); 1458 bool stopAutoInit(); 1459 1460 /// Print the postfix for externalized static variable or kernels for single 1461 /// source offloading languages CUDA and HIP. 1462 void printPostfixForExternalizedDecl(llvm::raw_ostream &OS, 1463 const Decl *D) const; 1464 1465 private: 1466 llvm::Constant *GetOrCreateLLVMFunction( 1467 StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable, 1468 bool DontDefer = false, bool IsThunk = false, 1469 llvm::AttributeList ExtraAttrs = llvm::AttributeList(), 1470 ForDefinition_t IsForDefinition = NotForDefinition); 1471 1472 // References to multiversion functions are resolved through an implicitly 1473 // defined resolver function. This function is responsible for creating 1474 // the resolver symbol for the provided declaration. The value returned 1475 // will be for an ifunc (llvm::GlobalIFunc) if the current target supports 1476 // that feature and for a regular function (llvm::GlobalValue) otherwise. 1477 llvm::Constant *GetOrCreateMultiVersionResolver(GlobalDecl GD); 1478 1479 // In scenarios where a function is not known to be a multiversion function 1480 // until a later declaration, it is sometimes necessary to change the 1481 // previously created mangled name to align with requirements of whatever 1482 // multiversion function kind the function is now known to be. This function 1483 // is responsible for performing such mangled name updates. 1484 void UpdateMultiVersionNames(GlobalDecl GD, const FunctionDecl *FD, 1485 StringRef &CurName); 1486 1487 llvm::Constant * 1488 GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty, LangAS AddrSpace, 1489 const VarDecl *D, 1490 ForDefinition_t IsForDefinition = NotForDefinition); 1491 1492 bool GetCPUAndFeaturesAttributes(GlobalDecl GD, 1493 llvm::AttrBuilder &AttrBuilder); 1494 void setNonAliasAttributes(GlobalDecl GD, llvm::GlobalObject *GO); 1495 1496 /// Set function attributes for a function declaration. 1497 void SetFunctionAttributes(GlobalDecl GD, llvm::Function *F, 1498 bool IsIncompleteFunction, bool IsThunk); 1499 1500 void EmitGlobalDefinition(GlobalDecl D, llvm::GlobalValue *GV = nullptr); 1501 1502 void EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV); 1503 void EmitMultiVersionFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV); 1504 1505 void EmitGlobalVarDefinition(const VarDecl *D, bool IsTentative = false); 1506 void EmitExternalVarDeclaration(const VarDecl *D); 1507 void EmitAliasDefinition(GlobalDecl GD); 1508 void emitIFuncDefinition(GlobalDecl GD); 1509 void emitCPUDispatchDefinition(GlobalDecl GD); 1510 void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D); 1511 void EmitObjCIvarInitializations(ObjCImplementationDecl *D); 1512 1513 // C++ related functions. 1514 1515 void EmitDeclContext(const DeclContext *DC); 1516 void EmitLinkageSpec(const LinkageSpecDecl *D); 1517 1518 /// Emit the function that initializes C++ thread_local variables. 1519 void EmitCXXThreadLocalInitFunc(); 1520 1521 /// Emit the function that initializes C++ globals. 1522 void EmitCXXGlobalInitFunc(); 1523 1524 /// Emit the function that performs cleanup associated with C++ globals. 1525 void EmitCXXGlobalCleanUpFunc(); 1526 1527 /// Emit the function that initializes the specified global (if PerformInit is 1528 /// true) and registers its destructor. 1529 void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D, 1530 llvm::GlobalVariable *Addr, 1531 bool PerformInit); 1532 1533 void EmitPointerToInitFunc(const VarDecl *VD, llvm::GlobalVariable *Addr, 1534 llvm::Function *InitFunc, InitSegAttr *ISA); 1535 1536 // FIXME: Hardcoding priority here is gross. 1537 void AddGlobalCtor(llvm::Function *Ctor, int Priority = 65535, 1538 llvm::Constant *AssociatedData = nullptr); 1539 void AddGlobalDtor(llvm::Function *Dtor, int Priority = 65535, 1540 bool IsDtorAttrFunc = false); 1541 1542 /// EmitCtorList - Generates a global array of functions and priorities using 1543 /// the given list and name. This array will have appending linkage and is 1544 /// suitable for use as a LLVM constructor or destructor array. Clears Fns. 1545 void EmitCtorList(CtorList &Fns, const char *GlobalName); 1546 1547 /// Emit any needed decls for which code generation was deferred. 1548 void EmitDeferred(); 1549 1550 /// Try to emit external vtables as available_externally if they have emitted 1551 /// all inlined virtual functions. It runs after EmitDeferred() and therefore 1552 /// is not allowed to create new references to things that need to be emitted 1553 /// lazily. 1554 void EmitVTablesOpportunistically(); 1555 1556 /// Call replaceAllUsesWith on all pairs in Replacements. 1557 void applyReplacements(); 1558 1559 /// Call replaceAllUsesWith on all pairs in GlobalValReplacements. 1560 void applyGlobalValReplacements(); 1561 1562 void checkAliases(); 1563 1564 std::map<int, llvm::TinyPtrVector<llvm::Function *>> DtorsUsingAtExit; 1565 1566 /// Register functions annotated with __attribute__((destructor)) using 1567 /// __cxa_atexit, if it is available, or atexit otherwise. 1568 void registerGlobalDtorsWithAtExit(); 1569 1570 // When using sinit and sterm functions, unregister 1571 // __attribute__((destructor)) annotated functions which were previously 1572 // registered by the atexit subroutine using unatexit. 1573 void unregisterGlobalDtorsWithUnAtExit(); 1574 1575 /// Emit deferred multiversion function resolvers and associated variants. 1576 void emitMultiVersionFunctions(); 1577 1578 /// Emit any vtables which we deferred and still have a use for. 1579 void EmitDeferredVTables(); 1580 1581 /// Emit a dummy function that reference a CoreFoundation symbol when 1582 /// @available is used on Darwin. 1583 void emitAtAvailableLinkGuard(); 1584 1585 /// Emit the llvm.used and llvm.compiler.used metadata. 1586 void emitLLVMUsed(); 1587 1588 /// Emit the link options introduced by imported modules. 1589 void EmitModuleLinkOptions(); 1590 1591 /// Helper function for EmitStaticExternCAliases() to redirect ifuncs that 1592 /// have a resolver name that matches 'Elem' to instead resolve to the name of 1593 /// 'CppFunc'. This redirection is necessary in cases where 'Elem' has a name 1594 /// that will be emitted as an alias of the name bound to 'CppFunc'; ifuncs 1595 /// may not reference aliases. Redirection is only performed if 'Elem' is only 1596 /// used by ifuncs in which case, 'Elem' is destroyed. 'true' is returned if 1597 /// redirection is successful, and 'false' is returned otherwise. 1598 bool CheckAndReplaceExternCIFuncs(llvm::GlobalValue *Elem, 1599 llvm::GlobalValue *CppFunc); 1600 1601 /// Emit aliases for internal-linkage declarations inside "C" language 1602 /// linkage specifications, giving them the "expected" name where possible. 1603 void EmitStaticExternCAliases(); 1604 1605 void EmitDeclMetadata(); 1606 1607 /// Emit the Clang version as llvm.ident metadata. 1608 void EmitVersionIdentMetadata(); 1609 1610 /// Emit the Clang commandline as llvm.commandline metadata. 1611 void EmitCommandLineMetadata(); 1612 1613 /// Emit the module flag metadata used to pass options controlling the 1614 /// the backend to LLVM. 1615 void EmitBackendOptionsMetadata(const CodeGenOptions CodeGenOpts); 1616 1617 /// Emits OpenCL specific Metadata e.g. OpenCL version. 1618 void EmitOpenCLMetadata(); 1619 1620 /// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and 1621 /// .gcda files in a way that persists in .bc files. 1622 void EmitCoverageFile(); 1623 1624 /// Determine whether the definition must be emitted; if this returns \c 1625 /// false, the definition can be emitted lazily if it's used. 1626 bool MustBeEmitted(const ValueDecl *D); 1627 1628 /// Determine whether the definition can be emitted eagerly, or should be 1629 /// delayed until the end of the translation unit. This is relevant for 1630 /// definitions whose linkage can change, e.g. implicit function instantions 1631 /// which may later be explicitly instantiated. 1632 bool MayBeEmittedEagerly(const ValueDecl *D); 1633 1634 /// Check whether we can use a "simpler", more core exceptions personality 1635 /// function. 1636 void SimplifyPersonality(); 1637 1638 /// Helper function for ConstructAttributeList and 1639 /// addDefaultFunctionDefinitionAttributes. Builds a set of function 1640 /// attributes to add to a function with the given properties. 1641 void getDefaultFunctionAttributes(StringRef Name, bool HasOptnone, 1642 bool AttrOnCallSite, 1643 llvm::AttrBuilder &FuncAttrs); 1644 1645 llvm::Metadata *CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map, 1646 StringRef Suffix); 1647 }; 1648 1649 } // end namespace CodeGen 1650 } // end namespace clang 1651 1652 #endif // LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H 1653