LLVM 17.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");
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/// A handle used to represent a loaded dylib in the target process.
105
106using LookupResult = std::vector<ExecutorAddr>;
107
108} // end namespace tpctypes
109
110namespace shared {
111
112class SPSRemoteAllocGroup;
113
116
119
122
126
127template <typename T>
129
134
136
137template <>
138class SPSSerializationTraits<SPSRemoteAllocGroup, tpctypes::RemoteAllocGroup> {
139 enum WireBits {
140 ReadBit = 1 << 0,
141 WriteBit = 1 << 1,
142 ExecBit = 1 << 2,
143 FinalizeBit = 1 << 3
144 };
145
146public:
147 static size_t size(const tpctypes::RemoteAllocGroup &RAG) {
148 // All AllocGroup values encode to the same size.
149 return SPSArgList<uint8_t>::size(uint8_t(0));
150 }
151
152 static bool serialize(SPSOutputBuffer &OB,
153 const tpctypes::RemoteAllocGroup &RAG) {
154 uint8_t WireValue = 0;
155 if ((RAG.Prot & MemProt::Read) != MemProt::None)
156 WireValue |= ReadBit;
157 if ((RAG.Prot & MemProt::Write) != MemProt::None)
158 WireValue |= WriteBit;
159 if ((RAG.Prot & MemProt::Exec) != MemProt::None)
160 WireValue |= ExecBit;
161 if (RAG.FinalizeLifetime)
162 WireValue |= FinalizeBit;
163 return SPSArgList<uint8_t>::serialize(OB, WireValue);
164 }
165
167 uint8_t Val;
169 return false;
171 if (Val & ReadBit)
172 MP |= MemProt::Read;
173 if (Val & WriteBit)
174 MP |= MemProt::Write;
175 if (Val & ExecBit)
176 MP |= MemProt::Exec;
177 bool FinalizeLifetime = (Val & FinalizeBit) ? true : false;
178 RAG = {MP, FinalizeLifetime};
179 return true;
180 }
181};
182
183template <>
185 tpctypes::SegFinalizeRequest> {
187
188public:
189 static size_t size(const tpctypes::SegFinalizeRequest &SFR) {
190 return SFRAL::size(SFR.RAG, SFR.Addr, SFR.Size, SFR.Content);
191 }
192
193 static bool serialize(SPSOutputBuffer &OB,
194 const tpctypes::SegFinalizeRequest &SFR) {
195 return SFRAL::serialize(OB, SFR.RAG, SFR.Addr, SFR.Size, SFR.Content);
196 }
197
200 return SFRAL::deserialize(IB, SFR.RAG, SFR.Addr, SFR.Size, SFR.Content);
201 }
202};
203
204template <>
205class SPSSerializationTraits<SPSFinalizeRequest, tpctypes::FinalizeRequest> {
207
208public:
209 static size_t size(const tpctypes::FinalizeRequest &FR) {
210 return FRAL::size(FR.Segments, FR.Actions);
211 }
212
213 static bool serialize(SPSOutputBuffer &OB,
214 const tpctypes::FinalizeRequest &FR) {
215 return FRAL::serialize(OB, FR.Segments, FR.Actions);
216 }
217
219 return FRAL::deserialize(IB, FR.Segments, FR.Actions);
220 }
221};
222
223template <>
225 tpctypes::SharedMemorySegFinalizeRequest> {
227
228public:
230 return SFRAL::size(SFR.RAG, SFR.Addr, SFR.Size);
231 }
232
233 static bool serialize(SPSOutputBuffer &OB,
235 return SFRAL::serialize(OB, SFR.RAG, SFR.Addr, SFR.Size);
236 }
237
240 return SFRAL::deserialize(IB, SFR.RAG, SFR.Addr, SFR.Size);
241 }
242};
243
244template <>
246 tpctypes::SharedMemoryFinalizeRequest> {
248
249public:
251 return FRAL::size(FR.Segments, FR.Actions);
252 }
253
254 static bool serialize(SPSOutputBuffer &OB,
256 return FRAL::serialize(OB, FR.Segments, FR.Actions);
257 }
258
261 return FRAL::deserialize(IB, FR.Segments, FR.Actions);
262 }
263};
264
265template <typename T>
267 tpctypes::UIntWrite<T>> {
268public:
269 static size_t size(const tpctypes::UIntWrite<T> &W) {
270 return SPSTuple<SPSExecutorAddr, T>::AsArgList::size(W.Addr, W.Value);
271 }
272
275 W.Value);
276 }
277
280 W.Value);
281 }
282};
283
284template <>
286 tpctypes::BufferWrite> {
287public:
288 static size_t size(const tpctypes::BufferWrite &W) {
289 return SPSTuple<SPSExecutorAddr, SPSSequence<char>>::AsArgList::size(
290 W.Addr, W.Buffer);
291 }
292
294 return SPSTuple<SPSExecutorAddr, SPSSequence<char>>::AsArgList ::serialize(
295 OB, W.Addr, W.Buffer);
296 }
297
300 SPSSequence<char>>::AsArgList ::deserialize(IB, W.Addr,
301 W.Buffer);
302 }
303};
304
305} // end namespace shared
306} // end namespace orc
307} // end namespace llvm
308
309#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
MemLifetimePolicy getMemLifetimePolicy() const
Returns the MemLifetimePolicy 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
RemoteAllocGroup(MemProt Prot, bool FinalizeLifetime)
std::vector< SharedMemorySegFinalizeRequest > Segments
UIntWrite(ExecutorAddr Addr, T Value)