LLVM  14.0.0git
LTO.h
Go to the documentation of this file.
1 //===-LTO.h - LLVM Link Time Optimizer ------------------------------------===//
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 // This file declares functions and classes used to support LTO. It is intended
10 // to be used both by LTO classes as well as by clients (gold-plugin) that
11 // don't utilize the LTO code generator interfaces.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_LTO_LTO_H
16 #define LLVM_LTO_LTO_H
17 
18 #include "llvm/ADT/MapVector.h"
19 #include "llvm/ADT/StringMap.h"
22 #include "llvm/LTO/Config.h"
23 #include "llvm/Object/IRSymtab.h"
24 #include "llvm/Support/Caching.h"
25 #include "llvm/Support/Error.h"
26 #include "llvm/Support/thread.h"
29 
30 namespace llvm {
31 
32 class Error;
33 class IRMover;
34 class LLVMContext;
35 class MemoryBufferRef;
36 class Module;
37 class raw_pwrite_stream;
38 class Target;
39 class ToolOutputFile;
40 
41 /// Resolve linkage for prevailing symbols in the \p Index. Linkage changes
42 /// recorded in the index and the ThinLTO backends must apply the changes to
43 /// the module via thinLTOFinalizeInModule.
44 ///
45 /// This is done for correctness (if value exported, ensure we always
46 /// emit a copy), and compile-time optimization (allow drop of duplicates).
48  const lto::Config &C, ModuleSummaryIndex &Index,
49  function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
50  isPrevailing,
51  function_ref<void(StringRef, GlobalValue::GUID, GlobalValue::LinkageTypes)>
52  recordNewLinkage,
53  const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols);
54 
55 /// Update the linkages in the given \p Index to mark exported values
56 /// as external and non-exported values as internal. The ThinLTO backends
57 /// must apply the changes to the Module via thinLTOInternalizeModule.
59  ModuleSummaryIndex &Index,
60  function_ref<bool(StringRef, ValueInfo)> isExported,
61  function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
62  isPrevailing);
63 
64 /// Computes a unique hash for the Module considering the current list of
65 /// export/import and other global analysis results.
66 /// The hash is produced in \p Key.
68  SmallString<40> &Key, const lto::Config &Conf,
69  const ModuleSummaryIndex &Index, StringRef ModuleID,
70  const FunctionImporter::ImportMapTy &ImportList,
71  const FunctionImporter::ExportSetTy &ExportList,
72  const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
73  const GVSummaryMapTy &DefinedGlobals,
74  const std::set<GlobalValue::GUID> &CfiFunctionDefs = {},
75  const std::set<GlobalValue::GUID> &CfiFunctionDecls = {});
76 
77 namespace lto {
78 
79 /// Given the original \p Path to an output file, replace any path
80 /// prefix matching \p OldPrefix with \p NewPrefix. Also, create the
81 /// resulting directory if it does not yet exist.
82 std::string getThinLTOOutputFile(const std::string &Path,
83  const std::string &OldPrefix,
84  const std::string &NewPrefix);
85 
86 /// Setup optimization remarks.
87 Expected<std::unique_ptr<ToolOutputFile>> setupLLVMOptimizationRemarks(
88  LLVMContext &Context, StringRef RemarksFilename, StringRef RemarksPasses,
89  StringRef RemarksFormat, bool RemarksWithHotness,
90  Optional<uint64_t> RemarksHotnessThreshold = 0, int Count = -1);
91 
92 /// Setups the output file for saving statistics.
93 Expected<std::unique_ptr<ToolOutputFile>>
94 setupStatsFile(StringRef StatsFilename);
95 
96 /// Produces a container ordering for optimal multi-threaded processing. Returns
97 /// ordered indices to elements in the input array.
98 std::vector<int> generateModulesOrdering(ArrayRef<BitcodeModule *> R);
99 
100 class LTO;
101 struct SymbolResolution;
102 class ThinBackendProc;
103 
104 /// An input file. This is a symbol table wrapper that only exposes the
105 /// information that an LTO client should need in order to do symbol resolution.
106 class InputFile {
107 public:
108  class Symbol;
109 
110 private:
111  // FIXME: Remove LTO class friendship once we have bitcode symbol tables.
112  friend LTO;
113  InputFile() = default;
114 
115  std::vector<BitcodeModule> Mods;
116  SmallVector<char, 0> Strtab;
117  std::vector<Symbol> Symbols;
118 
119  // [begin, end) for each module
120  std::vector<std::pair<size_t, size_t>> ModuleSymIndices;
121 
122  StringRef TargetTriple, SourceFileName, COFFLinkerOpts;
123  std::vector<StringRef> DependentLibraries;
124  std::vector<std::pair<StringRef, Comdat::SelectionKind>> ComdatTable;
125 
126 public:
127  ~InputFile();
128 
129  /// Create an InputFile.
131 
132  /// The purpose of this class is to only expose the symbol information that an
133  /// LTO client should need in order to do symbol resolution.
135  friend LTO;
136 
137  public:
138  Symbol(const irsymtab::Symbol &S) : irsymtab::Symbol(S) {}
139 
156  };
157 
158  /// A range over the symbols in this InputFile.
159  ArrayRef<Symbol> symbols() const { return Symbols; }
160 
161  /// Returns linker options specified in the input file.
162  StringRef getCOFFLinkerOpts() const { return COFFLinkerOpts; }
163 
164  /// Returns dependent library specifiers from the input file.
165  ArrayRef<StringRef> getDependentLibraries() const { return DependentLibraries; }
166 
167  /// Returns the path to the InputFile.
168  StringRef getName() const;
169 
170  /// Returns the input file's target triple.
171  StringRef getTargetTriple() const { return TargetTriple; }
172 
173  /// Returns the source file path specified at compile time.
174  StringRef getSourceFileName() const { return SourceFileName; }
175 
176  // Returns a table with all the comdats used by this file.
178  return ComdatTable;
179  }
180 
181  // Returns the only BitcodeModule from InputFile.
183 
184 private:
185  ArrayRef<Symbol> module_symbols(unsigned I) const {
186  const auto &Indices = ModuleSymIndices[I];
187  return {Symbols.data() + Indices.first, Symbols.data() + Indices.second};
188  }
189 };
190 
191 /// A ThinBackend defines what happens after the thin-link phase during ThinLTO.
192 /// The details of this type definition aren't important; clients can only
193 /// create a ThinBackend using one of the create*ThinBackend() functions below.
194 using ThinBackend = std::function<std::unique_ptr<ThinBackendProc>(
195  const Config &C, ModuleSummaryIndex &CombinedIndex,
196  StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries,
197  AddStreamFn AddStream, NativeObjectCache Cache)>;
198 
199 /// This ThinBackend runs the individual backend jobs in-process.
200 /// The default value means to use one job per hardware core (not hyper-thread).
202 
203 /// This ThinBackend writes individual module indexes to files, instead of
204 /// running the individual backend jobs. This backend is for distributed builds
205 /// where separate processes will invoke the real backends.
206 ///
207 /// To find the path to write the index to, the backend checks if the path has a
208 /// prefix of OldPrefix; if so, it replaces that prefix with NewPrefix. It then
209 /// appends ".thinlto.bc" and writes the index to that path. If
210 /// ShouldEmitImportsFiles is true it also writes a list of imported files to a
211 /// similar path with ".imports" appended instead.
212 /// LinkedObjectsFile is an output stream to write the list of object files for
213 /// the final ThinLTO linking. Can be nullptr.
214 /// OnWrite is callback which receives module identifier and notifies LTO user
215 /// that index file for the module (and optionally imports file) was created.
216 using IndexWriteCallback = std::function<void(const std::string &)>;
217 ThinBackend createWriteIndexesThinBackend(std::string OldPrefix,
218  std::string NewPrefix,
219  bool ShouldEmitImportsFiles,
220  raw_fd_ostream *LinkedObjectsFile,
221  IndexWriteCallback OnWrite);
222 
223 /// This class implements a resolution-based interface to LLVM's LTO
224 /// functionality. It supports regular LTO, parallel LTO code generation and
225 /// ThinLTO. You can use it from a linker in the following way:
226 /// - Set hooks and code generation options (see lto::Config struct defined in
227 /// Config.h), and use the lto::Config object to create an lto::LTO object.
228 /// - Create lto::InputFile objects using lto::InputFile::create(), then use
229 /// the symbols() function to enumerate its symbols and compute a resolution
230 /// for each symbol (see SymbolResolution below).
231 /// - After the linker has visited each input file (and each regular object
232 /// file) and computed a resolution for each symbol, take each lto::InputFile
233 /// and pass it and an array of symbol resolutions to the add() function.
234 /// - Call the getMaxTasks() function to get an upper bound on the number of
235 /// native object files that LTO may add to the link.
236 /// - Call the run() function. This function will use the supplied AddStream
237 /// and Cache functions to add up to getMaxTasks() native object files to
238 /// the link.
239 class LTO {
240  friend InputFile;
241 
242 public:
243  /// Create an LTO object. A default constructed LTO object has a reasonable
244  /// production configuration, but you can customize it by passing arguments to
245  /// this constructor.
246  /// FIXME: We do currently require the DiagHandler field to be set in Conf.
247  /// Until that is fixed, a Config argument is required.
248  LTO(Config Conf, ThinBackend Backend = nullptr,
249  unsigned ParallelCodeGenParallelismLevel = 1);
250  ~LTO();
251 
252  /// Add an input file to the LTO link, using the provided symbol resolutions.
253  /// The symbol resolutions must appear in the enumeration order given by
254  /// InputFile::symbols().
255  Error add(std::unique_ptr<InputFile> Obj, ArrayRef<SymbolResolution> Res);
256 
257  /// Returns an upper bound on the number of tasks that the client may expect.
258  /// This may only be called after all IR object files have been added. For a
259  /// full description of tasks see LTOBackend.h.
260  unsigned getMaxTasks() const;
261 
262  /// Runs the LTO pipeline. This function calls the supplied AddStream
263  /// function to add native object files to the link.
264  ///
265  /// The Cache parameter is optional. If supplied, it will be used to cache
266  /// native object files and add them to the link.
267  ///
268  /// The client will receive at most one callback (via either AddStream or
269  /// Cache) for each task identifier.
270  Error run(AddStreamFn AddStream, NativeObjectCache Cache = nullptr);
271 
272  /// Static method that returns a list of libcall symbols that can be generated
273  /// by LTO but might not be visible from bitcode symbol table.
275 
276 private:
277  Config Conf;
278 
279  struct RegularLTOState {
280  RegularLTOState(unsigned ParallelCodeGenParallelismLevel,
281  const Config &Conf);
285  /// Record if at least one instance of the common was marked as prevailing
286  bool Prevailing = false;
287  };
288  std::map<std::string, CommonResolution> Commons;
289 
290  unsigned ParallelCodeGenParallelismLevel;
291  LTOLLVMContext Ctx;
292  std::unique_ptr<Module> CombinedModule;
293  std::unique_ptr<IRMover> Mover;
294 
295  // This stores the information about a regular LTO module that we have added
296  // to the link. It will either be linked immediately (for modules without
297  // summaries) or after summary-based dead stripping (for modules with
298  // summaries).
299  struct AddedModule {
300  std::unique_ptr<Module> M;
301  std::vector<GlobalValue *> Keep;
302  };
303  std::vector<AddedModule> ModsWithSummaries;
304  bool EmptyCombinedModule = true;
305  } RegularLTO;
306 
308 
309  struct ThinLTOState {
310  ThinLTOState(ThinBackend Backend);
311 
312  ThinBackend Backend;
313  ModuleSummaryIndex CombinedIndex;
314  // The full set of bitcode modules in input order.
315  ModuleMapType ModuleMap;
316  // The bitcode modules to compile, if specified by the LTO Config.
317  Optional<ModuleMapType> ModulesToCompile;
318  DenseMap<GlobalValue::GUID, StringRef> PrevailingModuleForGUID;
319  } ThinLTO;
320 
321  // The global resolution for a particular (mangled) symbol name. This is in
322  // particular necessary to track whether each symbol can be internalized.
323  // Because any input file may introduce a new cross-partition reference, we
324  // cannot make any final internalization decisions until all input files have
325  // been added and the client has called run(). During run() we apply
326  // internalization decisions either directly to the module (for regular LTO)
327  // or to the combined index (for ThinLTO).
328  struct GlobalResolution {
329  /// The unmangled name of the global.
330  std::string IRName;
331 
332  /// Keep track if the symbol is visible outside of a module with a summary
333  /// (i.e. in either a regular object or a regular LTO module without a
334  /// summary).
335  bool VisibleOutsideSummary = false;
336 
337  /// The symbol was exported dynamically, and therefore could be referenced
338  /// by a shared library not visible to the linker.
339  bool ExportDynamic = false;
340 
341  bool UnnamedAddr = true;
342 
343  /// True if module contains the prevailing definition.
344  bool Prevailing = false;
345 
346  /// Returns true if module contains the prevailing definition and symbol is
347  /// an IR symbol. For example when module-level inline asm block is used,
348  /// symbol can be prevailing in module but have no IR name.
349  bool isPrevailingIRSymbol() const { return Prevailing && !IRName.empty(); }
350 
351  /// This field keeps track of the partition number of this global. The
352  /// regular LTO object is partition 0, while each ThinLTO object has its own
353  /// partition number from 1 onwards.
354  ///
355  /// Any global that is defined or used by more than one partition, or that
356  /// is referenced externally, may not be internalized.
357  ///
358  /// Partitions generally have a one-to-one correspondence with tasks, except
359  /// that we use partition 0 for all parallel LTO code generation partitions.
360  /// Any partitioning of the combined LTO object is done internally by the
361  /// LTO backend.
362  unsigned Partition = Unknown;
363 
364  /// Special partition numbers.
365  enum : unsigned {
366  /// A partition number has not yet been assigned to this global.
367  Unknown = -1u,
368 
369  /// This global is either used by more than one partition or has an
370  /// external reference, and therefore cannot be internalized.
371  External = -2u,
372 
373  /// The RegularLTO partition
374  RegularLTO = 0,
375  };
376  };
377 
378  // Global mapping from mangled symbol names to resolutions.
379  StringMap<GlobalResolution> GlobalResolutions;
380 
381  void addModuleToGlobalRes(ArrayRef<InputFile::Symbol> Syms,
382  ArrayRef<SymbolResolution> Res, unsigned Partition,
383  bool InSummary);
384 
385  // These functions take a range of symbol resolutions [ResI, ResE) and consume
386  // the resolutions used by a single input module by incrementing ResI. After
387  // these functions return, [ResI, ResE) will refer to the resolution range for
388  // the remaining modules in the InputFile.
389  Error addModule(InputFile &Input, unsigned ModI,
390  const SymbolResolution *&ResI, const SymbolResolution *ResE);
391 
392  Expected<RegularLTOState::AddedModule>
393  addRegularLTO(BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
394  const SymbolResolution *&ResI, const SymbolResolution *ResE);
395  Error linkRegularLTO(RegularLTOState::AddedModule Mod,
396  bool LivenessFromIndex);
397 
398  Error addThinLTO(BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
399  const SymbolResolution *&ResI, const SymbolResolution *ResE);
400 
401  Error runRegularLTO(AddStreamFn AddStream);
402  Error runThinLTO(AddStreamFn AddStream, NativeObjectCache Cache,
403  const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols);
404 
405  Error checkPartiallySplit();
406 
407  mutable bool CalledGetMaxTasks = false;
408 
409  // Use Optional to distinguish false from not yet initialized.
410  Optional<bool> EnableSplitLTOUnit;
411 
412  // Identify symbols exported dynamically, and that therefore could be
413  // referenced by a shared library not visible to the linker.
414  DenseSet<GlobalValue::GUID> DynamicExportSymbols;
415 
416  // Diagnostic optimization remarks file
417  std::unique_ptr<ToolOutputFile> DiagnosticOutputFile;
418 };
419 
420 /// The resolution for a symbol. The linker must provide a SymbolResolution for
421 /// each global symbol based on its internal resolution of that symbol.
426 
427  /// The linker has chosen this definition of the symbol.
428  unsigned Prevailing : 1;
429 
430  /// The definition of this symbol is unpreemptable at runtime and is known to
431  /// be in this linkage unit.
433 
434  /// The definition of this symbol is visible outside of the LTO unit.
435  unsigned VisibleToRegularObj : 1;
436 
437  /// The symbol was exported dynamically, and therefore could be referenced
438  /// by a shared library not visible to the linker.
439  unsigned ExportDynamic : 1;
440 
441  /// Linker redefined version of the symbol which appeared in -wrap or -defsym
442  /// linker option.
443  unsigned LinkerRedefined : 1;
444 };
445 
446 } // namespace lto
447 } // namespace llvm
448 
449 #endif
llvm::GlobalValue::GUID
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
Definition: GlobalValue.h:509
llvm::RemarksPasses
cl::opt< std::string > RemarksPasses("lto-pass-remarks-filter", cl::desc("Only record optimization remarks from passes whose " "names match the given regular expression"), cl::value_desc("regex"))
Definition: ThinLTOCodeGenerator.cpp:82
llvm::lto::LTO::RegularLTOState::CommonResolution::Size
uint64_t Size
Definition: LTO.h:283
llvm::irsymtab::Symbol::getIRName
StringRef getIRName() const
Returns the unmangled symbol name, or the empty string if this is not an IR symbol.
Definition: IRSymtab.h:186
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::lltok::Error
@ Error
Definition: LLToken.h:21
llvm::lto::InputFile::Symbol
The purpose of this class is to only expose the symbol information that an LTO client should need in ...
Definition: LTO.h:134
llvm::computeLTOCacheKey
void computeLTOCacheKey(SmallString< 40 > &Key, const lto::Config &Conf, const ModuleSummaryIndex &Index, StringRef ModuleID, const FunctionImporter::ImportMapTy &ImportList, const FunctionImporter::ExportSetTy &ExportList, const std::map< GlobalValue::GUID, GlobalValue::LinkageTypes > &ResolvedODR, const GVSummaryMapTy &DefinedGlobals, const std::set< GlobalValue::GUID > &CfiFunctionDefs={}, const std::set< GlobalValue::GUID > &CfiFunctionDecls={})
Computes a unique hash for the Module considering the current list of export/import and other global ...
Definition: LTO.cpp:79
llvm::lto::InputFile::getTargetTriple
StringRef getTargetTriple() const
Returns the input file's target triple.
Definition: LTO.h:171
llvm::irsymtab::Symbol::getCOFFWeakExternalFallback
StringRef getCOFFWeakExternalFallback() const
COFF-specific: for weak externals, returns the name of the symbol that is used as a fallback if the w...
Definition: IRSymtab.h:226
llvm::SmallVector< char, 0 >
FunctionImport.h
llvm::ThreadPoolStrategy
This tells how a thread pool will be used.
Definition: Threading.h:119
llvm::RemarksFilename
cl::opt< std::string > RemarksFilename("lto-pass-remarks-output", cl::desc("Output filename for pass remarks"), cl::value_desc("filename"))
Definition: ThinLTOCodeGenerator.cpp:81
llvm::lto::InputFile::getSingleBitcodeModule
BitcodeModule & getSingleBitcodeModule()
Definition: LTO.cpp:505
MapVector.h
llvm::irsymtab::Symbol::canBeOmittedFromSymbolTable
bool canBeOmittedFromSymbolTable() const
Definition: IRSymtab.h:205
Error.h
llvm::lto::InputFile::~InputFile
~InputFile()
llvm::irsymtab::Symbol::isExecutable
bool isExecutable() const
Definition: IRSymtab.h:212
llvm::lto::SymbolResolution::Prevailing
unsigned Prevailing
The linker has chosen this definition of the symbol.
Definition: LTO.h:428
llvm::RemarksHotnessThreshold
cl::opt< Optional< uint64_t >, false, remarks::HotnessThresholdParser > RemarksHotnessThreshold("lto-pass-remarks-hotness-threshold", cl::desc("Minimum profile count required for an " "optimization remark to be output." " Use 'auto' to apply the threshold from profile summary."), cl::value_desc("uint or 'auto'"), cl::init(0), cl::Hidden)
Definition: ThinLTOCodeGenerator.cpp:85
llvm::irsymtab::Symbol::getSectionName
StringRef getSectionName() const
Definition: IRSymtab.h:231
llvm::lto::Config
LTO configuration.
Definition: Config.h:40
llvm::AMDGPU::Exp::Target
Target
Definition: SIDefines.h:742
llvm::Optional
Definition: APInt.h:33
llvm::MapVector< StringRef, BitcodeModule >
llvm::RemarksWithHotness
cl::opt< bool > RemarksWithHotness("lto-pass-remarks-with-hotness", cl::desc("With PGO, include profile count in optimization remarks"), cl::Hidden)
Definition: ThinLTOCodeGenerator.cpp:83
llvm::lto::setupLLVMOptimizationRemarks
Expected< std::unique_ptr< ToolOutputFile > > setupLLVMOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename, StringRef RemarksPasses, StringRef RemarksFormat, bool RemarksWithHotness, Optional< uint64_t > RemarksHotnessThreshold=0, int Count=-1)
Setup optimization remarks.
Definition: LTO.cpp:1574
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::thinLTOResolvePrevailingInIndex
void thinLTOResolvePrevailingInIndex(const lto::Config &C, ModuleSummaryIndex &Index, function_ref< bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing, function_ref< void(StringRef, GlobalValue::GUID, GlobalValue::LinkageTypes)> recordNewLinkage, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols)
Resolve linkage for prevailing symbols in the Index.
Definition: LTO.cpp:399
llvm::GlobalValue::LinkageTypes
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:47
llvm::MemoryBufferRef
Definition: MemoryBufferRef.h:22
llvm::lto::setupStatsFile
Expected< std::unique_ptr< ToolOutputFile > > setupStatsFile(StringRef StatsFilename)
Setups the output file for saving statistics.
Definition: LTO.cpp:1599
ModuleSummaryIndex.h
llvm::lto::getThinLTOOutputFile
std::string getThinLTOOutputFile(const std::string &Path, const std::string &OldPrefix, const std::string &NewPrefix)
Given the original Path to an output file, replace any path prefix matching OldPrefix with NewPrefix.
Definition: LTO.cpp:1314
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
Caching.h
llvm::irsymtab::Symbol::getName
StringRef getName() const
Returns the mangled symbol name.
Definition: IRSymtab.h:182
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::irsymtab::Symbol::getVisibility
GlobalValue::VisibilityTypes getVisibility() const
Definition: IRSymtab.h:194
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:481
llvm::MaybeAlign
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:109
llvm::thinLTOInternalizeAndPromoteInIndex
void thinLTOInternalizeAndPromoteInIndex(ModuleSummaryIndex &Index, function_ref< bool(StringRef, ValueInfo)> isExported, function_ref< bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing)
Update the linkages in the given Index to mark exported values as external and non-exported values as...
Definition: LTO.cpp:459
llvm::lto::LTO::run
Error run(AddStreamFn AddStream, NativeObjectCache Cache=nullptr)
Runs the LTO pipeline.
Definition: LTO.cpp:1000
llvm::lto::SymbolResolution::SymbolResolution
SymbolResolution()
Definition: LTO.h:423
llvm::lto::InputFile::symbols
ArrayRef< Symbol > symbols() const
A range over the symbols in this InputFile.
Definition: LTO.h:159
llvm::lto::InputFile::create
static Expected< std::unique_ptr< InputFile > > create(MemoryBufferRef Object)
Create an InputFile.
Definition: LTO.cpp:472
llvm::irsymtab::Symbol::getComdatIndex
int getComdatIndex() const
Returns the index into the comdat table (see Reader::getComdatTable()), or -1 if not a comdat member.
Definition: IRSymtab.h:190
StringMap.h
llvm::lto::InputFile::Symbol::Symbol
Symbol(const irsymtab::Symbol &S)
Definition: LTO.h:138
llvm::irsymtab::Symbol::isUsed
bool isUsed() const
Definition: IRSymtab.h:202
llvm::lto::LTO::getMaxTasks
unsigned getMaxTasks() const
Returns an upper bound on the number of tasks that the client may expect.
Definition: LTO.cpp:954
llvm::lto::LTO::RegularLTOState::AddedModule::M
std::unique_ptr< Module > M
Definition: LTO.h:300
llvm::RemarksFormat
cl::opt< std::string > RemarksFormat("lto-pass-remarks-format", cl::desc("The format used for serializing remarks (default: YAML)"), cl::value_desc("format"), cl::init("yaml"))
Definition: ThinLTOCodeGenerator.cpp:86
llvm::OutputFileType::Object
@ Object
llvm::irsymtab::Symbol::isUndefined
bool isUndefined() const
Definition: IRSymtab.h:198
IRSymtab.h
llvm::NativeObjectCache
std::function< AddStreamFn(unsigned Task, StringRef Key)> NativeObjectCache
This is the type of a native object cache.
Definition: Caching.h:56
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
uint64_t
llvm::irsymtab::Symbol::getCommonSize
uint64_t getCommonSize() const
Definition: IRSymtab.h:214
llvm::lto::LTO
This class implements a resolution-based interface to LLVM's LTO functionality.
Definition: LTO.h:239
llvm::DenseMap
Definition: DenseMap.h:714
llvm::lto::LTOLLVMContext
A derived class of LLVMContext that initializes itself according to a given Config object.
Definition: Config.h:284
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::lto::LTO::getRuntimeLibcallSymbols
static ArrayRef< const char * > getRuntimeLibcallSymbols()
Static method that returns a list of libcall symbols that can be generated by LTO but might not be vi...
Definition: LTO.cpp:1154
llvm::lto::ThinBackend
std::function< std::unique_ptr< ThinBackendProc >(const Config &C, ModuleSummaryIndex &CombinedIndex, StringMap< GVSummaryMapTy > &ModuleToDefinedGVSummaries, AddStreamFn AddStream, NativeObjectCache Cache)> ThinBackend
A ThinBackend defines what happens after the thin-link phase during ThinLTO.
Definition: LTO.h:197
llvm::irsymtab::Symbol::isIndirect
bool isIndirect() const
Definition: IRSymtab.h:201
llvm::irsymtab::Symbol::isWeak
bool isWeak() const
Definition: IRSymtab.h:199
llvm::lto::LTO::RegularLTOState::CommonResolution
Definition: LTO.h:282
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::lto::InputFile::getSourceFileName
StringRef getSourceFileName() const
Returns the source file path specified at compile time.
Definition: LTO.h:174
llvm::lto::InputFile::getName
StringRef getName() const
Returns the path to the InputFile.
Definition: LTO.cpp:501
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::irsymtab::Symbol::getCommonAlignment
uint32_t getCommonAlignment() const
Definition: IRSymtab.h:219
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::lto::LTO::~LTO
~LTO()
Config.h
llvm::FunctionImporter::ExportSetTy
DenseSet< ValueInfo > ExportSetTy
The set contains an entry for every global value the module exports.
Definition: FunctionImport.h:101
llvm::lto::createWriteIndexesThinBackend
ThinBackend createWriteIndexesThinBackend(std::string OldPrefix, std::string NewPrefix, bool ShouldEmitImportsFiles, raw_fd_ostream *LinkedObjectsFile, IndexWriteCallback OnWrite)
Definition: LTO.cpp:1393
llvm::GVSummaryMapTy
DenseMap< GlobalValue::GUID, GlobalValueSummary * > GVSummaryMapTy
Map of global value GUID to its summary, used to identify values defined in a particular module,...
Definition: ModuleSummaryIndex.h:1046
llvm::FunctionImporter::ImportMapTy
StringMap< FunctionsToImportTy > ImportMapTy
The map contains an entry for every module to import from, the key being the module identifier to pas...
Definition: FunctionImport.h:98
llvm::lto::LTO::RegularLTOState::CommonResolution::Align
MaybeAlign Align
Definition: LTO.h:284
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::raw_fd_ostream
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:443
llvm::AddStreamFn
std::function< std::unique_ptr< NativeObjectStream >(unsigned Task)> AddStreamFn
This type defines the callback to add a native object that is generated on the fly.
Definition: Caching.h:41
llvm::irsymtab::Symbol
This represents a symbol that has been read from a storage::Symbol and possibly a storage::Uncommon.
Definition: IRSymtab.h:170
llvm::DenseMapBase::empty
LLVM_NODISCARD bool empty() const
Definition: DenseMap.h:97
llvm::lto::LTO::RegularLTOState::AddedModule
Definition: LTO.h:299
llvm::lto::LTO::RegularLTOState::AddedModule::Keep
std::vector< GlobalValue * > Keep
Definition: LTO.h:301
llvm::lto::LTO::LTO
LTO(Config Conf, ThinBackend Backend=nullptr, unsigned ParallelCodeGenParallelismLevel=1)
Create an LTO object.
Definition: LTO.cpp:523
llvm::lto::InputFile::getDependentLibraries
ArrayRef< StringRef > getDependentLibraries() const
Returns dependent library specifiers from the input file.
Definition: LTO.h:165
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::lto::SymbolResolution::FinalDefinitionInLinkageUnit
unsigned FinalDefinitionInLinkageUnit
The definition of this symbol is unpreemptable at runtime and is known to be in this linkage unit.
Definition: LTO.h:432
llvm::lto::IndexWriteCallback
std::function< void(const std::string &)> IndexWriteCallback
This ThinBackend writes individual module indexes to files, instead of running the individual backend...
Definition: LTO.h:216
llvm::lto::InputFile::getCOFFLinkerOpts
StringRef getCOFFLinkerOpts() const
Returns linker options specified in the input file.
Definition: LTO.h:162
llvm::lto::SymbolResolution
The resolution for a symbol.
Definition: LTO.h:422
llvm::lto::SymbolResolution::VisibleToRegularObj
unsigned VisibleToRegularObj
The definition of this symbol is visible outside of the LTO unit.
Definition: LTO.h:435
llvm::lto::generateModulesOrdering
std::vector< int > generateModulesOrdering(ArrayRef< BitcodeModule * > R)
Produces a container ordering for optimal multi-threaded processing.
Definition: LTO.cpp:1618
llvm::ModuleSummaryIndex
Class to hold module path string table and global value map, and encapsulate methods for operating on...
Definition: ModuleSummaryIndex.h:1078
llvm::irsymtab::Symbol::isTLS
bool isTLS() const
Definition: IRSymtab.h:203
llvm::lto::createInProcessThinBackend
ThinBackend createInProcessThinBackend(ThreadPoolStrategy Parallelism)
This ThinBackend runs the individual backend jobs in-process.
Definition: LTO.cpp:1301
llvm::lto::LTO::RegularLTOState::CommonResolution::Prevailing
bool Prevailing
Record if at least one instance of the common was marked as prevailing.
Definition: LTO.h:286
thread.h
llvm::BitcodeModule
Represents a module in a bitcode file.
Definition: BitcodeReader.h:60
llvm::lto::LTO::add
Error add(std::unique_ptr< InputFile > Obj, ArrayRef< SymbolResolution > Res)
Add an input file to the LTO link, using the provided symbol resolutions.
Definition: LTO.cpp:613
BitcodeReader.h
llvm::lto::SymbolResolution::ExportDynamic
unsigned ExportDynamic
The symbol was exported dynamically, and therefore could be referenced by a shared library not visibl...
Definition: LTO.h:439
llvm::irsymtab::storage::Symbol
Contains the information needed by linkers for symbol resolution, as well as by the LTO implementatio...
Definition: IRSymtab.h:91
FunctionAttrs.h
llvm::lto::SymbolResolution::LinkerRedefined
unsigned LinkerRedefined
Linker redefined version of the symbol which appeared in -wrap or -defsym linker option.
Definition: LTO.h:443
llvm::irsymtab::Symbol::isCommon
bool isCommon() const
Definition: IRSymtab.h:200
llvm::lto::InputFile
An input file.
Definition: LTO.h:106
llvm::lto::InputFile::getComdatTable
ArrayRef< std::pair< StringRef, Comdat::SelectionKind > > getComdatTable() const
Definition: LTO.h:177