16 #ifndef LLVM_LTO_LTO_H
17 #define LLVM_LTO_LTO_H
39 class MemoryBufferRef;
42 class raw_pwrite_stream;
51 ModuleSummaryIndex &Index,
61 ModuleSummaryIndex &Index,
70 const std::string &OldPrefix,
71 const std::string &NewPrefix);
74 Expected<std::unique_ptr<tool_output_file>>
79 struct SymbolResolution;
80 class ThinBackendProc;
93 std::vector<BitcodeModule> Mods;
95 std::vector<Symbol> Symbols;
98 std::vector<std::pair<size_t, size_t>> ModuleSymIndices;
100 StringRef TargetTriple, SourceFileName, COFFLinkerOpts;
101 std::vector<StringRef> ComdatTable;
152 const auto &Indices = ModuleSymIndices[
I];
153 return {Symbols.data() + Indices.first, Symbols.data() + Indices.second};
165 std::unique_ptr<raw_pwrite_stream>
OS;
173 typedef std::function<std::unique_ptr<NativeObjectStream>(
unsigned Task)>
188 typedef std::function<AddStreamFn(unsigned Task, StringRef Key)>
194 typedef std::function<std::unique_ptr<ThinBackendProc>(
213 std::string NewPrefix,
214 bool ShouldEmitImportsFiles,
215 std::string LinkedObjectsFile);
243 unsigned ParallelCodeGenParallelismLevel = 1);
269 struct RegularLTOState {
270 RegularLTOState(
unsigned ParallelCodeGenParallelismLevel,
Config &Conf);
277 std::map<std::string, CommonResolution> Commons;
279 unsigned ParallelCodeGenParallelismLevel;
281 bool HasModule =
false;
282 std::unique_ptr<Module> CombinedModule;
283 std::unique_ptr<IRMover> Mover;
290 std::unique_ptr<Module>
M;
291 std::vector<GlobalValue *>
Keep;
293 std::vector<AddedModule> ModsWithSummaries;
296 struct ThinLTOState {
312 struct GlobalResolution {
319 bool VisibleOutsideSummary =
false;
321 bool UnnamedAddr =
true;
334 unsigned Partition = Unknown;
351 StringMap<GlobalResolution> GlobalResolutions;
353 void addModuleToGlobalRes(ArrayRef<InputFile::Symbol> Syms,
354 ArrayRef<SymbolResolution> Res,
unsigned Partition,
361 Error addModule(InputFile &Input,
unsigned ModI,
362 const SymbolResolution *&ResI,
const SymbolResolution *ResE);
364 Expected<RegularLTOState::AddedModule>
365 addRegularLTO(BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
366 const SymbolResolution *&ResI,
const SymbolResolution *ResE);
367 Error linkRegularLTO(RegularLTOState::AddedModule Mod,
368 bool LivenessFromIndex);
370 Error addThinLTO(BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
371 const SymbolResolution *&ResI,
const SymbolResolution *ResE);
377 mutable bool CalledGetMaxTasks =
false;
NativeObjectStream(std::unique_ptr< raw_pwrite_stream > OS)
uint32_t getCommonAlignment() const
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.
cl::opt< std::string > LTORemarksFilename("lto-pass-remarks-output", cl::desc("Output filename for pass remarks"), cl::value_desc("filename"))
bool Prevailing
Record if at least one instance of the common was marked as prevailing.
Contains the information needed by linkers for symbol resolution, as well as by the LTO implementatio...
StringRef getCOFFWeakExternalFallback() const
COFF-specific: for weak externals, returns the name of the symbol that is used as a fallback if the w...
unsigned LinkerRedefined
Linker redefined version of the symbol which appeared in -wrap or -defsym linker option.
The resolution for a symbol.
This class implements a map that also provides access to all stored values in a deterministic order...
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.
Tagged union holding either a T or a Error.
bool isExecutable() const
virtual ~NativeObjectStream()=default
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...
std::unique_ptr< Module > M
Error add(std::unique_ptr< InputFile > Obj, ArrayRef< SymbolResolution > Res)
Add an input file to the LTO link, using the provided symbol resolutions.
std::function< AddStreamFn(unsigned Task, StringRef Key)> NativeObjectCache
This is the type of a native object cache.
bool canBeOmittedFromSymbolTable() const
GlobalValue::VisibilityTypes getVisibility() const
This class wraps an output stream for a native object.
ThinBackend createWriteIndexesThinBackend(std::string OldPrefix, std::string NewPrefix, bool ShouldEmitImportsFiles, std::string LinkedObjectsFile)
This ThinBackend writes individual module indexes to files, instead of running the individual backend...
Expected< std::unique_ptr< tool_output_file > > setupOptimizationRemarks(LLVMContext &Context, StringRef LTORemarksFilename, bool LTOPassRemarksWithHotness, int Count=-1)
Setup optimization remarks.
This represents a symbol that has been read from a storage::Symbol and possibly a storage::Uncommon...
uint64_t getCommonSize() 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.
unsigned getMaxTasks() const
Returns an upper bound on the number of tasks that the client may expect.
static const char * Target
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.
int getComdatIndex() const
Returns the index into the comdat table (see Reader::getComdatTable()), or -1 if not a comdat member...
ThinBackend createInProcessThinBackend(unsigned ParallelismLevel)
This ThinBackend runs the individual backend jobs in-process.
std::vector< GlobalValue * > Keep
LTO(Config Conf, ThinBackend Backend=nullptr, unsigned ParallelCodeGenParallelismLevel=1)
Create an LTO object.
void thinLTOResolveWeakForLinkerInIndex(ModuleSummaryIndex &Index, function_ref< bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing, function_ref< void(StringRef, GlobalValue::GUID, GlobalValue::LinkageTypes)> recordNewLinkage)
Resolve Weak and LinkOnce values in the Index.
Error run(AddStreamFn AddStream, NativeObjectCache Cache=nullptr)
Runs the LTO pipeline.
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.
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...
StringRef getName() const
Returns the mangled symbol name.