summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorErich Keane <erich.keane@intel.com>2022-01-14 10:22:06 -0800
committerErich Keane <erich.keane@intel.com>2022-01-14 10:45:55 -0800
commit2bcba21c8ba95de866ed6333fa5cd29d5d232afe (patch)
treeb66dd9adc15805ac3844bf2f6bdda4c9833ee88c /clang/lib/CodeGen/CodeGenModule.cpp
parentbdd5b948371293f91c29d9b542d484bb2bbc5c4e (diff)
[CPU-Dispatch] Make sure Dispatch names get updated if previously mangled
Cases where there is a mangling of a cpu-dispatch/cpu-specific function before the function becomes 'multiversion' (such as a member function) causes the wrong name to be emitted for one of the variants/resolver, since the name is cached. Make sure we invalidate the cache in cpu-dispatch/cpu-specific modes, like we previously did for just target multiversioning.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 42dfce32ed13..bd6fc49beda0 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1368,7 +1368,8 @@ static std::string getMangledNameImpl(CodeGenModule &CGM, GlobalDecl GD,
}
void CodeGenModule::UpdateMultiVersionNames(GlobalDecl GD,
- const FunctionDecl *FD) {
+ const FunctionDecl *FD,
+ StringRef &CurName) {
if (!FD->isMultiVersion())
return;
@@ -1400,7 +1401,11 @@ void CodeGenModule::UpdateMultiVersionNames(GlobalDecl GD,
if (ExistingRecord != std::end(Manglings))
Manglings.remove(&(*ExistingRecord));
auto Result = Manglings.insert(std::make_pair(OtherName, OtherGD));
- MangledDeclNames[OtherGD.getCanonicalDecl()] = Result.first->first();
+ StringRef OtherNameRef = MangledDeclNames[OtherGD.getCanonicalDecl()] =
+ Result.first->first();
+ // If this is the current decl is being created, make sure we update the name.
+ if (GD.getCanonicalDecl() == OtherGD.getCanonicalDecl())
+ CurName = OtherNameRef;
if (llvm::GlobalValue *Entry = GetGlobalValue(NonTargetName))
Entry->setName(OtherName);
}
@@ -3490,6 +3495,7 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
}
StringRef ResolverName = getMangledName(GD);
+ UpdateMultiVersionNames(GD, FD, ResolverName);
llvm::Type *ResolverType;
GlobalDecl ResolverGD;
@@ -3498,8 +3504,6 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
llvm::PointerType::get(DeclTy,
Context.getTargetAddressSpace(FD->getType())),
false);
- assert(ResolverName.endswith(".resolver") &&
- "CPUDispatch IFunc resolver doesn't end with .resolver??");
}
else {
ResolverType = DeclTy;
@@ -3692,8 +3696,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
}
if (FD->isMultiVersion()) {
- if (FD->hasAttr<TargetAttr>())
- UpdateMultiVersionNames(GD, FD);
+ UpdateMultiVersionNames(GD, FD, MangledName);
if (!IsForDefinition)
return GetOrCreateMultiVersionResolver(GD, Ty, FD);
}