LLVM 23.0.0git
AArch64BaseInfo.h
Go to the documentation of this file.
1//===-- AArch64BaseInfo.h - Top level definitions for AArch64 ---*- 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// This file contains small standalone helper functions and enum definitions for
10// the AArch64 target useful for the compiler back-end and the MC libraries.
11// As such, it deliberately does not include references to LLVM core
12// code gen types, passes, etc..
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_LIB_TARGET_AARCH64_UTILS_AARCH64BASEINFO_H
17#define LLVM_LIB_TARGET_AARCH64_UTILS_AARCH64BASEINFO_H
18
19// FIXME: Is it easiest to fix this layering violation by moving the .inc
20// #includes from AArch64MCTargetDesc.h to here?
21#include "MCTargetDesc/AArch64MCTargetDesc.h" // For AArch64::X0 and friends.
22#include "llvm/ADT/APFloat.h"
23#include "llvm/ADT/APSInt.h"
25#include "llvm/ADT/STLExtras.h"
29
30namespace llvm {
31
33 switch (Reg.id()) {
34 case AArch64::X0: return AArch64::W0;
35 case AArch64::X1: return AArch64::W1;
36 case AArch64::X2: return AArch64::W2;
37 case AArch64::X3: return AArch64::W3;
38 case AArch64::X4: return AArch64::W4;
39 case AArch64::X5: return AArch64::W5;
40 case AArch64::X6: return AArch64::W6;
41 case AArch64::X7: return AArch64::W7;
42 case AArch64::X8: return AArch64::W8;
43 case AArch64::X9: return AArch64::W9;
44 case AArch64::X10: return AArch64::W10;
45 case AArch64::X11: return AArch64::W11;
46 case AArch64::X12: return AArch64::W12;
47 case AArch64::X13: return AArch64::W13;
48 case AArch64::X14: return AArch64::W14;
49 case AArch64::X15: return AArch64::W15;
50 case AArch64::X16: return AArch64::W16;
51 case AArch64::X17: return AArch64::W17;
52 case AArch64::X18: return AArch64::W18;
53 case AArch64::X19: return AArch64::W19;
54 case AArch64::X20: return AArch64::W20;
55 case AArch64::X21: return AArch64::W21;
56 case AArch64::X22: return AArch64::W22;
57 case AArch64::X23: return AArch64::W23;
58 case AArch64::X24: return AArch64::W24;
59 case AArch64::X25: return AArch64::W25;
60 case AArch64::X26: return AArch64::W26;
61 case AArch64::X27: return AArch64::W27;
62 case AArch64::X28: return AArch64::W28;
63 case AArch64::FP: return AArch64::W29;
64 case AArch64::LR: return AArch64::W30;
65 case AArch64::SP: return AArch64::WSP;
66 case AArch64::XZR: return AArch64::WZR;
67 }
68 // For anything else, return it unchanged.
69 return Reg;
70}
71
73 switch (Reg.id()) {
74 case AArch64::W0: return AArch64::X0;
75 case AArch64::W1: return AArch64::X1;
76 case AArch64::W2: return AArch64::X2;
77 case AArch64::W3: return AArch64::X3;
78 case AArch64::W4: return AArch64::X4;
79 case AArch64::W5: return AArch64::X5;
80 case AArch64::W6: return AArch64::X6;
81 case AArch64::W7: return AArch64::X7;
82 case AArch64::W8: return AArch64::X8;
83 case AArch64::W9: return AArch64::X9;
84 case AArch64::W10: return AArch64::X10;
85 case AArch64::W11: return AArch64::X11;
86 case AArch64::W12: return AArch64::X12;
87 case AArch64::W13: return AArch64::X13;
88 case AArch64::W14: return AArch64::X14;
89 case AArch64::W15: return AArch64::X15;
90 case AArch64::W16: return AArch64::X16;
91 case AArch64::W17: return AArch64::X17;
92 case AArch64::W18: return AArch64::X18;
93 case AArch64::W19: return AArch64::X19;
94 case AArch64::W20: return AArch64::X20;
95 case AArch64::W21: return AArch64::X21;
96 case AArch64::W22: return AArch64::X22;
97 case AArch64::W23: return AArch64::X23;
98 case AArch64::W24: return AArch64::X24;
99 case AArch64::W25: return AArch64::X25;
100 case AArch64::W26: return AArch64::X26;
101 case AArch64::W27: return AArch64::X27;
102 case AArch64::W28: return AArch64::X28;
103 case AArch64::W29: return AArch64::FP;
104 case AArch64::W30: return AArch64::LR;
105 case AArch64::WSP: return AArch64::SP;
106 case AArch64::WZR: return AArch64::XZR;
107 }
108 // For anything else, return it unchanged.
109 return Reg;
110}
111
113 switch (RegTuple.id()) {
114 case AArch64::X0_X1_X2_X3_X4_X5_X6_X7: return AArch64::X0;
115 case AArch64::X2_X3_X4_X5_X6_X7_X8_X9: return AArch64::X2;
116 case AArch64::X4_X5_X6_X7_X8_X9_X10_X11: return AArch64::X4;
117 case AArch64::X6_X7_X8_X9_X10_X11_X12_X13: return AArch64::X6;
118 case AArch64::X8_X9_X10_X11_X12_X13_X14_X15: return AArch64::X8;
119 case AArch64::X10_X11_X12_X13_X14_X15_X16_X17: return AArch64::X10;
120 case AArch64::X12_X13_X14_X15_X16_X17_X18_X19: return AArch64::X12;
121 case AArch64::X14_X15_X16_X17_X18_X19_X20_X21: return AArch64::X14;
122 case AArch64::X16_X17_X18_X19_X20_X21_X22_X23: return AArch64::X16;
123 case AArch64::X18_X19_X20_X21_X22_X23_X24_X25: return AArch64::X18;
124 case AArch64::X20_X21_X22_X23_X24_X25_X26_X27: return AArch64::X20;
125 case AArch64::X22_X23_X24_X25_X26_X27_X28_FP: return AArch64::X22;
126 }
127 // For anything else, return it unchanged.
128 return RegTuple;
129}
130
132 switch (Reg.id()) {
133 case AArch64::D0: return AArch64::B0;
134 case AArch64::D1: return AArch64::B1;
135 case AArch64::D2: return AArch64::B2;
136 case AArch64::D3: return AArch64::B3;
137 case AArch64::D4: return AArch64::B4;
138 case AArch64::D5: return AArch64::B5;
139 case AArch64::D6: return AArch64::B6;
140 case AArch64::D7: return AArch64::B7;
141 case AArch64::D8: return AArch64::B8;
142 case AArch64::D9: return AArch64::B9;
143 case AArch64::D10: return AArch64::B10;
144 case AArch64::D11: return AArch64::B11;
145 case AArch64::D12: return AArch64::B12;
146 case AArch64::D13: return AArch64::B13;
147 case AArch64::D14: return AArch64::B14;
148 case AArch64::D15: return AArch64::B15;
149 case AArch64::D16: return AArch64::B16;
150 case AArch64::D17: return AArch64::B17;
151 case AArch64::D18: return AArch64::B18;
152 case AArch64::D19: return AArch64::B19;
153 case AArch64::D20: return AArch64::B20;
154 case AArch64::D21: return AArch64::B21;
155 case AArch64::D22: return AArch64::B22;
156 case AArch64::D23: return AArch64::B23;
157 case AArch64::D24: return AArch64::B24;
158 case AArch64::D25: return AArch64::B25;
159 case AArch64::D26: return AArch64::B26;
160 case AArch64::D27: return AArch64::B27;
161 case AArch64::D28: return AArch64::B28;
162 case AArch64::D29: return AArch64::B29;
163 case AArch64::D30: return AArch64::B30;
164 case AArch64::D31: return AArch64::B31;
165 }
166 // For anything else, return it unchanged.
167 return Reg;
168}
169
171 switch (Reg.id()) {
172 case AArch64::B0: return AArch64::D0;
173 case AArch64::B1: return AArch64::D1;
174 case AArch64::B2: return AArch64::D2;
175 case AArch64::B3: return AArch64::D3;
176 case AArch64::B4: return AArch64::D4;
177 case AArch64::B5: return AArch64::D5;
178 case AArch64::B6: return AArch64::D6;
179 case AArch64::B7: return AArch64::D7;
180 case AArch64::B8: return AArch64::D8;
181 case AArch64::B9: return AArch64::D9;
182 case AArch64::B10: return AArch64::D10;
183 case AArch64::B11: return AArch64::D11;
184 case AArch64::B12: return AArch64::D12;
185 case AArch64::B13: return AArch64::D13;
186 case AArch64::B14: return AArch64::D14;
187 case AArch64::B15: return AArch64::D15;
188 case AArch64::B16: return AArch64::D16;
189 case AArch64::B17: return AArch64::D17;
190 case AArch64::B18: return AArch64::D18;
191 case AArch64::B19: return AArch64::D19;
192 case AArch64::B20: return AArch64::D20;
193 case AArch64::B21: return AArch64::D21;
194 case AArch64::B22: return AArch64::D22;
195 case AArch64::B23: return AArch64::D23;
196 case AArch64::B24: return AArch64::D24;
197 case AArch64::B25: return AArch64::D25;
198 case AArch64::B26: return AArch64::D26;
199 case AArch64::B27: return AArch64::D27;
200 case AArch64::B28: return AArch64::D28;
201 case AArch64::B29: return AArch64::D29;
202 case AArch64::B30: return AArch64::D30;
203 case AArch64::B31: return AArch64::D31;
204 }
205 // For anything else, return it unchanged.
206 return Reg;
207}
208
209static inline bool atomicBarrierDroppedOnZero(unsigned Opcode) {
210 switch (Opcode) {
211 case AArch64::LDADDAB: case AArch64::LDADDAH:
212 case AArch64::LDADDAW: case AArch64::LDADDAX:
213 case AArch64::LDADDALB: case AArch64::LDADDALH:
214 case AArch64::LDADDALW: case AArch64::LDADDALX:
215 case AArch64::LDCLRAB: case AArch64::LDCLRAH:
216 case AArch64::LDCLRAW: case AArch64::LDCLRAX:
217 case AArch64::LDCLRALB: case AArch64::LDCLRALH:
218 case AArch64::LDCLRALW: case AArch64::LDCLRALX:
219 case AArch64::LDEORAB: case AArch64::LDEORAH:
220 case AArch64::LDEORAW: case AArch64::LDEORAX:
221 case AArch64::LDEORALB: case AArch64::LDEORALH:
222 case AArch64::LDEORALW: case AArch64::LDEORALX:
223 case AArch64::LDSETAB: case AArch64::LDSETAH:
224 case AArch64::LDSETAW: case AArch64::LDSETAX:
225 case AArch64::LDSETALB: case AArch64::LDSETALH:
226 case AArch64::LDSETALW: case AArch64::LDSETALX:
227 case AArch64::LDSMAXAB: case AArch64::LDSMAXAH:
228 case AArch64::LDSMAXAW: case AArch64::LDSMAXAX:
229 case AArch64::LDSMAXALB: case AArch64::LDSMAXALH:
230 case AArch64::LDSMAXALW: case AArch64::LDSMAXALX:
231 case AArch64::LDSMINAB: case AArch64::LDSMINAH:
232 case AArch64::LDSMINAW: case AArch64::LDSMINAX:
233 case AArch64::LDSMINALB: case AArch64::LDSMINALH:
234 case AArch64::LDSMINALW: case AArch64::LDSMINALX:
235 case AArch64::LDUMAXAB: case AArch64::LDUMAXAH:
236 case AArch64::LDUMAXAW: case AArch64::LDUMAXAX:
237 case AArch64::LDUMAXALB: case AArch64::LDUMAXALH:
238 case AArch64::LDUMAXALW: case AArch64::LDUMAXALX:
239 case AArch64::LDUMINAB: case AArch64::LDUMINAH:
240 case AArch64::LDUMINAW: case AArch64::LDUMINAX:
241 case AArch64::LDUMINALB: case AArch64::LDUMINALH:
242 case AArch64::LDUMINALW: case AArch64::LDUMINALX:
243 case AArch64::SWPAB: case AArch64::SWPAH:
244 case AArch64::SWPAW: case AArch64::SWPAX:
245 case AArch64::SWPALB: case AArch64::SWPALH:
246 case AArch64::SWPALW: case AArch64::SWPALX:
247 return true;
248 }
249 return false;
250}
251
252inline unsigned CheckFixedPointOperandConstant(APFloat &FVal, unsigned RegWidth,
253 bool isReciprocal) {
254 // An FCVT[SU] instruction performs: convertToInt(Val * 2^fbits) where fbits
255 // is between 1 and 32 for a destination w-register, or 1 and 64 for an
256 // x-register.
257 //
258 // By this stage, we've detected (fp_to_[su]int (fmul Val, THIS_NODE)) so we
259 // want THIS_NODE to be 2^fbits. This is much easier to deal with using
260 // integers.
261 bool IsExact;
262
263 if (isReciprocal)
264 if (!FVal.getExactInverse(&FVal))
265 return 0;
266
267 // fbits is between 1 and 64 in the worst-case, which means the fmul
268 // could have 2^64 as an actual operand. Need 65 bits of precision.
269 APSInt IntVal(65, true);
270 FVal.convertToInteger(IntVal, APFloat::rmTowardZero, &IsExact);
271
272 // N.b. isPowerOf2 also checks for > 0.
273 if (!IsExact || !IntVal.isPowerOf2())
274 return 0;
275 unsigned FBits = IntVal.logBase2();
276
277 // Checks above should have guaranteed that we haven't lost information in
278 // finding FBits, but it must still be in range.
279 if (FBits == 0 || FBits > RegWidth)
280 return 0;
281 return FBits;
282}
283
284namespace AArch64CC {
285
286// The CondCodes constants map directly to the 4-bit encoding of the condition
287// field for predicated instructions.
288enum CondCode { // Meaning (integer) Meaning (floating-point)
289 EQ = 0x0, // Equal Equal
290 NE = 0x1, // Not equal Not equal, or unordered
291 HS = 0x2, // Unsigned higher or same >, ==, or unordered
292 LO = 0x3, // Unsigned lower Less than
293 MI = 0x4, // Minus, negative Less than
294 PL = 0x5, // Plus, positive or zero >, ==, or unordered
295 VS = 0x6, // Overflow Unordered
296 VC = 0x7, // No overflow Not unordered
297 HI = 0x8, // Unsigned higher Greater than, or unordered
298 LS = 0x9, // Unsigned lower or same Less than or equal
299 GE = 0xa, // Greater than or equal Greater than or equal
300 LT = 0xb, // Less than Less than, or unordered
301 GT = 0xc, // Greater than Greater than
302 LE = 0xd, // Less than or equal <, ==, or unordered
303 AL = 0xe, // Always (unconditional) Always (unconditional)
304 NV = 0xf, // Always (unconditional) Always (unconditional)
305 // Note the NV exists purely to disassemble 0b1111. Execution is "always".
307
308 // Common aliases used for SVE.
309 ANY_ACTIVE = NE, // (!Z)
310 FIRST_ACTIVE = MI, // ( N)
311 LAST_ACTIVE = LO, // (!C)
312 NONE_ACTIVE = EQ // ( Z)
313};
314
315inline static const char *getCondCodeName(CondCode Code) {
316 switch (Code) {
317 default: llvm_unreachable("Unknown condition code");
318 case EQ: return "eq";
319 case NE: return "ne";
320 case HS: return "hs";
321 case LO: return "lo";
322 case MI: return "mi";
323 case PL: return "pl";
324 case VS: return "vs";
325 case VC: return "vc";
326 case HI: return "hi";
327 case LS: return "ls";
328 case GE: return "ge";
329 case LT: return "lt";
330 case GT: return "gt";
331 case LE: return "le";
332 case AL: return "al";
333 case NV: return "nv";
334 }
335}
336
338 // To reverse a condition it's necessary to only invert the low bit:
339
340 return static_cast<CondCode>(static_cast<unsigned>(Code) ^ 0x1);
341}
342
343/// getSwappedCondition - assume the flags are set by MI(a,b), return
344/// the condition code if we modify the instructions such that flags are
345/// set by MI(b,a).
347 switch (CC) {
348 default:
349 return AL;
350 case EQ:
351 return EQ;
352 case NE:
353 return NE;
354 case HS:
355 return LS;
356 case LO:
357 return HI;
358 case HI:
359 return LO;
360 case LS:
361 return HS;
362 case GE:
363 return LE;
364 case LT:
365 return GT;
366 case GT:
367 return LT;
368 case LE:
369 return GE;
370 }
371}
372
373/// Given a condition code, return NZCV flags that would satisfy that condition.
374/// The flag bits are in the format expected by the ccmp instructions.
375/// Note that many different flag settings can satisfy a given condition code,
376/// this function just returns one of them.
377inline static unsigned getNZCVToSatisfyCondCode(CondCode Code) {
378 // NZCV flags encoded as expected by ccmp instructions, ARMv8 ISA 5.5.7.
379 enum { N = 8, Z = 4, C = 2, V = 1 };
380 switch (Code) {
381 default: llvm_unreachable("Unknown condition code");
382 case EQ: return Z; // Z == 1
383 case NE: return 0; // Z == 0
384 case HS: return C; // C == 1
385 case LO: return 0; // C == 0
386 case MI: return N; // N == 1
387 case PL: return 0; // N == 0
388 case VS: return V; // V == 1
389 case VC: return 0; // V == 0
390 case HI: return C; // C == 1 && Z == 0
391 case LS: return 0; // C == 0 || Z == 1
392 case GE: return 0; // N == V
393 case LT: return N; // N != V
394 case GT: return 0; // Z == 0 && N == V
395 case LE: return Z; // Z == 1 || N != V
396 }
397}
398
399/// True, if a given condition code can be used in a fused compare-and-branch
400/// instructions, false otherwise.
401inline static bool isValidCBCond(AArch64CC::CondCode Code) {
402 switch (Code) {
403 default:
404 return false;
405 case AArch64CC::EQ:
406 case AArch64CC::NE:
407 case AArch64CC::HS:
408 case AArch64CC::LO:
409 case AArch64CC::HI:
410 case AArch64CC::LS:
411 case AArch64CC::GE:
412 case AArch64CC::LT:
413 case AArch64CC::GT:
414 case AArch64CC::LE:
415 return true;
416 }
417}
418
419} // end namespace AArch64CC
420
421struct SysAlias {
422 const char *Name;
425
426 constexpr SysAlias(const char *N, uint16_t E) : Name(N), Encoding(E) {}
427 constexpr SysAlias(const char *N, uint16_t E, FeatureBitset F)
429
430 bool haveFeatures(FeatureBitset ActiveFeatures) const {
431 return ActiveFeatures[llvm::AArch64::FeatureAll] ||
432 (FeaturesRequired & ActiveFeatures) == FeaturesRequired;
433 }
434
436};
437
438#define GET_SysAliasRegUse_DECL
439#include "AArch64GenSystemOperands.inc"
440
443 constexpr SysAliasReg(const char *N, uint16_t E, bool R)
444 : SysAlias(N, E), NeedsReg(R) {}
445 constexpr SysAliasReg(const char *N, uint16_t E, bool R, FeatureBitset F)
446 : SysAlias(N, E, F), NeedsReg(R) {}
447};
448
450 SysAliasRegUse RegUse;
451 constexpr SysAliasOptionalReg(const char *N, uint16_t E, SysAliasRegUse R)
452 : SysAlias(N, E), RegUse(R) {}
453 constexpr SysAliasOptionalReg(const char *N, uint16_t E, SysAliasRegUse R,
455 : SysAlias(N, E, F), RegUse(R) {}
456};
457
460 constexpr SysAliasImm(const char *N, uint16_t E, uint16_t I)
461 : SysAlias(N, E), ImmValue(I) {}
462 constexpr SysAliasImm(const char *N, uint16_t E, uint16_t I, FeatureBitset F)
463 : SysAlias(N, E, F), ImmValue(I) {}
464};
465
466namespace AArch64SVCR {
467 struct SVCR : SysAlias{
468 using SysAlias::SysAlias;
469 };
470#define GET_SVCRValues_DECL
471#define GET_SVCRsList_DECL
472#include "AArch64GenSystemOperands.inc"
473}
474
475namespace AArch64AT{
476 struct AT : SysAlias {
477 using SysAlias::SysAlias;
478 };
479#define GET_ATValues_DECL
480#define GET_ATsList_DECL
481#include "AArch64GenSystemOperands.inc"
482}
483
484namespace AArch64DB {
485 struct DB : SysAlias {
486 using SysAlias::SysAlias;
487 };
488#define GET_DBValues_DECL
489#define GET_DBsList_DECL
490#include "AArch64GenSystemOperands.inc"
491}
492
493namespace AArch64DBnXS {
496 };
497#define GET_DBnXSValues_DECL
498#define GET_DBnXSsList_DECL
499#include "AArch64GenSystemOperands.inc"
500}
501
502namespace AArch64DC {
503 struct DC : SysAlias {
504 using SysAlias::SysAlias;
505 };
506#define GET_DCValues_DECL
507#define GET_DCsList_DECL
508#include "AArch64GenSystemOperands.inc"
509}
510
511namespace AArch64IC {
512 struct IC : SysAliasReg {
514 };
515#define GET_ICValues_DECL
516#define GET_ICsList_DECL
517#include "AArch64GenSystemOperands.inc"
518}
519
520namespace AArch64ISB {
521 struct ISB : SysAlias {
522 using SysAlias::SysAlias;
523 };
524#define GET_ISBValues_DECL
525#define GET_ISBsList_DECL
526#include "AArch64GenSystemOperands.inc"
527}
528
529namespace AArch64TSB {
530 struct TSB : SysAlias {
531 using SysAlias::SysAlias;
532 };
533#define GET_TSBValues_DECL
534#define GET_TSBsList_DECL
535#include "AArch64GenSystemOperands.inc"
536}
537
538namespace AArch64PRFM {
539 struct PRFM : SysAlias {
540 using SysAlias::SysAlias;
541 };
542#define GET_PRFMValues_DECL
543#define GET_PRFMsList_DECL
544#include "AArch64GenSystemOperands.inc"
545}
546
547namespace AArch64SVEPRFM {
548 struct SVEPRFM : SysAlias {
549 using SysAlias::SysAlias;
550 };
551#define GET_SVEPRFMValues_DECL
552#define GET_SVEPRFMsList_DECL
553#include "AArch64GenSystemOperands.inc"
554}
555
556namespace AArch64RPRFM {
557struct RPRFM : SysAlias {
558 using SysAlias::SysAlias;
559};
560#define GET_RPRFMValues_DECL
561#define GET_RPRFMsList_DECL
562#include "AArch64GenSystemOperands.inc"
563} // namespace AArch64RPRFM
564
565namespace AArch64SVEPredPattern {
566 struct SVEPREDPAT {
567 const char *Name;
569 };
570#define GET_SVEPREDPATValues_DECL
571#define GET_SVEPREDPATsList_DECL
572#include "AArch64GenSystemOperands.inc"
573}
574
577 const char *Name;
579 };
580#define GET_SVEVECLENSPECIFIERValues_DECL
581#define GET_SVEVECLENSPECIFIERsList_DECL
582#include "AArch64GenSystemOperands.inc"
583} // namespace AArch64SVEVecLenSpecifier
584
585/// Return the number of active elements for VL1 to VL256 predicate pattern,
586/// zero for all other patterns.
587inline unsigned getNumElementsFromSVEPredPattern(unsigned Pattern) {
588 switch (Pattern) {
589 default:
590 return 0;
591 case AArch64SVEPredPattern::vl1:
592 case AArch64SVEPredPattern::vl2:
593 case AArch64SVEPredPattern::vl3:
594 case AArch64SVEPredPattern::vl4:
595 case AArch64SVEPredPattern::vl5:
596 case AArch64SVEPredPattern::vl6:
597 case AArch64SVEPredPattern::vl7:
598 case AArch64SVEPredPattern::vl8:
599 return Pattern;
600 case AArch64SVEPredPattern::vl16:
601 return 16;
602 case AArch64SVEPredPattern::vl32:
603 return 32;
604 case AArch64SVEPredPattern::vl64:
605 return 64;
606 case AArch64SVEPredPattern::vl128:
607 return 128;
608 case AArch64SVEPredPattern::vl256:
609 return 256;
610 }
611}
612
613/// Return specific VL predicate pattern based on the number of elements.
614inline std::optional<unsigned>
616 switch (MinNumElts) {
617 default:
618 return std::nullopt;
619 case 1:
620 case 2:
621 case 3:
622 case 4:
623 case 5:
624 case 6:
625 case 7:
626 case 8:
627 return MinNumElts;
628 case 16:
629 return AArch64SVEPredPattern::vl16;
630 case 32:
631 return AArch64SVEPredPattern::vl32;
632 case 64:
633 return AArch64SVEPredPattern::vl64;
634 case 128:
635 return AArch64SVEPredPattern::vl128;
636 case 256:
637 return AArch64SVEPredPattern::vl256;
638 }
639}
640
641/// An enum to describe what types of loops we should attempt to tail-fold:
642/// Disabled: None
643/// Reductions: Loops containing reductions
644/// Recurrences: Loops with first-order recurrences, i.e. that would
645/// require a SVE splice instruction
646/// Reverse: Reverse loops
647/// Simple: Loops that are not reversed and don't contain reductions
648/// or first-order recurrences.
649/// All: All
658
660 /* LargestValue */ (long)TailFoldingOpts::Reverse);
661
662namespace AArch64ExactFPImm {
664 int Enum;
665 const char *Repr;
666};
667#define GET_ExactFPImmValues_DECL
668#define GET_ExactFPImmsList_DECL
669#include "AArch64GenSystemOperands.inc"
670}
671
672namespace AArch64PState {
674 using SysAlias::SysAlias;
675 };
676#define GET_PStateImm0_15Values_DECL
677#define GET_PStateImm0_15sList_DECL
678#include "AArch64GenSystemOperands.inc"
679
681 using SysAlias::SysAlias;
682 };
683#define GET_PStateImm0_1Values_DECL
684#define GET_PStateImm0_1sList_DECL
685#include "AArch64GenSystemOperands.inc"
686}
687
688namespace AArch64PSBHint {
689 struct PSB : SysAlias {
690 using SysAlias::SysAlias;
691 };
692#define GET_PSBValues_DECL
693#define GET_PSBsList_DECL
694#include "AArch64GenSystemOperands.inc"
695}
696
697namespace AArch64PHint {
698struct PHint {
699 const char *Name;
700 unsigned Encoding;
702
703 bool haveFeatures(FeatureBitset ActiveFeatures) const {
704 return ActiveFeatures[llvm::AArch64::FeatureAll] ||
705 (FeaturesRequired & ActiveFeatures) == FeaturesRequired;
706 }
707};
708
709#define GET_PHintValues_DECL
710#define GET_PHintsList_DECL
711#include "AArch64GenSystemOperands.inc"
712
715} // namespace AArch64PHint
716
717namespace AArch64BTIHint {
718 struct BTI : SysAlias {
719 using SysAlias::SysAlias;
720 };
721#define GET_BTIValues_DECL
722#define GET_BTIsList_DECL
723#include "AArch64GenSystemOperands.inc"
724}
725
726namespace AArch64CMHPriorityHint {
728 using SysAlias::SysAlias;
729};
730#define GET_CMHPRIORITYHINT_DECL
731#include "AArch64GenSystemOperands.inc"
732} // namespace AArch64CMHPriorityHint
733
734namespace AArch64TIndexHint {
735struct TIndex : SysAlias {
736 using SysAlias::SysAlias;
737};
738#define GET_TINDEX_DECL
739#include "AArch64GenSystemOperands.inc"
740} // namespace AArch64TIndexHint
741
749
770
771namespace AArch64Layout {
778
783
784 // Bare layout for the 128-bit vector
785 // (only show ".b", ".h", ".s", ".d" without vector number)
790 };
791}
792
793inline static const char *
795 switch (Layout) {
796 case AArch64Layout::VL_8B: return ".8b";
797 case AArch64Layout::VL_4H: return ".4h";
798 case AArch64Layout::VL_2S: return ".2s";
799 case AArch64Layout::VL_1D: return ".1d";
800 case AArch64Layout::VL_16B: return ".16b";
801 case AArch64Layout::VL_8H: return ".8h";
802 case AArch64Layout::VL_4S: return ".4s";
803 case AArch64Layout::VL_2D: return ".2d";
804 case AArch64Layout::VL_B: return ".b";
805 case AArch64Layout::VL_H: return ".h";
806 case AArch64Layout::VL_S: return ".s";
807 case AArch64Layout::VL_D: return ".d";
808 default: llvm_unreachable("Unknown Vector Layout");
809 }
810}
811
812inline static AArch64Layout::VectorLayout
829
830namespace AArch64SysReg {
831 struct SysReg {
832 const char Name[32];
833 unsigned Encoding;
837
838 bool haveFeatures(FeatureBitset ActiveFeatures) const {
839 return ActiveFeatures[llvm::AArch64::FeatureAll] ||
840 (FeaturesRequired & ActiveFeatures) == FeaturesRequired;
841 }
842 };
843
844#define GET_SysRegsList_DECL
845#define GET_SysRegValues_DECL
846#include "AArch64GenSystemOperands.inc"
847
848 uint32_t parseGenericRegister(StringRef Name);
849 std::string genericRegisterString(uint32_t Bits);
850}
851
852namespace AArch64TLBI {
856#define GET_TLBITable_DECL
857#include "AArch64GenSystemOperands.inc"
858}
859
860namespace AArch64TLBIP {
864#define GET_TLBIPTable_DECL
865#include "AArch64GenSystemOperands.inc"
866} // namespace AArch64TLBIP
867
868namespace AArch64MLBI {
871};
872#define GET_MLBITable_DECL
873#include "AArch64GenSystemOperands.inc"
874} // namespace AArch64MLBI
875
876namespace AArch64GIC {
877struct GIC : SysAliasReg {
879};
880#define GET_GICTable_DECL
881#include "AArch64GenSystemOperands.inc"
882} // namespace AArch64GIC
883
884namespace AArch64GICR {
887};
888#define GET_GICRTable_DECL
889#include "AArch64GenSystemOperands.inc"
890} // namespace AArch64GICR
891
892namespace AArch64GSB {
893struct GSB : SysAlias {
894 using SysAlias::SysAlias;
895};
896#define GET_GSBTable_DECL
897#include "AArch64GenSystemOperands.inc"
898} // namespace AArch64GSB
899
900namespace AArch64PLBI {
904#define GET_PLBITable_DECL
905#include "AArch64GenSystemOperands.inc"
906} // namespace AArch64PLBI
907
908namespace AArch64II {
909/// Target Operand Flag enum.
910enum TOF {
911 //===------------------------------------------------------------------===//
912 // AArch64 Specific MachineOperand flags.
913
915
917
918 /// MO_PAGE - A symbol operand with this flag represents the pc-relative
919 /// offset of the 4K page containing the symbol. This is used with the
920 /// ADRP instruction.
922
923 /// MO_PAGEOFF - A symbol operand with this flag represents the offset of
924 /// that symbol within a 4K page. This offset is added to the page address
925 /// to produce the complete address.
927
928 /// MO_G3 - A symbol operand with this flag (granule 3) represents the high
929 /// 16-bits of a 64-bit address, used in a MOVZ or MOVK instruction
930 MO_G3 = 3,
931
932 /// MO_G2 - A symbol operand with this flag (granule 2) represents the bits
933 /// 32-47 of a 64-bit address, used in a MOVZ or MOVK instruction
934 MO_G2 = 4,
935
936 /// MO_G1 - A symbol operand with this flag (granule 1) represents the bits
937 /// 16-31 of a 64-bit address, used in a MOVZ or MOVK instruction
938 MO_G1 = 5,
939
940 /// MO_G0 - A symbol operand with this flag (granule 0) represents the bits
941 /// 0-15 of a 64-bit address, used in a MOVZ or MOVK instruction
942 MO_G0 = 6,
943
944 /// MO_HI12 - This flag indicates that a symbol operand represents the bits
945 /// 13-24 of a 64-bit address, used in a arithmetic immediate-shifted-left-
946 /// by-12-bits instruction.
948
949 /// MO_COFFSTUB - On a symbol operand "FOO", this indicates that the
950 /// reference is actually to the ".refptr.FOO" symbol. This is used for
951 /// stub symbols on windows.
953
954 /// MO_GOT - This flag indicates that a symbol operand represents the
955 /// address of the GOT entry for the symbol, rather than the address of
956 /// the symbol itself.
957 MO_GOT = 0x10,
958
959 /// MO_NC - Indicates whether the linker is expected to check the symbol
960 /// reference for overflow. For example in an ADRP/ADD pair of relocations
961 /// the ADRP usually does check, but not the ADD.
962 MO_NC = 0x20,
963
964 /// MO_TLS - Indicates that the operand being accessed is some kind of
965 /// thread-local symbol. On Darwin, only one type of thread-local access
966 /// exists (pre linker-relaxation), but on ELF the TLSModel used for the
967 /// referee will affect interpretation.
968 MO_TLS = 0x40,
969
970 /// MO_DLLIMPORT - On a symbol operand, this represents that the reference
971 /// to the symbol is for an import stub. This is used for DLL import
972 /// storage class indication on Windows.
974
975 /// MO_S - Indicates that the bits of the symbol operand represented by
976 /// MO_G0 etc are signed.
977 MO_S = 0x100,
978
979 /// MO_PREL - Indicates that the bits of the symbol operand represented by
980 /// MO_G0 etc are PC relative.
981 MO_PREL = 0x200,
982
983 /// MO_TAGGED - With MO_PAGE, indicates that the page includes a memory tag
984 /// in bits 56-63.
985 /// On a FrameIndex operand, indicates that the underlying memory is tagged
986 /// with an unknown tag value (MTE); this needs to be lowered either to an
987 /// SP-relative load or store instruction (which do not check tags), or to
988 /// an LDG instruction to obtain the tag value.
989 MO_TAGGED = 0x400,
990
991 /// MO_ARM64EC_CALLMANGLE - Operand refers to the Arm64EC-mangled version
992 /// of a symbol, not the original. For dllimport symbols, this means it
993 /// uses "__imp_aux". For other symbols, this means it uses the mangled
994 /// ("#" prefix for C) name.
996};
997} // end namespace AArch64II
998
999//===----------------------------------------------------------------------===//
1000// v8.3a Pointer Authentication
1001//
1002
1003namespace AArch64PACKey {
1004enum ID : uint8_t {
1005 IA = 0,
1006 IB = 1,
1007 DA = 2,
1008 DB = 3,
1010};
1011} // namespace AArch64PACKey
1012
1013/// Return 2-letter identifier string for numeric key ID.
1015 switch (KeyID) {
1016 case AArch64PACKey::IA:
1017 return StringRef("ia");
1018 case AArch64PACKey::IB:
1019 return StringRef("ib");
1020 case AArch64PACKey::DA:
1021 return StringRef("da");
1022 case AArch64PACKey::DB:
1023 return StringRef("db");
1024 }
1025 llvm_unreachable("Unhandled AArch64PACKey::ID enum");
1026}
1027
1028/// Return numeric key ID for 2-letter identifier string.
1029inline static std::optional<AArch64PACKey::ID>
1031 if (Name == "ia")
1032 return AArch64PACKey::IA;
1033 if (Name == "ib")
1034 return AArch64PACKey::IB;
1035 if (Name == "da")
1036 return AArch64PACKey::DA;
1037 if (Name == "db")
1038 return AArch64PACKey::DB;
1039 return std::nullopt;
1040}
1041
1042inline static unsigned getBTIHintNum(bool CallTarget, bool JumpTarget) {
1043 unsigned HintNum = 32;
1044 if (CallTarget)
1045 HintNum |= 2;
1046 if (JumpTarget)
1047 HintNum |= 4;
1048 assert(HintNum != 32 && "No target kinds!");
1049 return HintNum;
1050}
1051
1052namespace AArch64 {
1053// The number of bits in a SVE register is architecturally defined
1054// to be a multiple of this value. If <M x t> has this number of bits,
1055// a <n x M x t> vector can be stored in a SVE register without any
1056// redundant bits. If <M x t> has this number of bits divided by P,
1057// a <n x M x t> vector is stored in a SVE register by placing index i
1058// in index i*P of a <n x (M*P) x t> vector. The other elements of the
1059// <n x (M*P) x t> vector (such as index 1) are undefined.
1060static constexpr unsigned SVEBitsPerBlock = 128;
1061static constexpr unsigned SVEMaxBitsPerVector = 2048;
1062} // end namespace AArch64
1063} // end namespace llvm
1064
1065#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...
#define LLVM_DECLARE_ENUM_AS_BITMASK(Enum, LargestValue)
LLVM_DECLARE_ENUM_AS_BITMASK can be used to declare an enum type as a bit set, so that bitwise operat...
Definition BitmaskEnum.h:66
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
This file contains some templates that are useful if you are working with the STL at all.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
static constexpr roundingMode rmTowardZero
Definition APFloat.h:348
LLVM_ABI bool getExactInverse(APFloat *Inv) const
If this value is normal and has an exact, normal, multiplicative inverse, store it in inv and return ...
Definition APFloat.cpp:5832
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
Definition APFloat.h:1387
An arbitrary precision integer that knows its signedness.
Definition APSInt.h:24
Container class for subtarget features.
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
constexpr unsigned id() const
Definition MCRegister.h:82
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static bool isValidCBCond(AArch64CC::CondCode Code)
True, if a given condition code can be used in a fused compare-and-branch instructions,...
static CondCode getSwappedCondition(CondCode CC)
getSwappedCondition - assume the flags are set by MI(a,b), return the condition code if we modify the...
static const char * getCondCodeName(CondCode Code)
static CondCode getInvertedCondCode(CondCode Code)
static unsigned getNZCVToSatisfyCondCode(CondCode Code)
Given a condition code, return NZCV flags that would satisfy that condition.
TOF
Target Operand Flag enum.
@ MO_DLLIMPORT
MO_DLLIMPORT - On a symbol operand, this represents that the reference to the symbol is for an import...
@ MO_NC
MO_NC - Indicates whether the linker is expected to check the symbol reference for overflow.
@ MO_G1
MO_G1 - A symbol operand with this flag (granule 1) represents the bits 16-31 of a 64-bit address,...
@ MO_S
MO_S - Indicates that the bits of the symbol operand represented by MO_G0 etc are signed.
@ MO_PAGEOFF
MO_PAGEOFF - A symbol operand with this flag represents the offset of that symbol within a 4K page.
@ MO_GOT
MO_GOT - This flag indicates that a symbol operand represents the address of the GOT entry for the sy...
@ MO_PREL
MO_PREL - Indicates that the bits of the symbol operand represented by MO_G0 etc are PC relative.
@ MO_G0
MO_G0 - A symbol operand with this flag (granule 0) represents the bits 0-15 of a 64-bit address,...
@ MO_ARM64EC_CALLMANGLE
MO_ARM64EC_CALLMANGLE - Operand refers to the Arm64EC-mangled version of a symbol,...
@ MO_PAGE
MO_PAGE - A symbol operand with this flag represents the pc-relative offset of the 4K page containing...
@ MO_HI12
MO_HI12 - This flag indicates that a symbol operand represents the bits 13-24 of a 64-bit address,...
@ MO_TLS
MO_TLS - Indicates that the operand being accessed is some kind of thread-local symbol.
@ MO_G2
MO_G2 - A symbol operand with this flag (granule 2) represents the bits 32-47 of a 64-bit address,...
@ MO_TAGGED
MO_TAGGED - With MO_PAGE, indicates that the page includes a memory tag in bits 56-63.
@ MO_G3
MO_G3 - A symbol operand with this flag (granule 3) represents the high 16-bits of a 64-bit address,...
@ MO_COFFSTUB
MO_COFFSTUB - On a symbol operand "FOO", this indicates that the reference is actually to the "....
const PHint * lookupPHintByName(StringRef)
const PHint * lookupPHintByEncoding(uint16_t)
uint32_t parseGenericRegister(StringRef Name)
std::string genericRegisterString(uint32_t Bits)
static constexpr unsigned SVEMaxBitsPerVector
static constexpr unsigned SVEBitsPerBlock
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
static std::optional< AArch64PACKey::ID > AArch64StringToPACKeyID(StringRef Name)
Return numeric key ID for 2-letter identifier string.
TailFoldingOpts
An enum to describe what types of loops we should attempt to tail-fold: Disabled: None Reductions: Lo...
static unsigned getBTIHintNum(bool CallTarget, bool JumpTarget)
unsigned CheckFixedPointOperandConstant(APFloat &FVal, unsigned RegWidth, bool isReciprocal)
static AArch64Layout::VectorLayout AArch64StringToVectorLayout(StringRef LayoutStr)
static const char * AArch64VectorLayoutToString(AArch64Layout::VectorLayout Layout)
std::optional< unsigned > getSVEPredPatternFromNumElements(unsigned MinNumElts)
Return specific VL predicate pattern based on the number of elements.
static bool atomicBarrierDroppedOnZero(unsigned Opcode)
static MCRegister getXRegFromWReg(MCRegister Reg)
static MCRegister getXRegFromXRegTuple(MCRegister RegTuple)
static MCRegister getWRegFromXReg(MCRegister Reg)
unsigned getNumElementsFromSVEPredPattern(unsigned Pattern)
Return the number of active elements for VL1 to VL256 predicate pattern, zero for all other patterns.
static MCRegister getDRegFromBReg(MCRegister Reg)
@ Disabled
Don't do any conversion of .debug_str_offsets tables.
Definition DWP.h:26
static MCRegister getBRegFromDReg(MCRegister Reg)
static StringRef AArch64PACKeyIDToString(AArch64PACKey::ID KeyID)
Return 2-letter identifier string for numeric key ID.
#define N
constexpr SysAlias(const char *N, uint16_t E)
constexpr SysAlias(const char *N, uint16_t E)
constexpr SysAlias(const char *N, uint16_t E)
constexpr SysAlias(const char *N, uint16_t E)
constexpr SysAliasImm(const char *N, uint16_t E, uint16_t I)
constexpr SysAlias(const char *N, uint16_t E)
constexpr SysAliasReg(const char *N, uint16_t E, bool R)
constexpr SysAliasReg(const char *N, uint16_t E, bool R)
constexpr SysAlias(const char *N, uint16_t E)
constexpr SysAliasReg(const char *N, uint16_t E, bool R)
constexpr SysAlias(const char *N, uint16_t E)
constexpr SysAliasReg(const char *N, uint16_t E, bool R)
bool haveFeatures(FeatureBitset ActiveFeatures) const
constexpr SysAliasOptionalReg(const char *N, uint16_t E, SysAliasRegUse R)
constexpr SysAlias(const char *N, uint16_t E)
constexpr SysAlias(const char *N, uint16_t E)
constexpr SysAlias(const char *N, uint16_t E)
constexpr SysAlias(const char *N, uint16_t E)
constexpr SysAlias(const char *N, uint16_t E)
constexpr SysAlias(const char *N, uint16_t E)
constexpr SysAlias(const char *N, uint16_t E)
bool haveFeatures(FeatureBitset ActiveFeatures) const
constexpr SysAlias(const char *N, uint16_t E)
constexpr SysAliasOptionalReg(const char *N, uint16_t E, SysAliasRegUse R)
constexpr SysAliasOptionalReg(const char *N, uint16_t E, SysAliasRegUse R)
constexpr SysAlias(const char *N, uint16_t E)
constexpr SysAliasImm(const char *N, uint16_t E, uint16_t I)
constexpr SysAliasImm(const char *N, uint16_t E, uint16_t I, FeatureBitset F)
constexpr SysAliasOptionalReg(const char *N, uint16_t E, SysAliasRegUse R, FeatureBitset F)
constexpr SysAliasOptionalReg(const char *N, uint16_t E, SysAliasRegUse R)
constexpr SysAliasReg(const char *N, uint16_t E, bool R, FeatureBitset F)
constexpr SysAliasReg(const char *N, uint16_t E, bool R)
bool haveFeatures(FeatureBitset ActiveFeatures) const
constexpr SysAlias(const char *N, uint16_t E)
FeatureBitset getRequiredFeatures() const
const char * Name
FeatureBitset FeaturesRequired
constexpr SysAlias(const char *N, uint16_t E, FeatureBitset F)