Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4554,15 +4554,17 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
ResolverName += ".resolver";
}

bool ShouldReturnIFunc =
getTarget().supportsIFunc() && !FD->isCPUSpecificMultiVersion();

// If the resolver has already been created, just return it. This lookup may
// yield a function declaration instead of a resolver on AArch64. That is
// because we didn't know whether a resolver will be generated when we first
// encountered a use of the symbol named after this resolver. Therefore,
// targets which support ifuncs should not return here unless we actually
// found an ifunc.
llvm::GlobalValue *ResolverGV = GetGlobalValue(ResolverName);
if (ResolverGV &&
(isa<llvm::GlobalIFunc>(ResolverGV) || !getTarget().supportsIFunc()))
if (ResolverGV && (isa<llvm::GlobalIFunc>(ResolverGV) || !ShouldReturnIFunc))
return ResolverGV;

const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
Expand All @@ -4575,7 +4577,7 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {

// For cpu_specific, don't create an ifunc yet because we don't know if the
// cpu_dispatch will be emitted in this translation unit.
if (getTarget().supportsIFunc() && !FD->isCPUSpecificMultiVersion()) {
if (ShouldReturnIFunc) {
unsigned AS = getTypes().getTargetAddressSpace(FD->getType());
llvm::Type *ResolverType =
llvm::FunctionType::get(llvm::PointerType::get(DeclTy, AS), false);
Expand All @@ -4594,11 +4596,9 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {

llvm::Constant *Resolver = GetOrCreateLLVMFunction(
ResolverName, DeclTy, GlobalDecl{}, /*ForVTable=*/false);
assert(isa<llvm::GlobalValue>(Resolver) &&
assert(isa<llvm::GlobalValue>(Resolver) && !ResolverGV &&
"Resolver should be created for the first time");
SetCommonAttributes(FD, cast<llvm::GlobalValue>(Resolver));
if (ResolverGV)
replaceDeclarationWith(ResolverGV, Resolver);
return Resolver;
}

Expand Down
12 changes: 6 additions & 6 deletions clang/test/CodeGen/attr-cpuspecific.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ void ThreeVersionsSameAttr(void){}
// CHECK: define {{.*}}void @ThreeVersionsSameAttr.Z() #[[K]]

ATTR(cpu_specific(knl))
void CpuSpecificNoDispatch(void) {}
// CHECK: define {{.*}}void @CpuSpecificNoDispatch.Z() #[[K:[0-9]+]]
void CpuSpecificNoDispatch(void (*f)(void)) {}
// CHECK: define {{.*}}void @CpuSpecificNoDispatch.Z(ptr noundef %f) #[[K:[0-9]+]]

ATTR(cpu_dispatch(knl))
void OrderDispatchUsageSpecific(void);
Expand Down Expand Up @@ -151,9 +151,9 @@ void usages(void) {
ThreeVersionsSameAttr();
// LINUX: @ThreeVersionsSameAttr.ifunc()
// WINDOWS: @ThreeVersionsSameAttr()
CpuSpecificNoDispatch();
// LINUX: @CpuSpecificNoDispatch.ifunc()
// WINDOWS: @CpuSpecificNoDispatch()
CpuSpecificNoDispatch((void (*)(void))CpuSpecificNoDispatch);
// LINUX: @CpuSpecificNoDispatch.ifunc(ptr noundef @CpuSpecificNoDispatch.ifunc)
// WINDOWS: @CpuSpecificNoDispatch(ptr noundef @CpuSpecificNoDispatch)
OrderDispatchUsageSpecific();
// LINUX: @OrderDispatchUsageSpecific.ifunc()
// WINDOWS: @OrderDispatchUsageSpecific()
Expand All @@ -162,7 +162,7 @@ void usages(void) {
// WINDOWS: @OrderSpecificUsageDispatch()
}

// LINUX: declare void @CpuSpecificNoDispatch.ifunc()
// LINUX: declare void @CpuSpecificNoDispatch.ifunc(ptr)

// has an extra config to emit!
ATTR(cpu_dispatch(ivybridge, knl, atom))
Expand Down
Loading