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