1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-02-01 05:01:59 +01:00

[LTO] Simplify APIs and constify (NFC)

Summary:
Multiple APIs were taking a StringMap for the ImportLists containing
the entries for for all the modules while operating on a single entry
for the current module. Instead we can pass the desired ModuleImport
directly. Also some of the APIs were not const, I believe just to be
able to use operator[] on the StringMap.

Reviewers: tejohnson

Subscribers: llvm-commits, mehdi_amini

Differential Revision: https://reviews.llvm.org/D23537

llvm-svn: 278776
This commit is contained in:
Mehdi Amini 2016-08-16 05:46:05 +00:00
parent 8812bdbcf4
commit 87829dabc8
4 changed files with 29 additions and 33 deletions

View File

@ -114,12 +114,13 @@ void ComputeCrossModuleImportForModule(
void gatherImportedSummariesForModule(
StringRef ModulePath,
const StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries,
const StringMap<FunctionImporter::ImportMapTy> &ImportLists,
const FunctionImporter::ImportMapTy &ImportList,
std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex);
/// Emit into \p OutputFilename the files module \p ModulePath will import from.
std::error_code
EmitImportsFiles(StringRef ModulePath, StringRef OutputFilename,
const StringMap<FunctionImporter::ImportMapTy> &ImportLists);
const FunctionImporter::ImportMapTy &ModuleImports);
/// Resolve WeakForLinker values in \p TheModule based on the information
/// recorded in the summaries during global summary-based analysis.

View File

@ -409,7 +409,7 @@ public:
virtual ~ThinBackendProc() {}
virtual Error start(unsigned Task, MemoryBufferRef MBRef,
StringMap<FunctionImporter::ImportMapTy> &ImportLists,
const FunctionImporter::ImportMapTy &ImportList,
MapVector<StringRef, MemoryBufferRef> &ModuleMap) = 0;
virtual Error wait() = 0;
};
@ -447,7 +447,7 @@ public:
}
Error start(unsigned Task, MemoryBufferRef MBRef,
StringMap<FunctionImporter::ImportMapTy> &ImportLists,
const FunctionImporter::ImportMapTy &ImportList,
MapVector<StringRef, MemoryBufferRef> &ModuleMap) override {
StringRef ModulePath = MBRef.getBufferIdentifier();
BackendThreadPool.async(
@ -466,7 +466,7 @@ public:
Err = std::move(E);
}
},
MBRef, std::ref(CombinedIndex), std::ref(ImportLists[ModulePath]),
MBRef, std::ref(CombinedIndex), std::ref(ImportList),
std::ref(ModuleToDefinedGVSummaries[ModulePath]), std::ref(ModuleMap));
return Error();
}
@ -530,7 +530,7 @@ public:
}
Error start(unsigned Task, MemoryBufferRef MBRef,
StringMap<FunctionImporter::ImportMapTy> &ImportLists,
const FunctionImporter::ImportMapTy &ImportList,
MapVector<StringRef, MemoryBufferRef> &ModuleMap) override {
StringRef ModulePath = MBRef.getBufferIdentifier();
std::string NewModulePath =
@ -549,7 +549,7 @@ public:
std::map<std::string, GVSummaryMapTy> ModuleToSummariesForIndex;
gatherImportedSummariesForModule(ModulePath, ModuleToDefinedGVSummaries,
ImportLists, ModuleToSummariesForIndex);
ImportList, ModuleToSummariesForIndex);
raw_fd_ostream OS(NewModulePath + ".thinlto.bc", EC,
sys::fs::OpenFlags::F_None);
@ -558,8 +558,8 @@ public:
WriteIndexToFile(CombinedIndex, OS, &ModuleToSummariesForIndex);
if (ShouldEmitImportsFiles)
return errorCodeToError(EmitImportsFiles(
ModulePath, NewModulePath + ".imports", ImportLists));
return errorCodeToError(
EmitImportsFiles(ModulePath, NewModulePath + ".imports", ImportList));
return Error();
}
@ -633,7 +633,7 @@ Error LTO::runThinLTO(AddStreamFn AddStream) {
unsigned Partition = 1;
for (auto &Mod : ThinLTO.ModuleMap) {
if (Error E = BackendProc->start(Task, Mod.second, ImportLists,
if (Error E = BackendProc->start(Task, Mod.second, ImportLists[Mod.first],
ThinLTO.ModuleMap))
return E;

View File

@ -578,7 +578,7 @@ void ThinLTOCodeGenerator::gatherImportedSummariesForModule(
ExportLists);
llvm::gatherImportedSummariesForModule(ModulePath, ModuleToDefinedGVSummaries,
ImportLists,
ImportLists[ModulePath],
ModuleToSummariesForIndex);
}
@ -601,7 +601,7 @@ void ThinLTOCodeGenerator::emitImports(StringRef ModulePath,
ExportLists);
std::error_code EC;
if ((EC = EmitImportsFiles(ModulePath, OutputName, ImportLists)))
if ((EC = EmitImportsFiles(ModulePath, OutputName, ImportLists[ModulePath])))
report_fatal_error(Twine("Failed to open ") + OutputName +
" to save imports lists\n");
}

View File

@ -440,40 +440,35 @@ void llvm::ComputeCrossModuleImportForModule(
void llvm::gatherImportedSummariesForModule(
StringRef ModulePath,
const StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries,
const StringMap<FunctionImporter::ImportMapTy> &ImportLists,
const FunctionImporter::ImportMapTy &ImportList,
std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex) {
// Include all summaries from the importing module.
ModuleToSummariesForIndex[ModulePath] =
ModuleToDefinedGVSummaries.lookup(ModulePath);
auto ModuleImports = ImportLists.find(ModulePath);
if (ModuleImports != ImportLists.end()) {
// Include summaries for imports.
for (auto &ILI : ModuleImports->second) {
auto &SummariesForIndex = ModuleToSummariesForIndex[ILI.first()];
const auto &DefinedGVSummaries =
ModuleToDefinedGVSummaries.lookup(ILI.first());
for (auto &GI : ILI.second) {
const auto &DS = DefinedGVSummaries.find(GI.first);
assert(DS != DefinedGVSummaries.end() &&
"Expected a defined summary for imported global value");
SummariesForIndex[GI.first] = DS->second;
}
// Include summaries for imports.
for (auto &ILI : ImportListForModule) {
auto &SummariesForIndex = ModuleToSummariesForIndex[ILI.first()];
const auto &DefinedGVSummaries =
ModuleToDefinedGVSummaries.lookup(ILI.first());
for (auto &GI : ILI.second) {
const auto &DS = DefinedGVSummaries.find(GI.first);
assert(DS != DefinedGVSummaries.end() &&
"Expected a defined summary for imported global value");
SummariesForIndex[GI.first] = DS->second;
}
}
}
/// Emit the files \p ModulePath will import from into \p OutputFilename.
std::error_code llvm::EmitImportsFiles(
StringRef ModulePath, StringRef OutputFilename,
const StringMap<FunctionImporter::ImportMapTy> &ImportLists) {
auto ModuleImports = ImportLists.find(ModulePath);
std::error_code
llvm::EmitImportsFiles(StringRef ModulePath, StringRef OutputFilename,
const FunctionImporter::ImportMapTy &ModuleImports) {
std::error_code EC;
raw_fd_ostream ImportsOS(OutputFilename, EC, sys::fs::OpenFlags::F_None);
if (EC)
return EC;
if (ModuleImports != ImportLists.end())
for (auto &ILI : ModuleImports->second)
ImportsOS << ILI.first() << "\n";
for (auto &ILI : ModuleImports)
ImportsOS << ILI.first() << "\n";
return std::error_code();
}