Index: lib/LTO/ThinLTOCodeGenerator.cpp =================================================================== --- lib/LTO/ThinLTOCodeGenerator.cpp +++ lib/LTO/ThinLTOCodeGenerator.cpp @@ -950,13 +950,6 @@ // Changes are made in the index, consumed in the ThinLTO backends. internalizeAndPromoteInIndex(ExportLists, GUIDPreservedSymbols, *Index); - // Make sure that every module has an entry in the ExportLists and - // ResolvedODR maps to enable threaded access to these maps below. - for (auto &DefinedGVSummaries : ModuleToDefinedGVSummaries) { - ExportLists[DefinedGVSummaries.first()]; - ResolvedODR[DefinedGVSummaries.first()]; - } - // Compute the ordering we will process the inputs: the rough heuristic here // is to sort them per size so that the largest module get schedule as soon as // possible. This is purely a compile-time optimization. @@ -972,6 +965,17 @@ // Parallel optimizer + codegen { + // Make sure that every module has an entry in the ExportLists and + // ResolvedODR maps to enable threaded access to these maps below. + for (auto IndexCount : ModulesOrdering) { + auto &ModuleBuffer = Modules[IndexCount]; + auto ModuleIdentifier = ModuleBuffer.getBufferIdentifier(); + ExportLists.try_emplace(ModuleIdentifier); + ImportLists.try_emplace(ModuleIdentifier); + ResolvedODR.try_emplace(ModuleIdentifier); + ModuleToDefinedGVSummaries.try_emplace(ModuleIdentifier); + } + ThreadPool Pool(ThreadCount); for (auto IndexCount : ModulesOrdering) { auto &ModuleBuffer = Modules[IndexCount];