LLVM  13.0.0git
Classes | Typedefs | Functions
llvm::lto Namespace Reference


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
class  NativeObjectStream
 This class wraps an output stream for a native object. More...
struct  SymbolResolution
 The resolution for a symbol. More...
class  ThinBackendProc
 This class defines the interface to the ThinLTO backend. More...


using AddBufferFn = std::function< void(unsigned Task, std::unique_ptr< MemoryBuffer > MB)>
 This type defines the callback to add a pre-existing native object file (e.g. More...
using AddStreamFn = std::function< std::unique_ptr< NativeObjectStream >(unsigned Task)>
 This type defines the callback to add a native object that is generated on the fly. More...
using NativeObjectCache = std::function< AddStreamFn(unsigned Task, StringRef Key)>
 This is the type of a native object cache. More...
using ThinBackend = std::function< std::unique_ptr< ThinBackendProc >(const Config &C, ModuleSummaryIndex &CombinedIndex, StringMap< GVSummaryMapTy > &ModuleToDefinedGVSummaries, AddStreamFn AddStream, NativeObjectCache Cache)>
 A ThinBackend defines what happens after the thin-link phase during ThinLTO. More...
using IndexWriteCallback = std::function< void(const std::string &)>
 This ThinBackend writes individual module indexes to files, instead of running the individual backend jobs. More...


Expected< NativeObjectCachelocalCache (StringRef CacheDirectoryPath, AddBufferFn AddBuffer)
 Create a local file system cache which uses the given cache directory and file callback. More...
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. More...
Expected< std::unique_ptr< ToolOutputFile > > setupLLVMOptimizationRemarks (LLVMContext &Context, StringRef RemarksFilename, StringRef RemarksPasses, StringRef RemarksFormat, bool RemarksWithHotness, Optional< uint64_t > RemarksHotnessThreshold=0, int Count=-1)
 Setup optimization remarks. More...
Expected< std::unique_ptr< ToolOutputFile > > setupStatsFile (StringRef StatsFilename)
 Setups the output file for saving statistics. More...
std::vector< intgenerateModulesOrdering (ArrayRef< BitcodeModule * > R)
 Produces a container ordering for optimal multi-threaded processing. More...
ThinBackend createInProcessThinBackend (ThreadPoolStrategy Parallelism)
 This ThinBackend runs the individual backend jobs in-process. More...
ThinBackend createWriteIndexesThinBackend (std::string OldPrefix, std::string NewPrefix, bool ShouldEmitImportsFiles, raw_fd_ostream *LinkedObjectsFile, IndexWriteCallback OnWrite)
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. More...
Error backend (const Config &C, AddStreamFn AddStream, unsigned ParallelCodeGenParallelismLevel, Module &M, ModuleSummaryIndex &CombinedIndex)
 Runs a regular LTO backend. More...
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. More...
Error finalizeOptimizationRemarks (std::unique_ptr< ToolOutputFile > DiagOutputFile)
BitcodeModulefindThinLTOModule (MutableArrayRef< BitcodeModule > BMs)
 Returns the BitcodeModule that is ThinLTO. More...
Expected< BitcodeModulefindThinLTOModule (MemoryBufferRef MBRef)
 Variant of the above. More...
bool initImportList (const Module &M, const ModuleSummaryIndex &CombinedIndex, FunctionImporter::ImportMapTy &ImportList)
 Distributed ThinLTO: collect the referenced modules based on module summary and initialize ImportList. More...

Typedef Documentation

◆ AddBufferFn

using llvm::lto::AddBufferFn = typedef std::function<void(unsigned Task, std::unique_ptr<MemoryBuffer> MB)>

This type defines the callback to add a pre-existing native object file (e.g.

in a cache).

Buffer callbacks must be thread safe.

Definition at line 27 of file Caching.h.

◆ AddStreamFn

using llvm::lto::AddStreamFn = typedef std::function<std::unique_ptr<NativeObjectStream>(unsigned Task)>

This type defines the callback to add a native object that is generated on the fly.

Stream callbacks must be thread safe.

Definition at line 204 of file LTO.h.

◆ IndexWriteCallback

using llvm::lto::IndexWriteCallback = typedef std::function<void(const std::string &)>

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. OnWrite is callback which receives module identifier and notifies LTO user that index file for the module (and optionally imports file) was created.

Definition at line 246 of file LTO.h.

◆ NativeObjectCache

using llvm::lto::NativeObjectCache = typedef std::function<AddStreamFn(unsigned Task, StringRef Key)>

This is the type of a native object cache.

To request an item from the cache, pass a unique string as the Key. For hits, the cached file will be added to the link and this function will return AddStreamFn(). For misses, the cache will return a stream callback which must be called at most once to produce content for the stream. The native object stream produced by the stream callback will add the file to the link after the stream is written to.

Clients generally look like this:

if (AddStreamFn AddStream = Cache(Task, Key)) ProduceContent(AddStream);

Definition at line 219 of file LTO.h.

◆ ThinBackend

using llvm::lto::ThinBackend = typedef std::function<std::unique_ptr<ThinBackendProc>( const Config &C, ModuleSummaryIndex &CombinedIndex, StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries, AddStreamFn AddStream, NativeObjectCache Cache)>

A ThinBackend defines what happens after the thin-link phase during ThinLTO.

The details of this type definition aren't important; clients can only create a ThinBackend using one of the create*ThinBackend() functions below.

Definition at line 227 of file LTO.h.

Function Documentation

◆ backend()

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 498 of file LTOBackend.cpp.

References codegen(), createTargetMachine(), initAndLookupTarget(), Mod, opt(), llvm::splitCodeGen(), llvm::Error::success(), llvm::Expected< T >::takeError(), and TM.

◆ createInProcessThinBackend()

ThinBackend llvm::lto::createInProcessThinBackend ( ThreadPoolStrategy  Parallelism)

This ThinBackend runs the individual backend jobs in-process.

The default value means to use one job per hardware core (not hyper-thread).

Definition at line 1295 of file LTO.cpp.

◆ createWriteIndexesThinBackend()

ThinBackend llvm::lto::createWriteIndexesThinBackend ( std::string  OldPrefix,
std::string  NewPrefix,
bool  ShouldEmitImportsFiles,
raw_fd_ostream LinkedObjectsFile,
IndexWriteCallback  OnWrite 

Definition at line 1387 of file LTO.cpp.

◆ finalizeOptimizationRemarks()

Error llvm::lto::finalizeOptimizationRemarks ( std::unique_ptr< ToolOutputFile DiagOutputFile)

Definition at line 487 of file LTOBackend.cpp.

References llvm::Error::success().

Referenced by thinBackend().

◆ findThinLTOModule() [1/2]

Expected< BitcodeModule > llvm::lto::findThinLTOModule ( MemoryBufferRef  MBRef)

◆ findThinLTOModule() [2/2]

BitcodeModule * llvm::lto::findThinLTOModule ( MutableArrayRef< BitcodeModule BMs)

Returns the BitcodeModule that is ThinLTO.

Definition at line 659 of file LTOBackend.cpp.

References llvm::MutableArrayRef< T >::begin(), llvm::ArrayRef< T >::size(), and ThinLTOAssumeMerged.

Referenced by findThinLTOModule(), and thinBackend().

◆ generateModulesOrdering()

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 1597 of file LTO.cpp.

References llvm::size(), and llvm::sort().

Referenced by llvm::ThinLTOCodeGenerator::run().

◆ getThinLTOOutputFile()

std::string llvm::lto::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.

Also, create the resulting directory if it does not yet exist.

Definition at line 1308 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().

◆ initImportList()

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 685 of file LTOBackend.cpp.

References llvm::StringMap< ValueTy, AllocatorTy >::insert(), M, and ThinLTOAssumeMerged.

◆ localCache()

Expected< NativeObjectCache > llvm::lto::localCache ( StringRef  CacheDirectoryPath,
AddBufferFn  AddBuffer 

◆ opt()

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 

◆ setupLLVMOptimizationRemarks()

Expected< std::unique_ptr< ToolOutputFile > > llvm::lto::setupLLVMOptimizationRemarks ( LLVMContext Context,
StringRef  RemarksFilename,
StringRef  RemarksPasses,
StringRef  RemarksFormat,
bool  RemarksWithHotness,
Optional< uint64_t >  RemarksHotnessThreshold = 0,
int  Count = -1 

◆ setupStatsFile()

Expected< std::unique_ptr< ToolOutputFile > > llvm::lto::setupStatsFile ( StringRef  StatsFilename)

Setups the output file for saving statistics.

Definition at line 1578 of file LTO.cpp.

References llvm::StringRef::empty(), llvm::EnableStatistics(), llvm::errorCodeToError(), move, and llvm::sys::fs::OF_None.

Referenced by llvm::LTOCodeGenerator::optimize(), and llvm::lto::LTO::run().

◆ thinBackend()

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 544 of file LTOBackend.cpp.

References assert(), codegen(), llvm::lto::Config::CodeGenOnly, createTargetMachine(), 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::Module::getContext(), llvm::ErrorOr< T >::getError(), llvm::MemoryBuffer::getFile(), llvm::Module::getPIELevel(), I, llvm::inconvertibleErrorCode(), initAndLookupTarget(), llvm::LLVMContext::isODRUniquingDebugTypes(), Mod, move, opt(), 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(), llvm::Module::setPartialSampleProfileRatio(), setupLLVMOptimizationRemarks(), llvm::Reloc::Static, llvm::Expected< T >::takeError(), ThinLTOAssumeMerged, llvm::thinLTOInternalizeModule(), llvm::thinLTOResolvePrevailingInModule(), TM, and llvm::toString().