@@ -199,6 +199,8 @@ class InputFile {
199199
200200using IndexWriteCallback = std::function<void (const std::string &)>;
201201
202+ using ImportsFilesContainer = llvm::SmallVector<std::string>;
203+
202204// / This class defines the interface to the ThinLTO backend.
203205class ThinBackendProc {
204206protected:
@@ -223,13 +225,15 @@ class ThinBackendProc {
223225 BackendThreadPool(ThinLTOParallelism) {}
224226
225227 virtual ~ThinBackendProc () = default ;
228+ virtual void setup (unsigned MaxTasks) {}
226229 virtual Error start (
227230 unsigned Task, BitcodeModule BM,
228231 const FunctionImporter::ImportMapTy &ImportList,
229232 const FunctionImporter::ExportSetTy &ExportList,
230233 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
231- MapVector<StringRef, BitcodeModule> &ModuleMap) = 0;
232- Error wait () {
234+ MapVector<StringRef, BitcodeModule> &ModuleMap,
235+ DenseMap<StringRef, std::string> &ModuleTriples) = 0;
236+ virtual Error wait () {
233237 BackendThreadPool.wait ();
234238 if (Err)
235239 return std::move (*Err);
@@ -240,8 +244,15 @@ class ThinBackendProc {
240244
241245 // Write sharded indices and (optionally) imports to disk
242246 Error emitFiles (const FunctionImporter::ImportMapTy &ImportList,
243- llvm::StringRef ModulePath,
244- const std::string &NewModulePath) const ;
247+ StringRef ModulePath, const std::string &NewModulePath) const ;
248+
249+ // Write sharded indices to SummaryPath, (optionally) imports
250+ // IndexPath, and (optionally) record imports in ImportsFiles.
251+ Error emitFiles (const FunctionImporter::ImportMapTy &ImportList,
252+ StringRef ModulePath, StringRef SummaryPath,
253+ const std::string &NewModulePath,
254+ std::optional<std::reference_wrapper<ImportsFilesContainer>>
255+ ImportsFiles) const ;
245256};
246257
247258// / This callable defines the behavior of a ThinLTO backend after the thin-link
@@ -294,6 +305,28 @@ ThinBackend createInProcessThinBackend(ThreadPoolStrategy Parallelism,
294305 bool ShouldEmitIndexFiles = false ,
295306 bool ShouldEmitImportsFiles = false );
296307
308+ // / This ThinBackend generates the index shards and then runs the individual
309+ // / backend jobs via an external process. It takes the same parameters as the
310+ // / InProcessThinBackend, however, these parameters only control the behavior
311+ // / when generating the index files for the modules. Addtionally:
312+ // / LinkerOutputFile is a string that should identify this LTO invocation in
313+ // / the context of a wider build. It's used for naming to aid the user in
314+ // / identifying activity related to a specific LTO invocation.
315+ // / RemoteOptTool specifies the path to a Clang executable to be invoked for the
316+ // / backend jobs.
317+ // / Distributor specifies the path to a process to invoke to manage the backend
318+ // / jobs execution.
319+ // / SaveTemps is a debugging tool that prevents temporary files created by this
320+ // / backend from being cleaned up.
321+ ThinBackend createOutOfProcessThinBackend (ThreadPoolStrategy Parallelism,
322+ IndexWriteCallback OnWrite,
323+ bool ShouldEmitIndexFiles,
324+ bool ShouldEmitImportsFiles,
325+ StringRef LinkerOutputFile,
326+ StringRef RemoteOptTool,
327+ StringRef Distributor,
328+ bool SaveTemps);
329+
297330// / This ThinBackend writes individual module indexes to files, instead of
298331// / running the individual backend jobs. This backend is for distributed builds
299332// / where separate processes will invoke the real backends.
@@ -426,6 +459,7 @@ class LTO {
426459 // The bitcode modules to compile, if specified by the LTO Config.
427460 std::optional<ModuleMapType> ModulesToCompile;
428461 DenseMap<GlobalValue::GUID, StringRef> PrevailingModuleForGUID;
462+ DenseMap<StringRef, std::string> ModuleTriples;
429463 } ThinLTO;
430464
431465 // The global resolution for a particular (mangled) symbol name. This is in
@@ -517,7 +551,8 @@ class LTO {
517551 bool LivenessFromIndex);
518552
519553 Error addThinLTO (BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
520- const SymbolResolution *&ResI, const SymbolResolution *ResE);
554+ const SymbolResolution *&ResI, const SymbolResolution *ResE,
555+ StringRef Triple);
521556
522557 Error runRegularLTO (AddStreamFn AddStream);
523558 Error runThinLTO (AddStreamFn AddStream, FileCache Cache,
0 commit comments