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