[PATCH] D128863: Add switch to use "source_file_name" instead of Module ID for globally promoted local
Bill Wendling via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 29 16:18:55 PDT 2022
void created this revision.
void added reviewers: tejohnson, evgeny777, steven_wu, pcc.
Herald added subscribers: arphaman, hiraditya.
Herald added a project: All.
void requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
During LTO a local promoted to a global gets a unique suffix based
partially on the Module's ID. This has a problem, because the Module ID
is not the same as the original Module ID. So any tool that's validating
changes will see a change when there isn't one (i.e. the names of the
promoted locals are changed, but it doesn't reflect a real change).
Instead of using the Module's ID, we can use the "source_file_name" if
it exists to generate a unique identifier that doesn't change due to LTO
shenanigans.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D128863
Files:
llvm/include/llvm/IR/ModuleSummaryIndex.h
llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
===================================================================
--- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
+++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -12,8 +12,13 @@
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
+#include "llvm/Support/CommandLine.h"
using namespace llvm;
+static cl::opt<bool> UseSourceFileNameForPromotedLocals(
+ "use-source-file-name-for-promoted-locals", cl::Hidden,
+ cl::desc("Uses the source file name instead of the Module hash"));
+
/// Checks if we should import SGV as a definition, otherwise import as a
/// declaration.
bool FunctionImportGlobalProcessing::doImportAsDefinition(
@@ -87,9 +92,31 @@
std::string
FunctionImportGlobalProcessing::getPromotedName(const GlobalValue *SGV) {
assert(SGV->hasLocalLinkage());
+
// For locals that must be promoted to global scope, ensure that
// the promoted name uniquely identifies the copy in the original module,
// using the ID assigned during combined index creation.
+ if (UseSourceFileNameForPromotedLocals &&
+ !SGV->getParent()->getSourceFileName().empty()) {
+ SmallString<256> Suffix(SGV->getParent()->getSourceFileName());
+ std::replace_if(Suffix.begin(), Suffix.end(),
+ [&](char ch) {
+ switch (ch) {
+ case '/':
+ case '\\':
+ case '+':
+ case '-':
+ case '*':
+ case ':':
+ return true;
+ }
+ return isSpace(ch);
+ }, '_');
+ std::replace(Suffix.begin(), Suffix.end(), '-', '_');
+ return ModuleSummaryIndex::getGlobalNameForLocal(
+ SGV->getName(), Suffix);
+ }
+
return ModuleSummaryIndex::getGlobalNameForLocal(
SGV->getName(),
ImportIndex.getModuleHash(SGV->getParent()->getModuleIdentifier()));
Index: llvm/include/llvm/IR/ModuleSummaryIndex.h
===================================================================
--- llvm/include/llvm/IR/ModuleSummaryIndex.h
+++ llvm/include/llvm/IR/ModuleSummaryIndex.h
@@ -1459,10 +1459,15 @@
/// Convenience method for creating a promoted global name
/// for the given value name of a local, and its original module's ID.
static std::string getGlobalNameForLocal(StringRef Name, ModuleHash ModHash) {
+ std::string Suffix = utostr((uint64_t(ModHash[0]) << 32) |
+ ModHash[1]); // Take the first 64 bits
+ return getGlobalNameForLocal(Name, Suffix);
+ }
+
+ static std::string getGlobalNameForLocal(StringRef Name, StringRef Suffix) {
SmallString<256> NewName(Name);
NewName += ".llvm.";
- NewName += utostr((uint64_t(ModHash[0]) << 32) |
- ModHash[1]); // Take the first 64 bits
+ NewName += Suffix;
return std::string(NewName.str());
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128863.441199.patch
Type: text/x-patch
Size: 3075 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220629/feb744d0/attachment.bin>
More information about the llvm-commits
mailing list