[llvm] 8b11783 - [ORC] Add non-const WrapperFunctionResult::data method, simplify allocate.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 24 00:15:46 PDT 2021
Author: Lang Hames
Date: 2021-08-24T17:15:37+10:00
New Revision: 8b117830b1b16b235e3d8447a4a70d624b69c641
URL: https://github.com/llvm/llvm-project/commit/8b117830b1b16b235e3d8447a4a70d624b69c641
DIFF: https://github.com/llvm/llvm-project/commit/8b117830b1b16b235e3d8447a4a70d624b69c641.diff
LOG: [ORC] Add non-const WrapperFunctionResult::data method, simplify allocate.
WrapperFunctionResult no longer supports wrapping constant data, so this patch
adds a non-const data method. Since data can now be written through the data
method, the allocate method can be simplified to return a WrapperFunctionResult.
Added:
Modified:
llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h
llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/OrcRPCTPCServer.h
llvm/unittests/ExecutionEngine/Orc/ExecutionSessionWrapperFunctionCallsTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h
index 3154bf68271fe..bd74b5b3529d3 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h
@@ -89,6 +89,13 @@ class WrapperFunctionResult {
}
/// Get a pointer to the data contained in this instance.
+ char *data() {
+ assert((R.Size != 0 || R.Data.ValuePtr == nullptr) &&
+ "Cannot get data for out-of-band error value");
+ return R.Size > sizeof(R.Data.Value) ? R.Data.ValuePtr : R.Data.Value;
+ }
+
+ /// Get a const pointer to the data contained in this instance.
const char *data() const {
assert((R.Size != 0 || R.Data.ValuePtr == nullptr) &&
"Cannot get data for out-of-band error value");
@@ -108,24 +115,19 @@ class WrapperFunctionResult {
/// Create a WrapperFunctionResult with the given size and return a pointer
/// to the underlying memory.
- static char *allocate(WrapperFunctionResult &WFR, size_t Size) {
+ static WrapperFunctionResult allocate(size_t Size) {
// Reset.
- WFR = WrapperFunctionResult();
+ WrapperFunctionResult WFR;
WFR.R.Size = Size;
- char *DataPtr;
- if (WFR.R.Size > sizeof(WFR.R.Data.Value)) {
- DataPtr = (char *)malloc(WFR.R.Size);
- WFR.R.Data.ValuePtr = DataPtr;
- } else
- DataPtr = WFR.R.Data.Value;
- return DataPtr;
+ if (WFR.R.Size > sizeof(WFR.R.Data.Value))
+ WFR.R.Data.ValuePtr = (char *)malloc(WFR.R.Size);
+ return WFR;
}
/// Copy from the given char range.
static WrapperFunctionResult copyFrom(const char *Source, size_t Size) {
- WrapperFunctionResult WFR;
- char *DataPtr = allocate(WFR, Size);
- memcpy(DataPtr, Source, Size);
+ auto WFR = allocate(Size);
+ memcpy(WFR.data(), Source, Size);
return WFR;
}
@@ -174,10 +176,8 @@ namespace detail {
template <typename SPSArgListT, typename... ArgTs>
WrapperFunctionResult
serializeViaSPSToWrapperFunctionResult(const ArgTs &...Args) {
- WrapperFunctionResult Result;
- char *DataPtr =
- WrapperFunctionResult::allocate(Result, SPSArgListT::size(Args...));
- SPSOutputBuffer OB(DataPtr, Result.size());
+ auto Result = WrapperFunctionResult::allocate(SPSArgListT::size(Args...));
+ SPSOutputBuffer OB(Result.data(), Result.size());
if (!SPSArgListT::serialize(OB, Args...))
return WrapperFunctionResult::createOutOfBandError(
"Error serializing arguments to blob in call");
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/OrcRPCTPCServer.h b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/OrcRPCTPCServer.h
index 96e4341fce688..0b11371905aff 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/OrcRPCTPCServer.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/OrcRPCTPCServer.h
@@ -125,10 +125,9 @@ class SerializationTraits<
if (auto Err = deserializeSeq(C, Size))
return Err;
- WrapperFunctionResult Tmp;
- char *Data = WrapperFunctionResult::allocate(Tmp, Size);
+ auto Tmp = WrapperFunctionResult::allocate(Size);
- if (auto Err = C.readBytes(Data, Size))
+ if (auto Err = C.readBytes(Tmp.data(), Tmp.size()))
return Err;
E = std::move(Tmp);
diff --git a/llvm/unittests/ExecutionEngine/Orc/ExecutionSessionWrapperFunctionCallsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/ExecutionSessionWrapperFunctionCallsTest.cpp
index 39554e2a82aa7..c30275d87ad38 100644
--- a/llvm/unittests/ExecutionEngine/Orc/ExecutionSessionWrapperFunctionCallsTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/ExecutionSessionWrapperFunctionCallsTest.cpp
@@ -97,10 +97,8 @@ TEST(ExecutionSessionWrapperFunctionCalls, RegisterAsyncHandlerAndRun) {
using ArgSerialization = SPSArgList<int32_t, int32_t>;
size_t ArgBufferSize = ArgSerialization::size(1, 2);
- WrapperFunctionResult ArgBuffer;
- char *ArgBufferData =
- WrapperFunctionResult::allocate(ArgBuffer, ArgBufferSize);
- SPSOutputBuffer OB(ArgBufferData, ArgBufferSize);
+ auto ArgBuffer = WrapperFunctionResult::allocate(ArgBufferSize);
+ SPSOutputBuffer OB(ArgBuffer.data(), ArgBuffer.size());
EXPECT_TRUE(ArgSerialization::serialize(OB, 1, 2));
ES.runJITDispatchHandler(
More information about the llvm-commits
mailing list