From a8961ec73e91d3a19e0c6f4fc10c2526eb5e11de Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Wed, 28 Dec 2016 18:00:08 +0000 Subject: [PATCH] [ThinLTO] No need to rediscover imports in distributed backend Summary: We can simply import all external values with summaries included in the individual index file created for the distributed backend job, as only those are added to the individual index file created by the WriteIndexesThinBackend (in addition to summaries for the original module, which are skipped here). While computing the cross module imports on this index would come to the same conclusion as the original thin link import logic, it is unnecessary work. And when tuning, it avoids the need to pass the same function importing parameters (e.g. -import-instr-limit) to both the thin link and the backends (otherwise they won't make the same decisions). Reviewers: mehdi_amini, pcc Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D28139 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290674 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/BackendUtil.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index 5f4878bf44..54f05ef75d 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -863,11 +863,23 @@ static void runThinLTOBackend(const CodeGenOptions &CGOpts, Module *M, ModuleToDefinedGVSummaries; CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); - // FIXME: We could simply import the modules mentioned in the combined index - // here. + // We can simply import the values mentioned in the combined index, since + // we should only invoke this using the individual indexes written out + // via a WriteIndexesThinBackend. FunctionImporter::ImportMapTy ImportList; - ComputeCrossModuleImportForModule(M->getModuleIdentifier(), *CombinedIndex, - ImportList); + for (auto &GlobalList : *CombinedIndex) { + auto GUID = GlobalList.first; + assert(GlobalList.second.size() == 1 && + "Expected individual combined index to have one summary per GUID"); + auto &Summary = GlobalList.second[0]; + // Skip the summaries for the importing module. These are included to + // e.g. record required linkage changes. + if (Summary->modulePath() == M->getModuleIdentifier()) + continue; + // Doesn't matter what value we plug in to the map, just needs an entry + // to provoke importing by thinBackend. + ImportList[Summary->modulePath()][GUID] = 1; + } std::vector> OwnedImports; MapVector ModuleMap; -- 2.40.0