[llvm] 12b2cc2 - [ORC] Rename SupportFunctionCall to WrapperFunctionCall.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 28 17:48:58 PDT 2021


Author: Lang Hames
Date: 2021-10-28T17:48:54-07:00
New Revision: 12b2cc229421cd9bd3f9f0cc44e7564b41fa9e5e

URL: https://github.com/llvm/llvm-project/commit/12b2cc229421cd9bd3f9f0cc44e7564b41fa9e5e
DIFF: https://github.com/llvm/llvm-project/commit/12b2cc229421cd9bd3f9f0cc44e7564b41fa9e5e.diff

LOG: [ORC] Rename SupportFunctionCall to WrapperFunctionCall.

The new name better suits the type.

This patch also changes the signature of the run method (it now returns a
WrapperFunctionResult), and adds runWithSPSRet methods that deserialize the
function result using SPS.

Together these chages bring this type into close alignment with its ORC runtime
counterpart.

Added: 
    

Modified: 
    llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h
    llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.h
    llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h
index fc70c46df231f..d071eb9b475e8 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h
@@ -69,36 +69,48 @@ inline std::string getWireProtectionFlagsStr(WireProtectionFlags WPF) {
   return Result;
 }
 
-struct SupportFunctionCall {
-  using FnTy = shared::detail::CWrapperFunctionResult(const char *ArgData,
-                                                      size_t ArgSize);
+struct WrapperFunctionCall {
   ExecutorAddr Func;
-  ExecutorAddrRange ArgDataRange;
+  ExecutorAddrRange ArgData;
 
-  SupportFunctionCall() = default;
-  SupportFunctionCall(ExecutorAddr Func, ExecutorAddr ArgData,
+  WrapperFunctionCall() = default;
+  WrapperFunctionCall(ExecutorAddr Func, ExecutorAddr ArgData,
                       ExecutorAddrDiff ArgSize)
-      : Func(Func), ArgDataRange(ArgData, ArgSize) {}
-  SupportFunctionCall(ExecutorAddr Func, ExecutorAddrRange ArgDataRange)
-      : Func(Func), ArgDataRange(ArgDataRange) {}
-
-  Error run() {
-    shared::WrapperFunctionResult WFR(Func.toPtr<FnTy *>()(
-        ArgDataRange.Start.toPtr<const char *>(),
-        static_cast<size_t>(ArgDataRange.size().getValue())));
+      : Func(Func), ArgData(ArgData, ArgSize) {}
+  WrapperFunctionCall(ExecutorAddr Func, ExecutorAddrRange ArgData)
+      : Func(Func), ArgData(ArgData) {}
+
+  shared::WrapperFunctionResult run() {
+    using FnTy = shared::detail::CWrapperFunctionResult(const char *ArgData,
+                                                        size_t ArgSize);
+    return shared::WrapperFunctionResult(
+        Func.toPtr<FnTy *>()(ArgData.Start.toPtr<const char *>(),
+                             static_cast<size_t>(ArgData.size().getValue())));
+  }
+
+  /// Run call and deserialize result using SPS.
+  template <typename SPSRetT, typename RetT> Error runWithSPSRet(RetT &RetVal) {
+    auto WFR = run();
     if (const char *ErrMsg = WFR.getOutOfBandError())
       return make_error<StringError>(ErrMsg, inconvertibleErrorCode());
-    if (!WFR.empty())
-      return make_error<StringError>("Unexpected result bytes from "
-                                     "support function call",
+    shared::SPSInputBuffer IB(WFR.data(), WFR.size());
+    if (!shared::SPSSerializationTraits<SPSRetT, RetT>::deserialize(IB, RetVal))
+      return make_error<StringError>("Could not deserialize result from "
+                                     "serialized wrapper function call",
                                      inconvertibleErrorCode());
     return Error::success();
   }
+
+  /// Overload for SPS functions returning void.
+  Error runWithSPSRet() {
+    shared::SPSEmpty E;
+    return runWithSPSRet<shared::SPSEmpty>(E);
+  }
 };
 
 struct AllocationActionsPair {
-  SupportFunctionCall Finalize;
-  SupportFunctionCall Deallocate;
+  WrapperFunctionCall Finalize;
+  WrapperFunctionCall Deallocate;
 };
 
 struct SegFinalizeRequest {
@@ -155,14 +167,14 @@ namespace shared {
 
 class SPSMemoryProtectionFlags {};
 
-using SPSSupportFunctionCall = SPSTuple<SPSExecutorAddr, SPSExecutorAddrRange>;
+using SPSWrapperFunctionCall = SPSTuple<SPSExecutorAddr, SPSExecutorAddrRange>;
 
 using SPSSegFinalizeRequest =
     SPSTuple<SPSMemoryProtectionFlags, SPSExecutorAddr, uint64_t,
              SPSSequence<char>>;
 
 using SPSAllocationActionsPair =
-    SPSTuple<SPSSupportFunctionCall, SPSSupportFunctionCall>;
+    SPSTuple<SPSWrapperFunctionCall, SPSWrapperFunctionCall>;
 
 using SPSFinalizeRequest = SPSTuple<SPSSequence<SPSSegFinalizeRequest>,
                                     SPSSequence<SPSAllocationActionsPair>>;
@@ -201,23 +213,23 @@ class SPSSerializationTraits<SPSMemoryProtectionFlags,
 };
 
 template <>
-class SPSSerializationTraits<SPSSupportFunctionCall,
-                             tpctypes::SupportFunctionCall> {
-  using AL = SPSSupportFunctionCall::AsArgList;
+class SPSSerializationTraits<SPSWrapperFunctionCall,
+                             tpctypes::WrapperFunctionCall> {
+  using AL = SPSWrapperFunctionCall::AsArgList;
 
 public:
-  static size_t size(const tpctypes::SupportFunctionCall &SFC) {
-    return AL::size(SFC.Func, SFC.ArgDataRange);
+  static size_t size(const tpctypes::WrapperFunctionCall &WFC) {
+    return AL::size(WFC.Func, WFC.ArgData);
   }
 
   static bool serialize(SPSOutputBuffer &OB,
-                        const tpctypes::SupportFunctionCall &SFC) {
-    return AL::serialize(OB, SFC.Func, SFC.ArgDataRange);
+                        const tpctypes::WrapperFunctionCall &WFC) {
+    return AL::serialize(OB, WFC.Func, WFC.ArgData);
   }
 
   static bool deserialize(SPSInputBuffer &IB,
-                          tpctypes::SupportFunctionCall &SFC) {
-    return AL::deserialize(IB, SFC.Func, SFC.ArgDataRange);
+                          tpctypes::WrapperFunctionCall &WFC) {
+    return AL::deserialize(IB, WFC.Func, WFC.ArgData);
   }
 };
 

diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.h b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.h
index 21c8a5dd312d5..00094055c4f3a 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.h
@@ -43,7 +43,7 @@ class SimpleExecutorMemoryManager : public ExecutorBootstrapService {
 private:
   struct Allocation {
     size_t Size = 0;
-    std::vector<tpctypes::SupportFunctionCall> DeallocationActions;
+    std::vector<tpctypes::WrapperFunctionCall> DeallocationActions;
   };
 
   using AllocationsMap = DenseMap<void *, Allocation>;

diff  --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.cpp b/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.cpp
index c25d188e0054c..90dcc9e4ccf7c 100644
--- a/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.cpp
@@ -35,7 +35,7 @@ Expected<ExecutorAddr> SimpleExecutorMemoryManager::allocate(uint64_t Size) {
 
 Error SimpleExecutorMemoryManager::finalize(tpctypes::FinalizeRequest &FR) {
   ExecutorAddr Base(~0ULL);
-  std::vector<tpctypes::SupportFunctionCall> DeallocationActions;
+  std::vector<tpctypes::WrapperFunctionCall> DeallocationActions;
   size_t SuccessfulFinalizationActions = 0;
 
   if (FR.Segments.empty()) {
@@ -94,9 +94,9 @@ Error SimpleExecutorMemoryManager::finalize(tpctypes::FinalizeRequest &FR) {
 
     // Run deallocation actions for all completed finalization actions.
     while (SuccessfulFinalizationActions)
-      Err = joinErrors(
-          std::move(Err),
-          FR.Actions[--SuccessfulFinalizationActions].Deallocate.run());
+      Err =
+          joinErrors(std::move(Err), FR.Actions[--SuccessfulFinalizationActions]
+                                         .Deallocate.runWithSPSRet());
 
     // Deallocate memory.
     sys::MemoryBlock MB(AllocToDestroy.first, AllocToDestroy.second.Size);
@@ -139,7 +139,7 @@ Error SimpleExecutorMemoryManager::finalize(tpctypes::FinalizeRequest &FR) {
 
   // Run finalization actions.
   for (auto &ActPair : FR.Actions) {
-    if (auto Err = ActPair.Finalize.run())
+    if (auto Err = ActPair.Finalize.runWithSPSRet())
       return BailOut(std::move(Err));
     ++SuccessfulFinalizationActions;
   }
@@ -211,7 +211,8 @@ Error SimpleExecutorMemoryManager::deallocateImpl(void *Base, Allocation &A) {
   Error Err = Error::success();
 
   while (!A.DeallocationActions.empty()) {
-    Err = joinErrors(std::move(Err), A.DeallocationActions.back().run());
+    Err = joinErrors(std::move(Err),
+                     A.DeallocationActions.back().runWithSPSRet());
     A.DeallocationActions.pop_back();
   }
 


        


More information about the llvm-commits mailing list