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