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
26
27namespace llvm::orc::sps {
28
29template <typename ProxyT, typename CI,
30 typename FnType = typename ProxyT::FnType>
32
33template <typename ProxyT, typename CI, typename RetT, typename... ArgTs>
34class ProxySpec<ProxyT, CI, RetT(ArgTs...)> {
35
36 using SPSSigT = typename CI::SPSSig;
37 using CalleeRetT = typename ProxyT::CalleeRetT;
38 using ErrorRetT = typename ProxyT::ErrorRetT;
39
40 static void consumeResult(Error &Err) { consumeError(std::move(Err)); }
41
42 template <typename T> static void consumeResult(T &V) {}
43
44 template <typename T> static void consumeResult(Expected<T> &E) {
45 consumeError(E.takeError());
46 }
47
48public:
49 static constexpr SymbolNameSpec Name = CI::Name;
50
51 static void dispatch(unique_function<void(ErrorRetT)> OnComplete,
52 ExecutionSession &ES, ExecutorAddr CalleeAddr,
53 const ArgTs &...Args) {
54 auto Caller = [&ES, CalleeAddr](auto &&SendResult, const char *ArgData,
55 size_t ArgSize) {
56 ES.callWrapperAsync(CalleeAddr,
57 std::forward<decltype(SendResult)>(SendResult),
58 ArrayRef<char>(ArgData, ArgSize));
59 };
60
61 if constexpr (std::is_void_v<CalleeRetT>) {
62 // Void result: the executor-side function produces no value, so the only
63 // thing to report is the dispatch error (success if the call ran).
64 shared::WrapperFunction<SPSSigT>::callAsync(Caller, std::move(OnComplete),
65 Args...);
66 } else {
68 Caller,
69 [OnComplete = std::move(OnComplete)](Error SerErr,
70 CalleeRetT Result) mutable {
71 if (SerErr) {
72 consumeResult(Result);
73 return OnComplete(std::move(SerErr));
74 }
75 // For an Error/Expected callee this forwards the callee's own
76 // result; for a plain value it is wrapped into Expected.
77 return OnComplete(std::move(Result));
78 },
79 Args...);
80 }
81 }
82};
83
84} // namespace llvm::orc::sps
85
86#endif // LLVM_EXECUTIONENGINE_ORC_SPSPROXYSPEC_H
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define T
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
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 callWrapperAsync(ExecutorAddr WrapperFnAddr, ExecutorProcessControl::IncomingWFRHandler OnComplete, ArrayRef< char > ArgBuffer)
Run a wrapper function in the executor.
Definition Core.h:1379
Represents an address in the executor process.
A symbol name together with the naming level (SymbolNameKind) it is expressed in, so that a Mangler /...
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