[compiler-rt] 8614cb9 - [ORC-RT] Add non-const WrapperFunctionResult data access, simplify allocate.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 24 00:35:15 PDT 2021
Author: Lang Hames
Date: 2021-08-24T17:34:59+10:00
New Revision: 8614cb9f999dc712138a553a710220b299576f41
URL: https://github.com/llvm/llvm-project/commit/8614cb9f999dc712138a553a710220b299576f41
DIFF: https://github.com/llvm/llvm-project/commit/8614cb9f999dc712138a553a710220b299576f41.diff
LOG: [ORC-RT] Add non-const WrapperFunctionResult data access, simplify allocate.
WrapperFunctionResult no longer supports wrapping constant data, so this patch
provides direct non-const access to the wrapped data. Since wrapped data can now
be written, the WrapperFunctionResult::allocate method can be simplified to
return a WrapperFunctionResult.
This is essentially the same change (and with the same motivation) as LLVM
commit 8b117830b1b, but applied to the ORC runtime's WrapperFunctionResult code.
Added:
Modified:
compiler-rt/lib/orc/c_api.h
compiler-rt/lib/orc/wrapper_function_utils.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/orc/c_api.h b/compiler-rt/lib/orc/c_api.h
index 6677da06ede52..a3f3acb388779 100644
--- a/compiler-rt/lib/orc/c_api.h
+++ b/compiler-rt/lib/orc/c_api.h
@@ -91,15 +91,13 @@ __orc_rt_CWrapperFunctionResultInit(__orc_rt_CWrapperFunctionResult *R) {
* Create an __orc_rt_CWrapperFunctionResult with an uninitialized buffer of
* size Size. The buffer is returned via the DataPtr argument.
*/
-static inline char *
-__orc_rt_CWrapperFunctionResultAllocate(__orc_rt_CWrapperFunctionResult *R,
- size_t Size) {
- R->Size = Size;
- if (Size <= sizeof(R->Data.Value))
- return R->Data.Value;
-
- R->Data.ValuePtr = (char *)malloc(Size);
- return R->Data.ValuePtr;
+static inline __orc_rt_CWrapperFunctionResult
+__orc_rt_CWrapperFunctionResultAllocate(size_t Size) {
+ __orc_rt_CWrapperFunctionResult R;
+ R.Size = Size;
+ if (Size > sizeof(R.Data.Value))
+ R.Data.ValuePtr = (char *)malloc(Size);
+ return R;
}
/**
@@ -163,8 +161,8 @@ __orc_rt_DisposeCWrapperFunctionResult(__orc_rt_CWrapperFunctionResult *R) {
* Get a pointer to the data contained in the given
* __orc_rt_CWrapperFunctionResult.
*/
-static inline const char *
-__orc_rt_CWrapperFunctionResultData(const __orc_rt_CWrapperFunctionResult *R) {
+static inline char *
+__orc_rt_CWrapperFunctionResultData(__orc_rt_CWrapperFunctionResult *R) {
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;
diff --git a/compiler-rt/lib/orc/wrapper_function_utils.h b/compiler-rt/lib/orc/wrapper_function_utils.h
index 49faa03e5eb81..db6c897241abf 100644
--- a/compiler-rt/lib/orc/wrapper_function_utils.h
+++ b/compiler-rt/lib/orc/wrapper_function_utils.h
@@ -61,7 +61,7 @@ class WrapperFunctionResult {
}
/// Get a pointer to the data contained in this instance.
- const char *data() const { return __orc_rt_CWrapperFunctionResultData(&R); }
+ char *data() { return __orc_rt_CWrapperFunctionResultData(&R); }
/// Returns the size of the data contained in this instance.
size_t size() const { return __orc_rt_CWrapperFunctionResultSize(&R); }
@@ -72,10 +72,10 @@ class WrapperFunctionResult {
/// Create a WrapperFunctionResult with the given size and return a pointer
/// to the underlying memory.
- static char *allocate(WrapperFunctionResult &R, size_t Size) {
- __orc_rt_DisposeCWrapperFunctionResult(&R.R);
- __orc_rt_CWrapperFunctionResultInit(&R.R);
- return __orc_rt_CWrapperFunctionResultAllocate(&R.R, Size);
+ static WrapperFunctionResult allocate(size_t Size) {
+ WrapperFunctionResult R;
+ R.R = __orc_rt_CWrapperFunctionResultAllocate(Size);
+ return R;
}
/// Copy from the given char range.
@@ -118,10 +118,8 @@ namespace detail {
template <typename SPSArgListT, typename... ArgTs>
Expected<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 make_error<StringError>(
"Error serializing arguments to blob in call");
More information about the llvm-commits
mailing list