LLVM 24.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"
21#include "llvm/Support/Error.h"
23
24#include <future>
25
26namespace llvm {
27namespace orc {
28
31public:
32 /// Create a SimpleRemoteEPC using the given transport type and args.
33 template <typename TransportT, typename... TransportTCtorArgTs>
35 Create(std::unique_ptr<TaskDispatcher> D,
36 TransportTCtorArgTs &&...TransportTCtorArgs) {
37 std::unique_ptr<SimpleRemoteEPC> SREPC(
38 new SimpleRemoteEPC(std::make_shared<SymbolStringPool>(),
39 std::move(D)));
40 auto T = TransportT::Create(
41 *SREPC, std::forward<TransportTCtorArgTs>(TransportTCtorArgs)...);
42 if (!T)
43 return T.takeError();
44 SREPC->T = std::move(*T);
45 if (auto Err = SREPC->setup())
46 return joinErrors(std::move(Err), SREPC->disconnect());
47 return std::move(SREPC);
48 }
49
54 ~SimpleRemoteEPC() override;
55
57 ArrayRef<std::string> Args) override;
58
59 void callWrapperAsync(ExecutorAddr WrapperFnAddr,
60 IncomingWFRHandler OnComplete,
61 ArrayRef<char> ArgBuffer) override;
62
65
67
69
70 Error disconnect() override;
71
74 shared::WrapperFunctionBuffer ArgBytes) override;
75
76 void handleDisconnect(Error Err) override;
77
78private:
79 SimpleRemoteEPC(std::shared_ptr<SymbolStringPool> SSP,
80 std::unique_ptr<TaskDispatcher> D)
82
83 Error sendMessage(SimpleRemoteEPCOpcode OpC, uint64_t SeqNo,
84 ExecutorAddr TagAddr, ArrayRef<char> ArgBytes);
85
86 Error handleSetup(uint64_t SeqNo, ExecutorAddr TagAddr,
88 Error setup();
89
90 Error handleResult(uint64_t SeqNo, ExecutorAddr TagAddr,
92 void handleCallWrapper(uint64_t RemoteSeqNo, ExecutorAddr TagAddr,
94 Error handleHangup(shared::WrapperFunctionBuffer ArgBytes);
95
96 uint64_t getNextSeqNo() { return NextSeqNo++; }
97 void releaseSeqNo(uint64_t SeqNo) {}
98
99 using PendingCallWrapperResultsMap =
100 DenseMap<uint64_t, IncomingWFRHandler>;
101
102 std::mutex SimpleRemoteEPCMutex;
103 std::condition_variable DisconnectCV;
104 bool Disconnected = false;
105 Error DisconnectErr = Error::success();
106
107 std::unique_ptr<SimpleRemoteEPCTransport> T;
108
109 ExecutorAddr RunAsMainAddr;
110
111 uint64_t NextSeqNo = 0;
112 PendingCallWrapperResultsMap PendingCallWrapperResults;
113};
114
115} // end namespace orc
116} // end namespace llvm
117
118#endif // LLVM_EXECUTIONENGINE_ORC_SIMPLEREMOTEEPC_H
#define LLVM_ABI
Definition Compiler.h:215
This file defines the DenseMap class.
This file provides a collection of function (or more generally, callable) type erasure utilities supp...
#define T
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.
Expected< std::unique_ptr< jitlink::JITLinkMemoryManager > > createDefaultMemoryManager() override
Create a default JITLinkMemoryManager for the target process.
SimpleRemoteEPC(const SimpleRemoteEPC &)=delete
static Expected< std::unique_ptr< SimpleRemoteEPC > > Create(std::unique_ptr< TaskDispatcher > D, TransportTCtorArgTs &&...TransportTCtorArgs)
Create a SimpleRemoteEPC using the given transport type and args.
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.
SimpleRemoteEPC(SimpleRemoteEPC &&)=delete
SimpleRemoteEPC & operator=(SimpleRemoteEPC &&)=delete
void callWrapperAsync(ExecutorAddr WrapperFnAddr, IncomingWFRHandler OnComplete, ArrayRef< char > ArgBuffer) override
Run a wrapper function in the executor.
C++ wrapper function buffer: Same as CWrapperFunctionBuffer but auto-releases memory.
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:878