LLVM 24.0.0git
ProxySpecs.h
Go to the documentation of this file.
1//===-------- ProxySpecs.h - SPS-based Call Wrappers ------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// SPS-based implementations of the RTBridge proxy interfaces.
10//
11// These implement the rt::Proxy interfaces by invoking executor-side wrapper
12// functions in the runtime's controller interface, using Simple Packed
13// Serialization to encode arguments and decode results.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_EXECUTIONENGINE_ORC_RTBRIDGE_SPS_PROXYSPECS_H
18#define LLVM_EXECUTIONENGINE_ORC_RTBRIDGE_SPS_PROXYSPECS_H
19
23
24#include <cstdint>
25
27
28template <typename ProxyT, typename SPSSigT, const char *DefaultName,
29 typename FnType = typename ProxyT::FnType>
31
32template <typename ProxyT, typename SPSSigT, const char *DefaultName,
33 typename RetT, typename... ArgTs>
34class ProxySpec<ProxyT, SPSSigT, DefaultName, RetT(ArgTs...)> {
35
36 using CalleeRetT = typename ProxyT::CalleeRetT;
37 using ErrorRetT = typename ProxyT::ErrorRetT;
38
39 static void consumeResult(Error &Err) { consumeError(std::move(Err)); }
40
41 template <typename T> static void consumeResult(T &V) {}
42
43 template <typename T> static void consumeResult(Expected<T> &E) {
44 consumeError(E.takeError());
45 }
46
47public:
48 static constexpr const char *Name = DefaultName;
49
50 static void dispatch(unique_function<void(ErrorRetT)> OnComplete,
51 ExecutionSession &ES, ExecutorAddr CalleeAddr,
52 const ArgTs &...Args) {
53 if constexpr (std::is_void_v<CalleeRetT>) {
54 // Void result: the executor-side function produces no value, so the only
55 // thing to report is the dispatch error (success if the call ran).
56 ES.callSPSWrapperAsync<SPSSigT>(CalleeAddr, std::move(OnComplete),
57 Args...);
58 } else {
59 ES.callSPSWrapperAsync<SPSSigT>(
60 CalleeAddr,
61 [OnComplete = std::move(OnComplete)](Error SerErr,
62 CalleeRetT Result) mutable {
63 if (SerErr) {
64 consumeResult(Result);
65 return OnComplete(std::move(SerErr));
66 }
67 // For an Error/Expected callee this forwards the callee's own
68 // result; for a plain value it is wrapped into Expected.
69 return OnComplete(std::move(Result));
70 },
71 Args...);
72 }
73 }
74};
75
78inline constexpr char CallMainCIName[] = "orc_rt_ci_sps_call_main";
79/// SPS proxy for rt::CallMainProxy: runs a main-like function
80/// (int(int argc, char *argv[])) in the executor.
83
85inline constexpr char CallVoidVoidCIName[] = "orc_rt_ci_sps_call_void_void";
86/// SPS proxy for rt::CallVoidVoidProxy: runs a void() function in the executor.
87/// WARNING: This Proxy is experimental and may be removed.
90
92inline constexpr char CallInt32VoidCIName[] = "orc_rt_ci_sps_call_int32_void";
93/// SPS proxy for rt::CallInt32VoidProxy: runs an int32_t() function in the
94/// executor.
95/// WARNING: This Proxy is experimental and may be removed.
98
100inline constexpr char CallInt32Int32CIName[] = "orc_rt_ci_sps_call_int32_int32";
101/// SPS proxy for rt::CallInt32Int32Proxy: runs an int32_t(int32_t) function in
102/// the executor.
103/// WARNING: This Proxy is experimental and may be removed.
107
108// Memory-access proxies. Unlike the Call* proxies above, these target wrappers
109// that perform the operation directly, so they take the operation's data
110// arguments and no callee address.
111
114inline constexpr char MemWriteUInt8sCIName[] = "orc_rt_ci_sps_mem_write_uint8s";
118
121inline constexpr char MemWriteUInt16sCIName[] =
122 "orc_rt_ci_sps_mem_write_uint16s";
126
129inline constexpr char MemWriteUInt32sCIName[] =
130 "orc_rt_ci_sps_mem_write_uint32s";
134
137inline constexpr char MemWriteUInt64sCIName[] =
138 "orc_rt_ci_sps_mem_write_uint64s";
142
145inline constexpr char MemWritePointersCIName[] =
146 "orc_rt_ci_sps_mem_write_pointers";
150
153inline constexpr char MemWriteBuffersCIName[] =
154 "orc_rt_ci_sps_mem_write_buffers";
158
161inline constexpr char MemReadUInt8sCIName[] = "orc_rt_ci_sps_mem_read_uint8s";
164
167inline constexpr char MemReadUInt16sCIName[] = "orc_rt_ci_sps_mem_read_uint16s";
171
174inline constexpr char MemReadUInt32sCIName[] = "orc_rt_ci_sps_mem_read_uint32s";
178
181inline constexpr char MemReadUInt64sCIName[] = "orc_rt_ci_sps_mem_read_uint64s";
185
188inline constexpr char MemReadPointersCIName[] =
189 "orc_rt_ci_sps_mem_read_pointers";
193
196inline constexpr char MemReadBuffersCIName[] = "orc_rt_ci_sps_mem_read_buffers";
200
203inline constexpr char MemReadStringsCIName[] = "orc_rt_ci_sps_mem_read_strings";
207
208} // namespace llvm::orc::rt::sps
209
210#endif // LLVM_EXECUTIONENGINE_ORC_RTBRIDGE_SPS_PROXYSPECS_H
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define T
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Tagged union holding either a T or a Error.
Definition Error.h:485
An ExecutionSession represents a running JIT program.
Definition Core.h:1111
void callSPSWrapperAsync(ExecutorAddr WrapperFnAddr, SendResultT &&SendResult, const ArgTs &...Args)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
Definition Core.h:1417
Represents an address in the executor process.
static void dispatch(unique_function< void(ErrorRetT)> OnComplete, ExecutionSession &ES, ExecutorAddr CalleeAddr, const ArgTs &...Args)
Definition ProxySpecs.h:50
unique_function is a type-erasing functor similar to std::function.
constexpr char MemWriteUInt8sCIName[]
Definition ProxySpecs.h:114
shared::SPSSequence< uint8_t >(shared::SPSSequence< shared::SPSExecutorAddr >) MemReadUInt8sSPSSig
Definition ProxySpecs.h:159
constexpr char MemReadStringsCIName[]
Definition ProxySpecs.h:203
ProxySpec< rt::MemReadPointersProxy, MemReadPointersSPSSig, MemReadPointersCIName > MemReadPointersProxySpec
Definition ProxySpecs.h:190
void(shared::SPSSequence< shared::SPSMemoryAccessBufferWrite >) MemWriteBuffersSPSSig
Definition ProxySpecs.h:151
ProxySpec< rt::CallInt32VoidProxy, CallInt32VoidSPSSig, CallInt32VoidCIName > CallInt32VoidProxySpec
SPS proxy for rt::CallInt32VoidProxy: runs an int32_t() function in the executor.
Definition ProxySpecs.h:96
constexpr char MemReadUInt8sCIName[]
Definition ProxySpecs.h:161
ProxySpec< rt::CallVoidVoidProxy, CallVoidVoidSPSSig, CallVoidVoidCIName > CallVoidVoidProxySpec
SPS proxy for rt::CallVoidVoidProxy: runs a void() function in the executor.
Definition ProxySpecs.h:88
constexpr char MemReadUInt16sCIName[]
Definition ProxySpecs.h:167
void(shared::SPSSequence< shared::SPSMemoryAccessPointerWrite >) MemWritePointersSPSSig
Definition ProxySpecs.h:143
shared::SPSSequence< shared::SPSString >( shared::SPSSequence< shared::SPSExecutorAddr >) MemReadStringsSPSSig
Definition ProxySpecs.h:201
shared::SPSSequence< shared::SPSExecutorAddr >( shared::SPSSequence< shared::SPSExecutorAddr >) MemReadPointersSPSSig
Definition ProxySpecs.h:186
void(shared::SPSExecutorAddr) CallVoidVoidSPSSig
Definition ProxySpecs.h:84
ProxySpec< rt::MemReadStringsProxy, MemReadStringsSPSSig, MemReadStringsCIName > MemReadStringsProxySpec
Definition ProxySpecs.h:204
int32_t(shared::SPSExecutorAddr, int32_t) CallInt32Int32SPSSig
Definition ProxySpecs.h:99
ProxySpec< rt::MemWriteUInt32sProxy, MemWriteUInt32sSPSSig, MemWriteUInt32sCIName > MemWriteUInt32sProxySpec
Definition ProxySpecs.h:131
ProxySpec< rt::MemWriteBuffersProxy, MemWriteBuffersSPSSig, MemWriteBuffersCIName > MemWriteBuffersProxySpec
Definition ProxySpecs.h:155
constexpr char MemReadUInt64sCIName[]
Definition ProxySpecs.h:181
void(shared::SPSSequence< shared::SPSMemoryAccessUInt32Write >) MemWriteUInt32sSPSSig
Definition ProxySpecs.h:127
ProxySpec< rt::MemReadUInt64sProxy, MemReadUInt64sSPSSig, MemReadUInt64sCIName > MemReadUInt64sProxySpec
Definition ProxySpecs.h:182
ProxySpec< rt::MemReadUInt32sProxy, MemReadUInt32sSPSSig, MemReadUInt32sCIName > MemReadUInt32sProxySpec
Definition ProxySpecs.h:175
ProxySpec< rt::CallMainProxy, CallMainSPSSig, CallMainCIName > CallMainProxySpec
SPS proxy for rt::CallMainProxy: runs a main-like function (int(int argc, char *argv[])) in the execu...
Definition ProxySpecs.h:81
constexpr char MemWriteUInt16sCIName[]
Definition ProxySpecs.h:121
shared::SPSSequence< shared::SPSSequence< uint8_t > >( shared::SPSSequence< shared::SPSExecutorAddrRange >) MemReadBuffersSPSSig
Definition ProxySpecs.h:194
constexpr char CallInt32VoidCIName[]
Definition ProxySpecs.h:92
void(shared::SPSSequence< shared::SPSMemoryAccessUInt64Write >) MemWriteUInt64sSPSSig
Definition ProxySpecs.h:135
ProxySpec< rt::MemWriteUInt8sProxy, MemWriteUInt8sSPSSig, MemWriteUInt8sCIName > MemWriteUInt8sProxySpec
Definition ProxySpecs.h:115
constexpr char MemReadUInt32sCIName[]
Definition ProxySpecs.h:174
shared::SPSSequence< uint64_t >(shared::SPSSequence< shared::SPSExecutorAddr >) MemReadUInt64sSPSSig
Definition ProxySpecs.h:179
void(shared::SPSSequence< shared::SPSMemoryAccessUInt8Write >) MemWriteUInt8sSPSSig
Definition ProxySpecs.h:112
constexpr char MemReadPointersCIName[]
Definition ProxySpecs.h:188
constexpr char CallMainCIName[]
Definition ProxySpecs.h:78
shared::SPSSequence< uint16_t >(shared::SPSSequence< shared::SPSExecutorAddr >) MemReadUInt16sSPSSig
Definition ProxySpecs.h:165
constexpr char CallInt32Int32CIName[]
Definition ProxySpecs.h:100
constexpr char MemWriteUInt64sCIName[]
Definition ProxySpecs.h:137
constexpr char MemWriteBuffersCIName[]
Definition ProxySpecs.h:153
constexpr char MemWritePointersCIName[]
Definition ProxySpecs.h:145
ProxySpec< rt::MemReadUInt16sProxy, MemReadUInt16sSPSSig, MemReadUInt16sCIName > MemReadUInt16sProxySpec
Definition ProxySpecs.h:168
constexpr char MemWriteUInt32sCIName[]
Definition ProxySpecs.h:129
ProxySpec< rt::MemReadUInt8sProxy, MemReadUInt8sSPSSig, MemReadUInt8sCIName > MemReadUInt8sProxySpec
Definition ProxySpecs.h:162
shared::SPSSequence< uint32_t >(shared::SPSSequence< shared::SPSExecutorAddr >) MemReadUInt32sSPSSig
Definition ProxySpecs.h:172
void(shared::SPSSequence< shared::SPSMemoryAccessUInt16Write >) MemWriteUInt16sSPSSig
Definition ProxySpecs.h:119
constexpr char CallVoidVoidCIName[]
Definition ProxySpecs.h:85
ProxySpec< rt::MemWriteUInt64sProxy, MemWriteUInt64sSPSSig, MemWriteUInt64sCIName > MemWriteUInt64sProxySpec
Definition ProxySpecs.h:139
int64_t(shared::SPSExecutorAddr, shared::SPSSequence< shared::SPSString >) CallMainSPSSig
Definition ProxySpecs.h:76
constexpr char MemReadBuffersCIName[]
Definition ProxySpecs.h:196
int32_t(shared::SPSExecutorAddr) CallInt32VoidSPSSig
Definition ProxySpecs.h:91
ProxySpec< rt::MemWriteUInt16sProxy, MemWriteUInt16sSPSSig, MemWriteUInt16sCIName > MemWriteUInt16sProxySpec
Definition ProxySpecs.h:123
ProxySpec< rt::MemReadBuffersProxy, MemReadBuffersSPSSig, MemReadBuffersCIName > MemReadBuffersProxySpec
Definition ProxySpecs.h:197
ProxySpec< rt::CallInt32Int32Proxy, CallInt32Int32SPSSig, CallInt32Int32CIName > CallInt32Int32ProxySpec
SPS proxy for rt::CallInt32Int32Proxy: runs an int32_t(int32_t) function in the executor.
Definition ProxySpecs.h:104
ProxySpec< rt::MemWritePointersProxy, MemWritePointersSPSSig, MemWritePointersCIName > MemWritePointersProxySpec
Definition ProxySpecs.h:147
Proxy< void(ArrayRef< tpctypes::PointerWrite >)> MemWritePointersProxy
Definition Proxy.h:246
Proxy< std::vector< ExecutorAddr >(ArrayRef< ExecutorAddr >)> MemReadPointersProxy
Definition Proxy.h:255
Proxy< std::vector< uint32_t >(ArrayRef< ExecutorAddr >)> MemReadUInt32sProxy
Definition Proxy.h:251
Proxy< int32_t(ExecutorAddr, int32_t)> CallInt32Int32Proxy
Runtime-agnostic interface for running an int32_t(int32_t) function in the executor.
Definition Proxy.h:236
Proxy< std::vector< uint64_t >(ArrayRef< ExecutorAddr >)> MemReadUInt64sProxy
Definition Proxy.h:253
Proxy< std::vector< std::vector< uint8_t > >(ArrayRef< ExecutorAddrRange >)> MemReadBuffersProxy
Definition Proxy.h:257
Proxy< std::vector< std::string >(ArrayRef< ExecutorAddr >)> MemReadStringsProxy
Definition Proxy.h:259
Proxy< void(ArrayRef< tpctypes::UInt64Write >)> MemWriteUInt64sProxy
Definition Proxy.h:245
Proxy< void(ArrayRef< tpctypes::UInt8Write >)> MemWriteUInt8sProxy
Runtime-agnostic interfaces for the memory-access operations.
Definition Proxy.h:242
Proxy< void(ArrayRef< tpctypes::UInt16Write >)> MemWriteUInt16sProxy
Definition Proxy.h:243
Proxy< std::vector< uint16_t >(ArrayRef< ExecutorAddr >)> MemReadUInt16sProxy
Definition Proxy.h:249
Proxy< void(ArrayRef< tpctypes::UInt32Write >)> MemWriteUInt32sProxy
Definition Proxy.h:244
Proxy< void(ArrayRef< tpctypes::BufferWrite >)> MemWriteBuffersProxy
Definition Proxy.h:247
void consumeError(Error Err)
Consume a Error without doing anything.
Definition Error.h:1106