LLVM 22.0.0git
llvm::lto::LTO Class Reference

This class implements a resolution-based interface to LLVM's LTO functionality. More...

#include "llvm/LTO/LTO.h"

Public Types

enum  LTOKind { LTOK_Default , LTOK_UnifiedRegular , LTOK_UnifiedThin }
 Unified LTO modes. More...

Public Member Functions

LLVM_ABI LTO (Config Conf, ThinBackend Backend={}, unsigned ParallelCodeGenParallelismLevel=1, LTOKind LTOMode=LTOK_Default)
 Create an LTO object.
LLVM_ABI ~LTO ()
LLVM_ABI Error add (std::unique_ptr< InputFile > Obj, ArrayRef< SymbolResolution > Res)
 Add an input file to the LTO link, using the provided symbol resolutions.
LLVM_ABI unsigned getMaxTasks () const
 Returns an upper bound on the number of tasks that the client may expect.
LLVM_ABI Error run (AddStreamFn AddStream, FileCache Cache={})
 Runs the LTO pipeline.

Static Public Member Functions

static LLVM_ABI SmallVector< const char * > getRuntimeLibcallSymbols (const Triple &TT)
 Static method that returns a list of libcall symbols that can be generated by LTO but might not be visible from bitcode symbol table.

Detailed Description

This class implements a resolution-based interface to LLVM's LTO functionality.

It supports regular LTO, parallel LTO code generation and ThinLTO. You can use it from a linker in the following way:

  • Set hooks and code generation options (see lto::Config struct defined in Config.h), and use the lto::Config object to create an lto::LTO object.
  • Create lto::InputFile objects using lto::InputFile::create(), then use the symbols() function to enumerate its symbols and compute a resolution for each symbol (see SymbolResolution below).
  • After the linker has visited each input file (and each regular object file) and computed a resolution for each symbol, take each lto::InputFile and pass it and an array of symbol resolutions to the add() function.
  • Call the getMaxTasks() function to get an upper bound on the number of native object files that LTO may add to the link.
  • Call the run() function. This function will use the supplied AddStream and Cache functions to add up to getMaxTasks() native object files to the link.

Definition at line 374 of file LTO.h.

Member Enumeration Documentation

◆ LTOKind

Unified LTO modes.

Enumerator
LTOK_Default 

Any LTO mode without Unified LTO. The default mode.

LTOK_UnifiedRegular 

Regular LTO, with Unified LTO enabled.

LTOK_UnifiedThin 

ThinLTO, with Unified LTO enabled.

Definition at line 379 of file LTO.h.

Constructor & Destructor Documentation

◆ LTO()

LTO::LTO ( Config Conf,
ThinBackend Backend = {},
unsigned ParallelCodeGenParallelismLevel = 1,
LTOKind LTOMode = LTOK_Default )

Create an LTO object.

A default constructed LTO object has a reasonable production configuration, but you can customize it by passing arguments to this constructor. FIXME: We do currently require the DiagHandler field to be set in Conf. Until that is fixed, a Config argument is required.

Definition at line 612 of file LTO.cpp.

References llvm::LTOKeepSymbolCopies, and llvm::move().

◆ ~LTO()

LTO::~LTO ( )
default

References LLVM_ABI.

Member Function Documentation

◆ add()

Error LTO::add ( std::unique_ptr< InputFile > Obj,
ArrayRef< SymbolResolution > Res )

Add an input file to the LTO link, using the provided symbol resolutions.

The symbol resolutions must appear in the enumeration order given by InputFile::symbols().

Definition at line 733 of file LTO.cpp.

References assert(), llvm::lto::Config::ELF, llvm::ArrayRef< T >::empty(), I, llvm::Triple::isOSBinFormatELF(), llvm::Error::success(), and writeToResolutionFile().

◆ getMaxTasks()

unsigned LTO::getMaxTasks ( ) const

Returns an upper bound on the number of tasks that the client may expect.

This may only be called after all IR object files have been added. For a full description of tasks see LTOBackend.h.

Definition at line 1150 of file LTO.cpp.

◆ getRuntimeLibcallSymbols()

SmallVector< const char * > LTO::getRuntimeLibcallSymbols ( const Triple & TT)
static

Static method that returns a list of libcall symbols that can be generated by LTO but might not be visible from bitcode symbol table.

Definition at line 1427 of file LTO.cpp.

References llvm::StringRef::data(), llvm::RTLIB::RuntimeLibcallsInfo::getLibcallImplName(), llvm::RTLIB::RuntimeLibcallsInfo::getLibcallImpls(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorImpl< T >::reserve(), and llvm::ArrayRef< T >::size().

◆ run()

Error LTO::run ( AddStreamFn AddStream,
FileCache Cache = {} )

Runs the LTO pipeline.

This function calls the supplied AddStream function to add native object files to the link.

The Cache parameter is optional. If supplied, it will be used to cache native object files and add them to the link.

The client will receive at most one callback (via either AddStream or Cache) for each task identifier.

Definition at line 1201 of file LTO.cpp.

References llvm::computeDeadSymbolsWithConstProp(), llvm::GlobalValue::dropLLVMManglingEscape(), llvm::ArrayRef< T >::empty(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), G, llvm::GlobalValue::getGUIDAssumingExternalLinkage(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::insert(), llvm::No, llvm::PrintStatisticsJSON(), llvm::lto::setupStatsFile(), llvm::SupportsHotColdNew, llvm::Unknown, and llvm::Yes.


The documentation for this class was generated from the following files: