Skip to content

Commit 12b2cc2

Browse files
committed
[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.
1 parent d1e9514 commit 12b2cc2

File tree

3 files changed

+50
-37
lines changed

3 files changed

+50
-37
lines changed

llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -69,36 +69,48 @@ inline std::string getWireProtectionFlagsStr(WireProtectionFlags WPF) {
6969
return Result;
7070
}
7171

72-
struct SupportFunctionCall {
73-
using FnTy = shared::detail::CWrapperFunctionResult(const char *ArgData,
74-
size_t ArgSize);
72+
struct WrapperFunctionCall {
7573
ExecutorAddr Func;
76-
ExecutorAddrRange ArgDataRange;
74+
ExecutorAddrRange ArgData;
7775

78-
SupportFunctionCall() = default;
79-
SupportFunctionCall(ExecutorAddr Func, ExecutorAddr ArgData,
76+
WrapperFunctionCall() = default;
77+
WrapperFunctionCall(ExecutorAddr Func, ExecutorAddr ArgData,
8078
ExecutorAddrDiff ArgSize)
81-
: Func(Func), ArgDataRange(ArgData, ArgSize) {}
82-
SupportFunctionCall(ExecutorAddr Func, ExecutorAddrRange ArgDataRange)
83-
: Func(Func), ArgDataRange(ArgDataRange) {}
84-
85-
Error run() {
86-
shared::WrapperFunctionResult WFR(Func.toPtr<FnTy *>()(
87-
ArgDataRange.Start.toPtr<const char *>(),
88-
static_cast<size_t>(ArgDataRange.size().getValue())));
79+
: Func(Func), ArgData(ArgData, ArgSize) {}
80+
WrapperFunctionCall(ExecutorAddr Func, ExecutorAddrRange ArgData)
81+
: Func(Func), ArgData(ArgData) {}
82+
83+
shared::WrapperFunctionResult run() {
84+
using FnTy = shared::detail::CWrapperFunctionResult(const char *ArgData,
85+
size_t ArgSize);
86+
return shared::WrapperFunctionResult(
87+
Func.toPtr<FnTy *>()(ArgData.Start.toPtr<const char *>(),
88+
static_cast<size_t>(ArgData.size().getValue())));
89+
}
90+
91+
/// Run call and deserialize result using SPS.
92+
template <typename SPSRetT, typename RetT> Error runWithSPSRet(RetT &RetVal) {
93+
auto WFR = run();
8994
if (const char *ErrMsg = WFR.getOutOfBandError())
9095
return make_error<StringError>(ErrMsg, inconvertibleErrorCode());
91-
if (!WFR.empty())
92-
return make_error<StringError>("Unexpected result bytes from "
93-
"support function call",
96+
shared::SPSInputBuffer IB(WFR.data(), WFR.size());
97+
if (!shared::SPSSerializationTraits<SPSRetT, RetT>::deserialize(IB, RetVal))
98+
return make_error<StringError>("Could not deserialize result from "
99+
"serialized wrapper function call",
94100
inconvertibleErrorCode());
95101
return Error::success();
96102
}
103+
104+
/// Overload for SPS functions returning void.
105+
Error runWithSPSRet() {
106+
shared::SPSEmpty E;
107+
return runWithSPSRet<shared::SPSEmpty>(E);
108+
}
97109
};
98110

99111
struct AllocationActionsPair {
100-
SupportFunctionCall Finalize;
101-
SupportFunctionCall Deallocate;
112+
WrapperFunctionCall Finalize;
113+
WrapperFunctionCall Deallocate;
102114
};
103115

104116
struct SegFinalizeRequest {
@@ -155,14 +167,14 @@ namespace shared {
155167

156168
class SPSMemoryProtectionFlags {};
157169

158-
using SPSSupportFunctionCall = SPSTuple<SPSExecutorAddr, SPSExecutorAddrRange>;
170+
using SPSWrapperFunctionCall = SPSTuple<SPSExecutorAddr, SPSExecutorAddrRange>;
159171

160172
using SPSSegFinalizeRequest =
161173
SPSTuple<SPSMemoryProtectionFlags, SPSExecutorAddr, uint64_t,
162174
SPSSequence<char>>;
163175

164176
using SPSAllocationActionsPair =
165-
SPSTuple<SPSSupportFunctionCall, SPSSupportFunctionCall>;
177+
SPSTuple<SPSWrapperFunctionCall, SPSWrapperFunctionCall>;
166178

167179
using SPSFinalizeRequest = SPSTuple<SPSSequence<SPSSegFinalizeRequest>,
168180
SPSSequence<SPSAllocationActionsPair>>;
@@ -201,23 +213,23 @@ class SPSSerializationTraits<SPSMemoryProtectionFlags,
201213
};
202214

203215
template <>
204-
class SPSSerializationTraits<SPSSupportFunctionCall,
205-
tpctypes::SupportFunctionCall> {
206-
using AL = SPSSupportFunctionCall::AsArgList;
216+
class SPSSerializationTraits<SPSWrapperFunctionCall,
217+
tpctypes::WrapperFunctionCall> {
218+
using AL = SPSWrapperFunctionCall::AsArgList;
207219

208220
public:
209-
static size_t size(const tpctypes::SupportFunctionCall &SFC) {
210-
return AL::size(SFC.Func, SFC.ArgDataRange);
221+
static size_t size(const tpctypes::WrapperFunctionCall &WFC) {
222+
return AL::size(WFC.Func, WFC.ArgData);
211223
}
212224

213225
static bool serialize(SPSOutputBuffer &OB,
214-
const tpctypes::SupportFunctionCall &SFC) {
215-
return AL::serialize(OB, SFC.Func, SFC.ArgDataRange);
226+
const tpctypes::WrapperFunctionCall &WFC) {
227+
return AL::serialize(OB, WFC.Func, WFC.ArgData);
216228
}
217229

218230
static bool deserialize(SPSInputBuffer &IB,
219-
tpctypes::SupportFunctionCall &SFC) {
220-
return AL::deserialize(IB, SFC.Func, SFC.ArgDataRange);
231+
tpctypes::WrapperFunctionCall &WFC) {
232+
return AL::deserialize(IB, WFC.Func, WFC.ArgData);
221233
}
222234
};
223235

llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class SimpleExecutorMemoryManager : public ExecutorBootstrapService {
4343
private:
4444
struct Allocation {
4545
size_t Size = 0;
46-
std::vector<tpctypes::SupportFunctionCall> DeallocationActions;
46+
std::vector<tpctypes::WrapperFunctionCall> DeallocationActions;
4747
};
4848

4949
using AllocationsMap = DenseMap<void *, Allocation>;

llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Expected<ExecutorAddr> SimpleExecutorMemoryManager::allocate(uint64_t Size) {
3535

3636
Error SimpleExecutorMemoryManager::finalize(tpctypes::FinalizeRequest &FR) {
3737
ExecutorAddr Base(~0ULL);
38-
std::vector<tpctypes::SupportFunctionCall> DeallocationActions;
38+
std::vector<tpctypes::WrapperFunctionCall> DeallocationActions;
3939
size_t SuccessfulFinalizationActions = 0;
4040

4141
if (FR.Segments.empty()) {
@@ -94,9 +94,9 @@ Error SimpleExecutorMemoryManager::finalize(tpctypes::FinalizeRequest &FR) {
9494

9595
// Run deallocation actions for all completed finalization actions.
9696
while (SuccessfulFinalizationActions)
97-
Err = joinErrors(
98-
std::move(Err),
99-
FR.Actions[--SuccessfulFinalizationActions].Deallocate.run());
97+
Err =
98+
joinErrors(std::move(Err), FR.Actions[--SuccessfulFinalizationActions]
99+
.Deallocate.runWithSPSRet());
100100

101101
// Deallocate memory.
102102
sys::MemoryBlock MB(AllocToDestroy.first, AllocToDestroy.second.Size);
@@ -139,7 +139,7 @@ Error SimpleExecutorMemoryManager::finalize(tpctypes::FinalizeRequest &FR) {
139139

140140
// Run finalization actions.
141141
for (auto &ActPair : FR.Actions) {
142-
if (auto Err = ActPair.Finalize.run())
142+
if (auto Err = ActPair.Finalize.runWithSPSRet())
143143
return BailOut(std::move(Err));
144144
++SuccessfulFinalizationActions;
145145
}
@@ -211,7 +211,8 @@ Error SimpleExecutorMemoryManager::deallocateImpl(void *Base, Allocation &A) {
211211
Error Err = Error::success();
212212

213213
while (!A.DeallocationActions.empty()) {
214-
Err = joinErrors(std::move(Err), A.DeallocationActions.back().run());
214+
Err = joinErrors(std::move(Err),
215+
A.DeallocationActions.back().runWithSPSRet());
215216
A.DeallocationActions.pop_back();
216217
}
217218

0 commit comments

Comments
 (0)