Skip to content

Commit 4fcc0ac

Browse files
committed
[ORC] Use a Setup object for SimpleRemoteEPC construction.
SimpleRemoteEPC notionally allowed subclasses to override the createMemoryManager and createMemoryAccess methods to use custom objects, but could not actually be subclassed in practice (The construction process in SimpleRemoteEPC::Create could not be re-used). Instead of subclassing, this commit adds a SimpleRemoteEPC::Setup class that can be used by clients to set up the memory manager and memory access members. A default-constructed Setup object results in no change from previous behavior (EPCGeneric* memory manager and memory access objects used by default).
1 parent 8d2736d commit 4fcc0ac

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

llvm/include/llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,24 @@ namespace orc {
3131
class SimpleRemoteEPC : public ExecutorProcessControl,
3232
public SimpleRemoteEPCTransportClient {
3333
public:
34+
/// A setup object containing callbacks to construct a memory manager and
35+
/// memory access object. Both are optional. If not specified,
36+
/// EPCGenericJITLinkMemoryManager and EPCGenericMemoryAccess will be used.
37+
struct Setup {
38+
using CreateMemoryManagerFn =
39+
Expected<std::unique_ptr<jitlink::JITLinkMemoryManager>>(
40+
SimpleRemoteEPC &);
41+
using CreateMemoryAccessFn =
42+
Expected<std::unique_ptr<MemoryAccess>>(SimpleRemoteEPC &);
43+
44+
unique_function<CreateMemoryManagerFn> CreateMemoryManager;
45+
unique_function<CreateMemoryAccessFn> CreateMemoryAccess;
46+
};
47+
3448
/// Create a SimpleRemoteEPC using the given transport type and args.
3549
template <typename TransportT, typename... TransportTCtorArgTs>
3650
static Expected<std::unique_ptr<SimpleRemoteEPC>>
37-
Create(std::unique_ptr<TaskDispatcher> D,
51+
Create(std::unique_ptr<TaskDispatcher> D, Setup S,
3852
TransportTCtorArgTs &&...TransportTCtorArgs) {
3953
std::unique_ptr<SimpleRemoteEPC> SREPC(
4054
new SimpleRemoteEPC(std::make_shared<SymbolStringPool>(),
@@ -44,7 +58,7 @@ class SimpleRemoteEPC : public ExecutorProcessControl,
4458
if (!T)
4559
return T.takeError();
4660
SREPC->T = std::move(*T);
47-
if (auto Err = SREPC->setup())
61+
if (auto Err = SREPC->setup(std::move(S)))
4862
return joinErrors(std::move(Err), SREPC->disconnect());
4963
return std::move(SREPC);
5064
}
@@ -75,22 +89,22 @@ class SimpleRemoteEPC : public ExecutorProcessControl,
7589

7690
void handleDisconnect(Error Err) override;
7791

78-
protected:
79-
virtual Expected<std::unique_ptr<jitlink::JITLinkMemoryManager>>
80-
createMemoryManager();
81-
virtual Expected<std::unique_ptr<MemoryAccess>> createMemoryAccess();
82-
8392
private:
8493
SimpleRemoteEPC(std::shared_ptr<SymbolStringPool> SSP,
8594
std::unique_ptr<TaskDispatcher> D)
8695
: ExecutorProcessControl(std::move(SSP), std::move(D)) {}
8796

97+
static Expected<std::unique_ptr<jitlink::JITLinkMemoryManager>>
98+
createDefaultMemoryManager(SimpleRemoteEPC &SREPC);
99+
static Expected<std::unique_ptr<MemoryAccess>>
100+
createDefaultMemoryAccess(SimpleRemoteEPC &SREPC);
101+
88102
Error sendMessage(SimpleRemoteEPCOpcode OpC, uint64_t SeqNo,
89103
ExecutorAddr TagAddr, ArrayRef<char> ArgBytes);
90104

91105
Error handleSetup(uint64_t SeqNo, ExecutorAddr TagAddr,
92106
SimpleRemoteEPCArgBytesVector ArgBytes);
93-
Error setup();
107+
Error setup(Setup S);
94108

95109
Error handleResult(uint64_t SeqNo, ExecutorAddr TagAddr,
96110
SimpleRemoteEPCArgBytesVector ArgBytes);

llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,22 +180,21 @@ void SimpleRemoteEPC::handleDisconnect(Error Err) {
180180
}
181181

182182
Expected<std::unique_ptr<jitlink::JITLinkMemoryManager>>
183-
SimpleRemoteEPC::createMemoryManager() {
183+
SimpleRemoteEPC::createDefaultMemoryManager(SimpleRemoteEPC &SREPC) {
184184
EPCGenericJITLinkMemoryManager::SymbolAddrs SAs;
185-
if (auto Err = getBootstrapSymbols(
185+
if (auto Err = SREPC.getBootstrapSymbols(
186186
{{SAs.Allocator, rt::SimpleExecutorMemoryManagerInstanceName},
187187
{SAs.Reserve, rt::SimpleExecutorMemoryManagerReserveWrapperName},
188188
{SAs.Finalize, rt::SimpleExecutorMemoryManagerFinalizeWrapperName},
189189
{SAs.Deallocate,
190190
rt::SimpleExecutorMemoryManagerDeallocateWrapperName}}))
191191
return std::move(Err);
192192

193-
return std::make_unique<EPCGenericJITLinkMemoryManager>(*this, SAs);
193+
return std::make_unique<EPCGenericJITLinkMemoryManager>(SREPC, SAs);
194194
}
195195

196196
Expected<std::unique_ptr<ExecutorProcessControl::MemoryAccess>>
197-
SimpleRemoteEPC::createMemoryAccess() {
198-
197+
SimpleRemoteEPC::createDefaultMemoryAccess(SimpleRemoteEPC &SREPC) {
199198
return nullptr;
200199
}
201200

@@ -260,7 +259,7 @@ Error SimpleRemoteEPC::handleSetup(uint64_t SeqNo, ExecutorAddr TagAddr,
260259
return Error::success();
261260
}
262261

263-
Error SimpleRemoteEPC::setup() {
262+
Error SimpleRemoteEPC::setup(Setup S) {
264263
using namespace SimpleRemoteEPCDefaultBootstrapSymbolNames;
265264

266265
std::promise<MSVCPExpected<SimpleRemoteEPCExecutorInfo>> EIP;
@@ -322,13 +321,21 @@ Error SimpleRemoteEPC::setup() {
322321
else
323322
return DM.takeError();
324323

325-
if (auto MemMgr = createMemoryManager()) {
324+
// Set a default CreateMemoryManager if none is specified.
325+
if (!S.CreateMemoryManager)
326+
S.CreateMemoryManager = createDefaultMemoryManager;
327+
328+
if (auto MemMgr = S.CreateMemoryManager(*this)) {
326329
OwnedMemMgr = std::move(*MemMgr);
327330
this->MemMgr = OwnedMemMgr.get();
328331
} else
329332
return MemMgr.takeError();
330333

331-
if (auto MemAccess = createMemoryAccess()) {
334+
// Set a default CreateMemoryAccess if none is specified.
335+
if (!S.CreateMemoryAccess)
336+
S.CreateMemoryAccess = createDefaultMemoryAccess;
337+
338+
if (auto MemAccess = S.CreateMemoryAccess(*this)) {
332339
OwnedMemAccess = std::move(*MemAccess);
333340
this->MemAccess = OwnedMemAccess.get();
334341
} else

llvm/tools/lli/lli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,6 @@ Expected<std::unique_ptr<orc::ExecutorProcessControl>> launchRemote() {
11511151
// Return a SimpleRemoteEPC instance connected to our end of the pipes.
11521152
return orc::SimpleRemoteEPC::Create<orc::FDSimpleRemoteEPCTransport>(
11531153
std::make_unique<llvm::orc::InPlaceTaskDispatcher>(),
1154-
PipeFD[1][0], PipeFD[0][1]);
1154+
llvm::orc::SimpleRemoteEPC::Setup(), PipeFD[1][0], PipeFD[0][1]);
11551155
#endif
11561156
}

llvm/tools/llvm-jitlink/llvm-jitlink.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ static Expected<std::unique_ptr<ExecutorProcessControl>> launchExecutor() {
798798

799799
return SimpleRemoteEPC::Create<FDSimpleRemoteEPCTransport>(
800800
std::make_unique<DynamicThreadPoolTaskDispatcher>(),
801-
FromExecutor[ReadEnd], ToExecutor[WriteEnd]);
801+
SimpleRemoteEPC::Setup(), FromExecutor[ReadEnd], ToExecutor[WriteEnd]);
802802
#endif
803803
}
804804

@@ -883,7 +883,8 @@ static Expected<std::unique_ptr<ExecutorProcessControl>> connectToExecutor() {
883883
return SockFD.takeError();
884884

885885
return SimpleRemoteEPC::Create<FDSimpleRemoteEPCTransport>(
886-
std::make_unique<DynamicThreadPoolTaskDispatcher>(), *SockFD, *SockFD);
886+
std::make_unique<DynamicThreadPoolTaskDispatcher>(),
887+
SimpleRemoteEPC::Setup(), *SockFD, *SockFD);
887888
#endif
888889
}
889890

0 commit comments

Comments
 (0)