LLVM 18.0.0git
TargetProcessControlTypes.h
Go to the documentation of this file.
1//===--- TargetProcessControlTypes.h -- Shared Core/TPC types ---*- 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// TargetProcessControl types that are used by both the Orc and
10// OrcTargetProcess libraries.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_TARGETPROCESSCONTROLTYPES_H
15#define LLVM_EXECUTIONENGINE_ORC_SHARED_TARGETPROCESSCONTROLTYPES_H
16
17#include "llvm/ADT/ArrayRef.h"
18#include "llvm/ADT/StringRef.h"
25#include "llvm/Support/Memory.h"
26
27#include <vector>
28
29namespace llvm {
30namespace orc {
31namespace tpctypes {
32
34 RemoteAllocGroup() = default;
38 RemoteAllocGroup(const AllocGroup &AG) : Prot(AG.getMemProt()) {
40 "Cannot use no-alloc memory in a remote alloc request");
42 }
43
45 bool FinalizeLifetime = false;
46};
47
53};
54
56 std::vector<SegFinalizeRequest> Segments;
58};
59
64};
65
67 std::vector<SharedMemorySegFinalizeRequest> Segments;
69};
70
71template <typename T> struct UIntWrite {
72 UIntWrite() = default;
74
76 T Value = 0;
77};
78
79/// Describes a write to a uint8_t.
81
82/// Describes a write to a uint16_t.
84
85/// Describes a write to a uint32_t.
87
88/// Describes a write to a uint64_t.
90
91/// Describes a write to a buffer.
92/// For use with TargetProcessControl::MemoryAccess objects.
94 BufferWrite() = default;
96 : Addr(Addr), Buffer(Buffer) {}
97
100};
101
102/// Describes a write to a pointer.
103/// For use with TargetProcessControl::MemoryAccess objects.
105 PointerWrite() = default;
107 : Addr(Addr), Value(Value) {}
108
111};
112
113/// A handle used to represent a loaded dylib in the target process.
115
116using LookupResult = std::vector<ExecutorAddr>;
117
118} // end namespace tpctypes
119
120namespace shared {
121
122class SPSRemoteAllocGroup;
123
126
129
132
136
137template <typename T>
139
144
147
148template <>
149class SPSSerializationTraits<SPSRemoteAllocGroup, tpctypes::RemoteAllocGroup> {
150 enum WireBits {
151 ReadBit = 1 << 0,
152 WriteBit = 1 << 1,
153 ExecBit = 1 << 2,
154 FinalizeBit = 1 << 3
155 };
156
157public:
158 static size_t size(const tpctypes::RemoteAllocGroup &RAG) {
159 // All AllocGroup values encode to the same size.
160 return SPSArgList<uint8_t>::size(uint8_t(0));
161 }
162
163 static bool serialize(SPSOutputBuffer &OB,
164 const tpctypes::RemoteAllocGroup &RAG) {
165 uint8_t WireValue = 0;
166 if ((RAG.Prot & MemProt::Read) != MemProt::None)
167 WireValue |= ReadBit;
168 if ((RAG.Prot & MemProt::Write) != MemProt::None)
169 WireValue |= WriteBit;
170 if ((RAG.Prot & MemProt::Exec) != MemProt::None)
171 WireValue |= ExecBit;
172 if (RAG.FinalizeLifetime)
173 WireValue |= FinalizeBit;
174 return SPSArgList<uint8_t>::serialize(OB, WireValue);
175 }
176
178 uint8_t Val;
180 return false;
182 if (Val & ReadBit)
183 MP |= MemProt::Read;
184 if (Val & WriteBit)
185 MP |= MemProt::Write;
186 if (Val & ExecBit)
187 MP |= MemProt::Exec;
188 bool FinalizeLifetime = (Val & FinalizeBit) ? true : false;
189 RAG = {MP, FinalizeLifetime};
190 return true;
191 }
192};
193
194template <>
196 tpctypes::SegFinalizeRequest> {
198
199public:
200 static size_t size(const tpctypes::SegFinalizeRequest &SFR) {
201 return SFRAL::size(SFR.RAG, SFR.Addr, SFR.Size, SFR.Content);
202 }
203
204 static bool serialize(SPSOutputBuffer &OB,
205 const tpctypes::SegFinalizeRequest &SFR) {
206 return SFRAL::serialize(OB, SFR.RAG, SFR.Addr, SFR.Size, SFR.Content);
207 }
208
211 return SFRAL::deserialize(IB, SFR.RAG, SFR.Addr, SFR.Size, SFR.Content);
212 }
213};
214
215template <>
216class SPSSerializationTraits<SPSFinalizeRequest, tpctypes::FinalizeRequest> {
218
219public:
220 static size_t size(const tpctypes::FinalizeRequest &FR) {
221 return FRAL::size(FR.Segments, FR.Actions);
222 }
223
224 static bool serialize(SPSOutputBuffer &OB,
225 const tpctypes::FinalizeRequest &FR) {
226 return FRAL::serialize(OB, FR.Segments, FR.Actions);
227 }
228
230 return FRAL::deserialize(IB, FR.Segments, FR.Actions);
231 }
232};
233
234template <>
236 tpctypes::SharedMemorySegFinalizeRequest> {
238
239public:
241 return SFRAL::size(SFR.RAG, SFR.Addr, SFR.Size);
242 }
243
244 static bool serialize(SPSOutputBuffer &OB,
246 return SFRAL::serialize(OB, SFR.RAG, SFR.Addr, SFR.Size);
247 }
248
251 return SFRAL::deserialize(IB, SFR.RAG, SFR.Addr, SFR.Size);
252 }
253};
254
255template <>
257 tpctypes::SharedMemoryFinalizeRequest> {
259
260public:
262 return FRAL::size(FR.Segments, FR.Actions);
263 }
264
265 static bool serialize(SPSOutputBuffer &OB,
267 return FRAL::serialize(OB, FR.Segments, FR.Actions);
268 }
269
272 return FRAL::deserialize(IB, FR.Segments, FR.Actions);
273 }
274};
275
276template <typename T>
278 tpctypes::UIntWrite<T>> {
279public:
280 static size_t size(const tpctypes::UIntWrite<T> &W) {
281 return SPSTuple<SPSExecutorAddr, T>::AsArgList::size(W.Addr, W.Value);
282 }
283
286 W.Value);
287 }
288
291 W.Value);
292 }
293};
294
295template <>
297 tpctypes::BufferWrite> {
298public:
299 static size_t size(const tpctypes::BufferWrite &W) {
300 return SPSTuple<SPSExecutorAddr, SPSSequence<char>>::AsArgList::size(
301 W.Addr, W.Buffer);
302 }
303
305 return SPSTuple<SPSExecutorAddr, SPSSequence<char>>::AsArgList ::serialize(
306 OB, W.Addr, W.Buffer);
307 }
308
311 SPSSequence<char>>::AsArgList ::deserialize(IB, W.Addr,
312 W.Buffer);
313 }
314};
315
316template <>
318 tpctypes::PointerWrite> {
319public:
320 static size_t size(const tpctypes::PointerWrite &W) {
322 W.Value);
323 }
324
327 OB, W.Addr, W.Value);
328 }
329
332 IB, W.Addr, W.Value);
333 }
334};
335
336} // end namespace shared
337} // end namespace orc
338} // end namespace llvm
339
340#endif // LLVM_EXECUTIONENGINE_ORC_SHARED_TARGETPROCESSCONTROLTYPES_H
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
LLVM Value Representation.
Definition: Value.h:74
A pair of memory protections and allocation policies.
Definition: MemoryFlags.h:110
MemLifetime getMemLifetime() const
Returns the MemLifetime for this group.
Definition: MemoryFlags.h:141
Represents an address in the executor process.
A utility class for serializing to a blob from a variadic list.
Input char buffer with underflow check.
Output char buffer with overflow check.
static bool serialize(SPSOutputBuffer &OB, const tpctypes::FinalizeRequest &FR)
static bool serialize(SPSOutputBuffer &OB, const tpctypes::RemoteAllocGroup &RAG)
static bool serialize(SPSOutputBuffer &OB, const tpctypes::SegFinalizeRequest &SFR)
Specialize to describe how to serialize/deserialize to/from the given concrete type.
SPSArgList< SPSTagTs... > AsArgList
Convenience typedef of the corresponding arg list.
std::vector< AllocActionCallPair > AllocActions
A vector of allocation actions to be run for this allocation.
std::vector< ExecutorAddr > LookupResult
MemProt
Describes Read/Write/Exec permissions for memory.
Definition: MemoryFlags.h:27
@ NoAlloc
NoAlloc memory should not be allocated by the JITLinkMemoryManager at all.
@ Finalize
Finalize memory should be allocated by the allocator, and then be overwritten and deallocated after a...
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Describes a write to a buffer.
BufferWrite(ExecutorAddr Addr, StringRef Buffer)
std::vector< SegFinalizeRequest > Segments
Describes a write to a pointer.
PointerWrite(ExecutorAddr Addr, ExecutorAddr Value)
RemoteAllocGroup(MemProt Prot, bool FinalizeLifetime)
std::vector< SharedMemorySegFinalizeRequest > Segments
UIntWrite(ExecutorAddr Addr, T Value)