@@ -3449,9 +3449,6 @@ bool CodeGenModule::MayBeEmittedEagerly(const ValueDecl *Global) {
34493449 // Implicit template instantiations may change linkage if they are later
34503450 // explicitly instantiated, so they should not be emitted eagerly.
34513451 return false ;
3452- // Defer until all versions have been semantically checked.
3453- if (FD->hasAttr <TargetVersionAttr>() && !FD->isMultiVersion ())
3454- return false ;
34553452 }
34563453 if (const auto *VD = dyn_cast<VarDecl>(Global)) {
34573454 if (Context.getInlineVariableDefinitionKind (VD) ==
@@ -4000,13 +3997,10 @@ void CodeGenModule::EmitMultiVersionFunctionDefinition(GlobalDecl GD,
40003997 EmitGlobalFunctionDefinition (GD.getWithMultiVersionIndex (I), nullptr );
40013998 // Ensure that the resolver function is also emitted.
40023999 GetOrCreateMultiVersionResolver (GD);
4000+ } else if (FD->hasAttr <TargetVersionAttr>()) {
4001+ GetOrCreateMultiVersionResolver (GD);
40034002 } else
40044003 EmitGlobalFunctionDefinition (GD, GV);
4005-
4006- // Defer the resolver emission until we can reason whether the TU
4007- // contains a default target version implementation.
4008- if (FD->isTargetVersionMultiVersion ())
4009- AddDeferredMultiVersionResolverToEmit (GD);
40104004}
40114005
40124006void CodeGenModule::EmitGlobalDefinition (GlobalDecl GD, llvm::GlobalValue *GV) {
@@ -4099,11 +4093,10 @@ void CodeGenModule::emitMultiVersionFunctions() {
40994093 const auto *FD = cast<FunctionDecl>(GD.getDecl ());
41004094 assert (FD && " Expected a FunctionDecl" );
41014095
4102- bool EmitResolver = !FD->isTargetVersionMultiVersion ();
41034096 SmallVector<CodeGenFunction::MultiVersionResolverOption, 10 > Options;
41044097 if (FD->isTargetMultiVersion ()) {
41054098 getContext ().forEachMultiversionedFunctionVersion (
4106- FD, [this , &GD, &Options, &EmitResolver ](const FunctionDecl *CurFD) {
4099+ FD, [this , &GD, &Options](const FunctionDecl *CurFD) {
41074100 GlobalDecl CurGD{
41084101 (CurFD->isDefined () ? CurFD->getDefinition () : CurFD)};
41094102 StringRef MangledName = getMangledName (CurGD);
@@ -4129,9 +4122,6 @@ void CodeGenModule::emitMultiVersionFunctions() {
41294122 TA->getArchitecture (), Feats);
41304123 } else {
41314124 const auto *TVA = CurFD->getAttr <TargetVersionAttr>();
4132- if (CurFD->isUsed () || (TVA->isDefaultVersion () &&
4133- CurFD->doesThisDeclarationHaveABody ()))
4134- EmitResolver = true ;
41354125 llvm::SmallVector<StringRef, 8 > Feats;
41364126 TVA->getFeatures (Feats);
41374127 Options.emplace_back (cast<llvm::Function>(Func),
@@ -4187,27 +4177,22 @@ void CodeGenModule::emitMultiVersionFunctions() {
41874177 continue ;
41884178 }
41894179
4190- if (!EmitResolver)
4191- continue ;
4192-
41934180 llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver (GD);
41944181 if (auto *IFunc = dyn_cast<llvm::GlobalIFunc>(ResolverConstant)) {
41954182 ResolverConstant = IFunc->getResolver ();
41964183 if (FD->isTargetClonesMultiVersion () ||
41974184 FD->isTargetVersionMultiVersion ()) {
4185+ const CGFunctionInfo &FI = getTypes ().arrangeGlobalDeclaration (GD);
4186+ llvm::FunctionType *DeclTy = getTypes ().GetFunctionType (FI);
41984187 std::string MangledName = getMangledNameImpl (
41994188 *this , GD, FD, /* OmitMultiVersionMangling=*/ true );
4200- if (!GetGlobalValue (MangledName + " .ifunc" )) {
4201- const CGFunctionInfo &FI = getTypes ().arrangeGlobalDeclaration (GD);
4202- llvm::FunctionType *DeclTy = getTypes ().GetFunctionType (FI);
4203- // In prior versions of Clang, the mangling for ifuncs incorrectly
4204- // included an .ifunc suffix. This alias is generated for backward
4205- // compatibility. It is deprecated, and may be removed in the future.
4206- auto *Alias = llvm::GlobalAlias::create (
4207- DeclTy, 0 , getMultiversionLinkage (*this , GD),
4208- MangledName + " .ifunc" , IFunc, &getModule ());
4209- SetCommonAttributes (FD, Alias);
4210- }
4189+ // In prior versions of Clang, the mangling for ifuncs incorrectly
4190+ // included an .ifunc suffix. This alias is generated for backward
4191+ // compatibility. It is deprecated, and may be removed in the future.
4192+ auto *Alias = llvm::GlobalAlias::create (
4193+ DeclTy, 0 , getMultiversionLinkage (*this , GD),
4194+ MangledName + " .ifunc" , IFunc, &getModule ());
4195+ SetCommonAttributes (FD, Alias);
42114196 }
42124197 }
42134198 llvm::Function *ResolverFunc = cast<llvm::Function>(ResolverConstant);
@@ -4364,20 +4349,6 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
43644349 }
43654350}
43664351
4367- // / Adds a declaration to the list of multi version functions if not present.
4368- void CodeGenModule::AddDeferredMultiVersionResolverToEmit (GlobalDecl GD) {
4369- const auto *FD = cast<FunctionDecl>(GD.getDecl ());
4370- assert (FD && " Not a FunctionDecl?" );
4371-
4372- if (FD->isTargetVersionMultiVersion ()) {
4373- std::string MangledName =
4374- getMangledNameImpl (*this , GD, FD, /* OmitMultiVersionMangling=*/ true );
4375- if (!DeferredResolversToEmit.insert (MangledName).second )
4376- return ;
4377- }
4378- MultiVersionFuncs.push_back (GD);
4379- }
4380-
43814352// / If a dispatcher for the specified mangled name is not in the module, create
43824353// / and return an llvm Function with the specified type.
43834354llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver (GlobalDecl GD) {
@@ -4417,7 +4388,7 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
44174388 // The resolver needs to be created. For target and target_clones, defer
44184389 // creation until the end of the TU.
44194390 if (FD->isTargetMultiVersion () || FD->isTargetClonesMultiVersion ())
4420- AddDeferredMultiVersionResolverToEmit (GD);
4391+ MultiVersionFuncs. push_back (GD);
44214392
44224393 // For cpu_specific, don't create an ifunc yet because we don't know if the
44234394 // cpu_dispatch will be emitted in this translation unit.
0 commit comments