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