LLVM 24.0.0git
SPSProxySpec.h
Go to the documentation of this file.
1//===------- SPSProxySpec.h - SPS dispatch for orc::Proxy -------*- 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// ProxySpec implements an orc::Proxy's dispatch by invoking an executor-side
10// wrapper function in the runtime's controller interface, using Simple Packed
11// Serialization to encode arguments and decode results.
12//
13// A ProxySpec pairs a Proxy with a controller-interface descriptor from
14// Shared/SPSCI, which supplies the wrapper name and wire signature. Specs for
15// specific operation families live alongside the utilities that use them (e.g.
16// CallProxiesSPS.h, EPCGenericMemoryAccessSPS.h).
17//
18//===----------------------------------------------------------------------===//
19
20#ifndef LLVM_EXECUTIONENGINE_ORC_SPSPROXYSPEC_H
21#define LLVM_EXECUTIONENGINE_ORC_SPSPROXYSPEC_H
22
25
26namespace llvm::orc::sps {
27
28template <typename ProxyT, typename CI,
29 typename FnType = typename ProxyT::FnType>
31
32template <typename ProxyT, typename CI, typename RetT, typename... ArgTs>
33class ProxySpec<ProxyT, CI, RetT(ArgTs...)> {
34
35 using SPSSigT = typename CI::SPSSig;
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 = CI::Name;
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
76} // namespace llvm::orc::sps
77
78#endif // LLVM_EXECUTIONENGINE_ORC_SPSPROXYSPEC_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)
unique_function is a type-erasing functor similar to std::function.
void consumeError(Error Err)
Consume a Error without doing anything.
Definition Error.h:1106