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

Static Public Member Functions

static const char * getVersionString ()
 

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 ( )

Definition at line 135 of file LTOCodeGenerator.cpp.

Member Function Documentation

◆ addModule()

bool LTOCodeGenerator::addModule ( struct LTOModule Mod)

Merge given module.

Return true on success.

Resets HasVerifiedInput.

Definition at line 143 of file LTOCodeGenerator.cpp.

References assert(), llvm::Module::getContext(), Mod, ret(), and setAsmUndefinedRefs().

◆ addMustPreserveSymbol()

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

Definition at line 122 of file LTOCodeGenerator.h.

References llvm::StringSet< AllocatorTy >::insert().

◆ 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 308 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 301 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 281 of file LTOCodeGenerator.cpp.

References llvm::ErrorOr< T >::getError(), llvm::MemoryBuffer::getFile(), move, 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 559 of file LTOCodeGenerator.cpp.

References llvm::lto::Config::CodeGenOnly.

◆ DiagnosticHandler()

void LTOCodeGenerator::DiagnosticHandler ( const DiagnosticInfo DI)

◆ getContext()

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

Definition at line 191 of file LTOCodeGenerator.h.

References Context.

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

References llvm::parseCommandLineOptions().

◆ resetMergedModule()

void llvm::LTOCodeGenerator::resetMergedModule ( )
inline

Definition at line 193 of file LTOCodeGenerator.h.

◆ setAsmUndefinedRefs()

void LTOCodeGenerator::setAsmUndefinedRefs ( struct LTOModule Mod)

Definition at line 137 of file LTOCodeGenerator.cpp.

References llvm::numbers::e, i, llvm::StringSet< AllocatorTy >::insert(), and 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 594 of file LTOCodeGenerator.cpp.

References Options.

◆ setCodePICModel()

void llvm::LTOCodeGenerator::setCodePICModel ( 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)

◆ setDiagnosticHandler()

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

Definition at line 657 of file LTOCodeGenerator.cpp.

References llvm::LLVMContext::setDiagnosticHandler().

◆ setDisableVerify()

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

Definition at line 185 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 CGFT_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 183 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 156 of file LTOCodeGenerator.cpp.

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

◆ setOptLevel()

void LTOCodeGenerator::setOptLevel ( unsigned  OptLevel)

◆ setShouldEmbedUselists()

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

Definition at line 104 of file LTOCodeGenerator.h.

◆ setShouldInternalize()

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

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

◆ setTargetOptions()

void LTOCodeGenerator::setTargetOptions ( const TargetOptions Options)

Definition at line 170 of file LTOCodeGenerator.cpp.

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

◆ setUseNewPM()

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

Definition at line 187 of file LTOCodeGenerator.h.

References llvm::lto::Config::UseNewPM.

◆ 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 208 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(), llvm::StringRef::str(), and llvm::WriteBitcodeToFile().


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