Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / source / Plugins / Process / Utility / LinuxPTraceDefines_arm64sve.h
blob8b5393ca18881cf7dba4dd5a1a402921dc897144
1 //===-- LinuxPTraceDefines_arm64sve.h ------------------------- -*- 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 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_LINUXPTRACEDEFINES_ARM64SVE_H
10 #define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_LINUXPTRACEDEFINES_ARM64SVE_H
12 #include <cstdint>
14 namespace lldb_private {
15 namespace sve {
18 * The SVE architecture leaves space for future expansion of the
19 * vector length beyond its initial architectural limit of 2048 bits
20 * (16 quadwords).
22 * See <Linux kernel source tree>/Documentation/arm64/sve.rst for a description
23 * of the vl/vq terminology.
26 const uint16_t vq_bytes = 16; /* number of bytes per quadword */
28 const uint16_t vq_min = 1;
29 const uint16_t vq_max = 512;
31 const uint16_t vl_min = vq_min * vq_bytes;
32 const uint16_t vl_max = vq_max * vq_bytes;
34 const uint16_t num_of_zregs = 32;
35 const uint16_t num_of_pregs = 16;
37 inline uint16_t vl_valid(uint16_t vl) {
38 return (vl % vq_bytes == 0 && vl >= vl_min && vl <= vl_max);
41 inline uint16_t vq_from_vl(uint16_t vl) { return vl / vq_bytes; }
42 inline uint16_t vl_from_vq(uint16_t vq) { return vq * vq_bytes; }
44 /* A new signal frame record sve_context encodes the SVE Registers on signal
45 * delivery. sve_context struct definition may be included in asm/sigcontext.h.
46 * We define sve_context_size which will be used by LLDB sve helper functions.
47 * More information on sve_context can be found in Linux kernel source tree at
48 * Documentation/arm64/sve.rst.
51 const uint16_t sve_context_size = 16;
54 * If the SVE registers are currently live for the thread at signal delivery,
55 * sve_context.head.size >=
56 * SigContextSize(vq_from_vl(sve_context.vl))
57 * and the register data may be accessed using the Sig*() functions.
59 * If sve_context.head.size <
60 * SigContextSize(vq_from_vl(sve_context.vl)),
61 * the SVE registers were not live for the thread and no register data
62 * is included: in this case, the Sig*() functions should not be
63 * used except for this check.
65 * The same convention applies when returning from a signal: a caller
66 * will need to remove or resize the sve_context block if it wants to
67 * make the SVE registers live when they were previously non-live or
68 * vice-versa. This may require the caller to allocate fresh
69 * memory and/or move other context blocks in the signal frame.
71 * Changing the vector length during signal return is not permitted:
72 * sve_context.vl must equal the thread's current vector length when
73 * doing a sigreturn.
76 * Note: for all these functions, the "vq" argument denotes the SVE
77 * vector length in quadwords (i.e., units of 128 bits).
79 * The correct way to obtain vq is to use vq_from_vl(vl). The
80 * result is valid if and only if vl_valid(vl) is true. This is
81 * guaranteed for a struct sve_context written by the kernel.
84 * Additional functions describe the contents and layout of the payload.
85 * For each, Sig*Offset(args) is the start offset relative to
86 * the start of struct sve_context, and Sig*Size(args) is the
87 * size in bytes:
89 * x type description
90 * - ---- -----------
91 * REGS the entire SVE context
93 * ZREGS __uint128_t[num_of_zregs][vq] all Z-registers
94 * ZREG __uint128_t[vq] individual Z-register Zn
96 * PREGS uint16_t[num_of_pregs][vq] all P-registers
97 * PREG uint16_t[vq] individual P-register Pn
99 * FFR uint16_t[vq] first-fault status register
101 * Additional data might be appended in the future.
104 inline uint16_t SigZRegSize(uint16_t vq) { return vq * vq_bytes; }
105 inline uint16_t SigPRegSize(uint16_t vq) { return vq * vq_bytes / 8; }
106 inline uint16_t SigFFRSize(uint16_t vq) { return SigPRegSize(vq); }
108 inline uint32_t SigRegsOffset() {
109 return (sve_context_size + vq_bytes - 1) / vq_bytes * vq_bytes;
112 inline uint32_t SigZRegsOffset() { return SigRegsOffset(); }
114 inline uint32_t SigZRegOffset(uint16_t vq, uint16_t n) {
115 return SigRegsOffset() + SigZRegSize(vq) * n;
118 inline uint32_t SigZRegsSize(uint16_t vq) {
119 return SigZRegOffset(vq, num_of_zregs) - SigRegsOffset();
122 inline uint32_t SigPRegsOffset(uint16_t vq) {
123 return SigRegsOffset() + SigZRegsSize(vq);
126 inline uint32_t SigPRegOffset(uint16_t vq, uint16_t n) {
127 return SigPRegsOffset(vq) + SigPRegSize(vq) * n;
130 inline uint32_t SigpRegsSize(uint16_t vq) {
131 return SigPRegOffset(vq, num_of_pregs) - SigPRegsOffset(vq);
134 inline uint32_t SigFFROffset(uint16_t vq) {
135 return SigPRegsOffset(vq) + SigpRegsSize(vq);
138 inline uint32_t SigRegsSize(uint16_t vq) {
139 return SigFFROffset(vq) + SigFFRSize(vq) - SigRegsOffset();
142 inline uint32_t SVESigContextSize(uint16_t vq) {
143 return SigRegsOffset() + SigRegsSize(vq);
146 struct user_sve_header {
147 uint32_t size; /* total meaningful regset content in bytes */
148 uint32_t max_size; /* maxmium possible size for this thread */
149 uint16_t vl; /* current vector length */
150 uint16_t max_vl; /* maximum possible vector length */
151 uint16_t flags;
152 uint16_t reserved;
155 using user_za_header = user_sve_header;
157 /* Definitions for user_sve_header.flags: */
158 const uint16_t ptrace_regs_mask = 1 << 0;
159 const uint16_t ptrace_regs_fpsimd = 0;
160 const uint16_t ptrace_regs_sve = ptrace_regs_mask;
163 * The remainder of the SVE state follows struct user_sve_header. The
164 * total size of the SVE state (including header) depends on the
165 * metadata in the header: PTraceSize(vq, flags) gives the total size
166 * of the state in bytes, including the header.
168 * Refer to <asm/sigcontext.h> for details of how to pass the correct
169 * "vq" argument to these macros.
172 /* Offset from the start of struct user_sve_header to the register data */
173 inline uint16_t PTraceRegsOffset() {
174 return (sizeof(struct user_sve_header) + vq_bytes - 1) / vq_bytes * vq_bytes;
178 * The register data content and layout depends on the value of the
179 * flags field.
183 * (flags & ptrace_regs_mask) == ptrace_regs_fpsimd case:
185 * The payload starts at offset PTraceFPSIMDOffset, and is of type
186 * struct user_fpsimd_state. Additional data might be appended in the
187 * future: use PTraceFPSIMDSize(vq, flags) to compute the total size.
188 * PTraceFPSIMDSize(vq, flags) will never be less than
189 * sizeof(struct user_fpsimd_state).
192 const uint32_t ptrace_fpsimd_offset = PTraceRegsOffset();
194 /* Return size of struct user_fpsimd_state from asm/ptrace.h */
195 inline uint32_t PTraceFPSIMDSize(uint16_t vq, uint16_t flags) { return 528; }
198 * (flags & ptrace_regs_mask) == ptrace_regs_sve case:
200 * The payload starts at offset PTraceSVEOffset, and is of size
201 * PTraceSVESize(vq, flags).
203 * Additional functions describe the contents and layout of the payload.
204 * For each, PTrace*X*Offset(args) is the start offset relative to
205 * the start of struct user_sve_header, and PTrace*X*Size(args) is
206 * the size in bytes:
208 * x type description
209 * - ---- -----------
210 * ZREGS \
211 * ZREG |
212 * PREGS | refer to <asm/sigcontext.h>
213 * PREG |
214 * FFR /
216 * FPSR uint32_t FPSR
217 * FPCR uint32_t FPCR
219 * Additional data might be appended in the future.
222 inline uint32_t PTraceZRegSize(uint16_t vq) { return SigZRegSize(vq); }
224 inline uint32_t PTracePRegSize(uint16_t vq) { return SigPRegSize(vq); }
226 inline uint32_t PTraceFFRSize(uint16_t vq) { return SigFFRSize(vq); }
228 const uint32_t fpsr_size = sizeof(uint32_t);
229 const uint32_t fpcr_size = sizeof(uint32_t);
231 inline uint32_t SigToPTrace(uint32_t offset) {
232 return offset - SigRegsOffset() + PTraceRegsOffset();
235 const uint32_t ptrace_sve_offset = PTraceRegsOffset();
237 inline uint32_t PTraceZRegsOffset(uint16_t vq) {
238 return SigToPTrace(SigZRegsOffset());
241 inline uint32_t PTraceZRegOffset(uint16_t vq, uint16_t n) {
242 return SigToPTrace(SigZRegOffset(vq, n));
245 inline uint32_t PTraceZRegsSize(uint16_t vq) {
246 return PTraceZRegOffset(vq, num_of_zregs) - SigToPTrace(SigRegsOffset());
249 inline uint32_t PTracePRegsOffset(uint16_t vq) {
250 return SigToPTrace(SigPRegsOffset(vq));
253 inline uint32_t PTracePRegOffset(uint16_t vq, uint16_t n) {
254 return SigToPTrace(SigPRegOffset(vq, n));
257 inline uint32_t PTracePRegsSize(uint16_t vq) {
258 return PTracePRegOffset(vq, num_of_pregs) - PTracePRegsOffset(vq);
261 inline uint32_t PTraceFFROffset(uint16_t vq) {
262 return SigToPTrace(SigFFROffset(vq));
265 inline uint32_t PTraceFPSROffset(uint16_t vq) {
266 return (PTraceFFROffset(vq) + PTraceFFRSize(vq) + (vq_bytes - 1)) / vq_bytes *
267 vq_bytes;
270 inline uint32_t PTraceFPCROffset(uint16_t vq) {
271 return PTraceFPSROffset(vq) + fpsr_size;
275 * Any future extension appended after FPCR must be aligned to the next
276 * 128-bit boundary.
279 inline uint32_t PTraceSVESize(uint16_t vq, uint16_t flags) {
280 return (PTraceFPCROffset(vq) + fpcr_size - ptrace_sve_offset + vq_bytes - 1) /
281 vq_bytes * vq_bytes;
284 inline uint32_t PTraceSize(uint16_t vq, uint16_t flags) {
285 return (flags & ptrace_regs_mask) == ptrace_regs_sve
286 ? ptrace_sve_offset + PTraceSVESize(vq, flags)
287 : ptrace_fpsimd_offset + PTraceFPSIMDSize(vq, flags);
290 } // namespace SVE
291 } // namespace lldb_private
293 #endif // LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_LINUXPTRACEDEFINES_ARM64SVE_H