@@ -581,10 +581,10 @@ LTO::RegularLTOState::RegularLTOState(unsigned ParallelCodeGenParallelismLevel,
581
581
CombinedModule->IsNewDbgInfoFormat = UseNewDbgInfoFormat;
582
582
}
583
583
584
- LTO::ThinLTOState::ThinLTOState (ThinBackend Backend )
585
- : Backend(Backend ), CombinedIndex(/* HaveGVs*/ false ) {
586
- if (!Backend)
587
- this -> Backend =
584
+ LTO::ThinLTOState::ThinLTOState (ThinBackend BackendParam )
585
+ : Backend(std::move(BackendParam) ), CombinedIndex(/* HaveGVs*/ false ) {
586
+ if (!Backend. isValid () )
587
+ Backend =
588
588
createInProcessThinBackend (llvm::heavyweight_hardware_concurrency ());
589
589
}
590
590
@@ -1371,64 +1371,6 @@ SmallVector<const char *> LTO::getRuntimeLibcallSymbols(const Triple &TT) {
1371
1371
return LibcallSymbols;
1372
1372
}
1373
1373
1374
- // / This class defines the interface to the ThinLTO backend.
1375
- class lto ::ThinBackendProc {
1376
- protected:
1377
- const Config &Conf;
1378
- ModuleSummaryIndex &CombinedIndex;
1379
- const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries;
1380
- lto::IndexWriteCallback OnWrite;
1381
- bool ShouldEmitImportsFiles;
1382
-
1383
- public:
1384
- ThinBackendProc (
1385
- const Config &Conf, ModuleSummaryIndex &CombinedIndex,
1386
- const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
1387
- lto::IndexWriteCallback OnWrite, bool ShouldEmitImportsFiles)
1388
- : Conf(Conf), CombinedIndex(CombinedIndex),
1389
- ModuleToDefinedGVSummaries (ModuleToDefinedGVSummaries),
1390
- OnWrite(OnWrite), ShouldEmitImportsFiles(ShouldEmitImportsFiles) {}
1391
-
1392
- virtual ~ThinBackendProc () = default ;
1393
- virtual Error start (
1394
- unsigned Task, BitcodeModule BM,
1395
- const FunctionImporter::ImportMapTy &ImportList,
1396
- const FunctionImporter::ExportSetTy &ExportList,
1397
- const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
1398
- MapVector<StringRef, BitcodeModule> &ModuleMap) = 0;
1399
- virtual Error wait () = 0;
1400
- virtual unsigned getThreadCount () = 0;
1401
-
1402
- // Write sharded indices and (optionally) imports to disk
1403
- Error emitFiles (const FunctionImporter::ImportMapTy &ImportList,
1404
- llvm::StringRef ModulePath,
1405
- const std::string &NewModulePath) {
1406
- ModuleToSummariesForIndexTy ModuleToSummariesForIndex;
1407
- GVSummaryPtrSet DeclarationSummaries;
1408
-
1409
- std::error_code EC;
1410
- gatherImportedSummariesForModule (ModulePath, ModuleToDefinedGVSummaries,
1411
- ImportList, ModuleToSummariesForIndex,
1412
- DeclarationSummaries);
1413
-
1414
- raw_fd_ostream OS (NewModulePath + " .thinlto.bc" , EC,
1415
- sys::fs::OpenFlags::OF_None);
1416
- if (EC)
1417
- return errorCodeToError (EC);
1418
-
1419
- writeIndexToFile (CombinedIndex, OS, &ModuleToSummariesForIndex,
1420
- &DeclarationSummaries);
1421
-
1422
- if (ShouldEmitImportsFiles) {
1423
- EC = EmitImportsFiles (ModulePath, NewModulePath + " .imports" ,
1424
- ModuleToSummariesForIndex);
1425
- if (EC)
1426
- return errorCodeToError (EC);
1427
- }
1428
- return Error::success ();
1429
- }
1430
- };
1431
-
1432
1374
namespace {
1433
1375
class InProcessThinBackend : public ThinBackendProc {
1434
1376
DefaultThreadPool BackendThreadPool;
@@ -1631,7 +1573,7 @@ ThinBackend lto::createInProcessThinBackend(ThreadPoolStrategy Parallelism,
1631
1573
lto::IndexWriteCallback OnWrite,
1632
1574
bool ShouldEmitIndexFiles,
1633
1575
bool ShouldEmitImportsFiles) {
1634
- return
1576
+ auto Func =
1635
1577
[=](const Config &Conf, ModuleSummaryIndex &CombinedIndex,
1636
1578
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
1637
1579
AddStreamFn AddStream, FileCache Cache) {
@@ -1640,6 +1582,7 @@ ThinBackend lto::createInProcessThinBackend(ThreadPoolStrategy Parallelism,
1640
1582
AddStream, Cache, OnWrite, ShouldEmitIndexFiles,
1641
1583
ShouldEmitImportsFiles);
1642
1584
};
1585
+ return ThinBackend (Func, Parallelism);
1643
1586
}
1644
1587
1645
1588
StringLiteral lto::getThinLTODefaultCPU (const Triple &TheTriple) {
@@ -1732,7 +1675,7 @@ ThinBackend lto::createWriteIndexesThinBackend(
1732
1675
std::string OldPrefix, std::string NewPrefix,
1733
1676
std::string NativeObjectPrefix, bool ShouldEmitImportsFiles,
1734
1677
raw_fd_ostream *LinkedObjectsFile, IndexWriteCallback OnWrite) {
1735
- return
1678
+ auto Func =
1736
1679
[=](const Config &Conf, ModuleSummaryIndex &CombinedIndex,
1737
1680
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
1738
1681
AddStreamFn AddStream, FileCache Cache) {
@@ -1741,6 +1684,7 @@ ThinBackend lto::createWriteIndexesThinBackend(
1741
1684
NewPrefix, NativeObjectPrefix, ShouldEmitImportsFiles,
1742
1685
LinkedObjectsFile, OnWrite);
1743
1686
};
1687
+ return ThinBackend (Func);
1744
1688
}
1745
1689
1746
1690
Error LTO::runThinLTO (AddStreamFn AddStream, FileCache Cache,
@@ -2041,3 +1985,31 @@ std::vector<int> lto::generateModulesOrdering(ArrayRef<BitcodeModule *> R) {
2041
1985
});
2042
1986
return ModulesOrdering;
2043
1987
}
1988
+
1989
+ Error ThinBackendProc::emitFiles (
1990
+ const FunctionImporter::ImportMapTy &ImportList, llvm::StringRef ModulePath,
1991
+ const std::string &NewModulePath) {
1992
+ ModuleToSummariesForIndexTy ModuleToSummariesForIndex;
1993
+ GVSummaryPtrSet DeclarationSummaries;
1994
+
1995
+ std::error_code EC;
1996
+ gatherImportedSummariesForModule (ModulePath, ModuleToDefinedGVSummaries,
1997
+ ImportList, ModuleToSummariesForIndex,
1998
+ DeclarationSummaries);
1999
+
2000
+ raw_fd_ostream OS (NewModulePath + " .thinlto.bc" , EC,
2001
+ sys::fs::OpenFlags::OF_None);
2002
+ if (EC)
2003
+ return errorCodeToError (EC);
2004
+
2005
+ writeIndexToFile (CombinedIndex, OS, &ModuleToSummariesForIndex,
2006
+ &DeclarationSummaries);
2007
+
2008
+ if (ShouldEmitImportsFiles) {
2009
+ EC = EmitImportsFiles (ModulePath, NewModulePath + " .imports" ,
2010
+ ModuleToSummariesForIndex);
2011
+ if (EC)
2012
+ return errorCodeToError (EC);
2013
+ }
2014
+ return Error::success ();
2015
+ }
0 commit comments