[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
Mon Aug 1 12:36:05 PDT 2022
void updated this revision to Diff 449096.
void added a comment.
Improve string substitution logic.
TBD: testcase.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128863/new/
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,18 @@
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
+#include "llvm/Support/CommandLine.h"
using namespace llvm;
+/// Uses the "source_filename" instead of a Module hash ID for the suffix of
+/// promoted locals during LTO. NOTE: This requires that the source filename
+/// has a unique name / path to avoid name collisions.
+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. "
+ "This requires that the source filename has a unique name / "
+ "path to avoid name collisions."));
+
/// Checks if we should import SGV as a definition, otherwise import as a
/// declaration.
bool FunctionImportGlobalProcessing::doImportAsDefinition(
@@ -94,9 +104,19 @@
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(std::begin(Suffix), std::end(Suffix),
+ [&](char ch) { return !isAlnum(ch); }, '_');
+ 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
@@ -1465,10 +1465,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.449096.patch
Type: text/x-patch
Size: 3006 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220801/947f646b/attachment.bin>
More information about the llvm-commits
mailing list