@@ -1376,15 +1376,21 @@ class lto::ThinBackendProc {
13761376 const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries;
13771377 lto::IndexWriteCallback OnWrite;
13781378 bool ShouldEmitImportsFiles;
1379+ DefaultThreadPool BackendThreadPool;
1380+ std::optional<Error> Err;
1381+ std::mutex ErrMu;
1382+ std::mutex OnWriteMu;
13791383
13801384public:
13811385 ThinBackendProc (
13821386 const Config &Conf, ModuleSummaryIndex &CombinedIndex,
13831387 const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
1384- lto::IndexWriteCallback OnWrite, bool ShouldEmitImportsFiles)
1388+ lto::IndexWriteCallback OnWrite, bool ShouldEmitImportsFiles,
1389+ ThreadPoolStrategy ThinLTOParallelism)
13851390 : Conf(Conf), CombinedIndex(CombinedIndex),
13861391 ModuleToDefinedGVSummaries (ModuleToDefinedGVSummaries),
1387- OnWrite(OnWrite), ShouldEmitImportsFiles(ShouldEmitImportsFiles) {}
1392+ OnWrite(OnWrite), ShouldEmitImportsFiles(ShouldEmitImportsFiles),
1393+ BackendThreadPool(ThinLTOParallelism) {}
13881394
13891395 virtual ~ThinBackendProc () = default ;
13901396 virtual Error start (
@@ -1393,8 +1399,13 @@ class lto::ThinBackendProc {
13931399 const FunctionImporter::ExportSetTy &ExportList,
13941400 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
13951401 MapVector<StringRef, BitcodeModule> &ModuleMap) = 0;
1396- virtual Error wait () = 0;
1397- virtual unsigned getThreadCount () = 0;
1402+ Error wait () {
1403+ BackendThreadPool.wait ();
1404+ if (Err)
1405+ return std::move (*Err);
1406+ return Error::success ();
1407+ }
1408+ unsigned getThreadCount () { return BackendThreadPool.getMaxConcurrency (); }
13981409 virtual bool isSensitiveToInputOrder () { return false ; }
13991410
14001411 // Write sharded indices and (optionally) imports to disk
@@ -1429,15 +1440,11 @@ class lto::ThinBackendProc {
14291440
14301441namespace {
14311442class InProcessThinBackend : public ThinBackendProc {
1432- DefaultThreadPool BackendThreadPool;
14331443 AddStreamFn AddStream;
14341444 FileCache Cache;
14351445 DenseSet<GlobalValue::GUID> CfiFunctionDefs;
14361446 DenseSet<GlobalValue::GUID> CfiFunctionDecls;
14371447
1438- std::optional<Error> Err;
1439- std::mutex ErrMu;
1440-
14411448 bool ShouldEmitIndexFiles;
14421449
14431450public:
@@ -1448,9 +1455,9 @@ class InProcessThinBackend : public ThinBackendProc {
14481455 AddStreamFn AddStream, FileCache Cache, lto::IndexWriteCallback OnWrite,
14491456 bool ShouldEmitIndexFiles, bool ShouldEmitImportsFiles)
14501457 : ThinBackendProc(Conf, CombinedIndex, ModuleToDefinedGVSummaries,
1451- OnWrite, ShouldEmitImportsFiles),
1452- BackendThreadPool (ThinLTOParallelism), AddStream (std::move(AddStream )),
1453- Cache(std::move(Cache)), ShouldEmitIndexFiles(ShouldEmitIndexFiles) {
1458+ OnWrite, ShouldEmitImportsFiles, ThinLTOParallelism ),
1459+ AddStream (std::move(AddStream)), Cache (std::move(Cache )),
1460+ ShouldEmitIndexFiles(ShouldEmitIndexFiles) {
14541461 for (auto &Name : CombinedIndex.cfiFunctionDefs ())
14551462 CfiFunctionDefs.insert (
14561463 GlobalValue::getGUID (GlobalValue::dropLLVMManglingEscape (Name)));
@@ -1547,18 +1554,6 @@ class InProcessThinBackend : public ThinBackendProc {
15471554 OnWrite (std::string (ModulePath));
15481555 return Error::success ();
15491556 }
1550-
1551- Error wait () override {
1552- BackendThreadPool.wait ();
1553- if (Err)
1554- return std::move (*Err);
1555- else
1556- return Error::success ();
1557- }
1558-
1559- unsigned getThreadCount () override {
1560- return BackendThreadPool.getMaxConcurrency ();
1561- }
15621557};
15631558} // end anonymous namespace
15641559
@@ -1615,10 +1610,6 @@ namespace {
16151610class WriteIndexesThinBackend : public ThinBackendProc {
16161611 std::string OldPrefix, NewPrefix, NativeObjectPrefix;
16171612 raw_fd_ostream *LinkedObjectsFile;
1618- DefaultThreadPool BackendThreadPool;
1619- std::optional<Error> Err;
1620- std::mutex ErrMu;
1621- std::mutex OnWriteMu;
16221613
16231614public:
16241615 WriteIndexesThinBackend (
@@ -1628,7 +1619,8 @@ class WriteIndexesThinBackend : public ThinBackendProc {
16281619 std::string NativeObjectPrefix, bool ShouldEmitImportsFiles,
16291620 raw_fd_ostream *LinkedObjectsFile, lto::IndexWriteCallback OnWrite)
16301621 : ThinBackendProc(Conf, CombinedIndex, ModuleToDefinedGVSummaries,
1631- OnWrite, ShouldEmitImportsFiles),
1622+ OnWrite, ShouldEmitImportsFiles,
1623+ /* ThinLTOParallelism */ hardware_concurrency()),
16321624 OldPrefix (OldPrefix), NewPrefix(NewPrefix),
16331625 NativeObjectPrefix(NativeObjectPrefix),
16341626 LinkedObjectsFile(LinkedObjectsFile) {}
@@ -1641,6 +1633,10 @@ class WriteIndexesThinBackend : public ThinBackendProc {
16411633 MapVector<StringRef, BitcodeModule> &ModuleMap) override {
16421634 StringRef ModulePath = BM.getModuleIdentifier ();
16431635
1636+ // The contents of this file may be used as input to a native link, and must
1637+ // therefore contain the processed modules in a determinstic order than
1638+ // match the order they are provided on the command line. For that reason,
1639+ // we cannot include this in the asynchronously executed lambda below.
16441640 if (LinkedObjectsFile) {
16451641 std::string ObjectPrefix =
16461642 NativeObjectPrefix.empty () ? NewPrefix : NativeObjectPrefix;
@@ -1675,17 +1671,6 @@ class WriteIndexesThinBackend : public ThinBackendProc {
16751671 return Error::success ();
16761672 }
16771673
1678- Error wait () override {
1679- BackendThreadPool.wait ();
1680- if (Err)
1681- return std::move (*Err);
1682- return Error::success ();
1683- }
1684-
1685- unsigned getThreadCount () override {
1686- return BackendThreadPool.getMaxConcurrency ();
1687- }
1688-
16891674 bool isSensitiveToInputOrder () override {
16901675 // The order which modules are written to LinkedObjectsFile should be
16911676 // deterministic and match the order they are passed on the command line.
0 commit comments