From 8a3675023693093d9f00157d09dda504c999439a Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Thu, 19 Aug 2021 12:19:36 +1000 Subject: [PATCH] [ORC] Handle void and no-argument async wrapper calls. --- .../Orc/Shared/WrapperFunctionUtils.h | 12 +++++++++++ .../ExecutionSessionWrapperFunctionCallsTest.cpp | 23 +++++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h index e92f580..d1d7d54 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h @@ -547,6 +547,18 @@ public: return WrapperFunction::call(Caller, BE, Args...); } + template + static void callAsync(AsyncCallerFn &&Caller, + SendDeserializedResultFn &&SendDeserializedResult, + const ArgTs &...Args) { + WrapperFunction::callAsync( + Caller, + [SDR = std::move(SendDeserializedResult)]( + Error SerializeErr, SPSEmpty E) { SDR(std::move(SerializeErr)); }, + Args...); + } + using WrapperFunction::handle; using WrapperFunction::handleAsync; }; diff --git a/llvm/unittests/ExecutionEngine/Orc/ExecutionSessionWrapperFunctionCallsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/ExecutionSessionWrapperFunctionCallsTest.cpp index 9044ead..39554e2 100644 --- a/llvm/unittests/ExecutionEngine/Orc/ExecutionSessionWrapperFunctionCallsTest.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/ExecutionSessionWrapperFunctionCallsTest.cpp @@ -30,6 +30,11 @@ static void addAsyncWrapper(unique_function SendResult, SendResult(X + Y); } +static llvm::orc::shared::detail::CWrapperFunctionResult +voidWrapper(const char *ArgData, size_t ArgSize) { + return WrapperFunction::handle(ArgData, ArgSize, []() {}).release(); +} + TEST(ExecutionSessionWrapperFunctionCalls, RunWrapperTemplate) { ExecutionSession ES(cantFail(SelfExecutorProcessControl::Create())); @@ -40,12 +45,24 @@ TEST(ExecutionSessionWrapperFunctionCalls, RunWrapperTemplate) { EXPECT_EQ(Result, 5); } -TEST(ExecutionSessionWrapperFunctionCalls, RunWrapperAsyncTemplate) { +TEST(ExecutionSessionWrapperFunctionCalls, RunVoidWrapperAsyncTemplate) { + ExecutionSession ES(cantFail(SelfExecutorProcessControl::Create())); + + std::promise RP; + ES.callSPSWrapperAsync( + [&](Error SerializationErr) { + RP.set_value(std::move(SerializationErr)); + }, + pointerToJITTargetAddress(voidWrapper)); + Error Err = RP.get_future().get(); + EXPECT_THAT_ERROR(std::move(Err), Succeeded()); +} + +TEST(ExecutionSessionWrapperFunctionCalls, RunNonVoidWrapperAsyncTemplate) { ExecutionSession ES(cantFail(SelfExecutorProcessControl::Create())); std::promise> RP; - using Sig = int32_t(int32_t, int32_t); - ES.callSPSWrapperAsync( + ES.callSPSWrapperAsync( [&](Error SerializationErr, int32_t R) { if (SerializationErr) RP.set_value(std::move(SerializationErr)); -- 2.7.4