16 #ifndef LLVM_LTO_LTO_H
17 #define LLVM_LTO_LTO_H
37 class MemoryBufferRef;
40 class raw_pwrite_stream;
49 ModuleSummaryIndex &Index,
59 ModuleSummaryIndex &Index,
68 const std::string &OldPrefix,
69 const std::string &NewPrefix);
72 struct SymbolResolution;
73 class ThinBackendProc;
85 std::vector<InputModule> Mods;
88 std::vector<StringRef> Comdats;
138 bool isGV()
const {
return I->is<
GlobalValue *>(); }
144 : I(I), SymTab(SymTab), File(File) {
178 getGV()->
getType()->getElementType());
194 : Sym(I, SymTab, File) {}
212 return Sym.I != Other.Sym.I;
244 std::unique_ptr<raw_pwrite_stream>
OS;
252 typedef std::function<std::unique_ptr<NativeObjectStream>(
unsigned Task)>
267 typedef std::function<AddStreamFn(unsigned Task, StringRef Key)>
273 typedef std::function<std::unique_ptr<ThinBackendProc>(
292 std::string NewPrefix,
293 bool ShouldEmitImportsFiles,
294 std::string LinkedObjectsFile);
322 unsigned ParallelCodeGenParallelismLevel = 1);
348 struct RegularLTOState {
349 RegularLTOState(
unsigned ParallelCodeGenParallelismLevel,
Config &Conf);
356 std::map<std::string, CommonResolution> Commons;
358 unsigned ParallelCodeGenParallelismLevel;
360 bool HasModule =
false;
361 std::unique_ptr<Module> CombinedModule;
362 std::unique_ptr<IRMover> Mover;
365 struct ThinLTOState {
381 struct GlobalResolution {
387 bool VisibleOutsideThinLTO =
false;
389 bool UnnamedAddr =
true;
419 StringMap<GlobalResolution> GlobalResolutions;
421 void addSymbolToGlobalRes(SmallPtrSet<GlobalValue *, 8> &Used,
430 const SymbolResolution *&ResI,
const SymbolResolution *ResE);
431 Error addRegularLTO(BitcodeModule BM,
const SymbolResolution *&ResI,
432 const SymbolResolution *ResE);
433 Error addThinLTO(BitcodeModule BM, Module &M,
434 iterator_range<InputFile::symbol_iterator> Syms,
435 const SymbolResolution *&ResI,
const SymbolResolution *ResE);
441 mutable bool CalledGetMaxTasks =
false;
NativeObjectStream(std::unique_ptr< raw_pwrite_stream > OS)
VisibilityTypes getVisibility() 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.
bool Prevailing
Record if at least one instance of the common was marked as prevailing.
bool canBeOmittedFromSymbolTable(const GlobalValue *GV)
A raw_ostream that writes to an SmallVector or SmallString.
The resolution for a symbol.
This class implements a map that also provides access to all stored values in a deterministic order...
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
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.
virtual ~NativeObjectStream()=default
VisibilityTypes
An enumeration for the kinds of visibility of global values.
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...
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
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.
This is an important class for using LLVM in a threaded context.
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...
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
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.
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
unsigned getMaxTasks() const
Returns an upper bound on the number of tasks that the client may expect.
static const char * Target
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
A range adaptor for a pair of iterators.
LinkageTypes
An enumeration for the kinds of linkage for global values.
uint32_t getSymbolFlags(Symbol S) const
ThinBackend createInProcessThinBackend(unsigned ParallelismLevel)
This ThinBackend runs the individual backend jobs in-process.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
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.
ArrayRef< Symbol > symbols() const
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.
void printSymbolName(raw_ostream &OS, Symbol S) const
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
unsigned getAlignment() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Module * getParent()
Get the module that this global value is contained inside of...
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...