[llvm-branch-commits] [llvm] [NFC] Drop leading dot from getUniqueModuleId (PR #241147)
Vitaly Buka via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Nov 10 23:11:32 PST 2026
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/241147
>From 21b0f6b5e931289566f7a582dfb0df1d73b20b47 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Tue, 10 Nov 2026 22:19:41 -0800
Subject: [PATCH] [spr] update
Created using spr 2.0.0-beta.2
---
llvm/include/llvm/Transforms/Utils/ModuleUtils.h | 2 ++
llvm/lib/Target/AMDGPU/AMDGPULowerExecSync.cpp | 2 +-
llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp | 4 ++--
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp | 2 +-
llvm/lib/Transforms/IPO/ElimAvailExtern.cpp | 6 +++++-
llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp | 10 ++++------
.../Transforms/Instrumentation/AddressSanitizer.cpp | 3 +--
llvm/lib/Transforms/Utils/ModuleUtils.cpp | 2 +-
8 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/llvm/include/llvm/Transforms/Utils/ModuleUtils.h b/llvm/include/llvm/Transforms/Utils/ModuleUtils.h
index baafc078039ece..0ba97772e7eacb 100644
--- a/llvm/include/llvm/Transforms/Utils/ModuleUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/ModuleUtils.h
@@ -128,6 +128,8 @@ filterDeadComdatFunctions(SmallVectorImpl<Function *> &DeadComdatFunctions);
/// the names of the module's strong external symbols that are not comdat
/// members.
///
+/// The result is a hex string without a leading separator.
+///
/// This identifier is normally guaranteed to be unique, or the program would
/// fail to link due to multiply defined symbols.
///
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerExecSync.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerExecSync.cpp
index 48395bd0b43672..8514aef8dd0368 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerExecSync.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerExecSync.cpp
@@ -188,7 +188,7 @@ static bool handleNamedBarriersForObjectLinking(Module &M) {
"modules with named barriers should have a unique ID");
for (auto &[V, Funcs] : BarrierToFuncs) {
if (V->hasLocalLinkage())
- V->setName("__amdgpu_named_barrier." + V->getName() + ModuleId);
+ V->setName("__amdgpu_named_barrier." + V->getName() + "." + ModuleId);
else if (!V->getName().starts_with("__amdgpu_named_barrier"))
V->setName("__amdgpu_named_barrier." + V->getName());
V->setInitializer(nullptr);
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
index b9bfc531041564..c714388163a3f9 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
@@ -950,7 +950,7 @@ class AMDGPULowerModuleLDS {
std::string StructName =
F->hasLocalLinkage()
- ? ("__amdgpu_lds." + F->getName() + ModuleId).str()
+ ? ("__amdgpu_lds." + F->getName() + "." + ModuleId).str()
: ("__amdgpu_lds." + F->getName()).str();
LDSVariableReplacement Replacement =
createLDSVariableReplacement(M, StructName, FuncScopeVars);
@@ -974,7 +974,7 @@ class AMDGPULowerModuleLDS {
// different TUs). Pack them into a single per-module struct with a
// module-unique name so the linker treats them as one allocation unit.
if (!InternalMultiUserVars.empty()) {
- std::string StructName = "__amdgpu_lds.__internal" + ModuleId;
+ std::string StructName = "__amdgpu_lds.__internal." + ModuleId;
LDSVariableReplacement Replacement =
createLDSVariableReplacement(M, StructName, InternalMultiUserVars);
diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index f607b351268b66..5f83f1e66f49f2 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -3145,7 +3145,7 @@ bool PPCAIXAsmPrinter::doInitialization(Module &M) {
// TODO: Use source file full path to generate the unique module id
// and add a format indicator as a part of function name in case we
// will support more than one format.
- FormatIndicatorAndUniqueModId = "clang_" + UniqueModuleId.substr(1);
+ FormatIndicatorAndUniqueModId = "clang_" + UniqueModuleId;
else {
// Use threadId, Pid, and current time as the unique module id when we
// cannot generate one based on a module's strong external symbols.
diff --git a/llvm/lib/Transforms/IPO/ElimAvailExtern.cpp b/llvm/lib/Transforms/IPO/ElimAvailExtern.cpp
index 2624fc1fa5c9ac..d41df598580c44 100644
--- a/llvm/lib/Transforms/IPO/ElimAvailExtern.cpp
+++ b/llvm/lib/Transforms/IPO/ElimAvailExtern.cpp
@@ -42,7 +42,11 @@ void deleteFunction(Function &F) {
}
static std::string getNewName(Module &M, const GlobalValue &GV) {
- return GV.getName().str() + ".__uniq" + getUniqueModuleId(&M);
+ std::string Name = GV.getName().str() + ".__uniq";
+ std::string ModuleId = getUniqueModuleId(&M);
+ if (!ModuleId.empty())
+ Name += "." + ModuleId;
+ return Name;
}
/// Create a copy of the thinlto import, mark it local, and redirect direct
diff --git a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
index 689b791308f9dc..8177ca85e4a9c0 100644
--- a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
+++ b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
@@ -31,14 +31,11 @@ using namespace llvm;
namespace {
// Promote each local-linkage entity defined by ExportM and used by ImportM by
-// changing visibility and appending ".llvm" + ModuleId (matching
+// changing visibility and appending ".llvm." + ModuleId (matching
// ModuleSummaryIndex::getGlobalNameForLocal so downstream PGO, SamplePGO,
// MemProf, and linker symbol canonicalization strip the promotion suffix).
void promoteInternals(Module &ExportM, Module &ImportM, StringRef ModuleId,
SetVector<GlobalValue *> *PromoteExtra = nullptr) {
- assert(ModuleId.starts_with(".") &&
- "Expected getUniqueModuleId to return a leading dot");
- StringRef ModuleHashStr = ModuleId.drop_front();
DenseMap<const Comdat *, Comdat *> RenamedComdats;
for (auto &ExportGV : ExportM.global_values()) {
if (!ExportGV.hasLocalLinkage())
@@ -59,7 +56,7 @@ void promoteInternals(Module &ExportM, Module &ImportM, StringRef ModuleId,
}
std::string NewName =
- ModuleSummaryIndex::getGlobalNameForLocal(Name, ModuleHashStr);
+ ModuleSummaryIndex::getGlobalNameForLocal(Name, ModuleId);
if (const auto *C = ExportGV.getComdat())
if (C->getName() == Name)
@@ -120,7 +117,8 @@ void promoteTypeIds(Module &M, StringRef ModuleId) {
if (isa<MDNode>(MD) && cast<MDNode>(MD)->isDistinct()) {
Metadata *&GlobalMD = LocalToGlobal[MD];
if (!GlobalMD) {
- std::string NewName = (Twine(LocalToGlobal.size()) + ModuleId).str();
+ std::string NewName =
+ (Twine(LocalToGlobal.size()) + "." + ModuleId).str();
GlobalMD = MDString::get(M.getContext(), NewName);
}
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index b7fee3bd4af8eb..0a4d930dbabde2 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2141,8 +2141,7 @@ void ModuleAddressSanitizer::SetComdatForGlobalMetadata(
}
if (!InternalSuffix.empty() && G->hasLocalLinkage()) {
- std::string Name = std::string(G->getName());
- Name += InternalSuffix;
+ std::string Name = (G->getName() + "." + InternalSuffix).str();
C = M.getOrInsertComdat(Name);
} else {
C = M.getOrInsertComdat(G->getName());
diff --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp b/llvm/lib/Transforms/Utils/ModuleUtils.cpp
index 0734a747d6f462..4372e74fb9b77b 100644
--- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp
+++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp
@@ -379,7 +379,7 @@ std::string llvm::getUniqueModuleId(Module *M) {
SmallString<32> Str;
MD5::stringifyResult(R, Str);
- return ("." + Str).str();
+ return std::string(Str);
}
GlobalVariable *llvm::embedBufferInModule(Module &M, MemoryBufferRef Buf,
More information about the llvm-branch-commits
mailing list