#include "CGCall.h"
#include "ABIInfo.h"
#include "ABIInfoImpl.h"
#include "CGBlocks.h"
#include "CGCXXABI.h"
#include "CGCleanup.h"
#include "CGRecordLayout.h"
#include "CodeGenFunction.h"
#include "CodeGenModule.h"
#include "TargetInfo.h"
#include "clang/AST/Attr.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
#include "clang/Basic/CodeGenOptions.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/CodeGen/CGFunctionInfo.h"
#include "clang/CodeGen/SwiftCallingConv.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Assumptions.h"
#include "llvm/IR/AttributeMask.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/InlineAsm.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/Type.h"
#include "llvm/Transforms/Utils/Local.h"
#include <optional>
usingnamespaceclang;
usingnamespaceCodeGen;
unsigned CodeGenTypes::ClangCallConvToLLVMCallConv(CallingConv CC) { … }
CanQualType CodeGenTypes::DeriveThisType(const CXXRecordDecl *RD,
const CXXMethodDecl *MD) { … }
static CanQual<FunctionProtoType> GetFormalType(const CXXMethodDecl *MD) { … }
static CanQualType GetReturnType(QualType RetTy) { … }
const CGFunctionInfo &
CodeGenTypes::arrangeFreeFunctionType(CanQual<FunctionNoProtoType> FTNP) { … }
static void addExtParameterInfosForCall(
llvm::SmallVectorImpl<FunctionProtoType::ExtParameterInfo> ¶mInfos,
const FunctionProtoType *proto,
unsigned prefixArgs,
unsigned totalArgs) { … }
static void appendParameterTypes(const CodeGenTypes &CGT,
SmallVectorImpl<CanQualType> &prefix,
SmallVectorImpl<FunctionProtoType::ExtParameterInfo> ¶mInfos,
CanQual<FunctionProtoType> FPT) { … }
static const CGFunctionInfo &
arrangeLLVMFunctionInfo(CodeGenTypes &CGT, bool instanceMethod,
SmallVectorImpl<CanQualType> &prefix,
CanQual<FunctionProtoType> FTP) { … }
const CGFunctionInfo &
CodeGenTypes::arrangeFreeFunctionType(CanQual<FunctionProtoType> FTP) { … }
static CallingConv getCallingConventionForDecl(const ObjCMethodDecl *D,
bool IsWindows) { … }
const CGFunctionInfo &
CodeGenTypes::arrangeCXXMethodType(const CXXRecordDecl *RD,
const FunctionProtoType *FTP,
const CXXMethodDecl *MD) { … }
static void setCUDAKernelCallingConvention(CanQualType &FTy, CodeGenModule &CGM,
const FunctionDecl *FD) { … }
const CGFunctionInfo &
CodeGenTypes::arrangeCXXMethodDeclaration(const CXXMethodDecl *MD) { … }
bool CodeGenTypes::inheritingCtorHasParams(
const InheritedConstructor &Inherited, CXXCtorType Type) { … }
const CGFunctionInfo &
CodeGenTypes::arrangeCXXStructorDeclaration(GlobalDecl GD) { … }
static SmallVector<CanQualType, 16>
getArgTypesForCall(ASTContext &ctx, const CallArgList &args) { … }
static SmallVector<CanQualType, 16>
getArgTypesForDeclaration(ASTContext &ctx, const FunctionArgList &args) { … }
static llvm::SmallVector<FunctionProtoType::ExtParameterInfo, 16>
getExtParameterInfosForCall(const FunctionProtoType *proto,
unsigned prefixArgs, unsigned totalArgs) { … }
const CGFunctionInfo &
CodeGenTypes::arrangeCXXConstructorCall(const CallArgList &args,
const CXXConstructorDecl *D,
CXXCtorType CtorKind,
unsigned ExtraPrefixArgs,
unsigned ExtraSuffixArgs,
bool PassProtoArgs) { … }
const CGFunctionInfo &
CodeGenTypes::arrangeFunctionDeclaration(const FunctionDecl *FD) { … }
const CGFunctionInfo &
CodeGenTypes::arrangeObjCMethodDeclaration(const ObjCMethodDecl *MD) { … }
const CGFunctionInfo &
CodeGenTypes::arrangeObjCMessageSendSignature(const ObjCMethodDecl *MD,
QualType receiverType) { … }
const CGFunctionInfo &
CodeGenTypes::arrangeUnprototypedObjCMessageSend(QualType returnType,
const CallArgList &args) { … }
const CGFunctionInfo &
CodeGenTypes::arrangeGlobalDeclaration(GlobalDecl GD) { … }
const CGFunctionInfo &
CodeGenTypes::arrangeUnprototypedMustTailThunk(const CXXMethodDecl *MD) { … }
const CGFunctionInfo &
CodeGenTypes::arrangeMSCtorClosure(const CXXConstructorDecl *CD,
CXXCtorType CT) { … }
static const CGFunctionInfo &
arrangeFreeFunctionLikeCall(CodeGenTypes &CGT,
CodeGenModule &CGM,
const CallArgList &args,
const FunctionType *fnType,
unsigned numExtraRequiredArgs,
bool chainCall) { … }
const CGFunctionInfo &
CodeGenTypes::arrangeFreeFunctionCall(const CallArgList &args,
const FunctionType *fnType,
bool chainCall) { … }
const CGFunctionInfo &
CodeGenTypes::arrangeBlockFunctionCall(const CallArgList &args,
const FunctionType *fnType) { … }
const CGFunctionInfo &
CodeGenTypes::arrangeBlockFunctionDeclaration(const FunctionProtoType *proto,
const FunctionArgList ¶ms) { … }
const CGFunctionInfo &
CodeGenTypes::arrangeBuiltinFunctionCall(QualType resultType,
const CallArgList &args) { … }
const CGFunctionInfo &
CodeGenTypes::arrangeBuiltinFunctionDeclaration(QualType resultType,
const FunctionArgList &args) { … }
const CGFunctionInfo &
CodeGenTypes::arrangeBuiltinFunctionDeclaration(CanQualType resultType,
ArrayRef<CanQualType> argTypes) { … }
const CGFunctionInfo &
CodeGenTypes::arrangeCXXMethodCall(const CallArgList &args,
const FunctionProtoType *proto,
RequiredArgs required,
unsigned numPrefixArgs) { … }
const CGFunctionInfo &CodeGenTypes::arrangeNullaryFunction() { … }
const CGFunctionInfo &
CodeGenTypes::arrangeCall(const CGFunctionInfo &signature,
const CallArgList &args) { … }
namespace clang {
namespace CodeGen {
void computeSPIRKernelABIInfo(CodeGenModule &CGM, CGFunctionInfo &FI);
}
}
const CGFunctionInfo &CodeGenTypes::arrangeLLVMFunctionInfo(
CanQualType resultType, FnInfoOpts opts, ArrayRef<CanQualType> argTypes,
FunctionType::ExtInfo info,
ArrayRef<FunctionProtoType::ExtParameterInfo> paramInfos,
RequiredArgs required) { … }
CGFunctionInfo *CGFunctionInfo::create(unsigned llvmCC, bool instanceMethod,
bool chainCall, bool delegateCall,
const FunctionType::ExtInfo &info,
ArrayRef<ExtParameterInfo> paramInfos,
CanQualType resultType,
ArrayRef<CanQualType> argTypes,
RequiredArgs required) { … }
namespace {
struct TypeExpansion { … };
struct ConstantArrayExpansion : TypeExpansion { … };
struct RecordExpansion : TypeExpansion { … };
struct ComplexExpansion : TypeExpansion { … };
struct NoExpansion : TypeExpansion { … };
}
static std::unique_ptr<TypeExpansion>
getTypeExpansion(QualType Ty, const ASTContext &Context) { … }
static int getExpansionSize(QualType Ty, const ASTContext &Context) { … }
void
CodeGenTypes::getExpandedTypes(QualType Ty,
SmallVectorImpl<llvm::Type *>::iterator &TI) { … }
static void forConstantArrayExpansion(CodeGenFunction &CGF,
ConstantArrayExpansion *CAE,
Address BaseAddr,
llvm::function_ref<void(Address)> Fn) { … }
void CodeGenFunction::ExpandTypeFromArgs(QualType Ty, LValue LV,
llvm::Function::arg_iterator &AI) { … }
void CodeGenFunction::ExpandTypeToArgs(
QualType Ty, CallArg Arg, llvm::FunctionType *IRFuncTy,
SmallVectorImpl<llvm::Value *> &IRCallArgs, unsigned &IRCallArgPos) { … }
static RawAddress CreateTempAllocaForCoercion(CodeGenFunction &CGF,
llvm::Type *Ty,
CharUnits MinAlign,
const Twine &Name = "tmp") { … }
static Address
EnterStructPointerForCoercedAccess(Address SrcPtr,
llvm::StructType *SrcSTy,
uint64_t DstSize, CodeGenFunction &CGF) { … }
static llvm::Value *CoerceIntOrPtrToIntOrPtr(llvm::Value *Val,
llvm::Type *Ty,
CodeGenFunction &CGF) { … }
static llvm::Value *CreateCoercedLoad(Address Src, llvm::Type *Ty,
CodeGenFunction &CGF) { … }
void CodeGenFunction::CreateCoercedStore(llvm::Value *Src, Address Dst,
llvm::TypeSize DstSize,
bool DstIsVolatile) { … }
static Address emitAddressAtOffset(CodeGenFunction &CGF, Address addr,
const ABIArgInfo &info) { … }
namespace {
class ClangToLLVMArgMapping { … };
void ClangToLLVMArgMapping::construct(const ASTContext &Context,
const CGFunctionInfo &FI,
bool OnlyRequiredArgs) { … }
}
bool CodeGenModule::ReturnTypeUsesSRet(const CGFunctionInfo &FI) { … }
bool CodeGenModule::ReturnTypeHasInReg(const CGFunctionInfo &FI) { … }
bool CodeGenModule::ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI) { … }
bool CodeGenModule::ReturnTypeUsesFPRet(QualType ResultType) { … }
bool CodeGenModule::ReturnTypeUsesFP2Ret(QualType ResultType) { … }
llvm::FunctionType *CodeGenTypes::GetFunctionType(GlobalDecl GD) { … }
llvm::FunctionType *
CodeGenTypes::GetFunctionType(const CGFunctionInfo &FI) { … }
llvm::Type *CodeGenTypes::GetFunctionTypeForVTable(GlobalDecl GD) { … }
static void AddAttributesFromFunctionProtoType(ASTContext &Ctx,
llvm::AttrBuilder &FuncAttrs,
const FunctionProtoType *FPT) { … }
static void AddAttributesFromOMPAssumes(llvm::AttrBuilder &FuncAttrs,
const Decl *Callee) { … }
bool CodeGenModule::MayDropFunctionReturn(const ASTContext &Context,
QualType ReturnType) const { … }
static bool HasStrictReturn(const CodeGenModule &Module, QualType RetTy,
const Decl *TargetDecl) { … }
static void addDenormalModeAttrs(llvm::DenormalMode FPDenormalMode,
llvm::DenormalMode FP32DenormalMode,
llvm::AttrBuilder &FuncAttrs) { … }
static void
addMergableDefaultFunctionAttributes(const CodeGenOptions &CodeGenOpts,
llvm::AttrBuilder &FuncAttrs) { … }
static void getTrivialDefaultFunctionAttributes(
StringRef Name, bool HasOptnone, const CodeGenOptions &CodeGenOpts,
const LangOptions &LangOpts, bool AttrOnCallSite,
llvm::AttrBuilder &FuncAttrs) { … }
static void
overrideFunctionFeaturesWithTargetFeatures(llvm::AttrBuilder &FuncAttr,
const llvm::Function &F,
const TargetOptions &TargetOpts) { … }
void CodeGen::mergeDefaultFunctionDefinitionAttributes(
llvm::Function &F, const CodeGenOptions &CodeGenOpts,
const LangOptions &LangOpts, const TargetOptions &TargetOpts,
bool WillInternalize) { … }
void CodeGenModule::getTrivialDefaultFunctionAttributes(
StringRef Name, bool HasOptnone, bool AttrOnCallSite,
llvm::AttrBuilder &FuncAttrs) { … }
void CodeGenModule::getDefaultFunctionAttributes(StringRef Name,
bool HasOptnone,
bool AttrOnCallSite,
llvm::AttrBuilder &FuncAttrs) { … }
void CodeGenModule::addDefaultFunctionDefinitionAttributes(
llvm::AttrBuilder &attrs) { … }
static void addNoBuiltinAttributes(llvm::AttrBuilder &FuncAttrs,
const LangOptions &LangOpts,
const NoBuiltinAttr *NBA = nullptr) { … }
static bool DetermineNoUndef(QualType QTy, CodeGenTypes &Types,
const llvm::DataLayout &DL, const ABIArgInfo &AI,
bool CheckCoerce = true) { … }
static bool IsArgumentMaybeUndef(const Decl *TargetDecl,
unsigned NumRequiredArgs, unsigned ArgNo) { … }
static bool canApplyNoFPClass(const ABIArgInfo &AI, QualType ParamType,
bool IsReturn) { … }
static llvm::FPClassTest getNoFPClassTestMask(const LangOptions &LangOpts) { … }
void CodeGenModule::AdjustMemoryAttribute(StringRef Name,
CGCalleeInfo CalleeInfo,
llvm::AttributeList &Attrs) { … }
void CodeGenModule::ConstructAttributeList(StringRef Name,
const CGFunctionInfo &FI,
CGCalleeInfo CalleeInfo,
llvm::AttributeList &AttrList,
unsigned &CallingConv,
bool AttrOnCallSite, bool IsThunk) { … }
static llvm::Value *emitArgumentDemotion(CodeGenFunction &CGF,
const VarDecl *var,
llvm::Value *value) { … }
static const NonNullAttr *getNonNullAttr(const Decl *FD, const ParmVarDecl *PVD,
QualType ArgType, unsigned ArgNo) { … }
namespace {
struct CopyBackSwiftError final : EHScopeStack::Cleanup { … };
}
void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
llvm::Function *Fn,
const FunctionArgList &Args) { … }
static void eraseUnusedBitCasts(llvm::Instruction *insn) { … }
static llvm::Value *tryEmitFusedAutoreleaseOfResult(CodeGenFunction &CGF,
llvm::Value *result) { … }
static llvm::Value *tryRemoveRetainOfSelf(CodeGenFunction &CGF,
llvm::Value *result) { … }
static llvm::Value *emitAutoreleaseOfResult(CodeGenFunction &CGF,
llvm::Value *result) { … }
static llvm::StoreInst *findDominatingStoreToReturnValue(CodeGenFunction &CGF) { … }
static void setBitRange(SmallVectorImpl<uint64_t> &Bits, int BitOffset,
int BitWidth, int CharWidth) { … }
static void setBitRange(SmallVectorImpl<uint64_t> &Bits, int StorageOffset,
int StorageSize, int BitOffset, int BitWidth,
int CharWidth, bool BigEndian) { … }
static void setUsedBits(CodeGenModule &, QualType, int,
SmallVectorImpl<uint64_t> &);
static void setUsedBits(CodeGenModule &CGM, const RecordType *RTy, int Offset,
SmallVectorImpl<uint64_t> &Bits) { … }
static void setUsedBits(CodeGenModule &CGM, const ConstantArrayType *ATy,
int Offset, SmallVectorImpl<uint64_t> &Bits) { … }
static void setUsedBits(CodeGenModule &CGM, QualType QTy, int Offset,
SmallVectorImpl<uint64_t> &Bits) { … }
static uint64_t buildMultiCharMask(const SmallVectorImpl<uint64_t> &Bits,
int Pos, int Size, int CharWidth,
bool BigEndian) { … }
llvm::Value *CodeGenFunction::EmitCMSEClearRecord(llvm::Value *Src,
llvm::IntegerType *ITy,
QualType QTy) { … }
llvm::Value *CodeGenFunction::EmitCMSEClearRecord(llvm::Value *Src,
llvm::ArrayType *ATy,
QualType QTy) { … }
void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI,
bool EmitRetDbgLoc,
SourceLocation EndLoc) { … }
void CodeGenFunction::EmitReturnValueCheck(llvm::Value *RV) { … }
static bool isInAllocaArgument(CGCXXABI &ABI, QualType type) { … }
static AggValueSlot createPlaceholderSlot(CodeGenFunction &CGF,
QualType Ty) { … }
void CodeGenFunction::EmitDelegateCallArg(CallArgList &args,
const VarDecl *param,
SourceLocation loc) { … }
static bool isProvablyNull(llvm::Value *addr) { … }
static bool isProvablyNonNull(Address Addr, CodeGenFunction &CGF) { … }
static void emitWriteback(CodeGenFunction &CGF,
const CallArgList::Writeback &writeback) { … }
static void emitWritebacks(CodeGenFunction &CGF,
const CallArgList &args) { … }
static void deactivateArgCleanupsBeforeCall(CodeGenFunction &CGF,
const CallArgList &CallArgs) { … }
static const Expr *maybeGetUnaryAddrOfOperand(const Expr *E) { … }
static void emitWritebackArg(CodeGenFunction &CGF, CallArgList &args,
const ObjCIndirectCopyRestoreExpr *CRE) { … }
void CallArgList::allocateArgumentMemory(CodeGenFunction &CGF) { … }
void CallArgList::freeArgumentMemory(CodeGenFunction &CGF) const { … }
void CodeGenFunction::EmitNonNullArgCheck(RValue RV, QualType ArgType,
SourceLocation ArgLoc,
AbstractCallee AC,
unsigned ParmNum) { … }
void CodeGenFunction::EmitNonNullArgCheck(Address Addr, QualType ArgType,
SourceLocation ArgLoc,
AbstractCallee AC, unsigned ParmNum) { … }
static bool hasInAllocaArgs(CodeGenModule &CGM, CallingConv ExplicitCC,
ArrayRef<QualType> ArgTypes) { … }
#ifndef NDEBUG
static bool isObjCMethodWithTypeParams(const ObjCMethodDecl *method) {
const DeclContext *dc = method->getDeclContext();
if (const ObjCInterfaceDecl *classDecl = dyn_cast<ObjCInterfaceDecl>(dc)) {
return classDecl->getTypeParamListAsWritten();
}
if (const ObjCCategoryDecl *catDecl = dyn_cast<ObjCCategoryDecl>(dc)) {
return catDecl->getTypeParamList();
}
return false;
}
#endif
void CodeGenFunction::EmitCallArgs(
CallArgList &Args, PrototypeWrapper Prototype,
llvm::iterator_range<CallExpr::const_arg_iterator> ArgRange,
AbstractCallee AC, unsigned ParamsToSkip, EvaluationOrder Order) { … }
namespace {
struct DestroyUnpassedArg final : EHScopeStack::Cleanup { … };
struct DisableDebugLocationUpdates { … };
}
RValue CallArg::getRValue(CodeGenFunction &CGF) const { … }
void CallArg::copyInto(CodeGenFunction &CGF, Address Addr) const { … }
void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E,
QualType type) { … }
QualType CodeGenFunction::getVarArgType(const Expr *Arg) { … }
void
CodeGenFunction::AddObjCARCExceptionMetadata(llvm::Instruction *Inst) { … }
llvm::CallInst *
CodeGenFunction::EmitNounwindRuntimeCall(llvm::FunctionCallee callee,
const llvm::Twine &name) { … }
llvm::CallInst *
CodeGenFunction::EmitNounwindRuntimeCall(llvm::FunctionCallee callee,
ArrayRef<Address> args,
const llvm::Twine &name) { … }
llvm::CallInst *
CodeGenFunction::EmitNounwindRuntimeCall(llvm::FunctionCallee callee,
ArrayRef<llvm::Value *> args,
const llvm::Twine &name) { … }
llvm::CallInst *CodeGenFunction::EmitRuntimeCall(llvm::FunctionCallee callee,
const llvm::Twine &name) { … }
SmallVector<llvm::OperandBundleDef, 1>
CodeGenFunction::getBundlesForFunclet(llvm::Value *Callee) { … }
llvm::CallInst *CodeGenFunction::EmitRuntimeCall(llvm::FunctionCallee callee,
ArrayRef<llvm::Value *> args,
const llvm::Twine &name) { … }
void CodeGenFunction::EmitNoreturnRuntimeCallOrInvoke(
llvm::FunctionCallee callee, ArrayRef<llvm::Value *> args) { … }
llvm::CallBase *
CodeGenFunction::EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee,
const Twine &name) { … }
llvm::CallBase *
CodeGenFunction::EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee,
ArrayRef<llvm::Value *> args,
const Twine &name) { … }
llvm::CallBase *CodeGenFunction::EmitCallOrInvoke(llvm::FunctionCallee Callee,
ArrayRef<llvm::Value *> Args,
const Twine &Name) { … }
void CodeGenFunction::deferPlaceholderReplacement(llvm::Instruction *Old,
llvm::Value *New) { … }
namespace {
[[nodiscard]] llvm::AttributeList
maybeRaiseRetAlignmentAttribute(llvm::LLVMContext &Ctx,
const llvm::AttributeList &Attrs,
llvm::Align NewAlign) { … }
template <typename AlignedAttrTy> class AbstractAssumeAlignedAttrEmitter { … };
class AssumeAlignedAttrEmitter final
: public AbstractAssumeAlignedAttrEmitter<AssumeAlignedAttr> { … };
class AllocAlignAttrEmitter final
: public AbstractAssumeAlignedAttrEmitter<AllocAlignAttr> { … };
}
static unsigned getMaxVectorWidth(const llvm::Type *Ty) { … }
RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
const CGCallee &Callee,
ReturnValueSlot ReturnValue,
const CallArgList &CallArgs,
llvm::CallBase **callOrInvoke, bool IsMustTail,
SourceLocation Loc,
bool IsVirtualFunctionPointerThunk) { … }
CGCallee CGCallee::prepareConcreteCallee(CodeGenFunction &CGF) const { … }
RValue CodeGenFunction::EmitVAArg(VAArgExpr *VE, Address &VAListAddr,
AggValueSlot Slot) { … }