#ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
#define LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
#include "CGVTables.h"
#include "CodeGenTypeCache.h"
#include "CodeGenTypes.h"
#include "SanitizerMetadata.h"
#include "clang/AST/Attr.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/GlobalDecl.h"
#include "clang/AST/Mangle.h"
#include "clang/Basic/ABI.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/Module.h"
#include "clang/Basic/SanitizerBlacklist.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/Transforms/Utils/SanitizerStats.h"
namespace llvm {
class Module;
class Constant;
class ConstantInt;
class Function;
class GlobalValue;
class DataLayout;
class FunctionType;
class LLVMContext;
class IndexedInstrProfReader;
}
namespace clang {
class ASTContext;
class AtomicType;
class FunctionDecl;
class IdentifierInfo;
class ObjCMethodDecl;
class ObjCImplementationDecl;
class ObjCCategoryImplDecl;
class ObjCProtocolDecl;
class ObjCEncodeExpr;
class BlockExpr;
class CharUnits;
class Decl;
class Expr;
class Stmt;
class InitListExpr;
class StringLiteral;
class NamedDecl;
class ValueDecl;
class VarDecl;
class LangOptions;
class CodeGenOptions;
class HeaderSearchOptions;
class PreprocessorOptions;
class DiagnosticsEngine;
class AnnotateAttr;
class CXXDestructorDecl;
class Module;
class CoverageSourceInfo;
namespace CodeGen {
class CallArgList;
class CodeGenFunction;
class CodeGenTBAA;
class CGCXXABI;
class CGDebugInfo;
class CGObjCRuntime;
class CGOpenCLRuntime;
class CGOpenMPRuntime;
class CGCUDARuntime;
class BlockFieldFlags;
class FunctionArgList;
class CoverageMappingModuleGen;
class TargetCodeGenInfo;
struct OrderGlobalInits {
unsigned int priority;
unsigned int lex_order;
OrderGlobalInits(unsigned int p, unsigned int l)
: priority(p), lex_order(l) {}
bool operator==(const OrderGlobalInits &RHS) const {
return priority == RHS.priority && lex_order == RHS.lex_order;
}
bool operator<(const OrderGlobalInits &RHS) const {
return std::tie(priority, lex_order) <
std::tie(RHS.priority, RHS.lex_order);
}
};
struct ObjCEntrypoints {
ObjCEntrypoints() { memset(this, 0, sizeof(*this)); }
llvm::Constant *objc_autoreleasePoolPop;
llvm::Constant *objc_autoreleasePoolPush;
llvm::Constant *objc_autorelease;
llvm::Constant *objc_autoreleaseReturnValue;
llvm::Constant *objc_copyWeak;
llvm::Constant *objc_destroyWeak;
llvm::Constant *objc_initWeak;
llvm::Constant *objc_loadWeak;
llvm::Constant *objc_loadWeakRetained;
llvm::Constant *objc_moveWeak;
llvm::Constant *objc_retain;
llvm::Constant *objc_retainAutorelease;
llvm::Constant *objc_retainAutoreleaseReturnValue;
llvm::Constant *objc_retainAutoreleasedReturnValue;
llvm::Constant *objc_retainBlock;
llvm::Constant *objc_release;
llvm::Constant *objc_storeStrong;
llvm::Constant *objc_storeWeak;
llvm::Constant *objc_unsafeClaimAutoreleasedReturnValue;
llvm::InlineAsm *retainAutoreleasedReturnValueMarker;
llvm::Constant *clang_arc_use;
};
class InstrProfStats {
uint32_t VisitedInMainFile;
uint32_t MissingInMainFile;
uint32_t Visited;
uint32_t Missing;
uint32_t Mismatched;
public:
InstrProfStats()
: VisitedInMainFile(0), MissingInMainFile(0), Visited(0), Missing(0),
Mismatched(0) {}
void addVisited(bool MainFile) {
if (MainFile)
++VisitedInMainFile;
++Visited;
}
void addMissing(bool MainFile) {
if (MainFile)
++MissingInMainFile;
++Missing;
}
void addMismatched(bool MainFile) { ++Mismatched; }
bool hasDiagnostics() { return Missing || Mismatched; }
void reportDiagnostics(DiagnosticsEngine &Diags, StringRef MainFile);
};
class BlockByrefHelpers : public llvm::FoldingSetNode {
public:
llvm::Constant *CopyHelper;
llvm::Constant *DisposeHelper;
CharUnits Alignment;
BlockByrefHelpers(CharUnits alignment) : Alignment(alignment) {}
BlockByrefHelpers(const BlockByrefHelpers &) = default;
virtual ~BlockByrefHelpers();
void Profile(llvm::FoldingSetNodeID &id) const {
id.AddInteger(Alignment.getQuantity());
profileImpl(id);
}
virtual void profileImpl(llvm::FoldingSetNodeID &id) const = 0;
virtual bool needsCopy() const { return true; }
virtual void emitCopy(CodeGenFunction &CGF, Address dest, Address src) = 0;
virtual bool needsDispose() const { return true; }
virtual void emitDispose(CodeGenFunction &CGF, Address field) = 0;
};
class CodeGenModule : public CodeGenTypeCache {
CodeGenModule(const CodeGenModule &) = delete;
void operator=(const CodeGenModule &) = delete;
public:
struct Structor {
Structor() : Priority(0), Initializer(nullptr), AssociatedData(nullptr) {}
Structor(int Priority, llvm::Constant *Initializer,
llvm::Constant *AssociatedData)
: Priority(Priority), Initializer(Initializer),
AssociatedData(AssociatedData) {}
int Priority;
llvm::Constant *Initializer;
llvm::Constant *AssociatedData;
};
typedef std::vector<Structor> CtorList;
private:
ASTContext &Context;
const LangOptions &LangOpts;
const HeaderSearchOptions &HeaderSearchOpts; const PreprocessorOptions &PreprocessorOpts; const CodeGenOptions &CodeGenOpts;
llvm::Module &TheModule;
DiagnosticsEngine &Diags;
const TargetInfo &Target;
std::unique_ptr<CGCXXABI> ABI;
llvm::LLVMContext &VMContext;
CodeGenTBAA *TBAA;
mutable const TargetCodeGenInfo *TheTargetCodeGenInfo;
CodeGenTypes Types;
CodeGenVTables VTables;
CGObjCRuntime* ObjCRuntime;
CGOpenCLRuntime* OpenCLRuntime;
CGOpenMPRuntime* OpenMPRuntime;
CGCUDARuntime* CUDARuntime;
CGDebugInfo* DebugInfo;
ObjCEntrypoints *ObjCData;
llvm::MDNode *NoObjCARCExceptionsMetadata;
std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader;
InstrProfStats PGOStats;
std::unique_ptr<llvm::SanitizerStatReport> SanStats;
llvm::SmallPtrSet<llvm::GlobalValue*, 10> WeakRefReferences;
std::map<StringRef, GlobalDecl> DeferredDecls;
struct DeferredGlobal {
DeferredGlobal(llvm::GlobalValue *GV, GlobalDecl GD) : GV(GV), GD(GD) {}
llvm::TrackingVH<llvm::GlobalValue> GV;
GlobalDecl GD;
};
std::vector<DeferredGlobal> DeferredDeclsToEmit;
void addDeferredDeclToEmit(llvm::GlobalValue *GV, GlobalDecl GD) {
DeferredDeclsToEmit.emplace_back(GV, GD);
}
std::vector<GlobalDecl> Aliases;
typedef llvm::StringMap<llvm::TrackingVH<llvm::Constant> > ReplacementsTy;
ReplacementsTy Replacements;
llvm::SmallVector<std::pair<llvm::GlobalValue *, llvm::Constant *>, 8>
GlobalValReplacements;
llvm::DenseSet<GlobalDecl> DiagnosedConflictingDefinitions;
std::vector<const CXXRecordDecl*> DeferredVTables;
std::vector<llvm::WeakVH> LLVMUsed;
std::vector<llvm::WeakVH> LLVMCompilerUsed;
CtorList GlobalCtors;
CtorList GlobalDtors;
llvm::MapVector<GlobalDecl, StringRef> MangledDeclNames;
llvm::StringMap<GlobalDecl, llvm::BumpPtrAllocator> Manglings;
std::vector<llvm::Constant*> Annotations;
llvm::StringMap<llvm::Constant*> AnnotationStrings;
llvm::StringMap<llvm::GlobalVariable *> CFConstantStringMap;
llvm::DenseMap<llvm::Constant *, llvm::GlobalVariable *> ConstantStringMap;
llvm::DenseMap<const Decl*, llvm::Constant *> StaticLocalDeclMap;
llvm::DenseMap<const Decl*, llvm::GlobalVariable*> StaticLocalDeclGuardMap;
llvm::DenseMap<const Expr*, llvm::Constant *> MaterializedGlobalTemporaryMap;
llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap;
llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap;
llvm::DenseMap<QualType, llvm::Constant *> TypeDescriptorMap;
typedef llvm::MapVector<IdentifierInfo *,
llvm::GlobalValue *> StaticExternCMap;
StaticExternCMap StaticExternCValues;
std::vector<const VarDecl *> CXXThreadLocals;
std::vector<llvm::Function *> CXXThreadLocalInits;
std::vector<const VarDecl *> CXXThreadLocalInitVars;
std::vector<llvm::Function *> CXXGlobalInits;
llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition;
typedef std::pair<OrderGlobalInits, llvm::Function*> GlobalInitData;
struct GlobalInitPriorityCmp {
bool operator()(const GlobalInitData &LHS,
const GlobalInitData &RHS) const {
return LHS.first.priority < RHS.first.priority;
}
};
SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits;
std::vector<std::pair<llvm::WeakVH,llvm::Constant*> > CXXGlobalDtors;
llvm::SetVector<clang::Module *> ImportedModules;
SmallVector<llvm::Metadata *, 16> LinkerOptionsMetadata;
llvm::WeakVH CFConstantStringClassRef;
llvm::WeakVH ConstantStringClassRef;
llvm::StructType *NSConstantStringType;
QualType ObjCFastEnumerationStateType;
void createObjCRuntime();
void createOpenCLRuntime();
void createOpenMPRuntime();
void createCUDARuntime();
bool isTriviallyRecursive(const FunctionDecl *F);
bool shouldEmitFunction(GlobalDecl GD);
llvm::Constant *NSConcreteGlobalBlock;
llvm::Constant *NSConcreteStackBlock;
llvm::Constant *BlockObjectAssign;
llvm::Constant *BlockObjectDispose;
llvm::Type *BlockDescriptorType;
llvm::Type *GenericBlockLiteralType;
struct {
int GlobalUniqueCount;
} Block;
llvm::Constant *LifetimeStartFn;
llvm::Constant *LifetimeEndFn;
GlobalDecl initializedGlobalDecl;
std::unique_ptr<SanitizerMetadata> SanitizerMD;
llvm::DenseMap<const Decl *, bool> DeferredEmptyCoverageMappingDecls;
std::unique_ptr<CoverageMappingModuleGen> CoverageMapping;
llvm::DenseMap<QualType, llvm::Metadata *> MetadataIdMap;
public:
CodeGenModule(ASTContext &C, const HeaderSearchOptions &headersearchopts,
const PreprocessorOptions &ppopts,
const CodeGenOptions &CodeGenOpts, llvm::Module &M,
DiagnosticsEngine &Diags,
CoverageSourceInfo *CoverageInfo = nullptr);
~CodeGenModule();
void clear();
void Release();
CGObjCRuntime &getObjCRuntime() {
if (!ObjCRuntime) createObjCRuntime();
return *ObjCRuntime;
}
bool hasObjCRuntime() { return !!ObjCRuntime; }
CGOpenCLRuntime &getOpenCLRuntime() {
assert(OpenCLRuntime != nullptr);
return *OpenCLRuntime;
}
CGOpenMPRuntime &getOpenMPRuntime() {
assert(OpenMPRuntime != nullptr);
return *OpenMPRuntime;
}
CGCUDARuntime &getCUDARuntime() {
assert(CUDARuntime != nullptr);
return *CUDARuntime;
}
ObjCEntrypoints &getObjCEntrypoints() const {
assert(ObjCData != nullptr);
return *ObjCData;
}
InstrProfStats &getPGOStats() { return PGOStats; }
llvm::IndexedInstrProfReader *getPGOReader() const { return PGOReader.get(); }
CoverageMappingModuleGen *getCoverageMapping() const {
return CoverageMapping.get();
}
llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) {
return StaticLocalDeclMap[D];
}
void setStaticLocalDeclAddress(const VarDecl *D,
llvm::Constant *C) {
StaticLocalDeclMap[D] = C;
}
llvm::Constant *
getOrCreateStaticVarDecl(const VarDecl &D,
llvm::GlobalValue::LinkageTypes Linkage);
llvm::GlobalVariable *getStaticLocalDeclGuardAddress(const VarDecl *D) {
return StaticLocalDeclGuardMap[D];
}
void setStaticLocalDeclGuardAddress(const VarDecl *D,
llvm::GlobalVariable *C) {
StaticLocalDeclGuardMap[D] = C;
}
bool lookupRepresentativeDecl(StringRef MangledName,
GlobalDecl &Result) const;
llvm::Constant *getAtomicSetterHelperFnMap(QualType Ty) {
return AtomicSetterHelperFnMap[Ty];
}
void setAtomicSetterHelperFnMap(QualType Ty,
llvm::Constant *Fn) {
AtomicSetterHelperFnMap[Ty] = Fn;
}
llvm::Constant *getAtomicGetterHelperFnMap(QualType Ty) {
return AtomicGetterHelperFnMap[Ty];
}
void setAtomicGetterHelperFnMap(QualType Ty,
llvm::Constant *Fn) {
AtomicGetterHelperFnMap[Ty] = Fn;
}
llvm::Constant *getTypeDescriptorFromMap(QualType Ty) {
return TypeDescriptorMap[Ty];
}
void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C) {
TypeDescriptorMap[Ty] = C;
}
CGDebugInfo *getModuleDebugInfo() { return DebugInfo; }
llvm::MDNode *getNoObjCARCExceptionsMetadata() {
if (!NoObjCARCExceptionsMetadata)
NoObjCARCExceptionsMetadata = llvm::MDNode::get(getLLVMContext(), None);
return NoObjCARCExceptionsMetadata;
}
ASTContext &getContext() const { return Context; }
const LangOptions &getLangOpts() const { return LangOpts; }
const HeaderSearchOptions &getHeaderSearchOpts()
const { return HeaderSearchOpts; }
const PreprocessorOptions &getPreprocessorOpts()
const { return PreprocessorOpts; }
const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
llvm::Module &getModule() const { return TheModule; }
DiagnosticsEngine &getDiags() const { return Diags; }
const llvm::DataLayout &getDataLayout() const {
return TheModule.getDataLayout();
}
const TargetInfo &getTarget() const { return Target; }
const llvm::Triple &getTriple() const;
bool supportsCOMDAT() const;
void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO);
CGCXXABI &getCXXABI() const { return *ABI; }
llvm::LLVMContext &getLLVMContext() { return VMContext; }
bool shouldUseTBAA() const { return TBAA != nullptr; }
const TargetCodeGenInfo &getTargetCodeGenInfo();
CodeGenTypes &getTypes() { return Types; }
CodeGenVTables &getVTables() { return VTables; }
ItaniumVTableContext &getItaniumVTableContext() {
return VTables.getItaniumVTableContext();
}
MicrosoftVTableContext &getMicrosoftVTableContext() {
return VTables.getMicrosoftVTableContext();
}
CtorList &getGlobalCtors() { return GlobalCtors; }
CtorList &getGlobalDtors() { return GlobalDtors; }
llvm::MDNode *getTBAAInfo(QualType QTy);
llvm::MDNode *getTBAAInfoForVTablePtr();
llvm::MDNode *getTBAAStructInfo(QualType QTy);
llvm::MDNode *getTBAAStructTagInfo(QualType BaseTy, llvm::MDNode *AccessN,
uint64_t O);
bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor);
bool isPaddedAtomicType(QualType type);
bool isPaddedAtomicType(const AtomicType *type);
void DecorateInstructionWithTBAA(llvm::Instruction *Inst,
llvm::MDNode *TBAAInfo,
bool ConvertTypeToTag = true);
void DecorateInstructionWithInvariantGroup(llvm::Instruction *I,
const CXXRecordDecl *RD);
llvm::ConstantInt *getSize(CharUnits numChars);
void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const;
void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const;
static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) {
switch (V) {
case DefaultVisibility: return llvm::GlobalValue::DefaultVisibility;
case HiddenVisibility: return llvm::GlobalValue::HiddenVisibility;
case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility;
}
llvm_unreachable("unknown visibility!");
}
llvm::Constant *GetAddrOfGlobal(GlobalDecl GD, bool IsForDefinition = false);
llvm::GlobalVariable *
CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty,
llvm::GlobalValue::LinkageTypes Linkage);
llvm::Function *
CreateGlobalInitOrDestructFunction(llvm::FunctionType *ty, const Twine &name,
const CGFunctionInfo &FI,
SourceLocation Loc = SourceLocation(),
bool TLS = false);
unsigned GetGlobalVarAddressSpace(const VarDecl *D, unsigned AddrSpace);
llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
llvm::Type *Ty = nullptr,
bool IsForDefinition = false);
llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = nullptr,
bool ForVTable = false,
bool DontDefer = false,
bool IsForDefinition = false);
llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false);
ConstantAddress GetAddrOfUuidDescriptor(const CXXUuidofExpr* E);
llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk);
ConstantAddress GetWeakRefReference(const ValueDecl *VD);
CharUnits getClassPointerAlignment(const CXXRecordDecl *CD);
CharUnits getVBaseAlignment(CharUnits DerivedAlign,
const CXXRecordDecl *Derived,
const CXXRecordDecl *VBase);
CharUnits getDynamicOffsetAlignment(CharUnits ActualAlign,
const CXXRecordDecl *Class,
CharUnits ExpectedTargetAlign);
CharUnits
computeNonVirtualBaseClassOffset(const CXXRecordDecl *DerivedClass,
CastExpr::path_const_iterator Start,
CastExpr::path_const_iterator End);
llvm::Constant *
GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl,
CastExpr::path_const_iterator PathBegin,
CastExpr::path_const_iterator PathEnd);
llvm::FoldingSet<BlockByrefHelpers> ByrefHelpersCache;
int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; }
llvm::Type *getBlockDescriptorType();
llvm::Type *getGenericBlockLiteralType();
llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, const char *);
ConstantAddress GetAddrOfConstantCFString(const StringLiteral *Literal);
ConstantAddress GetAddrOfConstantString(const StringLiteral *Literal);
llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E);
ConstantAddress
GetAddrOfConstantStringFromLiteral(const StringLiteral *S,
StringRef Name = ".str");
ConstantAddress
GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *);
ConstantAddress
GetAddrOfConstantCString(const std::string &Str,
const char *GlobalName = nullptr);
ConstantAddress GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr*E);
ConstantAddress GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E,
const Expr *Inner);
QualType getObjCFastEnumerationStateType();
llvm::Function *codegenCXXStructor(const CXXMethodDecl *MD,
StructorType Type);
llvm::Constant *
getAddrOfCXXStructor(const CXXMethodDecl *MD, StructorType Type,
const CGFunctionInfo *FnInfo = nullptr,
llvm::FunctionType *FnType = nullptr,
bool DontDefer = false, bool IsForDefinition = false);
llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD,
unsigned BuiltinID);
llvm::Function *getIntrinsic(unsigned IID, ArrayRef<llvm::Type*> Tys = None);
void EmitTopLevelDecl(Decl *D);
void AddDeferredUnusedCoverageMapping(Decl *D);
void ClearUnusedCoverageMapping(const Decl *D);
void EmitDeferredUnusedCoverageMappings();
void HandleCXXStaticMemberVarInstantiation(VarDecl *VD);
template<typename SomeDecl>
void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
void addUsedGlobal(llvm::GlobalValue *GV);
void addCompilerUsedGlobal(llvm::GlobalValue *GV);
void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) {
CXXGlobalDtors.emplace_back(DtorFn, Object);
}
llvm::Constant *CreateRuntimeFunction(llvm::FunctionType *Ty,
StringRef Name,
llvm::AttributeSet ExtraAttrs =
llvm::AttributeSet());
llvm::Constant *CreateBuiltinFunction(llvm::FunctionType *Ty,
StringRef Name,
llvm::AttributeSet ExtraAttrs =
llvm::AttributeSet());
llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty,
StringRef Name);
llvm::Constant *getNSConcreteGlobalBlock();
llvm::Constant *getNSConcreteStackBlock();
llvm::Constant *getBlockObjectAssign();
llvm::Constant *getBlockObjectDispose();
llvm::Constant *getLLVMLifetimeStartFn();
llvm::Constant *getLLVMLifetimeEndFn();
void UpdateCompletedType(const TagDecl *TD);
llvm::Constant *getMemberPointerConstant(const UnaryOperator *e);
llvm::Constant *EmitConstantInit(const VarDecl &D,
CodeGenFunction *CGF = nullptr);
llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType,
CodeGenFunction *CGF = nullptr);
llvm::Constant *EmitConstantValue(const APValue &Value, QualType DestType,
CodeGenFunction *CGF = nullptr);
llvm::Constant *EmitConstantValueForMemory(const APValue &Value,
QualType DestType,
CodeGenFunction *CGF = nullptr);
void EmitExplicitCastExprType(const ExplicitCastExpr *E,
CodeGenFunction *CGF = nullptr);
llvm::Constant *EmitNullConstant(QualType T);
llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record);
void Error(SourceLocation loc, StringRef error);
void ErrorUnsupported(const Stmt *S, const char *Type);
void ErrorUnsupported(const Decl *D, const char *Type);
void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F,
const CGFunctionInfo &FI);
void SetLLVMFunctionAttributes(const Decl *D,
const CGFunctionInfo &Info,
llvm::Function *F);
void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F);
bool ReturnTypeUsesSRet(const CGFunctionInfo &FI);
bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI);
bool ReturnTypeUsesFPRet(QualType ResultType);
bool ReturnTypeUsesFP2Ret(QualType ResultType);
void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info,
CGCalleeInfo CalleeInfo, AttributeListType &PAL,
unsigned &CallingConv, bool AttrOnCallSite);
void getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap,
const FunctionDecl *FD);
StringRef getMangledName(GlobalDecl GD);
StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD);
void EmitTentativeDefinition(const VarDecl *D);
void EmitVTable(CXXRecordDecl *Class);
void AppendLinkerOptions(StringRef Opts);
void AddDetectMismatch(StringRef Name, StringRef Value);
void AddDependentLib(StringRef Lib);
llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD);
void setFunctionLinkage(GlobalDecl GD, llvm::Function *F) {
F->setLinkage(getFunctionLinkage(GD));
}
void setFunctionDLLStorageClass(GlobalDecl GD, llvm::Function *F);
llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD);
CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const;
llvm::GlobalValue::LinkageTypes
getLLVMLinkageForDeclarator(const DeclaratorDecl *D, GVALinkage Linkage,
bool IsConstantVariable);
llvm::GlobalValue::LinkageTypes
getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant);
void EmitGlobalAnnotations();
llvm::Constant *EmitAnnotationString(StringRef Str);
llvm::Constant *EmitAnnotationUnit(SourceLocation Loc);
llvm::Constant *EmitAnnotationLineNo(SourceLocation L);
llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
const AnnotateAttr *AA,
SourceLocation L);
void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
bool isInSanitizerBlacklist(llvm::Function *Fn, SourceLocation Loc) const;
bool isInSanitizerBlacklist(llvm::GlobalVariable *GV, SourceLocation Loc,
QualType Ty,
StringRef Category = StringRef()) const;
SanitizerMetadata *getSanitizerMetadata() {
return SanitizerMD.get();
}
void addDeferredVTable(const CXXRecordDecl *RD) {
DeferredVTables.push_back(RD);
}
void EmitGlobal(GlobalDecl D);
bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target,
bool InEveryTU);
bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D);
void setFunctionDefinitionAttributes(const FunctionDecl *D,
llvm::Function *F);
llvm::GlobalValue *GetGlobalValue(StringRef Ref);
void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV);
void setAliasAttributes(const Decl *D, llvm::GlobalValue *GV);
void addReplacement(StringRef Name, llvm::Constant *C);
void addGlobalValReplacement(llvm::GlobalValue *GV, llvm::Constant *C);
void EmitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D);
bool IsCFIBlacklistedRecord(const CXXRecordDecl *RD);
void EmitVTableBitSetEntries(llvm::GlobalVariable *VTable,
const VTableLayout &VTLayout);
llvm::ConstantInt *CreateCfiIdForTypeMetadata(llvm::Metadata *MD);
llvm::Metadata *CreateMetadataIdentifierForType(QualType T);
void CreateFunctionBitSetEntry(const FunctionDecl *FD, llvm::Function *F);
void CreateVTableBitSetEntry(llvm::NamedMDNode *BitsetsMD,
llvm::GlobalVariable *VTable, CharUnits Offset,
const CXXRecordDecl *RD);
llvm::Constant *getTerminateFn();
llvm::SanitizerStatReport &getSanStats();
private:
llvm::Constant *
GetOrCreateLLVMFunction(StringRef MangledName, llvm::Type *Ty, GlobalDecl D,
bool ForVTable, bool DontDefer = false,
bool IsThunk = false,
llvm::AttributeSet ExtraAttrs = llvm::AttributeSet(),
bool IsForDefinition = false);
llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName,
llvm::PointerType *PTy,
const VarDecl *D,
bool IsForDefinition = false);
void setNonAliasAttributes(const Decl *D, llvm::GlobalObject *GO);
void SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
bool IsIncompleteFunction, bool IsThunk);
void EmitGlobalDefinition(GlobalDecl D, llvm::GlobalValue *GV = nullptr);
void EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);
void EmitGlobalVarDefinition(const VarDecl *D, bool IsTentative = false);
void EmitAliasDefinition(GlobalDecl GD);
void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
void EmitObjCIvarInitializations(ObjCImplementationDecl *D);
void EmitNamespace(const NamespaceDecl *D);
void EmitLinkageSpec(const LinkageSpecDecl *D);
void CompleteDIClassType(const CXXMethodDecl* D);
void EmitCXXThreadLocalInitFunc();
void EmitCXXGlobalInitFunc();
void EmitCXXGlobalDtorFunc();
void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
llvm::GlobalVariable *Addr,
bool PerformInit);
void EmitPointerToInitFunc(const VarDecl *VD, llvm::GlobalVariable *Addr,
llvm::Function *InitFunc, InitSegAttr *ISA);
void AddGlobalCtor(llvm::Function *Ctor, int Priority = 65535,
llvm::Constant *AssociatedData = nullptr);
void AddGlobalDtor(llvm::Function *Dtor, int Priority = 65535);
void EmitCtorList(const CtorList &Fns, const char *GlobalName);
void EmitDeferred();
void applyReplacements();
void applyGlobalValReplacements();
void checkAliases();
void EmitDeferredVTables();
void emitLLVMUsed();
void EmitModuleLinkOptions();
void EmitStaticExternCAliases();
void EmitDeclMetadata();
void EmitVersionIdentMetadata();
void EmitTargetMetadata();
void EmitCoverageFile();
llvm::Constant *EmitUuidofInitializer(StringRef uuidstr);
bool MustBeEmitted(const ValueDecl *D);
bool MayBeEmittedEagerly(const ValueDecl *D);
void SimplifyPersonality();
};
} }
#endif // LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H