Skip to content

Commit 3cd5f60

Browse files
committed
[DTLTO][LLVM] Implement integrated distribution for ThinLTO (DTLTO).
Structural changes: 1. A new ThinLTO backend implementing DTLTO has been added. 2. Both the new backend and the InProcess backend derive from a common base class to share common setup code and state. 3. The target triple is now stored for the ThinLTO bitcode files. 4. A new setup() member is called, which the ThinLTO backends can use to prepare for code generation. For the DTLTO backend, this is used to pre-allocate storage for the information required to perform the backend compilation jobs. 5. The functions for emitting summary index shard and imports files have been altered to allow the caller to specify the filenames to write and to allow the list of imports to be stored in a container rather than written to a file.
1 parent 8ed3637 commit 3cd5f60

File tree

13 files changed

+868
-24
lines changed

13 files changed

+868
-24
lines changed

llvm/include/llvm/LTO/LTO.h

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ class InputFile {
199199

200200
using 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.
203205
class ThinBackendProc {
204206
protected:
@@ -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,

llvm/include/llvm/Transforms/IPO/FunctionImport.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,12 @@ Error EmitImportsFiles(
421421
StringRef ModulePath, StringRef OutputFilename,
422422
const ModuleToSummariesForIndexTy &ModuleToSummariesForIndex);
423423

424+
/// Call \p F passing each of the files module \p ModulePath will import from.
425+
void processImportsFiles(
426+
StringRef ModulePath,
427+
const ModuleToSummariesForIndexTy &ModuleToSummariesForIndex,
428+
function_ref<void(const std::string &)> F);
429+
424430
/// Based on the information recorded in the summaries during global
425431
/// summary-based analysis:
426432
/// 1. Resolve prevailing symbol linkages and constrain visibility (CanAutoHide

0 commit comments

Comments
 (0)