37class raw_pwrite_stream;
47 const lto::Config &
C, ModuleSummaryIndex &
Index,
52 const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols);
58 ModuleSummaryIndex &
Index,
59 function_ref<
bool(StringRef, ValueInfo)> isExported,
67 SmallString<40> &Key,
const lto::Config &Conf,
68 const ModuleSummaryIndex &
Index, StringRef ModuleID,
71 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
73 const std::set<GlobalValue::GUID> &CfiFunctionDefs = {},
74 const std::set<GlobalValue::GUID> &CfiFunctionDecls = {});
93Expected<std::unique_ptr<ToolOutputFile>>
106struct SymbolResolution;
107class ThinBackendProc;
120 std::vector<BitcodeModule> Mods;
122 std::vector<Symbol> Symbols;
125 std::vector<std::pair<size_t, size_t>> ModuleSymIndices;
127 StringRef TargetTriple, SourceFileName, COFFLinkerOpts;
128 std::vector<StringRef> DependentLibraries;
129 std::vector<std::pair<StringRef, Comdat::SelectionKind>> ComdatTable;
191 const auto &Indices = ModuleSymIndices[
I];
192 return {Symbols.data() + Indices.first, Symbols.data() + Indices.second};
199using ThinBackend = std::function<std::unique_ptr<ThinBackendProc>(
215 bool ShouldEmitIndexFiles =
false,
216 bool ShouldEmitImportsFiles =
false);
234 std::string NewPrefix,
235 std::string NativeObjectPrefix,
236 bool ShouldEmitImportsFiles,
278 unsigned ParallelCodeGenParallelismLevel = 1,
309 struct RegularLTOState {
310 RegularLTOState(
unsigned ParallelCodeGenParallelismLevel,
318 std::map<std::string, CommonResolution> Commons;
320 unsigned ParallelCodeGenParallelismLevel;
322 std::unique_ptr<Module> CombinedModule;
323 std::unique_ptr<IRMover> Mover;
330 std::unique_ptr<Module>
M;
331 std::vector<GlobalValue *>
Keep;
333 std::vector<AddedModule> ModsWithSummaries;
334 bool EmptyCombinedModule =
true;
339 struct ThinLTOState {
347 std::optional<ModuleMapType> ModulesToCompile;
358 struct GlobalResolution {
365 bool VisibleOutsideSummary =
false;
369 bool ExportDynamic =
false;
371 bool UnnamedAddr =
true;
374 bool Prevailing =
false;
379 bool isPrevailingIRSymbol()
const {
return Prevailing && !IRName.empty(); }
392 unsigned Partition = Unknown;
411 std::optional<StringMap<GlobalResolution>> GlobalResolutions;
413 void addModuleToGlobalRes(ArrayRef<InputFile::Symbol> Syms,
414 ArrayRef<SymbolResolution> Res,
unsigned Partition,
421 Error addModule(InputFile &Input,
unsigned ModI,
422 const SymbolResolution *&ResI,
const SymbolResolution *ResE);
424 Expected<RegularLTOState::AddedModule>
425 addRegularLTO(BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
426 const SymbolResolution *&ResI,
const SymbolResolution *ResE);
427 Error linkRegularLTO(RegularLTOState::AddedModule
Mod,
428 bool LivenessFromIndex);
430 Error addThinLTO(BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
431 const SymbolResolution *&ResI,
const SymbolResolution *ResE);
435 const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols);
437 Error checkPartiallySplit();
439 mutable bool CalledGetMaxTasks =
false;
445 std::optional<bool> EnableSplitLTOUnit;
449 DenseSet<GlobalValue::GUID> DynamicExportSymbols;
452 std::unique_ptr<ToolOutputFile> DiagnosticOutputFile;
This file defines the StringMap class.
Provides passes for computing function attributes based on interprocedural analyses.
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),...
Represents a module in a bitcode file.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
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.
LinkageTypes
An enumeration for the kinds of linkage for global values.
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.
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.
This class implements a resolution-based interface to LLVM's LTO functionality.
Error add(std::unique_ptr< InputFile > Obj, ArrayRef< SymbolResolution > Res)
Add an input file to the LTO link, using the provided symbol resolutions.
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...
LTOKind
Unified LTO modes.
@ LTOK_UnifiedRegular
Regular LTO, with Unified LTO enabled.
@ LTOK_Default
Any LTO mode without Unified LTO. The default mode.
@ LTOK_UnifiedThin
ThinLTO, with Unified LTO enabled.
Error run(AddStreamFn AddStream, FileCache Cache=nullptr)
Runs the LTO pipeline.
unsigned getMaxTasks() const
Returns an upper bound on the number of tasks that the client may expect.
A raw_ostream that writes to a file descriptor.
@ C
The default llvm calling convention, compatible with C.
ThinBackend createInProcessThinBackend(ThreadPoolStrategy Parallelism, IndexWriteCallback OnWrite=nullptr, bool ShouldEmitIndexFiles=false, bool ShouldEmitImportsFiles=false)
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.
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.
std::function< void(const std::string &)> IndexWriteCallback
This ThinBackend runs the individual backend jobs in-process.
StringLiteral getThinLTODefaultCPU(const Triple &TheTriple)
Expected< std::unique_ptr< ToolOutputFile > > setupStatsFile(StringRef StatsFilename)
Setups the output file for saving statistics.
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...
std::vector< int > generateModulesOrdering(ArrayRef< BitcodeModule * > R)
Produces a container ordering for optimal multi-threaded processing.
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.
void updateMemProfAttributes(Module &Mod, const ModuleSummaryIndex &Index)
Updates MemProf attributes (and metadata) based on whether the index has recorded that we are linking...
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"))
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.
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...
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 ...
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.
@ 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::function< Expected< AddStreamFn >(unsigned Task, StringRef Key, const Twine &ModuleName)> FileCache
This is the type of a file cache.
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.
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...
Contains the information needed by linkers for symbol resolution, as well as by the LTO implementatio...
A derived class of LLVMContext that initializes itself according to a given Config object.
std::vector< GlobalValue * > Keep
std::unique_ptr< Module > M
bool Prevailing
Record if at least one instance of the common was marked as prevailing.
The resolution for a symbol.
unsigned FinalDefinitionInLinkageUnit
The definition of this symbol is unpreemptable at runtime and is known to be in this linkage unit.
unsigned ExportDynamic
The symbol was exported dynamically, and therefore could be referenced by a shared library not visibl...
unsigned Prevailing
The linker has chosen this definition of the symbol.
unsigned LinkerRedefined
Linker redefined version of the symbol which appeared in -wrap or -defsym linker option.
unsigned VisibleToRegularObj
The definition of this symbol is visible outside of the LTO unit.