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);
86 return ES->createJITDylib(std::move(
Name));
142 this->PS = std::move(
PS);
151 dbgs() <<
"LLJIT running initializers for JITDylib \"" << JD.
getName()
154 assert(
PS &&
"PlatformSupport must be set to run initializers.");
155 return PS->initialize(JD);
161 dbgs() <<
"LLJIT running deinitializers for JITDylib \"" << JD.
getName()
164 assert(
PS &&
"PlatformSupport must be set to run initializers.");
165 return PS->deinitialize(JD);
185 return ES->intern(
mangle(UnmangledName));
202 std::unique_ptr<ExecutionSession>
ES;
203 std::unique_ptr<PlatformSupport>
PS;
228 CODLayer->setPartitionFunction(std::move(Partition));
247 std::unique_ptr<LazyCallThroughManager> LCTMgr;
248 std::unique_ptr<CompileOnDemandLayer> CODLayer;
258 std::function<Expected<std::unique_ptr<IRCompileLayer::IRCompiler>>(
263 std::unique_ptr<ExecutorProcessControl>
EPC;
264 std::unique_ptr<ExecutionSession>
ES;
265 std::optional<JITTargetMachineBuilder>
JTMB;
266 std::optional<DataLayout>
DL;
276template <
typename JITType,
typename SetterImpl,
typename State>
285 "setExecutorProcessControl should not be called if an ExecutionSession "
286 "has already been set");
287 impl().EPC = std::move(EPC);
293 impl().ES = std::move(ES);
302 impl().JTMB = std::move(JTMB);
315 impl().DL = std::move(
DL);
325 impl().CreateObjectLinkingLayer = std::move(CreateObjectLinkingLayer);
337 impl().CreateCompileFunction = std::move(CreateCompileFunction);
347 impl().SetUpPlatform = std::move(SetUpPlatform);
360 impl().NumCompileThreads = NumCompileThreads;
377 if (
auto Err =
impl().prepareForConstruction())
378 return std::move(Err);
381 std::unique_ptr<JITType> J(
new JITType(
impl(), Err));
383 return std::move(Err);
388 SetterImpl &
impl() {
return static_cast<SetterImpl &
>(*this); }
401 std::function<std::unique_ptr<IndirectStubsManager>()>;
405 std::unique_ptr<LazyCallThroughManager>
LCTMgr;
411template <
typename JITType,
typename SetterImpl,
typename State>
419 this->
impl().LazyCompileFailureAddr =
Addr;
429 this->
impl().LCTMgr = std::move(LCTMgr);
439 this->
impl().ISMBuilder = std::move(ISMBuilder);
448 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.
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.
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.