@@ -1473,7 +1473,8 @@ class InProcessThinBackend : public ThinBackendProc {
14731473 return MOrErr.takeError ();
14741474
14751475 return thinBackend (Conf, Task, AddStream, **MOrErr, CombinedIndex,
1476- ImportList, DefinedGlobals, &ModuleMap);
1476+ ImportList, DefinedGlobals, &ModuleMap,
1477+ Conf.CodeGenOnly );
14771478 };
14781479
14791480 auto ModuleID = BM.getModuleIdentifier ();
@@ -1839,45 +1840,49 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
18391840
18401841 TimeTraceScopeExit.release ();
18411842
1842- std::unique_ptr<ThinBackendProc> BackendProc =
1843- ThinLTO.Backend (Conf, ThinLTO.CombinedIndex , ModuleToDefinedGVSummaries,
1844- AddStream, Cache);
1845-
18461843 auto &ModuleMap =
18471844 ThinLTO.ModulesToCompile ? *ThinLTO.ModulesToCompile : ThinLTO.ModuleMap ;
18481845
1849- auto ProcessOneModule = [&](int I) -> Error {
1850- auto &Mod = *(ModuleMap.begin () + I);
1851- // Tasks 0 through ParallelCodeGenParallelismLevel-1 are reserved for
1852- // combined module and parallel code generation partitions.
1853- return BackendProc->start (RegularLTO.ParallelCodeGenParallelismLevel + I,
1854- Mod.second , ImportLists[Mod.first ],
1855- ExportLists[Mod.first ], ResolvedODR[Mod.first ],
1856- ThinLTO.ModuleMap );
1846+ auto RunBackends = [&](ThinBackendProc *BackendProcess) -> Error {
1847+ auto ProcessOneModule = [&](int I) -> Error {
1848+ auto &Mod = *(ModuleMap.begin () + I);
1849+ // Tasks 0 through ParallelCodeGenParallelismLevel-1 are reserved for
1850+ // combined module and parallel code generation partitions.
1851+ return BackendProcess->start (
1852+ RegularLTO.ParallelCodeGenParallelismLevel + I, Mod.second ,
1853+ ImportLists[Mod.first ], ExportLists[Mod.first ],
1854+ ResolvedODR[Mod.first ], ThinLTO.ModuleMap );
1855+ };
1856+
1857+ if (BackendProcess->getThreadCount () == 1 ) {
1858+ // Process the modules in the order they were provided on the
1859+ // command-line. It is important for this codepath to be used for
1860+ // WriteIndexesThinBackend, to ensure the emitted LinkedObjectsFile lists
1861+ // ThinLTO objects in the same order as the inputs, which otherwise would
1862+ // affect the final link order.
1863+ for (int I = 0 , E = ModuleMap.size (); I != E; ++I)
1864+ if (Error E = ProcessOneModule (I))
1865+ return E;
1866+ } else {
1867+ // When executing in parallel, process largest bitsize modules first to
1868+ // improve parallelism, and avoid starving the thread pool near the end.
1869+ // This saves about 15 sec on a 36-core machine while link `clang.exe`
1870+ // (out of 100 sec).
1871+ std::vector<BitcodeModule *> ModulesVec;
1872+ ModulesVec.reserve (ModuleMap.size ());
1873+ for (auto &Mod : ModuleMap)
1874+ ModulesVec.push_back (&Mod.second );
1875+ for (int I : generateModulesOrdering (ModulesVec))
1876+ if (Error E = ProcessOneModule (I))
1877+ return E;
1878+ }
1879+ return BackendProcess->wait ();
18571880 };
18581881
1859- if (BackendProc->getThreadCount () == 1 ) {
1860- // Process the modules in the order they were provided on the command-line.
1861- // It is important for this codepath to be used for WriteIndexesThinBackend,
1862- // to ensure the emitted LinkedObjectsFile lists ThinLTO objects in the same
1863- // order as the inputs, which otherwise would affect the final link order.
1864- for (int I = 0 , E = ModuleMap.size (); I != E; ++I)
1865- if (Error E = ProcessOneModule (I))
1866- return E;
1867- } else {
1868- // When executing in parallel, process largest bitsize modules first to
1869- // improve parallelism, and avoid starving the thread pool near the end.
1870- // This saves about 15 sec on a 36-core machine while link `clang.exe` (out
1871- // of 100 sec).
1872- std::vector<BitcodeModule *> ModulesVec;
1873- ModulesVec.reserve (ModuleMap.size ());
1874- for (auto &Mod : ModuleMap)
1875- ModulesVec.push_back (&Mod.second );
1876- for (int I : generateModulesOrdering (ModulesVec))
1877- if (Error E = ProcessOneModule (I))
1878- return E;
1879- }
1880- return BackendProc->wait ();
1882+ std::unique_ptr<ThinBackendProc> BackendProc =
1883+ ThinLTO.Backend (Conf, ThinLTO.CombinedIndex , ModuleToDefinedGVSummaries,
1884+ AddStream, Cache);
1885+ return RunBackends (BackendProc.get ());
18811886}
18821887
18831888Expected<std::unique_ptr<ToolOutputFile>> lto::setupLLVMOptimizationRemarks (
0 commit comments