[llvm] [orc-rt] Enable transparent SPS conversion for Expected<T*>. (PR #162073)
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 6 05:06:19 PDT 2025
https://github.com/lhames created https://github.com/llvm/llvm-project/pull/162073
Expected<T*> values will be converted to/from Expected<ExecutorAddr> values.
>From 5b56af86182878b41c7dbd8159f0f28472ea5b04 Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Mon, 6 Oct 2025 23:01:43 +1100
Subject: [PATCH] [orc-rt] Enable transparent SPS conversion for Expected<T*>.
Expected<T*> values will be converted to/from Expected<ExecutorAddr> values.
---
orc-rt/include/orc-rt/SPSWrapperFunction.h | 15 +++++++++++++
orc-rt/unittests/SPSWrapperFunctionTest.cpp | 24 +++++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/orc-rt/include/orc-rt/SPSWrapperFunction.h b/orc-rt/include/orc-rt/SPSWrapperFunction.h
index e5ed14f5cd721..5cf387345e6ba 100644
--- a/orc-rt/include/orc-rt/SPSWrapperFunction.h
+++ b/orc-rt/include/orc-rt/SPSWrapperFunction.h
@@ -63,6 +63,21 @@ template <typename... SPSArgTs> struct WFSPSHelper {
}
};
+ template <typename T> struct Serializable<Expected<T *>> {
+ typedef SPSSerializableExpected<ExecutorAddr> serializable_type;
+ static SPSSerializableExpected<ExecutorAddr> to(Expected<T *> Val) {
+ return SPSSerializableExpected<ExecutorAddr>(
+ Val ? Expected<ExecutorAddr>(ExecutorAddr::fromPtr(*Val))
+ : Expected<ExecutorAddr>(Val.takeError()));
+ }
+ static Expected<T *> from(SPSSerializableExpected<ExecutorAddr> Val) {
+ if (auto Tmp = Val.toExpected())
+ return Tmp->toPtr<T *>();
+ else
+ return Tmp.takeError();
+ }
+ };
+
template <typename... Ts> struct DeserializableTuple;
template <typename... Ts> struct DeserializableTuple<std::tuple<Ts...>> {
diff --git a/orc-rt/unittests/SPSWrapperFunctionTest.cpp b/orc-rt/unittests/SPSWrapperFunctionTest.cpp
index 7f88ce0434ddb..9d0d9e46d1958 100644
--- a/orc-rt/unittests/SPSWrapperFunctionTest.cpp
+++ b/orc-rt/unittests/SPSWrapperFunctionTest.cpp
@@ -242,6 +242,30 @@ TEST(SPSWrapperFunctionUtilsTest, TransparentSerializationPointers) {
EXPECT_EQ(P, &X);
}
+static void
+expected_int_pointer_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx,
+ orc_rt_WrapperFunctionReturn Return,
+ orc_rt_WrapperFunctionBuffer ArgBytes) {
+ SPSWrapperFunction<SPSExpected<SPSExecutorAddr>(SPSExecutorAddr)>::handle(
+ Session, CallCtx, Return, ArgBytes,
+ [](move_only_function<void(Expected<int32_t *>)> Return, int32_t *P) {
+ Return(P);
+ });
+}
+
+TEST(SPSWrapperFunctionUtilsTest, TransparentSerializationExpectedPointers) {
+ int X = 42;
+ int *P = nullptr;
+ SPSWrapperFunction<SPSExpected<SPSExecutorAddr>(SPSExecutorAddr)>::call(
+ DirectCaller(nullptr, expected_int_pointer_sps_wrapper),
+ [&](Expected<Expected<int32_t *>> R) {
+ P = cantFail(cantFail(std::move(R)));
+ },
+ &X);
+
+ EXPECT_EQ(P, &X);
+}
+
template <size_t N> struct SPSOpCounter {};
namespace orc_rt {
More information about the llvm-commits
mailing list