Skip to content

Commit f3a29bd

Browse files
committed
Change design more ergonomic, add future.then()
1 parent aa5f257 commit f3a29bd

27 files changed

+1012
-418
lines changed

llvm-julia-task-dispatcher.h

Lines changed: 487 additions & 0 deletions
Large diffs are not rendered by default.

llvm/include/llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,12 @@ class LLVM_ABI JITLinkMemoryManager {
140140

141141
/// Co-synchronous convenience version of finalize.
142142
Expected<FinalizedAlloc> finalize(orc::TaskDispatcher &D) {
143-
orc::promise<MSVCPExpected<FinalizedAlloc>> FinalizeResultP;
144-
auto FinalizeResultF = FinalizeResultP.get_future();
145-
finalize([FinalizeResultP = std::move(FinalizeResultP)](
143+
orc::future<MSVCPExpected<FinalizedAlloc>> FinalizeResultF;
144+
finalize([FinalizeResultP = FinalizeResultF.get_promise(D)](
146145
Expected<FinalizedAlloc> Result) mutable {
147146
FinalizeResultP.set_value(std::move(Result));
148147
});
149-
return FinalizeResultF.get(D);
148+
return FinalizeResultF.get();
150149
}
151150
};
152151

@@ -173,14 +172,12 @@ class LLVM_ABI JITLinkMemoryManager {
173172
/// Convenience function for co-blocking allocation.
174173
AllocResult allocate(const JITLinkDylib *JD, LinkGraph &G,
175174
orc::TaskDispatcher &D) {
176-
orc::promise<MSVCPExpected<std::unique_ptr<InFlightAlloc>>> AllocResultP;
177-
auto AllocResultF = AllocResultP.get_future();
178-
allocate(
179-
JD, G,
180-
[AllocResultP = std::move(AllocResultP)](AllocResult Alloc) mutable {
181-
AllocResultP.set_value(std::move(Alloc));
182-
});
183-
return AllocResultF.get(D);
175+
orc::future<MSVCPExpected<std::unique_ptr<InFlightAlloc>>> AllocResultF;
176+
allocate(JD, G,
177+
[AllocResultP = AllocResultF.get_promise(D)](AllocResult Alloc) {
178+
AllocResultP.set_value(std::move(Alloc));
179+
});
180+
return AllocResultF.get();
184181
}
185182

186183
/// Deallocate a list of allocation objects.
@@ -199,13 +196,12 @@ class LLVM_ABI JITLinkMemoryManager {
199196

200197
/// Convenience function for co-blocking deallocation.
201198
Error deallocate(std::vector<FinalizedAlloc> Allocs, orc::TaskDispatcher &D) {
202-
orc::promise<MSVCPError> DeallocResultP;
203-
auto DeallocResultF = DeallocResultP.get_future();
199+
orc::future<MSVCPError> DeallocResultF;
204200
deallocate(std::move(Allocs),
205-
[DeallocResultP = std::move(DeallocResultP)](Error Err) mutable {
201+
[DeallocResultP = DeallocResultF.get_promise(D)](Error Err) {
206202
DeallocResultP.set_value(std::move(Err));
207203
});
208-
return DeallocResultF.get(D);
204+
return DeallocResultF.get();
209205
}
210206

211207
/// Convenience function for co-blocking deallocation of a single alloc.
@@ -343,7 +339,15 @@ class SimpleSegmentAlloc {
343339
LLVM_ABI static Expected<SimpleSegmentAlloc>
344340
Create(JITLinkMemoryManager &MemMgr,
345341
std::shared_ptr<orc::SymbolStringPool> SSP, Triple TT,
346-
const JITLinkDylib *JD, SegmentMap Segments, orc::TaskDispatcher &D);
342+
const JITLinkDylib *JD, SegmentMap Segments, orc::TaskDispatcher &D) {
343+
orc::future<MSVCPExpected<SimpleSegmentAlloc>> AllocF;
344+
Create(
345+
MemMgr, std::move(SSP), std::move(TT), JD, std::move(Segments),
346+
[AllocP = AllocF.get_promise(D)](Expected<SimpleSegmentAlloc> Result) {
347+
AllocP.set_value(std::move(Result));
348+
});
349+
return AllocF.get();
350+
}
347351

348352
LLVM_ABI SimpleSegmentAlloc(SimpleSegmentAlloc &&);
349353
LLVM_ABI SimpleSegmentAlloc &operator=(SimpleSegmentAlloc &&);

llvm/include/llvm/ExecutionEngine/Orc/DylibManager.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ class LLVM_ABI DylibManager : public ExecutorProcessControl {
5656
/// symbol is not found then it be assigned a '0' value.
5757
Expected<std::vector<tpctypes::LookupResult>>
5858
lookupSymbols(ArrayRef<LookupRequest> Request) {
59-
orc::promise<MSVCPExpected<std::vector<tpctypes::LookupResult>>> RP;
60-
auto RF = RP.get_future();
59+
orc::future<MSVCPExpected<std::vector<tpctypes::LookupResult>>> RF;
6160
lookupSymbolsAsync(Request,
62-
[&RP](auto Result) { RP.set_value(std::move(Result)); });
63-
return RF.get(getDispatcher());
61+
[RP = RF.get_promise(getDispatcher())](auto Result) {
62+
RP.set_value(std::move(Result));
63+
});
64+
return RF.get();
6465
}
6566

6667
using SymbolLookupCompleteFn =
@@ -76,8 +77,6 @@ class LLVM_ABI DylibManager : public ExecutorProcessControl {
7677
SymbolLookupCompleteFn F) = 0;
7778
};
7879

79-
80-
8180
} // end namespace llvm::orc
8281

8382
#endif // LLVM_EXECUTIONENGINE_ORC_DYLIBMANAGER_H

llvm/include/llvm/ExecutionEngine/Orc/EPCGenericDylibManager.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,21 @@ class EPCGenericDylibManager {
5454
/// Looks up symbols within the given dylib.
5555
Expected<std::vector<ExecutorSymbolDef>>
5656
lookup(tpctypes::DylibHandle H, const SymbolLookupSet &Lookup) {
57-
orc::promise<MSVCPExpected<std::vector<ExecutorSymbolDef>>> RP;
58-
auto RF = RP.get_future();
59-
lookupAsync(H, Lookup, [&RP](auto R) { RP.set_value(std::move(R)); });
60-
return RF.get(EPC.getDispatcher());
57+
orc::future<MSVCPExpected<std::vector<ExecutorSymbolDef>>> RF;
58+
lookupAsync(H, Lookup, [RP = RF.get_promise(EPC.getDispatcher())](auto R) {
59+
RP.set_value(std::move(R));
60+
});
61+
return RF.get();
6162
}
6263

6364
/// Looks up symbols within the given dylib.
6465
Expected<std::vector<ExecutorSymbolDef>>
6566
lookup(tpctypes::DylibHandle H, const RemoteSymbolLookupSet &Lookup) {
66-
orc::promise<MSVCPExpected<std::vector<ExecutorSymbolDef>>> RP;
67-
auto RF = RP.get_future();
68-
lookupAsync(H, Lookup, [&RP](auto R) { RP.set_value(std::move(R)); });
69-
return RF.get(EPC.getDispatcher());
67+
orc::future<MSVCPExpected<std::vector<ExecutorSymbolDef>>> RF;
68+
lookupAsync(H, Lookup, [RP = RF.get_promise(EPC.getDispatcher())](auto R) {
69+
RP.set_value(std::move(R));
70+
});
71+
return RF.get();
7072
}
7173

7274
using SymbolLookupCompleteFn =

llvm/include/llvm/ExecutionEngine/Orc/EPCGenericMemoryAccess.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ class EPCGenericMemoryAccess : public MemoryAccess {
108108
void readUInt16sAsync(ArrayRef<ExecutorAddr> Rs,
109109
OnReadUIntsCompleteFn<uint16_t> OnComplete) override {
110110
using namespace shared;
111-
EPC.callSPSWrapperAsync<SPSSequence<uint16_t>(SPSSequence<SPSExecutorAddr>)>(
111+
EPC.callSPSWrapperAsync<SPSSequence<uint16_t>(
112+
SPSSequence<SPSExecutorAddr>)>(
112113
FAs.ReadUInt16s,
113114
[OnComplete = std::move(OnComplete)](
114115
Error Err, ReadUIntsResult<uint16_t> Result) mutable {
@@ -123,7 +124,8 @@ class EPCGenericMemoryAccess : public MemoryAccess {
123124
void readUInt32sAsync(ArrayRef<ExecutorAddr> Rs,
124125
OnReadUIntsCompleteFn<uint32_t> OnComplete) override {
125126
using namespace shared;
126-
EPC.callSPSWrapperAsync<SPSSequence<uint32_t>(SPSSequence<SPSExecutorAddr>)>(
127+
EPC.callSPSWrapperAsync<SPSSequence<uint32_t>(
128+
SPSSequence<SPSExecutorAddr>)>(
127129
FAs.ReadUInt32s,
128130
[OnComplete = std::move(OnComplete)](
129131
Error Err, ReadUIntsResult<uint32_t> Result) mutable {
@@ -138,7 +140,8 @@ class EPCGenericMemoryAccess : public MemoryAccess {
138140
void readUInt64sAsync(ArrayRef<ExecutorAddr> Rs,
139141
OnReadUIntsCompleteFn<uint64_t> OnComplete) override {
140142
using namespace shared;
141-
EPC.callSPSWrapperAsync<SPSSequence<uint64_t>(SPSSequence<SPSExecutorAddr>)>(
143+
EPC.callSPSWrapperAsync<SPSSequence<uint64_t>(
144+
SPSSequence<SPSExecutorAddr>)>(
142145
FAs.ReadUInt64s,
143146
[OnComplete = std::move(OnComplete)](
144147
Error Err, ReadUIntsResult<uint64_t> Result) mutable {

llvm/include/llvm/ExecutionEngine/Orc/ExecutorProcessControl.h

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ class SymbolLookupSet;
3838
/// ExecutorProcessControl supports interaction with a JIT target process.
3939
class LLVM_ABI ExecutorProcessControl {
4040
friend class ExecutionSession;
41-
public:
4241

42+
public:
4343
/// A handler or incoming WrapperFunctionResults -- either return values from
4444
/// callWrapper* calls, or incoming JIT-dispatch requests.
4545
///
4646
/// IncomingWFRHandlers are constructible from
4747
/// unique_function<void(shared::WrapperFunctionResult)>s using the
48-
/// runInPlace function or a RunWithDispatch object.
48+
/// RunInPlace function or a RunAsTask object.
4949
class IncomingWFRHandler {
5050
friend class ExecutorProcessControl;
5151
public:
@@ -84,21 +84,21 @@ class LLVM_ABI ExecutorProcessControl {
8484

8585
template <typename FnT>
8686
IncomingWFRHandler operator()(FnT &&Fn) {
87-
return IncomingWFRHandler(
88-
[&D = this->D, Fn = std::move(Fn)]
89-
(shared::WrapperFunctionResult WFR) mutable {
90-
D.dispatch(
91-
makeGenericNamedTask(
92-
[Fn = std::move(Fn), WFR = std::move(WFR)]() mutable {
93-
Fn(std::move(WFR));
94-
}, "WFR handler task"));
87+
orc::future<shared::WrapperFunctionResult> F;
88+
auto H = IncomingWFRHandler(
89+
[P = F.get_promise(D)](shared::WrapperFunctionResult WFR) {
90+
P.set_value(std::move(WFR));
9591
});
92+
std::move(F).then(
93+
[Fn = std::move(Fn)](shared::WrapperFunctionResult &&WFR) mutable {
94+
Fn(std::move(WFR));
95+
});
96+
return H;
9697
}
9798
private:
9899
TaskDispatcher &D;
99100
};
100101

101-
102102
/// Contains the address of the dispatch function and context that the ORC
103103
/// runtime can use to call functions in the JIT.
104104
struct JITDispatchInfo {
@@ -253,14 +253,14 @@ class LLVM_ABI ExecutorProcessControl {
253253
/// \endcode{.cpp}
254254
shared::WrapperFunctionResult callWrapper(ExecutorAddr WrapperFnAddr,
255255
ArrayRef<char> ArgBuffer) {
256-
orc::promise<shared::WrapperFunctionResult> RP;
257-
auto RF = RP.get_future();
256+
orc::future<shared::WrapperFunctionResult> RF;
258257
callWrapperAsync(
259258
RunInPlace(), WrapperFnAddr,
260-
[&](shared::WrapperFunctionResult R) {
259+
[RP = RF.get_promise(*D)](shared::WrapperFunctionResult R) {
261260
RP.set_value(std::move(R));
262-
}, ArgBuffer);
263-
return RF.get(*D);
261+
},
262+
ArgBuffer);
263+
return RF.get();
264264
}
265265

266266
/// Run a wrapper function using SPS to serialize the arguments and
@@ -324,8 +324,6 @@ class LLVM_ABI ExecutorProcessControl {
324324
StringMap<ExecutorAddr> BootstrapSymbols;
325325
};
326326

327-
328-
329327
} // end namespace orc
330328
} // end namespace llvm
331329

llvm/include/llvm/ExecutionEngine/Orc/InProcessMemoryAccess.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ExecutorProcessControl;
2121

2222
class LLVM_ABI InProcessMemoryAccess : public MemoryAccess {
2323
public:
24-
InProcessMemoryAccess(ExecutorProcessControl &EPC, bool IsArch64Bit)
24+
InProcessMemoryAccess(ExecutorProcessControl &EPC, bool IsArch64Bit)
2525
: MemoryAccess(EPC), IsArch64Bit(IsArch64Bit) {}
2626
void writeUInt8sAsync(ArrayRef<tpctypes::UInt8Write> Ws,
2727
WriteResultFn OnWriteComplete) override;

llvm/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,15 @@ template <typename ORCABI> class LocalTrampolinePool : public TrampolinePool {
123123
LocalTrampolinePool<ORCABI> *TrampolinePool =
124124
static_cast<LocalTrampolinePool *>(TrampolinePoolPtr);
125125

126-
orc::promise<ExecutorAddr> LandingAddressP;
127-
auto LandingAddressF = LandingAddressP.get_future();
128-
129-
TrampolinePool->ResolveLanding(ExecutorAddr::fromPtr(TrampolineId),
130-
[&](ExecutorAddr LandingAddress) {
131-
LandingAddressP.set_value(LandingAddress);
132-
});
133-
return LandingAddressF.get(TrampolinePool->D).getValue();
126+
orc::future<ExecutorAddr> LandingAddressF;
127+
128+
TrampolinePool->ResolveLanding(
129+
ExecutorAddr::fromPtr(TrampolineId),
130+
[LandingAddressP = LandingAddressF.get_promise(TrampolinePool->D)](
131+
ExecutorAddr LandingAddress) {
132+
LandingAddressP.set_value(LandingAddress);
133+
});
134+
return LandingAddressF.get().getValue();
134135
}
135136

136137
LocalTrampolinePool(ResolveLandingFunction ResolveLanding, TaskDispatcher &D,

0 commit comments

Comments
 (0)