[clang] [llvm] [llvm][clang] Propagate VFS through LTO to `PGOOptions` (PR #159671)
Jan Svoboda via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 22 09:30:14 PDT 2025
https://github.com/jansvoboda11 updated https://github.com/llvm/llvm-project/pull/159671
>From 76f75d7123154922261d083bcb4a2bc00e050a47 Mon Sep 17 00:00:00 2001
From: Jan Svoboda <jan_svoboda at apple.com>
Date: Wed, 16 Jul 2025 14:03:27 -0700
Subject: [PATCH 1/6] [llvm] Propagate VFS to LTO (step 1)
---
llvm/lib/LTO/LTOBackend.cpp | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index c126e8efe82b3..e8618310acf73 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -236,11 +236,11 @@ createTargetMachine(const Config &Conf, const Target *TheTarget, Module &M) {
return TM;
}
-static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
- unsigned OptLevel, bool IsThinLTO,
+static void runNewPMPasses(const Config &Conf,
+ IntrusiveRefCntPtr<vfs::FileSystem> FS, Module &Mod,
+ TargetMachine *TM, unsigned OptLevel, bool IsThinLTO,
ModuleSummaryIndex *ExportSummary,
const ModuleSummaryIndex *ImportSummary) {
- auto FS = vfs::getRealFileSystem();
std::optional<PGOOptions> PGOOpt;
if (!Conf.SampleProfile.empty())
PGOOpt = PGOOptions(Conf.SampleProfile, "", Conf.ProfileRemapping,
@@ -390,9 +390,10 @@ bool lto::opt(const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
// analysis in the case of a ThinLTO build where this might be an empty
// regular LTO combined module, with a large combined index from ThinLTO.
if (!isEmptyModule(Mod)) {
+ auto FS = vfs::getRealFileSystem();
// FIXME: Plumb the combined index into the new pass manager.
- runNewPMPasses(Conf, Mod, TM, Conf.OptLevel, IsThinLTO, ExportSummary,
- ImportSummary);
+ runNewPMPasses(Conf, std::move(FS), Mod, TM, Conf.OptLevel, IsThinLTO,
+ ExportSummary, ImportSummary);
}
return !Conf.PostOptModuleHook || Conf.PostOptModuleHook(Task, Mod);
}
>From e9d8256a6eb48dbd28bab2ce886d7b2ba4f6369e Mon Sep 17 00:00:00 2001
From: Jan Svoboda <jan_svoboda at apple.com>
Date: Wed, 16 Jul 2025 14:16:00 -0700
Subject: [PATCH 2/6] step 2
---
llvm/include/llvm/LTO/LTOBackend.h | 4 ++--
llvm/lib/LTO/LTOBackend.cpp | 12 +++++++-----
llvm/lib/LTO/LTOCodeGenerator.cpp | 4 +++-
3 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/llvm/include/llvm/LTO/LTOBackend.h b/llvm/include/llvm/LTO/LTOBackend.h
index 48ad5aa64f61f..87af6653643e3 100644
--- a/llvm/include/llvm/LTO/LTOBackend.h
+++ b/llvm/include/llvm/LTO/LTOBackend.h
@@ -35,8 +35,8 @@ class Target;
namespace lto {
/// Runs middle-end LTO optimizations on \p Mod.
-LLVM_ABI bool opt(const Config &Conf, TargetMachine *TM, unsigned Task,
- Module &Mod, bool IsThinLTO,
+LLVM_ABI bool opt(const Config &Conf, IntrusiveRefCntPtr<vfs::FileSystem> FS,
+ TargetMachine *TM, unsigned Task, Module &Mod, bool IsThinLTO,
ModuleSummaryIndex *ExportSummary,
const ModuleSummaryIndex *ImportSummary,
const std::vector<uint8_t> &CmdArgs);
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index e8618310acf73..5ac72a92dd421 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -362,8 +362,9 @@ static bool isEmptyModule(const Module &Mod) {
Mod.getModuleInlineAsm().empty();
}
-bool lto::opt(const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
- bool IsThinLTO, ModuleSummaryIndex *ExportSummary,
+bool lto::opt(const Config &Conf, IntrusiveRefCntPtr<vfs::FileSystem> FS,
+ TargetMachine *TM, unsigned Task, Module &Mod, bool IsThinLTO,
+ ModuleSummaryIndex *ExportSummary,
const ModuleSummaryIndex *ImportSummary,
const std::vector<uint8_t> &CmdArgs) {
llvm::TimeTraceScope timeScope("opt");
@@ -390,7 +391,6 @@ bool lto::opt(const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
// analysis in the case of a ThinLTO build where this might be an empty
// regular LTO combined module, with a large combined index from ThinLTO.
if (!isEmptyModule(Mod)) {
- auto FS = vfs::getRealFileSystem();
// FIXME: Plumb the combined index into the new pass manager.
runNewPMPasses(Conf, std::move(FS), Mod, TM, Conf.OptLevel, IsThinLTO,
ExportSummary, ImportSummary);
@@ -564,7 +564,8 @@ Error lto::backend(const Config &C, AddStreamFn AddStream,
LLVM_DEBUG(dbgs() << "Running regular LTO\n");
if (!C.CodeGenOnly) {
- if (!opt(C, TM.get(), 0, Mod, /*IsThinLTO=*/false,
+ auto FS = vfs::getRealFileSystem();
+ if (!opt(C, FS, TM.get(), 0, Mod, /*IsThinLTO=*/false,
/*ExportSummary=*/&CombinedIndex, /*ImportSummary=*/nullptr,
/*CmdArgs*/ std::vector<uint8_t>()))
return Error::success();
@@ -642,8 +643,9 @@ Error lto::thinBackend(const Config &Conf, unsigned Task, AddStreamFn AddStream,
auto OptimizeAndCodegen =
[&](Module &Mod, TargetMachine *TM,
LLVMRemarkFileHandle DiagnosticOutputFile) {
+ auto FS = vfs::getRealFileSystem();
// Perform optimization and code generation for ThinLTO.
- if (!opt(Conf, TM, Task, Mod, /*IsThinLTO=*/true,
+ if (!opt(Conf, FS, TM, Task, Mod, /*IsThinLTO=*/true,
/*ExportSummary=*/nullptr, /*ImportSummary=*/&CombinedIndex,
CmdArgs))
return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp
index 8aa404da15286..a577269cf02f8 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -46,6 +46,7 @@
#include "llvm/Support/Process.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/ToolOutputFile.h"
+#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/TargetParser/Host.h"
@@ -612,7 +613,8 @@ bool LTOCodeGenerator::optimize() {
ModuleSummaryIndex CombinedIndex(false);
TargetMach = createTargetMachine();
- if (!opt(Config, TargetMach.get(), 0, *MergedModule, /*IsThinLTO=*/false,
+ auto FS = vfs::getRealFileSystem();
+ if (!opt(Config, FS, TargetMach.get(), 0, *MergedModule, /*IsThinLTO=*/false,
/*ExportSummary=*/&CombinedIndex, /*ImportSummary=*/nullptr,
/*CmdArgs*/ std::vector<uint8_t>())) {
emitError("LTO middle-end optimizations failed");
>From e59551da87cf0482f7772beca897ace7ecbf2885 Mon Sep 17 00:00:00 2001
From: Jan Svoboda <jan_svoboda at apple.com>
Date: Wed, 16 Jul 2025 14:20:37 -0700
Subject: [PATCH 3/6] step 3
---
clang/lib/CodeGen/BackendUtil.cpp | 10 +++++-----
llvm/include/llvm/LTO/LTOBackend.h | 16 ++++++++--------
llvm/lib/LTO/LTO.cpp | 10 +++++++---
llvm/lib/LTO/LTOBackend.cpp | 7 ++++---
4 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 106363fa83e2b..6a4e3c7952b30 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1389,11 +1389,11 @@ runThinLTOBackend(CompilerInstance &CI, ModuleSummaryIndex *CombinedIndex,
// FIXME: Both ExecuteAction and thinBackend set up optimization remarks for
// the same context.
finalizeLLVMOptimizationRemarks(M->getContext());
- if (Error E =
- thinBackend(Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
- ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
- /*ModuleMap=*/nullptr, Conf.CodeGenOnly,
- /*IRAddStream=*/nullptr, CGOpts.CmdArgs)) {
+ if (Error E = thinBackend(
+ Conf, &CI.getVirtualFileSystem(), -1, AddStream, *M, *CombinedIndex,
+ ImportList, ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
+ /*ModuleMap=*/nullptr, Conf.CodeGenOnly,
+ /*IRAddStream=*/nullptr, CGOpts.CmdArgs)) {
handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
errs() << "Error running ThinLTO backend: " << EIB.message() << '\n';
});
diff --git a/llvm/include/llvm/LTO/LTOBackend.h b/llvm/include/llvm/LTO/LTOBackend.h
index 87af6653643e3..80876fd65bd4a 100644
--- a/llvm/include/llvm/LTO/LTOBackend.h
+++ b/llvm/include/llvm/LTO/LTOBackend.h
@@ -56,14 +56,14 @@ LLVM_ABI Error backend(const Config &C, AddStreamFn AddStream,
/// the backend will skip optimization and only perform code generation. If
/// \p IRAddStream is not nullptr, it will be called just before code generation
/// to serialize the optimized IR.
-LLVM_ABI Error
-thinBackend(const Config &C, unsigned Task, AddStreamFn AddStream, Module &M,
- const ModuleSummaryIndex &CombinedIndex,
- const FunctionImporter::ImportMapTy &ImportList,
- const GVSummaryMapTy &DefinedGlobals,
- MapVector<StringRef, BitcodeModule> *ModuleMap, bool CodeGenOnly,
- AddStreamFn IRAddStream = nullptr,
- const std::vector<uint8_t> &CmdArgs = std::vector<uint8_t>());
+LLVM_ABI Error thinBackend(
+ const Config &C, IntrusiveRefCntPtr<vfs::FileSystem> FS, unsigned Task,
+ AddStreamFn AddStream, Module &M, const ModuleSummaryIndex &CombinedIndex,
+ const FunctionImporter::ImportMapTy &ImportList,
+ const GVSummaryMapTy &DefinedGlobals,
+ MapVector<StringRef, BitcodeModule> *ModuleMap, bool CodeGenOnly,
+ AddStreamFn IRAddStream = nullptr,
+ const std::vector<uint8_t> &CmdArgs = std::vector<uint8_t>());
LLVM_ABI Error finalizeOptimizationRemarks(LLVMRemarkFileHandle DiagOutputFile);
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 7b252627d73f9..414611c0a9959 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -54,6 +54,7 @@
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/VCSRevision.h"
+#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/Transforms/IPO.h"
@@ -1545,7 +1546,8 @@ class InProcessThinBackend : public CGThinBackend {
if (!MOrErr)
return MOrErr.takeError();
- return thinBackend(Conf, Task, AddStream, **MOrErr, CombinedIndex,
+ auto FS = vfs::getRealFileSystem();
+ return thinBackend(Conf, FS, Task, AddStream, **MOrErr, CombinedIndex,
ImportList, DefinedGlobals, &ModuleMap,
Conf.CodeGenOnly);
};
@@ -1659,7 +1661,8 @@ class FirstRoundThinBackend : public InProcessThinBackend {
if (!MOrErr)
return MOrErr.takeError();
- return thinBackend(Conf, Task, CGAddStream, **MOrErr, CombinedIndex,
+ auto FS = vfs::getRealFileSystem();
+ return thinBackend(Conf, FS, Task, CGAddStream, **MOrErr, CombinedIndex,
ImportList, DefinedGlobals, &ModuleMap,
Conf.CodeGenOnly, IRAddStream);
};
@@ -1754,7 +1757,8 @@ class SecondRoundThinBackend : public InProcessThinBackend {
std::unique_ptr<Module> LoadedModule =
cgdata::loadModuleForTwoRounds(BM, Task, BackendContext, *IRFiles);
- return thinBackend(Conf, Task, AddStream, *LoadedModule, CombinedIndex,
+ auto FS = vfs::getRealFileSystem();
+ return thinBackend(Conf, FS, Task, AddStream, *LoadedModule, CombinedIndex,
ImportList, DefinedGlobals, &ModuleMap,
/*CodeGenOnly=*/true);
};
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index 5ac72a92dd421..2788ea95e1cd7 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -602,8 +602,10 @@ static void dropDeadSymbols(Module &Mod, const GVSummaryMapTy &DefinedGlobals,
}
}
-Error lto::thinBackend(const Config &Conf, unsigned Task, AddStreamFn AddStream,
- Module &Mod, const ModuleSummaryIndex &CombinedIndex,
+Error lto::thinBackend(const Config &Conf,
+ IntrusiveRefCntPtr<vfs::FileSystem> FS, unsigned Task,
+ AddStreamFn AddStream, Module &Mod,
+ const ModuleSummaryIndex &CombinedIndex,
const FunctionImporter::ImportMapTy &ImportList,
const GVSummaryMapTy &DefinedGlobals,
MapVector<StringRef, BitcodeModule> *ModuleMap,
@@ -643,7 +645,6 @@ Error lto::thinBackend(const Config &Conf, unsigned Task, AddStreamFn AddStream,
auto OptimizeAndCodegen =
[&](Module &Mod, TargetMachine *TM,
LLVMRemarkFileHandle DiagnosticOutputFile) {
- auto FS = vfs::getRealFileSystem();
// Perform optimization and code generation for ThinLTO.
if (!opt(Conf, FS, TM, Task, Mod, /*IsThinLTO=*/true,
/*ExportSummary=*/nullptr, /*ImportSummary=*/&CombinedIndex,
>From c502aeb92b1a516ad912a09f81a970abd27564b5 Mon Sep 17 00:00:00 2001
From: Jan Svoboda <jan_svoboda at apple.com>
Date: Wed, 16 Jul 2025 14:25:54 -0700
Subject: [PATCH 4/6] step 4
---
llvm/include/llvm/LTO/LTO.h | 7 +++--
llvm/lib/LTO/LTO.cpp | 51 +++++++++++++++++++++----------------
2 files changed, 34 insertions(+), 24 deletions(-)
diff --git a/llvm/include/llvm/LTO/LTO.h b/llvm/include/llvm/LTO/LTO.h
index 3a9a7f7c25859..7a78095c69813 100644
--- a/llvm/include/llvm/LTO/LTO.h
+++ b/llvm/include/llvm/LTO/LTO.h
@@ -29,6 +29,7 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/StringSaver.h"
#include "llvm/Support/ThreadPool.h"
+#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/thread.h"
#include "llvm/Transforms/IPO/FunctionAttrs.h"
#include "llvm/Transforms/IPO/FunctionImport.h"
@@ -210,6 +211,7 @@ using ImportsFilesContainer = llvm::SmallVector<std::string>;
class ThinBackendProc {
protected:
const Config &Conf;
+ IntrusiveRefCntPtr<vfs::FileSystem> FS;
ModuleSummaryIndex &CombinedIndex;
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries;
IndexWriteCallback OnWrite;
@@ -220,11 +222,12 @@ class ThinBackendProc {
public:
ThinBackendProc(
- const Config &Conf, ModuleSummaryIndex &CombinedIndex,
+ const Config &Conf, IntrusiveRefCntPtr<vfs::FileSystem> FS,
+ ModuleSummaryIndex &CombinedIndex,
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
lto::IndexWriteCallback OnWrite, bool ShouldEmitImportsFiles,
ThreadPoolStrategy ThinLTOParallelism)
- : Conf(Conf), CombinedIndex(CombinedIndex),
+ : Conf(Conf), FS(std::move(FS)), CombinedIndex(CombinedIndex),
ModuleToDefinedGVSummaries(ModuleToDefinedGVSummaries),
OnWrite(OnWrite), ShouldEmitImportsFiles(ShouldEmitImportsFiles),
BackendThreadPool(ThinLTOParallelism) {}
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 414611c0a9959..26b345ecdf97f 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -1495,13 +1495,15 @@ class CGThinBackend : public ThinBackendProc {
public:
CGThinBackend(
- const Config &Conf, ModuleSummaryIndex &CombinedIndex,
+ const Config &Conf, IntrusiveRefCntPtr<vfs::FileSystem> FS,
+ ModuleSummaryIndex &CombinedIndex,
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
AddStreamFn AddStream, lto::IndexWriteCallback OnWrite,
bool ShouldEmitIndexFiles, bool ShouldEmitImportsFiles,
ThreadPoolStrategy ThinLTOParallelism)
- : ThinBackendProc(Conf, CombinedIndex, ModuleToDefinedGVSummaries,
- OnWrite, ShouldEmitImportsFiles, ThinLTOParallelism),
+ : ThinBackendProc(Conf, std::move(FS), CombinedIndex,
+ ModuleToDefinedGVSummaries, OnWrite,
+ ShouldEmitImportsFiles, ThinLTOParallelism),
AddStream(std::move(AddStream)),
ShouldEmitIndexFiles(ShouldEmitIndexFiles) {
auto &Defs = CombinedIndex.cfiFunctionDefs();
@@ -1519,14 +1521,15 @@ class InProcessThinBackend : public CGThinBackend {
public:
InProcessThinBackend(
- const Config &Conf, ModuleSummaryIndex &CombinedIndex,
- ThreadPoolStrategy ThinLTOParallelism,
+ const Config &Conf, IntrusiveRefCntPtr<vfs::FileSystem> FS,
+ ModuleSummaryIndex &CombinedIndex, ThreadPoolStrategy ThinLTOParallelism,
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
AddStreamFn AddStream, FileCache Cache, lto::IndexWriteCallback OnWrite,
bool ShouldEmitIndexFiles, bool ShouldEmitImportsFiles)
- : CGThinBackend(Conf, CombinedIndex, ModuleToDefinedGVSummaries,
- AddStream, OnWrite, ShouldEmitIndexFiles,
- ShouldEmitImportsFiles, ThinLTOParallelism),
+ : CGThinBackend(Conf, std::move(FS), CombinedIndex,
+ ModuleToDefinedGVSummaries, AddStream, OnWrite,
+ ShouldEmitIndexFiles, ShouldEmitImportsFiles,
+ ThinLTOParallelism),
Cache(std::move(Cache)) {}
virtual Error runThinLTOBackendThread(
@@ -1546,7 +1549,6 @@ class InProcessThinBackend : public CGThinBackend {
if (!MOrErr)
return MOrErr.takeError();
- auto FS = vfs::getRealFileSystem();
return thinBackend(Conf, FS, Task, AddStream, **MOrErr, CombinedIndex,
ImportList, DefinedGlobals, &ModuleMap,
Conf.CodeGenOnly);
@@ -1631,12 +1633,12 @@ class FirstRoundThinBackend : public InProcessThinBackend {
public:
FirstRoundThinBackend(
- const Config &Conf, ModuleSummaryIndex &CombinedIndex,
+ const Config &Conf, IntrusiveRefCntPtr<vfs::FileSystem> FS, ModuleSummaryIndex &CombinedIndex,
ThreadPoolStrategy ThinLTOParallelism,
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
AddStreamFn CGAddStream, FileCache CGCache, AddStreamFn IRAddStream,
FileCache IRCache)
- : InProcessThinBackend(Conf, CombinedIndex, ThinLTOParallelism,
+ : InProcessThinBackend(Conf, std::move(FS), CombinedIndex, ThinLTOParallelism,
ModuleToDefinedGVSummaries, std::move(CGAddStream),
std::move(CGCache), /*OnWrite=*/nullptr,
/*ShouldEmitIndexFiles=*/false,
@@ -1727,13 +1729,13 @@ class SecondRoundThinBackend : public InProcessThinBackend {
public:
SecondRoundThinBackend(
- const Config &Conf, ModuleSummaryIndex &CombinedIndex,
+ const Config &Conf, IntrusiveRefCntPtr<vfs::FileSystem> FS, ModuleSummaryIndex &CombinedIndex,
ThreadPoolStrategy ThinLTOParallelism,
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
AddStreamFn AddStream, FileCache Cache,
std::unique_ptr<SmallVector<StringRef>> IRFiles,
stable_hash CombinedCGDataHash)
- : InProcessThinBackend(Conf, CombinedIndex, ThinLTOParallelism,
+ : InProcessThinBackend(Conf, std::move(FS), CombinedIndex, ThinLTOParallelism,
ModuleToDefinedGVSummaries, std::move(AddStream),
std::move(Cache),
/*OnWrite=*/nullptr,
@@ -1800,8 +1802,9 @@ ThinBackend lto::createInProcessThinBackend(ThreadPoolStrategy Parallelism,
[=](const Config &Conf, ModuleSummaryIndex &CombinedIndex,
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
AddStreamFn AddStream, FileCache Cache) {
+ auto FS = vfs::getRealFileSystem();
return std::make_unique<InProcessThinBackend>(
- Conf, CombinedIndex, Parallelism, ModuleToDefinedGVSummaries,
+ Conf, FS, CombinedIndex, Parallelism, ModuleToDefinedGVSummaries,
AddStream, Cache, OnWrite, ShouldEmitIndexFiles,
ShouldEmitImportsFiles);
};
@@ -1849,13 +1852,13 @@ class WriteIndexesThinBackend : public ThinBackendProc {
public:
WriteIndexesThinBackend(
- const Config &Conf, ModuleSummaryIndex &CombinedIndex,
+ const Config &Conf, IntrusiveRefCntPtr<vfs::FileSystem> FS, ModuleSummaryIndex &CombinedIndex,
ThreadPoolStrategy ThinLTOParallelism,
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
std::string OldPrefix, std::string NewPrefix,
std::string NativeObjectPrefix, bool ShouldEmitImportsFiles,
raw_fd_ostream *LinkedObjectsFile, lto::IndexWriteCallback OnWrite)
- : ThinBackendProc(Conf, CombinedIndex, ModuleToDefinedGVSummaries,
+ : ThinBackendProc(Conf, std::move(FS), CombinedIndex, ModuleToDefinedGVSummaries,
OnWrite, ShouldEmitImportsFiles, ThinLTOParallelism),
OldPrefix(OldPrefix), NewPrefix(NewPrefix),
NativeObjectPrefix(NativeObjectPrefix),
@@ -1921,8 +1924,9 @@ ThinBackend lto::createWriteIndexesThinBackend(
[=](const Config &Conf, ModuleSummaryIndex &CombinedIndex,
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
AddStreamFn AddStream, FileCache Cache) {
+ auto FS = vfs::getRealFileSystem();
return std::make_unique<WriteIndexesThinBackend>(
- Conf, CombinedIndex, Parallelism, ModuleToDefinedGVSummaries,
+ Conf, FS, CombinedIndex, Parallelism, ModuleToDefinedGVSummaries,
OldPrefix, NewPrefix, NativeObjectPrefix, ShouldEmitImportsFiles,
LinkedObjectsFile, OnWrite);
};
@@ -2155,12 +2159,14 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
// objects and optimized IRs, using the same cache directory as the original.
cgdata::StreamCacheData CG(MaxTasks, Cache, "CG"), IR(MaxTasks, Cache, "IR");
+ auto FS = vfs::getRealFileSystem();
+
// First round: Execute optimization and code generation, outputting to
// temporary scratch objects. Serialize the optimized IRs before initiating
// code generation.
LLVM_DEBUG(dbgs() << "[TwoRounds] Running the first round of codegen\n");
auto FirstRoundLTO = std::make_unique<FirstRoundThinBackend>(
- Conf, ThinLTO.CombinedIndex, Parallelism, ModuleToDefinedGVSummaries,
+ Conf, FS, ThinLTO.CombinedIndex, Parallelism, ModuleToDefinedGVSummaries,
CG.AddStream, CG.Cache, IR.AddStream, IR.Cache);
if (Error E = RunBackends(FirstRoundLTO.get()))
return E;
@@ -2176,7 +2182,7 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
// merged data.
LLVM_DEBUG(dbgs() << "[TwoRounds] Running the second round of codegen\n");
auto SecondRoundLTO = std::make_unique<SecondRoundThinBackend>(
- Conf, ThinLTO.CombinedIndex, Parallelism, ModuleToDefinedGVSummaries,
+ Conf, FS, ThinLTO.CombinedIndex, Parallelism, ModuleToDefinedGVSummaries,
AddStream, Cache, IR.getResult(), CombinedHash);
return RunBackends(SecondRoundLTO.get());
}
@@ -2284,7 +2290,7 @@ class OutOfProcessThinBackend : public CGThinBackend {
public:
OutOfProcessThinBackend(
- const Config &Conf, ModuleSummaryIndex &CombinedIndex,
+ const Config &Conf, IntrusiveRefCntPtr<vfs::FileSystem> FS, ModuleSummaryIndex &CombinedIndex,
ThreadPoolStrategy ThinLTOParallelism,
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
AddStreamFn AddStream, lto::IndexWriteCallback OnWrite,
@@ -2292,7 +2298,7 @@ class OutOfProcessThinBackend : public CGThinBackend {
StringRef LinkerOutputFile, StringRef Distributor,
ArrayRef<StringRef> DistributorArgs, StringRef RemoteCompiler,
ArrayRef<StringRef> RemoteCompilerArgs, bool SaveTemps)
- : CGThinBackend(Conf, CombinedIndex, ModuleToDefinedGVSummaries,
+ : CGThinBackend(Conf, std::move(FS), CombinedIndex, ModuleToDefinedGVSummaries,
AddStream, OnWrite, ShouldEmitIndexFiles,
ShouldEmitImportsFiles, ThinLTOParallelism),
LinkerOutputFile(LinkerOutputFile), DistributorPath(Distributor),
@@ -2553,8 +2559,9 @@ ThinBackend lto::createOutOfProcessThinBackend(
[=](const Config &Conf, ModuleSummaryIndex &CombinedIndex,
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
AddStreamFn AddStream, FileCache /*Cache*/) {
+ auto FS = vfs::getRealFileSystem();
return std::make_unique<OutOfProcessThinBackend>(
- Conf, CombinedIndex, Parallelism, ModuleToDefinedGVSummaries,
+ Conf, FS, CombinedIndex, Parallelism, ModuleToDefinedGVSummaries,
AddStream, OnWrite, ShouldEmitIndexFiles, ShouldEmitImportsFiles,
LinkerOutputFile, Distributor, DistributorArgs, RemoteCompiler,
RemoteCompilerArgs, SaveTemps);
>From a8ae4211f17378067cb548c6b4a36c10811b7303 Mon Sep 17 00:00:00 2001
From: Jan Svoboda <jan_svoboda at apple.com>
Date: Wed, 16 Jul 2025 14:26:26 -0700
Subject: [PATCH 5/6] step 5
---
llvm/lib/LTO/LTO.cpp | 2 --
1 file changed, 2 deletions(-)
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 26b345ecdf97f..b16023c2c15a3 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -1663,7 +1663,6 @@ class FirstRoundThinBackend : public InProcessThinBackend {
if (!MOrErr)
return MOrErr.takeError();
- auto FS = vfs::getRealFileSystem();
return thinBackend(Conf, FS, Task, CGAddStream, **MOrErr, CombinedIndex,
ImportList, DefinedGlobals, &ModuleMap,
Conf.CodeGenOnly, IRAddStream);
@@ -1759,7 +1758,6 @@ class SecondRoundThinBackend : public InProcessThinBackend {
std::unique_ptr<Module> LoadedModule =
cgdata::loadModuleForTwoRounds(BM, Task, BackendContext, *IRFiles);
- auto FS = vfs::getRealFileSystem();
return thinBackend(Conf, FS, Task, AddStream, *LoadedModule, CombinedIndex,
ImportList, DefinedGlobals, &ModuleMap,
/*CodeGenOnly=*/true);
>From 673d4bc33a6c9b6c1dfd64c298cd991171877885 Mon Sep 17 00:00:00 2001
From: Jan Svoboda <jan_svoboda at apple.com>
Date: Mon, 22 Sep 2025 09:18:41 -0700
Subject: [PATCH 6/6] git-clang-format
---
llvm/lib/LTO/LTO.cpp | 45 +++++++++++++++++++++++---------------------
1 file changed, 24 insertions(+), 21 deletions(-)
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index b16023c2c15a3..47639cd733dda 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -1633,14 +1633,15 @@ class FirstRoundThinBackend : public InProcessThinBackend {
public:
FirstRoundThinBackend(
- const Config &Conf, IntrusiveRefCntPtr<vfs::FileSystem> FS, ModuleSummaryIndex &CombinedIndex,
- ThreadPoolStrategy ThinLTOParallelism,
+ const Config &Conf, IntrusiveRefCntPtr<vfs::FileSystem> FS,
+ ModuleSummaryIndex &CombinedIndex, ThreadPoolStrategy ThinLTOParallelism,
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
AddStreamFn CGAddStream, FileCache CGCache, AddStreamFn IRAddStream,
FileCache IRCache)
- : InProcessThinBackend(Conf, std::move(FS), CombinedIndex, ThinLTOParallelism,
- ModuleToDefinedGVSummaries, std::move(CGAddStream),
- std::move(CGCache), /*OnWrite=*/nullptr,
+ : InProcessThinBackend(Conf, std::move(FS), CombinedIndex,
+ ThinLTOParallelism, ModuleToDefinedGVSummaries,
+ std::move(CGAddStream), std::move(CGCache),
+ /*OnWrite=*/nullptr,
/*ShouldEmitIndexFiles=*/false,
/*ShouldEmitImportsFiles=*/false),
IRAddStream(std::move(IRAddStream)), IRCache(std::move(IRCache)) {}
@@ -1728,15 +1729,15 @@ class SecondRoundThinBackend : public InProcessThinBackend {
public:
SecondRoundThinBackend(
- const Config &Conf, IntrusiveRefCntPtr<vfs::FileSystem> FS, ModuleSummaryIndex &CombinedIndex,
- ThreadPoolStrategy ThinLTOParallelism,
+ const Config &Conf, IntrusiveRefCntPtr<vfs::FileSystem> FS,
+ ModuleSummaryIndex &CombinedIndex, ThreadPoolStrategy ThinLTOParallelism,
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
AddStreamFn AddStream, FileCache Cache,
std::unique_ptr<SmallVector<StringRef>> IRFiles,
stable_hash CombinedCGDataHash)
- : InProcessThinBackend(Conf, std::move(FS), CombinedIndex, ThinLTOParallelism,
- ModuleToDefinedGVSummaries, std::move(AddStream),
- std::move(Cache),
+ : InProcessThinBackend(Conf, std::move(FS), CombinedIndex,
+ ThinLTOParallelism, ModuleToDefinedGVSummaries,
+ std::move(AddStream), std::move(Cache),
/*OnWrite=*/nullptr,
/*ShouldEmitIndexFiles=*/false,
/*ShouldEmitImportsFiles=*/false),
@@ -1758,8 +1759,8 @@ class SecondRoundThinBackend : public InProcessThinBackend {
std::unique_ptr<Module> LoadedModule =
cgdata::loadModuleForTwoRounds(BM, Task, BackendContext, *IRFiles);
- return thinBackend(Conf, FS, Task, AddStream, *LoadedModule, CombinedIndex,
- ImportList, DefinedGlobals, &ModuleMap,
+ return thinBackend(Conf, FS, Task, AddStream, *LoadedModule,
+ CombinedIndex, ImportList, DefinedGlobals, &ModuleMap,
/*CodeGenOnly=*/true);
};
if (!Cache.isValid() || !CombinedIndex.modulePaths().count(ModuleID) ||
@@ -1850,14 +1851,15 @@ class WriteIndexesThinBackend : public ThinBackendProc {
public:
WriteIndexesThinBackend(
- const Config &Conf, IntrusiveRefCntPtr<vfs::FileSystem> FS, ModuleSummaryIndex &CombinedIndex,
- ThreadPoolStrategy ThinLTOParallelism,
+ const Config &Conf, IntrusiveRefCntPtr<vfs::FileSystem> FS,
+ ModuleSummaryIndex &CombinedIndex, ThreadPoolStrategy ThinLTOParallelism,
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
std::string OldPrefix, std::string NewPrefix,
std::string NativeObjectPrefix, bool ShouldEmitImportsFiles,
raw_fd_ostream *LinkedObjectsFile, lto::IndexWriteCallback OnWrite)
- : ThinBackendProc(Conf, std::move(FS), CombinedIndex, ModuleToDefinedGVSummaries,
- OnWrite, ShouldEmitImportsFiles, ThinLTOParallelism),
+ : ThinBackendProc(Conf, std::move(FS), CombinedIndex,
+ ModuleToDefinedGVSummaries, OnWrite,
+ ShouldEmitImportsFiles, ThinLTOParallelism),
OldPrefix(OldPrefix), NewPrefix(NewPrefix),
NativeObjectPrefix(NativeObjectPrefix),
LinkedObjectsFile(LinkedObjectsFile) {}
@@ -2288,17 +2290,18 @@ class OutOfProcessThinBackend : public CGThinBackend {
public:
OutOfProcessThinBackend(
- const Config &Conf, IntrusiveRefCntPtr<vfs::FileSystem> FS, ModuleSummaryIndex &CombinedIndex,
- ThreadPoolStrategy ThinLTOParallelism,
+ const Config &Conf, IntrusiveRefCntPtr<vfs::FileSystem> FS,
+ ModuleSummaryIndex &CombinedIndex, ThreadPoolStrategy ThinLTOParallelism,
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
AddStreamFn AddStream, lto::IndexWriteCallback OnWrite,
bool ShouldEmitIndexFiles, bool ShouldEmitImportsFiles,
StringRef LinkerOutputFile, StringRef Distributor,
ArrayRef<StringRef> DistributorArgs, StringRef RemoteCompiler,
ArrayRef<StringRef> RemoteCompilerArgs, bool SaveTemps)
- : CGThinBackend(Conf, std::move(FS), CombinedIndex, ModuleToDefinedGVSummaries,
- AddStream, OnWrite, ShouldEmitIndexFiles,
- ShouldEmitImportsFiles, ThinLTOParallelism),
+ : CGThinBackend(Conf, std::move(FS), CombinedIndex,
+ ModuleToDefinedGVSummaries, AddStream, OnWrite,
+ ShouldEmitIndexFiles, ShouldEmitImportsFiles,
+ ThinLTOParallelism),
LinkerOutputFile(LinkerOutputFile), DistributorPath(Distributor),
DistributorArgs(DistributorArgs), RemoteCompiler(RemoteCompiler),
RemoteCompilerArgs(RemoteCompilerArgs), SaveTemps(SaveTemps) {}
More information about the llvm-commits
mailing list