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
33public:
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 {
43
46 };
47
48 /// Create a SimpleRemoteEPC using the given transport type and args.
49 template <typename TransportT, typename... TransportTCtorArgTs>
51 Create(std::unique_ptr<TaskDispatcher> D, Setup S,
52 TransportTCtorArgTs &&...TransportTCtorArgs) {
53 std::unique_ptr<SimpleRemoteEPC> SREPC(
54 new SimpleRemoteEPC(std::make_shared<SymbolStringPool>(),
55 std::move(D)));
56 auto T = TransportT::Create(
57 *SREPC, std::forward<TransportTCtorArgTs>(TransportTCtorArgs)...);
58 if (!T)
59 return T.takeError();
60 SREPC->T = std::move(*T);
61 if (auto Err = SREPC->setup(std::move(S)))
62 return joinErrors(std::move(Err), SREPC->disconnect());
63 return std::move(SREPC);
64 }
65
71
72 Expected<tpctypes::DylibHandle> loadDylib(const char *DylibPath) override;
73
75 SymbolLookupCompleteFn F) override;
76
78 ArrayRef<std::string> Args) override;
79
81
82 Expected<int32_t> runAsIntFunction(ExecutorAddr IntFnAddr, int Arg) override;
83
84 void callWrapperAsync(ExecutorAddr WrapperFnAddr,
85 IncomingWFRHandler OnComplete,
86 ArrayRef<char> ArgBuffer) override;
87
88 Error disconnect() override;
89
92 SimpleRemoteEPCArgBytesVector ArgBytes) override;
93
94 void handleDisconnect(Error Err) override;
95
96private:
97 SimpleRemoteEPC(std::shared_ptr<SymbolStringPool> SSP,
98 std::unique_ptr<TaskDispatcher> D)
100
102 createDefaultMemoryManager(SimpleRemoteEPC &SREPC);
104 createDefaultMemoryAccess(SimpleRemoteEPC &SREPC);
105
106 Error sendMessage(SimpleRemoteEPCOpcode OpC, uint64_t SeqNo,
107 ExecutorAddr TagAddr, ArrayRef<char> ArgBytes);
108
109 Error handleSetup(uint64_t SeqNo, ExecutorAddr TagAddr,
111 Error setup(Setup S);
112
113 Error handleResult(uint64_t SeqNo, ExecutorAddr TagAddr,
115 void handleCallWrapper(uint64_t RemoteSeqNo, ExecutorAddr TagAddr,
117 Error handleHangup(SimpleRemoteEPCArgBytesVector ArgBytes);
118
119 uint64_t getNextSeqNo() { return NextSeqNo++; }
120 void releaseSeqNo(uint64_t SeqNo) {}
121
122 using PendingCallWrapperResultsMap =
123 DenseMap<uint64_t, IncomingWFRHandler>;
124
125 std::mutex SimpleRemoteEPCMutex;
126 std::condition_variable DisconnectCV;
127 bool Disconnected = false;
128 Error DisconnectErr = Error::success();
129
130 std::unique_ptr<SimpleRemoteEPCTransport> T;
131 std::unique_ptr<jitlink::JITLinkMemoryManager> OwnedMemMgr;
132 std::unique_ptr<MemoryAccess> OwnedMemAccess;
133
134 std::unique_ptr<EPCGenericDylibManager> DylibMgr;
135 ExecutorAddr RunAsMainAddr;
136 ExecutorAddr RunAsVoidFunctionAddr;
137 ExecutorAddr RunAsIntFunctionAddr;
138
139 uint64_t NextSeqNo = 0;
140 PendingCallWrapperResultsMap PendingCallWrapperResults;
141};
142
143} // end namespace orc
144} // end namespace llvm
145
146#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:1209
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 lookupSymbolsAsync(ArrayRef< LookupRequest > Request, SymbolLookupCompleteFn F) override
Search for symbols in the target process.
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< tpctypes::DylibHandle > loadDylib(const char *DylibPath) override
Load the dynamic library at the given path and return a handle to it.
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:1856
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