diff options
author | Kyungwoo Lee <kyulee@meta.com> | 2024-10-03 09:58:01 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-03 09:58:01 -0700 |
commit | c1959813d6a650de7626ef9b7a7313369277f49e (patch) | |
tree | 1661effa6a855c8d55fb8f0a2e596ee0b9d97152 /llvm/lib/LTO/LTO.cpp | |
parent | a72248cb65a74aff3cc5aef8d2807fc7efb4fb75 (diff) | |
download | llvm-c1959813d6a650de7626ef9b7a7313369277f49e.zip llvm-c1959813d6a650de7626ef9b7a7313369277f49e.tar.gz llvm-c1959813d6a650de7626ef9b7a7313369277f49e.tar.bz2 |
[CGData][ThinLTO][NFC] Prep for two-codegen rounds (#90934)
This is NFC for https://github.com/llvm/llvm-project/pull/90933.
- Create a lambda function, `RunBackends`, to group the backend
operations into a single function.
- Explicitly pass the `CodeGenOnly` argument to thinBackend, instead of
depending on a configuration value.
Depends on https://github.com/llvm/llvm-project/pull/90304.
This is a patch for
https://discourse.llvm.org/t/rfc-enhanced-machine-outliner-part-2-thinlto-nolto/78753.
Diffstat (limited to 'llvm/lib/LTO/LTO.cpp')
-rw-r--r-- | llvm/lib/LTO/LTO.cpp | 75 |
1 files changed, 40 insertions, 35 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index a88124d..f4c25f8 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -1473,7 +1473,8 @@ public: return MOrErr.takeError(); return thinBackend(Conf, Task, AddStream, **MOrErr, CombinedIndex, - ImportList, DefinedGlobals, &ModuleMap); + ImportList, DefinedGlobals, &ModuleMap, + Conf.CodeGenOnly); }; auto ModuleID = BM.getModuleIdentifier(); @@ -1839,45 +1840,49 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache, TimeTraceScopeExit.release(); - std::unique_ptr<ThinBackendProc> BackendProc = - ThinLTO.Backend(Conf, ThinLTO.CombinedIndex, ModuleToDefinedGVSummaries, - AddStream, Cache); - auto &ModuleMap = ThinLTO.ModulesToCompile ? *ThinLTO.ModulesToCompile : ThinLTO.ModuleMap; - auto ProcessOneModule = [&](int I) -> Error { - auto &Mod = *(ModuleMap.begin() + I); - // Tasks 0 through ParallelCodeGenParallelismLevel-1 are reserved for - // combined module and parallel code generation partitions. - return BackendProc->start(RegularLTO.ParallelCodeGenParallelismLevel + I, - Mod.second, ImportLists[Mod.first], - ExportLists[Mod.first], ResolvedODR[Mod.first], - ThinLTO.ModuleMap); + auto RunBackends = [&](ThinBackendProc *BackendProcess) -> Error { + auto ProcessOneModule = [&](int I) -> Error { + auto &Mod = *(ModuleMap.begin() + I); + // Tasks 0 through ParallelCodeGenParallelismLevel-1 are reserved for + // combined module and parallel code generation partitions. + return BackendProcess->start( + RegularLTO.ParallelCodeGenParallelismLevel + I, Mod.second, + ImportLists[Mod.first], ExportLists[Mod.first], + ResolvedODR[Mod.first], ThinLTO.ModuleMap); + }; + + if (BackendProcess->getThreadCount() == 1) { + // Process the modules in the order they were provided on the + // command-line. It is important for this codepath to be used for + // WriteIndexesThinBackend, to ensure the emitted LinkedObjectsFile lists + // ThinLTO objects in the same order as the inputs, which otherwise would + // affect the final link order. + for (int I = 0, E = ModuleMap.size(); I != E; ++I) + if (Error E = ProcessOneModule(I)) + return E; + } else { + // When executing in parallel, process largest bitsize modules first to + // improve parallelism, and avoid starving the thread pool near the end. + // This saves about 15 sec on a 36-core machine while link `clang.exe` + // (out of 100 sec). + std::vector<BitcodeModule *> ModulesVec; + ModulesVec.reserve(ModuleMap.size()); + for (auto &Mod : ModuleMap) + ModulesVec.push_back(&Mod.second); + for (int I : generateModulesOrdering(ModulesVec)) + if (Error E = ProcessOneModule(I)) + return E; + } + return BackendProcess->wait(); }; - if (BackendProc->getThreadCount() == 1) { - // Process the modules in the order they were provided on the command-line. - // It is important for this codepath to be used for WriteIndexesThinBackend, - // to ensure the emitted LinkedObjectsFile lists ThinLTO objects in the same - // order as the inputs, which otherwise would affect the final link order. - for (int I = 0, E = ModuleMap.size(); I != E; ++I) - if (Error E = ProcessOneModule(I)) - return E; - } else { - // When executing in parallel, process largest bitsize modules first to - // improve parallelism, and avoid starving the thread pool near the end. - // This saves about 15 sec on a 36-core machine while link `clang.exe` (out - // of 100 sec). - std::vector<BitcodeModule *> ModulesVec; - ModulesVec.reserve(ModuleMap.size()); - for (auto &Mod : ModuleMap) - ModulesVec.push_back(&Mod.second); - for (int I : generateModulesOrdering(ModulesVec)) - if (Error E = ProcessOneModule(I)) - return E; - } - return BackendProc->wait(); + std::unique_ptr<ThinBackendProc> BackendProc = + ThinLTO.Backend(Conf, ThinLTO.CombinedIndex, ModuleToDefinedGVSummaries, + AddStream, Cache); + return RunBackends(BackendProc.get()); } Expected<std::unique_ptr<ToolOutputFile>> lto::setupLLVMOptimizationRemarks( |