78 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
104LLVM_ABI Expected<std::unique_ptr<ToolOutputFile>>
123 InputFile() =
default;
125 std::vector<BitcodeModule> Mods;
127 std::vector<Symbol> Symbols;
130 std::vector<std::pair<size_t, size_t>> ModuleSymIndices;
132 StringRef TargetTriple, SourceFileName, COFFLinkerOpts;
133 std::vector<StringRef> DependentLibraries;
134 std::vector<std::pair<StringRef, Comdat::SelectionKind>> ComdatTable;
137 bool IsFatLTOObject =
false;
143 bool ExtractForDistribution =
false;
144 bool IsThinLTO =
false;
241 const auto &Indices = ModuleSymIndices[
I];
242 return {Symbols.data() + Indices.first, Symbols.data() + Indices.second};
274 virtual void setup(
unsigned ThinLTONumTasks,
unsigned ThinLTOTaskOffset,
280 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
285 return std::move(*
Err);
294 const std::string &NewModulePath)
const;
300 const std::string &NewModulePath,
332 return Func(Conf, CombinedIndex, ModuleToDefinedGVSummaries,
333 std::move(AddStream), std::move(Cache), BitcodeLibFuncs);
336 bool isValid()
const {
return static_cast<bool>(Func); }
353 bool ShouldEmitIndexFiles =
false,
bool ShouldEmitImportsFiles =
false);
372 std::string NewPrefix, std::string NativeObjectPrefix,
414 unsigned ParallelCodeGenParallelismLevel = 1,
415 LTOKind LTOMode = LTOK_Default);
478 std::map<std::string, CommonResolution>
Commons;
490 std::unique_ptr<Module>
M;
491 std::vector<GlobalValue *>
Keep;
510 PrevailingModuleForGUID[GUID] =
Module;
514 auto It = PrevailingModuleForGUID.find(GUID);
515 return It != PrevailingModuleForGUID.end() && It->second ==
Module;
534 struct GlobalResolution {
541 bool VisibleOutsideSummary =
false;
545 bool ExportDynamic =
false;
547 bool UnnamedAddr =
true;
550 bool Prevailing =
false;
555 bool isPrevailingIRSymbol()
const {
return Prevailing && !IRName.empty(); }
580 GlobalValue::GUID getGUID()
const {
582 : GlobalValue::getGUIDAssumingExternalLinkage(
583 GlobalValue::getGlobalIdentifier(
584 IRName, GlobalValue::LinkageTypes::ExternalLinkage,
603 std::unique_ptr<llvm::BumpPtrAllocator>
Alloc;
606 std::unique_ptr<llvm::StringSaver> GlobalResolutionSymbolSaver;
611 std::unique_ptr<llvm::DenseMap<StringRef, GlobalResolution>>
614 void releaseGlobalResolutionsMemory();
616 void addModuleToGlobalRes(ArrayRef<InputFile::Symbol> Syms,
617 ArrayRef<SymbolResolution> Res,
unsigned Partition,
618 bool InSummary,
const Triple &TT);
623 Expected<ArrayRef<SymbolResolution>>
624 addModule(InputFile &Input, ArrayRef<SymbolResolution> InputRes,
625 unsigned ModI, ArrayRef<SymbolResolution> Res);
627 Expected<std::pair<RegularLTOState::AddedModule, ArrayRef<SymbolResolution>>>
628 addRegularLTO(InputFile &Input, ArrayRef<SymbolResolution> InputRes,
629 BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
630 ArrayRef<SymbolResolution> Res);
631 Error linkRegularLTO(RegularLTOState::AddedModule
Mod,
632 bool LivenessFromIndex);
634 Expected<ArrayRef<SymbolResolution>>
635 addThinLTO(BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
636 ArrayRef<SymbolResolution> Res);
638 Error runRegularLTO(AddStreamFn AddStream);
639 Error runThinLTO(AddStreamFn AddStream, FileCache Cache,
640 const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols);
642 Error checkPartiallySplit();
644 mutable bool CalledGetMaxTasks =
false;
652 std::optional<bool> EnableSplitLTOUnit;
662 std::unique_ptr<Module> DummyModule;
668 Function *LinkerRemarkFunction =
nullptr;
671 Error setupOptimizationRemarks();
677 Error setupPassPlugins();
690 addInput(std::unique_ptr<lto::InputFile> InputPtr) {
691 return std::shared_ptr<lto::InputFile>(InputPtr.release());
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static void cleanup(BlockFrequencyInfoImplBase &BFI)
Clear all memory not needed downstream.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file defines the DenseMap class.
Provides passes for computing function attributes based on interprocedural analyses.
static void emitRemark(const Function &F, OptimizationRemarkEmitter &ORE, bool Skip)
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...
if(auto Err=PB.parsePassPipeline(MPM, Passes)) return wrap(std MPM run * Mod
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Represents a module in a bitcode file.
Implements a dense probed hash-table based set.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
The map maintains the list of imports.
DenseSet< ValueInfo > ExportSetTy
The set contains an entry for every global value that the module exports.
Function and variable summary information to aid decisions and implementation of importing.
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.
This is an important class for using LLVM in a threaded context.
RAII handle that manages the lifetime of the ToolOutputFile used to output remarks.
This class implements a map that also provides access to all stored values in a deterministic order.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
A Module instance is used to store all the information related to an LLVM module.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
Provides information about what library functions are available for the current target.
This tells how a thread pool will be used.
Triple - Helper class for working with autoconf configuration names.
An efficient, type-erasing, non-owning reference to a callable.
This class implements a resolution-based interface to LLVM's LTO functionality.
LTO(Config Conf, ThinBackend Backend={}, unsigned ParallelCodeGenParallelismLevel=1, LTOKind LTOMode=LTOK_Default)
Create an LTO object.
Error add(std::unique_ptr< InputFile > Obj, ArrayRef< SymbolResolution > Res)
Add an input file to the LTO link, using the provided symbol resolutions.
virtual Expected< std::shared_ptr< lto::InputFile > > addInput(std::unique_ptr< lto::InputFile > InputPtr)
void setBitcodeLibFuncs(ArrayRef< StringRef > BitcodeLibFuncs)
Set the list of functions implemented in bitcode that were not extracted from an archive.
MapVector< StringRef, BitcodeModule > ModuleMapType
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.
unsigned getMaxTasks() const
Returns an upper bound on the number of tasks that the client may expect.
virtual Error run(AddStreamFn AddStream, FileCache Cache={})
Runs the LTO pipeline.
virtual void waitForCleanup()
Wait for cleanup work started by run() to finish.
DefaultThreadPool BackendThreadPool
bool ShouldEmitImportsFiles
std::optional< Error > Err
virtual bool isSensitiveToInputOrder()
unsigned getThreadCount()
const DenseMap< StringRef, GVSummaryMapTy > & ModuleToDefinedGVSummaries
ThinBackendProc(const Config &Conf, ModuleSummaryIndex &CombinedIndex, const DenseMap< StringRef, GVSummaryMapTy > &ModuleToDefinedGVSummaries, lto::IndexWriteCallback OnWrite, bool ShouldEmitImportsFiles, ThreadPoolStrategy ThinLTOParallelism)
ModuleSummaryIndex & CombinedIndex
virtual void setup(unsigned ThinLTONumTasks, unsigned ThinLTOTaskOffset, Triple Triple)
virtual ~ThinBackendProc()=default
virtual Error start(unsigned Task, BitcodeModule BM, const FunctionImporter::ImportMapTy &ImportList, const FunctionImporter::ExportSetTy &ExportList, const std::map< GlobalValue::GUID, GlobalValue::LinkageTypes > &ResolvedODR, MapVector< StringRef, BitcodeModule > &ModuleMap)=0
LLVM_ABI Error emitFiles(const FunctionImporter::ImportMapTy &ImportList, unsigned Task, StringRef ModulePath, const std::string &NewModulePath) const
IndexWriteCallback OnWrite
A raw_ostream that writes to a file descriptor.
An abstract base class for streams implementations that also support a pwrite operation.
LLVM_ABI ThinBackend createInProcessThinBackend(ThreadPoolStrategy Parallelism, IndexWriteCallback OnWrite=nullptr, bool ShouldEmitIndexFiles=false, bool ShouldEmitImportsFiles=false)
This ThinBackend runs the individual backend jobs in-process.
LLVM_ABI 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, const DenseMap< StringRef, GVSummaryMapTy > &ModuleToDefinedGVSummaries, AddStreamFn AddStream, FileCache Cache, ArrayRef< StringRef > BitcodeLibFuncs)> ThinBackendFunction
This callable defines the behavior of a ThinLTO backend after the thin-link phase.
LLVM_ABI StringLiteral getThinLTODefaultCPU(const Triple &TheTriple)
LLVM_ABI Expected< std::unique_ptr< ToolOutputFile > > setupStatsFile(StringRef StatsFilename)
Setups the output file for saving statistics.
std::function< void(const std::string &)> IndexWriteCallback
LLVM_ABI ThinBackend createWriteIndexesThinBackend(ThreadPoolStrategy Parallelism, 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...
LLVM_ABI Expected< LLVMRemarkFileHandle > setupLLVMOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename, StringRef RemarksPasses, StringRef RemarksFormat, bool RemarksWithHotness, std::optional< uint64_t > RemarksHotnessThreshold=0, int Count=-1)
Setup optimization remarks.
LLVM_ABI std::vector< int > generateModulesOrdering(ArrayRef< BitcodeModule * > R)
Produces a container ordering for optimal multi-threaded processing.
llvm::SmallVector< std::string > ImportsFilesContainer
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"))
@ Unknown
Not known to have no common set bits.
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"))
DenseMap< GlobalValue::GUID, GlobalValueSummary * > GVSummaryMapTy
Map of global value GUID to its summary, used to identify values defined in a particular module,...
LLVM_ABI std::string recomputeLTOCacheKey(const std::string &Key, StringRef ExtraID)
Recomputes the LTO cache key for a given key with an extra identifier.
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"))
LLVM_ABI 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.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
SingleThreadExecutor DefaultThreadPool
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
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)
LLVM_ABI std::string computeLTOCacheKey(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 DenseSet< GlobalValue::GUID > &CfiFunctionDefs={}, const DenseSet< GlobalValue::GUID > &CfiFunctionDecls={})
Computes a unique hash for the Module considering the current list of export/import and other global ...
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.
LLVM_ABI void thinLTOInternalizeAndPromoteInIndex(ModuleSummaryIndex &Index, function_ref< bool(StringRef, ValueInfo)> isExported, function_ref< bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing, DenseSet< StringRef > *ExternallyVisibleSymbolNamesPtr=nullptr)
Update the linkages in the given Index to mark exported values as external and non-exported values as...
Implement std::hash so that hash_code can be used in STL containers.
This struct is a compact representation of a valid (non-zero power of two) alignment.
This type represents a file cache system that manages caching of files.
A simple container for information about the supported runtime calls.
Struct that holds a reference to a particular GUID in a global value summary.
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...
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.
std::vector< AddedModule > ModsWithSummaries
std::unique_ptr< IRMover > Mover
unsigned ParallelCodeGenParallelismLevel
std::map< std::string, CommonResolution > Commons
std::unique_ptr< Module > CombinedModule
LLVM_ABI RegularLTOState(unsigned ParallelCodeGenParallelismLevel, const Config &Conf)
LLVM_ABI ThinLTOState(ThinBackend Backend)
bool isPrevailingModuleForGUID(GlobalValue::GUID GUID, StringRef Module) const
void setPrevailingModuleForGUID(GlobalValue::GUID GUID, StringRef Module)
std::optional< ModuleMapType > ModulesToCompile
ModuleSummaryIndex CombinedIndex
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.
This type defines the behavior following the thin-link phase during ThinLTO.
std::unique_ptr< ThinBackendProc > operator()(const Config &Conf, ModuleSummaryIndex &CombinedIndex, const DenseMap< StringRef, GVSummaryMapTy > &ModuleToDefinedGVSummaries, AddStreamFn AddStream, FileCache Cache, ArrayRef< StringRef > BitcodeLibFuncs)
ThreadPoolStrategy getParallelism() const
ThinBackend(ThinBackendFunction Func, ThreadPoolStrategy Parallelism)