Skip to content

Commit 482a0b1

Browse files
pccalexcrichton
authored andcommitted
FunctionImport: Use IRMover directly.
The importer was previously using ModuleLinker in a sort of "IRMover mode". Use IRMover directly instead in order to remove a level of indirection. I will remove all importing support from ModuleLinker in a separate change. Differential Revision: https://reviews.llvm.org/D29468 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294014 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 487c636 commit 482a0b1

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

include/llvm/Transforms/Utils/FunctionImportUtils.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class FunctionImportGlobalProcessing {
3232

3333
/// Globals to import from this module, all other functions will be
3434
/// imported as declarations instead of definitions.
35-
DenseSet<const GlobalValue *> *GlobalsToImport;
35+
SetVector<GlobalValue *> *GlobalsToImport;
3636

3737
/// Set to true if the given ModuleSummaryIndex contains any functions
3838
/// from this source module, in which case we must conservatively assume
@@ -85,7 +85,7 @@ class FunctionImportGlobalProcessing {
8585
public:
8686
FunctionImportGlobalProcessing(
8787
Module &M, const ModuleSummaryIndex &Index,
88-
DenseSet<const GlobalValue *> *GlobalsToImport = nullptr)
88+
SetVector<GlobalValue *> *GlobalsToImport = nullptr)
8989
: M(M), ImportIndex(Index), GlobalsToImport(GlobalsToImport) {
9090
// If we have a ModuleSummaryIndex but no function to import,
9191
// then this is the primary module being compiled in a ThinLTO
@@ -104,16 +104,15 @@ class FunctionImportGlobalProcessing {
104104

105105
bool run();
106106

107-
static bool
108-
doImportAsDefinition(const GlobalValue *SGV,
109-
DenseSet<const GlobalValue *> *GlobalsToImport);
107+
static bool doImportAsDefinition(const GlobalValue *SGV,
108+
SetVector<GlobalValue *> *GlobalsToImport);
110109
};
111110

112111
/// Perform in-place global value handling on the given Module for
113112
/// exported local functions renamed and promoted for ThinLTO.
114113
bool renameModuleForThinLTO(
115114
Module &M, const ModuleSummaryIndex &Index,
116-
DenseSet<const GlobalValue *> *GlobalsToImport = nullptr);
115+
SetVector<GlobalValue *> *GlobalsToImport = nullptr);
117116

118117
} // End llvm namespace
119118

lib/Linker/LinkModules.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ class ModuleLinker {
129129
bool ModuleLinker::doImportAsDefinition(const GlobalValue *SGV) {
130130
if (!isPerformingImport())
131131
return false;
132-
return FunctionImportGlobalProcessing::doImportAsDefinition(SGV,
133-
GlobalsToImport);
132+
report_fatal_error("ModuleLinker does not support importing");
134133
}
135134

136135
static GlobalValue::VisibilityTypes

lib/Transforms/IPO/FunctionImport.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,7 @@ Expected<bool> FunctionImporter::importFunctions(
623623
<< DestModule.getModuleIdentifier() << "\n");
624624
unsigned ImportedCount = 0;
625625

626-
// Linker that will be used for importing function
627-
Linker TheLinker(DestModule);
626+
IRMover Mover(DestModule);
628627
// Do the actual import of functions now, one Module at a time
629628
std::set<StringRef> ModuleNameOrderedList;
630629
for (auto &FunctionsToImportPerModule : ImportList) {
@@ -648,7 +647,7 @@ Expected<bool> FunctionImporter::importFunctions(
648647

649648
auto &ImportGUIDs = FunctionsToImportPerModule->second;
650649
// Find the globals to import
651-
DenseSet<const GlobalValue *> GlobalsToImport;
650+
SetVector<GlobalValue *> GlobalsToImport;
652651
for (Function &F : *SrcModule) {
653652
if (!F.hasName())
654653
continue;
@@ -687,6 +686,13 @@ Expected<bool> FunctionImporter::importFunctions(
687686
}
688687
}
689688
for (GlobalAlias &GA : SrcModule->aliases()) {
689+
// FIXME: This should eventually be controlled entirely by the summary.
690+
if (FunctionImportGlobalProcessing::doImportAsDefinition(
691+
&GA, &GlobalsToImport)) {
692+
GlobalsToImport.insert(&GA);
693+
continue;
694+
}
695+
690696
if (!GA.hasName())
691697
continue;
692698
auto GUID = GA.getGUID();
@@ -731,12 +737,9 @@ Expected<bool> FunctionImporter::importFunctions(
731737
<< " from " << SrcModule->getSourceFileName() << "\n";
732738
}
733739

734-
// Instruct the linker that the client will take care of linkonce resolution
735-
unsigned Flags = Linker::Flags::None;
736-
if (!ForceImportReferencedDiscardableSymbols)
737-
Flags |= Linker::Flags::DontForceLinkLinkonceODR;
738-
739-
if (TheLinker.linkInModule(std::move(SrcModule), Flags, &GlobalsToImport))
740+
if (Mover.move(std::move(SrcModule), GlobalsToImport.getArrayRef(),
741+
[](GlobalValue &, IRMover::ValueAdder) {},
742+
/*LinkModuleInlineAsm=*/false, /*IsPerformingImport=*/true))
740743
report_fatal_error("Function Import: link error");
741744

742745
ImportedCount += GlobalsToImport.size();

lib/Transforms/Utils/FunctionImportUtils.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ using namespace llvm;
2121
/// Checks if we should import SGV as a definition, otherwise import as a
2222
/// declaration.
2323
bool FunctionImportGlobalProcessing::doImportAsDefinition(
24-
const GlobalValue *SGV, DenseSet<const GlobalValue *> *GlobalsToImport) {
24+
const GlobalValue *SGV, SetVector<GlobalValue *> *GlobalsToImport) {
2525

2626
// For alias, we tie the definition to the base object. Extract it and recurse
2727
if (auto *GA = dyn_cast<GlobalAlias>(SGV)) {
28-
if (GA->hasWeakAnyLinkage())
28+
if (GA->isInterposable())
2929
return false;
3030
const GlobalObject *GO = GA->getBaseObject();
3131
if (!GO->hasLinkOnceODRLinkage())
@@ -34,7 +34,7 @@ bool FunctionImportGlobalProcessing::doImportAsDefinition(
3434
GO, GlobalsToImport);
3535
}
3636
// Only import the globals requested for importing.
37-
if (GlobalsToImport->count(SGV))
37+
if (GlobalsToImport->count(const_cast<GlobalValue *>(SGV)))
3838
return true;
3939
// Otherwise no.
4040
return false;
@@ -57,7 +57,8 @@ bool FunctionImportGlobalProcessing::shouldPromoteLocalToGlobal(
5757
return false;
5858

5959
if (isPerformingImport()) {
60-
assert((!GlobalsToImport->count(SGV) || !isNonRenamableLocal(*SGV)) &&
60+
assert((!GlobalsToImport->count(const_cast<GlobalValue *>(SGV)) ||
61+
!isNonRenamableLocal(*SGV)) &&
6162
"Attempting to promote non-renamable local");
6263
// We don't know for sure yet if we are importing this value (as either
6364
// a reference or a def), since we are simply walking all values in the
@@ -254,9 +255,8 @@ bool FunctionImportGlobalProcessing::run() {
254255
return false;
255256
}
256257

257-
bool llvm::renameModuleForThinLTO(
258-
Module &M, const ModuleSummaryIndex &Index,
259-
DenseSet<const GlobalValue *> *GlobalsToImport) {
258+
bool llvm::renameModuleForThinLTO(Module &M, const ModuleSummaryIndex &Index,
259+
SetVector<GlobalValue *> *GlobalsToImport) {
260260
FunctionImportGlobalProcessing ThinLTOProcessing(M, Index, GlobalsToImport);
261261
return ThinLTOProcessing.run();
262262
}

0 commit comments

Comments
 (0)