Index: include/llvm/Transforms/IPO/FunctionImport.h =================================================================== --- include/llvm/Transforms/IPO/FunctionImport.h +++ include/llvm/Transforms/IPO/FunctionImport.h @@ -114,12 +114,13 @@ void gatherImportedSummariesForModule( StringRef ModulePath, const StringMap &ModuleToDefinedGVSummaries, - const StringMap &ImportLists, + const FunctionImporter::ImportMapTy &ImportListsForModule, std::map &ModuleToSummariesForIndex); +/// Emit into \p OutputFilename the files module \p ModulePath will import from. std::error_code EmitImportsFiles(StringRef ModulePath, StringRef OutputFilename, - const StringMap &ImportLists); + const FunctionImporter::ImportMapTy &ModuleImports); /// Resolve WeakForLinker values in \p TheModule based on the information /// recorded in the summaries during global summary-based analysis. Index: lib/LTO/LTO.cpp =================================================================== --- lib/LTO/LTO.cpp +++ lib/LTO/LTO.cpp @@ -409,7 +409,7 @@ virtual ~ThinBackendProc() {} virtual Error start(unsigned Task, MemoryBufferRef MBRef, - StringMap &ImportLists, + const FunctionImporter::ImportMapTy &ImportList, MapVector &ModuleMap) = 0; virtual Error wait() = 0; }; @@ -447,7 +447,7 @@ } Error start(unsigned Task, MemoryBufferRef MBRef, - StringMap &ImportLists, + const FunctionImporter::ImportMapTy &ImportList, MapVector &ModuleMap) override { StringRef ModulePath = MBRef.getBufferIdentifier(); BackendThreadPool.async( @@ -466,7 +466,7 @@ 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 @@ } Error start(unsigned Task, MemoryBufferRef MBRef, - StringMap &ImportLists, + const FunctionImporter::ImportMapTy &ImportList, MapVector &ModuleMap) override { StringRef ModulePath = MBRef.getBufferIdentifier(); std::string NewModulePath = @@ -549,7 +549,7 @@ std::map 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 @@ 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 @@ 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; Index: lib/LTO/ThinLTOCodeGenerator.cpp =================================================================== --- lib/LTO/ThinLTOCodeGenerator.cpp +++ lib/LTO/ThinLTOCodeGenerator.cpp @@ -578,7 +578,7 @@ ExportLists); llvm::gatherImportedSummariesForModule(ModulePath, ModuleToDefinedGVSummaries, - ImportLists, + ImportLists[ModulePath], ModuleToSummariesForIndex); } @@ -601,7 +601,7 @@ 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"); } Index: lib/Transforms/IPO/FunctionImport.cpp =================================================================== --- lib/Transforms/IPO/FunctionImport.cpp +++ lib/Transforms/IPO/FunctionImport.cpp @@ -440,40 +440,35 @@ void llvm::gatherImportedSummariesForModule( StringRef ModulePath, const StringMap &ModuleToDefinedGVSummaries, - const StringMap &ImportLists, + const FunctionImporter::ImportMapTy &ImportListForModule, std::map &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 &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(); }