Remove redundant FunctionDecl argument from a couple functions.

This argument was added in r254554 in order to support the
pass_object_size attribute. However, in r296076, the attribute's
presence is now also represented in FunctionProtoType's
ExtParameterInfo, and thus it's unnecessary to pass along a separate
FunctionDecl.

The functions modified are:
 RequiredArgs::forPrototype{,Plus}, and
 CodeGenTypes::ConvertFunctionType.

After this, it's also (again) unnecessary to have a separate
ConvertFunctionType function ConvertType, so convert callers back to
the latter, leaving the former as an internal helper function.

llvm-svn: 352946
This commit is contained in:
James Y Knight 2019-02-02 01:48:23 +00:00
parent 2be4eabb6f
commit 916db651c8
10 changed files with 47 additions and 64 deletions

View File

@ -440,31 +440,30 @@ public:
/// ///
/// If FD is not null, this will consider pass_object_size params in FD. /// If FD is not null, this will consider pass_object_size params in FD.
static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype, static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype,
unsigned additional, unsigned additional) {
const FunctionDecl *FD) {
if (!prototype->isVariadic()) return All; if (!prototype->isVariadic()) return All;
if (FD)
additional += if (prototype->hasExtParameterInfos())
llvm::count_if(FD->parameters(), [](const ParmVarDecl *PVD) { additional += llvm::count_if(
return PVD->hasAttr<PassObjectSizeAttr>(); prototype->getExtParameterInfos(),
[](const FunctionProtoType::ExtParameterInfo &ExtInfo) {
return ExtInfo.hasPassObjectSize();
}); });
return RequiredArgs(prototype->getNumParams() + additional); return RequiredArgs(prototype->getNumParams() + additional);
} }
static RequiredArgs forPrototype(const FunctionProtoType *prototype,
const FunctionDecl *FD) {
return forPrototypePlus(prototype, 0, FD);
}
static RequiredArgs forPrototype(CanQual<FunctionProtoType> prototype,
const FunctionDecl *FD) {
return forPrototype(prototype.getTypePtr(), FD);
}
static RequiredArgs forPrototypePlus(CanQual<FunctionProtoType> prototype, static RequiredArgs forPrototypePlus(CanQual<FunctionProtoType> prototype,
unsigned additional, unsigned additional) {
const FunctionDecl *FD) { return forPrototypePlus(prototype.getTypePtr(), additional);
return forPrototypePlus(prototype.getTypePtr(), additional, FD); }
static RequiredArgs forPrototype(const FunctionProtoType *prototype) {
return forPrototypePlus(prototype, 0);
}
static RequiredArgs forPrototype(CanQual<FunctionProtoType> prototype) {
return forPrototypePlus(prototype.getTypePtr(), 0);
} }
bool allowsOptionalArgs() const { return NumRequired != ~0U; } bool allowsOptionalArgs() const { return NumRequired != ~0U; }

View File

@ -54,8 +54,7 @@ const CGFunctionInfo &arrangeObjCMessageSendSignature(CodeGenModule &CGM,
QualType receiverType); QualType receiverType);
const CGFunctionInfo &arrangeFreeFunctionType(CodeGenModule &CGM, const CGFunctionInfo &arrangeFreeFunctionType(CodeGenModule &CGM,
CanQual<FunctionProtoType> Ty, CanQual<FunctionProtoType> Ty);
const FunctionDecl *FD);
const CGFunctionInfo &arrangeFreeFunctionType(CodeGenModule &CGM, const CGFunctionInfo &arrangeFreeFunctionType(CodeGenModule &CGM,
CanQual<FunctionNoProtoType> Ty); CanQual<FunctionNoProtoType> Ty);

View File

@ -278,7 +278,7 @@ void CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction &CGF,
QualType QT = cudaLaunchKernelFD->getType(); QualType QT = cudaLaunchKernelFD->getType();
QualType CQT = QT.getCanonicalType(); QualType CQT = QT.getCanonicalType();
llvm::Type *Ty = CGM.getTypes().ConvertFunctionType(CQT, cudaLaunchKernelFD); llvm::Type *Ty = CGM.getTypes().ConvertType(CQT);
llvm::FunctionType *FTy = dyn_cast<llvm::FunctionType>(Ty); llvm::FunctionType *FTy = dyn_cast<llvm::FunctionType>(Ty);
const CGFunctionInfo &FI = const CGFunctionInfo &FI =

View File

@ -167,11 +167,9 @@ static void appendParameterTypes(const CodeGenTypes &CGT,
static const CGFunctionInfo & static const CGFunctionInfo &
arrangeLLVMFunctionInfo(CodeGenTypes &CGT, bool instanceMethod, arrangeLLVMFunctionInfo(CodeGenTypes &CGT, bool instanceMethod,
SmallVectorImpl<CanQualType> &prefix, SmallVectorImpl<CanQualType> &prefix,
CanQual<FunctionProtoType> FTP, CanQual<FunctionProtoType> FTP) {
const FunctionDecl *FD) {
SmallVector<FunctionProtoType::ExtParameterInfo, 16> paramInfos; SmallVector<FunctionProtoType::ExtParameterInfo, 16> paramInfos;
RequiredArgs Required = RequiredArgs Required = RequiredArgs::forPrototypePlus(FTP, prefix.size());
RequiredArgs::forPrototypePlus(FTP, prefix.size(), FD);
// FIXME: Kill copy. // FIXME: Kill copy.
appendParameterTypes(CGT, prefix, paramInfos, FTP); appendParameterTypes(CGT, prefix, paramInfos, FTP);
CanQualType resultType = FTP->getReturnType().getUnqualifiedType(); CanQualType resultType = FTP->getReturnType().getUnqualifiedType();
@ -185,11 +183,10 @@ arrangeLLVMFunctionInfo(CodeGenTypes &CGT, bool instanceMethod,
/// Arrange the argument and result information for a value of the /// Arrange the argument and result information for a value of the
/// given freestanding function type. /// given freestanding function type.
const CGFunctionInfo & const CGFunctionInfo &
CodeGenTypes::arrangeFreeFunctionType(CanQual<FunctionProtoType> FTP, CodeGenTypes::arrangeFreeFunctionType(CanQual<FunctionProtoType> FTP) {
const FunctionDecl *FD) {
SmallVector<CanQualType, 16> argTypes; SmallVector<CanQualType, 16> argTypes;
return ::arrangeLLVMFunctionInfo(*this, /*instanceMethod=*/false, argTypes, return ::arrangeLLVMFunctionInfo(*this, /*instanceMethod=*/false, argTypes,
FTP, FD); FTP);
} }
static CallingConv getCallingConventionForDecl(const Decl *D, bool IsWindows) { static CallingConv getCallingConventionForDecl(const Decl *D, bool IsWindows) {
@ -256,7 +253,7 @@ CodeGenTypes::arrangeCXXMethodType(const CXXRecordDecl *RD,
return ::arrangeLLVMFunctionInfo( return ::arrangeLLVMFunctionInfo(
*this, true, argTypes, *this, true, argTypes,
FTP->getCanonicalTypeUnqualified().getAs<FunctionProtoType>(), MD); FTP->getCanonicalTypeUnqualified().getAs<FunctionProtoType>());
} }
/// Set calling convention for CUDA/HIP kernel. /// Set calling convention for CUDA/HIP kernel.
@ -288,7 +285,7 @@ CodeGenTypes::arrangeCXXMethodDeclaration(const CXXMethodDecl *MD) {
return arrangeCXXMethodType(ThisType, prototype.getTypePtr(), MD); return arrangeCXXMethodType(ThisType, prototype.getTypePtr(), MD);
} }
return arrangeFreeFunctionType(prototype, MD); return arrangeFreeFunctionType(prototype);
} }
bool CodeGenTypes::inheritingCtorHasParams( bool CodeGenTypes::inheritingCtorHasParams(
@ -407,7 +404,7 @@ CodeGenTypes::arrangeCXXConstructorCall(const CallArgList &args,
CanQual<FunctionProtoType> FPT = GetFormalType(D); CanQual<FunctionProtoType> FPT = GetFormalType(D);
RequiredArgs Required = RequiredArgs Required =
RequiredArgs::forPrototypePlus(FPT, TotalPrefixArgs + ExtraSuffixArgs, D); RequiredArgs::forPrototypePlus(FPT, TotalPrefixArgs + ExtraSuffixArgs);
GlobalDecl GD(D, CtorKind); GlobalDecl GD(D, CtorKind);
CanQualType ResultType = TheCXXABI.HasThisReturn(GD) CanQualType ResultType = TheCXXABI.HasThisReturn(GD)
? ArgTypes.front() ? ArgTypes.front()
@ -450,7 +447,7 @@ CodeGenTypes::arrangeFunctionDeclaration(const FunctionDecl *FD) {
/*chainCall=*/false, None, noProto->getExtInfo(), {},RequiredArgs::All); /*chainCall=*/false, None, noProto->getExtInfo(), {},RequiredArgs::All);
} }
return arrangeFreeFunctionType(FTy.castAs<FunctionProtoType>(), FD); return arrangeFreeFunctionType(FTy.castAs<FunctionProtoType>());
} }
/// Arrange the argument and result information for the declaration or /// Arrange the argument and result information for the declaration or
@ -633,11 +630,10 @@ CodeGenTypes::arrangeBlockFunctionDeclaration(const FunctionProtoType *proto,
auto paramInfos = getExtParameterInfosForCall(proto, 1, params.size()); auto paramInfos = getExtParameterInfosForCall(proto, 1, params.size());
auto argTypes = getArgTypesForDeclaration(Context, params); auto argTypes = getArgTypesForDeclaration(Context, params);
return arrangeLLVMFunctionInfo( return arrangeLLVMFunctionInfo(GetReturnType(proto->getReturnType()),
GetReturnType(proto->getReturnType()), /*instanceMethod*/ false, /*chainCall*/ false,
/*instanceMethod*/ false, /*chainCall*/ false, argTypes, argTypes, proto->getExtInfo(), paramInfos,
proto->getExtInfo(), paramInfos, RequiredArgs::forPrototypePlus(proto, 1));
RequiredArgs::forPrototypePlus(proto, 1, nullptr));
} }
const CGFunctionInfo & const CGFunctionInfo &

View File

@ -54,7 +54,7 @@ commonEmitCXXMemberOrOperatorCall(CodeGenFunction &CGF, const CXXMethodDecl *MD,
} }
const FunctionProtoType *FPT = MD->getType()->castAs<FunctionProtoType>(); const FunctionProtoType *FPT = MD->getType()->castAs<FunctionProtoType>();
RequiredArgs required = RequiredArgs::forPrototypePlus(FPT, Args.size(), MD); RequiredArgs required = RequiredArgs::forPrototypePlus(FPT, Args.size());
unsigned PrefixSize = Args.size() - 1; unsigned PrefixSize = Args.size() - 1;
// And the rest of the call args. // And the rest of the call args.
@ -452,8 +452,7 @@ CodeGenFunction::EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E,
// Push the this ptr. // Push the this ptr.
Args.add(RValue::get(ThisPtrForCall), ThisType); Args.add(RValue::get(ThisPtrForCall), ThisType);
RequiredArgs required = RequiredArgs required = RequiredArgs::forPrototypePlus(FPT, 1);
RequiredArgs::forPrototypePlus(FPT, 1, /*FD=*/nullptr);
// And the rest of the call args // And the rest of the call args
EmitCallArgs(Args, FPT, E->arguments()); EmitCallArgs(Args, FPT, E->arguments());

View File

@ -326,7 +326,7 @@ void CodeGenFunction::EmitCallAndReturnForThunk(llvm::Constant *CalleePtr,
#ifndef NDEBUG #ifndef NDEBUG
const CGFunctionInfo &CallFnInfo = CGM.getTypes().arrangeCXXMethodCall( const CGFunctionInfo &CallFnInfo = CGM.getTypes().arrangeCXXMethodCall(
CallArgs, FPT, RequiredArgs::forPrototypePlus(FPT, 1, MD), PrefixArgs); CallArgs, FPT, RequiredArgs::forPrototypePlus(FPT, 1), PrefixArgs);
assert(CallFnInfo.getRegParm() == CurFnInfo->getRegParm() && assert(CallFnInfo.getRegParm() == CurFnInfo->getRegParm() &&
CallFnInfo.isNoReturn() == CurFnInfo->isNoReturn() && CallFnInfo.isNoReturn() == CurFnInfo->isNoReturn() &&
CallFnInfo.getCallingConvention() == CurFnInfo->getCallingConvention()); CallFnInfo.getCallingConvention() == CurFnInfo->getCallingConvention());

View File

@ -34,9 +34,8 @@ CodeGen::arrangeObjCMessageSendSignature(CodeGenModule &CGM,
const CGFunctionInfo & const CGFunctionInfo &
CodeGen::arrangeFreeFunctionType(CodeGenModule &CGM, CodeGen::arrangeFreeFunctionType(CodeGenModule &CGM,
CanQual<FunctionProtoType> Ty, CanQual<FunctionProtoType> Ty) {
const FunctionDecl *FD) { return CGM.getTypes().arrangeFreeFunctionType(Ty);
return CGM.getTypes().arrangeFreeFunctionType(Ty, FD);
} }
const CGFunctionInfo & const CGFunctionInfo &
@ -67,7 +66,7 @@ CodeGen::arrangeFreeFunctionCall(CodeGenModule &CGM,
llvm::FunctionType * llvm::FunctionType *
CodeGen::convertFreeFunctionType(CodeGenModule &CGM, const FunctionDecl *FD) { CodeGen::convertFreeFunctionType(CodeGenModule &CGM, const FunctionDecl *FD) {
assert(FD != nullptr && "Expected a non-null function declaration!"); assert(FD != nullptr && "Expected a non-null function declaration!");
llvm::Type *T = CGM.getTypes().ConvertFunctionType(FD->getType(), FD); llvm::Type *T = CGM.getTypes().ConvertType(FD->getType());
if (auto FT = dyn_cast<llvm::FunctionType>(T)) if (auto FT = dyn_cast<llvm::FunctionType>(T))
return FT; return FT;

View File

@ -2576,8 +2576,7 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
assert(FD && "Not a FunctionDecl?"); assert(FD && "Not a FunctionDecl?");
const auto *DD = FD->getAttr<CPUDispatchAttr>(); const auto *DD = FD->getAttr<CPUDispatchAttr>();
assert(DD && "Not a cpu_dispatch Function?"); assert(DD && "Not a cpu_dispatch Function?");
QualType CanonTy = Context.getCanonicalType(FD->getType()); llvm::Type *DeclTy = getTypes().ConvertType(FD->getType());
llvm::Type *DeclTy = getTypes().ConvertFunctionType(CanonTy, FD);
if (const auto *CXXFD = dyn_cast<CXXMethodDecl>(FD)) { if (const auto *CXXFD = dyn_cast<CXXMethodDecl>(FD)) {
const CGFunctionInfo &FInfo = getTypes().arrangeCXXMethodDeclaration(CXXFD); const CGFunctionInfo &FInfo = getTypes().arrangeCXXMethodDeclaration(CXXFD);
@ -2916,8 +2915,7 @@ llvm::Constant *CodeGenModule::GetAddrOfFunction(GlobalDecl GD,
// If there was no specific requested type, just convert it now. // If there was no specific requested type, just convert it now.
if (!Ty) { if (!Ty) {
const auto *FD = cast<FunctionDecl>(GD.getDecl()); const auto *FD = cast<FunctionDecl>(GD.getDecl());
auto CanonTy = Context.getCanonicalType(FD->getType()); Ty = getTypes().ConvertType(FD->getType());
Ty = getTypes().ConvertFunctionType(CanonTy, FD);
} }
// Devirtualized destructor calls may come through here instead of via // Devirtualized destructor calls may come through here instead of via

View File

@ -308,8 +308,7 @@ static llvm::Type *getTypeForFormat(llvm::LLVMContext &VMContext,
llvm_unreachable("Unknown float format!"); llvm_unreachable("Unknown float format!");
} }
llvm::Type *CodeGenTypes::ConvertFunctionType(QualType QFT, llvm::Type *CodeGenTypes::ConvertFunctionTypeInternal(QualType QFT) {
const FunctionDecl *FD) {
assert(QFT.isCanonical()); assert(QFT.isCanonical());
const Type *Ty = QFT.getTypePtr(); const Type *Ty = QFT.getTypePtr();
const FunctionType *FT = cast<FunctionType>(QFT.getTypePtr()); const FunctionType *FT = cast<FunctionType>(QFT.getTypePtr());
@ -347,7 +346,7 @@ llvm::Type *CodeGenTypes::ConvertFunctionType(QualType QFT,
const CGFunctionInfo *FI; const CGFunctionInfo *FI;
if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FT)) { if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FT)) {
FI = &arrangeFreeFunctionType( FI = &arrangeFreeFunctionType(
CanQual<FunctionProtoType>::CreateUnsafe(QualType(FPT, 0)), FD); CanQual<FunctionProtoType>::CreateUnsafe(QualType(FPT, 0)));
} else { } else {
const FunctionNoProtoType *FNPT = cast<FunctionNoProtoType>(FT); const FunctionNoProtoType *FNPT = cast<FunctionNoProtoType>(FT);
FI = &arrangeFreeFunctionType( FI = &arrangeFreeFunctionType(
@ -596,7 +595,7 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
} }
case Type::FunctionNoProto: case Type::FunctionNoProto:
case Type::FunctionProto: case Type::FunctionProto:
ResultType = ConvertFunctionType(T); ResultType = ConvertFunctionTypeInternal(T);
break; break;
case Type::ObjCObject: case Type::ObjCObject:
ResultType = ConvertType(cast<ObjCObjectType>(Ty)->getBaseType()); ResultType = ConvertType(cast<ObjCObjectType>(Ty)->getBaseType());

View File

@ -162,6 +162,9 @@ class CodeGenTypes {
llvm::SmallSet<const Type *, 8> RecordsWithOpaqueMemberPointers; llvm::SmallSet<const Type *, 8> RecordsWithOpaqueMemberPointers;
/// Helper for ConvertType.
llvm::Type *ConvertFunctionTypeInternal(QualType FT);
public: public:
CodeGenTypes(CodeGenModule &cgm); CodeGenTypes(CodeGenModule &cgm);
~CodeGenTypes(); ~CodeGenTypes();
@ -182,14 +185,6 @@ public:
/// ConvertType - Convert type T into a llvm::Type. /// ConvertType - Convert type T into a llvm::Type.
llvm::Type *ConvertType(QualType T); llvm::Type *ConvertType(QualType T);
/// Converts the GlobalDecl into an llvm::Type. This should be used
/// when we know the target of the function we want to convert. This is
/// because some functions (explicitly, those with pass_object_size
/// parameters) may not have the same signature as their type portrays, and
/// can only be called directly.
llvm::Type *ConvertFunctionType(QualType FT,
const FunctionDecl *FD = nullptr);
/// ConvertTypeForMem - Convert type T into a llvm::Type. This differs from /// ConvertTypeForMem - Convert type T into a llvm::Type. This differs from
/// ConvertType in that it is used to convert to the memory representation for /// ConvertType in that it is used to convert to the memory representation for
/// a type. For example, the scalar representation for _Bool is i1, but the /// a type. For example, the scalar representation for _Bool is i1, but the
@ -262,8 +257,7 @@ public:
const CGFunctionInfo &arrangeFreeFunctionCall(const CallArgList &Args, const CGFunctionInfo &arrangeFreeFunctionCall(const CallArgList &Args,
const FunctionType *Ty, const FunctionType *Ty,
bool ChainCall); bool ChainCall);
const CGFunctionInfo &arrangeFreeFunctionType(CanQual<FunctionProtoType> Ty, const CGFunctionInfo &arrangeFreeFunctionType(CanQual<FunctionProtoType> Ty);
const FunctionDecl *FD);
const CGFunctionInfo &arrangeFreeFunctionType(CanQual<FunctionNoProtoType> Ty); const CGFunctionInfo &arrangeFreeFunctionType(CanQual<FunctionNoProtoType> Ty);
/// A nullary function is a freestanding function of type 'void ()'. /// A nullary function is a freestanding function of type 'void ()'.