LLVM 20.0.0git
Public Member Functions | Static Public Member Functions | List of all members
llvm::LTOCodeGenerator Struct Reference

C++ class which implements the opaque lto_code_gen_t type. More...

#include "llvm/LTO/legacy/LTOCodeGenerator.h"

Public Member Functions

 LTOCodeGenerator (LLVMContext &Context)
 
 ~LTOCodeGenerator ()
 
bool addModule (struct LTOModule *)
 Merge given module.
 
void setModule (std::unique_ptr< LTOModule > M)
 Set the destination module.
 
void setAsmUndefinedRefs (struct LTOModule *)
 
void setTargetOptions (const TargetOptions &Options)
 
void setDebugInfo (lto_debug_model)
 
void setCodePICModel (std::optional< Reloc::Model > Model)
 
void setFileType (CodeGenFileType FT)
 Set the file type to be emitted (assembly or object code).
 
void setCpu (StringRef MCpu)
 
void setAttrs (std::vector< std::string > MAttrs)
 
void setOptLevel (unsigned OptLevel)
 
void setShouldInternalize (bool Value)
 
void setShouldEmbedUselists (bool Value)
 
void setSaveIRBeforeOptPath (std::string Value)
 
void setShouldRestoreGlobalsLinkage (bool Value)
 Restore linkage of globals.
 
void addMustPreserveSymbol (StringRef Sym)
 
void setCodeGenDebugOptions (ArrayRef< StringRef > Opts)
 Pass options to the driver and optimization passes.
 
void parseCodeGenDebugOptions ()
 Parse the options set in setCodeGenDebugOptions.
 
bool writeMergedModules (StringRef Path)
 Write the merged module to the file specified by the given path.
 
bool compile_to_file (const char **Name)
 Compile the merged module into a single output file; the path to output file is returned to the caller via argument "name".
 
std::unique_ptr< MemoryBuffercompile ()
 As with compile_to_file(), this function compiles the merged module into single output file.
 
bool optimize ()
 Optimizes the merged module.
 
std::unique_ptr< MemoryBuffercompileOptimized ()
 Compiles the merged optimized module into a single output file.
 
bool compileOptimized (AddStreamFn AddStream, unsigned ParallelismLevel)
 Compile the merged optimized module ParallelismLevel output files each representing a linkable partition of the module.
 
void setFreestanding (bool Enabled)
 Enable the Freestanding mode: indicate that the optimizer should not assume builtins are present on the target.
 
void setDisableVerify (bool Value)
 
void setDebugPassManager (bool Enabled)
 
void setDiagnosticHandler (lto_diagnostic_handler_t, void *)
 
LLVMContextgetContext ()
 
void resetMergedModule ()
 
void DiagnosticHandler (const DiagnosticInfo &DI)
 

Static Public Member Functions

static const chargetVersionString ()
 

Detailed Description

C++ class which implements the opaque lto_code_gen_t type.

Definition at line 72 of file LTOCodeGenerator.h.

Constructor & Destructor Documentation

◆ LTOCodeGenerator()

LTOCodeGenerator::LTOCodeGenerator ( LLVMContext Context)

◆ ~LTOCodeGenerator()

LTOCodeGenerator::~LTOCodeGenerator ( )
default

Member Function Documentation

◆ addModule()

bool LTOCodeGenerator::addModule ( struct LTOModule Mod)

Merge given module.

Return true on success.

Resets HasVerifiedInput.

Definition at line 150 of file LTOCodeGenerator.cpp.

References assert(), llvm::Mod, and setAsmUndefinedRefs().

◆ addMustPreserveSymbol()

void llvm::LTOCodeGenerator::addMustPreserveSymbol ( StringRef  Sym)
inline

Definition at line 127 of file LTOCodeGenerator.h.

References llvm::StringSet< AllocatorTy >::insert(), and Sym.

◆ compile()

std::unique_ptr< MemoryBuffer > LTOCodeGenerator::compile ( )

As with compile_to_file(), this function compiles the merged module into single output file.

Instead of returning the output file path to the caller (linker), it brings the output to a buffer, and returns the buffer to the caller. This function should delete the intermediate file once its content is brought to memory. Return NULL if the compilation was not successful.

Definition at line 376 of file LTOCodeGenerator.cpp.

References compileOptimized(), and optimize().

◆ compile_to_file()

bool LTOCodeGenerator::compile_to_file ( const char **  Name)

Compile the merged module into a single output file; the path to output file is returned to the caller via argument "name".

Return true on success.

Note
It is up to the linker to remove the intermediate output file. Do not try to remove the object file in LTOCodeGenerator's destructor as we don't who (LTOCodeGenerator or the output file) will last longer.

Definition at line 369 of file LTOCodeGenerator.cpp.

References Name, and optimize().

◆ compileOptimized() [1/2]

std::unique_ptr< MemoryBuffer > LTOCodeGenerator::compileOptimized ( )

Compiles the merged optimized module into a single output file.

It brings the output to a buffer, and returns the buffer to the caller. Return NULL if the compilation was not successful.

Definition at line 349 of file LTOCodeGenerator.cpp.

References llvm::ErrorOr< T >::getError(), llvm::MemoryBuffer::getFile(), name, and llvm::sys::fs::remove().

Referenced by compile().

◆ compileOptimized() [2/2]

bool LTOCodeGenerator::compileOptimized ( AddStreamFn  AddStream,
unsigned  ParallelismLevel 
)

Compile the merged optimized module ParallelismLevel output files each representing a linkable partition of the module.

If out contains more than one element, code generation is done in parallel with ParallelismLevel threads. Output files will be written to the streams created using the AddStream callback. Returns true on success.

Calls verifyMergedModuleOnce().

Definition at line 637 of file LTOCodeGenerator.cpp.

References llvm::AreStatisticsEnabled(), assert(), llvm::lto::Config::CodeGenOnly, llvm::PrintStatistics(), llvm::PrintStatisticsJSON(), and llvm::reportAndResetTimings().

◆ DiagnosticHandler()

void LTOCodeGenerator::DiagnosticHandler ( const DiagnosticInfo DI)

◆ getContext()

LLVMContext & llvm::LTOCodeGenerator::getContext ( )
inline

Definition at line 196 of file LTOCodeGenerator.h.

◆ getVersionString()

const char * LTOCodeGenerator::getVersionString ( )
static

Definition at line 68 of file LTOCodeGenerator.cpp.

◆ optimize()

bool LTOCodeGenerator::optimize ( )

◆ parseCodeGenDebugOptions()

void LTOCodeGenerator::parseCodeGenDebugOptions ( )

Parse the options set in setCodeGenDebugOptions.

Like setCodeGenDebugOptions(), this must be called before LTOCodeGenerator::compilexxx() and LTOCodeGenerator::writeMergedModules().

Definition at line 677 of file LTOCodeGenerator.cpp.

References llvm::parseCommandLineOptions().

◆ resetMergedModule()

void llvm::LTOCodeGenerator::resetMergedModule ( )
inline

Definition at line 198 of file LTOCodeGenerator.h.

◆ setAsmUndefinedRefs()

void LTOCodeGenerator::setAsmUndefinedRefs ( struct LTOModule Mod)

Definition at line 145 of file LTOCodeGenerator.cpp.

References llvm::StringSet< AllocatorTy >::insert(), and llvm::Mod.

Referenced by addModule(), and setModule().

◆ setAttrs()

void llvm::LTOCodeGenerator::setAttrs ( std::vector< std::string >  MAttrs)
inline

Definition at line 100 of file LTOCodeGenerator.h.

References llvm::lto::Config::MAttrs.

◆ setCodeGenDebugOptions()

void LTOCodeGenerator::setCodeGenDebugOptions ( ArrayRef< StringRef Opts)

Pass options to the driver and optimization passes.

These options are not necessarily for debugging purpose (the function name is misleading). This function should be called before LTOCodeGenerator::compilexxx(), and LTOCodeGenerator::writeMergedModules().

Definition at line 672 of file LTOCodeGenerator.cpp.

References Options.

◆ setCodePICModel()

void llvm::LTOCodeGenerator::setCodePICModel ( std::optional< Reloc::Model Model)
inline

Definition at line 91 of file LTOCodeGenerator.h.

References llvm::lto::Config::RelocModel.

◆ setCpu()

void llvm::LTOCodeGenerator::setCpu ( StringRef  MCpu)
inline

Definition at line 99 of file LTOCodeGenerator.h.

References llvm::lto::Config::CPU.

◆ setDebugInfo()

void LTOCodeGenerator::setDebugInfo ( lto_debug_model  Debug)

◆ setDebugPassManager()

void llvm::LTOCodeGenerator::setDebugPassManager ( bool  Enabled)
inline

Definition at line 192 of file LTOCodeGenerator.h.

References llvm::lto::Config::DebugPassManager, and Enabled.

◆ setDiagnosticHandler()

void LTOCodeGenerator::setDiagnosticHandler ( lto_diagnostic_handler_t  DiagHandler,
void *  Ctxt 
)

Definition at line 735 of file LTOCodeGenerator.cpp.

References llvm::LLVMContext::setDiagnosticHandler().

◆ setDisableVerify()

void llvm::LTOCodeGenerator::setDisableVerify ( bool  Value)
inline

Definition at line 190 of file LTOCodeGenerator.h.

References llvm::lto::Config::DisableVerify.

◆ setFileType()

void llvm::LTOCodeGenerator::setFileType ( CodeGenFileType  FT)
inline

Set the file type to be emitted (assembly or object code).

The default is CodeGenFileType::ObjectFile.

Definition at line 97 of file LTOCodeGenerator.h.

References llvm::lto::Config::CGFileType.

◆ setFreestanding()

void llvm::LTOCodeGenerator::setFreestanding ( bool  Enabled)
inline

Enable the Freestanding mode: indicate that the optimizer should not assume builtins are present on the target.

Definition at line 188 of file LTOCodeGenerator.h.

References Enabled, and llvm::lto::Config::Freestanding.

◆ setModule()

void LTOCodeGenerator::setModule ( std::unique_ptr< LTOModule M)

Set the destination module.

Resets HasVerifiedInput.

Definition at line 163 of file LTOCodeGenerator.cpp.

References assert(), llvm::StringMap< ValueTy, AllocatorTy >::clear(), llvm::Mod, and setAsmUndefinedRefs().

◆ setOptLevel()

void LTOCodeGenerator::setOptLevel ( unsigned  OptLevel)

◆ setSaveIRBeforeOptPath()

void llvm::LTOCodeGenerator::setSaveIRBeforeOptPath ( std::string  Value)
inline

Definition at line 107 of file LTOCodeGenerator.h.

◆ setShouldEmbedUselists()

void llvm::LTOCodeGenerator::setShouldEmbedUselists ( bool  Value)
inline

Definition at line 106 of file LTOCodeGenerator.h.

◆ setShouldInternalize()

void llvm::LTOCodeGenerator::setShouldInternalize ( bool  Value)
inline

Definition at line 105 of file LTOCodeGenerator.h.

◆ setShouldRestoreGlobalsLinkage()

void llvm::LTOCodeGenerator::setShouldRestoreGlobalsLinkage ( bool  Value)
inline

Restore linkage of globals.

When set, the linkage of globals will be restored prior to code generation. That is, a global symbol that had external linkage prior to LTO will be emitted with external linkage again; and a local will remain local. Note that this option only affects the end result - globals may still be internalized in the process of LTO and may be modified and/or deleted where legal.

The default behavior will internalize globals (unless on the preserve list) and, if parallel code generation is enabled, will externalize all locals.

Definition at line 123 of file LTOCodeGenerator.h.

◆ setTargetOptions()

void LTOCodeGenerator::setTargetOptions ( const TargetOptions Options)

Definition at line 177 of file LTOCodeGenerator.cpp.

References llvm::lto::Config::Options, and Options.

◆ writeMergedModules()

bool LTOCodeGenerator::writeMergedModules ( StringRef  Path)

Write the merged module to the file specified by the given path.

Return true on success.

Calls verifyMergedModuleOnce().

Definition at line 204 of file LTOCodeGenerator.cpp.

References llvm::raw_fd_ostream::clear_error(), llvm::raw_fd_ostream::close(), llvm::raw_fd_ostream::error(), llvm::raw_fd_ostream::has_error(), llvm::ToolOutputFile::keep(), llvm::sys::fs::OF_None, llvm::ToolOutputFile::os(), and llvm::WriteBitcodeToFile().


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