LLVM 24.0.0git
ProxySpec.h
Go to the documentation of this file.
1//===------- ProxySpec.h - SPS dispatch for rt::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 rt::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// Specs for specific operation families live in sibling headers whose specs
14// only need Shared/SPS vocabulary types (e.g. CallProxySpecs.h,
15// MemoryAccessProxySpecs.h).
16//
17//===----------------------------------------------------------------------===//
18
19#ifndef LLVM_EXECUTIONENGINE_ORC_RTBRIDGE_SPS_PROXYSPEC_H
20#define LLVM_EXECUTIONENGINE_ORC_RTBRIDGE_SPS_PROXYSPEC_H
21
24
25namespace llvm::orc::rt::sps {
26
27template <typename ProxyT, typename SPSSigT, const char *DefaultName,
28 typename FnType = typename ProxyT::FnType>
30
31template <typename ProxyT, typename SPSSigT, const char *DefaultName,
32 typename RetT, typename... ArgTs>
33class ProxySpec<ProxyT, SPSSigT, DefaultName, RetT(ArgTs...)> {
34
35 using CalleeRetT = typename ProxyT::CalleeRetT;
36 using ErrorRetT = typename ProxyT::ErrorRetT;
37
38 static void consumeResult(Error &Err) { consumeError(std::move(Err)); }
39
40 template <typename T> static void consumeResult(T &V) {}
41
42 template <typename T> static void consumeResult(Expected<T> &E) {
43 consumeError(E.takeError());
44 }
45
46public:
47 static constexpr const char *Name = DefaultName;
48
49 static void dispatch(unique_function<void(ErrorRetT)> OnComplete,
50 ExecutionSession &ES, ExecutorAddr CalleeAddr,
51 const ArgTs &...Args) {
52 if constexpr (std::is_void_v<CalleeRetT>) {
53 // Void result: the executor-side function produces no value, so the only
54 // thing to report is the dispatch error (success if the call ran).
55 ES.callSPSWrapperAsync<SPSSigT>(CalleeAddr, std::move(OnComplete),
56 Args...);
57 } else {
58 ES.callSPSWrapperAsync<SPSSigT>(
59 CalleeAddr,
60 [OnComplete = std::move(OnComplete)](Error SerErr,
61 CalleeRetT Result) mutable {
62 if (SerErr) {
63 consumeResult(Result);
64 return OnComplete(std::move(SerErr));
65 }
66 // For an Error/Expected callee this forwards the callee's own
67 // result; for a plain value it is wrapped into Expected.
68 return OnComplete(std::move(Result));
69 },
70 Args...);
71 }
72 }
73};
74
75} // namespace llvm::orc::rt::sps
76
77#endif // LLVM_EXECUTIONENGINE_ORC_RTBRIDGE_SPS_PROXYSPEC_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 ProxySpec.h:49
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