@@ -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,75 +1368,33 @@ 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
- DefaultThreadPool BackendThreadPool;
1380
- std::optional<Error> Err;
1381
- std::mutex ErrMu;
1371
+ Error ThinBackendProc::emitFiles (
1372
+ const FunctionImporter::ImportMapTy &ImportList, llvm::StringRef ModulePath,
1373
+ const std::string &NewModulePath) const {
1374
+ ModuleToSummariesForIndexTy ModuleToSummariesForIndex;
1375
+ GVSummaryPtrSet DeclarationSummaries;
1382
1376
1383
- public:
1384
- ThinBackendProc (
1385
- const Config &Conf, ModuleSummaryIndex &CombinedIndex,
1386
- const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
1387
- lto::IndexWriteCallback OnWrite, bool ShouldEmitImportsFiles,
1388
- ThreadPoolStrategy ThinLTOParallelism)
1389
- : Conf(Conf), CombinedIndex(CombinedIndex),
1390
- ModuleToDefinedGVSummaries (ModuleToDefinedGVSummaries),
1391
- OnWrite(OnWrite), ShouldEmitImportsFiles(ShouldEmitImportsFiles),
1392
- BackendThreadPool(ThinLTOParallelism) {}
1393
-
1394
- virtual ~ThinBackendProc () = default ;
1395
- virtual Error start (
1396
- unsigned Task, BitcodeModule BM,
1397
- const FunctionImporter::ImportMapTy &ImportList,
1398
- const FunctionImporter::ExportSetTy &ExportList,
1399
- const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
1400
- MapVector<StringRef, BitcodeModule> &ModuleMap) = 0;
1401
- Error wait () {
1402
- BackendThreadPool.wait ();
1403
- if (Err)
1404
- return std::move (*Err);
1405
- return Error::success ();
1406
- }
1407
- unsigned getThreadCount () { return BackendThreadPool.getMaxConcurrency (); }
1408
- virtual bool isSensitiveToInputOrder () { return false ; }
1409
-
1410
- // Write sharded indices and (optionally) imports to disk
1411
- Error emitFiles (const FunctionImporter::ImportMapTy &ImportList,
1412
- llvm::StringRef ModulePath,
1413
- const std::string &NewModulePath) const {
1414
- ModuleToSummariesForIndexTy ModuleToSummariesForIndex;
1415
- GVSummaryPtrSet DeclarationSummaries;
1416
-
1417
- std::error_code EC;
1418
- gatherImportedSummariesForModule (ModulePath, ModuleToDefinedGVSummaries,
1419
- ImportList, ModuleToSummariesForIndex,
1420
- DeclarationSummaries);
1421
-
1422
- raw_fd_ostream OS (NewModulePath + " .thinlto.bc" , EC,
1423
- sys::fs::OpenFlags::OF_None);
1424
- if (EC)
1425
- return createFileError (" cannot open " + NewModulePath + " .thinlto.bc" ,
1426
- EC);
1427
-
1428
- writeIndexToFile (CombinedIndex, OS, &ModuleToSummariesForIndex,
1429
- &DeclarationSummaries);
1430
-
1431
- if (ShouldEmitImportsFiles) {
1432
- Error ImportFilesError = EmitImportsFiles (
1433
- ModulePath, NewModulePath + " .imports" , ModuleToSummariesForIndex);
1434
- if (ImportFilesError)
1435
- return ImportFilesError;
1436
- }
1437
- return Error::success ();
1377
+ std::error_code EC;
1378
+ gatherImportedSummariesForModule (ModulePath, ModuleToDefinedGVSummaries,
1379
+ ImportList, ModuleToSummariesForIndex,
1380
+ DeclarationSummaries);
1381
+
1382
+ raw_fd_ostream OS (NewModulePath + " .thinlto.bc" , EC,
1383
+ sys::fs::OpenFlags::OF_None);
1384
+ if (EC)
1385
+ return createFileError (" cannot open " + NewModulePath + " .thinlto.bc" , EC);
1386
+
1387
+ writeIndexToFile (CombinedIndex, OS, &ModuleToSummariesForIndex,
1388
+ &DeclarationSummaries);
1389
+
1390
+ if (ShouldEmitImportsFiles) {
1391
+ Error ImportFilesError = EmitImportsFiles (
1392
+ ModulePath, NewModulePath + " .imports" , ModuleToSummariesForIndex);
1393
+ if (ImportFilesError)
1394
+ return ImportFilesError;
1438
1395
}
1439
- };
1396
+ return Error::success ();
1397
+ }
1440
1398
1441
1399
namespace {
1442
1400
class InProcessThinBackend : public ThinBackendProc {
@@ -1561,7 +1519,7 @@ ThinBackend lto::createInProcessThinBackend(ThreadPoolStrategy Parallelism,
1561
1519
lto::IndexWriteCallback OnWrite,
1562
1520
bool ShouldEmitIndexFiles,
1563
1521
bool ShouldEmitImportsFiles) {
1564
- return
1522
+ auto Func =
1565
1523
[=](const Config &Conf, ModuleSummaryIndex &CombinedIndex,
1566
1524
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
1567
1525
AddStreamFn AddStream, FileCache Cache) {
@@ -1570,6 +1528,7 @@ ThinBackend lto::createInProcessThinBackend(ThreadPoolStrategy Parallelism,
1570
1528
AddStream, Cache, OnWrite, ShouldEmitIndexFiles,
1571
1529
ShouldEmitImportsFiles);
1572
1530
};
1531
+ return ThinBackend (Func, Parallelism);
1573
1532
}
1574
1533
1575
1534
StringLiteral lto::getThinLTODefaultCPU (const Triple &TheTriple) {
@@ -1681,7 +1640,7 @@ ThinBackend lto::createWriteIndexesThinBackend(
1681
1640
std::string NewPrefix, std::string NativeObjectPrefix,
1682
1641
bool ShouldEmitImportsFiles, raw_fd_ostream *LinkedObjectsFile,
1683
1642
IndexWriteCallback OnWrite) {
1684
- return
1643
+ auto Func =
1685
1644
[=](const Config &Conf, ModuleSummaryIndex &CombinedIndex,
1686
1645
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
1687
1646
AddStreamFn AddStream, FileCache Cache) {
@@ -1690,6 +1649,7 @@ ThinBackend lto::createWriteIndexesThinBackend(
1690
1649
OldPrefix, NewPrefix, NativeObjectPrefix, ShouldEmitImportsFiles,
1691
1650
LinkedObjectsFile, OnWrite);
1692
1651
};
1652
+ return ThinBackend (Func, Parallelism);
1693
1653
}
1694
1654
1695
1655
Error LTO::runThinLTO (AddStreamFn AddStream, FileCache Cache,
0 commit comments