forked from OSchip/llvm-project
[ThinLTO] Only compute imports for current module in FunctionImport pass
Summary: The function import pass was computing all the imports for all the modules in the index, and only using the imports for the current module. Change this to instead compute only for the given module. This means that the exports list can't be populated, but they weren't being used anyway. Longer term, the linker can collect all the imports and export lists and serialize them out for consumption by the distributed backend processes which use this pass. Reviewers: joker.eph Subscribers: llvm-commits, joker.eph Differential Revision: http://reviews.llvm.org/D18945 llvm-svn: 266125
This commit is contained in:
parent
1bb32ac480
commit
c86af3345c
|
@ -434,6 +434,12 @@ public:
|
||||||
/// but if there was only one module or this was the first module we might
|
/// but if there was only one module or this was the first module we might
|
||||||
/// not invoke mergeFrom.
|
/// not invoke mergeFrom.
|
||||||
void removeEmptySummaryEntries();
|
void removeEmptySummaryEntries();
|
||||||
|
|
||||||
|
/// Collect for the given module the list of function it defines
|
||||||
|
/// (GUID -> Summary).
|
||||||
|
void collectDefinedFunctionsForModule(
|
||||||
|
StringRef ModulePath,
|
||||||
|
std::map<GlobalValue::GUID, FunctionSummary *> &FunctionInfoMap) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
|
|
@ -70,6 +70,14 @@ void ComputeCrossModuleImport(
|
||||||
const ModuleSummaryIndex &Index,
|
const ModuleSummaryIndex &Index,
|
||||||
StringMap<FunctionImporter::ImportMapTy> &ImportLists,
|
StringMap<FunctionImporter::ImportMapTy> &ImportLists,
|
||||||
StringMap<FunctionImporter::ExportSetTy> &ExportLists);
|
StringMap<FunctionImporter::ExportSetTy> &ExportLists);
|
||||||
|
|
||||||
|
/// Compute all the imports for the given module using the Index.
|
||||||
|
///
|
||||||
|
/// \p ImportList will be populated with a map that can be passed to
|
||||||
|
/// FunctionImporter::importFunctions() above (see description there).
|
||||||
|
void ComputeCrossModuleImportForModule(
|
||||||
|
StringRef ModulePath, const ModuleSummaryIndex &Index,
|
||||||
|
FunctionImporter::ImportMapTy &ImportList);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // LLVM_FUNCTIONIMPORT_H
|
#endif // LLVM_FUNCTIONIMPORT_H
|
||||||
|
|
|
@ -69,6 +69,26 @@ void ModuleSummaryIndex::removeEmptySummaryEntries() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Collect for the given module the list of function it defines
|
||||||
|
// (GUID -> Summary).
|
||||||
|
void ModuleSummaryIndex::collectDefinedFunctionsForModule(
|
||||||
|
StringRef ModulePath,
|
||||||
|
std::map<GlobalValue::GUID, FunctionSummary *> &FunctionInfoMap) const {
|
||||||
|
for (auto &GlobalList : *this) {
|
||||||
|
auto GUID = GlobalList.first;
|
||||||
|
for (auto &GlobInfo : GlobalList.second) {
|
||||||
|
auto *Summary = dyn_cast_or_null<FunctionSummary>(GlobInfo->summary());
|
||||||
|
if (!Summary)
|
||||||
|
// Ignore global variable, focus on functions
|
||||||
|
continue;
|
||||||
|
// Ignore summaries from other modules.
|
||||||
|
if (Summary->modulePath() != ModulePath)
|
||||||
|
continue;
|
||||||
|
FunctionInfoMap[GUID] = Summary;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GlobalValueInfo *
|
GlobalValueInfo *
|
||||||
ModuleSummaryIndex::getGlobalValueInfo(uint64_t ValueGUID,
|
ModuleSummaryIndex::getGlobalValueInfo(uint64_t ValueGUID,
|
||||||
bool PerModuleIndex) const {
|
bool PerModuleIndex) const {
|
||||||
|
|
|
@ -143,7 +143,7 @@ static void computeImportForFunction(
|
||||||
const std::map<GlobalValue::GUID, FunctionSummary *> &DefinedFunctions,
|
const std::map<GlobalValue::GUID, FunctionSummary *> &DefinedFunctions,
|
||||||
SmallVectorImpl<EdgeInfo> &Worklist,
|
SmallVectorImpl<EdgeInfo> &Worklist,
|
||||||
FunctionImporter::ImportMapTy &ImportsForModule,
|
FunctionImporter::ImportMapTy &ImportsForModule,
|
||||||
StringMap<FunctionImporter::ExportSetTy> &ExportLists) {
|
StringMap<FunctionImporter::ExportSetTy> *ExportLists = nullptr) {
|
||||||
for (auto &Edge : Summary.calls()) {
|
for (auto &Edge : Summary.calls()) {
|
||||||
auto GUID = Edge.first.getGUID();
|
auto GUID = Edge.first.getGUID();
|
||||||
DEBUG(dbgs() << " edge -> " << GUID << " Threshold:" << Threshold << "\n");
|
DEBUG(dbgs() << " edge -> " << GUID << " Threshold:" << Threshold << "\n");
|
||||||
|
@ -176,19 +176,21 @@ static void computeImportForFunction(
|
||||||
|
|
||||||
// Make exports in the source module.
|
// Make exports in the source module.
|
||||||
auto ExportModulePath = CalleeSummary->modulePath();
|
auto ExportModulePath = CalleeSummary->modulePath();
|
||||||
auto ExportList = ExportLists[ExportModulePath];
|
if (ExportLists) {
|
||||||
ExportList.insert(GUID);
|
auto ExportList = (*ExportLists)[ExportModulePath];
|
||||||
// Mark all functions and globals referenced by this function as exported to
|
ExportList.insert(GUID);
|
||||||
// the outside if they are defined in the same source module.
|
// Mark all functions and globals referenced by this function as exported
|
||||||
for (auto &Edge : CalleeSummary->calls()) {
|
// to the outside if they are defined in the same source module.
|
||||||
auto CalleeGUID = Edge.first.getGUID();
|
for (auto &Edge : CalleeSummary->calls()) {
|
||||||
if (isGlobalExported(Index, ExportModulePath, CalleeGUID))
|
auto CalleeGUID = Edge.first.getGUID();
|
||||||
ExportList.insert(CalleeGUID);
|
if (isGlobalExported(Index, ExportModulePath, CalleeGUID))
|
||||||
}
|
ExportList.insert(CalleeGUID);
|
||||||
for (auto &Ref : CalleeSummary->refs()) {
|
}
|
||||||
auto GUID = Ref.getGUID();
|
for (auto &Ref : CalleeSummary->refs()) {
|
||||||
if (isGlobalExported(Index, ExportModulePath, GUID))
|
auto GUID = Ref.getGUID();
|
||||||
ExportList.insert(GUID);
|
if (isGlobalExported(Index, ExportModulePath, GUID))
|
||||||
|
ExportList.insert(GUID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert the newly imported function to the worklist.
|
// Insert the newly imported function to the worklist.
|
||||||
|
@ -203,7 +205,7 @@ static void ComputeImportForModule(
|
||||||
const std::map<GlobalValue::GUID, FunctionSummary *> &DefinedFunctions,
|
const std::map<GlobalValue::GUID, FunctionSummary *> &DefinedFunctions,
|
||||||
const ModuleSummaryIndex &Index,
|
const ModuleSummaryIndex &Index,
|
||||||
FunctionImporter::ImportMapTy &ImportsForModule,
|
FunctionImporter::ImportMapTy &ImportsForModule,
|
||||||
StringMap<FunctionImporter::ExportSetTy> &ExportLists) {
|
StringMap<FunctionImporter::ExportSetTy> *ExportLists = nullptr) {
|
||||||
// Worklist contains the list of function imported in this module, for which
|
// Worklist contains the list of function imported in this module, for which
|
||||||
// we will analyse the callees and may import further down the callgraph.
|
// we will analyse the callees and may import further down the callgraph.
|
||||||
SmallVector<EdgeInfo, 128> Worklist;
|
SmallVector<EdgeInfo, 128> Worklist;
|
||||||
|
@ -234,7 +236,7 @@ static void ComputeImportForModule(
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
/// Compute all the import and export for every module in the Index.
|
/// Compute all the import and export for every module using the Index.
|
||||||
void llvm::ComputeCrossModuleImport(
|
void llvm::ComputeCrossModuleImport(
|
||||||
const ModuleSummaryIndex &Index,
|
const ModuleSummaryIndex &Index,
|
||||||
StringMap<FunctionImporter::ImportMapTy> &ImportLists,
|
StringMap<FunctionImporter::ImportMapTy> &ImportLists,
|
||||||
|
@ -265,7 +267,7 @@ void llvm::ComputeCrossModuleImport(
|
||||||
DEBUG(dbgs() << "Computing import for Module '" << DefinedFunctions.first()
|
DEBUG(dbgs() << "Computing import for Module '" << DefinedFunctions.first()
|
||||||
<< "'\n");
|
<< "'\n");
|
||||||
ComputeImportForModule(DefinedFunctions.second, Index, ImportsForModule,
|
ComputeImportForModule(DefinedFunctions.second, Index, ImportsForModule,
|
||||||
ExportLists);
|
&ExportLists);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
@ -286,6 +288,31 @@ void llvm::ComputeCrossModuleImport(
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Compute all the imports for the given module in the Index.
|
||||||
|
void llvm::ComputeCrossModuleImportForModule(
|
||||||
|
StringRef ModulePath, const ModuleSummaryIndex &Index,
|
||||||
|
FunctionImporter::ImportMapTy &ImportList) {
|
||||||
|
|
||||||
|
// Collect the list of functions this module defines.
|
||||||
|
// GUID -> Summary
|
||||||
|
std::map<GlobalValue::GUID, FunctionSummary *> FunctionInfoMap;
|
||||||
|
Index.collectDefinedFunctionsForModule(ModulePath, FunctionInfoMap);
|
||||||
|
|
||||||
|
// Compute the import list for this module.
|
||||||
|
DEBUG(dbgs() << "Computing import for Module '" << ModulePath << "'\n");
|
||||||
|
ComputeImportForModule(FunctionInfoMap, Index, ImportList);
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
DEBUG(dbgs() << "* Module " << ModulePath << " imports from "
|
||||||
|
<< ImportList.size() << " modules.\n");
|
||||||
|
for (auto &Src : ImportList) {
|
||||||
|
auto SrcModName = Src.first();
|
||||||
|
DEBUG(dbgs() << " - " << Src.second.size() << " functions imported from "
|
||||||
|
<< SrcModName << "\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Automatically import functions in Module \p DestModule based on the summaries
|
// Automatically import functions in Module \p DestModule based on the summaries
|
||||||
// index.
|
// index.
|
||||||
//
|
//
|
||||||
|
@ -463,13 +490,10 @@ public:
|
||||||
Index = IndexPtr.get();
|
Index = IndexPtr.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
// First step is collecting the import/export lists
|
// First step is collecting the import list.
|
||||||
// The export list is not used yet, but could limit the amount of renaming
|
FunctionImporter::ImportMapTy ImportList;
|
||||||
// performed in renameModuleForThinLTO()
|
ComputeCrossModuleImportForModule(M.getModuleIdentifier(), *Index,
|
||||||
StringMap<FunctionImporter::ImportMapTy> ImportLists;
|
ImportList);
|
||||||
StringMap<FunctionImporter::ExportSetTy> ExportLists;
|
|
||||||
ComputeCrossModuleImport(*Index, ImportLists, ExportLists);
|
|
||||||
auto &ImportList = ImportLists[M.getModuleIdentifier()];
|
|
||||||
|
|
||||||
// Next we need to promote to global scope and rename any local values that
|
// Next we need to promote to global scope and rename any local values that
|
||||||
// are potentially exported to other modules.
|
// are potentially exported to other modules.
|
||||||
|
|
Loading…
Reference in New Issue