13#ifndef LLVM_EXECUTIONENGINE_ORC_LLJIT_H
14#define LLVM_EXECUTIONENGINE_ORC_LLJIT_H
29class LLJITBuilderState;
30class LLLazyJITBuilderState;
31class ObjectTransformLayer;
32class ExecutorProcessControl;
76 return ES->getJITDylibByName(
Name);
95 std::unique_ptr<MemoryBuffer> LibBuffer);
112 return ES->createJITDylib(std::move(
Name));
168 this->PS = std::move(
PS);
177 dbgs() <<
"LLJIT running initializers for JITDylib \"" << JD.
getName()
180 assert(
PS &&
"PlatformSupport must be set to run initializers.");
181 return PS->initialize(JD);
187 dbgs() <<
"LLJIT running deinitializers for JITDylib \"" << JD.
getName()
190 assert(
PS &&
"PlatformSupport must be set to run initializers.");
191 return PS->deinitialize(JD);
211 return ES->intern(
mangle(UnmangledName));
228 std::unique_ptr<ExecutionSession>
ES;
229 std::unique_ptr<PlatformSupport>
PS;
254 CODLayer->setPartitionFunction(std::move(Partition));
273 std::unique_ptr<LazyCallThroughManager> LCTMgr;
274 std::unique_ptr<CompileOnDemandLayer> CODLayer;
284 std::function<Expected<std::unique_ptr<IRCompileLayer::IRCompiler>>(
289 std::unique_ptr<ExecutorProcessControl>
EPC;
290 std::unique_ptr<ExecutionSession>
ES;
291 std::optional<JITTargetMachineBuilder>
JTMB;
292 std::optional<DataLayout>
DL;
302template <
typename JITType,
typename SetterImpl,
typename State>
311 "setExecutorProcessControl should not be called if an ExecutionSession "
312 "has already been set");
313 impl().EPC = std::move(EPC);
319 impl().ES = std::move(ES);
328 impl().JTMB = std::move(JTMB);
341 impl().DL = std::move(
DL);
351 impl().CreateObjectLinkingLayer = std::move(CreateObjectLinkingLayer);
363 impl().CreateCompileFunction = std::move(CreateCompileFunction);
373 impl().SetUpPlatform = std::move(SetUpPlatform);
386 impl().NumCompileThreads = NumCompileThreads;
403 if (
auto Err =
impl().prepareForConstruction())
404 return std::move(Err);
407 std::unique_ptr<JITType> J(
new JITType(
impl(), Err));
409 return std::move(Err);
414 SetterImpl &
impl() {
return static_cast<SetterImpl &
>(*this); }
427 std::function<std::unique_ptr<IndirectStubsManager>()>;
431 std::unique_ptr<LazyCallThroughManager>
LCTMgr;
437template <
typename JITType,
typename SetterImpl,
typename State>
445 this->
impl().LazyCompileFailureAddr =
Addr;
455 this->
impl().LCTMgr = std::move(LCTMgr);
465 this->
impl().ISMBuilder = std::move(ISMBuilder);
474 LLLazyJITBuilderState> {};
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define DEBUG_WITH_TYPE(TYPE, X)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A parsed version of the target data layout string in and methods for querying it.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
A Module instance is used to store all the information related to an LLVM module.
StringRef - Represent a constant reference to a string, i.e.
Triple - Helper class for working with autoconf configuration names.
const std::string & getName() const
Get the name for this JITLinkDylib.
std::function< std::optional< GlobalValueSet >(GlobalValueSet Requested)> PartitionFunction
Partitioning function.
An ExecutionSession represents a running JIT program.
Represents an address in the executor process.
ExecutorProcessControl supports interaction with a JIT target process.
Represents a JIT'd dynamic library.
A utility class for building TargetMachines for JITs.
SetterImpl & setExecutorProcessControl(ExecutorProcessControl &EPC)
Set an ExecutorProcessControl object.
std::optional< JITTargetMachineBuilder > & getJITTargetMachineBuilder()
Return a reference to the JITTargetMachineBuilder.
SetterImpl & setCompileFunctionCreator(LLJITBuilderState::CompileFunctionCreator CreateCompileFunction)
Set a CompileFunctionCreator.
SetterImpl & setNumCompileThreads(unsigned NumCompileThreads)
Set the number of compile threads to use.
SetterImpl & setDataLayout(std::optional< DataLayout > DL)
Set a DataLayout for this instance.
SetterImpl & setJITTargetMachineBuilder(JITTargetMachineBuilder JTMB)
Set the JITTargetMachineBuilder for this instance.
SetterImpl & setExecutorProcessControl(std::unique_ptr< ExecutorProcessControl > EPC)
Set a ExecutorProcessControl for this instance.
SetterImpl & setObjectLinkingLayerCreator(LLJITBuilderState::ObjectLinkingLayerCreator CreateObjectLinkingLayer)
Set an ObjectLinkingLayer creation function.
SetterImpl & setPlatformSetUp(LLJITBuilderState::PlatformSetupFunction SetUpPlatform)
Set up an PlatformSetupFunction.
Expected< std::unique_ptr< JITType > > create()
Create an instance of the JIT.
SetterImpl & setExecutionSession(std::unique_ptr< ExecutionSession > ES)
Set an ExecutionSession for this instance.
Error prepareForConstruction()
Called prior to JIT class construcion to fix up defaults.
ObjectLinkingLayerCreator CreateObjectLinkingLayer
std::function< Expected< std::unique_ptr< IRCompileLayer::IRCompiler > >(JITTargetMachineBuilder JTMB)> CompileFunctionCreator
unsigned NumCompileThreads
std::function< Error(LLJIT &J)> PlatformSetupFunction
std::unique_ptr< ExecutionSession > ES
std::function< Expected< std::unique_ptr< ObjectLayer > >(ExecutionSession &, const Triple &)> ObjectLinkingLayerCreator
CompileFunctionCreator CreateCompileFunction
std::unique_ptr< ExecutorProcessControl > EPC
std::optional< DataLayout > DL
std::optional< JITTargetMachineBuilder > JTMB
PlatformSetupFunction SetUpPlatform
Constructs LLJIT instances.
A pre-fabricated ORC JIT stack that can serve as an alternative to MCJIT.
static Expected< std::unique_ptr< ObjectLayer > > createObjectLinkingLayer(LLJITBuilderState &S, ExecutionSession &ES)
void setPlatformSupport(std::unique_ptr< PlatformSupport > PS)
Set the PlatformSupport instance.
std::unique_ptr< ExecutionSession > ES
Error addObjectFile(ResourceTrackerSP RT, std::unique_ptr< MemoryBuffer > Obj)
Adds an object file to the given JITDylib.
Expected< JITDylib & > createJITDylib(std::string Name)
Create a new JITDylib with the given name and return a reference to it.
JITDylib & getMainJITDylib()
Returns a reference to the JITDylib representing the JIT'd main program.
const DataLayout & getDataLayout() const
Returns a reference to the DataLayout for this instance.
void recordCtorDtors(Module &M)
Error initialize(JITDylib &JD)
Run the initializers for the given JITDylib.
Error addIRModule(ThreadSafeModule TSM)
Adds an IR module to the Main JITDylib.
ObjectLayer & getObjLinkingLayer()
Returns a reference to the ObjLinkingLayer.
Expected< ExecutorAddr > lookupLinkerMangled(JITDylib &JD, StringRef Name)
Look up a symbol in JITDylib JD by the symbol's linker-mangled name (to look up symbols based on thei...
IRCompileLayer & getIRCompileLayer()
Returns a reference to the IR compile layer.
std::unique_ptr< ObjectTransformLayer > ObjTransformLayer
virtual ~LLJIT()
Destruct this instance.
IRTransformLayer & getIRTransformLayer()
Returns a reference to the IR transform layer.
std::string mangle(StringRef UnmangledName) const
Returns a linker-mangled version of UnmangledName.
Expected< ExecutorAddr > lookup(JITDylib &JD, StringRef UnmangledName)
Look up a symbol in JITDylib JD based on its IR symbol name.
Expected< JITDylib & > loadPlatformDynamicLibrary(const char *Path)
Load a (real) dynamic library and make its symbols available through a new JITDylib with the same nam...
std::unique_ptr< IRTransformLayer > InitHelperTransformLayer
Error deinitialize(JITDylib &JD)
Run the deinitializers for the given JITDylib.
std::unique_ptr< IRCompileLayer > CompileLayer
Expected< ExecutorAddr > lookup(StringRef UnmangledName)
Look up a symbol in the main JITDylib based on its IR symbol name.
const Triple & getTargetTriple() const
Returns a reference to the triple for this instance.
Expected< ExecutorAddr > 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 thei...
static Expected< std::unique_ptr< IRCompileLayer::IRCompiler > > createCompileFunction(LLJITBuilderState &S, JITTargetMachineBuilder JTMB)
PlatformSupport * getPlatformSupport()
Get the PlatformSupport instance.
ExecutionSession & getExecutionSession()
Returns the ExecutionSession for this instance.
std::unique_ptr< IRTransformLayer > TransformLayer
SymbolStringPtr mangleAndIntern(StringRef UnmangledName) const
Returns an interned, linker-mangled version of UnmangledName.
Error addObjectFile(std::unique_ptr< MemoryBuffer > Obj)
Adds an object file to the given JITDylib.
Error linkStaticLibraryInto(JITDylib &JD, std::unique_ptr< MemoryBuffer > LibBuffer)
Link a static library into the given JITDylib.
friend void setUpGenericLLVMIRPlatform(LLJIT &J)
Configure the LLJIT instance to scrape modules for llvm.global_ctors and llvm.global_dtors variables ...
Error applyDataLayout(Module &M)
std::unique_ptr< ThreadPool > CompileThreads
std::unique_ptr< ObjectLayer > ObjLinkingLayer
std::unique_ptr< PlatformSupport > PS
JITDylib * getJITDylibByName(StringRef Name)
Returns the JITDylib with the given name, or nullptr if no JITDylib with that name exists.
ObjectTransformLayer & getObjTransformLayer()
Returns a reference to the object transform layer.
Error addIRModule(ResourceTrackerSP RT, ThreadSafeModule TSM)
Adds an IR module with the given ResourceTracker.
Expected< ExecutorAddr > lookupLinkerMangled(StringRef Name)
Look up a symbol in the main JITDylib by the symbol's linker-mangled name (to look up symbols based o...
SetterImpl & setLazyCompileFailureAddr(ExecutorAddr Addr)
Set the address in the target address to call if a lazy compile fails.
SetterImpl & setLazyCallthroughManager(std::unique_ptr< LazyCallThroughManager > LCTMgr)
Set the lazy-callthrough manager.
SetterImpl & setIndirectStubsManagerBuilder(LLLazyJITBuilderState::IndirectStubsManagerBuilderFunction ISMBuilder)
Set the IndirectStubsManager builder function.
ExecutorAddr LazyCompileFailureAddr
std::unique_ptr< LazyCallThroughManager > LCTMgr
std::function< std::unique_ptr< IndirectStubsManager >()> IndirectStubsManagerBuilderFunction
Error prepareForConstruction()
IndirectStubsManagerBuilderFunction ISMBuilder
Constructs LLLazyJIT instances.
An extended version of LLJIT that supports lazy function-at-a-time compilation of LLVM IR.
void setPartitionFunction(CompileOnDemandLayer::PartitionFunction Partition)
Sets the partition function.
Error addLazyIRModule(ThreadSafeModule M)
Add a module to be lazily compiled to the main JITDylib.
CompileOnDemandLayer & getCompileOnDemandLayer()
Returns a reference to the on-demand layer.
Error addLazyIRModule(JITDylib &JD, ThreadSafeModule M)
Add a module to be lazily compiled to JITDylib JD.
Interface for Layers that accept object files.
Pointer to a pooled string representing a symbol name.
An LLVM Module together with a shared ThreadSafeContext.
Error setUpOrcPlatform(LLJIT &J)
Configure the LLJIT instance to use orc runtime support.
void setUpGenericLLVMIRPlatform(LLJIT &J)
Configure the LLJIT instance to scrape modules for llvm.global_ctors and llvm.global_dtors variables ...
Error setUpInactivePlatform(LLJIT &J)
Configure the LLJIT instance to disable platform support explicitly.
This is an optimization pass for GlobalISel generic memory operations.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.