16 #ifndef LLVM_LTO_LTO_H 17 #define LLVM_LTO_LTO_H 38 class MemoryBufferRef;
41 class raw_pwrite_stream;
50 ModuleSummaryIndex &
Index,
60 ModuleSummaryIndex &Index,
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 = {});
82 const std::string &OldPrefix,
83 const std::string &NewPrefix);
86 Expected<std::unique_ptr<ToolOutputFile>>
91 struct SymbolResolution;
92 class ThinBackendProc;
105 std::vector<BitcodeModule> Mods;
107 std::vector<Symbol> Symbols;
110 std::vector<std::pair<size_t, size_t>> ModuleSymIndices;
112 StringRef TargetTriple, SourceFileName, COFFLinkerOpts;
113 std::vector<StringRef> ComdatTable;
165 const auto &Indices = ModuleSymIndices[
I];
166 return {Symbols.
data() + Indices.first, Symbols.data() + Indices.second};
178 std::unique_ptr<raw_pwrite_stream>
OS;
186 typedef std::function<std::unique_ptr<NativeObjectStream>(
unsigned Task)>
201 typedef std::function<AddStreamFn(unsigned Task, StringRef Key)>
207 typedef std::function<std::unique_ptr<ThinBackendProc>(
231 std::string NewPrefix,
232 bool ShouldEmitImportsFiles,
262 unsigned ParallelCodeGenParallelismLevel = 1);
273 unsigned getMaxTasks()
const;
288 struct RegularLTOState {
289 RegularLTOState(
unsigned ParallelCodeGenParallelismLevel,
Config &Conf);
294 bool Prevailing =
false;
296 std::map<std::string, CommonResolution> Commons;
298 unsigned ParallelCodeGenParallelismLevel;
300 std::unique_ptr<Module> CombinedModule;
301 std::unique_ptr<IRMover> Mover;
308 std::unique_ptr<Module>
M;
309 std::vector<GlobalValue *>
Keep;
311 std::vector<AddedModule> ModsWithSummaries;
314 struct ThinLTOState {
330 struct GlobalResolution {
337 bool VisibleOutsideSummary =
false;
339 bool UnnamedAddr =
true;
342 bool Prevailing =
false;
347 bool isPrevailingIRSymbol()
const {
return Prevailing && !IRName.empty(); }
360 unsigned Partition = Unknown;
394 bool LivenessFromIndex);
402 mutable bool CalledGetMaxTasks =
false;
412 : Prevailing(0), FinalDefinitionInLinkageUnit(0), VisibleToRegularObj(0),
413 LinkerRedefined(0) {}
NativeObjectStream(std::unique_ptr< raw_pwrite_stream > OS)
GlobalValue::VisibilityTypes getVisibility() const
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
StringRef getCOFFWeakExternalFallback() const
COFF-specific: for weak externals, returns the name of the symbol that is used as a fallback if the w...
Expected< std::unique_ptr< ToolOutputFile > > setupOptimizationRemarks(LLVMContext &Context, StringRef LTORemarksFilename, bool LTOPassRemarksWithHotness, int Count=-1)
Setup optimization remarks.
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< std::string > LTORemarksFilename("lto-pass-remarks-output", cl::desc("Output filename for pass remarks"), cl::value_desc("filename"))
Contains the information needed by linkers for symbol resolution, as well as by the LTO implementatio...
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...
std::unique_ptr< raw_pwrite_stream > OS
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.
Represents a module in a bitcode file.
std::unordered_set< GlobalValue::GUID > ExportSetTy
The set contains an entry for every global value the module exports.
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...
cl::opt< bool > LTOPassRemarksWithHotness("lto-pass-remarks-with-hotness", cl::desc("With PGO, include profile count in optimization remarks"), cl::Hidden)
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.
std::unique_ptr< Module > M
std::function< AddStreamFn(unsigned Task, StringRef Key)> NativeObjectCache
This is the type of a native object cache.
uint32_t getCommonAlignment() const
This class wraps an output stream for a native object.
void thinLTOResolvePrevailingInIndex(ModuleSummaryIndex &Index, function_ref< bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing, function_ref< void(StringRef, GlobalValue::GUID, GlobalValue::LinkageTypes)> recordNewLinkage)
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...
StringRef getSectionName() const
std::function< std::unique_ptr< ThinBackendProc > Config &C, ModuleSummaryIndex &CombinedIndex, StringMap< GVSummaryMapTy > &ModuleToDefinedGVSummaries, AddStreamFn AddStream, NativeObjectCache Cache)> ThinBackend
A ThinBackend defines what happens after the thin-link phase during ThinLTO.
int getComdatIndex() const
Returns the index into the comdat table (see Reader::getComdatTable()), or -1 if not a comdat member...
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 ...
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...
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...
void thinLTOInternalizeAndPromoteInIndex(ModuleSummaryIndex &Index, function_ref< bool(StringRef, GlobalValue::GUID)> isExported)
Update the linkages in the given Index to mark exported values as external and non-exported values as...