15 #ifndef LLVM_LTO_LTO_H 16 #define LLVM_LTO_LTO_H 38 class MemoryBufferRef;
41 class raw_pwrite_stream;
50 ModuleSummaryIndex &
Index,
55 const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols);
61 ModuleSummaryIndex &Index,
62 function_ref<
bool(StringRef, ValueInfo)> isExported,
70 SmallString<40> &
Key,
const lto::Config &Conf,
71 const ModuleSummaryIndex &Index, StringRef ModuleID,
74 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
76 const std::set<GlobalValue::GUID> &CfiFunctionDefs = {},
77 const std::set<GlobalValue::GUID> &CfiFunctionDecls = {});
85 const std::string &OldPrefix,
86 const std::string &NewPrefix);
89 Expected<std::unique_ptr<ToolOutputFile>>
95 Expected<std::unique_ptr<ToolOutputFile>>
99 struct SymbolResolution;
100 class ThinBackendProc;
113 std::vector<BitcodeModule> Mods;
115 std::vector<Symbol> Symbols;
118 std::vector<std::pair<size_t, size_t>> ModuleSymIndices;
120 StringRef TargetTriple, SourceFileName, COFFLinkerOpts;
121 std::vector<StringRef> DependentLibraries;
122 std::vector<StringRef> ComdatTable;
182 const auto &Indices = ModuleSymIndices[
I];
183 return {Symbols.
data() + Indices.first, Symbols.data() + Indices.second};
195 std::unique_ptr<raw_pwrite_stream>
OS;
204 std::function<std::unique_ptr<NativeObjectStream>(
unsigned Task)>;
219 std::function<AddStreamFn(unsigned Task, StringRef Key)>;
224 using ThinBackend = std::function<std::unique_ptr<ThinBackendProc>(
247 std::string NewPrefix,
248 bool ShouldEmitImportsFiles,
278 unsigned ParallelCodeGenParallelismLevel = 1);
289 unsigned getMaxTasks()
const;
308 struct RegularLTOState {
309 RegularLTOState(
unsigned ParallelCodeGenParallelismLevel,
315 bool Prevailing =
false;
317 std::map<std::string, CommonResolution> Commons;
319 unsigned ParallelCodeGenParallelismLevel;
321 std::unique_ptr<Module> CombinedModule;
322 std::unique_ptr<IRMover> Mover;
329 std::unique_ptr<Module>
M;
330 std::vector<GlobalValue *>
Keep;
332 std::vector<AddedModule> ModsWithSummaries;
335 struct ThinLTOState {
351 struct GlobalResolution {
358 bool VisibleOutsideSummary =
false;
360 bool UnnamedAddr =
true;
363 bool Prevailing =
false;
368 bool isPrevailingIRSymbol()
const {
return Prevailing && !IRName.empty(); }
381 unsigned Partition = Unknown;
415 bool LivenessFromIndex);
424 Error checkPartiallySplit();
426 mutable bool CalledGetMaxTasks =
false;
436 : Prevailing(0), FinalDefinitionInLinkageUnit(0), VisibleToRegularObj(0),
437 LinkerRedefined(0) {}
NativeObjectStream(std::unique_ptr< raw_pwrite_stream > OS)
DenseSet< ValueInfo > ExportSetTy
The set contains an entry for every global value the module exports.
StringRef getIRName() const
Returns the unmangled symbol name, or the empty string if this is not an IR symbol.
GlobalValue::VisibilityTypes getVisibility() const
StringRef getCOFFWeakExternalFallback() const
COFF-specific: for weak externals, returns the name of the symbol that is used as a fallback if the w...
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...
unsigned Prevailing
The linker has chosen this definition of the symbol.
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
This class represents lattice values for constants.
cl::opt< bool > RemarksWithHotness("lto-pass-remarks-with-hotness", cl::desc("With PGO, include profile count in optimization remarks"), cl::Hidden)
Contains the information needed by linkers for symbol resolution, as well as by the LTO implementatio...
Implements a dense probed hash-table based set.
unsigned LinkerRedefined
Linker redefined version of the symbol which appeared in -wrap or -defsym linker option.
bool isExecutable() const
The resolution for a symbol.
This class implements a map that also provides access to all stored values in a deterministic order...
std::function< void(const std::string &)> IndexWriteCallback
This ThinBackend writes individual module indexes to files, instead of running the individual backend...
bool canBeOmittedFromSymbolTable() const
ThinBackend createWriteIndexesThinBackend(std::string OldPrefix, std::string NewPrefix, bool ShouldEmitImportsFiles, raw_fd_ostream *LinkedObjectsFile, IndexWriteCallback OnWrite)
StringMap< FunctionsToImportTy > ImportMapTy
The map contains an entry for every module to import from, the key being the module identifier to pas...
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::unique_ptr< raw_pwrite_stream > OS
Represents a module in a bitcode file.
Tagged union holding either a T or a Error.
DenseMap< GlobalValue::GUID, GlobalValueSummary * > GVSummaryMapTy
Map of global value GUID to its summary, used to identify values defined in a particular module...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
This class implements a resolution-based interface to LLVM's LTO functionality.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
StringRef getName() const
Returns the mangled symbol name.
Expected< std::unique_ptr< ToolOutputFile > > setupStatsFile(StringRef StatsFilename)
Setups the output file for saving statistics.
std::unique_ptr< Module > M
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.
uint32_t getCommonAlignment() const
This class wraps an output stream for a native object.
std::function< AddStreamFn(unsigned Task, StringRef Key)> NativeObjectCache
This is the type of a native object cache.
void thinLTOResolvePrevailingInIndex(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.
This represents a symbol that has been read from a storage::Symbol and possibly a storage::Uncommon...
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.
StringRef getSectionName() const
int getComdatIndex() const
Returns the index into the comdat table (see Reader::getComdatTable()), or -1 if not a comdat member...
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
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 ...
static uint64_t add(uint64_t LeftOp, uint64_t RightOp)
The access may modify the value stored in memory.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
LinkageTypes
An enumeration for the kinds of linkage for global values.
ThinBackend createInProcessThinBackend(unsigned ParallelismLevel)
This ThinBackend runs the individual backend jobs in-process.
std::vector< GlobalValue * > Keep
A raw_ostream that writes to a file descriptor.
unsigned VisibleToRegularObj
The definition of this symbol is visible outside of the LTO unit.
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
Expected< std::unique_ptr< ToolOutputFile > > setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename, StringRef RemarksPasses, StringRef RemarksFormat, bool RemarksWithHotness, int Count=-1)
Setup optimization remarks.
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 > RemarksFilename("lto-pass-remarks-output", cl::desc("Output filename for pass remarks"), cl::value_desc("filename"))
Lightweight error class with error context and mandatory checking.
uint64_t getCommonSize() const
A derived class of LLVMContext that initializes itself according to a given Config object...
StringRef - Represent a constant reference to a string, i.e.
unsigned FinalDefinitionInLinkageUnit
The definition of this symbol is unpreemptable at runtime and is known to be in this linkage unit...
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...