13#ifndef LLVM_EXECUTIONENGINE_ORC_EXECUTORPROCESSCONTROL_H
14#define LLVM_EXECUTIONENGINE_ORC_EXECUTORPROCESSCONTROL_H
34class ExecutionSession;
52 explicit operator bool()
const {
return !!
H; }
56 :
H(
std::forward<FnT>(Fn)) {}
69 template <
typename FnT>
84 template <
typename FnT>
87 [&D = this->D, Fn = std::move(Fn)]
91 [Fn = std::move(Fn), WFR = std::move(WFR)]()
mutable {
93 },
"WFR handler task"));
127 std::promise<MSVCPError> ResultP;
128 auto ResultF = ResultP.get_future();
130 [&](
Error Err) { ResultP.set_value(std::move(Err)); });
131 return ResultF.get();
135 std::promise<MSVCPError> ResultP;
136 auto ResultF = ResultP.get_future();
138 [&](
Error Err) { ResultP.set_value(std::move(Err)); });
139 return ResultF.get();
143 std::promise<MSVCPError> ResultP;
144 auto ResultF = ResultP.get_future();
146 [&](
Error Err) { ResultP.set_value(std::move(Err)); });
147 return ResultF.get();
151 std::promise<MSVCPError> ResultP;
152 auto ResultF = ResultP.get_future();
154 [&](
Error Err) { ResultP.set_value(std::move(Err)); });
155 return ResultF.get();
159 std::promise<MSVCPError> ResultP;
160 auto ResultF = ResultP.get_future();
162 [&](
Error Err) { ResultP.set_value(std::move(Err)); });
163 return ResultF.get();
167 std::promise<MSVCPError> ResultP;
168 auto ResultF = ResultP.get_future();
170 [&](
Error Err) { ResultP.set_value(std::move(Err)); });
171 return ResultF.get();
191 std::unique_ptr<TaskDispatcher>
D)
199 assert(
ES &&
"No ExecutionSession associated yet");
240 template <
typename T,
typename SPSTagT>
251 return make_error<StringError>(
"Could not deserialize value for key " +
255 Val = std::move(Tmp);
268 ArrayRef<std::pair<ExecutorAddr &, StringRef>> Pairs)
const {
269 for (
const auto &KV : Pairs) {
272 return make_error<StringError>(
"Symbol \"" + KV.second +
274 "in bootstrap symbols map",
277 KV.first =
I->second;
295 std::promise<MSVCPExpected<std::vector<tpctypes::LookupResult>>> RP;
296 auto RF = RP.get_future();
298 [&RP](
auto Result) { RP.set_value(std::move(
Result)); });
341 template <
typename RunPolicyT,
typename FnT>
345 WrapperFnAddr, Runner(std::forward<FnT>(OnComplete)), ArgBuffer);
350 template <
typename FnT>
354 std::forward<FnT>(OnComplete), ArgBuffer);
365 std::promise<shared::WrapperFunctionResult> RP;
366 auto RF = RP.get_future();
370 RP.set_value(std::move(R));
377 template <
typename SPSSignature,
typename RunPolicyT,
typename SendResultT,
380 SendResultT &&SendResult,
const ArgTs &...Args) {
382 [
this, WrapperFnAddr, Runner = std::move(Runner)]
383 (
auto &&SendResult,
const char *ArgData,
size_t ArgSize)
mutable {
385 std::move(SendResult),
388 std::forward<SendResultT>(SendResult), Args...);
393 template <
typename SPSSignature,
typename SendResultT,
typename... ArgTs>
395 const ArgTs &...Args) {
396 callSPSWrapperAsync<SPSSignature>(
RunAsTask(*
D), WrapperFnAddr,
397 std::forward<SendResultT>(SendResult),
406 template <
typename SPSSignature,
typename... WrapperCallArgTs>
408 WrapperCallArgTs &&...WrapperCallArgs) {
410 [
this, WrapperFnAddr](
const char *ArgData,
size_t ArgSize) {
413 std::forward<WrapperCallArgTs>(WrapperCallArgs)...);
423 std::shared_ptr<SymbolStringPool>
SSP;
424 std::unique_ptr<TaskDispatcher>
D;
467 std::shared_ptr<SymbolStringPool>
SSP =
nullptr,
468 std::unique_ptr<TaskDispatcher>
D =
nullptr,
const std::string &TT =
"",
515 std::shared_ptr<SymbolStringPool>
SSP, std::unique_ptr<TaskDispatcher>
D,
517 std::unique_ptr<jitlink::JITLinkMemoryManager>
MemMgr);
525 Create(std::shared_ptr<SymbolStringPool>
SSP =
nullptr,
526 std::unique_ptr<TaskDispatcher>
D =
nullptr,
527 std::unique_ptr<jitlink::JITLinkMemoryManager>
MemMgr =
nullptr);
549 jitDispatchViaWrapperFunctionManager(
void *Ctx,
const void *FnTag,
552 std::unique_ptr<jitlink::JITLinkMemoryManager> OwnedMemMgr;
553 char GlobalManglingPrefix = 0;
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
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.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
iterator find(StringRef Key)
StringRef - Represent a constant reference to a string, i.e.
Triple - Helper class for working with autoconf configuration names.
Manages allocations of JIT memory.
An ExecutionSession represents a running JIT program.
Represents an address in the executor process.
A handler or incoming WrapperFunctionResults – either return values from callWrapper* calls,...
void operator()(shared::WrapperFunctionResult WFR)
IncomingWFRHandler()=default
APIs for manipulating memory in the target process.
virtual void writePointersAsync(ArrayRef< tpctypes::PointerWrite > Ws, WriteResultFn OnWriteComplete)=0
Error writeUInt64s(ArrayRef< tpctypes::UInt64Write > Ws)
Error writeBuffers(ArrayRef< tpctypes::BufferWrite > Ws)
Error writeUInt32s(ArrayRef< tpctypes::UInt32Write > Ws)
Error writePointers(ArrayRef< tpctypes::PointerWrite > Ws)
Error writeUInt8s(ArrayRef< tpctypes::UInt8Write > Ws)
virtual void writeUInt8sAsync(ArrayRef< tpctypes::UInt8Write > Ws, WriteResultFn OnWriteComplete)=0
Error writeUInt16s(ArrayRef< tpctypes::UInt16Write > Ws)
virtual void writeUInt32sAsync(ArrayRef< tpctypes::UInt32Write > Ws, WriteResultFn OnWriteComplete)=0
unique_function< void(Error)> WriteResultFn
Callback function for asynchronous writes.
virtual void writeBuffersAsync(ArrayRef< tpctypes::BufferWrite > Ws, WriteResultFn OnWriteComplete)=0
virtual void writeUInt16sAsync(ArrayRef< tpctypes::UInt16Write > Ws, WriteResultFn OnWriteComplete)=0
virtual void writeUInt64sAsync(ArrayRef< tpctypes::UInt64Write > Ws, WriteResultFn OnWriteComplete)=0
Constructs an IncomingWFRHandler from a function object by creating a new function object that dispat...
IncomingWFRHandler operator()(FnT &&Fn)
RunAsTask(TaskDispatcher &D)
Constructs an IncomingWFRHandler from a function object that is callable as void(shared::WrapperFunct...
IncomingWFRHandler operator()(FnT &&Fn)
ExecutorProcessControl supports interaction with a JIT target process.
jitlink::JITLinkMemoryManager & getMemMgr() const
Return a JITLinkMemoryManager for the target process.
shared::WrapperFunctionResult callWrapper(ExecutorAddr WrapperFnAddr, ArrayRef< char > ArgBuffer)
Run a wrapper function in the executor.
void callWrapperAsync(ExecutorAddr WrapperFnAddr, FnT &&OnComplete, ArrayRef< char > ArgBuffer)
Run a wrapper function in the executor.
virtual Expected< int32_t > runAsIntFunction(ExecutorAddr IntFnAddr, int Arg)=0
Run function with a int (*)(int) signature.
void callSPSWrapperAsync(RunPolicyT &&Runner, ExecutorAddr WrapperFnAddr, SendResultT &&SendResult, const ArgTs &...Args)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
virtual Expected< int32_t > runAsMain(ExecutorAddr MainFnAddr, ArrayRef< std::string > Args)=0
Run function with a main-like signature.
Error getBootstrapMapValue(StringRef Key, std::optional< T > &Val) const
Look up and SPS-deserialize a bootstrap map value.
std::unique_ptr< TaskDispatcher > D
void callSPSWrapperAsync(ExecutorAddr WrapperFnAddr, SendResultT &&SendResult, const ArgTs &...Args)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
virtual void callWrapperAsync(ExecutorAddr WrapperFnAddr, IncomingWFRHandler OnComplete, ArrayRef< char > ArgBuffer)=0
Run a wrapper function in the executor.
virtual Expected< tpctypes::DylibHandle > loadDylib(const char *DylibPath)=0
Load the dynamic library at the given path and return a handle to it.
const StringMap< std::vector< char > > & getBootstrapMap() const
Returns the bootstrap map.
std::shared_ptr< SymbolStringPool > SSP
const Triple & getTargetTriple() const
Return the Triple for the target process.
StringMap< ExecutorAddr > BootstrapSymbols
SymbolStringPtr intern(StringRef SymName)
Intern a symbol name in the SymbolStringPool.
virtual Error disconnect()=0
Disconnect from the target process.
virtual void lookupSymbolsAsync(ArrayRef< LookupRequest > Request, SymbolLookupCompleteFn F)=0
Search for symbols in the target process.
StringMap< std::vector< char > > BootstrapMap
std::shared_ptr< SymbolStringPool > getSymbolStringPool() const
Return a shared pointer to the SymbolStringPool for this instance.
const StringMap< ExecutorAddr > & getBootstrapSymbolsMap() const
Returns the bootstrap symbol map.
virtual Expected< int32_t > runAsVoidFunction(ExecutorAddr VoidFnAddr)=0
Run function with a int (*)(void) signature.
jitlink::JITLinkMemoryManager * MemMgr
unsigned getPageSize() const
Get the page size for the target process.
const JITDispatchInfo & getJITDispatchInfo() const
Get the JIT dispatch function and context address for the executor.
Error callSPSWrapper(ExecutorAddr WrapperFnAddr, WrapperCallArgTs &&...WrapperCallArgs)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
void callWrapperAsync(RunPolicyT &&Runner, ExecutorAddr WrapperFnAddr, FnT &&OnComplete, ArrayRef< char > ArgBuffer)
Run a wrapper function in the executor using the given Runner to dispatch OnComplete when the result ...
Error getBootstrapSymbols(ArrayRef< std::pair< ExecutorAddr &, StringRef > > Pairs) const
For each (ExecutorAddr&, StringRef) pair, looks up the string in the bootstrap symbols map and writes...
ExecutionSession & getExecutionSession()
Return the ExecutionSession associated with this instance.
ExecutorProcessControl(std::shared_ptr< SymbolStringPool > SSP, std::unique_ptr< TaskDispatcher > D)
Expected< std::vector< tpctypes::LookupResult > > lookupSymbols(ArrayRef< LookupRequest > Request)
Search for symbols in the target process.
MemoryAccess & getMemoryAccess() const
Return a MemoryAccess object for the target process.
TaskDispatcher & getDispatcher()
virtual ~ExecutorProcessControl()
Runs all tasks on the current thread.
void writePointersAsync(ArrayRef< tpctypes::PointerWrite > Ws, WriteResultFn OnWriteComplete) override
void writeUInt32sAsync(ArrayRef< tpctypes::UInt32Write > Ws, WriteResultFn OnWriteComplete) override
void writeUInt8sAsync(ArrayRef< tpctypes::UInt8Write > Ws, WriteResultFn OnWriteComplete) override
InProcessMemoryAccess(bool IsArch64Bit)
void writeUInt16sAsync(ArrayRef< tpctypes::UInt16Write > Ws, WriteResultFn OnWriteComplete) override
void writeBuffersAsync(ArrayRef< tpctypes::BufferWrite > Ws, WriteResultFn OnWriteComplete) override
void writeUInt64sAsync(ArrayRef< tpctypes::UInt64Write > Ws, WriteResultFn OnWriteComplete) override
A ExecutorProcessControl implementation targeting the current process.
Expected< tpctypes::DylibHandle > loadDylib(const char *DylibPath) override
Load the dynamic library at the given path and return a handle to it.
void lookupSymbolsAsync(ArrayRef< LookupRequest > Request, SymbolLookupCompleteFn F) override
Search for symbols in the target process.
Error disconnect() override
Disconnect from the target process.
Expected< int32_t > runAsVoidFunction(ExecutorAddr VoidFnAddr) override
Run function with a int (*)(void) signature.
Expected< int32_t > runAsMain(ExecutorAddr MainFnAddr, ArrayRef< std::string > Args) override
Run function with a main-like signature.
void callWrapperAsync(ExecutorAddr WrapperFnAddr, IncomingWFRHandler OnComplete, ArrayRef< char > ArgBuffer) override
Run a wrapper function in the executor.
static Expected< std::unique_ptr< SelfExecutorProcessControl > > Create(std::shared_ptr< SymbolStringPool > SSP=nullptr, std::unique_ptr< TaskDispatcher > D=nullptr, std::unique_ptr< jitlink::JITLinkMemoryManager > MemMgr=nullptr)
Create a SelfExecutorProcessControl with the given symbol string pool and memory manager.
Expected< int32_t > runAsIntFunction(ExecutorAddr IntFnAddr, int Arg) override
Run function with a int (*)(int) signature.
A set of symbols to look up, each associated with a SymbolLookupFlags value.
String pool for symbol names used by the JIT.
Pointer to a pooled string representing a symbol name.
Abstract base for classes that dispatch ORC Tasks.
virtual void dispatch(std::unique_ptr< Task > T)=0
Run the given task.
A ExecutorProcessControl instance that asserts if any of its methods are used.
Expected< tpctypes::DylibHandle > loadDylib(const char *DylibPath) override
Load the dynamic library at the given path and return a handle to it.
Expected< int32_t > runAsMain(ExecutorAddr MainFnAddr, ArrayRef< std::string > Args) override
Run function with a main-like signature.
UnsupportedExecutorProcessControl(std::shared_ptr< SymbolStringPool > SSP=nullptr, std::unique_ptr< TaskDispatcher > D=nullptr, const std::string &TT="", unsigned PageSize=0)
void callWrapperAsync(ExecutorAddr WrapperFnAddr, IncomingWFRHandler OnComplete, ArrayRef< char > ArgBuffer) override
Run a wrapper function in the executor.
Error disconnect() override
Disconnect from the target process.
Expected< int32_t > runAsIntFunction(ExecutorAddr IntFnAddr, int Arg) override
Run function with a int (*)(int) signature.
void lookupSymbolsAsync(ArrayRef< LookupRequest > Request, SymbolLookupCompleteFn F) override
Search for symbols in the target process.
Expected< int32_t > runAsVoidFunction(ExecutorAddr VoidFnAddr) override
Run function with a int (*)(void) signature.
A utility class for serializing to a blob from a variadic list.
C++ wrapper function result: Same as CWrapperFunctionResult but auto-releases memory.
unique_function is a type-erasing functor similar to std::function.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::unique_ptr< GenericNamedTask > makeGenericNamedTask(FnT &&Fn, std::string Desc)
Create a generic named task from a std::string description.
This is an optimization pass for GlobalISel generic memory operations.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
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.
Contains the address of the dispatch function and context that the ORC runtime can use to call functi...
ExecutorAddr JITDispatchContext
ExecutorAddr JITDispatchFunction
A pair of a dylib and a set of symbols to be looked up.
tpctypes::DylibHandle Handle
const SymbolLookupSet & Symbols
LookupRequest(tpctypes::DylibHandle Handle, const SymbolLookupSet &Symbols)