[PATCH] D70337: [ThinLTO] Avoid extra index lookup during promotion
Teresa Johnson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 15 13:13:05 PST 2019
tejohnson created this revision.
tejohnson added reviewers: steven_wu, pcc, evgeny777.
Herald added subscribers: arphaman, dexonsmith, hiraditya, inglorion, mehdi_amini.
Herald added a project: LLVM.
Pass down the already accessed ValueInfo to shouldPromoteLocalToGlobal,
to avoid an unnecessary extra index lookup.
Add some assertion checking to confirm we have a non-empty VI when
expected.
Also some misc cleanup, merging the two versions of
doImportAsDefinition, since one was only called by the other, and
unnecessarily passed in a member variable.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D70337
Files:
llvm/include/llvm/Transforms/Utils/FunctionImportUtils.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
@@ -19,7 +19,9 @@
/// Checks if we should import SGV as a definition, otherwise import as a
/// declaration.
bool FunctionImportGlobalProcessing::doImportAsDefinition(
- const GlobalValue *SGV, SetVector<GlobalValue *> *GlobalsToImport) {
+ const GlobalValue *SGV) {
+ if (!isPerformingImport())
+ return false;
// Only import the globals requested for importing.
if (!GlobalsToImport->count(const_cast<GlobalValue *>(SGV)))
@@ -32,16 +34,8 @@
return true;
}
-bool FunctionImportGlobalProcessing::doImportAsDefinition(
- const GlobalValue *SGV) {
- if (!isPerformingImport())
- return false;
- return FunctionImportGlobalProcessing::doImportAsDefinition(SGV,
- GlobalsToImport);
-}
-
bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal(
- const GlobalValue *SGV) {
+ const GlobalValue *SGV, ValueInfo VI) {
assert(SGV->hasLocalLinkage());
// Both the imported references and the original local variable must
// be promoted.
@@ -66,7 +60,7 @@
// (so the source file name and resulting GUID is the same). Find the one
// in this module.
auto Summary = ImportIndex.findSummaryInModule(
- SGV->getGUID(), SGV->getParent()->getModuleIdentifier());
+ VI, SGV->getParent()->getModuleIdentifier());
assert(Summary && "Missing summary for global value when exporting");
auto Linkage = Summary->linkage();
if (!GlobalValue::isLocalLinkage(Linkage)) {
@@ -228,6 +222,11 @@
}
}
+ // We should always have a ValueInfo (i.e. GV in index) for definitions when
+ // we are exporting, and also when importing that value.
+ assert(VI || GV.isDeclaration() ||
+ (isPerformingImport() && !doImportAsDefinition(&GV)));
+
// Mark read/write-only variables which can be imported with specific
// attribute. We can't internalize them now because IRMover will fail
// to link variable definitions to their external declarations during
@@ -266,7 +265,7 @@
}
}
- if (GV.hasLocalLinkage() && shouldPromoteLocalToGlobal(&GV)) {
+ if (GV.hasLocalLinkage() && shouldPromoteLocalToGlobal(&GV, VI)) {
// Save the original name string before we rename GV below.
auto Name = GV.getName().str();
GV.setName(getName(&GV, /* DoPromote */ true));
Index: llvm/include/llvm/Transforms/Utils/FunctionImportUtils.h
===================================================================
--- llvm/include/llvm/Transforms/Utils/FunctionImportUtils.h
+++ llvm/include/llvm/Transforms/Utils/FunctionImportUtils.h
@@ -49,7 +49,7 @@
DenseMap<const Comdat *, Comdat *> RenamedComdats;
/// Check if we should promote the given local value to global scope.
- bool shouldPromoteLocalToGlobal(const GlobalValue *SGV);
+ bool shouldPromoteLocalToGlobal(const GlobalValue *SGV, ValueInfo VI);
#ifndef NDEBUG
/// Check if the given value is a local that can't be renamed (promoted).
@@ -107,9 +107,6 @@
}
bool run();
-
- static bool doImportAsDefinition(const GlobalValue *SGV,
- SetVector<GlobalValue *> *GlobalsToImport);
};
/// Perform in-place global value handling on the given Module for
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70337.229623.patch
Type: text/x-patch
Size: 3438 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191115/d03af6ad/attachment-0001.bin>
More information about the llvm-commits
mailing list