clang 20.0.0git
Functions | Variables
CodeGenModule.cpp File Reference
#include "CodeGenModule.h"
#include "ABIInfo.h"
#include "CGBlocks.h"
#include "CGCUDARuntime.h"
#include "CGCXXABI.h"
#include "CGCall.h"
#include "CGDebugInfo.h"
#include "CGHLSLRuntime.h"
#include "CGObjCRuntime.h"
#include "CGOpenCLRuntime.h"
#include "CGOpenMPRuntime.h"
#include "CGOpenMPRuntimeGPU.h"
#include "CodeGenFunction.h"
#include "CodeGenPGO.h"
#include "ConstantEmitter.h"
#include "CoverageMappingGen.h"
#include "TargetInfo.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTLambda.h"
#include "clang/AST/CharUnits.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Mangle.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/CodeGenOptions.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/Module.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/Version.h"
#include "clang/CodeGen/BackendUtil.h"
#include "clang/CodeGen/ConstantInitBuilder.h"
#include "clang/Frontend/FrontendDiagnostic.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
#include "llvm/IR/AttributeMask.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ProfileSummary.h"
#include "llvm/ProfileData/InstrProfReader.h"
#include "llvm/ProfileData/SampleProf.h"
#include "llvm/Support/CRC.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/xxhash.h"
#include "llvm/TargetParser/RISCVISAInfo.h"
#include "llvm/TargetParser/Triple.h"
#include "llvm/TargetParser/X86TargetParser.h"
#include "llvm/Transforms/Utils/BuildLibCalls.h"
#include <optional>

Go to the source code of this file.

Functions

static llvm::cl::opt< boolLimitedCoverage ("limited-coverage-experimental", llvm::cl::Hidden, llvm::cl::desc("Emit limited coverage mapping information (experimental)"))
 
static CGCXXABIcreateCXXABI (CodeGenModule &CGM)
 
static std::unique_ptr< TargetCodeGenInfocreateTargetCodeGenInfo (CodeGenModule &CGM)
 
static const llvm::GlobalValue * getAliasedGlobal (const llvm::GlobalValue *GV)
 
static bool checkAliasedGlobal (const ASTContext &Context, DiagnosticsEngine &Diags, SourceLocation Location, bool IsIFunc, const llvm::GlobalValue *Alias, const llvm::GlobalValue *&GV, const llvm::MapVector< GlobalDecl, StringRef > &MangledDeclNames, SourceRange AliasRange)
 
static void checkAliasForTocData (llvm::GlobalVariable *GVar, const CodeGenOptions &CodeGenOpts, DiagnosticsEngine &Diags, SourceLocation Location)
 
static std::optional< llvm::GlobalValue::VisibilityTypes > getLLVMVisibility (clang::LangOptions::VisibilityFromDLLStorageClassKinds K)
 
void setLLVMVisibility (llvm::GlobalValue &GV, std::optional< llvm::GlobalValue::VisibilityTypes > V)
 
static void setVisibilityFromDLLStorageClass (const clang::LangOptions &LO, llvm::Module &M)
 
static bool isStackProtectorOn (const LangOptions &LangOpts, const llvm::Triple &Triple, clang::LangOptions::StackProtectorMode Mode)
 
static bool shouldAssumeDSOLocal (const CodeGenModule &CGM, llvm::GlobalValue *GV)
 
static llvm::GlobalVariable::ThreadLocalMode GetLLVMTLSModel (StringRef S)
 
static std::string getCPUSpecificMangling (const CodeGenModule &CGM, StringRef Name)
 
static void AppendCPUSpecificCPUDispatchMangling (const CodeGenModule &CGM, const CPUSpecificAttr *Attr, unsigned CPUIndex, raw_ostream &Out)
 
static bool isUniqueInternalLinkageDecl (GlobalDecl GD, CodeGenModule &CGM)
 
static std::string getMangledNameImpl (CodeGenModule &CGM, GlobalDecl GD, const NamedDecl *ND, bool OmitMultiVersionMangling=false)
 
static void removeImageAccessQualifier (std::string &TyName)
 
static unsigned ArgInfoAddressSpace (LangAS AS)
 
static bool hasUnwindExceptions (const LangOptions &LangOpts)
 Determines whether the language options require us to model unwind exceptions.
 
static bool requiresMemberFunctionPointerTypeMetadata (CodeGenModule &CGM, const CXXMethodDecl *MD)
 
static void setLinkageForGV (llvm::GlobalValue *GV, const NamedDecl *ND)
 
static bool allowKCFIIdentifier (StringRef Name)
 
static void emitUsed (CodeGenModule &CGM, StringRef Name, std::vector< llvm::WeakTrackingVH > &List)
 
static void addLinkOptionsPostorder (CodeGenModule &CGM, Module *Mod, SmallVectorImpl< llvm::MDNode * > &Metadata, llvm::SmallPtrSet< Module *, 16 > &Visited)
 Add link options implied by the given module, including modules it depends on, using a postorder walk.
 
template<typename AttrT >
static bool hasImplicitAttr (const ValueDecl *D)
 
static bool HasNonDllImportDtor (QualType T)
 
static void ReplaceUsesOfNonProtoTypeWithRealFunction (llvm::GlobalValue *Old, llvm::Function *NewFn)
 ReplaceUsesOfNonProtoTypeWithRealFunction - This function is called when we implement a function with no prototype, e.g.
 
static unsigned TargetMVPriority (const TargetInfo &TI, const CodeGenFunction::MultiVersionResolverOption &RO)
 
llvm::GlobalValue::LinkageTypes getMultiversionLinkage (CodeGenModule &CGM, GlobalDecl GD)
 
static void replaceDeclarationWith (llvm::GlobalValue *Old, llvm::Constant *New)
 
static const FunctionDeclGetRuntimeFunctionDecl (ASTContext &C, StringRef Name)
 
static llvm::Constant * castStringLiteralToDefaultAddressSpace (CodeGenModule &CGM, llvm::GlobalVariable *GV)
 
static bool shouldBeInCOMDAT (CodeGenModule &CGM, const Decl &D)
 
static bool isVarDeclStrongDefinition (const ASTContext &Context, CodeGenModule &CGM, const VarDecl *D, bool NoCommon)
 
static void replaceUsesOfNonProtoConstant (llvm::Constant *old, llvm::Function *newFn)
 Replace the uses of a function that was declared with a non-proto type.
 
static llvm::StringMapEntry< llvm::GlobalVariable * > & GetConstantCFStringEntry (llvm::StringMap< llvm::GlobalVariable * > &Map, const StringLiteral *Literal, bool TargetIsLSB, bool &IsUTF16, unsigned &StringLength)
 
static llvm::GlobalVariable * GenerateStringLiteral (llvm::Constant *C, llvm::GlobalValue::LinkageTypes LT, CodeGenModule &CGM, StringRef GlobalName, CharUnits Alignment)
 
static bool needsDestructMethod (ObjCImplementationDecl *impl)
 
static bool AllTrivialInitializers (CodeGenModule &CGM, ObjCImplementationDecl *D)
 
static llvm::Constant * GetPointerConstant (llvm::LLVMContext &Context, const void *Ptr)
 Turns the given pointer into a constant.
 
static void EmitGlobalDeclMetadata (CodeGenModule &CGM, llvm::NamedMDNode *&GlobalMetadata, GlobalDecl D, llvm::GlobalValue *Addr)
 
static QualType GeneralizeType (ASTContext &Ctx, QualType Ty)
 
static QualType GeneralizeFunctionType (ASTContext &Ctx, QualType Ty)
 

Variables

static const char AnnotationSection [] = "llvm.metadata"
 

Function Documentation

◆ addLinkOptionsPostorder()

static void addLinkOptionsPostorder ( CodeGenModule CGM,
Module Mod,
SmallVectorImpl< llvm::MDNode * > &  Metadata,
llvm::SmallPtrSet< Module *, 16 > &  Visited 
)
static

◆ allowKCFIIdentifier()

static bool allowKCFIIdentifier ( StringRef  Name)
static

Definition at line 2819 of file CodeGenModule.cpp.

References clang::C.

Referenced by clang::CodeGen::CodeGenModule::finalizeKCFITypes().

◆ AllTrivialInitializers()

static bool AllTrivialInitializers ( CodeGenModule CGM,
ObjCImplementationDecl D 
)
static

◆ AppendCPUSpecificCPUDispatchMangling()

static void AppendCPUSpecificCPUDispatchMangling ( const CodeGenModule CGM,
const CPUSpecificAttr *  Attr,
unsigned  CPUIndex,
raw_ostream &  Out 
)
static

◆ ArgInfoAddressSpace()

static unsigned ArgInfoAddressSpace ( LangAS  AS)
static

◆ castStringLiteralToDefaultAddressSpace()

static llvm::Constant * castStringLiteralToDefaultAddressSpace ( CodeGenModule CGM,
llvm::GlobalVariable *  GV 
)
static

◆ checkAliasedGlobal()

static bool checkAliasedGlobal ( const ASTContext Context,
DiagnosticsEngine Diags,
SourceLocation  Location,
bool  IsIFunc,
const llvm::GlobalValue *  Alias,
const llvm::GlobalValue *&  GV,
const llvm::MapVector< GlobalDecl, StringRef > &  MangledDeclNames,
SourceRange  AliasRange 
)
static

◆ checkAliasForTocData()

static void checkAliasForTocData ( llvm::GlobalVariable *  GVar,
const CodeGenOptions CodeGenOpts,
DiagnosticsEngine Diags,
SourceLocation  Location 
)
static

◆ createCXXABI()

static CGCXXABI * createCXXABI ( CodeGenModule CGM)
static

◆ createTargetCodeGenInfo()

static std::unique_ptr< TargetCodeGenInfo > createTargetCodeGenInfo ( CodeGenModule CGM)
static

Definition at line 110 of file CodeGenModule.cpp.

References clang::CodeGen::createAArch64TargetCodeGenInfo(), clang::CodeGen::createAIXTargetCodeGenInfo(), clang::CodeGen::createAMDGPUTargetCodeGenInfo(), clang::CodeGen::createARCTargetCodeGenInfo(), clang::CodeGen::createARMTargetCodeGenInfo(), clang::CodeGen::createAVRTargetCodeGenInfo(), clang::CodeGen::createBPFTargetCodeGenInfo(), clang::CodeGen::createCommonSPIRTargetCodeGenInfo(), clang::CodeGen::createCSKYTargetCodeGenInfo(), clang::CodeGen::createDefaultTargetCodeGenInfo(), clang::CodeGen::createHexagonTargetCodeGenInfo(), clang::CodeGen::createLanaiTargetCodeGenInfo(), clang::CodeGen::createLoongArchTargetCodeGenInfo(), clang::CodeGen::createM68kTargetCodeGenInfo(), clang::CodeGen::createMIPSTargetCodeGenInfo(), clang::CodeGen::createMSP430TargetCodeGenInfo(), clang::CodeGen::createNVPTXTargetCodeGenInfo(), clang::CodeGen::createPNaClTargetCodeGenInfo(), clang::CodeGen::createPPC32TargetCodeGenInfo(), clang::CodeGen::createPPC64_SVR4_TargetCodeGenInfo(), clang::CodeGen::createPPC64TargetCodeGenInfo(), clang::CodeGen::createRISCVTargetCodeGenInfo(), clang::CodeGen::createSparcV8TargetCodeGenInfo(), clang::CodeGen::createSparcV9TargetCodeGenInfo(), clang::CodeGen::createSPIRVTargetCodeGenInfo(), clang::CodeGen::createSystemZTargetCodeGenInfo(), clang::CodeGen::createTCETargetCodeGenInfo(), clang::CodeGen::createVETargetCodeGenInfo(), clang::CodeGen::createWebAssemblyTargetCodeGenInfo(), clang::CodeGen::createWindowsAArch64TargetCodeGenInfo(), clang::CodeGen::createWindowsARMTargetCodeGenInfo(), clang::CodeGen::createWinX86_32TargetCodeGenInfo(), clang::CodeGen::createWinX86_64TargetCodeGenInfo(), clang::CodeGen::createX86_32TargetCodeGenInfo(), clang::CodeGen::createX86_64TargetCodeGenInfo(), clang::CodeGen::createXCoreTargetCodeGenInfo(), clang::CodeGenOptions::FloatABI, clang::CodeGen::CodeGenModule::getCodeGenOpts(), clang::CodeGen::CodeGenModule::getTarget(), and clang::TargetInfo::getTriple().

Referenced by clang::CodeGen::CodeGenModule::getTargetCodeGenInfo().

◆ EmitGlobalDeclMetadata()

static void EmitGlobalDeclMetadata ( CodeGenModule CGM,
llvm::NamedMDNode *&  GlobalMetadata,
GlobalDecl  D,
llvm::GlobalValue *  Addr 
)
static

◆ emitUsed()

static void emitUsed ( CodeGenModule CGM,
StringRef  Name,
std::vector< llvm::WeakTrackingVH > &  List 
)
static

◆ GeneralizeFunctionType()

static QualType GeneralizeFunctionType ( ASTContext Ctx,
QualType  Ty 
)
static

◆ GeneralizeType()

static QualType GeneralizeType ( ASTContext Ctx,
QualType  Ty 
)
static

◆ GenerateStringLiteral()

static llvm::GlobalVariable * GenerateStringLiteral ( llvm::Constant *  C,
llvm::GlobalValue::LinkageTypes  LT,
CodeGenModule CGM,
StringRef  GlobalName,
CharUnits  Alignment 
)
static

◆ getAliasedGlobal()

static const llvm::GlobalValue * getAliasedGlobal ( const llvm::GlobalValue *  GV)
static

Definition at line 561 of file CodeGenModule.cpp.

References clang::C.

Referenced by checkAliasedGlobal().

◆ GetConstantCFStringEntry()

static llvm::StringMapEntry< llvm::GlobalVariable * > & GetConstantCFStringEntry ( llvm::StringMap< llvm::GlobalVariable * > &  Map,
const StringLiteral Literal,
bool  TargetIsLSB,
bool IsUTF16,
unsigned StringLength 
)
static

◆ getCPUSpecificMangling()

static std::string getCPUSpecificMangling ( const CodeGenModule CGM,
StringRef  Name 
)
static

◆ GetLLVMTLSModel()

static llvm::GlobalVariable::ThreadLocalMode GetLLVMTLSModel ( StringRef  S)
static

Definition at line 1785 of file CodeGenModule.cpp.

Referenced by clang::CodeGen::CodeGenModule::setTLSMode().

◆ getLLVMVisibility()

static std::optional< llvm::GlobalValue::VisibilityTypes > getLLVMVisibility ( clang::LangOptions::VisibilityFromDLLStorageClassKinds  K)
static

◆ getMangledNameImpl()

static std::string getMangledNameImpl ( CodeGenModule CGM,
GlobalDecl  GD,
const NamedDecl ND,
bool  OmitMultiVersionMangling = false 
)
static

◆ getMultiversionLinkage()

llvm::GlobalValue::LinkageTypes getMultiversionLinkage ( CodeGenModule CGM,
GlobalDecl  GD 
)

◆ GetPointerConstant()

static llvm::Constant * GetPointerConstant ( llvm::LLVMContext &  Context,
const void *  Ptr 
)
static

Turns the given pointer into a constant.

Definition at line 7293 of file CodeGenModule.cpp.

Referenced by EmitGlobalDeclMetadata().

◆ GetRuntimeFunctionDecl()

static const FunctionDecl * GetRuntimeFunctionDecl ( ASTContext C,
StringRef  Name 
)
static

◆ hasImplicitAttr()

template<typename AttrT >
static bool hasImplicitAttr ( const ValueDecl D)
static

Definition at line 3734 of file CodeGenModule.cpp.

References D, clang::Decl::getAttr(), and clang::Decl::isImplicit().

◆ HasNonDllImportDtor()

static bool HasNonDllImportDtor ( QualType  T)
static

◆ hasUnwindExceptions()

static bool hasUnwindExceptions ( const LangOptions LangOpts)
static

Determines whether the language options require us to model unwind exceptions.

We treat -fexceptions as mandating this except under the fragile ObjC ABI with only ObjC exceptions enabled. This means, for example, that C with -fexceptions enables this.

Definition at line 2401 of file CodeGenModule.cpp.

References clang::ObjCRuntime::hasUnwindExceptions(), and clang::LangOptions::ObjCRuntime.

Referenced by clang::CodeGen::CodeGenModule::SetLLVMFunctionAttributesForDefinition().

◆ isStackProtectorOn()

static bool isStackProtectorOn ( const LangOptions LangOpts,
const llvm::Triple &  Triple,
clang::LangOptions::StackProtectorMode  Mode 
)
static

◆ isUniqueInternalLinkageDecl()

static bool isUniqueInternalLinkageDecl ( GlobalDecl  GD,
CodeGenModule CGM 
)
static

◆ isVarDeclStrongDefinition()

static bool isVarDeclStrongDefinition ( const ASTContext Context,
CodeGenModule CGM,
const VarDecl D,
bool  NoCommon 
)
static

◆ LimitedCoverage()

static llvm::cl::opt< bool > LimitedCoverage ( "limited-coverage-experimental"  ,
llvm::cl::Hidden  ,
llvm::cl::desc("Emit limited coverage mapping information (experimental)")   
)
static

◆ needsDestructMethod()

static bool needsDestructMethod ( ObjCImplementationDecl impl)
static

◆ removeImageAccessQualifier()

static void removeImageAccessQualifier ( std::string &  TyName)
static

◆ replaceDeclarationWith()

static void replaceDeclarationWith ( llvm::GlobalValue *  Old,
llvm::Constant *  New 
)
static

Definition at line 4350 of file CodeGenModule.cpp.

◆ replaceUsesOfNonProtoConstant()

static void replaceUsesOfNonProtoConstant ( llvm::Constant *  old,
llvm::Function *  newFn 
)
static

Replace the uses of a function that was declared with a non-proto type.

We want to silently drop extra arguments from call sites

Definition at line 5859 of file CodeGenModule.cpp.

References replaceUsesOfNonProtoConstant().

Referenced by replaceUsesOfNonProtoConstant(), and ReplaceUsesOfNonProtoTypeWithRealFunction().

◆ ReplaceUsesOfNonProtoTypeWithRealFunction()

static void ReplaceUsesOfNonProtoTypeWithRealFunction ( llvm::GlobalValue *  Old,
llvm::Function *  NewFn 
)
static

ReplaceUsesOfNonProtoTypeWithRealFunction - This function is called when we implement a function with no prototype, e.g.

"int foo() {}". If there are existing call uses of the old function in the module, this adjusts them to call the new function directly.

This is not just a cleanup: the always_inline pass requires direct calls to functions to be able to inline them. If there is a bitcast in the way, it won't inline them. Instcombine normally deletes these calls, but it isn't run at -O0.

Definition at line 5972 of file CodeGenModule.cpp.

References replaceUsesOfNonProtoConstant().

◆ requiresMemberFunctionPointerTypeMetadata()

static bool requiresMemberFunctionPointerTypeMetadata ( CodeGenModule CGM,
const CXXMethodDecl MD 
)
static

◆ setLinkageForGV()

static void setLinkageForGV ( llvm::GlobalValue *  GV,
const NamedDecl ND 
)
static

◆ setLLVMVisibility()

void setLLVMVisibility ( llvm::GlobalValue &  GV,
std::optional< llvm::GlobalValue::VisibilityTypes >  V 
)

Definition at line 785 of file CodeGenModule.cpp.

References V.

Referenced by setVisibilityFromDLLStorageClass().

◆ setVisibilityFromDLLStorageClass()

static void setVisibilityFromDLLStorageClass ( const clang::LangOptions LO,
llvm::Module &  M 
)
static

Definition at line 799 of file CodeGenModule.cpp.

References getLLVMVisibility(), and setLLVMVisibility().

Referenced by clang::CodeGen::CodeGenModule::Release().

◆ shouldAssumeDSOLocal()

static bool shouldAssumeDSOLocal ( const CodeGenModule CGM,
llvm::GlobalValue *  GV 
)
static

◆ shouldBeInCOMDAT()

static bool shouldBeInCOMDAT ( CodeGenModule CGM,
const Decl D 
)
static

◆ TargetMVPriority()

static unsigned TargetMVPriority ( const TargetInfo TI,
const CodeGenFunction::MultiVersionResolverOption &  RO 
)
static

Variable Documentation

◆ AnnotationSection

const char AnnotationSection[] = "llvm.metadata"
static