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 auto Caller = [&ES, CalleeAddr](auto &&SendResult, const char *ArgData,
54 size_t ArgSize) {
55 ES.callWrapperAsync(CalleeAddr,
56 std::forward<decltype(SendResult)>(SendResult),
57 ArrayRef<char>(ArgData, ArgSize));
58 };
59
60 if constexpr (std::is_void_v<CalleeRetT>) {
61 // Void result: the executor-side function produces no value, so the only
62 // thing to report is the dispatch error (success if the call ran).
63 shared::WrapperFunction<SPSSigT>::callAsync(Caller, std::move(OnComplete),
64 Args...);
65 } else {
67 Caller,
68 [OnComplete = std::move(OnComplete)](Error SerErr,
69 CalleeRetT Result) mutable {
70 if (SerErr) {
71 consumeResult(Result);
72 return OnComplete(std::move(SerErr));
73 }
74 // For an Error/Expected callee this forwards the callee's own
75 // result; for a plain value it is wrapped into Expected.
76 return OnComplete(std::move(Result));
77 },
78 Args...);
79 }
80 }
81};
82
83} // namespace llvm::orc::sps
84
85#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.
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