LLVM 20.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"
25#include "llvm/Support/Error.h"
26#include "llvm/Support/thread.h"
29
30namespace llvm {
31
32class Error;
33class IRMover;
34class LLVMContext;
35class MemoryBufferRef;
36class Module;
37class raw_pwrite_stream;
38class ToolOutputFile;
39
40/// Resolve linkage for prevailing symbols in the \p Index. Linkage changes
41/// recorded in the index and the ThinLTO backends must apply the changes to
42/// the module via thinLTOFinalizeInModule.
43///
44/// This is done for correctness (if value exported, ensure we always
45/// emit a copy), and compile-time optimization (allow drop of duplicates).
47 const lto::Config &C, ModuleSummaryIndex &Index,
48 function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
49 isPrevailing,
50 function_ref<void(StringRef, GlobalValue::GUID, GlobalValue::LinkageTypes)>
51 recordNewLinkage,
52 const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols);
53
54/// Update the linkages in the given \p Index to mark exported values
55/// as external and non-exported values as internal. The ThinLTO backends
56/// must apply the changes to the Module via thinLTOInternalizeModule.
58 ModuleSummaryIndex &Index,
59 function_ref<bool(StringRef, ValueInfo)> isExported,
60 function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
61 isPrevailing);
62
63/// Computes a unique hash for the Module considering the current list of
64/// export/import and other global analysis results.
65std::string computeLTOCacheKey(
66 const lto::Config &Conf, const ModuleSummaryIndex &Index,
67 StringRef ModuleID, const FunctionImporter::ImportMapTy &ImportList,
68 const FunctionImporter::ExportSetTy &ExportList,
69 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
70 const GVSummaryMapTy &DefinedGlobals,
71 const DenseSet<GlobalValue::GUID> &CfiFunctionDefs = {},
72 const DenseSet<GlobalValue::GUID> &CfiFunctionDecls = {});
73
74namespace lto {
75
76StringLiteral getThinLTODefaultCPU(const Triple &TheTriple);
77
78/// Given the original \p Path to an output file, replace any path
79/// prefix matching \p OldPrefix with \p NewPrefix. Also, create the
80/// resulting directory if it does not yet exist.
81std::string getThinLTOOutputFile(StringRef Path, StringRef OldPrefix,
82 StringRef NewPrefix);
83
84/// Setup optimization remarks.
85Expected<std::unique_ptr<ToolOutputFile>> setupLLVMOptimizationRemarks(
86 LLVMContext &Context, StringRef RemarksFilename, StringRef RemarksPasses,
87 StringRef RemarksFormat, bool RemarksWithHotness,
88 std::optional<uint64_t> RemarksHotnessThreshold = 0, int Count = -1);
89
90/// Setups the output file for saving statistics.
91Expected<std::unique_ptr<ToolOutputFile>>
92setupStatsFile(StringRef StatsFilename);
93
94/// Produces a container ordering for optimal multi-threaded processing. Returns
95/// ordered indices to elements in the input array.
96std::vector<int> generateModulesOrdering(ArrayRef<BitcodeModule *> R);
97
98/// Updates MemProf attributes (and metadata) based on whether the index
99/// has recorded that we are linking with allocation libraries containing
100/// the necessary APIs for downstream transformations.
101void updateMemProfAttributes(Module &Mod, const ModuleSummaryIndex &Index);
102
103class LTO;
104struct SymbolResolution;
105class ThinBackendProc;
106
107/// An input file. This is a symbol table wrapper that only exposes the
108/// information that an LTO client should need in order to do symbol resolution.
110public:
111 class Symbol;
112
113private:
114 // FIXME: Remove LTO class friendship once we have bitcode symbol tables.
115 friend LTO;
116 InputFile() = default;
117
118 std::vector<BitcodeModule> Mods;
120 std::vector<Symbol> Symbols;
121
122 // [begin, end) for each module
123 std::vector<std::pair<size_t, size_t>> ModuleSymIndices;
124
125 StringRef TargetTriple, SourceFileName, COFFLinkerOpts;
126 std::vector<StringRef> DependentLibraries;
127 std::vector<std::pair<StringRef, Comdat::SelectionKind>> ComdatTable;
128
129public:
131
132 /// Create an InputFile.
134
135 /// The purpose of this class is to only expose the symbol information that an
136 /// LTO client should need in order to do symbol resolution.
138 friend LTO;
139
140 public:
141 Symbol(const irsymtab::Symbol &S) : irsymtab::Symbol(S) {}
142
159 };
160
161 /// A range over the symbols in this InputFile.
162 ArrayRef<Symbol> symbols() const { return Symbols; }
163
164 /// Returns linker options specified in the input file.
165 StringRef getCOFFLinkerOpts() const { return COFFLinkerOpts; }
166
167 /// Returns dependent library specifiers from the input file.
168 ArrayRef<StringRef> getDependentLibraries() const { return DependentLibraries; }
169
170 /// Returns the path to the InputFile.
171 StringRef getName() const;
172
173 /// Returns the input file's target triple.
174 StringRef getTargetTriple() const { return TargetTriple; }
175
176 /// Returns the source file path specified at compile time.
177 StringRef getSourceFileName() const { return SourceFileName; }
178
179 // Returns a table with all the comdats used by this file.
181 return ComdatTable;
182 }
183
184 // Returns the only BitcodeModule from InputFile.
186
187private:
188 ArrayRef<Symbol> module_symbols(unsigned I) const {
189 const auto &Indices = ModuleSymIndices[I];
190 return {Symbols.data() + Indices.first, Symbols.data() + Indices.second};
191 }
192};
193
194/// A ThinBackend defines what happens after the thin-link phase during ThinLTO.
195/// The details of this type definition aren't important; clients can only
196/// create a ThinBackend using one of the create*ThinBackend() functions below.
197using ThinBackend = std::function<std::unique_ptr<ThinBackendProc>(
198 const Config &C, ModuleSummaryIndex &CombinedIndex,
199 DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
200 AddStreamFn AddStream, FileCache Cache)>;
201
202/// This ThinBackend runs the individual backend jobs in-process.
203/// The default value means to use one job per hardware core (not hyper-thread).
204/// OnWrite is callback which receives module identifier and notifies LTO user
205/// that index file for the module (and optionally imports file) was created.
206/// ShouldEmitIndexFiles being true will write sharded ThinLTO index files
207/// to the same path as the input module, with suffix ".thinlto.bc"
208/// ShouldEmitImportsFiles is true it also writes a list of imported files to a
209/// similar path with ".imports" appended instead.
210using IndexWriteCallback = std::function<void(const std::string &)>;
212 IndexWriteCallback OnWrite = nullptr,
213 bool ShouldEmitIndexFiles = false,
214 bool ShouldEmitImportsFiles = false);
215
216/// This ThinBackend writes individual module indexes to files, instead of
217/// running the individual backend jobs. This backend is for distributed builds
218/// where separate processes will invoke the real backends.
219///
220/// To find the path to write the index to, the backend checks if the path has a
221/// prefix of OldPrefix; if so, it replaces that prefix with NewPrefix. It then
222/// appends ".thinlto.bc" and writes the index to that path. If
223/// ShouldEmitImportsFiles is true it also writes a list of imported files to a
224/// similar path with ".imports" appended instead.
225/// LinkedObjectsFile is an output stream to write the list of object files for
226/// the final ThinLTO linking. Can be nullptr. If LinkedObjectsFile is not
227/// nullptr and NativeObjectPrefix is not empty then it replaces the prefix of
228/// the objects with NativeObjectPrefix instead of NewPrefix. OnWrite is
229/// callback which receives module identifier and notifies LTO user that index
230/// file for the module (and optionally imports file) was created.
231ThinBackend createWriteIndexesThinBackend(std::string OldPrefix,
232 std::string NewPrefix,
233 std::string NativeObjectPrefix,
234 bool ShouldEmitImportsFiles,
235 raw_fd_ostream *LinkedObjectsFile,
236 IndexWriteCallback OnWrite);
237
238/// This class implements a resolution-based interface to LLVM's LTO
239/// functionality. It supports regular LTO, parallel LTO code generation and
240/// ThinLTO. You can use it from a linker in the following way:
241/// - Set hooks and code generation options (see lto::Config struct defined in
242/// Config.h), and use the lto::Config object to create an lto::LTO object.
243/// - Create lto::InputFile objects using lto::InputFile::create(), then use
244/// the symbols() function to enumerate its symbols and compute a resolution
245/// for each symbol (see SymbolResolution below).
246/// - After the linker has visited each input file (and each regular object
247/// file) and computed a resolution for each symbol, take each lto::InputFile
248/// and pass it and an array of symbol resolutions to the add() function.
249/// - Call the getMaxTasks() function to get an upper bound on the number of
250/// native object files that LTO may add to the link.
251/// - Call the run() function. This function will use the supplied AddStream
252/// and Cache functions to add up to getMaxTasks() native object files to
253/// the link.
254class LTO {
255 friend InputFile;
256
257public:
258 /// Unified LTO modes
259 enum LTOKind {
260 /// Any LTO mode without Unified LTO. The default mode.
262
263 /// Regular LTO, with Unified LTO enabled.
265
266 /// ThinLTO, with Unified LTO enabled.
268 };
269
270 /// Create an LTO object. A default constructed LTO object has a reasonable
271 /// production configuration, but you can customize it by passing arguments to
272 /// this constructor.
273 /// FIXME: We do currently require the DiagHandler field to be set in Conf.
274 /// Until that is fixed, a Config argument is required.
275 LTO(Config Conf, ThinBackend Backend = nullptr,
276 unsigned ParallelCodeGenParallelismLevel = 1,
277 LTOKind LTOMode = LTOK_Default);
279
280 /// Add an input file to the LTO link, using the provided symbol resolutions.
281 /// The symbol resolutions must appear in the enumeration order given by
282 /// InputFile::symbols().
283 Error add(std::unique_ptr<InputFile> Obj, ArrayRef<SymbolResolution> Res);
284
285 /// Returns an upper bound on the number of tasks that the client may expect.
286 /// This may only be called after all IR object files have been added. For a
287 /// full description of tasks see LTOBackend.h.
288 unsigned getMaxTasks() const;
289
290 /// Runs the LTO pipeline. This function calls the supplied AddStream
291 /// function to add native object files to the link.
292 ///
293 /// The Cache parameter is optional. If supplied, it will be used to cache
294 /// native object files and add them to the link.
295 ///
296 /// The client will receive at most one callback (via either AddStream or
297 /// Cache) for each task identifier.
298 Error run(AddStreamFn AddStream, FileCache Cache = nullptr);
299
300 /// Static method that returns a list of libcall symbols that can be generated
301 /// by LTO but might not be visible from bitcode symbol table.
303
304private:
305 Config Conf;
306
307 struct RegularLTOState {
308 RegularLTOState(unsigned ParallelCodeGenParallelismLevel,
309 const Config &Conf);
313 /// Record if at least one instance of the common was marked as prevailing
314 bool Prevailing = false;
315 };
316 std::map<std::string, CommonResolution> Commons;
317
318 unsigned ParallelCodeGenParallelismLevel;
319 LTOLLVMContext Ctx;
320 std::unique_ptr<Module> CombinedModule;
321 std::unique_ptr<IRMover> Mover;
322
323 // This stores the information about a regular LTO module that we have added
324 // to the link. It will either be linked immediately (for modules without
325 // summaries) or after summary-based dead stripping (for modules with
326 // summaries).
327 struct AddedModule {
328 std::unique_ptr<Module> M;
329 std::vector<GlobalValue *> Keep;
330 };
331 std::vector<AddedModule> ModsWithSummaries;
332 bool EmptyCombinedModule = true;
333 } RegularLTO;
334
336
337 struct ThinLTOState {
338 ThinLTOState(ThinBackend Backend);
339
340 ThinBackend Backend;
341 ModuleSummaryIndex CombinedIndex;
342 // The full set of bitcode modules in input order.
343 ModuleMapType ModuleMap;
344 // The bitcode modules to compile, if specified by the LTO Config.
345 std::optional<ModuleMapType> ModulesToCompile;
346 DenseMap<GlobalValue::GUID, StringRef> PrevailingModuleForGUID;
347 } ThinLTO;
348
349 // The global resolution for a particular (mangled) symbol name. This is in
350 // particular necessary to track whether each symbol can be internalized.
351 // Because any input file may introduce a new cross-partition reference, we
352 // cannot make any final internalization decisions until all input files have
353 // been added and the client has called run(). During run() we apply
354 // internalization decisions either directly to the module (for regular LTO)
355 // or to the combined index (for ThinLTO).
356 struct GlobalResolution {
357 /// The unmangled name of the global.
358 std::string IRName;
359
360 /// Keep track if the symbol is visible outside of a module with a summary
361 /// (i.e. in either a regular object or a regular LTO module without a
362 /// summary).
363 bool VisibleOutsideSummary = false;
364
365 /// The symbol was exported dynamically, and therefore could be referenced
366 /// by a shared library not visible to the linker.
367 bool ExportDynamic = false;
368
369 bool UnnamedAddr = true;
370
371 /// True if module contains the prevailing definition.
372 bool Prevailing = false;
373
374 /// Returns true if module contains the prevailing definition and symbol is
375 /// an IR symbol. For example when module-level inline asm block is used,
376 /// symbol can be prevailing in module but have no IR name.
377 bool isPrevailingIRSymbol() const { return Prevailing && !IRName.empty(); }
378
379 /// This field keeps track of the partition number of this global. The
380 /// regular LTO object is partition 0, while each ThinLTO object has its own
381 /// partition number from 1 onwards.
382 ///
383 /// Any global that is defined or used by more than one partition, or that
384 /// is referenced externally, may not be internalized.
385 ///
386 /// Partitions generally have a one-to-one correspondence with tasks, except
387 /// that we use partition 0 for all parallel LTO code generation partitions.
388 /// Any partitioning of the combined LTO object is done internally by the
389 /// LTO backend.
390 unsigned Partition = Unknown;
391
392 /// Special partition numbers.
393 enum : unsigned {
394 /// A partition number has not yet been assigned to this global.
395 Unknown = -1u,
396
397 /// This global is either used by more than one partition or has an
398 /// external reference, and therefore cannot be internalized.
399 External = -2u,
400
401 /// The RegularLTO partition
402 RegularLTO = 0,
403 };
404 };
405
406 // Global mapping from mangled symbol names to resolutions.
407 // Make this an optional to guard against accessing after it has been reset
408 // (to reduce memory after we're done with it).
409 std::optional<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, FileCache Cache,
433 const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols);
434
435 Error checkPartiallySplit();
436
437 mutable bool CalledGetMaxTasks = false;
438
439 // LTO mode when using Unified LTO.
440 LTOKind LTOMode;
441
442 // Use Optional to distinguish false from not yet initialized.
443 std::optional<bool> EnableSplitLTOUnit;
444
445 // Identify symbols exported dynamically, and that therefore could be
446 // referenced by a shared library not visible to the linker.
447 DenseSet<GlobalValue::GUID> DynamicExportSymbols;
448
449 // Diagnostic optimization remarks file
450 std::unique_ptr<ToolOutputFile> DiagnosticOutputFile;
451};
452
453/// The resolution for a symbol. The linker must provide a SymbolResolution for
454/// each global symbol based on its internal resolution of that symbol.
459
460 /// The linker has chosen this definition of the symbol.
461 unsigned Prevailing : 1;
462
463 /// The definition of this symbol is unpreemptable at runtime and is known to
464 /// be in this linkage unit.
466
467 /// The definition of this symbol is visible outside of the LTO unit.
469
470 /// The symbol was exported dynamically, and therefore could be referenced
471 /// by a shared library not visible to the linker.
472 unsigned ExportDynamic : 1;
473
474 /// Linker redefined version of the symbol which appeared in -wrap or -defsym
475 /// linker option.
476 unsigned LinkerRedefined : 1;
477};
478
479} // namespace lto
480} // namespace llvm
481
482#endif
This file defines the StringMap class.
Provides passes for computing function attributes based on interprocedural analyses.
#define I(x, y, z)
Definition: MD5.cpp:58
Machine Check Debug Module
This file implements a map that provides insertion order iteration.
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Represents a module in a bitcode file.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
Tagged union holding either a T or a Error.
Definition: Error.h:481
DenseMap< StringRef, FunctionsToImportTy > ImportMapTy
The map contains an entry for every module to import from, the key being the module identifier to pas...
DenseSet< ValueInfo > ExportSetTy
The set contains an entry for every global value that the module exports.
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
Definition: GlobalValue.h:587
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:51
Class to hold module path string table and global value map, and encapsulate methods for operating on...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This tells how a thread pool will be used.
Definition: Threading.h:116
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
The purpose of this class is to only expose the symbol information that an LTO client should need in ...
Definition: LTO.h:137
Symbol(const irsymtab::Symbol &S)
Definition: LTO.h:141
An input file.
Definition: LTO.h:109
static Expected< std::unique_ptr< InputFile > > create(MemoryBufferRef Object)
Create an InputFile.
Definition: LTO.cpp:552
ArrayRef< Symbol > symbols() const
A range over the symbols in this InputFile.
Definition: LTO.h:162
StringRef getCOFFLinkerOpts() const
Returns linker options specified in the input file.
Definition: LTO.h:165
ArrayRef< StringRef > getDependentLibraries() const
Returns dependent library specifiers from the input file.
Definition: LTO.h:168
ArrayRef< std::pair< StringRef, Comdat::SelectionKind > > getComdatTable() const
Definition: LTO.h:180
StringRef getTargetTriple() const
Returns the input file's target triple.
Definition: LTO.h:174
StringRef getName() const
Returns the path to the InputFile.
Definition: LTO.cpp:581
BitcodeModule & getSingleBitcodeModule()
Definition: LTO.cpp:585
StringRef getSourceFileName() const
Returns the source file path specified at compile time.
Definition: LTO.h:177
This class implements a resolution-based interface to LLVM's LTO functionality.
Definition: LTO.h:254
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:707
static SmallVector< const char * > getRuntimeLibcallSymbols(const Triple &TT)
Static method that returns a list of libcall symbols that can be generated by LTO but might not be vi...
Definition: LTO.cpp:1361
LTOKind
Unified LTO modes.
Definition: LTO.h:259
@ LTOK_UnifiedRegular
Regular LTO, with Unified LTO enabled.
Definition: LTO.h:264
@ LTOK_Default
Any LTO mode without Unified LTO. The default mode.
Definition: LTO.h:261
@ LTOK_UnifiedThin
ThinLTO, with Unified LTO enabled.
Definition: LTO.h:267
Error run(AddStreamFn AddStream, FileCache Cache=nullptr)
Runs the LTO pipeline.
Definition: LTO.cpp:1140
unsigned getMaxTasks() const
Returns an upper bound on the number of tasks that the client may expect.
Definition: LTO.cpp:1089
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:460
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
ThinBackend createInProcessThinBackend(ThreadPoolStrategy Parallelism, IndexWriteCallback OnWrite=nullptr, bool ShouldEmitIndexFiles=false, bool ShouldEmitImportsFiles=false)
Definition: LTO.cpp:1561
std::string getThinLTOOutputFile(StringRef Path, StringRef OldPrefix, StringRef NewPrefix)
Given the original Path to an output file, replace any path prefix matching OldPrefix with NewPrefix.
Definition: LTO.cpp:1594
std::function< std::unique_ptr< ThinBackendProc >(const Config &C, ModuleSummaryIndex &CombinedIndex, DenseMap< StringRef, GVSummaryMapTy > &ModuleToDefinedGVSummaries, AddStreamFn AddStream, FileCache Cache)> ThinBackend
A ThinBackend defines what happens after the thin-link phase during ThinLTO.
Definition: LTO.h:200
std::function< void(const std::string &)> IndexWriteCallback
This ThinBackend runs the individual backend jobs in-process.
Definition: LTO.h:210
StringLiteral getThinLTODefaultCPU(const Triple &TheTriple)
Definition: LTO.cpp:1576
Expected< std::unique_ptr< ToolOutputFile > > setupStatsFile(StringRef StatsFilename)
Setups the output file for saving statistics.
Definition: LTO.cpp:1910
ThinBackend createWriteIndexesThinBackend(std::string OldPrefix, std::string NewPrefix, std::string NativeObjectPrefix, bool ShouldEmitImportsFiles, raw_fd_ostream *LinkedObjectsFile, IndexWriteCallback OnWrite)
This ThinBackend writes individual module indexes to files, instead of running the individual backend...
Definition: LTO.cpp:1662
std::vector< int > generateModulesOrdering(ArrayRef< BitcodeModule * > R)
Produces a container ordering for optimal multi-threaded processing.
Definition: LTO.cpp:1929
Expected< std::unique_ptr< ToolOutputFile > > setupLLVMOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename, StringRef RemarksPasses, StringRef RemarksFormat, bool RemarksWithHotness, std::optional< uint64_t > RemarksHotnessThreshold=0, int Count=-1)
Setup optimization remarks.
Definition: LTO.cpp:1885
void updateMemProfAttributes(Module &Mod, const ModuleSummaryIndex &Index)
Updates MemProf attributes (and metadata) based on whether the index has recorded that we are linking...
Definition: LTO.cpp:1198
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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"))
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"))
std::function< Expected< std::unique_ptr< CachedFileStream > >(unsigned Task, const Twine &ModuleName)> AddStreamFn
This type defines the callback to add a file that is generated on the fly.
Definition: Caching.h:42
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:539
cl::opt< bool > RemarksWithHotness("lto-pass-remarks-with-hotness", cl::desc("With PGO, include profile count in optimization remarks"), cl::Hidden)
cl::opt< std::string > RemarksFilename("lto-pass-remarks-output", cl::desc("Output filename for pass remarks"), cl::value_desc("filename"))
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:438
@ Mod
The access may modify the value stored in memory.
cl::opt< std::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)
std::string computeLTOCacheKey(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 DenseSet< GlobalValue::GUID > &CfiFunctionDefs={}, const DenseSet< GlobalValue::GUID > &CfiFunctionDecls={})
Computes a unique hash for the Module considering the current list of export/import and other global ...
Definition: LTO.cpp:92
std::function< Expected< AddStreamFn >(unsigned Task, StringRef Key, const Twine &ModuleName)> FileCache
This is the type of a file cache.
Definition: Caching.h:58
DenseMap< GlobalValue::GUID, GlobalValueSummary * > GVSummaryMapTy
Map of global value GUID to its summary, used to identify values defined in a particular module,...
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
This represents a symbol that has been read from a storage::Symbol and possibly a storage::Uncommon.
Definition: IRSymtab.h:170
StringRef getName() const
Returns the mangled symbol name.
Definition: IRSymtab.h:182
bool canBeOmittedFromSymbolTable() const
Definition: IRSymtab.h:205
bool isUsed() const
Definition: IRSymtab.h:202
StringRef getSectionName() const
Definition: IRSymtab.h:231
bool isTLS() const
Definition: IRSymtab.h:203
bool isWeak() const
Definition: IRSymtab.h:199
bool isIndirect() const
Definition: IRSymtab.h:201
bool isCommon() const
Definition: IRSymtab.h:200
uint32_t getCommonAlignment() const
Definition: IRSymtab.h:219
bool isExecutable() const
Definition: IRSymtab.h:212
uint64_t getCommonSize() const
Definition: IRSymtab.h:214
int getComdatIndex() const
Returns the index into the comdat table (see Reader::getComdatTable()), or -1 if not a comdat member.
Definition: IRSymtab.h:190
GlobalValue::VisibilityTypes getVisibility() const
Definition: IRSymtab.h:194
bool isUndefined() const
Definition: IRSymtab.h:198
StringRef getIRName() const
Returns the unmangled symbol name, or the empty string if this is not an IR symbol.
Definition: IRSymtab.h:186
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
Contains the information needed by linkers for symbol resolution, as well as by the LTO implementatio...
Definition: IRSymtab.h:91
LTO configuration.
Definition: Config.h:41
A derived class of LLVMContext that initializes itself according to a given Config object.
Definition: Config.h:294
std::vector< GlobalValue * > Keep
Definition: LTO.h:329
std::unique_ptr< Module > M
Definition: LTO.h:328
bool Prevailing
Record if at least one instance of the common was marked as prevailing.
Definition: LTO.h:314
The resolution for a symbol.
Definition: LTO.h:455
unsigned FinalDefinitionInLinkageUnit
The definition of this symbol is unpreemptable at runtime and is known to be in this linkage unit.
Definition: LTO.h:465
unsigned ExportDynamic
The symbol was exported dynamically, and therefore could be referenced by a shared library not visibl...
Definition: LTO.h:472
unsigned Prevailing
The linker has chosen this definition of the symbol.
Definition: LTO.h:461
unsigned LinkerRedefined
Linker redefined version of the symbol which appeared in -wrap or -defsym linker option.
Definition: LTO.h:476
unsigned VisibleToRegularObj
The definition of this symbol is visible outside of the LTO unit.
Definition: LTO.h:468