LLVM 20.0.0git
SimpleRemoteEPC.h
Go to the documentation of this file.
1//===---- SimpleRemoteEPC.h - Simple remote executor control ----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Simple remote executor process control.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_EXECUTIONENGINE_ORC_SIMPLEREMOTEEPC_H
14#define LLVM_EXECUTIONENGINE_ORC_SIMPLEREMOTEEPC_H
15
16#include "llvm/ADT/DenseMap.h"
23#include "llvm/Support/Error.h"
25
26#include <future>
27
28namespace llvm {
29namespace orc {
30
33 private DylibManager {
34public:
35 /// A setup object containing callbacks to construct a memory manager and
36 /// memory access object. Both are optional. If not specified,
37 /// EPCGenericJITLinkMemoryManager and EPCGenericMemoryAccess will be used.
38 struct Setup {
44
47 };
48
49 /// Create a SimpleRemoteEPC using the given transport type and args.
50 template <typename TransportT, typename... TransportTCtorArgTs>
52 Create(std::unique_ptr<TaskDispatcher> D, Setup S,
53 TransportTCtorArgTs &&...TransportTCtorArgs) {
54 std::unique_ptr<SimpleRemoteEPC> SREPC(
55 new SimpleRemoteEPC(std::make_shared<SymbolStringPool>(),
56 std::move(D)));
57 auto T = TransportT::Create(
58 *SREPC, std::forward<TransportTCtorArgTs>(TransportTCtorArgs)...);
59 if (!T)
60 return T.takeError();
61 SREPC->T = std::move(*T);
62 if (auto Err = SREPC->setup(std::move(S)))
63 return joinErrors(std::move(Err), SREPC->disconnect());
64 return std::move(SREPC);
65 }
66
72
74 ArrayRef<std::string> Args) override;
75
77
78 Expected<int32_t> runAsIntFunction(ExecutorAddr IntFnAddr, int Arg) override;
79
80 void callWrapperAsync(ExecutorAddr WrapperFnAddr,
81 IncomingWFRHandler OnComplete,
82 ArrayRef<char> ArgBuffer) override;
83
84 Error disconnect() override;
85
88 SimpleRemoteEPCArgBytesVector ArgBytes) override;
89
90 void handleDisconnect(Error Err) override;
91
92private:
93 SimpleRemoteEPC(std::shared_ptr<SymbolStringPool> SSP,
94 std::unique_ptr<TaskDispatcher> D)
96 this->DylibMgr = this;
97 }
98
100 createDefaultMemoryManager(SimpleRemoteEPC &SREPC);
102 createDefaultMemoryAccess(SimpleRemoteEPC &SREPC);
103
104 Error sendMessage(SimpleRemoteEPCOpcode OpC, uint64_t SeqNo,
105 ExecutorAddr TagAddr, ArrayRef<char> ArgBytes);
106
107 Error handleSetup(uint64_t SeqNo, ExecutorAddr TagAddr,
109 Error setup(Setup S);
110
111 Error handleResult(uint64_t SeqNo, ExecutorAddr TagAddr,
113 void handleCallWrapper(uint64_t RemoteSeqNo, ExecutorAddr TagAddr,
115 Error handleHangup(SimpleRemoteEPCArgBytesVector ArgBytes);
116
117 uint64_t getNextSeqNo() { return NextSeqNo++; }
118 void releaseSeqNo(uint64_t SeqNo) {}
119
120 Expected<tpctypes::DylibHandle> loadDylib(const char *DylibPath) override;
121
122 void lookupSymbolsAsync(ArrayRef<LookupRequest> Request,
123 SymbolLookupCompleteFn F) override;
124
125 using PendingCallWrapperResultsMap =
126 DenseMap<uint64_t, IncomingWFRHandler>;
127
128 std::mutex SimpleRemoteEPCMutex;
129 std::condition_variable DisconnectCV;
130 bool Disconnected = false;
131 Error DisconnectErr = Error::success();
132
133 std::unique_ptr<SimpleRemoteEPCTransport> T;
134 std::unique_ptr<jitlink::JITLinkMemoryManager> OwnedMemMgr;
135 std::unique_ptr<MemoryAccess> OwnedMemAccess;
136
137 std::unique_ptr<EPCGenericDylibManager> EPCDylibMgr;
138 ExecutorAddr RunAsMainAddr;
139 ExecutorAddr RunAsVoidFunctionAddr;
140 ExecutorAddr RunAsIntFunctionAddr;
141
142 uint64_t NextSeqNo = 0;
143 PendingCallWrapperResultsMap PendingCallWrapperResults;
144};
145
146} // end namespace orc
147} // end namespace llvm
148
149#endif // LLVM_EXECUTIONENGINE_ORC_SIMPLEREMOTEEPC_H
This file defines the DenseMap class.
This file provides a collection of function (or more generally, callable) type erasure utilities supp...
#define F(x, y, z)
Definition: MD5.cpp:55
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:337
Tagged union holding either a T or a Error.
Definition: Error.h:481
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
unique_function< void(Expected< std::vector< tpctypes::LookupResult > >)> SymbolLookupCompleteFn
Definition: DylibManager.h:61
Represents an address in the executor process.
A handler or incoming WrapperFunctionResults – either return values from callWrapper* calls,...
ExecutorProcessControl supports interaction with a JIT target process.
std::unique_ptr< TaskDispatcher > D
std::shared_ptr< SymbolStringPool > SSP
void handleDisconnect(Error Err) override
Handle a disconnection from the underlying transport.
SimpleRemoteEPC & operator=(const SimpleRemoteEPC &)=delete
Expected< int32_t > runAsMain(ExecutorAddr MainFnAddr, ArrayRef< std::string > Args) override
Run function with a main-like signature.
static Expected< std::unique_ptr< SimpleRemoteEPC > > Create(std::unique_ptr< TaskDispatcher > D, Setup S, TransportTCtorArgTs &&...TransportTCtorArgs)
Create a SimpleRemoteEPC using the given transport type and args.
Expected< HandleMessageAction > handleMessage(SimpleRemoteEPCOpcode OpC, uint64_t SeqNo, ExecutorAddr TagAddr, SimpleRemoteEPCArgBytesVector ArgBytes) override
Handle receipt of a message.
SimpleRemoteEPC(const SimpleRemoteEPC &)=delete
Error disconnect() override
Disconnect from the target process.
Expected< int32_t > runAsVoidFunction(ExecutorAddr VoidFnAddr) override
Run function with a int (*)(void) signature.
SimpleRemoteEPC(SimpleRemoteEPC &&)=delete
SimpleRemoteEPC & operator=(SimpleRemoteEPC &&)=delete
void callWrapperAsync(ExecutorAddr WrapperFnAddr, IncomingWFRHandler OnComplete, ArrayRef< char > ArgBuffer) override
Run a wrapper function in the executor.
Expected< int32_t > runAsIntFunction(ExecutorAddr IntFnAddr, int Arg) override
Run function with a int (*)(int) signature.
unique_function is a type-erasing functor similar to std::function.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition: Error.h:438
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1873
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
A setup object containing callbacks to construct a memory manager and memory access object.
Expected< std::unique_ptr< jitlink::JITLinkMemoryManager > >(SimpleRemoteEPC &) CreateMemoryManagerFn
unique_function< CreateMemoryManagerFn > CreateMemoryManager
unique_function< CreateMemoryAccessFn > CreateMemoryAccess