Skip to content

Commit 3be6dbc

Browse files
committed
[ThinLTO] Promotion handling cleanup (NFC)
Summary: Clean up the code that does GV promotion in the ThinLTO backends. Specifically, we don't need to check whether we are importing since that is already checked and handled correctly in shouldPromoteLocalToGlobal. Simply call shouldPromoteLocalToGlobal, and if it returns true we are guaranteed that we are promoting, whether or not we are importing (or in the exporting module). This also makes the handling in getName() consistent with that in getLinkage(), which checks the DoPromote parameter regardless of whether we are importing or exporting. Reviewers: steven_wu, pcc, evgeny777 Subscribers: mehdi_amini, inglorion, hiraditya, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D70327
1 parent ff75bf6 commit 3be6dbc

File tree

2 files changed

+15
-26
lines changed

2 files changed

+15
-26
lines changed

llvm/include/llvm/Transforms/Utils/FunctionImportUtils.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,9 @@ class FunctionImportGlobalProcessing {
6767
/// import SGV as a definition, otherwise import as a declaration.
6868
bool doImportAsDefinition(const GlobalValue *SGV);
6969

70-
/// Get the name for SGV that should be used in the linked destination
71-
/// module. Specifically, this handles the case where we need to rename
72-
/// a local that is being promoted to global scope, which it will always
73-
/// do when \p DoPromote is true (or when importing a local).
74-
std::string getName(const GlobalValue *SGV, bool DoPromote);
70+
/// Get the name for a local SGV that should be promoted and renamed to global
71+
/// scope in the linked destination module.
72+
std::string getPromotedName(const GlobalValue *SGV);
7573

7674
/// Process globals so that they can be used in ThinLTO. This includes
7775
/// promoting local variables so that they can be reference externally by

llvm/lib/Transforms/Utils/FunctionImportUtils.cpp

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,15 @@ bool FunctionImportGlobalProcessing::isNonRenamableLocal(
9292
}
9393
#endif
9494

95-
std::string FunctionImportGlobalProcessing::getName(const GlobalValue *SGV,
96-
bool DoPromote) {
95+
std::string
96+
FunctionImportGlobalProcessing::getPromotedName(const GlobalValue *SGV) {
97+
assert(SGV->hasLocalLinkage());
9798
// For locals that must be promoted to global scope, ensure that
9899
// the promoted name uniquely identifies the copy in the original module,
99-
// using the ID assigned during combined index creation. When importing,
100-
// we rename all locals (not just those that are promoted) in order to
101-
// avoid naming conflicts between locals imported from different modules.
102-
if (SGV->hasLocalLinkage() && (DoPromote || isPerformingImport()))
103-
return ModuleSummaryIndex::getGlobalNameForLocal(
104-
SGV->getName(),
105-
ImportIndex.getModuleHash(SGV->getParent()->getModuleIdentifier()));
106-
return SGV->getName();
100+
// using the ID assigned during combined index creation.
101+
return ModuleSummaryIndex::getGlobalNameForLocal(
102+
SGV->getName(),
103+
ImportIndex.getModuleHash(SGV->getParent()->getModuleIdentifier()));
107104
}
108105

109106
GlobalValue::LinkageTypes
@@ -268,19 +265,13 @@ void FunctionImportGlobalProcessing::processGlobalForThinLTO(GlobalValue &GV) {
268265
}
269266
}
270267

271-
bool DoPromote = false;
272-
if (GV.hasLocalLinkage() &&
273-
((DoPromote = shouldPromoteLocalToGlobal(&GV)) || isPerformingImport())) {
268+
if (GV.hasLocalLinkage() && shouldPromoteLocalToGlobal(&GV)) {
274269
// Save the original name string before we rename GV below.
275270
auto Name = GV.getName().str();
276-
// Once we change the name or linkage it is difficult to determine
277-
// again whether we should promote since shouldPromoteLocalToGlobal needs
278-
// to locate the summary (based on GUID from name and linkage). Therefore,
279-
// use DoPromote result saved above.
280-
GV.setName(getName(&GV, DoPromote));
281-
GV.setLinkage(getLinkage(&GV, DoPromote));
282-
if (!GV.hasLocalLinkage())
283-
GV.setVisibility(GlobalValue::HiddenVisibility);
271+
GV.setName(getPromotedName(&GV));
272+
GV.setLinkage(getLinkage(&GV, /* DoPromote */ true));
273+
assert(!GV.hasLocalLinkage());
274+
GV.setVisibility(GlobalValue::HiddenVisibility);
284275

285276
// If we are renaming a COMDAT leader, ensure that we record the COMDAT
286277
// for later renaming as well. This is required for COFF.

0 commit comments

Comments
 (0)