LLVM 22.0.0git
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

LLVM_ABI LTOCodeGenerator (LLVMContext &Context)
LLVM_ABI ~LTOCodeGenerator ()
LLVM_ABI bool addModule (struct LTOModule *)
 Merge given module.
LLVM_ABI void setModule (std::unique_ptr< LTOModule > M)
 Set the destination module.
LLVM_ABI void setAsmUndefinedRefs (struct LTOModule *)
LLVM_ABI void setTargetOptions (const TargetOptions &Options)
LLVM_ABI 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)
LLVM_ABI 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)
LLVM_ABI void setCodeGenDebugOptions (ArrayRef< StringRef > Opts)
 Pass options to the driver and optimization passes.
LLVM_ABI void parseCodeGenDebugOptions ()
 Parse the options set in setCodeGenDebugOptions.
LLVM_ABI bool writeMergedModules (StringRef Path)
 Write the merged module to the file specified by the given path.
LLVM_ABI 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".
LLVM_ABI std::unique_ptr< MemoryBuffercompile ()
 As with compile_to_file(), this function compiles the merged module into single output file.
LLVM_ABI bool optimize ()
 Optimizes the merged module.
LLVM_ABI std::unique_ptr< MemoryBuffercompileOptimized ()
 Compiles the merged optimized module into a single output file.
LLVM_ABI 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)
LLVM_ABI void setDiagnosticHandler (lto_diagnostic_handler_t, void *)
LLVMContextgetContext ()
void resetMergedModule ()
LLVM_ABI void DiagnosticHandler (const DiagnosticInfo &DI)

Static Public Member Functions

static LLVM_ABI const chargetVersionString ()

Detailed Description

C++ class which implements the opaque lto_code_gen_t type.

Definition at line 73 of file LTOCodeGenerator.h.

Constructor & Destructor Documentation

◆ LTOCodeGenerator()

LTOCodeGenerator::LTOCodeGenerator ( LLVMContext & Context)

◆ ~LTOCodeGenerator()

LTOCodeGenerator::~LTOCodeGenerator ( )
default

References LLVM_ABI, and Options.

Member Function Documentation

◆ addModule()

bool LTOCodeGenerator::addModule ( struct LTOModule * Mod)

Merge given module.

Return true on success.

Resets HasVerifiedInput.

Definition at line 141 of file LTOCodeGenerator.cpp.

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

◆ addMustPreserveSymbol()

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

Definition at line 128 of file LTOCodeGenerator.h.

◆ 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 367 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 360 of file LTOCodeGenerator.cpp.

References 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 340 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 628 of file LTOCodeGenerator.cpp.

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

◆ DiagnosticHandler()

◆ getContext()

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

Definition at line 198 of file LTOCodeGenerator.h.

◆ getVersionString()

const char * LTOCodeGenerator::getVersionString ( )
static

Definition at line 61 of file LTOCodeGenerator.cpp.

◆ 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 668 of file LTOCodeGenerator.cpp.

References llvm::parseCommandLineOptions().

◆ resetMergedModule()

void llvm::LTOCodeGenerator::resetMergedModule ( )
inline

Definition at line 200 of file LTOCodeGenerator.h.

◆ setAsmUndefinedRefs()

void LTOCodeGenerator::setAsmUndefinedRefs ( struct LTOModule * Mod)

Definition at line 137 of file LTOCodeGenerator.cpp.

References llvm::Mod.

Referenced by addModule(), and setModule().

◆ setAttrs()

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

Definition at line 101 of file LTOCodeGenerator.h.

◆ 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 663 of file LTOCodeGenerator.cpp.

References Options.

◆ setCodePICModel()

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

Definition at line 92 of file LTOCodeGenerator.h.

◆ setCpu()

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

Definition at line 100 of file LTOCodeGenerator.h.

◆ setDebugInfo()

void LTOCodeGenerator::setDebugInfo ( lto_debug_model Debug)

◆ setDebugPassManager()

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

Definition at line 194 of file LTOCodeGenerator.h.

References Enabled.

◆ setDiagnosticHandler()

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

Definition at line 726 of file LTOCodeGenerator.cpp.

◆ setDisableVerify()

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

Definition at line 192 of file LTOCodeGenerator.h.

◆ 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 98 of file LTOCodeGenerator.h.

◆ 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 190 of file LTOCodeGenerator.h.

References Enabled.

◆ setModule()

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

Set the destination module.

Resets HasVerifiedInput.

Definition at line 154 of file LTOCodeGenerator.cpp.

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

◆ setOptLevel()

void LTOCodeGenerator::setOptLevel ( unsigned OptLevel)

Definition at line 185 of file LTOCodeGenerator.cpp.

References assert(), and llvm::CodeGenOpt::getLevel().

◆ setSaveIRBeforeOptPath()

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

Definition at line 108 of file LTOCodeGenerator.h.

◆ setShouldEmbedUselists()

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

Definition at line 107 of file LTOCodeGenerator.h.

◆ setShouldInternalize()

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

Definition at line 106 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 124 of file LTOCodeGenerator.h.

◆ setTargetOptions()

void LTOCodeGenerator::setTargetOptions ( const TargetOptions & Options)

Definition at line 168 of file LTOCodeGenerator.cpp.

References 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 195 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: