LLVM 20.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"
26#include "llvm/Support/Memory.h"
27
28#include <vector>
29
30namespace llvm {
31namespace orc {
32namespace tpctypes {
33
35 RemoteAllocGroup() = default;
39 RemoteAllocGroup(const AllocGroup &AG) : Prot(AG.getMemProt()) {
41 "Cannot use no-alloc memory in a remote alloc request");
43 }
44
46 bool FinalizeLifetime = false;
47};
48
54};
55
57 std::vector<SegFinalizeRequest> Segments;
59};
60
65};
66
68 std::vector<SharedMemorySegFinalizeRequest> Segments;
70};
71
72template <typename T> struct UIntWrite {
73 UIntWrite() = default;
75
77 T Value = 0;
78};
79
80/// Describes a write to a uint8_t.
82
83/// Describes a write to a uint16_t.
85
86/// Describes a write to a uint32_t.
88
89/// Describes a write to a uint64_t.
91
92/// Describes a write to a buffer.
93/// For use with TargetProcessControl::MemoryAccess objects.
95 BufferWrite() = default;
97 : Addr(Addr), Buffer(Buffer) {}
98
101};
102
103/// Describes a write to a pointer.
104/// For use with TargetProcessControl::MemoryAccess objects.
106 PointerWrite() = default;
108 : Addr(Addr), Value(Value) {}
109
112};
113
114/// A handle used to represent a loaded dylib in the target process.
116
117using LookupResult = std::vector<ExecutorSymbolDef>;
118
119} // end namespace tpctypes
120
121namespace shared {
122
123class SPSRemoteAllocGroup;
124
127
130
133
137
138template <typename T>
140
145
148
149template <>
150class SPSSerializationTraits<SPSRemoteAllocGroup, tpctypes::RemoteAllocGroup> {
151 enum WireBits {
152 ReadBit = 1 << 0,
153 WriteBit = 1 << 1,
154 ExecBit = 1 << 2,
155 FinalizeBit = 1 << 3
156 };
157
158public:
159 static size_t size(const tpctypes::RemoteAllocGroup &RAG) {
160 // All AllocGroup values encode to the same size.
162 }
163
164 static bool serialize(SPSOutputBuffer &OB,
165 const tpctypes::RemoteAllocGroup &RAG) {
166 uint8_t WireValue = 0;
167 if ((RAG.Prot & MemProt::Read) != MemProt::None)
168 WireValue |= ReadBit;
169 if ((RAG.Prot & MemProt::Write) != MemProt::None)
170 WireValue |= WriteBit;
171 if ((RAG.Prot & MemProt::Exec) != MemProt::None)
172 WireValue |= ExecBit;
173 if (RAG.FinalizeLifetime)
174 WireValue |= FinalizeBit;
175 return SPSArgList<uint8_t>::serialize(OB, WireValue);
176 }
177
179 uint8_t Val;
181 return false;
183 if (Val & ReadBit)
184 MP |= MemProt::Read;
185 if (Val & WriteBit)
186 MP |= MemProt::Write;
187 if (Val & ExecBit)
188 MP |= MemProt::Exec;
189 bool FinalizeLifetime = (Val & FinalizeBit) ? true : false;
190 RAG = {MP, FinalizeLifetime};
191 return true;
192 }
193};
194
195template <>
197 tpctypes::SegFinalizeRequest> {
199
200public:
201 static size_t size(const tpctypes::SegFinalizeRequest &SFR) {
202 return SFRAL::size(SFR.RAG, SFR.Addr, SFR.Size, SFR.Content);
203 }
204
205 static bool serialize(SPSOutputBuffer &OB,
206 const tpctypes::SegFinalizeRequest &SFR) {
207 return SFRAL::serialize(OB, SFR.RAG, SFR.Addr, SFR.Size, SFR.Content);
208 }
209
212 return SFRAL::deserialize(IB, SFR.RAG, SFR.Addr, SFR.Size, SFR.Content);
213 }
214};
215
216template <>
217class SPSSerializationTraits<SPSFinalizeRequest, tpctypes::FinalizeRequest> {
219
220public:
221 static size_t size(const tpctypes::FinalizeRequest &FR) {
222 return FRAL::size(FR.Segments, FR.Actions);
223 }
224
225 static bool serialize(SPSOutputBuffer &OB,
226 const tpctypes::FinalizeRequest &FR) {
227 return FRAL::serialize(OB, FR.Segments, FR.Actions);
228 }
229
231 return FRAL::deserialize(IB, FR.Segments, FR.Actions);
232 }
233};
234
235template <>
237 tpctypes::SharedMemorySegFinalizeRequest> {
239
240public:
242 return SFRAL::size(SFR.RAG, SFR.Addr, SFR.Size);
243 }
244
245 static bool serialize(SPSOutputBuffer &OB,
247 return SFRAL::serialize(OB, SFR.RAG, SFR.Addr, SFR.Size);
248 }
249
252 return SFRAL::deserialize(IB, SFR.RAG, SFR.Addr, SFR.Size);
253 }
254};
255
256template <>
258 tpctypes::SharedMemoryFinalizeRequest> {
260
261public:
263 return FRAL::size(FR.Segments, FR.Actions);
264 }
265
266 static bool serialize(SPSOutputBuffer &OB,
268 return FRAL::serialize(OB, FR.Segments, FR.Actions);
269 }
270
273 return FRAL::deserialize(IB, FR.Segments, FR.Actions);
274 }
275};
276
277template <typename T>
279 tpctypes::UIntWrite<T>> {
280public:
281 static size_t size(const tpctypes::UIntWrite<T> &W) {
282 return SPSTuple<SPSExecutorAddr, T>::AsArgList::size(W.Addr, W.Value);
283 }
284
287 W.Value);
288 }
289
292 W.Value);
293 }
294};
295
296template <>
298 tpctypes::BufferWrite> {
299public:
300 static size_t size(const tpctypes::BufferWrite &W) {
301 return SPSTuple<SPSExecutorAddr, SPSSequence<char>>::AsArgList::size(
302 W.Addr, W.Buffer);
303 }
304
306 return SPSTuple<SPSExecutorAddr, SPSSequence<char>>::AsArgList ::serialize(
307 OB, W.Addr, W.Buffer);
308 }
309
312 SPSSequence<char>>::AsArgList ::deserialize(IB, W.Addr,
313 W.Buffer);
314 }
315};
316
317template <>
319 tpctypes::PointerWrite> {
320public:
321 static size_t size(const tpctypes::PointerWrite &W) {
323 W.Value);
324 }
325
328 OB, W.Addr, W.Value);
329 }
330
333 IB, W.Addr, W.Value);
334 }
335};
336
337} // end namespace shared
338} // end namespace orc
339} // end namespace llvm
340
341#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:51
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< ExecutorSymbolDef > 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)