From 916db651c873fa68cdb0aa3664fc301ba09d8d6c Mon Sep 17 00:00:00 2001 From: James Y Knight Date: Sat, 2 Feb 2019 01:48:23 +0000 Subject: [PATCH] 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 --- clang/include/clang/CodeGen/CGFunctionInfo.h | 31 +++++++++---------- clang/include/clang/CodeGen/CodeGenABITypes.h | 3 +- clang/lib/CodeGen/CGCUDANV.cpp | 2 +- clang/lib/CodeGen/CGCall.cpp | 28 +++++++---------- clang/lib/CodeGen/CGExprCXX.cpp | 5 ++- clang/lib/CodeGen/CGVTables.cpp | 2 +- clang/lib/CodeGen/CodeGenABITypes.cpp | 7 ++--- clang/lib/CodeGen/CodeGenModule.cpp | 6 ++-- clang/lib/CodeGen/CodeGenTypes.cpp | 7 ++--- clang/lib/CodeGen/CodeGenTypes.h | 14 +++------ 10 files changed, 44 insertions(+), 61 deletions(-) diff --git a/clang/include/clang/CodeGen/CGFunctionInfo.h b/clang/include/clang/CodeGen/CGFunctionInfo.h index d311bb3c9922..52157f0c3cc9 100644 --- a/clang/include/clang/CodeGen/CGFunctionInfo.h +++ b/clang/include/clang/CodeGen/CGFunctionInfo.h @@ -440,31 +440,30 @@ public: /// /// If FD is not null, this will consider pass_object_size params in FD. static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype, - unsigned additional, - const FunctionDecl *FD) { + unsigned additional) { if (!prototype->isVariadic()) return All; - if (FD) - additional += - llvm::count_if(FD->parameters(), [](const ParmVarDecl *PVD) { - return PVD->hasAttr(); + + if (prototype->hasExtParameterInfos()) + additional += llvm::count_if( + prototype->getExtParameterInfos(), + [](const FunctionProtoType::ExtParameterInfo &ExtInfo) { + return ExtInfo.hasPassObjectSize(); }); + return RequiredArgs(prototype->getNumParams() + additional); } - static RequiredArgs forPrototype(const FunctionProtoType *prototype, - const FunctionDecl *FD) { - return forPrototypePlus(prototype, 0, FD); + static RequiredArgs forPrototypePlus(CanQual prototype, + unsigned additional) { + return forPrototypePlus(prototype.getTypePtr(), additional); } - static RequiredArgs forPrototype(CanQual prototype, - const FunctionDecl *FD) { - return forPrototype(prototype.getTypePtr(), FD); + static RequiredArgs forPrototype(const FunctionProtoType *prototype) { + return forPrototypePlus(prototype, 0); } - static RequiredArgs forPrototypePlus(CanQual prototype, - unsigned additional, - const FunctionDecl *FD) { - return forPrototypePlus(prototype.getTypePtr(), additional, FD); + static RequiredArgs forPrototype(CanQual prototype) { + return forPrototypePlus(prototype.getTypePtr(), 0); } bool allowsOptionalArgs() const { return NumRequired != ~0U; } diff --git a/clang/include/clang/CodeGen/CodeGenABITypes.h b/clang/include/clang/CodeGen/CodeGenABITypes.h index f5b042b48291..febb25aa43be 100644 --- a/clang/include/clang/CodeGen/CodeGenABITypes.h +++ b/clang/include/clang/CodeGen/CodeGenABITypes.h @@ -54,8 +54,7 @@ const CGFunctionInfo &arrangeObjCMessageSendSignature(CodeGenModule &CGM, QualType receiverType); const CGFunctionInfo &arrangeFreeFunctionType(CodeGenModule &CGM, - CanQual Ty, - const FunctionDecl *FD); + CanQual Ty); const CGFunctionInfo &arrangeFreeFunctionType(CodeGenModule &CGM, CanQual Ty); diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp index 9aaa5f76c7a5..276b5d40d6d8 100644 --- a/clang/lib/CodeGen/CGCUDANV.cpp +++ b/clang/lib/CodeGen/CGCUDANV.cpp @@ -278,7 +278,7 @@ void CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction &CGF, QualType QT = cudaLaunchKernelFD->getType(); QualType CQT = QT.getCanonicalType(); - llvm::Type *Ty = CGM.getTypes().ConvertFunctionType(CQT, cudaLaunchKernelFD); + llvm::Type *Ty = CGM.getTypes().ConvertType(CQT); llvm::FunctionType *FTy = dyn_cast(Ty); const CGFunctionInfo &FI = diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index ebd374eff8c6..4051cfb820c3 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -167,11 +167,9 @@ static void appendParameterTypes(const CodeGenTypes &CGT, static const CGFunctionInfo & arrangeLLVMFunctionInfo(CodeGenTypes &CGT, bool instanceMethod, SmallVectorImpl &prefix, - CanQual FTP, - const FunctionDecl *FD) { + CanQual FTP) { SmallVector paramInfos; - RequiredArgs Required = - RequiredArgs::forPrototypePlus(FTP, prefix.size(), FD); + RequiredArgs Required = RequiredArgs::forPrototypePlus(FTP, prefix.size()); // FIXME: Kill copy. appendParameterTypes(CGT, prefix, paramInfos, FTP); 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 /// given freestanding function type. const CGFunctionInfo & -CodeGenTypes::arrangeFreeFunctionType(CanQual FTP, - const FunctionDecl *FD) { +CodeGenTypes::arrangeFreeFunctionType(CanQual FTP) { SmallVector argTypes; return ::arrangeLLVMFunctionInfo(*this, /*instanceMethod=*/false, argTypes, - FTP, FD); + FTP); } static CallingConv getCallingConventionForDecl(const Decl *D, bool IsWindows) { @@ -256,7 +253,7 @@ CodeGenTypes::arrangeCXXMethodType(const CXXRecordDecl *RD, return ::arrangeLLVMFunctionInfo( *this, true, argTypes, - FTP->getCanonicalTypeUnqualified().getAs(), MD); + FTP->getCanonicalTypeUnqualified().getAs()); } /// Set calling convention for CUDA/HIP kernel. @@ -288,7 +285,7 @@ CodeGenTypes::arrangeCXXMethodDeclaration(const CXXMethodDecl *MD) { return arrangeCXXMethodType(ThisType, prototype.getTypePtr(), MD); } - return arrangeFreeFunctionType(prototype, MD); + return arrangeFreeFunctionType(prototype); } bool CodeGenTypes::inheritingCtorHasParams( @@ -407,7 +404,7 @@ CodeGenTypes::arrangeCXXConstructorCall(const CallArgList &args, CanQual FPT = GetFormalType(D); RequiredArgs Required = - RequiredArgs::forPrototypePlus(FPT, TotalPrefixArgs + ExtraSuffixArgs, D); + RequiredArgs::forPrototypePlus(FPT, TotalPrefixArgs + ExtraSuffixArgs); GlobalDecl GD(D, CtorKind); CanQualType ResultType = TheCXXABI.HasThisReturn(GD) ? ArgTypes.front() @@ -450,7 +447,7 @@ CodeGenTypes::arrangeFunctionDeclaration(const FunctionDecl *FD) { /*chainCall=*/false, None, noProto->getExtInfo(), {},RequiredArgs::All); } - return arrangeFreeFunctionType(FTy.castAs(), FD); + return arrangeFreeFunctionType(FTy.castAs()); } /// 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 argTypes = getArgTypesForDeclaration(Context, params); - return arrangeLLVMFunctionInfo( - GetReturnType(proto->getReturnType()), - /*instanceMethod*/ false, /*chainCall*/ false, argTypes, - proto->getExtInfo(), paramInfos, - RequiredArgs::forPrototypePlus(proto, 1, nullptr)); + return arrangeLLVMFunctionInfo(GetReturnType(proto->getReturnType()), + /*instanceMethod*/ false, /*chainCall*/ false, + argTypes, proto->getExtInfo(), paramInfos, + RequiredArgs::forPrototypePlus(proto, 1)); } const CGFunctionInfo & diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp index 8aa84365f7f7..1f650ae419e8 100644 --- a/clang/lib/CodeGen/CGExprCXX.cpp +++ b/clang/lib/CodeGen/CGExprCXX.cpp @@ -54,7 +54,7 @@ commonEmitCXXMemberOrOperatorCall(CodeGenFunction &CGF, const CXXMethodDecl *MD, } const FunctionProtoType *FPT = MD->getType()->castAs(); - RequiredArgs required = RequiredArgs::forPrototypePlus(FPT, Args.size(), MD); + RequiredArgs required = RequiredArgs::forPrototypePlus(FPT, Args.size()); unsigned PrefixSize = Args.size() - 1; // And the rest of the call args. @@ -452,8 +452,7 @@ CodeGenFunction::EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E, // Push the this ptr. Args.add(RValue::get(ThisPtrForCall), ThisType); - RequiredArgs required = - RequiredArgs::forPrototypePlus(FPT, 1, /*FD=*/nullptr); + RequiredArgs required = RequiredArgs::forPrototypePlus(FPT, 1); // And the rest of the call args EmitCallArgs(Args, FPT, E->arguments()); diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp index f9445049f8a0..702e18daac87 100644 --- a/clang/lib/CodeGen/CGVTables.cpp +++ b/clang/lib/CodeGen/CGVTables.cpp @@ -326,7 +326,7 @@ void CodeGenFunction::EmitCallAndReturnForThunk(llvm::Constant *CalleePtr, #ifndef NDEBUG 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() && CallFnInfo.isNoReturn() == CurFnInfo->isNoReturn() && CallFnInfo.getCallingConvention() == CurFnInfo->getCallingConvention()); diff --git a/clang/lib/CodeGen/CodeGenABITypes.cpp b/clang/lib/CodeGen/CodeGenABITypes.cpp index d60afddd4580..c047587dc00c 100644 --- a/clang/lib/CodeGen/CodeGenABITypes.cpp +++ b/clang/lib/CodeGen/CodeGenABITypes.cpp @@ -34,9 +34,8 @@ CodeGen::arrangeObjCMessageSendSignature(CodeGenModule &CGM, const CGFunctionInfo & CodeGen::arrangeFreeFunctionType(CodeGenModule &CGM, - CanQual Ty, - const FunctionDecl *FD) { - return CGM.getTypes().arrangeFreeFunctionType(Ty, FD); + CanQual Ty) { + return CGM.getTypes().arrangeFreeFunctionType(Ty); } const CGFunctionInfo & @@ -67,7 +66,7 @@ CodeGen::arrangeFreeFunctionCall(CodeGenModule &CGM, llvm::FunctionType * CodeGen::convertFreeFunctionType(CodeGenModule &CGM, const FunctionDecl *FD) { 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(T)) return FT; diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 199ec5983511..dfc3dd2506d9 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2576,8 +2576,7 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) { assert(FD && "Not a FunctionDecl?"); const auto *DD = FD->getAttr(); assert(DD && "Not a cpu_dispatch Function?"); - QualType CanonTy = Context.getCanonicalType(FD->getType()); - llvm::Type *DeclTy = getTypes().ConvertFunctionType(CanonTy, FD); + llvm::Type *DeclTy = getTypes().ConvertType(FD->getType()); if (const auto *CXXFD = dyn_cast(FD)) { 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 (!Ty) { const auto *FD = cast(GD.getDecl()); - auto CanonTy = Context.getCanonicalType(FD->getType()); - Ty = getTypes().ConvertFunctionType(CanonTy, FD); + Ty = getTypes().ConvertType(FD->getType()); } // Devirtualized destructor calls may come through here instead of via diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp b/clang/lib/CodeGen/CodeGenTypes.cpp index add313292264..e95f839619e7 100644 --- a/clang/lib/CodeGen/CodeGenTypes.cpp +++ b/clang/lib/CodeGen/CodeGenTypes.cpp @@ -308,8 +308,7 @@ static llvm::Type *getTypeForFormat(llvm::LLVMContext &VMContext, llvm_unreachable("Unknown float format!"); } -llvm::Type *CodeGenTypes::ConvertFunctionType(QualType QFT, - const FunctionDecl *FD) { +llvm::Type *CodeGenTypes::ConvertFunctionTypeInternal(QualType QFT) { assert(QFT.isCanonical()); const Type *Ty = QFT.getTypePtr(); const FunctionType *FT = cast(QFT.getTypePtr()); @@ -347,7 +346,7 @@ llvm::Type *CodeGenTypes::ConvertFunctionType(QualType QFT, const CGFunctionInfo *FI; if (const FunctionProtoType *FPT = dyn_cast(FT)) { FI = &arrangeFreeFunctionType( - CanQual::CreateUnsafe(QualType(FPT, 0)), FD); + CanQual::CreateUnsafe(QualType(FPT, 0))); } else { const FunctionNoProtoType *FNPT = cast(FT); FI = &arrangeFreeFunctionType( @@ -596,7 +595,7 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) { } case Type::FunctionNoProto: case Type::FunctionProto: - ResultType = ConvertFunctionType(T); + ResultType = ConvertFunctionTypeInternal(T); break; case Type::ObjCObject: ResultType = ConvertType(cast(Ty)->getBaseType()); diff --git a/clang/lib/CodeGen/CodeGenTypes.h b/clang/lib/CodeGen/CodeGenTypes.h index 5458be7b599e..d7e6edde8319 100644 --- a/clang/lib/CodeGen/CodeGenTypes.h +++ b/clang/lib/CodeGen/CodeGenTypes.h @@ -162,6 +162,9 @@ class CodeGenTypes { llvm::SmallSet RecordsWithOpaqueMemberPointers; + /// Helper for ConvertType. + llvm::Type *ConvertFunctionTypeInternal(QualType FT); + public: CodeGenTypes(CodeGenModule &cgm); ~CodeGenTypes(); @@ -182,14 +185,6 @@ public: /// ConvertType - Convert type T into a llvm::Type. 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 /// 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 @@ -262,8 +257,7 @@ public: const CGFunctionInfo &arrangeFreeFunctionCall(const CallArgList &Args, const FunctionType *Ty, bool ChainCall); - const CGFunctionInfo &arrangeFreeFunctionType(CanQual Ty, - const FunctionDecl *FD); + const CGFunctionInfo &arrangeFreeFunctionType(CanQual Ty); const CGFunctionInfo &arrangeFreeFunctionType(CanQual Ty); /// A nullary function is a freestanding function of type 'void ()'. -- GitLab