13#ifndef LLVM_EXECUTIONENGINE_ORC_LLJIT_H
14#define LLVM_EXECUTIONENGINE_ORC_LLJIT_H
33class LLJITBuilderState;
34class LLLazyJITBuilderState;
35class ObjectTransformLayer;
36class ExecutorProcessControl;
94 return ES->getJITDylibByName(
Name);
113 std::unique_ptr<MemoryBuffer> LibBuffer);
189 this->PS = std::move(
PS);
198 dbgs() <<
"LLJIT running initializers for JITDylib \"" << JD.
getName()
201 assert(
PS &&
"PlatformSupport must be set to run initializers.");
202 return PS->initialize(JD);
208 dbgs() <<
"LLJIT running deinitializers for JITDylib \"" << JD.
getName()
211 assert(
PS &&
"PlatformSupport must be set to run initializers.");
212 return PS->deinitialize(JD);
232 return ES->intern(
mangle(UnmangledName));
249 std::unique_ptr<ExecutionSession>
ES;
250 std::unique_ptr<PlatformSupport>
PS;
277 IPLayer->setPartitionFunction(std::move(Partition));
296 std::unique_ptr<LazyCallThroughManager> LCTMgr;
297 std::unique_ptr<IRPartitionLayer> IPLayer;
298 std::unique_ptr<CompileOnDemandLayer> CODLayer;
308 std::function<Expected<std::unique_ptr<IRCompileLayer::IRCompiler>>(
318 std::unique_ptr<ExecutorProcessControl>
EPC;
319 std::unique_ptr<ExecutionSession>
ES;
320 std::optional<JITTargetMachineBuilder>
JTMB;
321 std::optional<DataLayout>
DL;
336template <
typename JITType,
typename SetterImpl,
typename State>
345 "setExecutorProcessControl should not be called if an ExecutionSession "
346 "has already been set");
347 impl().EPC = std::move(EPC);
355 "setExecutionSession should not be called if an ExecutorProcessControl "
356 "object has already been set");
357 impl().ES = std::move(ES);
366 impl().JTMB = std::move(JTMB);
379 impl().DL = std::move(
DL);
390 impl().LinkProcessSymbolsByDefault = LinkProcessSymbolsByDefault;
400 SetupProcessSymbolsJITDylib) {
401 impl().SetupProcessSymbolsJITDylib = std::move(SetupProcessSymbolsJITDylib);
411 impl().CreateObjectLinkingLayer = std::move(CreateObjectLinkingLayer);
423 impl().CreateCompileFunction = std::move(CreateCompileFunction);
436 impl().PrePlatformSetup = std::move(PrePlatformSetup);
446 impl().SetUpPlatform = std::move(SetUpPlatform);
456 impl().NotifyCreated = std::move(Callback);
473 impl().NumCompileThreads = NumCompileThreads;
486 std::optional<bool> SupportConcurrentCompilation) {
487 impl().SupportConcurrentCompilation = SupportConcurrentCompilation;
493 if (
auto Err =
impl().prepareForConstruction())
494 return std::move(Err);
497 std::unique_ptr<JITType> J(
new JITType(
impl(), Err));
499 return std::move(Err);
501 if (
impl().NotifyCreated)
502 if (
Error Err =
impl().NotifyCreated(*J))
503 return std::move(Err);
509 SetterImpl &
impl() {
return static_cast<SetterImpl &
>(*this); }
522 std::function<std::unique_ptr<IndirectStubsManager>()>;
526 std::unique_ptr<LazyCallThroughManager>
LCTMgr;
532template <
typename JITType,
typename SetterImpl,
typename State>
540 this->
impl().LazyCompileFailureAddr =
Addr;
550 this->
impl().LCTMgr = std::move(LCTMgr);
560 this->
impl().ISMBuilder = std::move(ISMBuilder);
569 LLLazyJITBuilderState> {};
581 : OrcRuntime(
std::
move(OrcRuntimePath)) {}
585 : OrcRuntime(
std::
move(OrcRuntimeMB)) {}
591 bool StaticVCRuntime) {
592 VCRuntime = {std::move(VCRuntimePath), StaticVCRuntime};
599 std::variant<std::string, std::unique_ptr<MemoryBuffer>> OrcRuntime;
600 std::optional<std::pair<std::string, bool>> VCRuntime;
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define DEBUG_WITH_TYPE(TYPE,...)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallSet class.
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.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
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.
An ExecutionSession represents a running JIT program.
Represents an address in the executor process.
std::function< std::optional< GlobalValueSet >(GlobalValueSet Requested)> PartitionFunction
Partitioning function.
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(IRPartitionLayer::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.