13#ifndef LLVM_EXECUTIONENGINE_ORC_LLJIT_H
14#define LLVM_EXECUTIONENGINE_ORC_LLJIT_H
30class LLJITBuilderState;
31class LLLazyJITBuilderState;
32class ObjectTransformLayer;
33class ExecutorProcessControl;
91 return ES->getJITDylibByName(
Name);
110 std::unique_ptr<MemoryBuffer> LibBuffer);
186 this->PS = std::move(
PS);
195 dbgs() <<
"LLJIT running initializers for JITDylib \"" << JD.
getName()
198 assert(
PS &&
"PlatformSupport must be set to run initializers.");
199 return PS->initialize(JD);
205 dbgs() <<
"LLJIT running deinitializers for JITDylib \"" << JD.
getName()
208 assert(
PS &&
"PlatformSupport must be set to run initializers.");
209 return PS->deinitialize(JD);
229 return ES->intern(
mangle(UnmangledName));
246 std::unique_ptr<ExecutionSession>
ES;
247 std::unique_ptr<PlatformSupport>
PS;
275 CODLayer->setPartitionFunction(std::move(Partition));
294 std::unique_ptr<LazyCallThroughManager> LCTMgr;
295 std::unique_ptr<CompileOnDemandLayer> CODLayer;
305 std::function<Expected<std::unique_ptr<IRCompileLayer::IRCompiler>>(
315 std::unique_ptr<ExecutorProcessControl>
EPC;
316 std::unique_ptr<ExecutionSession>
ES;
317 std::optional<JITTargetMachineBuilder>
JTMB;
318 std::optional<DataLayout>
DL;
333template <
typename JITType,
typename SetterImpl,
typename State>
342 "setExecutorProcessControl should not be called if an ExecutionSession "
343 "has already been set");
344 impl().EPC = std::move(EPC);
352 "setExecutionSession should not be called if an ExecutorProcessControl "
353 "object has already been set");
354 impl().ES = std::move(ES);
363 impl().JTMB = std::move(JTMB);
376 impl().DL = std::move(
DL);
387 impl().LinkProcessSymbolsByDefault = LinkProcessSymbolsByDefault;
397 SetupProcessSymbolsJITDylib) {
398 impl().SetupProcessSymbolsJITDylib = std::move(SetupProcessSymbolsJITDylib);
408 impl().CreateObjectLinkingLayer = std::move(CreateObjectLinkingLayer);
420 impl().CreateCompileFunction = std::move(CreateCompileFunction);
433 impl().PrePlatformSetup = std::move(PrePlatformSetup);
443 impl().SetUpPlatform = std::move(SetUpPlatform);
453 impl().NotifyCreated = std::move(Callback);
470 impl().NumCompileThreads = NumCompileThreads;
483 std::optional<bool> SupportConcurrentCompilation) {
484 impl().SupportConcurrentCompilation = SupportConcurrentCompilation;
490 if (
auto Err =
impl().prepareForConstruction())
491 return std::move(Err);
494 std::unique_ptr<JITType> J(
new JITType(
impl(), Err));
496 return std::move(Err);
498 if (
impl().NotifyCreated)
499 if (
Error Err =
impl().NotifyCreated(*J))
500 return std::move(Err);
506 SetterImpl &
impl() {
return static_cast<SetterImpl &
>(*this); }
519 std::function<std::unique_ptr<IndirectStubsManager>()>;
523 std::unique_ptr<LazyCallThroughManager>
LCTMgr;
529template <
typename JITType,
typename SetterImpl,
typename State>
537 this->
impl().LazyCompileFailureAddr =
Addr;
547 this->
impl().LCTMgr = std::move(LCTMgr);
557 this->
impl().ISMBuilder = std::move(ISMBuilder);
566 LLLazyJITBuilderState> {};
578 : OrcRuntime(
std::
move(OrcRuntimePath)) {}
582 : OrcRuntime(
std::
move(OrcRuntimeMB)) {}
588 bool StaticVCRuntime) {
589 VCRuntime = {std::move(VCRuntimePath), StaticVCRuntime};
596 std::variant<std::string, std::unique_ptr<MemoryBuffer>> OrcRuntime;
597 std::optional<std::pair<std::string, bool>> VCRuntime;
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.
Represents a JIT'd dynamic library.
A utility class for building TargetMachines for JITs.
SetterImpl & setLinkProcessSymbolsByDefault(bool LinkProcessSymbolsByDefault)
The LinkProcessSymbolsDyDefault flag determines whether the "Process" JITDylib will be added to the d...
SetterImpl & setNotifyCreatedCallback(LLJITBuilderState::NotifyCreatedFunction Callback)
Set up a callback after successful construction of the JIT.
std::optional< JITTargetMachineBuilder > & getJITTargetMachineBuilder()
Return a reference to the JITTargetMachineBuilder.
SetterImpl & setPrePlatformSetup(unique_function< Error(LLJIT &)> PrePlatformSetup)
Set a setup function to be run just before the PlatformSetupFunction is run.
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 an 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.
SetterImpl & setSupportConcurrentCompilation(std::optional< bool > SupportConcurrentCompilation)
If set, this forces LLJIT concurrent compilation support to be either on or off.
SetterImpl & setProcessSymbolsJITDylibSetup(LLJITBuilderState::ProcessSymbolsJITDylibSetupFunction SetupProcessSymbolsJITDylib)
Set a setup function for the process symbols dylib.
Error prepareForConstruction()
Called prior to JIT class construcion to fix up defaults.
ProcessSymbolsJITDylibSetupFunction SetupProcessSymbolsJITDylib
ObjectLinkingLayerCreator CreateObjectLinkingLayer
std::function< Expected< std::unique_ptr< IRCompileLayer::IRCompiler > >(JITTargetMachineBuilder JTMB)> CompileFunctionCreator
unsigned NumCompileThreads
std::function< Error(LLJIT &)> NotifyCreatedFunction
std::unique_ptr< ExecutionSession > ES
unique_function< Error(LLJIT &)> PrePlatformSetup
std::function< Expected< std::unique_ptr< ObjectLayer > >(ExecutionSession &, const Triple &)> ObjectLinkingLayerCreator
CompileFunctionCreator CreateCompileFunction
std::optional< bool > SupportConcurrentCompilation
bool LinkProcessSymbolsByDefault
std::unique_ptr< ExecutorProcessControl > EPC
std::optional< DataLayout > DL
std::optional< JITTargetMachineBuilder > JTMB
PlatformSetupFunction SetUpPlatform
NotifyCreatedFunction NotifyCreated
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.
JITDylibSearchOrder DefaultLinks
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
friend Expected< JITDylibSP > setUpGenericLLVMIRPlatform(LLJIT &J)
Configure the LLJIT instance to scrape modules for llvm.global_ctors and llvm.global_dtors variables ...
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.
JITDylibSP getPlatformJITDylib()
Returns the Platform JITDylib, which will contain the ORC runtime (if given) and any platform symbols...
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.
JITDylibSP getProcessSymbolsJITDylib()
Returns the ProcessSymbols JITDylib, which by default reflects non-JIT'd symbols in the host process.
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.
JITDylib * ProcessSymbols
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.
Error applyDataLayout(Module &M)
std::unique_ptr< ObjectLayer > ObjLinkingLayer
std::unique_ptr< PlatformSupport > PS
JITDylibSearchOrder defaultLinkOrder()
Returns the default link order for this LLJIT instance.
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.
std::vector< std::pair< JITDylib *, JITDylibLookupFlags > > JITDylibSearchOrder
A list of (JITDylib*, JITDylibLookupFlags) pairs to be used as a search order during symbol lookup.
Expected< JITDylibSP > setUpInactivePlatform(LLJIT &J)
Configure the LLJIT instance to disable platform support explicitly.
Expected< JITDylibSP > setUpGenericLLVMIRPlatform(LLJIT &J)
Configure the LLJIT instance to scrape modules for llvm.global_ctors and llvm.global_dtors variables ...
Error setUpOrcPlatformManually(LLJIT &J)
Configure the LLJIT instance to use orc runtime support.
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.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.