LLVM 22.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"
24#include "llvm/Support/Error.h"
26
27#include <future>
28
29namespace llvm {
30namespace orc {
31
34 private DylibManager {
35public:
36 /// A setup object containing callbacks to construct a memory manager and
37 /// memory access object. Both are optional. If not specified,
38 /// EPCGenericJITLinkMemoryManager and EPCGenericMemoryAccess will be used.
39 struct Setup {
45
48 };
49
50 /// Create a SimpleRemoteEPC using the given transport type and args.
51 template <typename TransportT, typename... TransportTCtorArgTs>
53 Create(std::unique_ptr<TaskDispatcher> D, Setup S,
54 TransportTCtorArgTs &&...TransportTCtorArgs) {
55 std::unique_ptr<SimpleRemoteEPC> SREPC(
56 new SimpleRemoteEPC(std::make_shared<SymbolStringPool>(),
57 std::move(D)));
58 auto T = TransportT::Create(
59 *SREPC, std::forward<TransportTCtorArgTs>(TransportTCtorArgs)...);
60 if (!T)
61 return T.takeError();
62 SREPC->T = std::move(*T);
63 if (auto Err = SREPC->setup(std::move(S)))
64 return joinErrors(std::move(Err), SREPC->disconnect());
65 return std::move(SREPC);
66 }
67
73
75 ArrayRef<std::string> Args) override;
76
78
79 Expected<int32_t> runAsIntFunction(ExecutorAddr IntFnAddr, int Arg) override;
80
81 void callWrapperAsync(ExecutorAddr WrapperFnAddr,
82 IncomingWFRHandler OnComplete,
83 ArrayRef<char> ArgBuffer) override;
84
85 Error disconnect() override;
86
88 handleMessage(SimpleRemoteEPCOpcode OpC, uint64_t SeqNo, ExecutorAddr TagAddr,
89 SimpleRemoteEPCArgBytesVector ArgBytes) override;
90
91 void handleDisconnect(Error Err) override;
92
93private:
94 SimpleRemoteEPC(std::shared_ptr<SymbolStringPool> SSP,
95 std::unique_ptr<TaskDispatcher> D)
97 this->DylibMgr = this;
98 }
99
101 createDefaultMemoryManager(SimpleRemoteEPC &SREPC);
103 createDefaultMemoryAccess(SimpleRemoteEPC &SREPC);
104
105 Error sendMessage(SimpleRemoteEPCOpcode OpC, uint64_t SeqNo,
106 ExecutorAddr TagAddr, ArrayRef<char> ArgBytes);
107
108 Error handleSetup(uint64_t SeqNo, ExecutorAddr TagAddr,
110 Error setup(Setup S);
111
112 Error handleResult(uint64_t SeqNo, ExecutorAddr TagAddr,
114 void handleCallWrapper(uint64_t RemoteSeqNo, ExecutorAddr TagAddr,
116 Error handleHangup(SimpleRemoteEPCArgBytesVector ArgBytes);
117
118 uint64_t getNextSeqNo() { return NextSeqNo++; }
119 void releaseSeqNo(uint64_t SeqNo) {}
120
121 Expected<tpctypes::DylibHandle> loadDylib(const char *DylibPath) override;
122
123 void lookupSymbolsAsync(ArrayRef<LookupRequest> Request,
124 SymbolLookupCompleteFn F) override;
125
126 using PendingCallWrapperResultsMap =
127 DenseMap<uint64_t, IncomingWFRHandler>;
128
129 std::mutex SimpleRemoteEPCMutex;
130 std::condition_variable DisconnectCV;
131 bool Disconnected = false;
132 Error DisconnectErr = Error::success();
133
134 std::unique_ptr<SimpleRemoteEPCTransport> T;
135 std::unique_ptr<jitlink::JITLinkMemoryManager> OwnedMemMgr;
136 std::unique_ptr<MemoryAccess> OwnedMemAccess;
137
138 std::unique_ptr<EPCGenericDylibManager> EPCDylibMgr;
139 ExecutorAddr RunAsMainAddr;
140 ExecutorAddr RunAsVoidFunctionAddr;
141 ExecutorAddr RunAsIntFunctionAddr;
142
143 uint64_t NextSeqNo = 0;
144 PendingCallWrapperResultsMap PendingCallWrapperResults;
145};
146
147} // end namespace orc
148} // end namespace llvm
149
150#endif // LLVM_EXECUTIONENGINE_ORC_SIMPLEREMOTEEPC_H
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#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 F(x, y, z)
Definition: MD5.cpp:55
#define T
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:159
Tagged union holding either a T or a Error.
Definition: Error.h:485
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
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.
SimpleRemoteEPC & operator=(const SimpleRemoteEPC &)=delete
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
SimpleRemoteEPC(SimpleRemoteEPC &&)=delete
SimpleRemoteEPC & operator=(SimpleRemoteEPC &&)=delete
unique_function is a type-erasing functor similar to std::function.
LLVM_ABI int runAsVoidFunction(int(*Func)(void))
LLVM_ABI int runAsIntFunction(int(*Func)(int), int Arg)
LLVM_ABI int runAsMain(int(*Main)(int, char *[]), ArrayRef< std::string > Args, std::optional< StringRef > ProgramName=std::nullopt)
Run a main function, returning the result.
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: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:1886
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
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