14#ifndef LLVM_EXECUTIONENGINE_ORC_EPCINDIRECTIONUTILS_H
15#define LLVM_EXECUTIONENGINE_ORC_EPCINDIRECTIONUTILS_H
31class EPCIndirectionUtils {
39 ABISupport(
unsigned PointerSize,
unsigned TrampolineSize,
unsigned StubSize,
40 unsigned StubToPointerMaxDisplacement,
unsigned ResolverCodeSize)
41 : PointerSize(PointerSize), TrampolineSize(TrampolineSize),
43 StubToPointerMaxDisplacement(StubToPointerMaxDisplacement),
44 ResolverCodeSize(ResolverCodeSize) {}
53 return StubToPointerMaxDisplacement;
65 unsigned NumTrampolines)
const = 0;
68 char *StubsBlockWorkingMem,
ExecutorAddr StubsBlockTargetAddress,
69 ExecutorAddr PointersBlockTargetAddress,
unsigned NumStubs)
const = 0;
72 unsigned PointerSize = 0;
73 unsigned TrampolineSize = 0;
74 unsigned StubSize = 0;
75 unsigned StubToPointerMaxDisplacement = 0;
76 unsigned ResolverCodeSize = 0;
80 template <
typename ORCABI>
81 static std::unique_ptr<EPCIndirectionUtils>
128 assert(LCTM &&
"createLazyCallThroughManager must be called first");
135 struct IndirectStubInfo {
136 IndirectStubInfo() =
default;
138 : StubAddress(StubAddress), PointerAddress(PointerAddress) {}
139 ExecutorAddr StubAddress;
140 ExecutorAddr PointerAddress;
143 using IndirectStubInfoVector = std::vector<IndirectStubInfo>;
146 EPCIndirectionUtils(ExecutorProcessControl &EPC,
147 std::unique_ptr<ABISupport> ABI);
149 Expected<IndirectStubInfoVector> getIndirectStubs(
unsigned NumStubs);
151 std::mutex EPCUIMutex;
152 ExecutorProcessControl &EPC;
153 std::unique_ptr<ABISupport> ABI;
154 ExecutorAddr ResolverBlockAddr;
155 FinalizedAlloc ResolverBlock;
156 std::unique_ptr<TrampolinePool> TP;
157 std::unique_ptr<LazyCallThroughManager> LCTM;
159 std::vector<IndirectStubInfo> AvailableIndirectStubs;
160 std::vector<FinalizedAlloc> IndirectStubAllocs;
178template <
typename ORCABI>
182 :
ABISupport(ORCABI::PointerSize, ORCABI::TrampolineSize,
183 ORCABI::StubSize, ORCABI::StubToPointerMaxDisplacement,
184 ORCABI::ResolverCodeSize) {}
190 ORCABI::writeResolverCode(ResolverWorkingMem, ResolverTargetAddr,
191 ReentryFnAddr, ReentryCtxAddr);
197 unsigned NumTrampolines)
const override {
198 ORCABI::writeTrampolines(TrampolineBlockWorkingMem,
199 TrampolineBlockTargetAddr, ResolverAddr,
206 unsigned NumStubs)
const override {
207 ORCABI::writeIndirectStubsBlock(StubsBlockWorkingMem,
208 StubsBlockTargetAddress,
209 PointersBlockTargetAddress, NumStubs);
215template <
typename ORCABI>
216std::unique_ptr<EPCIndirectionUtils>
218 return std::unique_ptr<EPCIndirectionUtils>(
new EPCIndirectionUtils(
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
Represents a finalized allocation.
virtual void writeIndirectStubsBlock(char *StubsBlockWorkingMem, ExecutorAddr StubsBlockTargetAddress, ExecutorAddr PointersBlockTargetAddress, unsigned NumStubs) const =0
ABISupport(unsigned PointerSize, unsigned TrampolineSize, unsigned StubSize, unsigned StubToPointerMaxDisplacement, unsigned ResolverCodeSize)
unsigned getStubSize() const
virtual void writeResolverCode(char *ResolverWorkingMem, ExecutorAddr ResolverTargetAddr, ExecutorAddr ReentryFnAddr, ExecutorAddr ReentryCtxAddr) const =0
unsigned getResolverCodeSize() const
virtual void writeTrampolines(char *TrampolineBlockWorkingMem, ExecutorAddr TrampolineBlockTragetAddr, ExecutorAddr ResolverAddr, unsigned NumTrampolines) const =0
unsigned getStubToPointerMaxDisplacement() const
unsigned getPointerSize() const
unsigned getTrampolineSize() const
Provides ExecutorProcessControl based indirect stubs, trampoline pool and lazy call through manager.
LLVM_ABI std::unique_ptr< IndirectStubsManager > createIndirectStubsManager()
Create an IndirectStubsManager for the executor process.
static Expected< std::unique_ptr< EPCIndirectionUtils > > Create(ExecutionSession &ES)
Create based on the ExecutorProcessControl triple.
LLVM_ABI Expected< ExecutorAddr > writeResolverBlock(ExecutorAddr ReentryFnAddr, ExecutorAddr ReentryCtxAddr)
Write resolver code to the executor process and return its address.
LazyCallThroughManager & getLazyCallThroughManager()
Create a LazyCallThroughManager for the executor process.
static std::unique_ptr< EPCIndirectionUtils > CreateWithABI(ExecutorProcessControl &EPC)
Create using the given ABI class.
ExecutorProcessControl & getExecutorProcessControl() const
Return a reference to the ExecutorProcessControl object.
LLVM_ABI LazyCallThroughManager & createLazyCallThroughManager(ExecutionSession &ES, ExecutorAddr ErrorHandlerAddr)
Create a LazyCallThroughManager.
LLVM_ABI Error cleanup()
Release memory for resources held by this instance.
LLVM_ABI TrampolinePool & getTrampolinePool()
Create a TrampolinePool for the executor process.
friend class EPCIndirectionUtilsAccess
static LLVM_ABI Expected< std::unique_ptr< EPCIndirectionUtils > > Create(ExecutorProcessControl &EPC)
Create based on the ExecutorProcessControl triple.
ABISupport & getABISupport() const
Return a reference to the ABISupport object for this instance.
ExecutorAddr getResolverBlockAddress() const
Returns the address of the Resolver block.
An ExecutionSession represents a running JIT program.
ExecutorProcessControl & getExecutorProcessControl()
Get the ExecutorProcessControl object associated with this ExecutionSession.
Represents an address in the executor process.
ExecutorProcessControl supports interaction with a JIT target process.
Manages a set of 'lazy call-through' trampolines.
Base class for pools of compiler re-entry trampolines.
void writeTrampolines(char *TrampolineBlockWorkingMem, ExecutorAddr TrampolineBlockTargetAddr, ExecutorAddr ResolverAddr, unsigned NumTrampolines) const override
void writeIndirectStubsBlock(char *StubsBlockWorkingMem, ExecutorAddr StubsBlockTargetAddress, ExecutorAddr PointersBlockTargetAddress, unsigned NumStubs) const override
void writeResolverCode(char *ResolverWorkingMem, ExecutorAddr ResolverTargetAddr, ExecutorAddr ReentryFnAddr, ExecutorAddr ReentryCtxAddr) const override
LLVM_ABI Error setUpInProcessLCTMReentryViaEPCIU(EPCIndirectionUtils &EPCIU)
This will call writeResolver on the given EPCIndirectionUtils instance to set up re-entry via a funct...
This is an optimization pass for GlobalISel generic memory operations.