Skip to content

Commit cb432ba

Browse files
labrineasys-ce-bb
authored andcommitted
Revert "[FMV] Emit the resolver along with the default version definition." (#85914)
Reverts llvm/llvm-project#84405 In between of passing the precommit tests on github and being merged some change (perhaps in the AArch64 backend?) landed which resulted in altering the generated resolver. I will regenerate the tests perhaps using a less sensitive runline to such changes.
1 parent 9995c7d commit cb432ba

File tree

4 files changed

+238
-629
lines changed

4 files changed

+238
-629
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3811,9 +3811,6 @@ bool CodeGenModule::MayBeEmittedEagerly(const ValueDecl *Global) {
38113811
// Implicit template instantiations may change linkage if they are later
38123812
// explicitly instantiated, so they should not be emitted eagerly.
38133813
return false;
3814-
// Defer until all versions have been semantically checked.
3815-
if (FD->hasAttr<TargetVersionAttr>() && !FD->isMultiVersion())
3816-
return false;
38173814
}
38183815
if (const auto *VD = dyn_cast<VarDecl>(Global)) {
38193816
if (Context.getInlineVariableDefinitionKind(VD) ==
@@ -4431,13 +4428,10 @@ void CodeGenModule::EmitMultiVersionFunctionDefinition(GlobalDecl GD,
44314428
EmitGlobalFunctionDefinition(GD.getWithMultiVersionIndex(I), nullptr);
44324429
// Ensure that the resolver function is also emitted.
44334430
GetOrCreateMultiVersionResolver(GD);
4431+
} else if (FD->hasAttr<TargetVersionAttr>()) {
4432+
GetOrCreateMultiVersionResolver(GD);
44344433
} else
44354434
EmitGlobalFunctionDefinition(GD, GV);
4436-
4437-
// Defer the resolver emission until we can reason whether the TU
4438-
// contains a default target version implementation.
4439-
if (FD->isTargetVersionMultiVersion())
4440-
AddDeferredMultiVersionResolverToEmit(GD);
44414435
}
44424436

44434437
void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD, llvm::GlobalValue *GV) {
@@ -4530,11 +4524,10 @@ void CodeGenModule::emitMultiVersionFunctions() {
45304524
const auto *FD = cast<FunctionDecl>(GD.getDecl());
45314525
assert(FD && "Expected a FunctionDecl");
45324526

4533-
bool EmitResolver = !FD->isTargetVersionMultiVersion();
45344527
SmallVector<CodeGenFunction::MultiVersionResolverOption, 10> Options;
45354528
if (FD->isTargetMultiVersion()) {
45364529
getContext().forEachMultiversionedFunctionVersion(
4537-
FD, [this, &GD, &Options, &EmitResolver](const FunctionDecl *CurFD) {
4530+
FD, [this, &GD, &Options](const FunctionDecl *CurFD) {
45384531
GlobalDecl CurGD{
45394532
(CurFD->isDefined() ? CurFD->getDefinition() : CurFD)};
45404533
StringRef MangledName = getMangledName(CurGD);
@@ -4560,9 +4553,6 @@ void CodeGenModule::emitMultiVersionFunctions() {
45604553
TA->getArchitecture(), Feats);
45614554
} else {
45624555
const auto *TVA = CurFD->getAttr<TargetVersionAttr>();
4563-
if (CurFD->isUsed() || (TVA->isDefaultVersion() &&
4564-
CurFD->doesThisDeclarationHaveABody()))
4565-
EmitResolver = true;
45664556
llvm::SmallVector<StringRef, 8> Feats;
45674557
TVA->getFeatures(Feats);
45684558
Options.emplace_back(cast<llvm::Function>(Func),
@@ -4618,27 +4608,22 @@ void CodeGenModule::emitMultiVersionFunctions() {
46184608
continue;
46194609
}
46204610

4621-
if (!EmitResolver)
4622-
continue;
4623-
46244611
llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD);
46254612
if (auto *IFunc = dyn_cast<llvm::GlobalIFunc>(ResolverConstant)) {
46264613
ResolverConstant = IFunc->getResolver();
46274614
if (FD->isTargetClonesMultiVersion() ||
46284615
FD->isTargetVersionMultiVersion()) {
4616+
const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
4617+
llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
46294618
std::string MangledName = getMangledNameImpl(
46304619
*this, GD, FD, /*OmitMultiVersionMangling=*/true);
4631-
if (!GetGlobalValue(MangledName + ".ifunc")) {
4632-
const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
4633-
llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
4634-
// In prior versions of Clang, the mangling for ifuncs incorrectly
4635-
// included an .ifunc suffix. This alias is generated for backward
4636-
// compatibility. It is deprecated, and may be removed in the future.
4637-
auto *Alias = llvm::GlobalAlias::create(
4638-
DeclTy, 0, getMultiversionLinkage(*this, GD),
4639-
MangledName + ".ifunc", IFunc, &getModule());
4640-
SetCommonAttributes(FD, Alias);
4641-
}
4620+
// In prior versions of Clang, the mangling for ifuncs incorrectly
4621+
// included an .ifunc suffix. This alias is generated for backward
4622+
// compatibility. It is deprecated, and may be removed in the future.
4623+
auto *Alias = llvm::GlobalAlias::create(
4624+
DeclTy, 0, getMultiversionLinkage(*this, GD),
4625+
MangledName + ".ifunc", IFunc, &getModule());
4626+
SetCommonAttributes(FD, Alias);
46424627
}
46434628
}
46444629
llvm::Function *ResolverFunc = cast<llvm::Function>(ResolverConstant);
@@ -4795,20 +4780,6 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
47954780
}
47964781
}
47974782

4798-
/// Adds a declaration to the list of multi version functions if not present.
4799-
void CodeGenModule::AddDeferredMultiVersionResolverToEmit(GlobalDecl GD) {
4800-
const auto *FD = cast<FunctionDecl>(GD.getDecl());
4801-
assert(FD && "Not a FunctionDecl?");
4802-
4803-
if (FD->isTargetVersionMultiVersion()) {
4804-
std::string MangledName =
4805-
getMangledNameImpl(*this, GD, FD, /*OmitMultiVersionMangling=*/true);
4806-
if (!DeferredResolversToEmit.insert(MangledName).second)
4807-
return;
4808-
}
4809-
MultiVersionFuncs.push_back(GD);
4810-
}
4811-
48124783
/// If a dispatcher for the specified mangled name is not in the module, create
48134784
/// and return an llvm Function with the specified type.
48144785
llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
@@ -4848,7 +4819,7 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
48484819
// The resolver needs to be created. For target and target_clones, defer
48494820
// creation until the end of the TU.
48504821
if (FD->isTargetMultiVersion() || FD->isTargetClonesMultiVersion())
4851-
AddDeferredMultiVersionResolverToEmit(GD);
4822+
MultiVersionFuncs.push_back(GD);
48524823

48534824
// For cpu_specific, don't create an ifunc yet because we don't know if the
48544825
// cpu_dispatch will be emitted in this translation unit.

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,6 @@ class CodeGenModule : public CodeGenTypeCache {
355355
/// associated in this map is that of the aliasee.
356356
std::map<StringRef, GlobalDecl> DeferredAliases;
357357

358-
llvm::StringSet<llvm::BumpPtrAllocator> DeferredResolversToEmit;
359-
360358
/// This is a list of deferred decls which we have seen that *are* actually
361359
/// referenced. These get code generated when the module is done.
362360
std::vector<GlobalDecl> DeferredDeclsToEmit;
@@ -1633,9 +1631,6 @@ class CodeGenModule : public CodeGenTypeCache {
16331631
llvm::AttributeList ExtraAttrs = llvm::AttributeList(),
16341632
ForDefinition_t IsForDefinition = NotForDefinition);
16351633

1636-
// Adds a declaration to the list of multi version functions if not present.
1637-
void AddDeferredMultiVersionResolverToEmit(GlobalDecl GD);
1638-
16391634
// References to multiversion functions are resolved through an implicitly
16401635
// defined resolver function. This function is responsible for creating
16411636
// the resolver symbol for the provided declaration. The value returned

0 commit comments

Comments
 (0)