@@ -578,10 +578,10 @@ LTO::RegularLTOState::RegularLTOState(unsigned ParallelCodeGenParallelismLevel,
578
578
CombinedModule->IsNewDbgInfoFormat = UseNewDbgInfoFormat;
579
579
}
580
580
581
- LTO::ThinLTOState::ThinLTOState (ThinBackend Backend )
582
- : Backend(Backend ), CombinedIndex(/* HaveGVs*/ false ) {
583
- if (!Backend)
584
- this -> Backend =
581
+ LTO::ThinLTOState::ThinLTOState (ThinBackend BackendParam )
582
+ : Backend(std::move(BackendParam) ), CombinedIndex(/* HaveGVs*/ false ) {
583
+ if (!Backend. isValid () )
584
+ Backend =
585
585
createInProcessThinBackend (llvm::heavyweight_hardware_concurrency ());
586
586
}
587
587
@@ -1368,64 +1368,6 @@ SmallVector<const char *> LTO::getRuntimeLibcallSymbols(const Triple &TT) {
1368
1368
return LibcallSymbols;
1369
1369
}
1370
1370
1371
- // / This class defines the interface to the ThinLTO backend.
1372
- class lto ::ThinBackendProc {
1373
- protected:
1374
- const Config &Conf;
1375
- ModuleSummaryIndex &CombinedIndex;
1376
- const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries;
1377
- lto::IndexWriteCallback OnWrite;
1378
- bool ShouldEmitImportsFiles;
1379
-
1380
- public:
1381
- ThinBackendProc (
1382
- const Config &Conf, ModuleSummaryIndex &CombinedIndex,
1383
- const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
1384
- lto::IndexWriteCallback OnWrite, bool ShouldEmitImportsFiles)
1385
- : Conf(Conf), CombinedIndex(CombinedIndex),
1386
- ModuleToDefinedGVSummaries (ModuleToDefinedGVSummaries),
1387
- OnWrite(OnWrite), ShouldEmitImportsFiles(ShouldEmitImportsFiles) {}
1388
-
1389
- virtual ~ThinBackendProc () = default ;
1390
- virtual Error start (
1391
- unsigned Task, BitcodeModule BM,
1392
- const FunctionImporter::ImportMapTy &ImportList,
1393
- const FunctionImporter::ExportSetTy &ExportList,
1394
- const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
1395
- MapVector<StringRef, BitcodeModule> &ModuleMap) = 0;
1396
- virtual Error wait () = 0;
1397
- virtual unsigned getThreadCount () = 0;
1398
-
1399
- // Write sharded indices and (optionally) imports to disk
1400
- Error emitFiles (const FunctionImporter::ImportMapTy &ImportList,
1401
- llvm::StringRef ModulePath,
1402
- const std::string &NewModulePath) {
1403
- ModuleToSummariesForIndexTy ModuleToSummariesForIndex;
1404
- GVSummaryPtrSet DeclarationSummaries;
1405
-
1406
- std::error_code EC;
1407
- gatherImportedSummariesForModule (ModulePath, ModuleToDefinedGVSummaries,
1408
- ImportList, ModuleToSummariesForIndex,
1409
- DeclarationSummaries);
1410
-
1411
- raw_fd_ostream OS (NewModulePath + " .thinlto.bc" , EC,
1412
- sys::fs::OpenFlags::OF_None);
1413
- if (EC)
1414
- return errorCodeToError (EC);
1415
-
1416
- writeIndexToFile (CombinedIndex, OS, &ModuleToSummariesForIndex,
1417
- &DeclarationSummaries);
1418
-
1419
- if (ShouldEmitImportsFiles) {
1420
- EC = EmitImportsFiles (ModulePath, NewModulePath + " .imports" ,
1421
- ModuleToSummariesForIndex);
1422
- if (EC)
1423
- return errorCodeToError (EC);
1424
- }
1425
- return Error::success ();
1426
- }
1427
- };
1428
-
1429
1371
namespace {
1430
1372
class InProcessThinBackend : public ThinBackendProc {
1431
1373
DefaultThreadPool BackendThreadPool;
@@ -1564,7 +1506,7 @@ ThinBackend lto::createInProcessThinBackend(ThreadPoolStrategy Parallelism,
1564
1506
lto::IndexWriteCallback OnWrite,
1565
1507
bool ShouldEmitIndexFiles,
1566
1508
bool ShouldEmitImportsFiles) {
1567
- return
1509
+ auto Func =
1568
1510
[=](const Config &Conf, ModuleSummaryIndex &CombinedIndex,
1569
1511
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
1570
1512
AddStreamFn AddStream, FileCache Cache) {
@@ -1573,6 +1515,7 @@ ThinBackend lto::createInProcessThinBackend(ThreadPoolStrategy Parallelism,
1573
1515
AddStream, Cache, OnWrite, ShouldEmitIndexFiles,
1574
1516
ShouldEmitImportsFiles);
1575
1517
};
1518
+ return ThinBackend (Func, Parallelism);
1576
1519
}
1577
1520
1578
1521
StringLiteral lto::getThinLTODefaultCPU (const Triple &TheTriple) {
@@ -1665,7 +1608,7 @@ ThinBackend lto::createWriteIndexesThinBackend(
1665
1608
std::string OldPrefix, std::string NewPrefix,
1666
1609
std::string NativeObjectPrefix, bool ShouldEmitImportsFiles,
1667
1610
raw_fd_ostream *LinkedObjectsFile, IndexWriteCallback OnWrite) {
1668
- return
1611
+ auto Func =
1669
1612
[=](const Config &Conf, ModuleSummaryIndex &CombinedIndex,
1670
1613
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
1671
1614
AddStreamFn AddStream, FileCache Cache) {
@@ -1674,6 +1617,7 @@ ThinBackend lto::createWriteIndexesThinBackend(
1674
1617
NewPrefix, NativeObjectPrefix, ShouldEmitImportsFiles,
1675
1618
LinkedObjectsFile, OnWrite);
1676
1619
};
1620
+ return ThinBackend (Func);
1677
1621
}
1678
1622
1679
1623
Error LTO::runThinLTO (AddStreamFn AddStream, FileCache Cache,
@@ -1934,3 +1878,31 @@ std::vector<int> lto::generateModulesOrdering(ArrayRef<BitcodeModule *> R) {
1934
1878
});
1935
1879
return ModulesOrdering;
1936
1880
}
1881
+
1882
+ Error ThinBackendProc::emitFiles (
1883
+ const FunctionImporter::ImportMapTy &ImportList, llvm::StringRef ModulePath,
1884
+ const std::string &NewModulePath) {
1885
+ ModuleToSummariesForIndexTy ModuleToSummariesForIndex;
1886
+ GVSummaryPtrSet DeclarationSummaries;
1887
+
1888
+ std::error_code EC;
1889
+ gatherImportedSummariesForModule (ModulePath, ModuleToDefinedGVSummaries,
1890
+ ImportList, ModuleToSummariesForIndex,
1891
+ DeclarationSummaries);
1892
+
1893
+ raw_fd_ostream OS (NewModulePath + " .thinlto.bc" , EC,
1894
+ sys::fs::OpenFlags::OF_None);
1895
+ if (EC)
1896
+ return errorCodeToError (EC);
1897
+
1898
+ writeIndexToFile (CombinedIndex, OS, &ModuleToSummariesForIndex,
1899
+ &DeclarationSummaries);
1900
+
1901
+ if (ShouldEmitImportsFiles) {
1902
+ EC = EmitImportsFiles (ModulePath, NewModulePath + " .imports" ,
1903
+ ModuleToSummariesForIndex);
1904
+ if (EC)
1905
+ return errorCodeToError (EC);
1906
+ }
1907
+ return Error::success ();
1908
+ }
0 commit comments