@@ -1441,7 +1441,7 @@ class InProcessThinBackend : public ThinBackendProc {
1441
1441
GlobalValue::getGUID (GlobalValue::dropLLVMManglingEscape (Name)));
1442
1442
}
1443
1443
1444
- Error runThinLTOBackendThread (
1444
+ virtual Error runThinLTOBackendThread (
1445
1445
AddStreamFn AddStream, FileCache Cache, unsigned Task, BitcodeModule BM,
1446
1446
ModuleSummaryIndex &CombinedIndex,
1447
1447
const FunctionImporter::ImportMapTy &ImportList,
@@ -1456,7 +1456,8 @@ class InProcessThinBackend : public ThinBackendProc {
1456
1456
return MOrErr.takeError ();
1457
1457
1458
1458
return thinBackend (Conf, Task, AddStream, **MOrErr, CombinedIndex,
1459
- ImportList, DefinedGlobals, &ModuleMap);
1459
+ ImportList, DefinedGlobals, &ModuleMap,
1460
+ Conf.CodeGenOnly );
1460
1461
};
1461
1462
1462
1463
auto ModuleID = BM.getModuleIdentifier ();
@@ -1827,45 +1828,49 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
1827
1828
1828
1829
TimeTraceScopeExit.release ();
1829
1830
1830
- std::unique_ptr<ThinBackendProc> BackendProc =
1831
- ThinLTO.Backend (Conf, ThinLTO.CombinedIndex , ModuleToDefinedGVSummaries,
1832
- AddStream, Cache);
1833
-
1834
1831
auto &ModuleMap =
1835
1832
ThinLTO.ModulesToCompile ? *ThinLTO.ModulesToCompile : ThinLTO.ModuleMap ;
1836
1833
1837
- auto ProcessOneModule = [&](int I) -> Error {
1838
- auto &Mod = *(ModuleMap.begin () + I);
1839
- // Tasks 0 through ParallelCodeGenParallelismLevel-1 are reserved for
1840
- // combined module and parallel code generation partitions.
1841
- return BackendProc->start (RegularLTO.ParallelCodeGenParallelismLevel + I,
1842
- Mod.second , ImportLists[Mod.first ],
1843
- ExportLists[Mod.first ], ResolvedODR[Mod.first ],
1844
- ThinLTO.ModuleMap );
1834
+ auto RunBackends = [&](ThinBackendProc *BackendProcess) -> Error {
1835
+ auto ProcessOneModule = [&](int I) -> Error {
1836
+ auto &Mod = *(ModuleMap.begin () + I);
1837
+ // Tasks 0 through ParallelCodeGenParallelismLevel-1 are reserved for
1838
+ // combined module and parallel code generation partitions.
1839
+ return BackendProcess->start (
1840
+ RegularLTO.ParallelCodeGenParallelismLevel + I, Mod.second ,
1841
+ ImportLists[Mod.first ], ExportLists[Mod.first ],
1842
+ ResolvedODR[Mod.first ], ThinLTO.ModuleMap );
1843
+ };
1844
+
1845
+ if (BackendProcess->getThreadCount () == 1 ) {
1846
+ // Process the modules in the order they were provided on the
1847
+ // command-line. It is important for this codepath to be used for
1848
+ // WriteIndexesThinBackend, to ensure the emitted LinkedObjectsFile lists
1849
+ // ThinLTO objects in the same order as the inputs, which otherwise would
1850
+ // affect the final link order.
1851
+ for (int I = 0 , E = ModuleMap.size (); I != E; ++I)
1852
+ if (Error E = ProcessOneModule (I))
1853
+ return E;
1854
+ } else {
1855
+ // When executing in parallel, process largest bitsize modules first to
1856
+ // improve parallelism, and avoid starving the thread pool near the end.
1857
+ // This saves about 15 sec on a 36-core machine while link `clang.exe`
1858
+ // (out of 100 sec).
1859
+ std::vector<BitcodeModule *> ModulesVec;
1860
+ ModulesVec.reserve (ModuleMap.size ());
1861
+ for (auto &Mod : ModuleMap)
1862
+ ModulesVec.push_back (&Mod.second );
1863
+ for (int I : generateModulesOrdering (ModulesVec))
1864
+ if (Error E = ProcessOneModule (I))
1865
+ return E;
1866
+ }
1867
+ return BackendProcess->wait ();
1845
1868
};
1846
1869
1847
- if (BackendProc->getThreadCount () == 1 ) {
1848
- // Process the modules in the order they were provided on the command-line.
1849
- // It is important for this codepath to be used for WriteIndexesThinBackend,
1850
- // to ensure the emitted LinkedObjectsFile lists ThinLTO objects in the same
1851
- // order as the inputs, which otherwise would affect the final link order.
1852
- for (int I = 0 , E = ModuleMap.size (); I != E; ++I)
1853
- if (Error E = ProcessOneModule (I))
1854
- return E;
1855
- } else {
1856
- // When executing in parallel, process largest bitsize modules first to
1857
- // improve parallelism, and avoid starving the thread pool near the end.
1858
- // This saves about 15 sec on a 36-core machine while link `clang.exe` (out
1859
- // of 100 sec).
1860
- std::vector<BitcodeModule *> ModulesVec;
1861
- ModulesVec.reserve (ModuleMap.size ());
1862
- for (auto &Mod : ModuleMap)
1863
- ModulesVec.push_back (&Mod.second );
1864
- for (int I : generateModulesOrdering (ModulesVec))
1865
- if (Error E = ProcessOneModule (I))
1866
- return E;
1867
- }
1868
- return BackendProc->wait ();
1870
+ std::unique_ptr<ThinBackendProc> BackendProc =
1871
+ ThinLTO.Backend (Conf, ThinLTO.CombinedIndex , ModuleToDefinedGVSummaries,
1872
+ AddStream, Cache);
1873
+ return RunBackends (BackendProc.get ());
1869
1874
}
1870
1875
1871
1876
Expected<std::unique_ptr<ToolOutputFile>> lto::setupLLVMOptimizationRemarks (
0 commit comments