llvm.org GIT mirror llvm / 7afe8bf
[ThinLTO/gold] Pass down the imports lists from the thin link (NFC) No longer need to compute the imports in each backend thread. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271690 91177308-0d34-0410-b5e6-96231b3b80d8 Teresa Johnson 4 years ago
1 changed file(s) with 30 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
893893 /// bitcode provided via the get_view gold callback.
894894 StringMap *ModuleMap;
895895
896 // Functions to import into this module.
897 FunctionImporter::ImportMapTy *ImportList;
898
896899 public:
897900 /// Constructor used by full LTO.
898901 CodeGen(std::unique_ptr M)
903906 /// Constructor used by ThinLTO.
904907 CodeGen(std::unique_ptr M, raw_fd_ostream *OS, int TaskID,
905908 const ModuleSummaryIndex *CombinedIndex, std::string Filename,
906 StringMap *ModuleMap)
909 StringMap *ModuleMap,
910 FunctionImporter::ImportMapTy *ImportList)
907911 : M(std::move(M)), OS(OS), TaskID(TaskID), CombinedIndex(CombinedIndex),
908 SaveTempsFilename(std::move(Filename)), ModuleMap(ModuleMap) {
912 SaveTempsFilename(std::move(Filename)), ModuleMap(ModuleMap),
913 ImportList(ImportList) {
909914 assert(options::thinlto == !!CombinedIndex &&
910915 "Expected module summary index iff performing ThinLTO");
911916 initTargetMachine();
990995 M->setDataLayout(TM->createDataLayout());
991996
992997 if (CombinedIndex) {
993 // First collect the import list.
994 FunctionImporter::ImportMapTy ImportList;
995 ComputeCrossModuleImportForModule(M->getModuleIdentifier(), *CombinedIndex,
996 ImportList);
997
998998 // Create a loader that will parse the bitcode from the buffers
999999 // in the ModuleMap.
10001000 ModuleLoader Loader(M->getContext(), *ModuleMap);
10011001
10021002 // Perform function importing.
10031003 FunctionImporter Importer(*CombinedIndex, Loader);
1004 Importer.importFunctions(*M, ImportList);
1004 Importer.importFunctions(*M, *ImportList);
10051005 }
10061006
10071007 legacy::PassManager passes;
11711171 StringRef Name, raw_fd_ostream *ApiFile,
11721172 const ModuleSummaryIndex &CombinedIndex,
11731173 raw_fd_ostream *OS, unsigned TaskID,
1174 StringMap &ModuleMap) {
1174 StringMap &ModuleMap,
1175 FunctionImporter::ImportMapTy &ImportList) {
11751176 // Need to use a separate context for each task
11761177 LLVMContext Context;
11771178 Context.setDiscardValueNames(options::TheOutputType !=
11881189 message(LDPL_FATAL, "Failed to rename module for ThinLTO");
11891190
11901191 CodeGen codeGen(std::move(NewModule), OS, TaskID, &CombinedIndex, Name,
1191 &ModuleMap);
1192 &ModuleMap, &ImportList);
11921193 codeGen.runAll();
11931194 }
11941195
11951196 /// Launch each module's backend pipeline in a separate task in a thread pool.
1196 static void thinLTOBackends(raw_fd_ostream *ApiFile,
1197 const ModuleSummaryIndex &CombinedIndex,
1198 StringMap &ModuleMap) {
1197 static void
1198 thinLTOBackends(raw_fd_ostream *ApiFile,
1199 const ModuleSummaryIndex &CombinedIndex,
1200 StringMap &ModuleMap,
1201 StringMap ImportLists) {
11991202 unsigned TaskCount = 0;
12001203 std::vector Tasks;
12011204 Tasks.reserve(Modules.size());
12381241 // Enqueue the task
12391242 ThinLTOThreadPool.async(thinLTOBackendTask, std::ref(F), View, F.name,
12401243 ApiFile, std::ref(CombinedIndex), OS.get(),
1241 TaskCount, std::ref(ModuleMap));
1244 TaskCount, std::ref(ModuleMap),
1245 std::ref(ImportLists[F.name]));
12421246
12431247 // Record the information needed by the task or during its cleanup
12441248 // to a ThinLTOTaskInfo instance. For information needed by the task
13221326 message(LDPL_WARNING,
13231327 "thinlto-emit-imports-files ignored unless thinlto-index-only");
13241328
1329 // Collect for each module the list of function it defines (GUID ->
1330 // Summary).
1331 StringMap>
1332 ModuleToDefinedGVSummaries(NextModuleId);
1333 CombinedIndex.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
1334
1335 StringMap ImportLists(NextModuleId);
1336 StringMap ExportLists(NextModuleId);
1337 ComputeCrossModuleImport(CombinedIndex, ModuleToDefinedGVSummaries,
1338 ImportLists, ExportLists);
1339
13251340 if (options::thinlto_index_only) {
1326 // Collect for each module the list of function it defines (GUID ->
1327 // Summary).
1328 StringMap>
1329 ModuleToDefinedGVSummaries(NextModuleId);
1330 CombinedIndex.collectDefinedGVSummariesPerModule(
1331 ModuleToDefinedGVSummaries);
1332
1333 // FIXME: We want to do this for the case where the threads are launched
1334 // from gold as well, in which case this will be moved out of the
1335 // thinlto_index_only handling, and the function importer will be invoked
1336 // directly using the Lists.
1337 StringMap ImportLists(NextModuleId);
1338 StringMap ExportLists(NextModuleId);
1339 ComputeCrossModuleImport(CombinedIndex, ModuleToDefinedGVSummaries,
1340 ImportLists, ExportLists);
1341
13421341 // If the thinlto-prefix-replace option was specified, parse it and
13431342 // extract the old and new prefixes.
13441343 std::string OldPrefix, NewPrefix;
13881387 WriteIndexToFile(CombinedIndex, OS);
13891388 }
13901389
1391 thinLTOBackends(ApiFile, CombinedIndex, ModuleMap);
1390 thinLTOBackends(ApiFile, CombinedIndex, ModuleMap, ImportLists);
13921391 return LDPS_OK;
13931392 }
13941393