LLVM 20.0.0git
Classes | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
llvm::orc::LLJIT Class Reference

A pre-fabricated ORC JIT stack that can serve as an alternative to MCJIT. More...

#include "llvm/ExecutionEngine/Orc/LLJIT.h"

Inheritance diagram for llvm::orc::LLJIT:
Inheritance graph
[legend]

Classes

class  PlatformSupport
 Initializer support for LLJIT. More...
 

Public Member Functions

virtual ~LLJIT ()
 Destruct this instance.
 
ExecutionSessiongetExecutionSession ()
 Returns the ExecutionSession for this instance.
 
const TriplegetTargetTriple () const
 Returns a reference to the triple for this instance.
 
const DataLayoutgetDataLayout () const
 Returns a reference to the DataLayout for this instance.
 
JITDylibgetMainJITDylib ()
 Returns a reference to the JITDylib representing the JIT'd main program.
 
JITDylibSP getProcessSymbolsJITDylib ()
 Returns the ProcessSymbols JITDylib, which by default reflects non-JIT'd symbols in the host process.
 
JITDylibSP getPlatformJITDylib ()
 Returns the Platform JITDylib, which will contain the ORC runtime (if given) and any platform symbols.
 
JITDylibgetJITDylibByName (StringRef Name)
 Returns the JITDylib with the given name, or nullptr if no JITDylib with that name exists.
 
Expected< JITDylib & > loadPlatformDynamicLibrary (const char *Path)
 Load a (real) dynamic library and make its symbols available through a new JITDylib with the same name.
 
Error linkStaticLibraryInto (JITDylib &JD, std::unique_ptr< MemoryBuffer > LibBuffer)
 Link a static library into the given JITDylib.
 
Error linkStaticLibraryInto (JITDylib &JD, const char *Path)
 Link a static library into the given JITDylib.
 
Expected< JITDylib & > createJITDylib (std::string Name)
 Create a new JITDylib with the given name and return a reference to it.
 
JITDylibSearchOrder defaultLinkOrder ()
 Returns the default link order for this LLJIT instance.
 
Error addIRModule (ResourceTrackerSP RT, ThreadSafeModule TSM)
 Adds an IR module with the given ResourceTracker.
 
Error addIRModule (JITDylib &JD, ThreadSafeModule TSM)
 Adds an IR module to the given JITDylib.
 
Error addIRModule (ThreadSafeModule TSM)
 Adds an IR module to the Main JITDylib.
 
Error addObjectFile (ResourceTrackerSP RT, std::unique_ptr< MemoryBuffer > Obj)
 Adds an object file to the given JITDylib.
 
Error addObjectFile (JITDylib &JD, std::unique_ptr< MemoryBuffer > Obj)
 Adds an object file to the given JITDylib.
 
Error addObjectFile (std::unique_ptr< MemoryBuffer > Obj)
 Adds an object file to the given JITDylib.
 
Expected< ExecutorAddrlookupLinkerMangled (JITDylib &JD, SymbolStringPtr Name)
 Look up a symbol in JITDylib JD by the symbol's linker-mangled name (to look up symbols based on their IR name use the lookup function instead).
 
Expected< ExecutorAddrlookupLinkerMangled (JITDylib &JD, StringRef Name)
 Look up a symbol in JITDylib JD by the symbol's linker-mangled name (to look up symbols based on their IR name use the lookup function instead).
 
Expected< ExecutorAddrlookupLinkerMangled (StringRef Name)
 Look up a symbol in the main JITDylib by the symbol's linker-mangled name (to look up symbols based on their IR name use the lookup function instead).
 
Expected< ExecutorAddrlookup (JITDylib &JD, StringRef UnmangledName)
 Look up a symbol in JITDylib JD based on its IR symbol name.
 
Expected< ExecutorAddrlookup (StringRef UnmangledName)
 Look up a symbol in the main JITDylib based on its IR symbol name.
 
void setPlatformSupport (std::unique_ptr< PlatformSupport > PS)
 Set the PlatformSupport instance.
 
PlatformSupportgetPlatformSupport ()
 Get the PlatformSupport instance.
 
Error initialize (JITDylib &JD)
 Run the initializers for the given JITDylib.
 
Error deinitialize (JITDylib &JD)
 Run the deinitializers for the given JITDylib.
 
ObjectLayergetObjLinkingLayer ()
 Returns a reference to the ObjLinkingLayer.
 
ObjectTransformLayergetObjTransformLayer ()
 Returns a reference to the object transform layer.
 
IRTransformLayergetIRTransformLayer ()
 Returns a reference to the IR transform layer.
 
IRCompileLayergetIRCompileLayer ()
 Returns a reference to the IR compile layer.
 
std::string mangle (StringRef UnmangledName) const
 Returns a linker-mangled version of UnmangledName.
 
SymbolStringPtr mangleAndIntern (StringRef UnmangledName) const
 Returns an interned, linker-mangled version of UnmangledName.
 

Protected Member Functions

 LLJIT (LLJITBuilderState &S, Error &Err)
 Create an LLJIT instance with a single compile thread.
 
Error applyDataLayout (Module &M)
 
void recordCtorDtors (Module &M)
 

Static Protected Member Functions

static Expected< std::unique_ptr< ObjectLayer > > createObjectLinkingLayer (LLJITBuilderState &S, ExecutionSession &ES)
 
static Expected< std::unique_ptr< IRCompileLayer::IRCompiler > > createCompileFunction (LLJITBuilderState &S, JITTargetMachineBuilder JTMB)
 

Protected Attributes

std::unique_ptr< ExecutionSessionES
 
std::unique_ptr< PlatformSupportPS
 
JITDylibProcessSymbols = nullptr
 
JITDylibPlatform = nullptr
 
JITDylibMain = nullptr
 
JITDylibSearchOrder DefaultLinks
 
DataLayout DL
 
Triple TT
 
std::unique_ptr< ObjectLayerObjLinkingLayer
 
std::unique_ptr< ObjectTransformLayerObjTransformLayer
 
std::unique_ptr< IRCompileLayerCompileLayer
 
std::unique_ptr< IRTransformLayerTransformLayer
 
std::unique_ptr< IRTransformLayerInitHelperTransformLayer
 

Friends

template<typename , typename , typename >
class LLJITBuilderSetters
 
Expected< JITDylibSPsetUpGenericLLVMIRPlatform (LLJIT &J)
 Configure the LLJIT instance to scrape modules for llvm.global_ctors and llvm.global_dtors variables and (if present) build initialization and deinitialization functions.
 

Detailed Description

A pre-fabricated ORC JIT stack that can serve as an alternative to MCJIT.

Create instances using LLJITBuilder.

Definition at line 38 of file LLJIT.h.

Constructor & Destructor Documentation

◆ ~LLJIT()

llvm::orc::LLJIT::~LLJIT ( )
virtual

Destruct this instance.

If a multi-threaded instance, waits for all compile threads to complete.

Definition at line 841 of file LLJIT.cpp.

References ES.

◆ LLJIT()

llvm::orc::LLJIT::LLJIT ( LLJITBuilderState S,
Error Err 
)
protected

Member Function Documentation

◆ addIRModule() [1/3]

Error llvm::orc::LLJIT::addIRModule ( JITDylib JD,
ThreadSafeModule  TSM 
)

Adds an IR module to the given JITDylib.

Definition at line 904 of file LLJIT.cpp.

References addIRModule(), and llvm::orc::JITDylib::getDefaultResourceTracker().

◆ addIRModule() [2/3]

Error llvm::orc::LLJIT::addIRModule ( ResourceTrackerSP  RT,
ThreadSafeModule  TSM 
)

Adds an IR module with the given ResourceTracker.

Definition at line 894 of file LLJIT.cpp.

References assert(), InitHelperTransformLayer, and llvm::orc::ThreadSafeModule::withModuleDo().

Referenced by addIRModule().

◆ addIRModule() [3/3]

Error llvm::orc::LLJIT::addIRModule ( ThreadSafeModule  TSM)
inline

Adds an IR module to the Main JITDylib.

Definition at line 140 of file LLJIT.h.

References addIRModule(), and Main.

◆ addObjectFile() [1/3]

Error llvm::orc::LLJIT::addObjectFile ( JITDylib JD,
std::unique_ptr< MemoryBuffer Obj 
)

Adds an object file to the given JITDylib.

Definition at line 915 of file LLJIT.cpp.

References addObjectFile(), and llvm::orc::JITDylib::getDefaultResourceTracker().

◆ addObjectFile() [2/3]

Error llvm::orc::LLJIT::addObjectFile ( ResourceTrackerSP  RT,
std::unique_ptr< MemoryBuffer Obj 
)

Adds an object file to the given JITDylib.

Definition at line 908 of file LLJIT.cpp.

References assert(), and ObjTransformLayer.

Referenced by addObjectFile().

◆ addObjectFile() [3/3]

Error llvm::orc::LLJIT::addObjectFile ( std::unique_ptr< MemoryBuffer Obj)
inline

Adds an object file to the given JITDylib.

Definition at line 151 of file LLJIT.h.

References addObjectFile(), and Main.

◆ applyDataLayout()

Error llvm::orc::LLJIT::applyDataLayout ( Module M)
protected

◆ createCompileFunction()

Expected< std::unique_ptr< IRCompileLayer::IRCompiler > > llvm::orc::LLJIT::createCompileFunction ( LLJITBuilderState S,
JITTargetMachineBuilder  JTMB 
)
staticprotected

If there is a custom compile function creator set then use it.

Definition at line 959 of file LLJIT.cpp.

References llvm::orc::LLJITBuilderState::CreateCompileFunction, llvm::orc::JITTargetMachineBuilder::createTargetMachine(), llvm::orc::LLJITBuilderState::SupportConcurrentCompilation, and TM.

Referenced by LLJIT().

◆ createJITDylib()

Expected< JITDylib & > llvm::orc::LLJIT::createJITDylib ( std::string  Name)

Create a new JITDylib with the given name and return a reference to it.

JITDylib names must be unique. If the given name is derived from user input or elsewhere in the environment then the client should check (e.g. by calling getJITDylibByName) that the given name is not already in use.

Definition at line 850 of file LLJIT.cpp.

References llvm::orc::JITDylib::addToLinkOrder(), DefaultLinks, ES, and Name.

Referenced by LLJIT().

◆ createObjectLinkingLayer()

Expected< std::unique_ptr< ObjectLayer > > llvm::orc::LLJIT::createObjectLinkingLayer ( LLJITBuilderState S,
ExecutionSession ES 
)
staticprotected

◆ defaultLinkOrder()

JITDylibSearchOrder llvm::orc::LLJIT::defaultLinkOrder ( )
inline

Returns the default link order for this LLJIT instance.

This link order will be appended to the link order of JITDylibs created by LLJIT's createJITDylib method.

Definition at line 131 of file LLJIT.h.

References DefaultLinks.

◆ deinitialize()

Error llvm::orc::LLJIT::deinitialize ( JITDylib JD)
inline

Run the deinitializers for the given JITDylib.

Definition at line 203 of file LLJIT.h.

References assert(), llvm::dbgs(), DEBUG_WITH_TYPE, llvm::jitlink::JITLinkDylib::getName(), and PS.

◆ getDataLayout()

const DataLayout & llvm::orc::LLJIT::getDataLayout ( ) const
inline

Returns a reference to the DataLayout for this instance.

Definition at line 69 of file LLJIT.h.

References DL.

◆ getExecutionSession()

ExecutionSession & llvm::orc::LLJIT::getExecutionSession ( )
inline

◆ getIRCompileLayer()

IRCompileLayer & llvm::orc::LLJIT::getIRCompileLayer ( )
inline

Returns a reference to the IR compile layer.

Definition at line 222 of file LLJIT.h.

References CompileLayer.

◆ getIRTransformLayer()

IRTransformLayer & llvm::orc::LLJIT::getIRTransformLayer ( )
inline

Returns a reference to the IR transform layer.

Definition at line 219 of file LLJIT.h.

References TransformLayer.

◆ getJITDylibByName()

JITDylib * llvm::orc::LLJIT::getJITDylibByName ( StringRef  Name)
inline

Returns the JITDylib with the given name, or nullptr if no JITDylib with that name exists.

Definition at line 90 of file LLJIT.h.

References ES, and Name.

◆ getMainJITDylib()

JITDylib & llvm::orc::LLJIT::getMainJITDylib ( )
inline

Returns a reference to the JITDylib representing the JIT'd main program.

Definition at line 72 of file LLJIT.h.

References Main.

Referenced by llvm::orc::ORCPlatformSupport::deinitialize(), and llvm::orc::ORCPlatformSupport::initialize().

◆ getObjLinkingLayer()

ObjectLayer & llvm::orc::LLJIT::getObjLinkingLayer ( )
inline

Returns a reference to the ObjLinkingLayer.

Definition at line 213 of file LLJIT.h.

References ObjLinkingLayer.

Referenced by llvm::orc::enableDebuggerSupport(), and llvm::orc::ExecutorNativePlatform::operator()().

◆ getObjTransformLayer()

ObjectTransformLayer & llvm::orc::LLJIT::getObjTransformLayer ( )
inline

Returns a reference to the object transform layer.

Definition at line 216 of file LLJIT.h.

References ObjTransformLayer.

◆ getPlatformJITDylib()

JITDylibSP llvm::orc::LLJIT::getPlatformJITDylib ( )

Returns the Platform JITDylib, which will contain the ORC runtime (if given) and any platform symbols.

Note: JIT'd code should not be added to the Platform JITDylib. Use the main JITDylib or a custom JITDylib instead.

Definition at line 848 of file LLJIT.cpp.

References Platform.

◆ getPlatformSupport()

PlatformSupport * llvm::orc::LLJIT::getPlatformSupport ( )
inline

Get the PlatformSupport instance.

Definition at line 190 of file LLJIT.h.

References PS.

◆ getProcessSymbolsJITDylib()

JITDylibSP llvm::orc::LLJIT::getProcessSymbolsJITDylib ( )

Returns the ProcessSymbols JITDylib, which by default reflects non-JIT'd symbols in the host process.

Note: JIT'd code should not be added to the ProcessSymbols JITDylib. Use the main JITDylib or a custom JITDylib instead.

Definition at line 846 of file LLJIT.cpp.

References ProcessSymbols.

Referenced by llvm::orc::enableDebuggerSupport(), and llvm::orc::ExecutorNativePlatform::operator()().

◆ getTargetTriple()

const Triple & llvm::orc::LLJIT::getTargetTriple ( ) const
inline

Returns a reference to the triple for this instance.

Definition at line 66 of file LLJIT.h.

References TT.

Referenced by llvm::orc::enableDebuggerSupport(), and llvm::orc::ExecutorNativePlatform::operator()().

◆ initialize()

Error llvm::orc::LLJIT::initialize ( JITDylib JD)
inline

Run the initializers for the given JITDylib.

Definition at line 193 of file LLJIT.h.

References assert(), llvm::dbgs(), DEBUG_WITH_TYPE, llvm::jitlink::JITLinkDylib::getName(), and PS.

◆ linkStaticLibraryInto() [1/2]

Error llvm::orc::LLJIT::linkStaticLibraryInto ( JITDylib JD,
const char Path 
)

Link a static library into the given JITDylib.

If the given host path contains a valid static archive (or a universal binary with an archive slice that fits the LLJIT instance's platform / architecture) then it will be added to the given JITDylib using a StaticLibraryDefinitionGenerator.

Definition at line 884 of file LLJIT.cpp.

References llvm::orc::JITDylib::addGenerator(), G, llvm::orc::StaticLibraryDefinitionGenerator::Load(), ObjLinkingLayer, and llvm::Error::success().

◆ linkStaticLibraryInto() [2/2]

Error llvm::orc::LLJIT::linkStaticLibraryInto ( JITDylib JD,
std::unique_ptr< MemoryBuffer LibBuffer 
)

Link a static library into the given JITDylib.

If the given MemoryBuffer contains a valid static archive (or a universal binary with an archive slice that fits the LLJIT instance's platform / architecture) then it will be added to the given JITDylib using a StaticLibraryDefinitionGenerator.

Definition at line 872 of file LLJIT.cpp.

References llvm::orc::JITDylib::addGenerator(), llvm::orc::StaticLibraryDefinitionGenerator::Create(), G, ObjLinkingLayer, and llvm::Error::success().

◆ loadPlatformDynamicLibrary()

Expected< JITDylib & > llvm::orc::LLJIT::loadPlatformDynamicLibrary ( const char Path)

Load a (real) dynamic library and make its symbols available through a new JITDylib with the same name.

If the given executor path contains a valid platform dynamic library then that library will be loaded, and a new bare JITDylib whose name is the given path will be created to make the library's symbols available to JIT'd code.

Definition at line 859 of file LLJIT.cpp.

References llvm::orc::JITDylib::addGenerator(), ES, G, and llvm::orc::EPCDynamicLibrarySearchGenerator::Load().

Referenced by llvm::orc::LoadAndLinkDynLibrary::operator()().

◆ lookup() [1/2]

Expected< ExecutorAddr > llvm::orc::LLJIT::lookup ( JITDylib JD,
StringRef  UnmangledName 
)
inline

Look up a symbol in JITDylib JD based on its IR symbol name.

Definition at line 175 of file LLJIT.h.

References lookupLinkerMangled(), and mangle().

Referenced by lookup().

◆ lookup() [2/2]

Expected< ExecutorAddr > llvm::orc::LLJIT::lookup ( StringRef  UnmangledName)
inline

Look up a symbol in the main JITDylib based on its IR symbol name.

Definition at line 180 of file LLJIT.h.

References lookup(), and Main.

◆ lookupLinkerMangled() [1/3]

Expected< ExecutorAddr > llvm::orc::LLJIT::lookupLinkerMangled ( JITDylib JD,
StringRef  Name 
)
inline

Look up a symbol in JITDylib JD by the symbol's linker-mangled name (to look up symbols based on their IR name use the lookup function instead).

Definition at line 162 of file LLJIT.h.

References ES, lookupLinkerMangled(), and Name.

◆ lookupLinkerMangled() [2/3]

Expected< ExecutorAddr > llvm::orc::LLJIT::lookupLinkerMangled ( JITDylib JD,
SymbolStringPtr  Name 
)

Look up a symbol in JITDylib JD by the symbol's linker-mangled name (to look up symbols based on their IR name use the lookup function instead).

Definition at line 919 of file LLJIT.cpp.

References ES, llvm::orc::makeJITDylibSearchOrder(), llvm::orc::MatchAllSymbols, Name, and Sym.

Referenced by lookup(), and lookupLinkerMangled().

◆ lookupLinkerMangled() [3/3]

Expected< ExecutorAddr > llvm::orc::LLJIT::lookupLinkerMangled ( StringRef  Name)
inline

Look up a symbol in the main JITDylib by the symbol's linker-mangled name (to look up symbols based on their IR name use the lookup function instead).

Definition at line 170 of file LLJIT.h.

References lookupLinkerMangled(), Main, and Name.

◆ mangle()

std::string llvm::orc::LLJIT::mangle ( StringRef  UnmangledName) const

Returns a linker-mangled version of UnmangledName.

Definition at line 1063 of file LLJIT.cpp.

References DL, and llvm::Mangler::getNameWithPrefix().

Referenced by lookup(), and mangleAndIntern().

◆ mangleAndIntern()

SymbolStringPtr llvm::orc::LLJIT::mangleAndIntern ( StringRef  UnmangledName) const
inline

Returns an interned, linker-mangled version of UnmangledName.

Definition at line 228 of file LLJIT.h.

References ES, and mangle().

Referenced by llvm::orc::ORCPlatformSupport::deinitialize(), and llvm::orc::ORCPlatformSupport::initialize().

◆ recordCtorDtors()

void llvm::orc::LLJIT::recordCtorDtors ( Module M)
protected

◆ setPlatformSupport()

void llvm::orc::LLJIT::setPlatformSupport ( std::unique_ptr< PlatformSupport PS)
inline

Friends And Related Function Documentation

◆ LLJITBuilderSetters

template<typename , typename , typename >
friend class LLJITBuilderSetters
friend

Definition at line 39 of file LLJIT.h.

◆ setUpGenericLLVMIRPlatform

Expected< JITDylibSP > setUpGenericLLVMIRPlatform ( LLJIT J)
friend

Configure the LLJIT instance to scrape modules for llvm.global_ctors and llvm.global_dtors variables and (if present) build initialization and deinitialization functions.

Platform specific initialization configurations should be preferred where available.

Definition at line 1193 of file LLJIT.cpp.

Referenced by LLJIT().

Member Data Documentation

◆ CompileLayer

std::unique_ptr<IRCompileLayer> llvm::orc::LLJIT::CompileLayer
protected

Definition at line 260 of file LLJIT.h.

Referenced by getIRCompileLayer(), and LLJIT().

◆ DefaultLinks

JITDylibSearchOrder llvm::orc::LLJIT::DefaultLinks
protected

Definition at line 253 of file LLJIT.h.

Referenced by createJITDylib(), defaultLinkOrder(), and LLJIT().

◆ DL

DataLayout llvm::orc::LLJIT::DL
protected

◆ ES

std::unique_ptr<ExecutionSession> llvm::orc::LLJIT::ES
protected

◆ InitHelperTransformLayer

std::unique_ptr<IRTransformLayer> llvm::orc::LLJIT::InitHelperTransformLayer
protected

◆ Main

JITDylib* llvm::orc::LLJIT::Main = nullptr
protected

◆ ObjLinkingLayer

std::unique_ptr<ObjectLayer> llvm::orc::LLJIT::ObjLinkingLayer
protected

◆ ObjTransformLayer

std::unique_ptr<ObjectTransformLayer> llvm::orc::LLJIT::ObjTransformLayer
protected

Definition at line 259 of file LLJIT.h.

Referenced by addObjectFile(), getObjTransformLayer(), and LLJIT().

◆ Platform

JITDylib* llvm::orc::LLJIT::Platform = nullptr
protected

Definition at line 250 of file LLJIT.h.

Referenced by getPlatformJITDylib(), and LLJIT().

◆ ProcessSymbols

JITDylib* llvm::orc::LLJIT::ProcessSymbols = nullptr
protected

Definition at line 249 of file LLJIT.h.

Referenced by getProcessSymbolsJITDylib(), and LLJIT().

◆ PS

std::unique_ptr<PlatformSupport> llvm::orc::LLJIT::PS
protected

Definition at line 247 of file LLJIT.h.

Referenced by deinitialize(), getPlatformSupport(), initialize(), and setPlatformSupport().

◆ TransformLayer

std::unique_ptr<IRTransformLayer> llvm::orc::LLJIT::TransformLayer
protected

Definition at line 261 of file LLJIT.h.

Referenced by getIRTransformLayer(), and LLJIT().

◆ TT

Triple llvm::orc::LLJIT::TT
protected

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