10b57cec5SDimitry Andric //===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This is the internal per-translation-unit state used for llvm translation.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
140b57cec5SDimitry Andric #define LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include "CGVTables.h"
170b57cec5SDimitry Andric #include "CodeGenTypeCache.h"
180b57cec5SDimitry Andric #include "CodeGenTypes.h"
190b57cec5SDimitry Andric #include "SanitizerMetadata.h"
200b57cec5SDimitry Andric #include "clang/AST/DeclCXX.h"
210b57cec5SDimitry Andric #include "clang/AST/DeclObjC.h"
220b57cec5SDimitry Andric #include "clang/AST/DeclOpenMP.h"
230b57cec5SDimitry Andric #include "clang/AST/GlobalDecl.h"
240b57cec5SDimitry Andric #include "clang/AST/Mangle.h"
250b57cec5SDimitry Andric #include "clang/Basic/ABI.h"
260b57cec5SDimitry Andric #include "clang/Basic/LangOptions.h"
270b57cec5SDimitry Andric #include "clang/Basic/Module.h"
28*5f7ddb14SDimitry Andric #include "clang/Basic/NoSanitizeList.h"
295ffd83dbSDimitry Andric #include "clang/Basic/TargetInfo.h"
300b57cec5SDimitry Andric #include "clang/Basic/XRayLists.h"
31*5f7ddb14SDimitry Andric #include "clang/Lex/PreprocessorOptions.h"
320b57cec5SDimitry Andric #include "llvm/ADT/DenseMap.h"
330b57cec5SDimitry Andric #include "llvm/ADT/SetVector.h"
340b57cec5SDimitry Andric #include "llvm/ADT/SmallPtrSet.h"
350b57cec5SDimitry Andric #include "llvm/ADT/StringMap.h"
360b57cec5SDimitry Andric #include "llvm/IR/Module.h"
370b57cec5SDimitry Andric #include "llvm/IR/ValueHandle.h"
380b57cec5SDimitry Andric #include "llvm/Transforms/Utils/SanitizerStats.h"
390b57cec5SDimitry Andric 
400b57cec5SDimitry Andric namespace llvm {
410b57cec5SDimitry Andric class Module;
420b57cec5SDimitry Andric class Constant;
430b57cec5SDimitry Andric class ConstantInt;
440b57cec5SDimitry Andric class Function;
450b57cec5SDimitry Andric class GlobalValue;
460b57cec5SDimitry Andric class DataLayout;
470b57cec5SDimitry Andric class FunctionType;
480b57cec5SDimitry Andric class LLVMContext;
49480093f4SDimitry Andric class OpenMPIRBuilder;
500b57cec5SDimitry Andric class IndexedInstrProfReader;
510b57cec5SDimitry Andric }
520b57cec5SDimitry Andric 
530b57cec5SDimitry Andric namespace clang {
540b57cec5SDimitry Andric class ASTContext;
550b57cec5SDimitry Andric class AtomicType;
560b57cec5SDimitry Andric class FunctionDecl;
570b57cec5SDimitry Andric class IdentifierInfo;
580b57cec5SDimitry Andric class ObjCMethodDecl;
590b57cec5SDimitry Andric class ObjCImplementationDecl;
600b57cec5SDimitry Andric class ObjCCategoryImplDecl;
610b57cec5SDimitry Andric class ObjCProtocolDecl;
620b57cec5SDimitry Andric class ObjCEncodeExpr;
630b57cec5SDimitry Andric class BlockExpr;
640b57cec5SDimitry Andric class CharUnits;
650b57cec5SDimitry Andric class Decl;
660b57cec5SDimitry Andric class Expr;
670b57cec5SDimitry Andric class Stmt;
680b57cec5SDimitry Andric class InitListExpr;
690b57cec5SDimitry Andric class StringLiteral;
700b57cec5SDimitry Andric class NamedDecl;
710b57cec5SDimitry Andric class ValueDecl;
720b57cec5SDimitry Andric class VarDecl;
730b57cec5SDimitry Andric class LangOptions;
740b57cec5SDimitry Andric class CodeGenOptions;
750b57cec5SDimitry Andric class HeaderSearchOptions;
760b57cec5SDimitry Andric class DiagnosticsEngine;
770b57cec5SDimitry Andric class AnnotateAttr;
780b57cec5SDimitry Andric class CXXDestructorDecl;
790b57cec5SDimitry Andric class Module;
800b57cec5SDimitry Andric class CoverageSourceInfo;
81480093f4SDimitry Andric class TargetAttr;
82480093f4SDimitry Andric class InitSegAttr;
83480093f4SDimitry Andric struct ParsedTargetAttr;
840b57cec5SDimitry Andric 
850b57cec5SDimitry Andric namespace CodeGen {
860b57cec5SDimitry Andric 
870b57cec5SDimitry Andric class CallArgList;
880b57cec5SDimitry Andric class CodeGenFunction;
890b57cec5SDimitry Andric class CodeGenTBAA;
900b57cec5SDimitry Andric class CGCXXABI;
910b57cec5SDimitry Andric class CGDebugInfo;
920b57cec5SDimitry Andric class CGObjCRuntime;
930b57cec5SDimitry Andric class CGOpenCLRuntime;
940b57cec5SDimitry Andric class CGOpenMPRuntime;
950b57cec5SDimitry Andric class CGCUDARuntime;
960b57cec5SDimitry Andric class BlockFieldFlags;
970b57cec5SDimitry Andric class FunctionArgList;
980b57cec5SDimitry Andric class CoverageMappingModuleGen;
990b57cec5SDimitry Andric class TargetCodeGenInfo;
1000b57cec5SDimitry Andric 
1010b57cec5SDimitry Andric enum ForDefinition_t : bool {
1020b57cec5SDimitry Andric   NotForDefinition = false,
1030b57cec5SDimitry Andric   ForDefinition = true
1040b57cec5SDimitry Andric };
1050b57cec5SDimitry Andric 
106*5f7ddb14SDimitry Andric struct OrderGlobalInitsOrStermFinalizers {
1070b57cec5SDimitry Andric   unsigned int priority;
1080b57cec5SDimitry Andric   unsigned int lex_order;
OrderGlobalInitsOrStermFinalizersOrderGlobalInitsOrStermFinalizers109*5f7ddb14SDimitry Andric   OrderGlobalInitsOrStermFinalizers(unsigned int p, unsigned int l)
1100b57cec5SDimitry Andric       : priority(p), lex_order(l) {}
1110b57cec5SDimitry Andric 
112*5f7ddb14SDimitry Andric   bool operator==(const OrderGlobalInitsOrStermFinalizers &RHS) const {
1130b57cec5SDimitry Andric     return priority == RHS.priority && lex_order == RHS.lex_order;
1140b57cec5SDimitry Andric   }
1150b57cec5SDimitry Andric 
116*5f7ddb14SDimitry Andric   bool operator<(const OrderGlobalInitsOrStermFinalizers &RHS) const {
1170b57cec5SDimitry Andric     return std::tie(priority, lex_order) <
1180b57cec5SDimitry Andric            std::tie(RHS.priority, RHS.lex_order);
1190b57cec5SDimitry Andric   }
1200b57cec5SDimitry Andric };
1210b57cec5SDimitry Andric 
1220b57cec5SDimitry Andric struct ObjCEntrypoints {
ObjCEntrypointsObjCEntrypoints1230b57cec5SDimitry Andric   ObjCEntrypoints() { memset(this, 0, sizeof(*this)); }
1240b57cec5SDimitry Andric 
1250b57cec5SDimitry Andric   /// void objc_alloc(id);
1260b57cec5SDimitry Andric   llvm::FunctionCallee objc_alloc;
1270b57cec5SDimitry Andric 
1280b57cec5SDimitry Andric   /// void objc_allocWithZone(id);
1290b57cec5SDimitry Andric   llvm::FunctionCallee objc_allocWithZone;
1300b57cec5SDimitry Andric 
1310b57cec5SDimitry Andric   /// void objc_alloc_init(id);
1320b57cec5SDimitry Andric   llvm::FunctionCallee objc_alloc_init;
1330b57cec5SDimitry Andric 
1340b57cec5SDimitry Andric   /// void objc_autoreleasePoolPop(void*);
1350b57cec5SDimitry Andric   llvm::FunctionCallee objc_autoreleasePoolPop;
1360b57cec5SDimitry Andric 
1370b57cec5SDimitry Andric   /// void objc_autoreleasePoolPop(void*);
1380b57cec5SDimitry Andric   /// Note this method is used when we are using exception handling
1390b57cec5SDimitry Andric   llvm::FunctionCallee objc_autoreleasePoolPopInvoke;
1400b57cec5SDimitry Andric 
1410b57cec5SDimitry Andric   /// void *objc_autoreleasePoolPush(void);
1420b57cec5SDimitry Andric   llvm::Function *objc_autoreleasePoolPush;
1430b57cec5SDimitry Andric 
1440b57cec5SDimitry Andric   /// id objc_autorelease(id);
1450b57cec5SDimitry Andric   llvm::Function *objc_autorelease;
1460b57cec5SDimitry Andric 
1470b57cec5SDimitry Andric   /// id objc_autorelease(id);
1480b57cec5SDimitry Andric   /// Note this is the runtime method not the intrinsic.
1490b57cec5SDimitry Andric   llvm::FunctionCallee objc_autoreleaseRuntimeFunction;
1500b57cec5SDimitry Andric 
1510b57cec5SDimitry Andric   /// id objc_autoreleaseReturnValue(id);
1520b57cec5SDimitry Andric   llvm::Function *objc_autoreleaseReturnValue;
1530b57cec5SDimitry Andric 
1540b57cec5SDimitry Andric   /// void objc_copyWeak(id *dest, id *src);
1550b57cec5SDimitry Andric   llvm::Function *objc_copyWeak;
1560b57cec5SDimitry Andric 
1570b57cec5SDimitry Andric   /// void objc_destroyWeak(id*);
1580b57cec5SDimitry Andric   llvm::Function *objc_destroyWeak;
1590b57cec5SDimitry Andric 
1600b57cec5SDimitry Andric   /// id objc_initWeak(id*, id);
1610b57cec5SDimitry Andric   llvm::Function *objc_initWeak;
1620b57cec5SDimitry Andric 
1630b57cec5SDimitry Andric   /// id objc_loadWeak(id*);
1640b57cec5SDimitry Andric   llvm::Function *objc_loadWeak;
1650b57cec5SDimitry Andric 
1660b57cec5SDimitry Andric   /// id objc_loadWeakRetained(id*);
1670b57cec5SDimitry Andric   llvm::Function *objc_loadWeakRetained;
1680b57cec5SDimitry Andric 
1690b57cec5SDimitry Andric   /// void objc_moveWeak(id *dest, id *src);
1700b57cec5SDimitry Andric   llvm::Function *objc_moveWeak;
1710b57cec5SDimitry Andric 
1720b57cec5SDimitry Andric   /// id objc_retain(id);
1730b57cec5SDimitry Andric   llvm::Function *objc_retain;
1740b57cec5SDimitry Andric 
1750b57cec5SDimitry Andric   /// id objc_retain(id);
1760b57cec5SDimitry Andric   /// Note this is the runtime method not the intrinsic.
1770b57cec5SDimitry Andric   llvm::FunctionCallee objc_retainRuntimeFunction;
1780b57cec5SDimitry Andric 
1790b57cec5SDimitry Andric   /// id objc_retainAutorelease(id);
1800b57cec5SDimitry Andric   llvm::Function *objc_retainAutorelease;
1810b57cec5SDimitry Andric 
1820b57cec5SDimitry Andric   /// id objc_retainAutoreleaseReturnValue(id);
1830b57cec5SDimitry Andric   llvm::Function *objc_retainAutoreleaseReturnValue;
1840b57cec5SDimitry Andric 
1850b57cec5SDimitry Andric   /// id objc_retainAutoreleasedReturnValue(id);
1860b57cec5SDimitry Andric   llvm::Function *objc_retainAutoreleasedReturnValue;
1870b57cec5SDimitry Andric 
1880b57cec5SDimitry Andric   /// id objc_retainBlock(id);
1890b57cec5SDimitry Andric   llvm::Function *objc_retainBlock;
1900b57cec5SDimitry Andric 
1910b57cec5SDimitry Andric   /// void objc_release(id);
1920b57cec5SDimitry Andric   llvm::Function *objc_release;
1930b57cec5SDimitry Andric 
1940b57cec5SDimitry Andric   /// void objc_release(id);
1950b57cec5SDimitry Andric   /// Note this is the runtime method not the intrinsic.
1960b57cec5SDimitry Andric   llvm::FunctionCallee objc_releaseRuntimeFunction;
1970b57cec5SDimitry Andric 
1980b57cec5SDimitry Andric   /// void objc_storeStrong(id*, id);
1990b57cec5SDimitry Andric   llvm::Function *objc_storeStrong;
2000b57cec5SDimitry Andric 
2010b57cec5SDimitry Andric   /// id objc_storeWeak(id*, id);
2020b57cec5SDimitry Andric   llvm::Function *objc_storeWeak;
2030b57cec5SDimitry Andric 
2040b57cec5SDimitry Andric   /// id objc_unsafeClaimAutoreleasedReturnValue(id);
2050b57cec5SDimitry Andric   llvm::Function *objc_unsafeClaimAutoreleasedReturnValue;
2060b57cec5SDimitry Andric 
2070b57cec5SDimitry Andric   /// A void(void) inline asm to use to mark that the return value of
2080b57cec5SDimitry Andric   /// a call will be immediately retain.
2090b57cec5SDimitry Andric   llvm::InlineAsm *retainAutoreleasedReturnValueMarker;
2100b57cec5SDimitry Andric 
2110b57cec5SDimitry Andric   /// void clang.arc.use(...);
2120b57cec5SDimitry Andric   llvm::Function *clang_arc_use;
213*5f7ddb14SDimitry Andric 
214*5f7ddb14SDimitry Andric   /// void clang.arc.noop.use(...);
215*5f7ddb14SDimitry Andric   llvm::Function *clang_arc_noop_use;
2160b57cec5SDimitry Andric };
2170b57cec5SDimitry Andric 
2180b57cec5SDimitry Andric /// This class records statistics on instrumentation based profiling.
2190b57cec5SDimitry Andric class InstrProfStats {
2200b57cec5SDimitry Andric   uint32_t VisitedInMainFile;
2210b57cec5SDimitry Andric   uint32_t MissingInMainFile;
2220b57cec5SDimitry Andric   uint32_t Visited;
2230b57cec5SDimitry Andric   uint32_t Missing;
2240b57cec5SDimitry Andric   uint32_t Mismatched;
2250b57cec5SDimitry Andric 
2260b57cec5SDimitry Andric public:
InstrProfStats()2270b57cec5SDimitry Andric   InstrProfStats()
2280b57cec5SDimitry Andric       : VisitedInMainFile(0), MissingInMainFile(0), Visited(0), Missing(0),
2290b57cec5SDimitry Andric         Mismatched(0) {}
2300b57cec5SDimitry Andric   /// Record that we've visited a function and whether or not that function was
2310b57cec5SDimitry Andric   /// in the main source file.
addVisited(bool MainFile)2320b57cec5SDimitry Andric   void addVisited(bool MainFile) {
2330b57cec5SDimitry Andric     if (MainFile)
2340b57cec5SDimitry Andric       ++VisitedInMainFile;
2350b57cec5SDimitry Andric     ++Visited;
2360b57cec5SDimitry Andric   }
2370b57cec5SDimitry Andric   /// Record that a function we've visited has no profile data.
addMissing(bool MainFile)2380b57cec5SDimitry Andric   void addMissing(bool MainFile) {
2390b57cec5SDimitry Andric     if (MainFile)
2400b57cec5SDimitry Andric       ++MissingInMainFile;
2410b57cec5SDimitry Andric     ++Missing;
2420b57cec5SDimitry Andric   }
2430b57cec5SDimitry Andric   /// Record that a function we've visited has mismatched profile data.
addMismatched(bool MainFile)2440b57cec5SDimitry Andric   void addMismatched(bool MainFile) { ++Mismatched; }
2450b57cec5SDimitry Andric   /// Whether or not the stats we've gathered indicate any potential problems.
hasDiagnostics()2460b57cec5SDimitry Andric   bool hasDiagnostics() { return Missing || Mismatched; }
2470b57cec5SDimitry Andric   /// Report potential problems we've found to \c Diags.
2480b57cec5SDimitry Andric   void reportDiagnostics(DiagnosticsEngine &Diags, StringRef MainFile);
2490b57cec5SDimitry Andric };
2500b57cec5SDimitry Andric 
2510b57cec5SDimitry Andric /// A pair of helper functions for a __block variable.
2520b57cec5SDimitry Andric class BlockByrefHelpers : public llvm::FoldingSetNode {
2530b57cec5SDimitry Andric   // MSVC requires this type to be complete in order to process this
2540b57cec5SDimitry Andric   // header.
2550b57cec5SDimitry Andric public:
2560b57cec5SDimitry Andric   llvm::Constant *CopyHelper;
2570b57cec5SDimitry Andric   llvm::Constant *DisposeHelper;
2580b57cec5SDimitry Andric 
2590b57cec5SDimitry Andric   /// The alignment of the field.  This is important because
2600b57cec5SDimitry Andric   /// different offsets to the field within the byref struct need to
2610b57cec5SDimitry Andric   /// have different helper functions.
2620b57cec5SDimitry Andric   CharUnits Alignment;
2630b57cec5SDimitry Andric 
BlockByrefHelpers(CharUnits alignment)2640b57cec5SDimitry Andric   BlockByrefHelpers(CharUnits alignment)
2650b57cec5SDimitry Andric       : CopyHelper(nullptr), DisposeHelper(nullptr), Alignment(alignment) {}
2660b57cec5SDimitry Andric   BlockByrefHelpers(const BlockByrefHelpers &) = default;
2670b57cec5SDimitry Andric   virtual ~BlockByrefHelpers();
2680b57cec5SDimitry Andric 
Profile(llvm::FoldingSetNodeID & id)2690b57cec5SDimitry Andric   void Profile(llvm::FoldingSetNodeID &id) const {
2700b57cec5SDimitry Andric     id.AddInteger(Alignment.getQuantity());
2710b57cec5SDimitry Andric     profileImpl(id);
2720b57cec5SDimitry Andric   }
2730b57cec5SDimitry Andric   virtual void profileImpl(llvm::FoldingSetNodeID &id) const = 0;
2740b57cec5SDimitry Andric 
needsCopy()2750b57cec5SDimitry Andric   virtual bool needsCopy() const { return true; }
2760b57cec5SDimitry Andric   virtual void emitCopy(CodeGenFunction &CGF, Address dest, Address src) = 0;
2770b57cec5SDimitry Andric 
needsDispose()2780b57cec5SDimitry Andric   virtual bool needsDispose() const { return true; }
2790b57cec5SDimitry Andric   virtual void emitDispose(CodeGenFunction &CGF, Address field) = 0;
2800b57cec5SDimitry Andric };
2810b57cec5SDimitry Andric 
2820b57cec5SDimitry Andric /// This class organizes the cross-function state that is used while generating
2830b57cec5SDimitry Andric /// LLVM code.
2840b57cec5SDimitry Andric class CodeGenModule : public CodeGenTypeCache {
2850b57cec5SDimitry Andric   CodeGenModule(const CodeGenModule &) = delete;
2860b57cec5SDimitry Andric   void operator=(const CodeGenModule &) = delete;
2870b57cec5SDimitry Andric 
2880b57cec5SDimitry Andric public:
2890b57cec5SDimitry Andric   struct Structor {
StructorStructor2900b57cec5SDimitry Andric     Structor() : Priority(0), Initializer(nullptr), AssociatedData(nullptr) {}
StructorStructor2910b57cec5SDimitry Andric     Structor(int Priority, llvm::Constant *Initializer,
2920b57cec5SDimitry Andric              llvm::Constant *AssociatedData)
2930b57cec5SDimitry Andric         : Priority(Priority), Initializer(Initializer),
2940b57cec5SDimitry Andric           AssociatedData(AssociatedData) {}
2950b57cec5SDimitry Andric     int Priority;
2960b57cec5SDimitry Andric     llvm::Constant *Initializer;
2970b57cec5SDimitry Andric     llvm::Constant *AssociatedData;
2980b57cec5SDimitry Andric   };
2990b57cec5SDimitry Andric 
3000b57cec5SDimitry Andric   typedef std::vector<Structor> CtorList;
3010b57cec5SDimitry Andric 
3020b57cec5SDimitry Andric private:
3030b57cec5SDimitry Andric   ASTContext &Context;
3040b57cec5SDimitry Andric   const LangOptions &LangOpts;
3050b57cec5SDimitry Andric   const HeaderSearchOptions &HeaderSearchOpts; // Only used for debug info.
3060b57cec5SDimitry Andric   const PreprocessorOptions &PreprocessorOpts; // Only used for debug info.
3070b57cec5SDimitry Andric   const CodeGenOptions &CodeGenOpts;
3085ffd83dbSDimitry Andric   unsigned NumAutoVarInit = 0;
3090b57cec5SDimitry Andric   llvm::Module &TheModule;
3100b57cec5SDimitry Andric   DiagnosticsEngine &Diags;
3110b57cec5SDimitry Andric   const TargetInfo &Target;
3120b57cec5SDimitry Andric   std::unique_ptr<CGCXXABI> ABI;
3130b57cec5SDimitry Andric   llvm::LLVMContext &VMContext;
314*5f7ddb14SDimitry Andric   std::string ModuleNameHash = "";
3150b57cec5SDimitry Andric 
3160b57cec5SDimitry Andric   std::unique_ptr<CodeGenTBAA> TBAA;
3170b57cec5SDimitry Andric 
3180b57cec5SDimitry Andric   mutable std::unique_ptr<TargetCodeGenInfo> TheTargetCodeGenInfo;
3190b57cec5SDimitry Andric 
3200b57cec5SDimitry Andric   // This should not be moved earlier, since its initialization depends on some
3210b57cec5SDimitry Andric   // of the previous reference members being already initialized and also checks
3220b57cec5SDimitry Andric   // if TheTargetCodeGenInfo is NULL
3230b57cec5SDimitry Andric   CodeGenTypes Types;
3240b57cec5SDimitry Andric 
3250b57cec5SDimitry Andric   /// Holds information about C++ vtables.
3260b57cec5SDimitry Andric   CodeGenVTables VTables;
3270b57cec5SDimitry Andric 
3280b57cec5SDimitry Andric   std::unique_ptr<CGObjCRuntime> ObjCRuntime;
3290b57cec5SDimitry Andric   std::unique_ptr<CGOpenCLRuntime> OpenCLRuntime;
3300b57cec5SDimitry Andric   std::unique_ptr<CGOpenMPRuntime> OpenMPRuntime;
3310b57cec5SDimitry Andric   std::unique_ptr<CGCUDARuntime> CUDARuntime;
3320b57cec5SDimitry Andric   std::unique_ptr<CGDebugInfo> DebugInfo;
3330b57cec5SDimitry Andric   std::unique_ptr<ObjCEntrypoints> ObjCData;
3340b57cec5SDimitry Andric   llvm::MDNode *NoObjCARCExceptionsMetadata = nullptr;
3350b57cec5SDimitry Andric   std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader;
3360b57cec5SDimitry Andric   InstrProfStats PGOStats;
3370b57cec5SDimitry Andric   std::unique_ptr<llvm::SanitizerStatReport> SanStats;
3380b57cec5SDimitry Andric 
3390b57cec5SDimitry Andric   // A set of references that have only been seen via a weakref so far. This is
3400b57cec5SDimitry Andric   // used to remove the weak of the reference if we ever see a direct reference
3410b57cec5SDimitry Andric   // or a definition.
3420b57cec5SDimitry Andric   llvm::SmallPtrSet<llvm::GlobalValue*, 10> WeakRefReferences;
3430b57cec5SDimitry Andric 
3440b57cec5SDimitry Andric   /// This contains all the decls which have definitions but/ which are deferred
3450b57cec5SDimitry Andric   /// for emission and therefore should only be output if they are actually
3460b57cec5SDimitry Andric   /// used. If a decl is in this, then it is known to have not been referenced
3470b57cec5SDimitry Andric   /// yet.
3480b57cec5SDimitry Andric   std::map<StringRef, GlobalDecl> DeferredDecls;
3490b57cec5SDimitry Andric 
3500b57cec5SDimitry Andric   /// This is a list of deferred decls which we have seen that *are* actually
3510b57cec5SDimitry Andric   /// referenced. These get code generated when the module is done.
3520b57cec5SDimitry Andric   std::vector<GlobalDecl> DeferredDeclsToEmit;
addDeferredDeclToEmit(GlobalDecl GD)3530b57cec5SDimitry Andric   void addDeferredDeclToEmit(GlobalDecl GD) {
3540b57cec5SDimitry Andric     DeferredDeclsToEmit.emplace_back(GD);
3550b57cec5SDimitry Andric   }
3560b57cec5SDimitry Andric 
3570b57cec5SDimitry Andric   /// List of alias we have emitted. Used to make sure that what they point to
3580b57cec5SDimitry Andric   /// is defined once we get to the end of the of the translation unit.
3590b57cec5SDimitry Andric   std::vector<GlobalDecl> Aliases;
3600b57cec5SDimitry Andric 
3610b57cec5SDimitry Andric   /// List of multiversion functions that have to be emitted.  Used to make sure
3620b57cec5SDimitry Andric   /// we properly emit the iFunc.
3630b57cec5SDimitry Andric   std::vector<GlobalDecl> MultiVersionFuncs;
3640b57cec5SDimitry Andric 
3650b57cec5SDimitry Andric   typedef llvm::StringMap<llvm::TrackingVH<llvm::Constant> > ReplacementsTy;
3660b57cec5SDimitry Andric   ReplacementsTy Replacements;
3670b57cec5SDimitry Andric 
3680b57cec5SDimitry Andric   /// List of global values to be replaced with something else. Used when we
3690b57cec5SDimitry Andric   /// want to replace a GlobalValue but can't identify it by its mangled name
3700b57cec5SDimitry Andric   /// anymore (because the name is already taken).
3710b57cec5SDimitry Andric   llvm::SmallVector<std::pair<llvm::GlobalValue *, llvm::Constant *>, 8>
3720b57cec5SDimitry Andric     GlobalValReplacements;
3730b57cec5SDimitry Andric 
3740b57cec5SDimitry Andric   /// Variables for which we've emitted globals containing their constant
3750b57cec5SDimitry Andric   /// values along with the corresponding globals, for opportunistic reuse.
3760b57cec5SDimitry Andric   llvm::DenseMap<const VarDecl*, llvm::GlobalVariable*> InitializerConstants;
3770b57cec5SDimitry Andric 
3780b57cec5SDimitry Andric   /// Set of global decls for which we already diagnosed mangled name conflict.
3790b57cec5SDimitry Andric   /// Required to not issue a warning (on a mangling conflict) multiple times
3800b57cec5SDimitry Andric   /// for the same decl.
3810b57cec5SDimitry Andric   llvm::DenseSet<GlobalDecl> DiagnosedConflictingDefinitions;
3820b57cec5SDimitry Andric 
3830b57cec5SDimitry Andric   /// A queue of (optional) vtables to consider emitting.
3840b57cec5SDimitry Andric   std::vector<const CXXRecordDecl*> DeferredVTables;
3850b57cec5SDimitry Andric 
3860b57cec5SDimitry Andric   /// A queue of (optional) vtables that may be emitted opportunistically.
3870b57cec5SDimitry Andric   std::vector<const CXXRecordDecl *> OpportunisticVTables;
3880b57cec5SDimitry Andric 
3890b57cec5SDimitry Andric   /// List of global values which are required to be present in the object file;
3900b57cec5SDimitry Andric   /// bitcast to i8*. This is used for forcing visibility of symbols which may
3910b57cec5SDimitry Andric   /// otherwise be optimized out.
3920b57cec5SDimitry Andric   std::vector<llvm::WeakTrackingVH> LLVMUsed;
3930b57cec5SDimitry Andric   std::vector<llvm::WeakTrackingVH> LLVMCompilerUsed;
3940b57cec5SDimitry Andric 
3950b57cec5SDimitry Andric   /// Store the list of global constructors and their respective priorities to
3960b57cec5SDimitry Andric   /// be emitted when the translation unit is complete.
3970b57cec5SDimitry Andric   CtorList GlobalCtors;
3980b57cec5SDimitry Andric 
3990b57cec5SDimitry Andric   /// Store the list of global destructors and their respective priorities to be
4000b57cec5SDimitry Andric   /// emitted when the translation unit is complete.
4010b57cec5SDimitry Andric   CtorList GlobalDtors;
4020b57cec5SDimitry Andric 
4030b57cec5SDimitry Andric   /// An ordered map of canonical GlobalDecls to their mangled names.
4040b57cec5SDimitry Andric   llvm::MapVector<GlobalDecl, StringRef> MangledDeclNames;
4050b57cec5SDimitry Andric   llvm::StringMap<GlobalDecl, llvm::BumpPtrAllocator> Manglings;
4060b57cec5SDimitry Andric 
4070b57cec5SDimitry Andric   // An ordered map of canonical GlobalDecls paired with the cpu-index for
4080b57cec5SDimitry Andric   // cpu-specific name manglings.
4090b57cec5SDimitry Andric   llvm::MapVector<std::pair<GlobalDecl, unsigned>, StringRef>
4100b57cec5SDimitry Andric       CPUSpecificMangledDeclNames;
4110b57cec5SDimitry Andric   llvm::StringMap<std::pair<GlobalDecl, unsigned>, llvm::BumpPtrAllocator>
4120b57cec5SDimitry Andric       CPUSpecificManglings;
4130b57cec5SDimitry Andric 
4140b57cec5SDimitry Andric   /// Global annotations.
4150b57cec5SDimitry Andric   std::vector<llvm::Constant*> Annotations;
4160b57cec5SDimitry Andric 
4170b57cec5SDimitry Andric   /// Map used to get unique annotation strings.
4180b57cec5SDimitry Andric   llvm::StringMap<llvm::Constant*> AnnotationStrings;
4190b57cec5SDimitry Andric 
420af732203SDimitry Andric   /// Used for uniquing of annotation arguments.
421af732203SDimitry Andric   llvm::DenseMap<unsigned, llvm::Constant *> AnnotationArgs;
422af732203SDimitry Andric 
4230b57cec5SDimitry Andric   llvm::StringMap<llvm::GlobalVariable *> CFConstantStringMap;
4240b57cec5SDimitry Andric 
4250b57cec5SDimitry Andric   llvm::DenseMap<llvm::Constant *, llvm::GlobalVariable *> ConstantStringMap;
4260b57cec5SDimitry Andric   llvm::DenseMap<const Decl*, llvm::Constant *> StaticLocalDeclMap;
4270b57cec5SDimitry Andric   llvm::DenseMap<const Decl*, llvm::GlobalVariable*> StaticLocalDeclGuardMap;
4280b57cec5SDimitry Andric   llvm::DenseMap<const Expr*, llvm::Constant *> MaterializedGlobalTemporaryMap;
4290b57cec5SDimitry Andric 
4300b57cec5SDimitry Andric   llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap;
4310b57cec5SDimitry Andric   llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap;
4320b57cec5SDimitry Andric 
4330b57cec5SDimitry Andric   /// Map used to get unique type descriptor constants for sanitizers.
4340b57cec5SDimitry Andric   llvm::DenseMap<QualType, llvm::Constant *> TypeDescriptorMap;
4350b57cec5SDimitry Andric 
4360b57cec5SDimitry Andric   /// Map used to track internal linkage functions declared within
4370b57cec5SDimitry Andric   /// extern "C" regions.
4380b57cec5SDimitry Andric   typedef llvm::MapVector<IdentifierInfo *,
4390b57cec5SDimitry Andric                           llvm::GlobalValue *> StaticExternCMap;
4400b57cec5SDimitry Andric   StaticExternCMap StaticExternCValues;
4410b57cec5SDimitry Andric 
4420b57cec5SDimitry Andric   /// thread_local variables defined or used in this TU.
4430b57cec5SDimitry Andric   std::vector<const VarDecl *> CXXThreadLocals;
4440b57cec5SDimitry Andric 
4450b57cec5SDimitry Andric   /// thread_local variables with initializers that need to run
4460b57cec5SDimitry Andric   /// before any thread_local variable in this TU is odr-used.
4470b57cec5SDimitry Andric   std::vector<llvm::Function *> CXXThreadLocalInits;
4480b57cec5SDimitry Andric   std::vector<const VarDecl *> CXXThreadLocalInitVars;
4490b57cec5SDimitry Andric 
4500b57cec5SDimitry Andric   /// Global variables with initializers that need to run before main.
4510b57cec5SDimitry Andric   std::vector<llvm::Function *> CXXGlobalInits;
4520b57cec5SDimitry Andric 
4530b57cec5SDimitry Andric   /// When a C++ decl with an initializer is deferred, null is
4540b57cec5SDimitry Andric   /// appended to CXXGlobalInits, and the index of that null is placed
4550b57cec5SDimitry Andric   /// here so that the initializer will be performed in the correct
4560b57cec5SDimitry Andric   /// order. Once the decl is emitted, the index is replaced with ~0U to ensure
4570b57cec5SDimitry Andric   /// that we don't re-emit the initializer.
4580b57cec5SDimitry Andric   llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition;
4590b57cec5SDimitry Andric 
460*5f7ddb14SDimitry Andric   typedef std::pair<OrderGlobalInitsOrStermFinalizers, llvm::Function *>
461*5f7ddb14SDimitry Andric       GlobalInitData;
4620b57cec5SDimitry Andric 
4630b57cec5SDimitry Andric   struct GlobalInitPriorityCmp {
operatorGlobalInitPriorityCmp4640b57cec5SDimitry Andric     bool operator()(const GlobalInitData &LHS,
4650b57cec5SDimitry Andric                     const GlobalInitData &RHS) const {
4660b57cec5SDimitry Andric       return LHS.first.priority < RHS.first.priority;
4670b57cec5SDimitry Andric     }
4680b57cec5SDimitry Andric   };
4690b57cec5SDimitry Andric 
4700b57cec5SDimitry Andric   /// Global variables with initializers whose order of initialization is set by
4710b57cec5SDimitry Andric   /// init_priority attribute.
4720b57cec5SDimitry Andric   SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits;
4730b57cec5SDimitry Andric 
4740b57cec5SDimitry Andric   /// Global destructor functions and arguments that need to run on termination.
4755ffd83dbSDimitry Andric   /// When UseSinitAndSterm is set, it instead contains sterm finalizer
4765ffd83dbSDimitry Andric   /// functions, which also run on unloading a shared library.
477*5f7ddb14SDimitry Andric   typedef std::tuple<llvm::FunctionType *, llvm::WeakTrackingVH,
478*5f7ddb14SDimitry Andric                      llvm::Constant *>
479*5f7ddb14SDimitry Andric       CXXGlobalDtorsOrStermFinalizer_t;
480*5f7ddb14SDimitry Andric   SmallVector<CXXGlobalDtorsOrStermFinalizer_t, 8>
4815ffd83dbSDimitry Andric       CXXGlobalDtorsOrStermFinalizers;
4820b57cec5SDimitry Andric 
483*5f7ddb14SDimitry Andric   typedef std::pair<OrderGlobalInitsOrStermFinalizers, llvm::Function *>
484*5f7ddb14SDimitry Andric       StermFinalizerData;
485*5f7ddb14SDimitry Andric 
486*5f7ddb14SDimitry Andric   struct StermFinalizerPriorityCmp {
operatorStermFinalizerPriorityCmp487*5f7ddb14SDimitry Andric     bool operator()(const StermFinalizerData &LHS,
488*5f7ddb14SDimitry Andric                     const StermFinalizerData &RHS) const {
489*5f7ddb14SDimitry Andric       return LHS.first.priority < RHS.first.priority;
490*5f7ddb14SDimitry Andric     }
491*5f7ddb14SDimitry Andric   };
492*5f7ddb14SDimitry Andric 
493*5f7ddb14SDimitry Andric   /// Global variables with sterm finalizers whose order of initialization is
494*5f7ddb14SDimitry Andric   /// set by init_priority attribute.
495*5f7ddb14SDimitry Andric   SmallVector<StermFinalizerData, 8> PrioritizedCXXStermFinalizers;
496*5f7ddb14SDimitry Andric 
4970b57cec5SDimitry Andric   /// The complete set of modules that has been imported.
4980b57cec5SDimitry Andric   llvm::SetVector<clang::Module *> ImportedModules;
4990b57cec5SDimitry Andric 
5000b57cec5SDimitry Andric   /// The set of modules for which the module initializers
5010b57cec5SDimitry Andric   /// have been emitted.
5020b57cec5SDimitry Andric   llvm::SmallPtrSet<clang::Module *, 16> EmittedModuleInitializers;
5030b57cec5SDimitry Andric 
5040b57cec5SDimitry Andric   /// A vector of metadata strings for linker options.
5050b57cec5SDimitry Andric   SmallVector<llvm::MDNode *, 16> LinkerOptionsMetadata;
5060b57cec5SDimitry Andric 
5070b57cec5SDimitry Andric   /// A vector of metadata strings for dependent libraries for ELF.
5080b57cec5SDimitry Andric   SmallVector<llvm::MDNode *, 16> ELFDependentLibraries;
5090b57cec5SDimitry Andric 
5100b57cec5SDimitry Andric   /// @name Cache for Objective-C runtime types
5110b57cec5SDimitry Andric   /// @{
5120b57cec5SDimitry Andric 
5130b57cec5SDimitry Andric   /// Cached reference to the class for constant strings. This value has type
5140b57cec5SDimitry Andric   /// int * but is actually an Obj-C class pointer.
5150b57cec5SDimitry Andric   llvm::WeakTrackingVH CFConstantStringClassRef;
5160b57cec5SDimitry Andric 
5170b57cec5SDimitry Andric   /// The type used to describe the state of a fast enumeration in
5180b57cec5SDimitry Andric   /// Objective-C's for..in loop.
5190b57cec5SDimitry Andric   QualType ObjCFastEnumerationStateType;
5200b57cec5SDimitry Andric 
5210b57cec5SDimitry Andric   /// @}
5220b57cec5SDimitry Andric 
5230b57cec5SDimitry Andric   /// Lazily create the Objective-C runtime
5240b57cec5SDimitry Andric   void createObjCRuntime();
5250b57cec5SDimitry Andric 
5260b57cec5SDimitry Andric   void createOpenCLRuntime();
5270b57cec5SDimitry Andric   void createOpenMPRuntime();
5280b57cec5SDimitry Andric   void createCUDARuntime();
5290b57cec5SDimitry Andric 
5300b57cec5SDimitry Andric   bool isTriviallyRecursive(const FunctionDecl *F);
5310b57cec5SDimitry Andric   bool shouldEmitFunction(GlobalDecl GD);
5320b57cec5SDimitry Andric   bool shouldOpportunisticallyEmitVTables();
5330b57cec5SDimitry Andric   /// Map used to be sure we don't emit the same CompoundLiteral twice.
5340b57cec5SDimitry Andric   llvm::DenseMap<const CompoundLiteralExpr *, llvm::GlobalVariable *>
5350b57cec5SDimitry Andric       EmittedCompoundLiterals;
5360b57cec5SDimitry Andric 
5370b57cec5SDimitry Andric   /// Map of the global blocks we've emitted, so that we don't have to re-emit
5380b57cec5SDimitry Andric   /// them if the constexpr evaluator gets aggressive.
5390b57cec5SDimitry Andric   llvm::DenseMap<const BlockExpr *, llvm::Constant *> EmittedGlobalBlocks;
5400b57cec5SDimitry Andric 
5410b57cec5SDimitry Andric   /// @name Cache for Blocks Runtime Globals
5420b57cec5SDimitry Andric   /// @{
5430b57cec5SDimitry Andric 
5440b57cec5SDimitry Andric   llvm::Constant *NSConcreteGlobalBlock = nullptr;
5450b57cec5SDimitry Andric   llvm::Constant *NSConcreteStackBlock = nullptr;
5460b57cec5SDimitry Andric 
5470b57cec5SDimitry Andric   llvm::FunctionCallee BlockObjectAssign = nullptr;
5480b57cec5SDimitry Andric   llvm::FunctionCallee BlockObjectDispose = nullptr;
5490b57cec5SDimitry Andric 
5500b57cec5SDimitry Andric   llvm::Type *BlockDescriptorType = nullptr;
5510b57cec5SDimitry Andric   llvm::Type *GenericBlockLiteralType = nullptr;
5520b57cec5SDimitry Andric 
5530b57cec5SDimitry Andric   struct {
5540b57cec5SDimitry Andric     int GlobalUniqueCount;
5550b57cec5SDimitry Andric   } Block;
5560b57cec5SDimitry Andric 
557480093f4SDimitry Andric   GlobalDecl initializedGlobalDecl;
558480093f4SDimitry Andric 
559480093f4SDimitry Andric   /// @}
560480093f4SDimitry Andric 
5610b57cec5SDimitry Andric   /// void @llvm.lifetime.start(i64 %size, i8* nocapture <ptr>)
5620b57cec5SDimitry Andric   llvm::Function *LifetimeStartFn = nullptr;
5630b57cec5SDimitry Andric 
5640b57cec5SDimitry Andric   /// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>)
5650b57cec5SDimitry Andric   llvm::Function *LifetimeEndFn = nullptr;
5660b57cec5SDimitry Andric 
5670b57cec5SDimitry Andric   std::unique_ptr<SanitizerMetadata> SanitizerMD;
5680b57cec5SDimitry Andric 
5690b57cec5SDimitry Andric   llvm::MapVector<const Decl *, bool> DeferredEmptyCoverageMappingDecls;
5700b57cec5SDimitry Andric 
5710b57cec5SDimitry Andric   std::unique_ptr<CoverageMappingModuleGen> CoverageMapping;
5720b57cec5SDimitry Andric 
5730b57cec5SDimitry Andric   /// Mapping from canonical types to their metadata identifiers. We need to
5740b57cec5SDimitry Andric   /// maintain this mapping because identifiers may be formed from distinct
5750b57cec5SDimitry Andric   /// MDNodes.
5760b57cec5SDimitry Andric   typedef llvm::DenseMap<QualType, llvm::Metadata *> MetadataTypeMap;
5770b57cec5SDimitry Andric   MetadataTypeMap MetadataIdMap;
5780b57cec5SDimitry Andric   MetadataTypeMap VirtualMetadataIdMap;
5790b57cec5SDimitry Andric   MetadataTypeMap GeneralizedMetadataIdMap;
5800b57cec5SDimitry Andric 
5810b57cec5SDimitry Andric public:
5820b57cec5SDimitry Andric   CodeGenModule(ASTContext &C, const HeaderSearchOptions &headersearchopts,
5830b57cec5SDimitry Andric                 const PreprocessorOptions &ppopts,
5840b57cec5SDimitry Andric                 const CodeGenOptions &CodeGenOpts, llvm::Module &M,
5850b57cec5SDimitry Andric                 DiagnosticsEngine &Diags,
5860b57cec5SDimitry Andric                 CoverageSourceInfo *CoverageInfo = nullptr);
5870b57cec5SDimitry Andric 
5880b57cec5SDimitry Andric   ~CodeGenModule();
5890b57cec5SDimitry Andric 
5900b57cec5SDimitry Andric   void clear();
5910b57cec5SDimitry Andric 
5920b57cec5SDimitry Andric   /// Finalize LLVM code generation.
5930b57cec5SDimitry Andric   void Release();
5940b57cec5SDimitry Andric 
5950b57cec5SDimitry Andric   /// Return true if we should emit location information for expressions.
5960b57cec5SDimitry Andric   bool getExpressionLocationsEnabled() const;
5970b57cec5SDimitry Andric 
5980b57cec5SDimitry Andric   /// Return a reference to the configured Objective-C runtime.
getObjCRuntime()5990b57cec5SDimitry Andric   CGObjCRuntime &getObjCRuntime() {
6000b57cec5SDimitry Andric     if (!ObjCRuntime) createObjCRuntime();
6010b57cec5SDimitry Andric     return *ObjCRuntime;
6020b57cec5SDimitry Andric   }
6030b57cec5SDimitry Andric 
6040b57cec5SDimitry Andric   /// Return true iff an Objective-C runtime has been configured.
hasObjCRuntime()6050b57cec5SDimitry Andric   bool hasObjCRuntime() { return !!ObjCRuntime; }
6060b57cec5SDimitry Andric 
getModuleNameHash()607*5f7ddb14SDimitry Andric   const std::string &getModuleNameHash() const { return ModuleNameHash; }
608*5f7ddb14SDimitry Andric 
6090b57cec5SDimitry Andric   /// Return a reference to the configured OpenCL runtime.
getOpenCLRuntime()6100b57cec5SDimitry Andric   CGOpenCLRuntime &getOpenCLRuntime() {
6110b57cec5SDimitry Andric     assert(OpenCLRuntime != nullptr);
6120b57cec5SDimitry Andric     return *OpenCLRuntime;
6130b57cec5SDimitry Andric   }
6140b57cec5SDimitry Andric 
6150b57cec5SDimitry Andric   /// Return a reference to the configured OpenMP runtime.
getOpenMPRuntime()6160b57cec5SDimitry Andric   CGOpenMPRuntime &getOpenMPRuntime() {
6170b57cec5SDimitry Andric     assert(OpenMPRuntime != nullptr);
6180b57cec5SDimitry Andric     return *OpenMPRuntime;
6190b57cec5SDimitry Andric   }
6200b57cec5SDimitry Andric 
6210b57cec5SDimitry Andric   /// Return a reference to the configured CUDA runtime.
getCUDARuntime()6220b57cec5SDimitry Andric   CGCUDARuntime &getCUDARuntime() {
6230b57cec5SDimitry Andric     assert(CUDARuntime != nullptr);
6240b57cec5SDimitry Andric     return *CUDARuntime;
6250b57cec5SDimitry Andric   }
6260b57cec5SDimitry Andric 
getObjCEntrypoints()6270b57cec5SDimitry Andric   ObjCEntrypoints &getObjCEntrypoints() const {
6280b57cec5SDimitry Andric     assert(ObjCData != nullptr);
6290b57cec5SDimitry Andric     return *ObjCData;
6300b57cec5SDimitry Andric   }
6310b57cec5SDimitry Andric 
632af732203SDimitry Andric   // Version checking functions, used to implement ObjC's @available:
6330b57cec5SDimitry Andric   // i32 @__isOSVersionAtLeast(i32, i32, i32)
6340b57cec5SDimitry Andric   llvm::FunctionCallee IsOSVersionAtLeastFn = nullptr;
635af732203SDimitry Andric   // i32 @__isPlatformVersionAtLeast(i32, i32, i32, i32)
636af732203SDimitry Andric   llvm::FunctionCallee IsPlatformVersionAtLeastFn = nullptr;
6370b57cec5SDimitry Andric 
getPGOStats()6380b57cec5SDimitry Andric   InstrProfStats &getPGOStats() { return PGOStats; }
getPGOReader()6390b57cec5SDimitry Andric   llvm::IndexedInstrProfReader *getPGOReader() const { return PGOReader.get(); }
6400b57cec5SDimitry Andric 
getCoverageMapping()6410b57cec5SDimitry Andric   CoverageMappingModuleGen *getCoverageMapping() const {
6420b57cec5SDimitry Andric     return CoverageMapping.get();
6430b57cec5SDimitry Andric   }
6440b57cec5SDimitry Andric 
getStaticLocalDeclAddress(const VarDecl * D)6450b57cec5SDimitry Andric   llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) {
6460b57cec5SDimitry Andric     return StaticLocalDeclMap[D];
6470b57cec5SDimitry Andric   }
setStaticLocalDeclAddress(const VarDecl * D,llvm::Constant * C)6480b57cec5SDimitry Andric   void setStaticLocalDeclAddress(const VarDecl *D,
6490b57cec5SDimitry Andric                                  llvm::Constant *C) {
6500b57cec5SDimitry Andric     StaticLocalDeclMap[D] = C;
6510b57cec5SDimitry Andric   }
6520b57cec5SDimitry Andric 
6530b57cec5SDimitry Andric   llvm::Constant *
6540b57cec5SDimitry Andric   getOrCreateStaticVarDecl(const VarDecl &D,
6550b57cec5SDimitry Andric                            llvm::GlobalValue::LinkageTypes Linkage);
6560b57cec5SDimitry Andric 
getStaticLocalDeclGuardAddress(const VarDecl * D)6570b57cec5SDimitry Andric   llvm::GlobalVariable *getStaticLocalDeclGuardAddress(const VarDecl *D) {
6580b57cec5SDimitry Andric     return StaticLocalDeclGuardMap[D];
6590b57cec5SDimitry Andric   }
setStaticLocalDeclGuardAddress(const VarDecl * D,llvm::GlobalVariable * C)6600b57cec5SDimitry Andric   void setStaticLocalDeclGuardAddress(const VarDecl *D,
6610b57cec5SDimitry Andric                                       llvm::GlobalVariable *C) {
6620b57cec5SDimitry Andric     StaticLocalDeclGuardMap[D] = C;
6630b57cec5SDimitry Andric   }
6640b57cec5SDimitry Andric 
6650b57cec5SDimitry Andric   Address createUnnamedGlobalFrom(const VarDecl &D, llvm::Constant *Constant,
6660b57cec5SDimitry Andric                                   CharUnits Align);
6670b57cec5SDimitry Andric 
6680b57cec5SDimitry Andric   bool lookupRepresentativeDecl(StringRef MangledName,
6690b57cec5SDimitry Andric                                 GlobalDecl &Result) const;
6700b57cec5SDimitry Andric 
getAtomicSetterHelperFnMap(QualType Ty)6710b57cec5SDimitry Andric   llvm::Constant *getAtomicSetterHelperFnMap(QualType Ty) {
6720b57cec5SDimitry Andric     return AtomicSetterHelperFnMap[Ty];
6730b57cec5SDimitry Andric   }
setAtomicSetterHelperFnMap(QualType Ty,llvm::Constant * Fn)6740b57cec5SDimitry Andric   void setAtomicSetterHelperFnMap(QualType Ty,
6750b57cec5SDimitry Andric                             llvm::Constant *Fn) {
6760b57cec5SDimitry Andric     AtomicSetterHelperFnMap[Ty] = Fn;
6770b57cec5SDimitry Andric   }
6780b57cec5SDimitry Andric 
getAtomicGetterHelperFnMap(QualType Ty)6790b57cec5SDimitry Andric   llvm::Constant *getAtomicGetterHelperFnMap(QualType Ty) {
6800b57cec5SDimitry Andric     return AtomicGetterHelperFnMap[Ty];
6810b57cec5SDimitry Andric   }
setAtomicGetterHelperFnMap(QualType Ty,llvm::Constant * Fn)6820b57cec5SDimitry Andric   void setAtomicGetterHelperFnMap(QualType Ty,
6830b57cec5SDimitry Andric                             llvm::Constant *Fn) {
6840b57cec5SDimitry Andric     AtomicGetterHelperFnMap[Ty] = Fn;
6850b57cec5SDimitry Andric   }
6860b57cec5SDimitry Andric 
getTypeDescriptorFromMap(QualType Ty)6870b57cec5SDimitry Andric   llvm::Constant *getTypeDescriptorFromMap(QualType Ty) {
6880b57cec5SDimitry Andric     return TypeDescriptorMap[Ty];
6890b57cec5SDimitry Andric   }
setTypeDescriptorInMap(QualType Ty,llvm::Constant * C)6900b57cec5SDimitry Andric   void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C) {
6910b57cec5SDimitry Andric     TypeDescriptorMap[Ty] = C;
6920b57cec5SDimitry Andric   }
6930b57cec5SDimitry Andric 
getModuleDebugInfo()6940b57cec5SDimitry Andric   CGDebugInfo *getModuleDebugInfo() { return DebugInfo.get(); }
6950b57cec5SDimitry Andric 
getNoObjCARCExceptionsMetadata()6960b57cec5SDimitry Andric   llvm::MDNode *getNoObjCARCExceptionsMetadata() {
6970b57cec5SDimitry Andric     if (!NoObjCARCExceptionsMetadata)
6980b57cec5SDimitry Andric       NoObjCARCExceptionsMetadata = llvm::MDNode::get(getLLVMContext(), None);
6990b57cec5SDimitry Andric     return NoObjCARCExceptionsMetadata;
7000b57cec5SDimitry Andric   }
7010b57cec5SDimitry Andric 
getContext()7020b57cec5SDimitry Andric   ASTContext &getContext() const { return Context; }
getLangOpts()7030b57cec5SDimitry Andric   const LangOptions &getLangOpts() const { return LangOpts; }
getHeaderSearchOpts()7040b57cec5SDimitry Andric   const HeaderSearchOptions &getHeaderSearchOpts()
7050b57cec5SDimitry Andric     const { return HeaderSearchOpts; }
getPreprocessorOpts()7060b57cec5SDimitry Andric   const PreprocessorOptions &getPreprocessorOpts()
7070b57cec5SDimitry Andric     const { return PreprocessorOpts; }
getCodeGenOpts()7080b57cec5SDimitry Andric   const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
getModule()7090b57cec5SDimitry Andric   llvm::Module &getModule() const { return TheModule; }
getDiags()7100b57cec5SDimitry Andric   DiagnosticsEngine &getDiags() const { return Diags; }
getDataLayout()7110b57cec5SDimitry Andric   const llvm::DataLayout &getDataLayout() const {
7120b57cec5SDimitry Andric     return TheModule.getDataLayout();
7130b57cec5SDimitry Andric   }
getTarget()7140b57cec5SDimitry Andric   const TargetInfo &getTarget() const { return Target; }
getTriple()7150b57cec5SDimitry Andric   const llvm::Triple &getTriple() const { return Target.getTriple(); }
7160b57cec5SDimitry Andric   bool supportsCOMDAT() const;
7170b57cec5SDimitry Andric   void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO);
7180b57cec5SDimitry Andric 
getCXXABI()7190b57cec5SDimitry Andric   CGCXXABI &getCXXABI() const { return *ABI; }
getLLVMContext()7200b57cec5SDimitry Andric   llvm::LLVMContext &getLLVMContext() { return VMContext; }
7210b57cec5SDimitry Andric 
shouldUseTBAA()7220b57cec5SDimitry Andric   bool shouldUseTBAA() const { return TBAA != nullptr; }
7230b57cec5SDimitry Andric 
7240b57cec5SDimitry Andric   const TargetCodeGenInfo &getTargetCodeGenInfo();
7250b57cec5SDimitry Andric 
getTypes()7260b57cec5SDimitry Andric   CodeGenTypes &getTypes() { return Types; }
7270b57cec5SDimitry Andric 
getVTables()7280b57cec5SDimitry Andric   CodeGenVTables &getVTables() { return VTables; }
7290b57cec5SDimitry Andric 
getItaniumVTableContext()7300b57cec5SDimitry Andric   ItaniumVTableContext &getItaniumVTableContext() {
7310b57cec5SDimitry Andric     return VTables.getItaniumVTableContext();
7320b57cec5SDimitry Andric   }
7330b57cec5SDimitry Andric 
getMicrosoftVTableContext()7340b57cec5SDimitry Andric   MicrosoftVTableContext &getMicrosoftVTableContext() {
7350b57cec5SDimitry Andric     return VTables.getMicrosoftVTableContext();
7360b57cec5SDimitry Andric   }
7370b57cec5SDimitry Andric 
getGlobalCtors()7380b57cec5SDimitry Andric   CtorList &getGlobalCtors() { return GlobalCtors; }
getGlobalDtors()7390b57cec5SDimitry Andric   CtorList &getGlobalDtors() { return GlobalDtors; }
7400b57cec5SDimitry Andric 
7410b57cec5SDimitry Andric   /// getTBAATypeInfo - Get metadata used to describe accesses to objects of
7420b57cec5SDimitry Andric   /// the given type.
7430b57cec5SDimitry Andric   llvm::MDNode *getTBAATypeInfo(QualType QTy);
7440b57cec5SDimitry Andric 
7450b57cec5SDimitry Andric   /// getTBAAAccessInfo - Get TBAA information that describes an access to
7460b57cec5SDimitry Andric   /// an object of the given type.
7470b57cec5SDimitry Andric   TBAAAccessInfo getTBAAAccessInfo(QualType AccessType);
7480b57cec5SDimitry Andric 
7490b57cec5SDimitry Andric   /// getTBAAVTablePtrAccessInfo - Get the TBAA information that describes an
7500b57cec5SDimitry Andric   /// access to a virtual table pointer.
7510b57cec5SDimitry Andric   TBAAAccessInfo getTBAAVTablePtrAccessInfo(llvm::Type *VTablePtrType);
7520b57cec5SDimitry Andric 
7530b57cec5SDimitry Andric   llvm::MDNode *getTBAAStructInfo(QualType QTy);
7540b57cec5SDimitry Andric 
7550b57cec5SDimitry Andric   /// getTBAABaseTypeInfo - Get metadata that describes the given base access
7560b57cec5SDimitry Andric   /// type. Return null if the type is not suitable for use in TBAA access tags.
7570b57cec5SDimitry Andric   llvm::MDNode *getTBAABaseTypeInfo(QualType QTy);
7580b57cec5SDimitry Andric 
7590b57cec5SDimitry Andric   /// getTBAAAccessTagInfo - Get TBAA tag for a given memory access.
7600b57cec5SDimitry Andric   llvm::MDNode *getTBAAAccessTagInfo(TBAAAccessInfo Info);
7610b57cec5SDimitry Andric 
7620b57cec5SDimitry Andric   /// mergeTBAAInfoForCast - Get merged TBAA information for the purposes of
7630b57cec5SDimitry Andric   /// type casts.
7640b57cec5SDimitry Andric   TBAAAccessInfo mergeTBAAInfoForCast(TBAAAccessInfo SourceInfo,
7650b57cec5SDimitry Andric                                       TBAAAccessInfo TargetInfo);
7660b57cec5SDimitry Andric 
7670b57cec5SDimitry Andric   /// mergeTBAAInfoForConditionalOperator - Get merged TBAA information for the
7680b57cec5SDimitry Andric   /// purposes of conditional operator.
7690b57cec5SDimitry Andric   TBAAAccessInfo mergeTBAAInfoForConditionalOperator(TBAAAccessInfo InfoA,
7700b57cec5SDimitry Andric                                                      TBAAAccessInfo InfoB);
7710b57cec5SDimitry Andric 
7720b57cec5SDimitry Andric   /// mergeTBAAInfoForMemoryTransfer - Get merged TBAA information for the
7730b57cec5SDimitry Andric   /// purposes of memory transfer calls.
7740b57cec5SDimitry Andric   TBAAAccessInfo mergeTBAAInfoForMemoryTransfer(TBAAAccessInfo DestInfo,
7750b57cec5SDimitry Andric                                                 TBAAAccessInfo SrcInfo);
7760b57cec5SDimitry Andric 
7770b57cec5SDimitry Andric   /// getTBAAInfoForSubobject - Get TBAA information for an access with a given
7780b57cec5SDimitry Andric   /// base lvalue.
getTBAAInfoForSubobject(LValue Base,QualType AccessType)7790b57cec5SDimitry Andric   TBAAAccessInfo getTBAAInfoForSubobject(LValue Base, QualType AccessType) {
7800b57cec5SDimitry Andric     if (Base.getTBAAInfo().isMayAlias())
7810b57cec5SDimitry Andric       return TBAAAccessInfo::getMayAliasInfo();
7820b57cec5SDimitry Andric     return getTBAAAccessInfo(AccessType);
7830b57cec5SDimitry Andric   }
7840b57cec5SDimitry Andric 
7850b57cec5SDimitry Andric   bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor);
7860b57cec5SDimitry Andric 
7870b57cec5SDimitry Andric   bool isPaddedAtomicType(QualType type);
7880b57cec5SDimitry Andric   bool isPaddedAtomicType(const AtomicType *type);
7890b57cec5SDimitry Andric 
7900b57cec5SDimitry Andric   /// DecorateInstructionWithTBAA - Decorate the instruction with a TBAA tag.
7910b57cec5SDimitry Andric   void DecorateInstructionWithTBAA(llvm::Instruction *Inst,
7920b57cec5SDimitry Andric                                    TBAAAccessInfo TBAAInfo);
7930b57cec5SDimitry Andric 
7940b57cec5SDimitry Andric   /// Adds !invariant.barrier !tag to instruction
7950b57cec5SDimitry Andric   void DecorateInstructionWithInvariantGroup(llvm::Instruction *I,
7960b57cec5SDimitry Andric                                              const CXXRecordDecl *RD);
7970b57cec5SDimitry Andric 
7980b57cec5SDimitry Andric   /// Emit the given number of characters as a value of type size_t.
7990b57cec5SDimitry Andric   llvm::ConstantInt *getSize(CharUnits numChars);
8000b57cec5SDimitry Andric 
8010b57cec5SDimitry Andric   /// Set the visibility for the given LLVM GlobalValue.
8020b57cec5SDimitry Andric   void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const;
8030b57cec5SDimitry Andric 
8040b57cec5SDimitry Andric   void setDSOLocal(llvm::GlobalValue *GV) const;
8050b57cec5SDimitry Andric 
8060b57cec5SDimitry Andric   void setDLLImportDLLExport(llvm::GlobalValue *GV, GlobalDecl D) const;
8070b57cec5SDimitry Andric   void setDLLImportDLLExport(llvm::GlobalValue *GV, const NamedDecl *D) const;
8080b57cec5SDimitry Andric   /// Set visibility, dllimport/dllexport and dso_local.
8090b57cec5SDimitry Andric   /// This must be called after dllimport/dllexport is set.
8100b57cec5SDimitry Andric   void setGVProperties(llvm::GlobalValue *GV, GlobalDecl GD) const;
8110b57cec5SDimitry Andric   void setGVProperties(llvm::GlobalValue *GV, const NamedDecl *D) const;
8120b57cec5SDimitry Andric 
8130b57cec5SDimitry Andric   void setGVPropertiesAux(llvm::GlobalValue *GV, const NamedDecl *D) const;
8140b57cec5SDimitry Andric 
8150b57cec5SDimitry Andric   /// Set the TLS mode for the given LLVM GlobalValue for the thread-local
8160b57cec5SDimitry Andric   /// variable declaration D.
8170b57cec5SDimitry Andric   void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const;
8180b57cec5SDimitry Andric 
8195ffd83dbSDimitry Andric   /// Get LLVM TLS mode from CodeGenOptions.
8205ffd83dbSDimitry Andric   llvm::GlobalVariable::ThreadLocalMode GetDefaultLLVMTLSModel() const;
8215ffd83dbSDimitry Andric 
GetLLVMVisibility(Visibility V)8220b57cec5SDimitry Andric   static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) {
8230b57cec5SDimitry Andric     switch (V) {
8240b57cec5SDimitry Andric     case DefaultVisibility:   return llvm::GlobalValue::DefaultVisibility;
8250b57cec5SDimitry Andric     case HiddenVisibility:    return llvm::GlobalValue::HiddenVisibility;
8260b57cec5SDimitry Andric     case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility;
8270b57cec5SDimitry Andric     }
8280b57cec5SDimitry Andric     llvm_unreachable("unknown visibility!");
8290b57cec5SDimitry Andric   }
8300b57cec5SDimitry Andric 
8310b57cec5SDimitry Andric   llvm::Constant *GetAddrOfGlobal(GlobalDecl GD,
8320b57cec5SDimitry Andric                                   ForDefinition_t IsForDefinition
8330b57cec5SDimitry Andric                                     = NotForDefinition);
8340b57cec5SDimitry Andric 
8350b57cec5SDimitry Andric   /// Will return a global variable of the given type. If a variable with a
8360b57cec5SDimitry Andric   /// different type already exists then a new  variable with the right type
8370b57cec5SDimitry Andric   /// will be created and all uses of the old variable will be replaced with a
8380b57cec5SDimitry Andric   /// bitcast to the new variable.
8390b57cec5SDimitry Andric   llvm::GlobalVariable *
8400b57cec5SDimitry Andric   CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty,
8410b57cec5SDimitry Andric                                     llvm::GlobalValue::LinkageTypes Linkage,
8420b57cec5SDimitry Andric                                     unsigned Alignment);
8430b57cec5SDimitry Andric 
8445ffd83dbSDimitry Andric   llvm::Function *CreateGlobalInitOrCleanUpFunction(
8455ffd83dbSDimitry Andric       llvm::FunctionType *ty, const Twine &name, const CGFunctionInfo &FI,
846af732203SDimitry Andric       SourceLocation Loc = SourceLocation(), bool TLS = false);
8470b57cec5SDimitry Andric 
8480b57cec5SDimitry Andric   /// Return the AST address space of the underlying global variable for D, as
8490b57cec5SDimitry Andric   /// determined by its declaration. Normally this is the same as the address
8500b57cec5SDimitry Andric   /// space of D's type, but in CUDA, address spaces are associated with
8510b57cec5SDimitry Andric   /// declarations, not types. If D is nullptr, return the default address
8520b57cec5SDimitry Andric   /// space for global variable.
8530b57cec5SDimitry Andric   ///
8540b57cec5SDimitry Andric   /// For languages without explicit address spaces, if D has default address
8550b57cec5SDimitry Andric   /// space, target-specific global or constant address space may be returned.
8560b57cec5SDimitry Andric   LangAS GetGlobalVarAddressSpace(const VarDecl *D);
8570b57cec5SDimitry Andric 
858*5f7ddb14SDimitry Andric   /// Return the AST address space of constant literal, which is used to emit
859*5f7ddb14SDimitry Andric   /// the constant literal as global variable in LLVM IR.
860*5f7ddb14SDimitry Andric   /// Note: This is not necessarily the address space of the constant literal
861*5f7ddb14SDimitry Andric   /// in AST. For address space agnostic language, e.g. C++, constant literal
862*5f7ddb14SDimitry Andric   /// in AST is always in default address space.
863*5f7ddb14SDimitry Andric   LangAS GetGlobalConstantAddressSpace() const;
864*5f7ddb14SDimitry Andric 
8650b57cec5SDimitry Andric   /// Return the llvm::Constant for the address of the given global variable.
8660b57cec5SDimitry Andric   /// If Ty is non-null and if the global doesn't exist, then it will be created
8670b57cec5SDimitry Andric   /// with the specified type instead of whatever the normal requested type
8680b57cec5SDimitry Andric   /// would be. If IsForDefinition is true, it is guaranteed that an actual
8690b57cec5SDimitry Andric   /// global with type Ty will be returned, not conversion of a variable with
8700b57cec5SDimitry Andric   /// the same mangled name but some other type.
8710b57cec5SDimitry Andric   llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
8720b57cec5SDimitry Andric                                      llvm::Type *Ty = nullptr,
8730b57cec5SDimitry Andric                                      ForDefinition_t IsForDefinition
8740b57cec5SDimitry Andric                                        = NotForDefinition);
8750b57cec5SDimitry Andric 
8760b57cec5SDimitry Andric   /// Return the address of the given function. If Ty is non-null, then this
8770b57cec5SDimitry Andric   /// function will use the specified type if it has to create it.
8780b57cec5SDimitry Andric   llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = nullptr,
8790b57cec5SDimitry Andric                                     bool ForVTable = false,
8800b57cec5SDimitry Andric                                     bool DontDefer = false,
8810b57cec5SDimitry Andric                                     ForDefinition_t IsForDefinition
8820b57cec5SDimitry Andric                                       = NotForDefinition);
8830b57cec5SDimitry Andric 
8840b57cec5SDimitry Andric   /// Get the address of the RTTI descriptor for the given type.
8850b57cec5SDimitry Andric   llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false);
8860b57cec5SDimitry Andric 
8875ffd83dbSDimitry Andric   /// Get the address of a GUID.
8885ffd83dbSDimitry Andric   ConstantAddress GetAddrOfMSGuidDecl(const MSGuidDecl *GD);
8890b57cec5SDimitry Andric 
890af732203SDimitry Andric   /// Get the address of a template parameter object.
891af732203SDimitry Andric   ConstantAddress
892af732203SDimitry Andric   GetAddrOfTemplateParamObject(const TemplateParamObjectDecl *TPO);
893af732203SDimitry Andric 
8940b57cec5SDimitry Andric   /// Get the address of the thunk for the given global decl.
8950b57cec5SDimitry Andric   llvm::Constant *GetAddrOfThunk(StringRef Name, llvm::Type *FnTy,
8960b57cec5SDimitry Andric                                  GlobalDecl GD);
8970b57cec5SDimitry Andric 
8980b57cec5SDimitry Andric   /// Get a reference to the target of VD.
8990b57cec5SDimitry Andric   ConstantAddress GetWeakRefReference(const ValueDecl *VD);
9000b57cec5SDimitry Andric 
9010b57cec5SDimitry Andric   /// Returns the assumed alignment of an opaque pointer to the given class.
9020b57cec5SDimitry Andric   CharUnits getClassPointerAlignment(const CXXRecordDecl *CD);
9030b57cec5SDimitry Andric 
9045ffd83dbSDimitry Andric   /// Returns the minimum object size for an object of the given class type
9055ffd83dbSDimitry Andric   /// (or a class derived from it).
9065ffd83dbSDimitry Andric   CharUnits getMinimumClassObjectSize(const CXXRecordDecl *CD);
9075ffd83dbSDimitry Andric 
9085ffd83dbSDimitry Andric   /// Returns the minimum object size for an object of the given type.
getMinimumObjectSize(QualType Ty)9095ffd83dbSDimitry Andric   CharUnits getMinimumObjectSize(QualType Ty) {
9105ffd83dbSDimitry Andric     if (CXXRecordDecl *RD = Ty->getAsCXXRecordDecl())
9115ffd83dbSDimitry Andric       return getMinimumClassObjectSize(RD);
9125ffd83dbSDimitry Andric     return getContext().getTypeSizeInChars(Ty);
9135ffd83dbSDimitry Andric   }
9145ffd83dbSDimitry Andric 
9150b57cec5SDimitry Andric   /// Returns the assumed alignment of a virtual base of a class.
9160b57cec5SDimitry Andric   CharUnits getVBaseAlignment(CharUnits DerivedAlign,
9170b57cec5SDimitry Andric                               const CXXRecordDecl *Derived,
9180b57cec5SDimitry Andric                               const CXXRecordDecl *VBase);
9190b57cec5SDimitry Andric 
9200b57cec5SDimitry Andric   /// Given a class pointer with an actual known alignment, and the
9210b57cec5SDimitry Andric   /// expected alignment of an object at a dynamic offset w.r.t that
9220b57cec5SDimitry Andric   /// pointer, return the alignment to assume at the offset.
9230b57cec5SDimitry Andric   CharUnits getDynamicOffsetAlignment(CharUnits ActualAlign,
9240b57cec5SDimitry Andric                                       const CXXRecordDecl *Class,
9250b57cec5SDimitry Andric                                       CharUnits ExpectedTargetAlign);
9260b57cec5SDimitry Andric 
9270b57cec5SDimitry Andric   CharUnits
9280b57cec5SDimitry Andric   computeNonVirtualBaseClassOffset(const CXXRecordDecl *DerivedClass,
9290b57cec5SDimitry Andric                                    CastExpr::path_const_iterator Start,
9300b57cec5SDimitry Andric                                    CastExpr::path_const_iterator End);
9310b57cec5SDimitry Andric 
9320b57cec5SDimitry Andric   /// Returns the offset from a derived class to  a class. Returns null if the
9330b57cec5SDimitry Andric   /// offset is 0.
9340b57cec5SDimitry Andric   llvm::Constant *
9350b57cec5SDimitry Andric   GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl,
9360b57cec5SDimitry Andric                                CastExpr::path_const_iterator PathBegin,
9370b57cec5SDimitry Andric                                CastExpr::path_const_iterator PathEnd);
9380b57cec5SDimitry Andric 
9390b57cec5SDimitry Andric   llvm::FoldingSet<BlockByrefHelpers> ByrefHelpersCache;
9400b57cec5SDimitry Andric 
9410b57cec5SDimitry Andric   /// Fetches the global unique block count.
getUniqueBlockCount()9420b57cec5SDimitry Andric   int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; }
9430b57cec5SDimitry Andric 
9440b57cec5SDimitry Andric   /// Fetches the type of a generic block descriptor.
9450b57cec5SDimitry Andric   llvm::Type *getBlockDescriptorType();
9460b57cec5SDimitry Andric 
9470b57cec5SDimitry Andric   /// The type of a generic block literal.
9480b57cec5SDimitry Andric   llvm::Type *getGenericBlockLiteralType();
9490b57cec5SDimitry Andric 
9500b57cec5SDimitry Andric   /// Gets the address of a block which requires no captures.
9510b57cec5SDimitry Andric   llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, StringRef Name);
9520b57cec5SDimitry Andric 
9530b57cec5SDimitry Andric   /// Returns the address of a block which requires no caputres, or null if
9540b57cec5SDimitry Andric   /// we've yet to emit the block for BE.
getAddrOfGlobalBlockIfEmitted(const BlockExpr * BE)9550b57cec5SDimitry Andric   llvm::Constant *getAddrOfGlobalBlockIfEmitted(const BlockExpr *BE) {
9560b57cec5SDimitry Andric     return EmittedGlobalBlocks.lookup(BE);
9570b57cec5SDimitry Andric   }
9580b57cec5SDimitry Andric 
9590b57cec5SDimitry Andric   /// Notes that BE's global block is available via Addr. Asserts that BE
9600b57cec5SDimitry Andric   /// isn't already emitted.
9610b57cec5SDimitry Andric   void setAddrOfGlobalBlock(const BlockExpr *BE, llvm::Constant *Addr);
9620b57cec5SDimitry Andric 
9630b57cec5SDimitry Andric   /// Return a pointer to a constant CFString object for the given string.
9640b57cec5SDimitry Andric   ConstantAddress GetAddrOfConstantCFString(const StringLiteral *Literal);
9650b57cec5SDimitry Andric 
9660b57cec5SDimitry Andric   /// Return a pointer to a constant NSString object for the given string. Or a
9670b57cec5SDimitry Andric   /// user defined String object as defined via
9680b57cec5SDimitry Andric   /// -fconstant-string-class=class_name option.
9690b57cec5SDimitry Andric   ConstantAddress GetAddrOfConstantString(const StringLiteral *Literal);
9700b57cec5SDimitry Andric 
9710b57cec5SDimitry Andric   /// Return a constant array for the given string.
9720b57cec5SDimitry Andric   llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E);
9730b57cec5SDimitry Andric 
9740b57cec5SDimitry Andric   /// Return a pointer to a constant array for the given string literal.
9750b57cec5SDimitry Andric   ConstantAddress
9760b57cec5SDimitry Andric   GetAddrOfConstantStringFromLiteral(const StringLiteral *S,
9770b57cec5SDimitry Andric                                      StringRef Name = ".str");
9780b57cec5SDimitry Andric 
9790b57cec5SDimitry Andric   /// Return a pointer to a constant array for the given ObjCEncodeExpr node.
9800b57cec5SDimitry Andric   ConstantAddress
9810b57cec5SDimitry Andric   GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *);
9820b57cec5SDimitry Andric 
9830b57cec5SDimitry Andric   /// Returns a pointer to a character array containing the literal and a
9840b57cec5SDimitry Andric   /// terminating '\0' character. The result has pointer to array type.
9850b57cec5SDimitry Andric   ///
9860b57cec5SDimitry Andric   /// \param GlobalName If provided, the name to use for the global (if one is
9870b57cec5SDimitry Andric   /// created).
9880b57cec5SDimitry Andric   ConstantAddress
9890b57cec5SDimitry Andric   GetAddrOfConstantCString(const std::string &Str,
9900b57cec5SDimitry Andric                            const char *GlobalName = nullptr);
9910b57cec5SDimitry Andric 
9920b57cec5SDimitry Andric   /// Returns a pointer to a constant global variable for the given file-scope
9930b57cec5SDimitry Andric   /// compound literal expression.
9940b57cec5SDimitry Andric   ConstantAddress GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr*E);
9950b57cec5SDimitry Andric 
9960b57cec5SDimitry Andric   /// If it's been emitted already, returns the GlobalVariable corresponding to
9970b57cec5SDimitry Andric   /// a compound literal. Otherwise, returns null.
9980b57cec5SDimitry Andric   llvm::GlobalVariable *
9990b57cec5SDimitry Andric   getAddrOfConstantCompoundLiteralIfEmitted(const CompoundLiteralExpr *E);
10000b57cec5SDimitry Andric 
10010b57cec5SDimitry Andric   /// Notes that CLE's GlobalVariable is GV. Asserts that CLE isn't already
10020b57cec5SDimitry Andric   /// emitted.
10030b57cec5SDimitry Andric   void setAddrOfConstantCompoundLiteral(const CompoundLiteralExpr *CLE,
10040b57cec5SDimitry Andric                                         llvm::GlobalVariable *GV);
10050b57cec5SDimitry Andric 
10060b57cec5SDimitry Andric   /// Returns a pointer to a global variable representing a temporary
10070b57cec5SDimitry Andric   /// with static or thread storage duration.
10080b57cec5SDimitry Andric   ConstantAddress GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E,
10090b57cec5SDimitry Andric                                            const Expr *Inner);
10100b57cec5SDimitry Andric 
10110b57cec5SDimitry Andric   /// Retrieve the record type that describes the state of an
10120b57cec5SDimitry Andric   /// Objective-C fast enumeration loop (for..in).
10130b57cec5SDimitry Andric   QualType getObjCFastEnumerationStateType();
10140b57cec5SDimitry Andric 
10150b57cec5SDimitry Andric   // Produce code for this constructor/destructor. This method doesn't try
10160b57cec5SDimitry Andric   // to apply any ABI rules about which other constructors/destructors
10170b57cec5SDimitry Andric   // are needed or if they are alias to each other.
10180b57cec5SDimitry Andric   llvm::Function *codegenCXXStructor(GlobalDecl GD);
10190b57cec5SDimitry Andric 
10200b57cec5SDimitry Andric   /// Return the address of the constructor/destructor of the given type.
10210b57cec5SDimitry Andric   llvm::Constant *
10220b57cec5SDimitry Andric   getAddrOfCXXStructor(GlobalDecl GD, const CGFunctionInfo *FnInfo = nullptr,
10230b57cec5SDimitry Andric                        llvm::FunctionType *FnType = nullptr,
10240b57cec5SDimitry Andric                        bool DontDefer = false,
10250b57cec5SDimitry Andric                        ForDefinition_t IsForDefinition = NotForDefinition) {
10260b57cec5SDimitry Andric     return cast<llvm::Constant>(getAddrAndTypeOfCXXStructor(GD, FnInfo, FnType,
10270b57cec5SDimitry Andric                                                             DontDefer,
10280b57cec5SDimitry Andric                                                             IsForDefinition)
10290b57cec5SDimitry Andric                                     .getCallee());
10300b57cec5SDimitry Andric   }
10310b57cec5SDimitry Andric 
10320b57cec5SDimitry Andric   llvm::FunctionCallee getAddrAndTypeOfCXXStructor(
10330b57cec5SDimitry Andric       GlobalDecl GD, const CGFunctionInfo *FnInfo = nullptr,
10340b57cec5SDimitry Andric       llvm::FunctionType *FnType = nullptr, bool DontDefer = false,
10350b57cec5SDimitry Andric       ForDefinition_t IsForDefinition = NotForDefinition);
10360b57cec5SDimitry Andric 
10370b57cec5SDimitry Andric   /// Given a builtin id for a function like "__builtin_fabsf", return a
10380b57cec5SDimitry Andric   /// Function* for "fabsf".
10390b57cec5SDimitry Andric   llvm::Constant *getBuiltinLibFunction(const FunctionDecl *FD,
10400b57cec5SDimitry Andric                                         unsigned BuiltinID);
10410b57cec5SDimitry Andric 
10420b57cec5SDimitry Andric   llvm::Function *getIntrinsic(unsigned IID, ArrayRef<llvm::Type*> Tys = None);
10430b57cec5SDimitry Andric 
10440b57cec5SDimitry Andric   /// Emit code for a single top level declaration.
10450b57cec5SDimitry Andric   void EmitTopLevelDecl(Decl *D);
10460b57cec5SDimitry Andric 
10470b57cec5SDimitry Andric   /// Stored a deferred empty coverage mapping for an unused
10480b57cec5SDimitry Andric   /// and thus uninstrumented top level declaration.
10490b57cec5SDimitry Andric   void AddDeferredUnusedCoverageMapping(Decl *D);
10500b57cec5SDimitry Andric 
10510b57cec5SDimitry Andric   /// Remove the deferred empty coverage mapping as this
10520b57cec5SDimitry Andric   /// declaration is actually instrumented.
10530b57cec5SDimitry Andric   void ClearUnusedCoverageMapping(const Decl *D);
10540b57cec5SDimitry Andric 
10550b57cec5SDimitry Andric   /// Emit all the deferred coverage mappings
10560b57cec5SDimitry Andric   /// for the uninstrumented functions.
10570b57cec5SDimitry Andric   void EmitDeferredUnusedCoverageMappings();
10580b57cec5SDimitry Andric 
10595ffd83dbSDimitry Andric   /// Emit an alias for "main" if it has no arguments (needed for wasm).
10605ffd83dbSDimitry Andric   void EmitMainVoidAlias();
10615ffd83dbSDimitry Andric 
10620b57cec5SDimitry Andric   /// Tell the consumer that this variable has been instantiated.
10630b57cec5SDimitry Andric   void HandleCXXStaticMemberVarInstantiation(VarDecl *VD);
10640b57cec5SDimitry Andric 
10650b57cec5SDimitry Andric   /// If the declaration has internal linkage but is inside an
10660b57cec5SDimitry Andric   /// extern "C" linkage specification, prepare to emit an alias for it
10670b57cec5SDimitry Andric   /// to the expected name.
10680b57cec5SDimitry Andric   template<typename SomeDecl>
10690b57cec5SDimitry Andric   void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
10700b57cec5SDimitry Andric 
10710b57cec5SDimitry Andric   /// Add a global to a list to be added to the llvm.used metadata.
10720b57cec5SDimitry Andric   void addUsedGlobal(llvm::GlobalValue *GV);
10730b57cec5SDimitry Andric 
10740b57cec5SDimitry Andric   /// Add a global to a list to be added to the llvm.compiler.used metadata.
10750b57cec5SDimitry Andric   void addCompilerUsedGlobal(llvm::GlobalValue *GV);
10760b57cec5SDimitry Andric 
1077*5f7ddb14SDimitry Andric   /// Add a global to a list to be added to the llvm.compiler.used metadata.
1078*5f7ddb14SDimitry Andric   void addUsedOrCompilerUsedGlobal(llvm::GlobalValue *GV);
1079*5f7ddb14SDimitry Andric 
10800b57cec5SDimitry Andric   /// Add a destructor and object to add to the C++ global destructor function.
AddCXXDtorEntry(llvm::FunctionCallee DtorFn,llvm::Constant * Object)10810b57cec5SDimitry Andric   void AddCXXDtorEntry(llvm::FunctionCallee DtorFn, llvm::Constant *Object) {
10825ffd83dbSDimitry Andric     CXXGlobalDtorsOrStermFinalizers.emplace_back(DtorFn.getFunctionType(),
10835ffd83dbSDimitry Andric                                                  DtorFn.getCallee(), Object);
10845ffd83dbSDimitry Andric   }
10855ffd83dbSDimitry Andric 
10865ffd83dbSDimitry Andric   /// Add an sterm finalizer to the C++ global cleanup function.
AddCXXStermFinalizerEntry(llvm::FunctionCallee DtorFn)10875ffd83dbSDimitry Andric   void AddCXXStermFinalizerEntry(llvm::FunctionCallee DtorFn) {
10885ffd83dbSDimitry Andric     CXXGlobalDtorsOrStermFinalizers.emplace_back(DtorFn.getFunctionType(),
10895ffd83dbSDimitry Andric                                                  DtorFn.getCallee(), nullptr);
10900b57cec5SDimitry Andric   }
10910b57cec5SDimitry Andric 
1092af732203SDimitry Andric   /// Add an sterm finalizer to its own llvm.global_dtors entry.
AddCXXStermFinalizerToGlobalDtor(llvm::Function * StermFinalizer,int Priority)1093af732203SDimitry Andric   void AddCXXStermFinalizerToGlobalDtor(llvm::Function *StermFinalizer,
1094af732203SDimitry Andric                                         int Priority) {
1095af732203SDimitry Andric     AddGlobalDtor(StermFinalizer, Priority);
1096af732203SDimitry Andric   }
1097af732203SDimitry Andric 
AddCXXPrioritizedStermFinalizerEntry(llvm::Function * StermFinalizer,int Priority)1098*5f7ddb14SDimitry Andric   void AddCXXPrioritizedStermFinalizerEntry(llvm::Function *StermFinalizer,
1099*5f7ddb14SDimitry Andric                                             int Priority) {
1100*5f7ddb14SDimitry Andric     OrderGlobalInitsOrStermFinalizers Key(Priority,
1101*5f7ddb14SDimitry Andric                                           PrioritizedCXXStermFinalizers.size());
1102*5f7ddb14SDimitry Andric     PrioritizedCXXStermFinalizers.push_back(
1103*5f7ddb14SDimitry Andric         std::make_pair(Key, StermFinalizer));
1104*5f7ddb14SDimitry Andric   }
1105*5f7ddb14SDimitry Andric 
11060b57cec5SDimitry Andric   /// Create or return a runtime function declaration with the specified type
1107480093f4SDimitry Andric   /// and name. If \p AssumeConvergent is true, the call will have the
1108480093f4SDimitry Andric   /// convergent attribute added.
11090b57cec5SDimitry Andric   llvm::FunctionCallee
11100b57cec5SDimitry Andric   CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name,
11110b57cec5SDimitry Andric                         llvm::AttributeList ExtraAttrs = llvm::AttributeList(),
1112480093f4SDimitry Andric                         bool Local = false, bool AssumeConvergent = false);
1113480093f4SDimitry Andric 
11140b57cec5SDimitry Andric   /// Create a new runtime global variable with the specified type and name.
11150b57cec5SDimitry Andric   llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty,
11160b57cec5SDimitry Andric                                         StringRef Name);
11170b57cec5SDimitry Andric 
11180b57cec5SDimitry Andric   ///@name Custom Blocks Runtime Interfaces
11190b57cec5SDimitry Andric   ///@{
11200b57cec5SDimitry Andric 
11210b57cec5SDimitry Andric   llvm::Constant *getNSConcreteGlobalBlock();
11220b57cec5SDimitry Andric   llvm::Constant *getNSConcreteStackBlock();
11230b57cec5SDimitry Andric   llvm::FunctionCallee getBlockObjectAssign();
11240b57cec5SDimitry Andric   llvm::FunctionCallee getBlockObjectDispose();
11250b57cec5SDimitry Andric 
11260b57cec5SDimitry Andric   ///@}
11270b57cec5SDimitry Andric 
11280b57cec5SDimitry Andric   llvm::Function *getLLVMLifetimeStartFn();
11290b57cec5SDimitry Andric   llvm::Function *getLLVMLifetimeEndFn();
11300b57cec5SDimitry Andric 
11310b57cec5SDimitry Andric   // Make sure that this type is translated.
11320b57cec5SDimitry Andric   void UpdateCompletedType(const TagDecl *TD);
11330b57cec5SDimitry Andric 
11340b57cec5SDimitry Andric   llvm::Constant *getMemberPointerConstant(const UnaryOperator *e);
11350b57cec5SDimitry Andric 
11360b57cec5SDimitry Andric   /// Emit type info if type of an expression is a variably modified
11370b57cec5SDimitry Andric   /// type. Also emit proper debug info for cast types.
11380b57cec5SDimitry Andric   void EmitExplicitCastExprType(const ExplicitCastExpr *E,
11390b57cec5SDimitry Andric                                 CodeGenFunction *CGF = nullptr);
11400b57cec5SDimitry Andric 
11410b57cec5SDimitry Andric   /// Return the result of value-initializing the given type, i.e. a null
11420b57cec5SDimitry Andric   /// expression of the given type.  This is usually, but not always, an LLVM
11430b57cec5SDimitry Andric   /// null constant.
11440b57cec5SDimitry Andric   llvm::Constant *EmitNullConstant(QualType T);
11450b57cec5SDimitry Andric 
11460b57cec5SDimitry Andric   /// Return a null constant appropriate for zero-initializing a base class with
11470b57cec5SDimitry Andric   /// the given type. This is usually, but not always, an LLVM null constant.
11480b57cec5SDimitry Andric   llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record);
11490b57cec5SDimitry Andric 
11500b57cec5SDimitry Andric   /// Emit a general error that something can't be done.
11510b57cec5SDimitry Andric   void Error(SourceLocation loc, StringRef error);
11520b57cec5SDimitry Andric 
11530b57cec5SDimitry Andric   /// Print out an error that codegen doesn't support the specified stmt yet.
11540b57cec5SDimitry Andric   void ErrorUnsupported(const Stmt *S, const char *Type);
11550b57cec5SDimitry Andric 
11560b57cec5SDimitry Andric   /// Print out an error that codegen doesn't support the specified decl yet.
11570b57cec5SDimitry Andric   void ErrorUnsupported(const Decl *D, const char *Type);
11580b57cec5SDimitry Andric 
11590b57cec5SDimitry Andric   /// Set the attributes on the LLVM function for the given decl and function
11600b57cec5SDimitry Andric   /// info. This applies attributes necessary for handling the ABI as well as
11610b57cec5SDimitry Andric   /// user specified attributes like section.
11620b57cec5SDimitry Andric   void SetInternalFunctionAttributes(GlobalDecl GD, llvm::Function *F,
11630b57cec5SDimitry Andric                                      const CGFunctionInfo &FI);
11640b57cec5SDimitry Andric 
11650b57cec5SDimitry Andric   /// Set the LLVM function attributes (sext, zext, etc).
11660b57cec5SDimitry Andric   void SetLLVMFunctionAttributes(GlobalDecl GD, const CGFunctionInfo &Info,
1167*5f7ddb14SDimitry Andric                                  llvm::Function *F, bool IsThunk);
11680b57cec5SDimitry Andric 
11690b57cec5SDimitry Andric   /// Set the LLVM function attributes which only apply to a function
11700b57cec5SDimitry Andric   /// definition.
11710b57cec5SDimitry Andric   void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F);
11720b57cec5SDimitry Andric 
1173af732203SDimitry Andric   /// Set the LLVM function attributes that represent floating point
1174af732203SDimitry Andric   /// environment.
1175af732203SDimitry Andric   void setLLVMFunctionFEnvAttributes(const FunctionDecl *D, llvm::Function *F);
1176af732203SDimitry Andric 
11770b57cec5SDimitry Andric   /// Return true iff the given type uses 'sret' when used as a return type.
11780b57cec5SDimitry Andric   bool ReturnTypeUsesSRet(const CGFunctionInfo &FI);
11790b57cec5SDimitry Andric 
11800b57cec5SDimitry Andric   /// Return true iff the given type uses an argument slot when 'sret' is used
11810b57cec5SDimitry Andric   /// as a return type.
11820b57cec5SDimitry Andric   bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI);
11830b57cec5SDimitry Andric 
11840b57cec5SDimitry Andric   /// Return true iff the given type uses 'fpret' when used as a return type.
11850b57cec5SDimitry Andric   bool ReturnTypeUsesFPRet(QualType ResultType);
11860b57cec5SDimitry Andric 
11870b57cec5SDimitry Andric   /// Return true iff the given type uses 'fp2ret' when used as a return type.
11880b57cec5SDimitry Andric   bool ReturnTypeUsesFP2Ret(QualType ResultType);
11890b57cec5SDimitry Andric 
11900b57cec5SDimitry Andric   /// Get the LLVM attributes and calling convention to use for a particular
11910b57cec5SDimitry Andric   /// function type.
11920b57cec5SDimitry Andric   ///
11930b57cec5SDimitry Andric   /// \param Name - The function name.
11940b57cec5SDimitry Andric   /// \param Info - The function type information.
11950b57cec5SDimitry Andric   /// \param CalleeInfo - The callee information these attributes are being
11960b57cec5SDimitry Andric   /// constructed for. If valid, the attributes applied to this decl may
11970b57cec5SDimitry Andric   /// contribute to the function attributes and calling convention.
11980b57cec5SDimitry Andric   /// \param Attrs [out] - On return, the attribute list to use.
11990b57cec5SDimitry Andric   /// \param CallingConv [out] - On return, the LLVM calling convention to use.
12000b57cec5SDimitry Andric   void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info,
12010b57cec5SDimitry Andric                               CGCalleeInfo CalleeInfo,
12020b57cec5SDimitry Andric                               llvm::AttributeList &Attrs, unsigned &CallingConv,
1203*5f7ddb14SDimitry Andric                               bool AttrOnCallSite, bool IsThunk);
12040b57cec5SDimitry Andric 
12050b57cec5SDimitry Andric   /// Adds attributes to F according to our CodeGenOptions and LangOptions, as
12060b57cec5SDimitry Andric   /// though we had emitted it ourselves.  We remove any attributes on F that
12070b57cec5SDimitry Andric   /// conflict with the attributes we add here.
12080b57cec5SDimitry Andric   ///
12090b57cec5SDimitry Andric   /// This is useful for adding attrs to bitcode modules that you want to link
12100b57cec5SDimitry Andric   /// with but don't control, such as CUDA's libdevice.  When linking with such
12110b57cec5SDimitry Andric   /// a bitcode library, you might want to set e.g. its functions'
12120b57cec5SDimitry Andric   /// "unsafe-fp-math" attribute to match the attr of the functions you're
12130b57cec5SDimitry Andric   /// codegen'ing.  Otherwise, LLVM will interpret the bitcode module's lack of
12140b57cec5SDimitry Andric   /// unsafe-fp-math attrs as tantamount to unsafe-fp-math=false, and then LLVM
12150b57cec5SDimitry Andric   /// will propagate unsafe-fp-math=false up to every transitive caller of a
12160b57cec5SDimitry Andric   /// function in the bitcode library!
12170b57cec5SDimitry Andric   ///
12180b57cec5SDimitry Andric   /// With the exception of fast-math attrs, this will only make the attributes
12190b57cec5SDimitry Andric   /// on the function more conservative.  But it's unsafe to call this on a
12200b57cec5SDimitry Andric   /// function which relies on particular fast-math attributes for correctness.
12210b57cec5SDimitry Andric   /// It's up to you to ensure that this is safe.
12225ffd83dbSDimitry Andric   void addDefaultFunctionDefinitionAttributes(llvm::Function &F);
12235ffd83dbSDimitry Andric 
12245ffd83dbSDimitry Andric   /// Like the overload taking a `Function &`, but intended specifically
12255ffd83dbSDimitry Andric   /// for frontends that want to build on Clang's target-configuration logic.
12265ffd83dbSDimitry Andric   void addDefaultFunctionDefinitionAttributes(llvm::AttrBuilder &attrs);
12270b57cec5SDimitry Andric 
12280b57cec5SDimitry Andric   StringRef getMangledName(GlobalDecl GD);
12290b57cec5SDimitry Andric   StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD);
12300b57cec5SDimitry Andric 
12310b57cec5SDimitry Andric   void EmitTentativeDefinition(const VarDecl *D);
12320b57cec5SDimitry Andric 
1233480093f4SDimitry Andric   void EmitExternalDeclaration(const VarDecl *D);
1234480093f4SDimitry Andric 
12350b57cec5SDimitry Andric   void EmitVTable(CXXRecordDecl *Class);
12360b57cec5SDimitry Andric 
12370b57cec5SDimitry Andric   void RefreshTypeCacheForClass(const CXXRecordDecl *Class);
12380b57cec5SDimitry Andric 
12390b57cec5SDimitry Andric   /// Appends Opts to the "llvm.linker.options" metadata value.
12400b57cec5SDimitry Andric   void AppendLinkerOptions(StringRef Opts);
12410b57cec5SDimitry Andric 
12420b57cec5SDimitry Andric   /// Appends a detect mismatch command to the linker options.
12430b57cec5SDimitry Andric   void AddDetectMismatch(StringRef Name, StringRef Value);
12440b57cec5SDimitry Andric 
12450b57cec5SDimitry Andric   /// Appends a dependent lib to the appropriate metadata value.
12460b57cec5SDimitry Andric   void AddDependentLib(StringRef Lib);
12470b57cec5SDimitry Andric 
12480b57cec5SDimitry Andric 
12490b57cec5SDimitry Andric   llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD);
12500b57cec5SDimitry Andric 
setFunctionLinkage(GlobalDecl GD,llvm::Function * F)12510b57cec5SDimitry Andric   void setFunctionLinkage(GlobalDecl GD, llvm::Function *F) {
12520b57cec5SDimitry Andric     F->setLinkage(getFunctionLinkage(GD));
12530b57cec5SDimitry Andric   }
12540b57cec5SDimitry Andric 
12550b57cec5SDimitry Andric   /// Return the appropriate linkage for the vtable, VTT, and type information
12560b57cec5SDimitry Andric   /// of the given class.
12570b57cec5SDimitry Andric   llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD);
12580b57cec5SDimitry Andric 
12590b57cec5SDimitry Andric   /// Return the store size, in character units, of the given LLVM type.
12600b57cec5SDimitry Andric   CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const;
12610b57cec5SDimitry Andric 
12620b57cec5SDimitry Andric   /// Returns LLVM linkage for a declarator.
12630b57cec5SDimitry Andric   llvm::GlobalValue::LinkageTypes
12640b57cec5SDimitry Andric   getLLVMLinkageForDeclarator(const DeclaratorDecl *D, GVALinkage Linkage,
12650b57cec5SDimitry Andric                               bool IsConstantVariable);
12660b57cec5SDimitry Andric 
12670b57cec5SDimitry Andric   /// Returns LLVM linkage for a declarator.
12680b57cec5SDimitry Andric   llvm::GlobalValue::LinkageTypes
12690b57cec5SDimitry Andric   getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant);
12700b57cec5SDimitry Andric 
12710b57cec5SDimitry Andric   /// Emit all the global annotations.
12720b57cec5SDimitry Andric   void EmitGlobalAnnotations();
12730b57cec5SDimitry Andric 
12740b57cec5SDimitry Andric   /// Emit an annotation string.
12750b57cec5SDimitry Andric   llvm::Constant *EmitAnnotationString(StringRef Str);
12760b57cec5SDimitry Andric 
12770b57cec5SDimitry Andric   /// Emit the annotation's translation unit.
12780b57cec5SDimitry Andric   llvm::Constant *EmitAnnotationUnit(SourceLocation Loc);
12790b57cec5SDimitry Andric 
12800b57cec5SDimitry Andric   /// Emit the annotation line number.
12810b57cec5SDimitry Andric   llvm::Constant *EmitAnnotationLineNo(SourceLocation L);
12820b57cec5SDimitry Andric 
1283af732203SDimitry Andric   /// Emit additional args of the annotation.
1284af732203SDimitry Andric   llvm::Constant *EmitAnnotationArgs(const AnnotateAttr *Attr);
1285af732203SDimitry Andric 
12860b57cec5SDimitry Andric   /// Generate the llvm::ConstantStruct which contains the annotation
12870b57cec5SDimitry Andric   /// information for a given GlobalValue. The annotation struct is
12880b57cec5SDimitry Andric   /// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the
12890b57cec5SDimitry Andric   /// GlobalValue being annotated. The second field is the constant string
12900b57cec5SDimitry Andric   /// created from the AnnotateAttr's annotation. The third field is a constant
12910b57cec5SDimitry Andric   /// string containing the name of the translation unit. The fourth field is
12920b57cec5SDimitry Andric   /// the line number in the file of the annotated value declaration.
12930b57cec5SDimitry Andric   llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
12940b57cec5SDimitry Andric                                    const AnnotateAttr *AA,
12950b57cec5SDimitry Andric                                    SourceLocation L);
12960b57cec5SDimitry Andric 
12970b57cec5SDimitry Andric   /// Add global annotations that are set on D, for the global GV. Those
12980b57cec5SDimitry Andric   /// annotations are emitted during finalization of the LLVM code.
12990b57cec5SDimitry Andric   void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
13000b57cec5SDimitry Andric 
1301*5f7ddb14SDimitry Andric   bool isInNoSanitizeList(SanitizerMask Kind, llvm::Function *Fn,
13020b57cec5SDimitry Andric                           SourceLocation Loc) const;
13030b57cec5SDimitry Andric 
1304*5f7ddb14SDimitry Andric   bool isInNoSanitizeList(llvm::GlobalVariable *GV, SourceLocation Loc,
1305*5f7ddb14SDimitry Andric                           QualType Ty, StringRef Category = StringRef()) const;
13060b57cec5SDimitry Andric 
13070b57cec5SDimitry Andric   /// Imbue XRay attributes to a function, applying the always/never attribute
13080b57cec5SDimitry Andric   /// lists in the process. Returns true if we did imbue attributes this way,
13090b57cec5SDimitry Andric   /// false otherwise.
13100b57cec5SDimitry Andric   bool imbueXRayAttrs(llvm::Function *Fn, SourceLocation Loc,
13110b57cec5SDimitry Andric                       StringRef Category = StringRef()) const;
13120b57cec5SDimitry Andric 
1313af732203SDimitry Andric   /// Returns true if function at the given location should be excluded from
1314af732203SDimitry Andric   /// profile instrumentation.
1315af732203SDimitry Andric   bool isProfileInstrExcluded(llvm::Function *Fn, SourceLocation Loc) const;
1316af732203SDimitry Andric 
getSanitizerMetadata()13170b57cec5SDimitry Andric   SanitizerMetadata *getSanitizerMetadata() {
13180b57cec5SDimitry Andric     return SanitizerMD.get();
13190b57cec5SDimitry Andric   }
13200b57cec5SDimitry Andric 
addDeferredVTable(const CXXRecordDecl * RD)13210b57cec5SDimitry Andric   void addDeferredVTable(const CXXRecordDecl *RD) {
13220b57cec5SDimitry Andric     DeferredVTables.push_back(RD);
13230b57cec5SDimitry Andric   }
13240b57cec5SDimitry Andric 
13250b57cec5SDimitry Andric   /// Emit code for a single global function or var decl. Forward declarations
13260b57cec5SDimitry Andric   /// are emitted lazily.
13270b57cec5SDimitry Andric   void EmitGlobal(GlobalDecl D);
13280b57cec5SDimitry Andric 
13290b57cec5SDimitry Andric   bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D);
13300b57cec5SDimitry Andric 
13310b57cec5SDimitry Andric   llvm::GlobalValue *GetGlobalValue(StringRef Ref);
13320b57cec5SDimitry Andric 
13330b57cec5SDimitry Andric   /// Set attributes which are common to any form of a global definition (alias,
13340b57cec5SDimitry Andric   /// Objective-C method, function, global variable).
13350b57cec5SDimitry Andric   ///
13360b57cec5SDimitry Andric   /// NOTE: This should only be called for definitions.
13370b57cec5SDimitry Andric   void SetCommonAttributes(GlobalDecl GD, llvm::GlobalValue *GV);
13380b57cec5SDimitry Andric 
13390b57cec5SDimitry Andric   void addReplacement(StringRef Name, llvm::Constant *C);
13400b57cec5SDimitry Andric 
13410b57cec5SDimitry Andric   void addGlobalValReplacement(llvm::GlobalValue *GV, llvm::Constant *C);
13420b57cec5SDimitry Andric 
13430b57cec5SDimitry Andric   /// Emit a code for threadprivate directive.
13440b57cec5SDimitry Andric   /// \param D Threadprivate declaration.
13450b57cec5SDimitry Andric   void EmitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D);
13460b57cec5SDimitry Andric 
13470b57cec5SDimitry Andric   /// Emit a code for declare reduction construct.
13480b57cec5SDimitry Andric   void EmitOMPDeclareReduction(const OMPDeclareReductionDecl *D,
13490b57cec5SDimitry Andric                                CodeGenFunction *CGF = nullptr);
13500b57cec5SDimitry Andric 
13510b57cec5SDimitry Andric   /// Emit a code for declare mapper construct.
13520b57cec5SDimitry Andric   void EmitOMPDeclareMapper(const OMPDeclareMapperDecl *D,
13530b57cec5SDimitry Andric                             CodeGenFunction *CGF = nullptr);
13540b57cec5SDimitry Andric 
13550b57cec5SDimitry Andric   /// Emit a code for requires directive.
13560b57cec5SDimitry Andric   /// \param D Requires declaration
13570b57cec5SDimitry Andric   void EmitOMPRequiresDecl(const OMPRequiresDecl *D);
13580b57cec5SDimitry Andric 
1359*5f7ddb14SDimitry Andric   /// Emit a code for the allocate directive.
1360*5f7ddb14SDimitry Andric   /// \param D The allocate declaration
1361*5f7ddb14SDimitry Andric   void EmitOMPAllocateDecl(const OMPAllocateDecl *D);
1362*5f7ddb14SDimitry Andric 
13630b57cec5SDimitry Andric   /// Returns whether the given record has hidden LTO visibility and therefore
13640b57cec5SDimitry Andric   /// may participate in (single-module) CFI and whole-program vtable
13650b57cec5SDimitry Andric   /// optimization.
13660b57cec5SDimitry Andric   bool HasHiddenLTOVisibility(const CXXRecordDecl *RD);
13670b57cec5SDimitry Andric 
13685ffd83dbSDimitry Andric   /// Returns whether the given record has public std LTO visibility
13695ffd83dbSDimitry Andric   /// and therefore may not participate in (single-module) CFI and whole-program
13705ffd83dbSDimitry Andric   /// vtable optimization.
13715ffd83dbSDimitry Andric   bool HasLTOVisibilityPublicStd(const CXXRecordDecl *RD);
13725ffd83dbSDimitry Andric 
1373a7dea167SDimitry Andric   /// Returns the vcall visibility of the given type. This is the scope in which
1374a7dea167SDimitry Andric   /// a virtual function call could be made which ends up being dispatched to a
1375a7dea167SDimitry Andric   /// member function of this class. This scope can be wider than the visibility
1376a7dea167SDimitry Andric   /// of the class itself when the class has a more-visible dynamic base class.
1377af732203SDimitry Andric   /// The client should pass in an empty Visited set, which is used to prevent
1378af732203SDimitry Andric   /// redundant recursive processing.
1379a7dea167SDimitry Andric   llvm::GlobalObject::VCallVisibility
1380af732203SDimitry Andric   GetVCallVisibilityLevel(const CXXRecordDecl *RD,
1381af732203SDimitry Andric                           llvm::DenseSet<const CXXRecordDecl *> &Visited);
1382a7dea167SDimitry Andric 
13830b57cec5SDimitry Andric   /// Emit type metadata for the given vtable using the given layout.
1384a7dea167SDimitry Andric   void EmitVTableTypeMetadata(const CXXRecordDecl *RD,
1385a7dea167SDimitry Andric                               llvm::GlobalVariable *VTable,
13860b57cec5SDimitry Andric                               const VTableLayout &VTLayout);
13870b57cec5SDimitry Andric 
13880b57cec5SDimitry Andric   /// Generate a cross-DSO type identifier for MD.
13890b57cec5SDimitry Andric   llvm::ConstantInt *CreateCrossDsoCfiTypeId(llvm::Metadata *MD);
13900b57cec5SDimitry Andric 
13910b57cec5SDimitry Andric   /// Create a metadata identifier for the given type. This may either be an
13920b57cec5SDimitry Andric   /// MDString (for external identifiers) or a distinct unnamed MDNode (for
13930b57cec5SDimitry Andric   /// internal identifiers).
13940b57cec5SDimitry Andric   llvm::Metadata *CreateMetadataIdentifierForType(QualType T);
13950b57cec5SDimitry Andric 
13960b57cec5SDimitry Andric   /// Create a metadata identifier that is intended to be used to check virtual
13970b57cec5SDimitry Andric   /// calls via a member function pointer.
13980b57cec5SDimitry Andric   llvm::Metadata *CreateMetadataIdentifierForVirtualMemPtrType(QualType T);
13990b57cec5SDimitry Andric 
14000b57cec5SDimitry Andric   /// Create a metadata identifier for the generalization of the given type.
14010b57cec5SDimitry Andric   /// This may either be an MDString (for external identifiers) or a distinct
14020b57cec5SDimitry Andric   /// unnamed MDNode (for internal identifiers).
14030b57cec5SDimitry Andric   llvm::Metadata *CreateMetadataIdentifierGeneralized(QualType T);
14040b57cec5SDimitry Andric 
14050b57cec5SDimitry Andric   /// Create and attach type metadata to the given function.
14060b57cec5SDimitry Andric   void CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD,
14070b57cec5SDimitry Andric                                           llvm::Function *F);
14080b57cec5SDimitry Andric 
1409*5f7ddb14SDimitry Andric   /// Whether this function's return type has no side effects, and thus may
1410*5f7ddb14SDimitry Andric   /// be trivially discarded if it is unused.
1411*5f7ddb14SDimitry Andric   bool MayDropFunctionReturn(const ASTContext &Context, QualType ReturnType);
1412*5f7ddb14SDimitry Andric 
14130b57cec5SDimitry Andric   /// Returns whether this module needs the "all-vtables" type identifier.
14140b57cec5SDimitry Andric   bool NeedAllVtablesTypeId() const;
14150b57cec5SDimitry Andric 
14160b57cec5SDimitry Andric   /// Create and attach type metadata for the given vtable.
14170b57cec5SDimitry Andric   void AddVTableTypeMetadata(llvm::GlobalVariable *VTable, CharUnits Offset,
14180b57cec5SDimitry Andric                              const CXXRecordDecl *RD);
14190b57cec5SDimitry Andric 
14200b57cec5SDimitry Andric   /// Return a vector of most-base classes for RD. This is used to implement
14210b57cec5SDimitry Andric   /// control flow integrity checks for member function pointers.
14220b57cec5SDimitry Andric   ///
14230b57cec5SDimitry Andric   /// A most-base class of a class C is defined as a recursive base class of C,
14240b57cec5SDimitry Andric   /// including C itself, that does not have any bases.
14250b57cec5SDimitry Andric   std::vector<const CXXRecordDecl *>
14260b57cec5SDimitry Andric   getMostBaseClasses(const CXXRecordDecl *RD);
14270b57cec5SDimitry Andric 
14280b57cec5SDimitry Andric   /// Get the declaration of std::terminate for the platform.
14290b57cec5SDimitry Andric   llvm::FunctionCallee getTerminateFn();
14300b57cec5SDimitry Andric 
14310b57cec5SDimitry Andric   llvm::SanitizerStatReport &getSanStats();
14320b57cec5SDimitry Andric 
14330b57cec5SDimitry Andric   llvm::Value *
14340b57cec5SDimitry Andric   createOpenCLIntToSamplerConversion(const Expr *E, CodeGenFunction &CGF);
14350b57cec5SDimitry Andric 
14360b57cec5SDimitry Andric   /// OpenCL v1.2 s5.6.4.6 allows the compiler to store kernel argument
14370b57cec5SDimitry Andric   /// information in the program executable. The argument information stored
14380b57cec5SDimitry Andric   /// includes the argument name, its type, the address and access qualifiers
14390b57cec5SDimitry Andric   /// used. This helper can be used to generate metadata for source code kernel
14400b57cec5SDimitry Andric   /// function as well as generated implicitly kernels. If a kernel is generated
14410b57cec5SDimitry Andric   /// implicitly null value has to be passed to the last two parameters,
14420b57cec5SDimitry Andric   /// otherwise all parameters must have valid non-null values.
14430b57cec5SDimitry Andric   /// \param FN is a pointer to IR function being generated.
14440b57cec5SDimitry Andric   /// \param FD is a pointer to function declaration if any.
14450b57cec5SDimitry Andric   /// \param CGF is a pointer to CodeGenFunction that generates this function.
14460b57cec5SDimitry Andric   void GenOpenCLArgMetadata(llvm::Function *FN,
14470b57cec5SDimitry Andric                             const FunctionDecl *FD = nullptr,
14480b57cec5SDimitry Andric                             CodeGenFunction *CGF = nullptr);
14490b57cec5SDimitry Andric 
14500b57cec5SDimitry Andric   /// Get target specific null pointer.
14510b57cec5SDimitry Andric   /// \param T is the LLVM type of the null pointer.
14520b57cec5SDimitry Andric   /// \param QT is the clang QualType of the null pointer.
14530b57cec5SDimitry Andric   llvm::Constant *getNullPointer(llvm::PointerType *T, QualType QT);
14540b57cec5SDimitry Andric 
14555ffd83dbSDimitry Andric   CharUnits getNaturalTypeAlignment(QualType T,
14565ffd83dbSDimitry Andric                                     LValueBaseInfo *BaseInfo = nullptr,
14575ffd83dbSDimitry Andric                                     TBAAAccessInfo *TBAAInfo = nullptr,
14585ffd83dbSDimitry Andric                                     bool forPointeeType = false);
14595ffd83dbSDimitry Andric   CharUnits getNaturalPointeeTypeAlignment(QualType T,
14605ffd83dbSDimitry Andric                                            LValueBaseInfo *BaseInfo = nullptr,
14615ffd83dbSDimitry Andric                                            TBAAAccessInfo *TBAAInfo = nullptr);
14625ffd83dbSDimitry Andric   bool stopAutoInit();
14635ffd83dbSDimitry Andric 
1464*5f7ddb14SDimitry Andric   /// Print the postfix for externalized static variable for single source
1465*5f7ddb14SDimitry Andric   /// offloading languages CUDA and HIP.
1466*5f7ddb14SDimitry Andric   void printPostfixForExternalizedStaticVar(llvm::raw_ostream &OS) const;
1467*5f7ddb14SDimitry Andric 
14680b57cec5SDimitry Andric private:
14690b57cec5SDimitry Andric   llvm::Constant *GetOrCreateLLVMFunction(
14700b57cec5SDimitry Andric       StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable,
14710b57cec5SDimitry Andric       bool DontDefer = false, bool IsThunk = false,
14720b57cec5SDimitry Andric       llvm::AttributeList ExtraAttrs = llvm::AttributeList(),
14730b57cec5SDimitry Andric       ForDefinition_t IsForDefinition = NotForDefinition);
14740b57cec5SDimitry Andric 
14750b57cec5SDimitry Andric   llvm::Constant *GetOrCreateMultiVersionResolver(GlobalDecl GD,
14760b57cec5SDimitry Andric                                                   llvm::Type *DeclTy,
14770b57cec5SDimitry Andric                                                   const FunctionDecl *FD);
14780b57cec5SDimitry Andric   void UpdateMultiVersionNames(GlobalDecl GD, const FunctionDecl *FD);
14790b57cec5SDimitry Andric 
1480*5f7ddb14SDimitry Andric   llvm::Constant *
1481*5f7ddb14SDimitry Andric   GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
1482*5f7ddb14SDimitry Andric                         unsigned AddrSpace, const VarDecl *D,
1483*5f7ddb14SDimitry Andric                         ForDefinition_t IsForDefinition = NotForDefinition);
14840b57cec5SDimitry Andric 
14850b57cec5SDimitry Andric   bool GetCPUAndFeaturesAttributes(GlobalDecl GD,
14860b57cec5SDimitry Andric                                    llvm::AttrBuilder &AttrBuilder);
14870b57cec5SDimitry Andric   void setNonAliasAttributes(GlobalDecl GD, llvm::GlobalObject *GO);
14880b57cec5SDimitry Andric 
14890b57cec5SDimitry Andric   /// Set function attributes for a function declaration.
14900b57cec5SDimitry Andric   void SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
14910b57cec5SDimitry Andric                              bool IsIncompleteFunction, bool IsThunk);
14920b57cec5SDimitry Andric 
14930b57cec5SDimitry Andric   void EmitGlobalDefinition(GlobalDecl D, llvm::GlobalValue *GV = nullptr);
14940b57cec5SDimitry Andric 
14950b57cec5SDimitry Andric   void EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);
14960b57cec5SDimitry Andric   void EmitMultiVersionFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);
14970b57cec5SDimitry Andric 
14980b57cec5SDimitry Andric   void EmitGlobalVarDefinition(const VarDecl *D, bool IsTentative = false);
1499480093f4SDimitry Andric   void EmitExternalVarDeclaration(const VarDecl *D);
15000b57cec5SDimitry Andric   void EmitAliasDefinition(GlobalDecl GD);
15010b57cec5SDimitry Andric   void emitIFuncDefinition(GlobalDecl GD);
15020b57cec5SDimitry Andric   void emitCPUDispatchDefinition(GlobalDecl GD);
15030b57cec5SDimitry Andric   void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
15040b57cec5SDimitry Andric   void EmitObjCIvarInitializations(ObjCImplementationDecl *D);
15050b57cec5SDimitry Andric 
15060b57cec5SDimitry Andric   // C++ related functions.
15070b57cec5SDimitry Andric 
15080b57cec5SDimitry Andric   void EmitDeclContext(const DeclContext *DC);
15090b57cec5SDimitry Andric   void EmitLinkageSpec(const LinkageSpecDecl *D);
15100b57cec5SDimitry Andric 
15110b57cec5SDimitry Andric   /// Emit the function that initializes C++ thread_local variables.
15120b57cec5SDimitry Andric   void EmitCXXThreadLocalInitFunc();
15130b57cec5SDimitry Andric 
15140b57cec5SDimitry Andric   /// Emit the function that initializes C++ globals.
15150b57cec5SDimitry Andric   void EmitCXXGlobalInitFunc();
15160b57cec5SDimitry Andric 
15175ffd83dbSDimitry Andric   /// Emit the function that performs cleanup associated with C++ globals.
15185ffd83dbSDimitry Andric   void EmitCXXGlobalCleanUpFunc();
15190b57cec5SDimitry Andric 
15200b57cec5SDimitry Andric   /// Emit the function that initializes the specified global (if PerformInit is
15210b57cec5SDimitry Andric   /// true) and registers its destructor.
15220b57cec5SDimitry Andric   void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
15230b57cec5SDimitry Andric                                     llvm::GlobalVariable *Addr,
15240b57cec5SDimitry Andric                                     bool PerformInit);
15250b57cec5SDimitry Andric 
15260b57cec5SDimitry Andric   void EmitPointerToInitFunc(const VarDecl *VD, llvm::GlobalVariable *Addr,
15270b57cec5SDimitry Andric                              llvm::Function *InitFunc, InitSegAttr *ISA);
15280b57cec5SDimitry Andric 
15290b57cec5SDimitry Andric   // FIXME: Hardcoding priority here is gross.
15300b57cec5SDimitry Andric   void AddGlobalCtor(llvm::Function *Ctor, int Priority = 65535,
15310b57cec5SDimitry Andric                      llvm::Constant *AssociatedData = nullptr);
1532af732203SDimitry Andric   void AddGlobalDtor(llvm::Function *Dtor, int Priority = 65535,
1533af732203SDimitry Andric                      bool IsDtorAttrFunc = false);
15340b57cec5SDimitry Andric 
15350b57cec5SDimitry Andric   /// EmitCtorList - Generates a global array of functions and priorities using
15360b57cec5SDimitry Andric   /// the given list and name. This array will have appending linkage and is
15370b57cec5SDimitry Andric   /// suitable for use as a LLVM constructor or destructor array. Clears Fns.
15380b57cec5SDimitry Andric   void EmitCtorList(CtorList &Fns, const char *GlobalName);
15390b57cec5SDimitry Andric 
15400b57cec5SDimitry Andric   /// Emit any needed decls for which code generation was deferred.
15410b57cec5SDimitry Andric   void EmitDeferred();
15420b57cec5SDimitry Andric 
15430b57cec5SDimitry Andric   /// Try to emit external vtables as available_externally if they have emitted
15440b57cec5SDimitry Andric   /// all inlined virtual functions.  It runs after EmitDeferred() and therefore
15450b57cec5SDimitry Andric   /// is not allowed to create new references to things that need to be emitted
15460b57cec5SDimitry Andric   /// lazily.
15470b57cec5SDimitry Andric   void EmitVTablesOpportunistically();
15480b57cec5SDimitry Andric 
15490b57cec5SDimitry Andric   /// Call replaceAllUsesWith on all pairs in Replacements.
15500b57cec5SDimitry Andric   void applyReplacements();
15510b57cec5SDimitry Andric 
15520b57cec5SDimitry Andric   /// Call replaceAllUsesWith on all pairs in GlobalValReplacements.
15530b57cec5SDimitry Andric   void applyGlobalValReplacements();
15540b57cec5SDimitry Andric 
15550b57cec5SDimitry Andric   void checkAliases();
15560b57cec5SDimitry Andric 
15570b57cec5SDimitry Andric   std::map<int, llvm::TinyPtrVector<llvm::Function *>> DtorsUsingAtExit;
15580b57cec5SDimitry Andric 
15590b57cec5SDimitry Andric   /// Register functions annotated with __attribute__((destructor)) using
15600b57cec5SDimitry Andric   /// __cxa_atexit, if it is available, or atexit otherwise.
15610b57cec5SDimitry Andric   void registerGlobalDtorsWithAtExit();
15620b57cec5SDimitry Andric 
1563af732203SDimitry Andric   // When using sinit and sterm functions, unregister
1564af732203SDimitry Andric   // __attribute__((destructor)) annotated functions which were previously
1565af732203SDimitry Andric   // registered by the atexit subroutine using unatexit.
1566af732203SDimitry Andric   void unregisterGlobalDtorsWithUnAtExit();
1567af732203SDimitry Andric 
15680b57cec5SDimitry Andric   void emitMultiVersionFunctions();
15690b57cec5SDimitry Andric 
15700b57cec5SDimitry Andric   /// Emit any vtables which we deferred and still have a use for.
15710b57cec5SDimitry Andric   void EmitDeferredVTables();
15720b57cec5SDimitry Andric 
15730b57cec5SDimitry Andric   /// Emit a dummy function that reference a CoreFoundation symbol when
15740b57cec5SDimitry Andric   /// @available is used on Darwin.
15750b57cec5SDimitry Andric   void emitAtAvailableLinkGuard();
15760b57cec5SDimitry Andric 
15770b57cec5SDimitry Andric   /// Emit the llvm.used and llvm.compiler.used metadata.
15780b57cec5SDimitry Andric   void emitLLVMUsed();
15790b57cec5SDimitry Andric 
15800b57cec5SDimitry Andric   /// Emit the link options introduced by imported modules.
15810b57cec5SDimitry Andric   void EmitModuleLinkOptions();
15820b57cec5SDimitry Andric 
15830b57cec5SDimitry Andric   /// Emit aliases for internal-linkage declarations inside "C" language
15840b57cec5SDimitry Andric   /// linkage specifications, giving them the "expected" name where possible.
15850b57cec5SDimitry Andric   void EmitStaticExternCAliases();
15860b57cec5SDimitry Andric 
15870b57cec5SDimitry Andric   void EmitDeclMetadata();
15880b57cec5SDimitry Andric 
15890b57cec5SDimitry Andric   /// Emit the Clang version as llvm.ident metadata.
15900b57cec5SDimitry Andric   void EmitVersionIdentMetadata();
15910b57cec5SDimitry Andric 
15920b57cec5SDimitry Andric   /// Emit the Clang commandline as llvm.commandline metadata.
15930b57cec5SDimitry Andric   void EmitCommandLineMetadata();
15940b57cec5SDimitry Andric 
15955ffd83dbSDimitry Andric   /// Emit the module flag metadata used to pass options controlling the
15965ffd83dbSDimitry Andric   /// the backend to LLVM.
15975ffd83dbSDimitry Andric   void EmitBackendOptionsMetadata(const CodeGenOptions CodeGenOpts);
15980b57cec5SDimitry Andric 
15990b57cec5SDimitry Andric   /// Emits OpenCL specific Metadata e.g. OpenCL version.
16000b57cec5SDimitry Andric   void EmitOpenCLMetadata();
16010b57cec5SDimitry Andric 
16020b57cec5SDimitry Andric   /// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and
16030b57cec5SDimitry Andric   /// .gcda files in a way that persists in .bc files.
16040b57cec5SDimitry Andric   void EmitCoverageFile();
16050b57cec5SDimitry Andric 
16060b57cec5SDimitry Andric   /// Determine whether the definition must be emitted; if this returns \c
16070b57cec5SDimitry Andric   /// false, the definition can be emitted lazily if it's used.
16080b57cec5SDimitry Andric   bool MustBeEmitted(const ValueDecl *D);
16090b57cec5SDimitry Andric 
16100b57cec5SDimitry Andric   /// Determine whether the definition can be emitted eagerly, or should be
16110b57cec5SDimitry Andric   /// delayed until the end of the translation unit. This is relevant for
16120b57cec5SDimitry Andric   /// definitions whose linkage can change, e.g. implicit function instantions
16130b57cec5SDimitry Andric   /// which may later be explicitly instantiated.
16140b57cec5SDimitry Andric   bool MayBeEmittedEagerly(const ValueDecl *D);
16150b57cec5SDimitry Andric 
16160b57cec5SDimitry Andric   /// Check whether we can use a "simpler", more core exceptions personality
16170b57cec5SDimitry Andric   /// function.
16180b57cec5SDimitry Andric   void SimplifyPersonality();
16190b57cec5SDimitry Andric 
16205ffd83dbSDimitry Andric   /// Helper function for ConstructAttributeList and
16215ffd83dbSDimitry Andric   /// addDefaultFunctionDefinitionAttributes.  Builds a set of function
16225ffd83dbSDimitry Andric   /// attributes to add to a function with the given properties.
16235ffd83dbSDimitry Andric   void getDefaultFunctionAttributes(StringRef Name, bool HasOptnone,
16240b57cec5SDimitry Andric                                     bool AttrOnCallSite,
16250b57cec5SDimitry Andric                                     llvm::AttrBuilder &FuncAttrs);
16260b57cec5SDimitry Andric 
16270b57cec5SDimitry Andric   llvm::Metadata *CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map,
16280b57cec5SDimitry Andric                                                StringRef Suffix);
16290b57cec5SDimitry Andric };
16300b57cec5SDimitry Andric 
16310b57cec5SDimitry Andric }  // end namespace CodeGen
16320b57cec5SDimitry Andric }  // end namespace clang
16330b57cec5SDimitry Andric 
16340b57cec5SDimitry Andric #endif // LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
1635