LLVM 23.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 a callback to construct a memory manager.
35 /// If not specified, EPCGenericJITLinkMemoryManager will be used.
43
44 /// Create a SimpleRemoteEPC using the given transport type and args.
45 template <typename TransportT, typename... TransportTCtorArgTs>
47 Create(std::unique_ptr<TaskDispatcher> D, Setup S,
48 TransportTCtorArgTs &&...TransportTCtorArgs) {
49 std::unique_ptr<SimpleRemoteEPC> SREPC(
50 new SimpleRemoteEPC(std::make_shared<SymbolStringPool>(),
51 std::move(D)));
52 auto T = TransportT::Create(
53 *SREPC, std::forward<TransportTCtorArgTs>(TransportTCtorArgs)...);
54 if (!T)
55 return T.takeError();
56 SREPC->T = std::move(*T);
57 if (auto Err = SREPC->setup(std::move(S)))
58 return joinErrors(std::move(Err), SREPC->disconnect());
59 return std::move(SREPC);
60 }
61
66 ~SimpleRemoteEPC() override;
67
69 ArrayRef<std::string> Args) override;
70
72
73 Expected<int32_t> runAsIntFunction(ExecutorAddr IntFnAddr, int Arg) override;
74
75 void callWrapperAsync(ExecutorAddr WrapperFnAddr,
76 IncomingWFRHandler OnComplete,
77 ArrayRef<char> ArgBuffer) override;
78
80
82
83 Error disconnect() override;
84
87 shared::WrapperFunctionBuffer ArgBytes) override;
88
89 void handleDisconnect(Error Err) override;
90
91private:
92 SimpleRemoteEPC(std::shared_ptr<SymbolStringPool> SSP,
93 std::unique_ptr<TaskDispatcher> D)
95
97 createDefaultMemoryManager(SimpleRemoteEPC &SREPC);
98
99 Error sendMessage(SimpleRemoteEPCOpcode OpC, uint64_t SeqNo,
100 ExecutorAddr TagAddr, ArrayRef<char> ArgBytes);
101
102 Error handleSetup(uint64_t SeqNo, ExecutorAddr TagAddr,
104 Error setup(Setup S);
105
106 Error handleResult(uint64_t SeqNo, ExecutorAddr TagAddr,
108 void handleCallWrapper(uint64_t RemoteSeqNo, ExecutorAddr TagAddr,
110 Error handleHangup(shared::WrapperFunctionBuffer ArgBytes);
111
112 uint64_t getNextSeqNo() { return NextSeqNo++; }
113 void releaseSeqNo(uint64_t SeqNo) {}
114
115 using PendingCallWrapperResultsMap =
116 DenseMap<uint64_t, IncomingWFRHandler>;
117
118 std::mutex SimpleRemoteEPCMutex;
119 std::condition_variable DisconnectCV;
120 bool Disconnected = false;
121 Error DisconnectErr = Error::success();
122
123 std::unique_ptr<SimpleRemoteEPCTransport> T;
124 std::unique_ptr<jitlink::JITLinkMemoryManager> OwnedMemMgr;
125
126 ExecutorAddr RunAsMainAddr;
127 ExecutorAddr RunAsVoidFunctionAddr;
128 ExecutorAddr RunAsIntFunctionAddr;
129
130 uint64_t NextSeqNo = 0;
131 PendingCallWrapperResultsMap PendingCallWrapperResults;
132};
133
134} // end namespace orc
135} // end namespace llvm
136
137#endif // LLVM_EXECUTIONENGINE_ORC_SIMPLEREMOTEEPC_H
#define LLVM_ABI
Definition Compiler.h:213
This file defines the DenseMap class.
This file provides a collection of function (or more generally, callable) type erasure utilities supp...
#define T
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Tagged union holding either a T or a Error.
Definition Error.h:485
Represents an address in the executor process.
A handler or incoming WrapperFunctionBuffers – either return values from callWrapper* calls,...
std::unique_ptr< TaskDispatcher > D
std::shared_ptr< SymbolStringPool > SSP
ExecutorProcessControl(std::shared_ptr< SymbolStringPool > SSP, std::unique_ptr< TaskDispatcher > D)
void handleDisconnect(Error Err) override
Handle a disconnection from the underlying transport.
SimpleRemoteEPC & operator=(const SimpleRemoteEPC &)=delete
Expected< std::unique_ptr< MemoryAccess > > createDefaultMemoryAccess() override
Create a default MemoryAccess for the target process.
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.
SimpleRemoteEPC(const SimpleRemoteEPC &)=delete
Expected< HandleMessageAction > handleMessage(SimpleRemoteEPCOpcode OpC, uint64_t SeqNo, ExecutorAddr TagAddr, shared::WrapperFunctionBuffer ArgBytes) override
Handle receipt of a message.
Expected< std::unique_ptr< DylibManager > > createDefaultDylibMgr() override
Create a default DylibManager for the target process.
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.
C++ wrapper function buffer: Same as CWrapperFunctionBuffer but auto-releases memory.
unique_function is a type-erasing functor similar to std::function.
This is an optimization pass for GlobalISel generic memory operations.
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition Error.h:442
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:1917
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870
A setup object containing a callback to construct a memory manager.
Expected< std::unique_ptr< jitlink::JITLinkMemoryManager > >( SimpleRemoteEPC &) CreateMemoryManagerFn
unique_function< CreateMemoryManagerFn > CreateMemoryManager