LLVM: include/llvm/LTO/LTO.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef LLVM_LTO_LTO_H
16#define LLVM_LTO_LTO_H
17
20#include
21
35
36namespace llvm {
37
45
46
47
48
49
50
51
55 isPrevailing,
57 recordNewLinkage,
59
60
61
62
67 isPrevailing);
68
69
70
75 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
79
80
83
84namespace lto {
85
87
88
89
90
92 StringRef NewPrefix);
93
94
99
100
101LLVM_ABI Expected<std::unique_ptr>
103
104
105
107
108class LTO;
110
111
112
113class InputFile {
114public:
116
117private:
118
119 friend LTO;
120 InputFile() = default;
121
122 std::vector Mods;
124 std::vector Symbols;
125
126
127 std::vector<std::pair<size_t, size_t>> ModuleSymIndices;
128
129 StringRef TargetTriple, SourceFileName, COFFLinkerOpts;
130 std::vector DependentLibraries;
131 std::vector<std::pair<StringRef, Comdat::SelectionKind>> ComdatTable;
132
133public:
135
136
139
140
141
144
145 public:
147
164 };
165
166
168
169
171
172
174
175
177
178
180
181
183
184
186 return ComdatTable;
187 }
188
189
191
192private:
194 const auto &Indices = ModuleSymIndices[I];
195 return {Symbols.data() + Indices.first, Symbols.data() + Indices.second};
196 }
197};
198
200
202
203
205protected:
214
215public:
225
227 virtual void setup(unsigned ThinLTONumTasks, unsigned ThinLTOTaskOffset,
233 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
238 return std::move(*Err);
240 }
243
244
247 const std::string &NewModulePath) const;
248
249
250
253 const std::string &NewModulePath, StringRef SummaryPath,
254 std::optional<std::reference_wrapper> ImportsFiles)
255 const;
256};
257
258
259
260
261
262
263
268
269
270
271
272
273
278
284 return Func(Conf, CombinedIndex, ModuleToDefinedGVSummaries,
285 std::move(AddStream), std::move(Cache));
286 }
288 bool isValid() const { return static_cast<bool>(Func); }
289
290private:
293};
294
295
296
297
298
299
300
301
302
305 bool ShouldEmitIndexFiles = false, bool ShouldEmitImportsFiles = false);
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
328 bool ShouldEmitIndexFiles, bool ShouldEmitImportsFiles,
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
351 std::string NewPrefix, std::string NativeObjectPrefix,
352 bool ShouldEmitImportsFiles, raw_fd_ostream *LinkedObjectsFile,
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
372 friend InputFile;
373
374public:
375
377
379
380
382
383
385 };
386
387
388
389
390
391
393 unsigned ParallelCodeGenParallelismLevel = 1,
396
397
398
399
402
403
404
405
407
408
409
410
411
412
413
414
415
417
418
419
422
423private:
425
426 struct RegularLTOState {
427 LLVM_ABI RegularLTOState(unsigned ParallelCodeGenParallelismLevel,
435 std::map<std::string, CommonResolution> Commons;
436
437 unsigned ParallelCodeGenParallelismLevel;
439 std::unique_ptr CombinedModule;
440 std::unique_ptr Mover;
441
442
443
444
445
448 std::vector<GlobalValue *> Keep;
449 };
450 std::vector ModsWithSummaries;
451 bool EmptyCombinedModule = true;
452 } RegularLTO;
453
455
456 struct ThinLTOState {
458
461
462 ModuleMapType ModuleMap;
463
464 std::optional ModulesToCompile;
465
467 PrevailingModuleForGUID[GUID] = Module;
468 }
471 auto It = PrevailingModuleForGUID.find(GUID);
472 return It != PrevailingModuleForGUID.end() && It->second == Module;
473 }
474
475 private:
476
477
479 } ThinLTO;
480
481
482
483
484
485
486
487
488 struct GlobalResolution {
489
490 std::string IRName;
491
492
493
494
495 bool VisibleOutsideSummary = false;
496
497
498
499 bool ExportDynamic = false;
500
501 bool UnnamedAddr = true;
502
503
504 bool Prevailing = false;
505
506
507
508
509 bool isPrevailingIRSymbol() const { return Prevailing && !IRName.empty(); }
510
511
512
513
514
515
516
517
518
519
520
521
522 unsigned Partition = Unknown;
523
524
525 enum : unsigned {
526
527 Unknown = -1u,
528
529
530
531 External = -2u,
532
533
534 RegularLTO = 0,
535 };
536 };
537
538
539 std::unique_ptrllvm::BumpPtrAllocator Alloc;
540
541
542 std::unique_ptrllvm::StringSaver GlobalResolutionSymbolSaver;
543
544
545
546
547 std::unique_ptr<llvm::DenseMap<StringRef, GlobalResolution>>
548 GlobalResolutions;
549
550 void releaseGlobalResolutionsMemory();
551
554 bool InSummary);
555
556
557
558
559 Expected<ArrayRef>
562
563 Expected<std::pair<RegularLTOState::AddedModule, ArrayRef>>
568 bool LivenessFromIndex);
569
570 Expected<ArrayRef>
573
576 const DenseSetGlobalValue::GUID &GUIDPreservedSymbols);
577
578 Error checkPartiallySplit();
579
580 mutable bool CalledGetMaxTasks = false;
581
582
584
585
586 std::optional EnableSplitLTOUnit;
587
588
589
590 DenseSetGlobalValue::GUID DynamicExportSymbols;
591
592
593 LLVMRemarkFileHandle DiagnosticOutputFile;
594};
595
596
597
602
603
605
606
607
609
610
612
613
614
616
617
618
620};
621
622}
623}
624
625#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the DenseMap class.
Provides passes for computing function attributes based on interprocedural analyses.
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),...
Represents a module in a bitcode file.
Implements a dense probed hash-table based set.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
The map maintains the list of imports.
DenseSet< ValueInfo > ExportSetTy
The set contains an entry for every global value that the module exports.
Function and variable summary information to aid decisions and implementation of importing.
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
LinkageTypes
An enumeration for the kinds of linkage for global values.
This is an important class for using LLVM in a threaded context.
This class implements a map that also provides access to all stored values in a deterministic order.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
A Module instance is used to store all the information related to an LLVM module.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
This tells how a thread pool will be used.
Triple - Helper class for working with autoconf configuration names.
An efficient, type-erasing, non-owning reference to a callable.
static LLVM_ABI Expected< std::unique_ptr< InputFile > > create(MemoryBufferRef Object)
Create an InputFile.
ArrayRef< Symbol > symbols() const
A range over the symbols in this InputFile.
Definition LTO.h:167
StringRef getCOFFLinkerOpts() const
Returns linker options specified in the input file.
Definition LTO.h:170
ArrayRef< StringRef > getDependentLibraries() const
Returns dependent library specifiers from the input file.
Definition LTO.h:173
ArrayRef< std::pair< StringRef, Comdat::SelectionKind > > getComdatTable() const
Definition LTO.h:185
StringRef getTargetTriple() const
Returns the input file's target triple.
Definition LTO.h:179
LLVM_ABI StringRef getName() const
Returns the path to the InputFile.
LLVM_ABI BitcodeModule & getSingleBitcodeModule()
StringRef getSourceFileName() const
Returns the source file path specified at compile time.
Definition LTO.h:182
This class implements a resolution-based interface to LLVM's LTO functionality.
Definition LTO.h:371
LLVM_ABI LTO(Config Conf, ThinBackend Backend={}, unsigned ParallelCodeGenParallelismLevel=1, LTOKind LTOMode=LTOK_Default)
Create an LTO object.
LLVM_ABI Error add(std::unique_ptr< InputFile > Obj, ArrayRef< SymbolResolution > Res)
Add an input file to the LTO link, using the provided symbol resolutions.
static LLVM_ABI 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...
LTOKind
Unified LTO modes.
Definition LTO.h:376
@ LTOK_UnifiedRegular
Regular LTO, with Unified LTO enabled.
Definition LTO.h:381
@ LTOK_Default
Any LTO mode without Unified LTO. The default mode.
Definition LTO.h:378
@ LTOK_UnifiedThin
ThinLTO, with Unified LTO enabled.
Definition LTO.h:384
LLVM_ABI unsigned getMaxTasks() const
Returns an upper bound on the number of tasks that the client may expect.
LLVM_ABI Error run(AddStreamFn AddStream, FileCache Cache={})
Runs the LTO pipeline.
DefaultThreadPool BackendThreadPool
Definition LTO.h:211
const Config & Conf
Definition LTO.h:206
bool ShouldEmitImportsFiles
Definition LTO.h:210
std::optional< Error > Err
Definition LTO.h:212
virtual bool isSensitiveToInputOrder()
Definition LTO.h:242
unsigned getThreadCount()
Definition LTO.h:241
const DenseMap< StringRef, GVSummaryMapTy > & ModuleToDefinedGVSummaries
Definition LTO.h:208
LLVM_ABI Error emitFiles(const FunctionImporter::ImportMapTy &ImportList, StringRef ModulePath, const std::string &NewModulePath) const
std::mutex ErrMu
Definition LTO.h:213
ThinBackendProc(const Config &Conf, ModuleSummaryIndex &CombinedIndex, const DenseMap< StringRef, GVSummaryMapTy > &ModuleToDefinedGVSummaries, lto::IndexWriteCallback OnWrite, bool ShouldEmitImportsFiles, ThreadPoolStrategy ThinLTOParallelism)
Definition LTO.h:216
virtual Error wait()
Definition LTO.h:235
ModuleSummaryIndex & CombinedIndex
Definition LTO.h:207
virtual void setup(unsigned ThinLTONumTasks, unsigned ThinLTOTaskOffset, Triple Triple)
Definition LTO.h:227
virtual ~ThinBackendProc()=default
virtual Error start(unsigned Task, BitcodeModule BM, const FunctionImporter::ImportMapTy &ImportList, const FunctionImporter::ExportSetTy &ExportList, const std::map< GlobalValue::GUID, GlobalValue::LinkageTypes > &ResolvedODR, MapVector< StringRef, BitcodeModule > &ModuleMap)=0
IndexWriteCallback OnWrite
Definition LTO.h:209
A raw_ostream that writes to a file descriptor.
An abstract base class for streams implementations that also support a pwrite operation.
@ C
The default llvm calling convention, compatible with C.
LLVM_ABI ThinBackend createInProcessThinBackend(ThreadPoolStrategy Parallelism, IndexWriteCallback OnWrite=nullptr, bool ShouldEmitIndexFiles=false, bool ShouldEmitImportsFiles=false)
This ThinBackend runs the individual backend jobs in-process.
LLVM_ABI 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.
LLVM_ABI StringLiteral getThinLTODefaultCPU(const Triple &TheTriple)
LLVM_ABI Expected< std::unique_ptr< ToolOutputFile > > setupStatsFile(StringRef StatsFilename)
Setups the output file for saving statistics.
LLVM_ABI ThinBackend createOutOfProcessThinBackend(ThreadPoolStrategy Parallelism, IndexWriteCallback OnWrite, bool ShouldEmitIndexFiles, bool ShouldEmitImportsFiles, StringRef LinkerOutputFile, StringRef Distributor, ArrayRef< StringRef > DistributorArgs, StringRef RemoteCompiler, ArrayRef< StringRef > RemoteCompilerPrependArgs, ArrayRef< StringRef > RemoteCompilerArgs, bool SaveTemps)
This ThinBackend generates the index shards and then runs the individual backend jobs via an external...
std::function< void(const std::string &)> IndexWriteCallback
Definition LTO.h:199
LLVM_ABI ThinBackend createWriteIndexesThinBackend(ThreadPoolStrategy Parallelism, 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...
LLVM_ABI Expected< LLVMRemarkFileHandle > setupLLVMOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename, StringRef RemarksPasses, StringRef RemarksFormat, bool RemarksWithHotness, std::optional< uint64_t > RemarksHotnessThreshold=0, int Count=-1)
Setup optimization remarks.
LLVM_ABI std::vector< int > generateModulesOrdering(ArrayRef< BitcodeModule * > R)
Produces a container ordering for optimal multi-threaded processing.
llvm::SmallVector< std::string > ImportsFilesContainer
Definition LTO.h:201
std::function< std::unique_ptr< ThinBackendProc >( const Config &C, ModuleSummaryIndex &CombinedIndex, const DenseMap< StringRef, GVSummaryMapTy > &ModuleToDefinedGVSummaries, AddStreamFn AddStream, FileCache Cache)> ThinBackendFunction
This callable defines the behavior of a ThinLTO backend after the thin-link phase.
Definition LTO.h:264
This is an optimization pass for GlobalISel generic memory operations.
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"))
DenseMap< GlobalValue::GUID, GlobalValueSummary * > GVSummaryMapTy
Map of global value GUID to its summary, used to identify values defined in a particular module,...
LLVM_ABI 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...
LLVM_ABI std::string recomputeLTOCacheKey(const std::string &Key, StringRef ExtraID)
Recomputes the LTO cache key for a given key with an extra identifier.
FunctionAddr VTableAddr Count
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"))
LLVM_ABI 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.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
@ Mod
The access may modify the value stored in memory.
SingleThreadExecutor DefaultThreadPool
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
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)
LLVM_ABI 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 ...
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.
Implement std::hash so that hash_code can be used in STL containers.
This struct is a compact representation of a valid (non-zero power of two) alignment.
This type represents a file cache system that manages caching of files.
Struct that holds a reference to a particular GUID in a global value summary.
This represents a symbol that has been read from a storage::Symbol and possibly a storage::Uncommon.
StringRef getName() const
Returns the mangled symbol name.
bool canBeOmittedFromSymbolTable() const
StringRef getSectionName() const
uint32_t getCommonAlignment() const
bool isExecutable() const
uint64_t getCommonSize() const
int getComdatIndex() const
Returns the index into the comdat table (see Reader::getComdatTable()), or -1 if not a comdat member.
GlobalValue::VisibilityTypes getVisibility() const
StringRef getIRName() const
Returns the unmangled symbol name, or the empty string if this is not an IR symbol.
StringRef getCOFFWeakExternalFallback() const
COFF-specific: for weak externals, returns the name of the symbol that is used as a fallback if the w...
The purpose of this struct is to only expose the symbol information that an LTO client should need in...
Definition LTO.h:142
friend LTO
Definition LTO.h:143
Symbol(const irsymtab::Symbol &S)
Definition LTO.h:146
A derived class of LLVMContext that initializes itself according to a given Config object.
std::vector< GlobalValue * > Keep
Definition LTO.h:448
std::unique_ptr< Module > M
Definition LTO.h:447
bool Prevailing
Record if at least one instance of the common was marked as prevailing.
Definition LTO.h:433
Align Alignment
Definition LTO.h:431
uint64_t Size
Definition LTO.h:430
The resolution for a symbol.
Definition LTO.h:598
unsigned FinalDefinitionInLinkageUnit
The definition of this symbol is unpreemptable at runtime and is known to be in this linkage unit.
Definition LTO.h:608
unsigned ExportDynamic
The symbol was exported dynamically, and therefore could be referenced by a shared library not visibl...
Definition LTO.h:615
unsigned Prevailing
The linker has chosen this definition of the symbol.
Definition LTO.h:604
unsigned LinkerRedefined
Linker redefined version of the symbol which appeared in -wrap or -defsym linker option.
Definition LTO.h:619
unsigned VisibleToRegularObj
The definition of this symbol is visible outside of the LTO unit.
Definition LTO.h:611
SymbolResolution()
Definition LTO.h:599
This type defines the behavior following the thin-link phase during ThinLTO.
Definition LTO.h:274
std::unique_ptr< ThinBackendProc > operator()(const Config &Conf, ModuleSummaryIndex &CombinedIndex, const DenseMap< StringRef, GVSummaryMapTy > &ModuleToDefinedGVSummaries, AddStreamFn AddStream, FileCache Cache)
Definition LTO.h:279
bool isValid() const
Definition LTO.h:288
ThreadPoolStrategy getParallelism() const
Definition LTO.h:287
ThinBackend(ThinBackendFunction Func, ThreadPoolStrategy Parallelism)
Definition LTO.h:275