LLVM 23.0.0git
DTLTO.h
Go to the documentation of this file.
1//===- DTLTO.h - Distributed ThinLTO functions and classes ----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===---------------------------------------------------------------------===//
8
9#ifndef LLVM_DTLTO_DTLTO_H
10#define LLVM_DTLTO_DTLTO_H
11
12#include "llvm/LTO/LTO.h"
14
15namespace llvm {
16namespace lto {
17
18// The purpose of this class is to prepare inputs so that distributed ThinLTO
19// backend compilations can succeed.
20//
21// For distributed compilation, each input must exist as an individual bitcode
22// file on disk and be loadable via its ModuleID. This requirement is not met
23// for archive members, as an archive is a collection of files rather than a
24// standalone file. Similarly, for FatLTO objects, the bitcode is stored in a
25// section of the containing ELF object file. To address this, the class ensures
26// that an individual bitcode file exists for each input (by writing it out if
27// necessary) and that the ModuleID is updated to point to it. Module IDs are
28// also normalized on Windows to remove short 8.3 form paths that cannot be
29// loaded on remote machines.
30//
31// The class ensures that lto::InputFile objects are preserved until enough of
32// the LTO pipeline has executed to determine the required per-module
33// information, such as whether a module will participate in ThinLTO.
34class DTLTO : public LTO {
35 using Base = LTO;
36
37public:
39 unsigned ParallelCodeGenParallelismLevel, LTOKind LTOMode,
40 StringRef LinkerOutputFile, bool SaveTemps)
41 : Base(std::move(Conf), Backend, ParallelCodeGenParallelismLevel,
42 LTOMode),
43 LinkerOutputFile(LinkerOutputFile), SaveTemps(SaveTemps) {
44 assert(!LinkerOutputFile.empty() && "expected a valid linker output file");
45 }
46
47 // Add an input file and prepare it for distribution.
49 addInput(std::unique_ptr<InputFile> InputPtr) override;
50
51protected:
52 // Save the contents of ThinLTO-enabled input files that must be serialized
53 // for distribution, such as archive members and FatLTO objects, to individual
54 // bitcode files named after the module ID.
56
57 LLVM_ABI void cleanup() override;
58
59private:
60 // Bump allocator for a purpose of saving updated module IDs.
61 BumpPtrAllocator PtrAlloc;
62 StringSaver Saver{PtrAlloc};
63
64 /// The output file to which this LTO invocation will contribute.
65 StringRef LinkerOutputFile;
66
67 /// The normalized output directory, derived from LinkerOutputFile.
68 StringRef LinkerOutputDir;
69
70 /// Controls preservation of any created temporary files.
71 bool SaveTemps;
72
73 // Array of input bitcode files for LTO.
74 std::vector<std::shared_ptr<lto::InputFile>> InputFiles;
75
76 // Cache of whether a path refers to a thin archive.
77 StringMap<bool> ArchiveIsThinCache;
78
79 // Determines if the file at the given path is a thin archive.
80 Expected<bool> isThinArchive(const StringRef ArchivePath);
81};
82
83} // namespace lto
84} // namespace llvm
85
86#endif // LLVM_DTLTO_DTLTO_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition Compiler.h:213
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Tagged union holding either a T or a Error.
Definition Error.h:485
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:133
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
Definition StringSaver.h:22
LLVM_ABI void cleanup() override
Definition DTLTO.cpp:250
LLVM_ABI Expected< std::shared_ptr< InputFile > > addInput(std::unique_ptr< InputFile > InputPtr) override
Definition DTLTO.cpp:156
LLVM_ABI llvm::Error serializeInputsForDistribution() override
Definition DTLTO.cpp:232
LLVM_ABI DTLTO(Config Conf, ThinBackend Backend, unsigned ParallelCodeGenParallelismLevel, LTOKind LTOMode, StringRef LinkerOutputFile, bool SaveTemps)
Definition DTLTO.h:38
LLVM_ABI LTO(Config Conf, ThinBackend Backend={}, unsigned ParallelCodeGenParallelismLevel=1, LTOKind LTOMode=LTOK_Default)
Create an LTO object.
Definition LTO.cpp:667
LTOKind
Unified LTO modes.
Definition LTO.h:419
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1917
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:383
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870
LTO configuration.
Definition Config.h:42
This type defines the behavior following the thin-link phase during ThinLTO.
Definition LTO.h:317