Skip to content

Commit 0ace010

Browse files
committed
[clang] NFC: Simplify the interface to CodeGenModule::GetOrCreateMultiVersionResolver().
Previously, GetOrCreateMultiVersionResolver() required the caller to provide a GlobalDecl along with an llvm::type and FunctionDecl. The latter two can be cheaply obtained from the first, and the llvm::type parameter is not always used, so requiring the caller to provide them was unnecessary and created the possibility that callers would pass an inconsistent set. This change simplifies the interface to only require the GlobalDecl value. Reviewed By: erichkeane Differential Revision: https://reviews.llvm.org/D122956
1 parent bed5ee3 commit 0ace010

File tree

2 files changed

+14
-25
lines changed

2 files changed

+14
-25
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3414,22 +3414,12 @@ void CodeGenModule::EmitTargetClonesResolver(GlobalDecl GD) {
34143414
const auto *TC = FD->getAttr<TargetClonesAttr>();
34153415
assert(TC && "Not a target_clones Function?");
34163416

3417-
QualType CanonTy = Context.getCanonicalType(FD->getType());
3418-
llvm::Type *DeclTy = getTypes().ConvertType(CanonTy);
3419-
3420-
if (const auto *CXXFD = dyn_cast<CXXMethodDecl>(FD)) {
3421-
const CGFunctionInfo &FInfo = getTypes().arrangeCXXMethodDeclaration(CXXFD);
3422-
DeclTy = getTypes().GetFunctionType(FInfo);
3423-
}
3424-
34253417
llvm::Function *ResolverFunc;
34263418
if (getTarget().supportsIFunc()) {
3427-
auto *IFunc = cast<llvm::GlobalIFunc>(
3428-
GetOrCreateMultiVersionResolver(GD, DeclTy, FD));
3419+
auto *IFunc = cast<llvm::GlobalIFunc>(GetOrCreateMultiVersionResolver(GD));
34293420
ResolverFunc = cast<llvm::Function>(IFunc->getResolver());
34303421
} else
3431-
ResolverFunc =
3432-
cast<llvm::Function>(GetOrCreateMultiVersionResolver(GD, DeclTy, FD));
3422+
ResolverFunc = cast<llvm::Function>(GetOrCreateMultiVersionResolver(GD));
34333423

34343424
SmallVector<CodeGenFunction::MultiVersionResolverOption, 10> Options;
34353425
for (unsigned VersionIndex = 0; VersionIndex < TC->featuresStrs_size();
@@ -3545,12 +3535,9 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
35453535
assert(FD->isCPUDispatchMultiVersion() && "Not a multiversion function?");
35463536
const auto *DD = FD->getAttr<CPUDispatchAttr>();
35473537
assert(DD && "Not a cpu_dispatch Function?");
3548-
llvm::Type *DeclTy = getTypes().ConvertType(FD->getType());
35493538

3550-
if (const auto *CXXFD = dyn_cast<CXXMethodDecl>(FD)) {
3551-
const CGFunctionInfo &FInfo = getTypes().arrangeCXXMethodDeclaration(CXXFD);
3552-
DeclTy = getTypes().GetFunctionType(FInfo);
3553-
}
3539+
const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
3540+
llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
35543541

35553542
StringRef ResolverName = getMangledName(GD);
35563543
UpdateMultiVersionNames(GD, FD, ResolverName);
@@ -3640,8 +3627,7 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
36403627

36413628
if (getTarget().supportsIFunc()) {
36423629
llvm::GlobalValue::LinkageTypes Linkage = getMultiversionLinkage(*this, GD);
3643-
auto *IFunc = cast<llvm::GlobalValue>(
3644-
GetOrCreateMultiVersionResolver(GD, DeclTy, FD));
3630+
auto *IFunc = cast<llvm::GlobalValue>(GetOrCreateMultiVersionResolver(GD));
36453631

36463632
// Fix up function declarations that were created for cpu_specific before
36473633
// cpu_dispatch was known
@@ -3668,8 +3654,10 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
36683654

36693655
/// If a dispatcher for the specified mangled name is not in the module, create
36703656
/// and return an llvm Function with the specified type.
3671-
llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(
3672-
GlobalDecl GD, llvm::Type *DeclTy, const FunctionDecl *FD) {
3657+
llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
3658+
const auto *FD = cast<FunctionDecl>(GD.getDecl());
3659+
assert(FD && "Not a FunctionDecl?");
3660+
36733661
std::string MangledName =
36743662
getMangledNameImpl(*this, GD, FD, /*OmitMultiVersionMangling=*/true);
36753663

@@ -3685,6 +3673,9 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(
36853673
if (llvm::GlobalValue *ResolverGV = GetGlobalValue(ResolverName))
36863674
return ResolverGV;
36873675

3676+
const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
3677+
llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
3678+
36883679
// Since this is the first time we've created this IFunc, make sure
36893680
// that we put this multiversioned function into the list to be
36903681
// replaced later if necessary (target multiversioning only).
@@ -3770,7 +3761,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
37703761
if (FD->isMultiVersion()) {
37713762
UpdateMultiVersionNames(GD, FD, MangledName);
37723763
if (!IsForDefinition)
3773-
return GetOrCreateMultiVersionResolver(GD, Ty, FD);
3764+
return GetOrCreateMultiVersionResolver(GD);
37743765
}
37753766
}
37763767

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,9 +1472,7 @@ class CodeGenModule : public CodeGenTypeCache {
14721472
// the resolver symbol for the provided declaration. The value returned
14731473
// will be for an ifunc (llvm::GlobalIFunc) if the current target supports
14741474
// that feature and for a regular function (llvm::GlobalValue) otherwise.
1475-
llvm::Constant *GetOrCreateMultiVersionResolver(GlobalDecl GD,
1476-
llvm::Type *DeclTy,
1477-
const FunctionDecl *FD);
1475+
llvm::Constant *GetOrCreateMultiVersionResolver(GlobalDecl GD);
14781476

14791477
// In scenarios where a function is not known to be a multiversion function
14801478
// until a later declaration, it is sometimes necessary to change the

0 commit comments

Comments
 (0)