[llvm] Make WriteIndexesThinBackend multi threaded (PR #109847)
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 25 10:38:37 PDT 2024
================
@@ -1645,19 +1648,48 @@ class WriteIndexesThinBackend : public ThinBackendProc {
*LinkedObjectsFile << LinkedObjectsFilePath << '\n';
}
- if (auto E = emitFiles(ImportList, ModulePath, NewModulePath))
- return E;
+ BackendThreadPool.async(
+ [this](const StringRef ModulePath,
+ const FunctionImporter::ImportMapTy &ImportList,
+ const std::string &OldPrefix, const std::string &NewPrefix) {
+ std::string NewModulePath =
+ getThinLTOOutputFile(ModulePath, OldPrefix, NewPrefix);
+ auto E = emitFiles(ImportList, ModulePath, NewModulePath);
+ if (E) {
+ std::unique_lock<std::mutex> L(ErrMu);
+ if (Err)
+ Err = joinErrors(std::move(*Err), std::move(E));
+ else
+ Err = std::move(E);
+ return;
+ }
+ if (OnWrite) {
+ // Serialize calls to the on write callback in case it is not thread
+ // safe
+ std::unique_lock<std::mutex> L(OnWriteMu);
+ OnWrite(std::string(ModulePath));
+ }
+ },
+ ModulePath, ImportList, OldPrefix, NewPrefix);
+ return Error::success();
+ }
- if (OnWrite)
- OnWrite(std::string(ModulePath));
+ Error wait() override {
+ BackendThreadPool.wait();
+ if (Err)
+ return std::move(*Err);
return Error::success();
}
- Error wait() override { return Error::success(); }
+ unsigned getThreadCount() override {
----------------
teresajohnson wrote:
can this be moved to the base class and made non-virtual? Ditto for wait()?
https://github.com/llvm/llvm-project/pull/109847
More information about the llvm-commits
mailing list