LLVM 20.0.0git
|
Classes | |
struct | Config |
LTO configuration. More... | |
class | InputFile |
An input file. More... | |
class | LTO |
This class implements a resolution-based interface to LLVM's LTO functionality. More... | |
struct | LTOLLVMContext |
A derived class of LLVMContext that initializes itself according to a given Config object. More... | |
struct | LTOLLVMDiagnosticHandler |
struct | SymbolResolution |
The resolution for a symbol. More... | |
class | ThinBackendProc |
This class defines the interface to the ThinLTO backend. More... | |
Typedefs | |
using | ThinBackend = std::function< std::unique_ptr< ThinBackendProc >(const Config &C, ModuleSummaryIndex &CombinedIndex, DenseMap< StringRef, GVSummaryMapTy > &ModuleToDefinedGVSummaries, AddStreamFn AddStream, FileCache Cache)> |
A ThinBackend defines what happens after the thin-link phase during ThinLTO. | |
using | IndexWriteCallback = std::function< void(const std::string &)> |
This ThinBackend runs the individual backend jobs in-process. | |
Functions | |
StringLiteral | getThinLTODefaultCPU (const Triple &TheTriple) |
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 . | |
Expected< std::unique_ptr< ToolOutputFile > > | setupLLVMOptimizationRemarks (LLVMContext &Context, StringRef RemarksFilename, StringRef RemarksPasses, StringRef RemarksFormat, bool RemarksWithHotness, std::optional< uint64_t > RemarksHotnessThreshold=0, int Count=-1) |
Setup optimization remarks. | |
Expected< std::unique_ptr< ToolOutputFile > > | setupStatsFile (StringRef StatsFilename) |
Setups the output file for saving statistics. | |
std::vector< int > | generateModulesOrdering (ArrayRef< BitcodeModule * > R) |
Produces a container ordering for optimal multi-threaded processing. | |
void | updateMemProfAttributes (Module &Mod, const ModuleSummaryIndex &Index) |
Updates MemProf attributes (and metadata) based on whether the index has recorded that we are linking with allocation libraries containing the necessary APIs for downstream transformations. | |
ThinBackend | createInProcessThinBackend (ThreadPoolStrategy Parallelism, IndexWriteCallback OnWrite=nullptr, bool ShouldEmitIndexFiles=false, bool ShouldEmitImportsFiles=false) |
ThinBackend | createWriteIndexesThinBackend (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 jobs. | |
bool | opt (const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod, bool IsThinLTO, ModuleSummaryIndex *ExportSummary, const ModuleSummaryIndex *ImportSummary, const std::vector< uint8_t > &CmdArgs) |
Runs middle-end LTO optimizations on Mod . | |
Error | backend (const Config &C, AddStreamFn AddStream, unsigned ParallelCodeGenParallelismLevel, Module &M, ModuleSummaryIndex &CombinedIndex) |
Runs a regular LTO backend. | |
Error | thinBackend (const Config &C, unsigned Task, AddStreamFn AddStream, Module &M, const ModuleSummaryIndex &CombinedIndex, const FunctionImporter::ImportMapTy &ImportList, const GVSummaryMapTy &DefinedGlobals, MapVector< StringRef, BitcodeModule > *ModuleMap, const std::vector< uint8_t > &CmdArgs=std::vector< uint8_t >()) |
Runs a ThinLTO backend. | |
Error | finalizeOptimizationRemarks (std::unique_ptr< ToolOutputFile > DiagOutputFile) |
BitcodeModule * | findThinLTOModule (MutableArrayRef< BitcodeModule > BMs) |
Returns the BitcodeModule that is ThinLTO. | |
Expected< BitcodeModule > | findThinLTOModule (MemoryBufferRef MBRef) |
Variant of the above. | |
bool | initImportList (const Module &M, const ModuleSummaryIndex &CombinedIndex, FunctionImporter::ImportMapTy &ImportList) |
Distributed ThinLTO: collect the referenced modules based on module summary and initialize ImportList. | |
using llvm::lto::IndexWriteCallback = typedef std::function<void(const std::string &)> |
This ThinBackend runs the individual backend jobs in-process.
The default value means to use one job per hardware core (not hyper-thread). OnWrite is callback which receives module identifier and notifies LTO user that index file for the module (and optionally imports file) was created. ShouldEmitIndexFiles being true will write sharded ThinLTO index files to the same path as the input module, with suffix ".thinlto.bc" ShouldEmitImportsFiles is true it also writes a list of imported files to a similar path with ".imports" appended instead.
using llvm::lto::ThinBackend = typedef std::function<std::unique_ptr<ThinBackendProc>( const Config &C, ModuleSummaryIndex &CombinedIndex, DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries, AddStreamFn AddStream, FileCache Cache)> |
Error llvm::lto::backend | ( | const Config & | C, |
AddStreamFn | AddStream, | ||
unsigned | ParallelCodeGenParallelismLevel, | ||
Module & | M, | ||
ModuleSummaryIndex & | CombinedIndex | ||
) |
Runs a regular LTO backend.
The regular LTO backend can also act as the regular LTO phase of ThinLTO, which may need to access the combined index.
Definition at line 516 of file LTOBackend.cpp.
References llvm::CallingConv::C, codegen(), createTargetMachine(), llvm::dbgs(), initAndLookupTarget(), LLVM_DEBUG, llvm::Mod, opt, splitCodeGen(), llvm::Error::success(), and llvm::Expected< T >::takeError().
ThinBackend llvm::lto::createInProcessThinBackend | ( | ThreadPoolStrategy | Parallelism, |
lto::IndexWriteCallback | OnWrite = nullptr , |
||
bool | ShouldEmitIndexFiles = false , |
||
bool | ShouldEmitImportsFiles = false |
||
) |
ThinBackend llvm::lto::createWriteIndexesThinBackend | ( | 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 jobs.
This backend is for distributed builds where separate processes will invoke the real backends.
To find the path to write the index to, the backend checks if the path has a prefix of OldPrefix; if so, it replaces that prefix with NewPrefix. It then appends ".thinlto.bc" and writes the index to that path. If ShouldEmitImportsFiles is true it also writes a list of imported files to a similar path with ".imports" appended instead. LinkedObjectsFile is an output stream to write the list of object files for the final ThinLTO linking. Can be nullptr. If LinkedObjectsFile is not nullptr and NativeObjectPrefix is not empty then it replaces the prefix of the objects with NativeObjectPrefix instead of NewPrefix. OnWrite is callback which receives module identifier and notifies LTO user that index file for the module (and optionally imports file) was created.
Error llvm::lto::finalizeOptimizationRemarks | ( | std::unique_ptr< ToolOutputFile > | DiagOutputFile | ) |
Definition at line 505 of file LTOBackend.cpp.
References llvm::Error::success().
Referenced by thinBackend().
Expected< BitcodeModule > llvm::lto::findThinLTOModule | ( | MemoryBufferRef | MBRef | ) |
Variant of the above.
Definition at line 695 of file LTOBackend.cpp.
References findThinLTOModule(), llvm::getBitcodeModuleList(), llvm::inconvertibleErrorCode(), and llvm::Expected< T >::takeError().
BitcodeModule * llvm::lto::findThinLTOModule | ( | MutableArrayRef< BitcodeModule > | BMs | ) |
Returns the BitcodeModule that is ThinLTO.
Definition at line 683 of file LTOBackend.cpp.
References llvm::MutableArrayRef< T >::begin(), llvm::ArrayRef< T >::size(), and ThinLTOAssumeMerged.
Referenced by findThinLTOModule(), and thinBackend().
std::vector< int > llvm::lto::generateModulesOrdering | ( | ArrayRef< BitcodeModule * > | R | ) |
Produces a container ordering for optimal multi-threaded processing.
Returns ordered indices to elements in the input array.
Definition at line 1929 of file LTO.cpp.
References llvm::size(), and llvm::sort().
Referenced by llvm::ThinLTOCodeGenerator::run().
StringLiteral llvm::lto::getThinLTODefaultCPU | ( | const Triple & | TheTriple | ) |
Definition at line 1576 of file LTO.cpp.
References llvm::Triple::aarch64, llvm::Triple::aarch64_32, llvm::Triple::getArch(), llvm::Triple::isArm64e(), llvm::Triple::isOSDarwin(), llvm::Triple::x86, and llvm::Triple::x86_64.
std::string llvm::lto::getThinLTOOutputFile | ( | StringRef | Path, |
StringRef | OldPrefix, | ||
StringRef | NewPrefix | ||
) |
Given the original Path
to an output file, replace any path prefix matching OldPrefix
with NewPrefix
.
Also, create the resulting directory if it does not yet exist.
Definition at line 1594 of file LTO.cpp.
References llvm::sys::fs::create_directories(), llvm::StringRef::empty(), llvm::errs(), llvm::sys::path::parent_path(), llvm::sys::path::replace_path_prefix(), and llvm::SmallString< InternalLen >::str().
bool llvm::lto::initImportList | ( | const Module & | M, |
const ModuleSummaryIndex & | CombinedIndex, | ||
FunctionImporter::ImportMapTy & | ImportList | ||
) |
Distributed ThinLTO: collect the referenced modules based on module summary and initialize ImportList.
Returns false if the operation failed.
Definition at line 709 of file LTOBackend.cpp.
References ThinLTOAssumeMerged, and llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::try_emplace().
bool llvm::lto::opt | ( | const Config & | Conf, |
TargetMachine * | TM, | ||
unsigned | Task, | ||
Module & | Mod, | ||
bool | IsThinLTO, | ||
ModuleSummaryIndex * | ExportSummary, | ||
const ModuleSummaryIndex * | ImportSummary, | ||
const std::vector< uint8_t > & | CmdArgs | ||
) |
Runs middle-end LTO optimizations on Mod
.
Definition at line 351 of file LTOBackend.cpp.
References llvm::dbgs(), EmbedBitcode, llvm::embedBitcodeInModule(), LLVM_DEBUG, llvm::Mod, llvm::lto::Config::OptLevel, llvm::lto::Config::PostOptModuleHook, and runNewPMPasses().
Expected< std::unique_ptr< ToolOutputFile > > llvm::lto::setupLLVMOptimizationRemarks | ( | LLVMContext & | Context, |
StringRef | RemarksFilename, | ||
StringRef | RemarksPasses, | ||
StringRef | RemarksFormat, | ||
bool | RemarksWithHotness, | ||
std::optional< uint64_t > | RemarksHotnessThreshold = 0 , |
||
int | Count = -1 |
||
) |
Setup optimization remarks.
Definition at line 1885 of file LTO.cpp.
References llvm::RemarksFilename, llvm::RemarksFormat, llvm::RemarksHotnessThreshold, llvm::RemarksPasses, llvm::RemarksWithHotness, and llvm::setupLLVMOptimizationRemarks().
Referenced by llvm::LTOCodeGenerator::optimize(), llvm::ThinLTOCodeGenerator::run(), and thinBackend().
Expected< std::unique_ptr< ToolOutputFile > > llvm::lto::setupStatsFile | ( | StringRef | StatsFilename | ) |
Setups the output file for saving statistics.
Definition at line 1910 of file LTO.cpp.
References llvm::StringRef::empty(), llvm::EnableStatistics(), llvm::errorCodeToError(), and llvm::sys::fs::OF_None.
Referenced by llvm::LTOCodeGenerator::optimize(), and llvm::lto::LTO::run().
Error llvm::lto::thinBackend | ( | const Config & | C, |
unsigned | Task, | ||
AddStreamFn | AddStream, | ||
Module & | M, | ||
const ModuleSummaryIndex & | CombinedIndex, | ||
const FunctionImporter::ImportMapTy & | ImportList, | ||
const GVSummaryMapTy & | DefinedGlobals, | ||
MapVector< StringRef, BitcodeModule > * | ModuleMap, | ||
const std::vector< uint8_t > & | CmdArgs = std::vector<uint8_t>() |
||
) |
Runs a ThinLTO backend.
If ModuleMap
is not nullptr, all the module files to be imported have already been mapped to memory and the corresponding BitcodeModule objects are saved in the ModuleMap. If ModuleMap
is nullptr, module files will be mapped to memory on demand and at any given time during importing, only one source module will be kept open at the most.
Definition at line 563 of file LTOBackend.cpp.
References assert(), codegen(), llvm::lto::Config::CodeGenOnly, createTargetMachine(), llvm::dbgs(), llvm::PIELevel::Default, dropDeadSymbols(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::empty(), llvm::MapVector< KeyT, ValueT, MapType, VectorType >::end(), finalizeOptimizationRemarks(), llvm::MapVector< KeyT, ValueT, MapType, VectorType >::find(), findThinLTOModule(), llvm::ErrorOr< T >::getError(), llvm::MemoryBuffer::getFile(), I, llvm::FunctionImporter::importFunctions(), llvm::inconvertibleErrorCode(), initAndLookupTarget(), LLVM_DEBUG, llvm::Mod, opt, llvm::lto::Config::PostImportModuleHook, llvm::lto::Config::PostInternalizeModuleHook, llvm::lto::Config::PostPromoteModuleHook, llvm::lto::Config::PreOptModuleHook, llvm::lto::Config::RemarksFilename, llvm::lto::Config::RemarksFormat, llvm::lto::Config::RemarksHotnessThreshold, llvm::lto::Config::RemarksPasses, llvm::lto::Config::RemarksWithHotness, llvm::renameModuleForThinLTO(), setupLLVMOptimizationRemarks(), llvm::Reloc::Static, llvm::Expected< T >::takeError(), ThinLTOAssumeMerged, llvm::thinLTOFinalizeInModule(), llvm::thinLTOInternalizeModule(), llvm::dwarf::toString(), updateMemProfAttributes(), llvm::updatePublicTypeTestCalls(), and llvm::ModuleSummaryIndex::withWholeProgramVisibility().
void llvm::lto::updateMemProfAttributes | ( | Module & | Mod, |
const ModuleSummaryIndex & | Index | ||
) |