2020#include " llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
2121#include " llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h"
2222#include " llvm/ExecutionEngine/Orc/SymbolStringPool.h"
23+ #include " llvm/ExecutionEngine/Orc/TaskDispatch.h"
2324#include " llvm/Support/Allocator.h"
2425#include " llvm/Support/Compiler.h"
2526#include " llvm/Support/Error.h"
3435#include < mutex>
3536
3637namespace llvm {
38+
39+ namespace orc {
40+ class ExecutorProcessControl ;
41+ }
42+
3743namespace jitlink {
3844
3945class Block ;
@@ -132,14 +138,15 @@ class LLVM_ABI JITLinkMemoryManager {
132138 // / Called to transfer working memory to the target and apply finalization.
133139 virtual void finalize (OnFinalizedFunction OnFinalized) = 0;
134140
135- // / Synchronous convenience version of finalize.
136- Expected<FinalizedAlloc> finalize () {
137- std ::promise<MSVCPExpected<FinalizedAlloc>> FinalizeResultP;
141+ // / Co-synchronous convenience version of finalize.
142+ Expected<FinalizedAlloc> finalize (orc::TaskDispatcher &D ) {
143+ orc ::promise<MSVCPExpected<FinalizedAlloc>> FinalizeResultP;
138144 auto FinalizeResultF = FinalizeResultP.get_future ();
139- finalize ([&](Expected<FinalizedAlloc> Result) {
145+ finalize ([FinalizeResultP = std::move (FinalizeResultP)](
146+ Expected<FinalizedAlloc> Result) mutable {
140147 FinalizeResultP.set_value (std::move (Result));
141148 });
142- return FinalizeResultF.get ();
149+ return FinalizeResultF.get (D );
143150 }
144151 };
145152
@@ -163,14 +170,17 @@ class LLVM_ABI JITLinkMemoryManager {
163170 virtual void allocate (const JITLinkDylib *JD, LinkGraph &G,
164171 OnAllocatedFunction OnAllocated) = 0;
165172
166- // / Convenience function for blocking allocation.
167- AllocResult allocate (const JITLinkDylib *JD, LinkGraph &G) {
168- std::promise<MSVCPExpected<std::unique_ptr<InFlightAlloc>>> AllocResultP;
173+ // / Convenience function for co-blocking allocation.
174+ AllocResult allocate (const JITLinkDylib *JD, LinkGraph &G,
175+ orc::TaskDispatcher &D) {
176+ orc::promise<MSVCPExpected<std::unique_ptr<InFlightAlloc>>> AllocResultP;
169177 auto AllocResultF = AllocResultP.get_future ();
170- allocate (JD, G, [&](AllocResult Alloc) {
171- AllocResultP.set_value (std::move (Alloc));
172- });
173- return AllocResultF.get ();
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);
174184 }
175185
176186 // / Deallocate a list of allocation objects.
@@ -187,20 +197,22 @@ class LLVM_ABI JITLinkMemoryManager {
187197 deallocate (std::move (Allocs), std::move (OnDeallocated));
188198 }
189199
190- // / Convenience function for blocking deallocation.
191- Error deallocate (std::vector<FinalizedAlloc> Allocs) {
192- std ::promise<MSVCPError> DeallocResultP;
200+ // / Convenience function for co- blocking deallocation.
201+ Error deallocate (std::vector<FinalizedAlloc> Allocs, orc::TaskDispatcher &D ) {
202+ orc ::promise<MSVCPError> DeallocResultP;
193203 auto DeallocResultF = DeallocResultP.get_future ();
194204 deallocate (std::move (Allocs),
195- [&](Error Err) { DeallocResultP.set_value (std::move (Err)); });
196- return DeallocResultF.get ();
205+ [DeallocResultP = std::move (DeallocResultP)](Error Err) mutable {
206+ DeallocResultP.set_value (std::move (Err));
207+ });
208+ return DeallocResultF.get (D);
197209 }
198210
199- // / Convenience function for blocking deallocation of a single alloc.
200- Error deallocate (FinalizedAlloc Alloc) {
211+ // / Convenience function for co- blocking deallocation of a single alloc.
212+ Error deallocate (FinalizedAlloc Alloc, orc::TaskDispatcher &D ) {
201213 std::vector<FinalizedAlloc> Allocs;
202214 Allocs.push_back (std::move (Alloc));
203- return deallocate (std::move (Allocs));
215+ return deallocate (std::move (Allocs), D );
204216 }
205217};
206218
@@ -326,10 +338,12 @@ class SimpleSegmentAlloc {
326338 Triple TT, const JITLinkDylib *JD,
327339 SegmentMap Segments, OnCreatedFunction OnCreated);
328340
341+ // The blocking version of this should be deprecated, and requires an
342+ // TaskDispatcher for co-async correctness.
329343 LLVM_ABI static Expected<SimpleSegmentAlloc>
330344 Create (JITLinkMemoryManager &MemMgr,
331345 std::shared_ptr<orc::SymbolStringPool> SSP, Triple TT,
332- const JITLinkDylib *JD, SegmentMap Segments);
346+ const JITLinkDylib *JD, SegmentMap Segments, orc::TaskDispatcher &D );
333347
334348 LLVM_ABI SimpleSegmentAlloc (SimpleSegmentAlloc &&);
335349 LLVM_ABI SimpleSegmentAlloc &operator =(SimpleSegmentAlloc &&);
@@ -343,9 +357,10 @@ class SimpleSegmentAlloc {
343357 Alloc->finalize (std::move (OnFinalized));
344358 }
345359
346- // / Finalize all groups.
347- Expected<JITLinkMemoryManager::FinalizedAlloc> finalize () {
348- return Alloc->finalize ();
360+ // / Finalize all groups (deprecated co-blocking version).
361+ Expected<JITLinkMemoryManager::FinalizedAlloc>
362+ finalize (orc::TaskDispatcher &D) {
363+ return Alloc->finalize (D);
349364 }
350365
351366private:
0 commit comments