[compiler-rt] ea9826f - [ORC-RT] Avoid switching out-of-band error value into __orc_rt::Error and back.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 19 19:53:24 PDT 2021
Author: Lang Hames
Date: 2021-10-19T18:38:01-07:00
New Revision: ea9826ff77195c12dfba698d5fcb90786c949aa2
URL: https://github.com/llvm/llvm-project/commit/ea9826ff77195c12dfba698d5fcb90786c949aa2
DIFF: https://github.com/llvm/llvm-project/commit/ea9826ff77195c12dfba698d5fcb90786c949aa2.diff
LOG: [ORC-RT] Avoid switching out-of-band error value into __orc_rt::Error and back.
WrapperFunctionResult can already convey serialization errors as out-of-band
error values, so there's no need to wrap it in an Expected here. Removing the
wrapper simplifies the plumbing and call sites.
Added:
Modified:
compiler-rt/lib/orc/wrapper_function_utils.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/orc/wrapper_function_utils.h b/compiler-rt/lib/orc/wrapper_function_utils.h
index db6c897241abf..a78c999ae5a22 100644
--- a/compiler-rt/lib/orc/wrapper_function_utils.h
+++ b/compiler-rt/lib/orc/wrapper_function_utils.h
@@ -116,14 +116,14 @@ class WrapperFunctionResult {
namespace detail {
template <typename SPSArgListT, typename... ArgTs>
-Expected<WrapperFunctionResult>
+WrapperFunctionResult
serializeViaSPSToWrapperFunctionResult(const ArgTs &...Args) {
auto Result = WrapperFunctionResult::allocate(SPSArgListT::size(Args...));
SPSOutputBuffer OB(Result.data(), Result.size());
if (!SPSArgListT::serialize(OB, Args...))
- return make_error<StringError>(
+ return WrapperFunctionResult::createOutOfBandError(
"Error serializing arguments to blob in call");
- return std::move(Result);
+ return Result;
}
template <typename RetT> class WrapperFunctionHandlerCaller {
@@ -171,12 +171,8 @@ class WrapperFunctionHandlerHelper<RetT(ArgTs...), ResultSerializer,
auto HandlerResult = WrapperFunctionHandlerCaller<RetT>::call(
std::forward<HandlerT>(H), Args, ArgIndices{});
- if (auto Result = ResultSerializer<decltype(HandlerResult)>::serialize(
- std::move(HandlerResult)))
- return std::move(*Result);
- else
- return WrapperFunctionResult::createOutOfBandError(
- toString(Result.takeError()));
+ return ResultSerializer<decltype(HandlerResult)>::serialize(
+ std::move(HandlerResult));
}
private:
@@ -186,7 +182,6 @@ class WrapperFunctionHandlerHelper<RetT(ArgTs...), ResultSerializer,
SPSInputBuffer IB(ArgData, ArgSize);
return SPSArgList<SPSTagTs...>::deserialize(IB, std::get<I>(Args)...);
}
-
};
// Map function references to function types.
@@ -215,7 +210,7 @@ class WrapperFunctionHandlerHelper<RetT (ClassT::*)(ArgTs...) const,
template <typename SPSRetTagT, typename RetT> class ResultSerializer {
public:
- static Expected<WrapperFunctionResult> serialize(RetT Result) {
+ static WrapperFunctionResult serialize(RetT Result) {
return serializeViaSPSToWrapperFunctionResult<SPSArgList<SPSRetTagT>>(
Result);
}
@@ -223,7 +218,7 @@ template <typename SPSRetTagT, typename RetT> class ResultSerializer {
template <typename SPSRetTagT> class ResultSerializer<SPSRetTagT, Error> {
public:
- static Expected<WrapperFunctionResult> serialize(Error Err) {
+ static WrapperFunctionResult serialize(Error Err) {
return serializeViaSPSToWrapperFunctionResult<SPSArgList<SPSRetTagT>>(
toSPSSerializable(std::move(Err)));
}
@@ -232,7 +227,7 @@ template <typename SPSRetTagT> class ResultSerializer<SPSRetTagT, Error> {
template <typename SPSRetTagT, typename T>
class ResultSerializer<SPSRetTagT, Expected<T>> {
public:
- static Expected<WrapperFunctionResult> serialize(Expected<T> E) {
+ static WrapperFunctionResult serialize(Expected<T> E) {
return serializeViaSPSToWrapperFunctionResult<SPSArgList<SPSRetTagT>>(
toSPSSerializable(std::move(E)));
}
@@ -310,12 +305,11 @@ class WrapperFunction<SPSRetTagT(SPSTagTs...)> {
auto ArgBuffer =
detail::serializeViaSPSToWrapperFunctionResult<SPSArgList<SPSTagTs...>>(
Args...);
- if (!ArgBuffer)
- return ArgBuffer.takeError();
+ 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 = __orc_rt_jit_dispatch(
+ &__orc_rt_jit_dispatch_ctx, FnTag, ArgBuffer.data(), ArgBuffer.size());
if (auto ErrMsg = ResultBuffer.getOutOfBandError())
return make_error<StringError>(ErrMsg);
More information about the llvm-commits
mailing list