[compiler-rt] 69f8923 - Re-apply "[ORC-RT] Replace FnTag arg of WrapperFunction::call..." with fixes.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 10 02:55:39 PDT 2024
Author: Lang Hames
Date: 2024-09-10T19:55:31+10:00
New Revision: 69f8923efa61034b57805a8d6d859e9c1ca976eb
URL: https://github.com/llvm/llvm-project/commit/69f8923efa61034b57805a8d6d859e9c1ca976eb
DIFF: https://github.com/llvm/llvm-project/commit/69f8923efa61034b57805a8d6d859e9c1ca976eb.diff
LOG: Re-apply "[ORC-RT] Replace FnTag arg of WrapperFunction::call..." with fixes.
This reapplies commits 462251b80b7 and 9b67c99dc5b, which were reverted in
53d35c4e86b due to bot failures for the wrapper_function_utils_test.cpp unit
test.
Added:
compiler-rt/lib/orc/jit_dispatch.h
Modified:
compiler-rt/lib/orc/coff_platform.cpp
compiler-rt/lib/orc/elfnix_platform.cpp
compiler-rt/lib/orc/macho_platform.cpp
compiler-rt/lib/orc/tests/unit/wrapper_function_utils_test.cpp
compiler-rt/lib/orc/wrapper_function_utils.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/orc/coff_platform.cpp b/compiler-rt/lib/orc/coff_platform.cpp
index 346d896f6c9484..49b805a0ec7d31 100644
--- a/compiler-rt/lib/orc/coff_platform.cpp
+++ b/compiler-rt/lib/orc/coff_platform.cpp
@@ -17,6 +17,7 @@
#include "debug.h"
#include "error.h"
+#include "jit_dispatch.h"
#include "wrapper_function_utils.h"
#include <array>
@@ -315,9 +316,9 @@ Error COFFPlatformRuntimeState::dlopenFull(JITDylibState &JDS) {
// Call back to the JIT to push the initializers.
Expected<COFFJITDylibDepInfoMap> DepInfoMap((COFFJITDylibDepInfoMap()));
if (auto Err = WrapperFunction<SPSExpected<SPSCOFFJITDylibDepInfoMap>(
- SPSExecutorAddr)>::call(&__orc_rt_coff_push_initializers_tag,
- DepInfoMap,
- ExecutorAddr::fromPtr(JDS.Header)))
+ SPSExecutorAddr)>::
+ call(JITDispatch(&__orc_rt_coff_push_initializers_tag), DepInfoMap,
+ ExecutorAddr::fromPtr(JDS.Header)))
return Err;
if (!DepInfoMap)
return DepInfoMap.takeError();
@@ -445,10 +446,9 @@ COFFPlatformRuntimeState::lookupSymbolInJITDylib(void *header,
std::string_view Sym) {
Expected<ExecutorAddr> Result((ExecutorAddr()));
if (auto Err = WrapperFunction<SPSExpected<SPSExecutorAddr>(
- SPSExecutorAddr, SPSString)>::call(&__orc_rt_coff_symbol_lookup_tag,
- Result,
- ExecutorAddr::fromPtr(header),
- Sym))
+ SPSExecutorAddr,
+ SPSString)>::call(JITDispatch(&__orc_rt_coff_symbol_lookup_tag),
+ Result, ExecutorAddr::fromPtr(header), Sym))
return std::move(Err);
return Result;
}
diff --git a/compiler-rt/lib/orc/elfnix_platform.cpp b/compiler-rt/lib/orc/elfnix_platform.cpp
index dc6af65dc996a0..bd76e3ed0ece7c 100644
--- a/compiler-rt/lib/orc/elfnix_platform.cpp
+++ b/compiler-rt/lib/orc/elfnix_platform.cpp
@@ -14,6 +14,7 @@
#include "common.h"
#include "compiler.h"
#include "error.h"
+#include "jit_dispatch.h"
#include "wrapper_function_utils.h"
#include <algorithm>
@@ -352,10 +353,9 @@ ELFNixPlatformRuntimeState::lookupSymbolInJITDylib(void *DSOHandle,
std::string_view Sym) {
Expected<ExecutorAddr> Result((ExecutorAddr()));
if (auto Err = WrapperFunction<SPSExpected<SPSExecutorAddr>(
- SPSExecutorAddr, SPSString)>::call(&__orc_rt_elfnix_symbol_lookup_tag,
- Result,
- ExecutorAddr::fromPtr(DSOHandle),
- Sym))
+ SPSExecutorAddr,
+ SPSString)>::call(JITDispatch(&__orc_rt_elfnix_symbol_lookup_tag),
+ Result, ExecutorAddr::fromPtr(DSOHandle), Sym))
return std::move(Err);
return Result;
}
@@ -368,8 +368,9 @@ ELFNixPlatformRuntimeState::getJITDylibInitializersByName(
std::string PathStr(Path.data(), Path.size());
if (auto Err =
WrapperFunction<SPSExpected<SPSELFNixJITDylibInitializerSequence>(
- SPSString)>::call(&__orc_rt_elfnix_get_initializers_tag, Result,
- Path))
+ SPSString)>::
+ call(JITDispatch(&__orc_rt_elfnix_get_initializers_tag), Result,
+ Path))
return std::move(Err);
return Result;
}
diff --git a/compiler-rt/lib/orc/jit_dispatch.h b/compiler-rt/lib/orc/jit_dispatch.h
new file mode 100644
index 00000000000000..9b2329fa1e4fc7
--- /dev/null
+++ b/compiler-rt/lib/orc/jit_dispatch.h
@@ -0,0 +1,50 @@
+//===------ jit_dispatch.h - Call back to an ORC controller -----*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a part of the ORC runtime support library.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef ORC_RT_JIT_DISPATCH_H
+#define ORC_RT_JIT_DISPATCH_H
+
+#include "common.h"
+#include "wrapper_function_utils.h"
+
+namespace orc_rt {
+
+class JITDispatch {
+public:
+ JITDispatch(const void *FnTag) : FnTag(FnTag) {}
+
+ WrapperFunctionResult operator()(const char *ArgData, size_t ArgSize) {
+ // Since the functions cannot be zero/unresolved on Windows, the following
+ // reference taking would always be non-zero, thus generating a compiler
+ // warning otherwise.
+#if !defined(_WIN32)
+ if (ORC_RT_UNLIKELY(!&__orc_rt_jit_dispatch_ctx))
+ return WrapperFunctionResult::createOutOfBandError(
+ "__orc_rt_jit_dispatch_ctx not set")
+ .release();
+ if (ORC_RT_UNLIKELY(!&__orc_rt_jit_dispatch))
+ return WrapperFunctionResult::createOutOfBandError(
+ "__orc_rt_jit_dispatch not set")
+ .release();
+#endif
+
+ return __orc_rt_jit_dispatch(&__orc_rt_jit_dispatch_ctx, FnTag, ArgData,
+ ArgSize);
+ }
+
+private:
+ const void *FnTag;
+};
+
+} // namespace orc_rt
+
+#endif // ORC_RT_JIT_DISPATCH_H
diff --git a/compiler-rt/lib/orc/macho_platform.cpp b/compiler-rt/lib/orc/macho_platform.cpp
index 1974d3f0ef33f8..c092545b2a3677 100644
--- a/compiler-rt/lib/orc/macho_platform.cpp
+++ b/compiler-rt/lib/orc/macho_platform.cpp
@@ -16,6 +16,7 @@
#include "debug.h"
#include "error.h"
#include "interval_map.h"
+#include "jit_dispatch.h"
#include "wrapper_function_utils.h"
#include <algorithm>
@@ -915,7 +916,7 @@ Error MachOPlatformRuntimeState::requestPushSymbols(
Error OpErr = Error::success();
if (auto Err = WrapperFunction<SPSError(
SPSExecutorAddr, SPSSequence<SPSTuple<SPSString, bool>>)>::
- call(&__orc_rt_macho_push_symbols_tag, OpErr,
+ call(JITDispatch(&__orc_rt_macho_push_symbols_tag), OpErr,
ExecutorAddr::fromPtr(JDS.Header), Symbols)) {
cantFail(std::move(OpErr));
return std::move(Err);
@@ -1145,8 +1146,9 @@ Error MachOPlatformRuntimeState::dlopenFull(
// Unlock so that we can accept the initializer update.
JDStatesLock.unlock();
if (auto Err = WrapperFunction<SPSExpected<SPSMachOJITDylibDepInfoMap>(
- SPSExecutorAddr)>::call(&__orc_rt_macho_push_initializers_tag,
- DepInfo, ExecutorAddr::fromPtr(JDS.Header)))
+ SPSExecutorAddr)>::
+ call(JITDispatch(&__orc_rt_macho_push_initializers_tag), DepInfo,
+ ExecutorAddr::fromPtr(JDS.Header)))
return Err;
JDStatesLock.lock();
diff --git a/compiler-rt/lib/orc/tests/unit/wrapper_function_utils_test.cpp b/compiler-rt/lib/orc/tests/unit/wrapper_function_utils_test.cpp
index 2f54f3afb32d01..91be84f15188f2 100644
--- a/compiler-rt/lib/orc/tests/unit/wrapper_function_utils_test.cpp
+++ b/compiler-rt/lib/orc/tests/unit/wrapper_function_utils_test.cpp
@@ -10,6 +10,8 @@
//
//===----------------------------------------------------------------------===//
+#include "common.h"
+#include "jit_dispatch.h"
#include "wrapper_function_utils.h"
#include "gtest/gtest.h"
@@ -98,13 +100,14 @@ __orc_rt_jit_dispatch(__orc_rt_Opaque *Ctx, const void *FnTag,
}
TEST(WrapperFunctionUtilsTest, WrapperFunctionCallVoidNoopAndHandle) {
- EXPECT_FALSE(!!WrapperFunction<void()>::call((void *)&voidNoopWrapper));
+ EXPECT_FALSE(
+ !!WrapperFunction<void()>::call(JITDispatch((void *)&voidNoopWrapper)));
}
TEST(WrapperFunctionUtilsTest, WrapperFunctionCallAddWrapperAndHandle) {
int32_t Result;
EXPECT_FALSE(!!WrapperFunction<int32_t(int32_t, int32_t)>::call(
- (void *)&addWrapper, Result, 1, 2));
+ JITDispatch((void *)&addWrapper), Result, 1, 2));
EXPECT_EQ(Result, (int32_t)3);
}
@@ -128,7 +131,8 @@ TEST(WrapperFunctionUtilsTest, WrapperFunctionMethodCallAndHandleRet) {
int32_t Result;
AddClass AddObj(1);
EXPECT_FALSE(!!WrapperFunction<int32_t(SPSExecutorAddr, int32_t)>::call(
- (void *)&addMethodWrapper, Result, ExecutorAddr::fromPtr(&AddObj), 2));
+ JITDispatch((void *)&addMethodWrapper), Result,
+ ExecutorAddr::fromPtr(&AddObj), 2));
EXPECT_EQ(Result, (int32_t)3);
}
diff --git a/compiler-rt/lib/orc/wrapper_function_utils.h b/compiler-rt/lib/orc/wrapper_function_utils.h
index e65aac0fe4e53e..3e372fe96d2d66 100644
--- a/compiler-rt/lib/orc/wrapper_function_utils.h
+++ b/compiler-rt/lib/orc/wrapper_function_utils.h
@@ -13,10 +13,9 @@
#ifndef ORC_RT_WRAPPER_FUNCTION_UTILS_H
#define ORC_RT_WRAPPER_FUNCTION_UTILS_H
-#include "orc_rt/c_api.h"
-#include "common.h"
#include "error.h"
#include "executor_address.h"
+#include "orc_rt/c_api.h"
#include "simple_packed_serialization.h"
#include <type_traits>
@@ -288,30 +287,22 @@ class WrapperFunction<SPSRetTagT(SPSTagTs...)> {
using ResultSerializer = detail::ResultSerializer<SPSRetTagT, RetT>;
public:
- template <typename RetT, typename... ArgTs>
- static Error call(const void *FnTag, RetT &Result, const ArgTs &...Args) {
+ template <typename DispatchFn, typename RetT, typename... ArgTs>
+ static Error call(DispatchFn &&Dispatch, RetT &Result, const ArgTs &...Args) {
// RetT might be an Error or Expected value. Set the checked flag now:
// we don't want the user to have to check the unused result if this
// operation fails.
detail::ResultDeserializer<SPSRetTagT, RetT>::makeSafe(Result);
- // Since the functions cannot be zero/unresolved on Windows, the following
- // reference taking would always be non-zero, thus generating a compiler
- // warning otherwise.
-#if !defined(_WIN32)
- if (ORC_RT_UNLIKELY(!&__orc_rt_jit_dispatch_ctx))
- return make_error<StringError>("__orc_rt_jit_dispatch_ctx not set");
- if (ORC_RT_UNLIKELY(!&__orc_rt_jit_dispatch))
- return make_error<StringError>("__orc_rt_jit_dispatch not set");
-#endif
auto ArgBuffer =
WrapperFunctionResult::fromSPSArgs<SPSArgList<SPSTagTs...>>(Args...);
if (const char *ErrMsg = ArgBuffer.getOutOfBandError())
return make_error<StringError>(ErrMsg);
- WrapperFunctionResult ResultBuffer = __orc_rt_jit_dispatch(
- &__orc_rt_jit_dispatch_ctx, FnTag, ArgBuffer.data(), ArgBuffer.size());
+ WrapperFunctionResult ResultBuffer =
+ Dispatch(ArgBuffer.data(), ArgBuffer.size());
+
if (auto ErrMsg = ResultBuffer.getOutOfBandError())
return make_error<StringError>(ErrMsg);
@@ -347,10 +338,11 @@ template <typename... SPSTagTs>
class WrapperFunction<void(SPSTagTs...)>
: private WrapperFunction<SPSEmpty(SPSTagTs...)> {
public:
- template <typename... ArgTs>
- static Error call(const void *FnTag, const ArgTs &...Args) {
+ template <typename DispatchFn, typename... ArgTs>
+ static Error call(DispatchFn &&Dispatch, const ArgTs &...Args) {
SPSEmpty BE;
- return WrapperFunction<SPSEmpty(SPSTagTs...)>::call(FnTag, BE, Args...);
+ return WrapperFunction<SPSEmpty(SPSTagTs...)>::call(
+ std::forward<DispatchFn>(Dispatch), BE, Args...);
}
using WrapperFunction<SPSEmpty(SPSTagTs...)>::handle;
More information about the llvm-commits
mailing list