LLVM 17.0.0git
SimpleRemoteEPCUtils.h
Go to the documentation of this file.
1//===--- SimpleRemoteEPCUtils.h - Utils for Simple Remote EPC ---*- 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// Message definitions and other utilities for SimpleRemoteEPC and
10// SimpleRemoteEPCServer.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_SIMPLEREMOTEEPCUTILS_H
15#define LLVM_EXECUTIONENGINE_ORC_SHARED_SIMPLEREMOTEEPCUTILS_H
16
17#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/StringMap.h"
22#include "llvm/Support/Error.h"
23
24#include <atomic>
25#include <mutex>
26#include <string>
27#include <thread>
28
29namespace llvm {
30namespace orc {
31
32namespace SimpleRemoteEPCDefaultBootstrapSymbolNames {
33extern const char *ExecutorSessionObjectName;
34extern const char *DispatchFnName;
35} // end namespace SimpleRemoteEPCDefaultBootstrapSymbolNames
36
37enum class SimpleRemoteEPCOpcode : uint8_t {
38 Setup,
39 Hangup,
40 Result,
43};
44
46 std::string TargetTriple;
49};
50
52
54public:
56
58
59 /// Handle receipt of a message.
60 ///
61 /// Returns an Error if the message cannot be handled, 'EndSession' if the
62 /// client will not accept any further messages, and 'ContinueSession'
63 /// otherwise.
67
68 /// Handle a disconnection from the underlying transport. No further messages
69 /// should be sent to handleMessage after this is called.
70 /// Err may contain an Error value indicating unexpected disconnection. This
71 /// allows clients to log such errors, but no attempt should be made at
72 /// recovery (which should be handled inside the transport class, if it is
73 /// supported at all).
74 virtual void handleDisconnect(Error Err) = 0;
75};
76
78public:
80
81 /// Called during setup of the client to indicate that the client is ready
82 /// to receive messages.
83 ///
84 /// Transport objects should not access the client until this method is
85 /// called.
86 virtual Error start() = 0;
87
88 /// Send a SimpleRemoteEPC message.
89 ///
90 /// This function may be called concurrently. Subclasses should implement
91 /// locking if required for the underlying transport.
93 ExecutorAddr TagAddr, ArrayRef<char> ArgBytes) = 0;
94
95 /// Trigger disconnection from the transport. The implementation should
96 /// respond by calling handleDisconnect on the client once disconnection
97 /// is complete. May be called more than once and from different threads.
98 virtual void disconnect() = 0;
99};
100
101/// Uses read/write on FileDescriptors for transport.
103public:
104 /// Create a FDSimpleRemoteEPCTransport using the given FDs for
105 /// reading (InFD) and writing (OutFD).
107 Create(SimpleRemoteEPCTransportClient &C, int InFD, int OutFD);
108
109 /// Create a FDSimpleRemoteEPCTransport using the given FD for both
110 /// reading and writing.
113 return Create(C, FD, FD);
114 }
115
117
118 Error start() override;
119
121 ExecutorAddr TagAddr, ArrayRef<char> ArgBytes) override;
122
123 void disconnect() override;
124
125private:
127 int OutFD)
128 : C(C), InFD(InFD), OutFD(OutFD) {}
129
130 Error readBytes(char *Dst, size_t Size, bool *IsEOF = nullptr);
131 int writeBytes(const char *Src, size_t Size);
132 void listenLoop();
133
134 std::mutex M;
135 SimpleRemoteEPCTransportClient &C;
136 std::thread ListenerThread;
137 int InFD, OutFD;
138 std::atomic<bool> Disconnected{false};
139};
140
142 std::string Name;
144};
145
146using RemoteSymbolLookupSet = std::vector<RemoteSymbolLookupSetElement>;
147
151};
152
153namespace shared {
154
156
158
160
161/// Tuple containing target triple, page size, and bootstrap symbols.
165
166template <>
169public:
170 static size_t size(const RemoteSymbolLookupSetElement &V) {
171 return SPSArgList<SPSString, bool>::size(V.Name, V.Required);
172 }
173
174 static size_t serialize(SPSOutputBuffer &OB,
176 return SPSArgList<SPSString, bool>::serialize(OB, V.Name, V.Required);
177 }
178
179 static size_t deserialize(SPSInputBuffer &IB,
181 return SPSArgList<SPSString, bool>::deserialize(IB, V.Name, V.Required);
182 }
183};
184
185template <>
187public:
188 static size_t size(const RemoteSymbolLookup &V) {
190 }
191
192 static size_t serialize(SPSOutputBuffer &OB, const RemoteSymbolLookup &V) {
194 V.Symbols);
195 }
196
199 IB, V.H, V.Symbols);
200 }
201};
202
203template <>
206public:
207 static size_t size(const SimpleRemoteEPCExecutorInfo &SI) {
208 return SPSSimpleRemoteEPCExecutorInfo::AsArgList ::size(
209 SI.TargetTriple, SI.PageSize, SI.BootstrapSymbols);
210 }
211
212 static bool serialize(SPSOutputBuffer &OB,
213 const SimpleRemoteEPCExecutorInfo &SI) {
214 return SPSSimpleRemoteEPCExecutorInfo::AsArgList ::serialize(
215 OB, SI.TargetTriple, SI.PageSize, SI.BootstrapSymbols);
216 }
217
219 return SPSSimpleRemoteEPCExecutorInfo::AsArgList ::deserialize(
220 IB, SI.TargetTriple, SI.PageSize, SI.BootstrapSymbols);
221 }
222};
223
226
230
231} // end namespace shared
232} // end namespace orc
233} // end namespace llvm
234
235#endif // LLVM_EXECUTIONENGINE_ORC_SHARED_SIMPLEREMOTEEPCUTILS_H
This file defines the StringMap class.
uint64_t Size
@ SI
This file defines the SmallVector class.
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:156
Tagged union holding either a T or a Error.
Definition: Error.h:470
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:111
Represents an address in the executor process.
Uses read/write on FileDescriptors for transport.
void disconnect() override
Trigger disconnection from the transport.
static Expected< std::unique_ptr< FDSimpleRemoteEPCTransport > > Create(SimpleRemoteEPCTransportClient &C, int InFD, int OutFD)
Create a FDSimpleRemoteEPCTransport using the given FDs for reading (InFD) and writing (OutFD).
Error start() override
Called during setup of the client to indicate that the client is ready to receive messages.
static Expected< std::unique_ptr< FDSimpleRemoteEPCTransport > > Create(SimpleRemoteEPCTransportClient &C, int FD)
Create a FDSimpleRemoteEPCTransport using the given FD for both reading and writing.
Error sendMessage(SimpleRemoteEPCOpcode OpC, uint64_t SeqNo, ExecutorAddr TagAddr, ArrayRef< char > ArgBytes) override
Send a SimpleRemoteEPC message.
virtual Expected< HandleMessageAction > handleMessage(SimpleRemoteEPCOpcode OpC, uint64_t SeqNo, ExecutorAddr TagAddr, SimpleRemoteEPCArgBytesVector ArgBytes)=0
Handle receipt of a message.
virtual void handleDisconnect(Error Err)=0
Handle a disconnection from the underlying transport.
virtual void disconnect()=0
Trigger disconnection from the transport.
virtual Error sendMessage(SimpleRemoteEPCOpcode OpC, uint64_t SeqNo, ExecutorAddr TagAddr, ArrayRef< char > ArgBytes)=0
Send a SimpleRemoteEPC message.
virtual Error start()=0
Called during setup of the client to indicate that the client is ready to receive messages.
A utility class for serializing to a blob from a variadic list.
SPS tag type for expecteds, which are either a T or a string representing an error.
Input char buffer with underflow check.
Output char buffer with overflow check.
static size_t serialize(SPSOutputBuffer &OB, const RemoteSymbolLookup &V)
Specialize to describe how to serialize/deserialize to/from the given concrete type.
SPSSequence< char > SPSString
SPS tag type for strings, which are equivalent to sequences of chars.
std::vector< RemoteSymbolLookupSetElement > RemoteSymbolLookupSet
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
StringMap< ExecutorAddr > BootstrapSymbols