aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/LTO
diff options
context:
space:
mode:
authorKyungwoo Lee <kyulee@meta.com>2024-09-29 18:28:15 -0700
committerKyungwoo Lee <kyulee@meta.com>2024-10-07 17:45:31 -0700
commitd75c88f55a8e271ab8ad6c2a8ef3383dafdf8516 (patch)
treea47c5fb3f220ebf8251bddbbd2a73586ff57c927 /llvm/lib/LTO
parent39ac121309f5c270c8fdc97c45a845542dd78681 (diff)
downloadllvm-users/kyulee-com/thinback2.zip
llvm-users/kyulee-com/thinback2.tar.gz
llvm-users/kyulee-com/thinback2.tar.bz2
[NFC] Refactor ThinBackendusers/kyulee-com/thinback2
- Change it to a type from a function. - Store the parallelism in the type for the future use.
Diffstat (limited to 'llvm/lib/LTO')
-rw-r--r--llvm/lib/LTO/LTO.cpp106
1 files changed, 33 insertions, 73 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index ccf1139..e1714b2 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -578,10 +578,10 @@ LTO::RegularLTOState::RegularLTOState(unsigned ParallelCodeGenParallelismLevel,
CombinedModule->IsNewDbgInfoFormat = UseNewDbgInfoFormat;
}
-LTO::ThinLTOState::ThinLTOState(ThinBackend Backend)
- : Backend(Backend), CombinedIndex(/*HaveGVs*/ false) {
- if (!Backend)
- this->Backend =
+LTO::ThinLTOState::ThinLTOState(ThinBackend BackendParam)
+ : Backend(std::move(BackendParam)), CombinedIndex(/*HaveGVs*/ false) {
+ if (!Backend.isValid())
+ Backend =
createInProcessThinBackend(llvm::heavyweight_hardware_concurrency());
}
@@ -1368,75 +1368,33 @@ SmallVector<const char *> LTO::getRuntimeLibcallSymbols(const Triple &TT) {
return LibcallSymbols;
}
-/// This class defines the interface to the ThinLTO backend.
-class lto::ThinBackendProc {
-protected:
- const Config &Conf;
- ModuleSummaryIndex &CombinedIndex;
- const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries;
- lto::IndexWriteCallback OnWrite;
- bool ShouldEmitImportsFiles;
- DefaultThreadPool BackendThreadPool;
- std::optional<Error> Err;
- std::mutex ErrMu;
+Error ThinBackendProc::emitFiles(
+ const FunctionImporter::ImportMapTy &ImportList, llvm::StringRef ModulePath,
+ const std::string &NewModulePath) const {
+ ModuleToSummariesForIndexTy ModuleToSummariesForIndex;
+ GVSummaryPtrSet DeclarationSummaries;
-public:
- ThinBackendProc(
- const Config &Conf, ModuleSummaryIndex &CombinedIndex,
- const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
- lto::IndexWriteCallback OnWrite, bool ShouldEmitImportsFiles,
- ThreadPoolStrategy ThinLTOParallelism)
- : Conf(Conf), CombinedIndex(CombinedIndex),
- ModuleToDefinedGVSummaries(ModuleToDefinedGVSummaries),
- OnWrite(OnWrite), ShouldEmitImportsFiles(ShouldEmitImportsFiles),
- BackendThreadPool(ThinLTOParallelism) {}
-
- virtual ~ThinBackendProc() = default;
- virtual Error start(
- unsigned Task, BitcodeModule BM,
- const FunctionImporter::ImportMapTy &ImportList,
- const FunctionImporter::ExportSetTy &ExportList,
- const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
- MapVector<StringRef, BitcodeModule> &ModuleMap) = 0;
- Error wait() {
- BackendThreadPool.wait();
- if (Err)
- return std::move(*Err);
- return Error::success();
- }
- unsigned getThreadCount() { return BackendThreadPool.getMaxConcurrency(); }
- virtual bool isSensitiveToInputOrder() { return false; }
-
- // Write sharded indices and (optionally) imports to disk
- Error emitFiles(const FunctionImporter::ImportMapTy &ImportList,
- llvm::StringRef ModulePath,
- const std::string &NewModulePath) const {
- ModuleToSummariesForIndexTy ModuleToSummariesForIndex;
- GVSummaryPtrSet DeclarationSummaries;
-
- std::error_code EC;
- gatherImportedSummariesForModule(ModulePath, ModuleToDefinedGVSummaries,
- ImportList, ModuleToSummariesForIndex,
- DeclarationSummaries);
-
- raw_fd_ostream OS(NewModulePath + ".thinlto.bc", EC,
- sys::fs::OpenFlags::OF_None);
- if (EC)
- return createFileError("cannot open " + NewModulePath + ".thinlto.bc",
- EC);
-
- writeIndexToFile(CombinedIndex, OS, &ModuleToSummariesForIndex,
- &DeclarationSummaries);
-
- if (ShouldEmitImportsFiles) {
- Error ImportFilesError = EmitImportsFiles(
- ModulePath, NewModulePath + ".imports", ModuleToSummariesForIndex);
- if (ImportFilesError)
- return ImportFilesError;
- }
- return Error::success();
+ std::error_code EC;
+ gatherImportedSummariesForModule(ModulePath, ModuleToDefinedGVSummaries,
+ ImportList, ModuleToSummariesForIndex,
+ DeclarationSummaries);
+
+ raw_fd_ostream OS(NewModulePath + ".thinlto.bc", EC,
+ sys::fs::OpenFlags::OF_None);
+ if (EC)
+ return createFileError("cannot open " + NewModulePath + ".thinlto.bc", EC);
+
+ writeIndexToFile(CombinedIndex, OS, &ModuleToSummariesForIndex,
+ &DeclarationSummaries);
+
+ if (ShouldEmitImportsFiles) {
+ Error ImportFilesError = EmitImportsFiles(
+ ModulePath, NewModulePath + ".imports", ModuleToSummariesForIndex);
+ if (ImportFilesError)
+ return ImportFilesError;
}
-};
+ return Error::success();
+}
namespace {
class InProcessThinBackend : public ThinBackendProc {
@@ -1561,7 +1519,7 @@ ThinBackend lto::createInProcessThinBackend(ThreadPoolStrategy Parallelism,
lto::IndexWriteCallback OnWrite,
bool ShouldEmitIndexFiles,
bool ShouldEmitImportsFiles) {
- return
+ auto Func =
[=](const Config &Conf, ModuleSummaryIndex &CombinedIndex,
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
AddStreamFn AddStream, FileCache Cache) {
@@ -1570,6 +1528,7 @@ ThinBackend lto::createInProcessThinBackend(ThreadPoolStrategy Parallelism,
AddStream, Cache, OnWrite, ShouldEmitIndexFiles,
ShouldEmitImportsFiles);
};
+ return ThinBackend(Func, Parallelism);
}
StringLiteral lto::getThinLTODefaultCPU(const Triple &TheTriple) {
@@ -1681,7 +1640,7 @@ ThinBackend lto::createWriteIndexesThinBackend(
std::string NewPrefix, std::string NativeObjectPrefix,
bool ShouldEmitImportsFiles, raw_fd_ostream *LinkedObjectsFile,
IndexWriteCallback OnWrite) {
- return
+ auto Func =
[=](const Config &Conf, ModuleSummaryIndex &CombinedIndex,
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
AddStreamFn AddStream, FileCache Cache) {
@@ -1690,6 +1649,7 @@ ThinBackend lto::createWriteIndexesThinBackend(
OldPrefix, NewPrefix, NativeObjectPrefix, ShouldEmitImportsFiles,
LinkedObjectsFile, OnWrite);
};
+ return ThinBackend(Func, Parallelism);
}
Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,