Skip to content

Commit 916db65

Browse files
committed
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
1 parent 2be4eab commit 916db65

File tree

10 files changed

+44
-61
lines changed

10 files changed

+44
-61
lines changed

clang/include/clang/CodeGen/CGFunctionInfo.h

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -440,31 +440,30 @@ class RequiredArgs {
440440
///
441441
/// If FD is not null, this will consider pass_object_size params in FD.
442442
static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype,
443-
unsigned additional,
444-
const FunctionDecl *FD) {
443+
unsigned additional) {
445444
if (!prototype->isVariadic()) return All;
446-
if (FD)
447-
additional +=
448-
llvm::count_if(FD->parameters(), [](const ParmVarDecl *PVD) {
449-
return PVD->hasAttr<PassObjectSizeAttr>();
445+
446+
if (prototype->hasExtParameterInfos())
447+
additional += llvm::count_if(
448+
prototype->getExtParameterInfos(),
449+
[](const FunctionProtoType::ExtParameterInfo &ExtInfo) {
450+
return ExtInfo.hasPassObjectSize();
450451
});
452+
451453
return RequiredArgs(prototype->getNumParams() + additional);
452454
}
453455

454-
static RequiredArgs forPrototype(const FunctionProtoType *prototype,
455-
const FunctionDecl *FD) {
456-
return forPrototypePlus(prototype, 0, FD);
456+
static RequiredArgs forPrototypePlus(CanQual<FunctionProtoType> prototype,
457+
unsigned additional) {
458+
return forPrototypePlus(prototype.getTypePtr(), additional);
457459
}
458460

459-
static RequiredArgs forPrototype(CanQual<FunctionProtoType> prototype,
460-
const FunctionDecl *FD) {
461-
return forPrototype(prototype.getTypePtr(), FD);
461+
static RequiredArgs forPrototype(const FunctionProtoType *prototype) {
462+
return forPrototypePlus(prototype, 0);
462463
}
463464

464-
static RequiredArgs forPrototypePlus(CanQual<FunctionProtoType> prototype,
465-
unsigned additional,
466-
const FunctionDecl *FD) {
467-
return forPrototypePlus(prototype.getTypePtr(), additional, FD);
465+
static RequiredArgs forPrototype(CanQual<FunctionProtoType> prototype) {
466+
return forPrototypePlus(prototype.getTypePtr(), 0);
468467
}
469468

470469
bool allowsOptionalArgs() const { return NumRequired != ~0U; }

clang/include/clang/CodeGen/CodeGenABITypes.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ const CGFunctionInfo &arrangeObjCMessageSendSignature(CodeGenModule &CGM,
5454
QualType receiverType);
5555

5656
const CGFunctionInfo &arrangeFreeFunctionType(CodeGenModule &CGM,
57-
CanQual<FunctionProtoType> Ty,
58-
const FunctionDecl *FD);
57+
CanQual<FunctionProtoType> Ty);
5958

6059
const CGFunctionInfo &arrangeFreeFunctionType(CodeGenModule &CGM,
6160
CanQual<FunctionNoProtoType> Ty);

clang/lib/CodeGen/CGCUDANV.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ void CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction &CGF,
278278

279279
QualType QT = cudaLaunchKernelFD->getType();
280280
QualType CQT = QT.getCanonicalType();
281-
llvm::Type *Ty = CGM.getTypes().ConvertFunctionType(CQT, cudaLaunchKernelFD);
281+
llvm::Type *Ty = CGM.getTypes().ConvertType(CQT);
282282
llvm::FunctionType *FTy = dyn_cast<llvm::FunctionType>(Ty);
283283

284284
const CGFunctionInfo &FI =

clang/lib/CodeGen/CGCall.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,9 @@ static void appendParameterTypes(const CodeGenTypes &CGT,
167167
static const CGFunctionInfo &
168168
arrangeLLVMFunctionInfo(CodeGenTypes &CGT, bool instanceMethod,
169169
SmallVectorImpl<CanQualType> &prefix,
170-
CanQual<FunctionProtoType> FTP,
171-
const FunctionDecl *FD) {
170+
CanQual<FunctionProtoType> FTP) {
172171
SmallVector<FunctionProtoType::ExtParameterInfo, 16> paramInfos;
173-
RequiredArgs Required =
174-
RequiredArgs::forPrototypePlus(FTP, prefix.size(), FD);
172+
RequiredArgs Required = RequiredArgs::forPrototypePlus(FTP, prefix.size());
175173
// FIXME: Kill copy.
176174
appendParameterTypes(CGT, prefix, paramInfos, FTP);
177175
CanQualType resultType = FTP->getReturnType().getUnqualifiedType();
@@ -185,11 +183,10 @@ arrangeLLVMFunctionInfo(CodeGenTypes &CGT, bool instanceMethod,
185183
/// Arrange the argument and result information for a value of the
186184
/// given freestanding function type.
187185
const CGFunctionInfo &
188-
CodeGenTypes::arrangeFreeFunctionType(CanQual<FunctionProtoType> FTP,
189-
const FunctionDecl *FD) {
186+
CodeGenTypes::arrangeFreeFunctionType(CanQual<FunctionProtoType> FTP) {
190187
SmallVector<CanQualType, 16> argTypes;
191188
return ::arrangeLLVMFunctionInfo(*this, /*instanceMethod=*/false, argTypes,
192-
FTP, FD);
189+
FTP);
193190
}
194191

195192
static CallingConv getCallingConventionForDecl(const Decl *D, bool IsWindows) {
@@ -256,7 +253,7 @@ CodeGenTypes::arrangeCXXMethodType(const CXXRecordDecl *RD,
256253

257254
return ::arrangeLLVMFunctionInfo(
258255
*this, true, argTypes,
259-
FTP->getCanonicalTypeUnqualified().getAs<FunctionProtoType>(), MD);
256+
FTP->getCanonicalTypeUnqualified().getAs<FunctionProtoType>());
260257
}
261258

262259
/// Set calling convention for CUDA/HIP kernel.
@@ -288,7 +285,7 @@ CodeGenTypes::arrangeCXXMethodDeclaration(const CXXMethodDecl *MD) {
288285
return arrangeCXXMethodType(ThisType, prototype.getTypePtr(), MD);
289286
}
290287

291-
return arrangeFreeFunctionType(prototype, MD);
288+
return arrangeFreeFunctionType(prototype);
292289
}
293290

294291
bool CodeGenTypes::inheritingCtorHasParams(
@@ -407,7 +404,7 @@ CodeGenTypes::arrangeCXXConstructorCall(const CallArgList &args,
407404

408405
CanQual<FunctionProtoType> FPT = GetFormalType(D);
409406
RequiredArgs Required =
410-
RequiredArgs::forPrototypePlus(FPT, TotalPrefixArgs + ExtraSuffixArgs, D);
407+
RequiredArgs::forPrototypePlus(FPT, TotalPrefixArgs + ExtraSuffixArgs);
411408
GlobalDecl GD(D, CtorKind);
412409
CanQualType ResultType = TheCXXABI.HasThisReturn(GD)
413410
? ArgTypes.front()
@@ -450,7 +447,7 @@ CodeGenTypes::arrangeFunctionDeclaration(const FunctionDecl *FD) {
450447
/*chainCall=*/false, None, noProto->getExtInfo(), {},RequiredArgs::All);
451448
}
452449

453-
return arrangeFreeFunctionType(FTy.castAs<FunctionProtoType>(), FD);
450+
return arrangeFreeFunctionType(FTy.castAs<FunctionProtoType>());
454451
}
455452

456453
/// Arrange the argument and result information for the declaration or
@@ -633,11 +630,10 @@ CodeGenTypes::arrangeBlockFunctionDeclaration(const FunctionProtoType *proto,
633630
auto paramInfos = getExtParameterInfosForCall(proto, 1, params.size());
634631
auto argTypes = getArgTypesForDeclaration(Context, params);
635632

636-
return arrangeLLVMFunctionInfo(
637-
GetReturnType(proto->getReturnType()),
638-
/*instanceMethod*/ false, /*chainCall*/ false, argTypes,
639-
proto->getExtInfo(), paramInfos,
640-
RequiredArgs::forPrototypePlus(proto, 1, nullptr));
633+
return arrangeLLVMFunctionInfo(GetReturnType(proto->getReturnType()),
634+
/*instanceMethod*/ false, /*chainCall*/ false,
635+
argTypes, proto->getExtInfo(), paramInfos,
636+
RequiredArgs::forPrototypePlus(proto, 1));
641637
}
642638

643639
const CGFunctionInfo &

clang/lib/CodeGen/CGExprCXX.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ commonEmitCXXMemberOrOperatorCall(CodeGenFunction &CGF, const CXXMethodDecl *MD,
5454
}
5555

5656
const FunctionProtoType *FPT = MD->getType()->castAs<FunctionProtoType>();
57-
RequiredArgs required = RequiredArgs::forPrototypePlus(FPT, Args.size(), MD);
57+
RequiredArgs required = RequiredArgs::forPrototypePlus(FPT, Args.size());
5858
unsigned PrefixSize = Args.size() - 1;
5959

6060
// And the rest of the call args.
@@ -452,8 +452,7 @@ CodeGenFunction::EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E,
452452
// Push the this ptr.
453453
Args.add(RValue::get(ThisPtrForCall), ThisType);
454454

455-
RequiredArgs required =
456-
RequiredArgs::forPrototypePlus(FPT, 1, /*FD=*/nullptr);
455+
RequiredArgs required = RequiredArgs::forPrototypePlus(FPT, 1);
457456

458457
// And the rest of the call args
459458
EmitCallArgs(Args, FPT, E->arguments());

clang/lib/CodeGen/CGVTables.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ void CodeGenFunction::EmitCallAndReturnForThunk(llvm::Constant *CalleePtr,
326326

327327
#ifndef NDEBUG
328328
const CGFunctionInfo &CallFnInfo = CGM.getTypes().arrangeCXXMethodCall(
329-
CallArgs, FPT, RequiredArgs::forPrototypePlus(FPT, 1, MD), PrefixArgs);
329+
CallArgs, FPT, RequiredArgs::forPrototypePlus(FPT, 1), PrefixArgs);
330330
assert(CallFnInfo.getRegParm() == CurFnInfo->getRegParm() &&
331331
CallFnInfo.isNoReturn() == CurFnInfo->isNoReturn() &&
332332
CallFnInfo.getCallingConvention() == CurFnInfo->getCallingConvention());

clang/lib/CodeGen/CodeGenABITypes.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ CodeGen::arrangeObjCMessageSendSignature(CodeGenModule &CGM,
3434

3535
const CGFunctionInfo &
3636
CodeGen::arrangeFreeFunctionType(CodeGenModule &CGM,
37-
CanQual<FunctionProtoType> Ty,
38-
const FunctionDecl *FD) {
39-
return CGM.getTypes().arrangeFreeFunctionType(Ty, FD);
37+
CanQual<FunctionProtoType> Ty) {
38+
return CGM.getTypes().arrangeFreeFunctionType(Ty);
4039
}
4140

4241
const CGFunctionInfo &
@@ -67,7 +66,7 @@ CodeGen::arrangeFreeFunctionCall(CodeGenModule &CGM,
6766
llvm::FunctionType *
6867
CodeGen::convertFreeFunctionType(CodeGenModule &CGM, const FunctionDecl *FD) {
6968
assert(FD != nullptr && "Expected a non-null function declaration!");
70-
llvm::Type *T = CGM.getTypes().ConvertFunctionType(FD->getType(), FD);
69+
llvm::Type *T = CGM.getTypes().ConvertType(FD->getType());
7170

7271
if (auto FT = dyn_cast<llvm::FunctionType>(T))
7372
return FT;

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2576,8 +2576,7 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
25762576
assert(FD && "Not a FunctionDecl?");
25772577
const auto *DD = FD->getAttr<CPUDispatchAttr>();
25782578
assert(DD && "Not a cpu_dispatch Function?");
2579-
QualType CanonTy = Context.getCanonicalType(FD->getType());
2580-
llvm::Type *DeclTy = getTypes().ConvertFunctionType(CanonTy, FD);
2579+
llvm::Type *DeclTy = getTypes().ConvertType(FD->getType());
25812580

25822581
if (const auto *CXXFD = dyn_cast<CXXMethodDecl>(FD)) {
25832582
const CGFunctionInfo &FInfo = getTypes().arrangeCXXMethodDeclaration(CXXFD);
@@ -2916,8 +2915,7 @@ llvm::Constant *CodeGenModule::GetAddrOfFunction(GlobalDecl GD,
29162915
// If there was no specific requested type, just convert it now.
29172916
if (!Ty) {
29182917
const auto *FD = cast<FunctionDecl>(GD.getDecl());
2919-
auto CanonTy = Context.getCanonicalType(FD->getType());
2920-
Ty = getTypes().ConvertFunctionType(CanonTy, FD);
2918+
Ty = getTypes().ConvertType(FD->getType());
29212919
}
29222920

29232921
// Devirtualized destructor calls may come through here instead of via

clang/lib/CodeGen/CodeGenTypes.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,7 @@ static llvm::Type *getTypeForFormat(llvm::LLVMContext &VMContext,
308308
llvm_unreachable("Unknown float format!");
309309
}
310310

311-
llvm::Type *CodeGenTypes::ConvertFunctionType(QualType QFT,
312-
const FunctionDecl *FD) {
311+
llvm::Type *CodeGenTypes::ConvertFunctionTypeInternal(QualType QFT) {
313312
assert(QFT.isCanonical());
314313
const Type *Ty = QFT.getTypePtr();
315314
const FunctionType *FT = cast<FunctionType>(QFT.getTypePtr());
@@ -347,7 +346,7 @@ llvm::Type *CodeGenTypes::ConvertFunctionType(QualType QFT,
347346
const CGFunctionInfo *FI;
348347
if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FT)) {
349348
FI = &arrangeFreeFunctionType(
350-
CanQual<FunctionProtoType>::CreateUnsafe(QualType(FPT, 0)), FD);
349+
CanQual<FunctionProtoType>::CreateUnsafe(QualType(FPT, 0)));
351350
} else {
352351
const FunctionNoProtoType *FNPT = cast<FunctionNoProtoType>(FT);
353352
FI = &arrangeFreeFunctionType(
@@ -596,7 +595,7 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
596595
}
597596
case Type::FunctionNoProto:
598597
case Type::FunctionProto:
599-
ResultType = ConvertFunctionType(T);
598+
ResultType = ConvertFunctionTypeInternal(T);
600599
break;
601600
case Type::ObjCObject:
602601
ResultType = ConvertType(cast<ObjCObjectType>(Ty)->getBaseType());

clang/lib/CodeGen/CodeGenTypes.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ class CodeGenTypes {
162162

163163
llvm::SmallSet<const Type *, 8> RecordsWithOpaqueMemberPointers;
164164

165+
/// Helper for ConvertType.
166+
llvm::Type *ConvertFunctionTypeInternal(QualType FT);
167+
165168
public:
166169
CodeGenTypes(CodeGenModule &cgm);
167170
~CodeGenTypes();
@@ -182,14 +185,6 @@ class CodeGenTypes {
182185
/// ConvertType - Convert type T into a llvm::Type.
183186
llvm::Type *ConvertType(QualType T);
184187

185-
/// Converts the GlobalDecl into an llvm::Type. This should be used
186-
/// when we know the target of the function we want to convert. This is
187-
/// because some functions (explicitly, those with pass_object_size
188-
/// parameters) may not have the same signature as their type portrays, and
189-
/// can only be called directly.
190-
llvm::Type *ConvertFunctionType(QualType FT,
191-
const FunctionDecl *FD = nullptr);
192-
193188
/// ConvertTypeForMem - Convert type T into a llvm::Type. This differs from
194189
/// ConvertType in that it is used to convert to the memory representation for
195190
/// a type. For example, the scalar representation for _Bool is i1, but the
@@ -262,8 +257,7 @@ class CodeGenTypes {
262257
const CGFunctionInfo &arrangeFreeFunctionCall(const CallArgList &Args,
263258
const FunctionType *Ty,
264259
bool ChainCall);
265-
const CGFunctionInfo &arrangeFreeFunctionType(CanQual<FunctionProtoType> Ty,
266-
const FunctionDecl *FD);
260+
const CGFunctionInfo &arrangeFreeFunctionType(CanQual<FunctionProtoType> Ty);
267261
const CGFunctionInfo &arrangeFreeFunctionType(CanQual<FunctionNoProtoType> Ty);
268262

269263
/// A nullary function is a freestanding function of type 'void ()'.

0 commit comments

Comments
 (0)