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