@@ -578,10 +578,10 @@ LTO::RegularLTOState::RegularLTOState(unsigned ParallelCodeGenParallelismLevel,
578578 CombinedModule->IsNewDbgInfoFormat = UseNewDbgInfoFormat;
579579}
580580
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 =
585585 createInProcessThinBackend (llvm::heavyweight_hardware_concurrency ());
586586}
587587
@@ -1368,75 +1368,33 @@ SmallVector<const char *> LTO::getRuntimeLibcallSymbols(const Triple &TT) {
13681368 return LibcallSymbols;
13691369}
13701370
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;
13821376
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;
14381395 }
1439- };
1396+ return Error::success ();
1397+ }
14401398
14411399namespace {
14421400class InProcessThinBackend : public ThinBackendProc {
@@ -1561,7 +1519,7 @@ ThinBackend lto::createInProcessThinBackend(ThreadPoolStrategy Parallelism,
15611519 lto::IndexWriteCallback OnWrite,
15621520 bool ShouldEmitIndexFiles,
15631521 bool ShouldEmitImportsFiles) {
1564- return
1522+ auto Func =
15651523 [=](const Config &Conf, ModuleSummaryIndex &CombinedIndex,
15661524 const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
15671525 AddStreamFn AddStream, FileCache Cache) {
@@ -1570,6 +1528,7 @@ ThinBackend lto::createInProcessThinBackend(ThreadPoolStrategy Parallelism,
15701528 AddStream, Cache, OnWrite, ShouldEmitIndexFiles,
15711529 ShouldEmitImportsFiles);
15721530 };
1531+ return ThinBackend (Func, Parallelism);
15731532}
15741533
15751534StringLiteral lto::getThinLTODefaultCPU (const Triple &TheTriple) {
@@ -1681,7 +1640,7 @@ ThinBackend lto::createWriteIndexesThinBackend(
16811640 std::string NewPrefix, std::string NativeObjectPrefix,
16821641 bool ShouldEmitImportsFiles, raw_fd_ostream *LinkedObjectsFile,
16831642 IndexWriteCallback OnWrite) {
1684- return
1643+ auto Func =
16851644 [=](const Config &Conf, ModuleSummaryIndex &CombinedIndex,
16861645 const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
16871646 AddStreamFn AddStream, FileCache Cache) {
@@ -1690,6 +1649,7 @@ ThinBackend lto::createWriteIndexesThinBackend(
16901649 OldPrefix, NewPrefix, NativeObjectPrefix, ShouldEmitImportsFiles,
16911650 LinkedObjectsFile, OnWrite);
16921651 };
1652+ return ThinBackend (Func, Parallelism);
16931653}
16941654
16951655Error LTO::runThinLTO (AddStreamFn AddStream, FileCache Cache,
0 commit comments