AArch64BaseInfo.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  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. #ifndef LLVM_LIB_TARGET_AARCH64_UTILS_AARCH64BASEINFO_H
  16. #define LLVM_LIB_TARGET_AARCH64_UTILS_AARCH64BASEINFO_H
  17. // FIXME: Is it easiest to fix this layering violation by moving the .inc
  18. // #includes from AArch64MCTargetDesc.h to here?
  19. #include "MCTargetDesc/AArch64MCTargetDesc.h" // For AArch64::X0 and friends.
  20. #include "llvm/ADT/STLExtras.h"
  21. #include "llvm/ADT/StringSwitch.h"
  22. #include "llvm/MC/SubtargetFeature.h"
  23. #include "llvm/Support/ErrorHandling.h"
  24. namespace llvm {
  25. inline static unsigned getWRegFromXReg(unsigned Reg) {
  26. switch (Reg) {
  27. case AArch64::X0: return AArch64::W0;
  28. case AArch64::X1: return AArch64::W1;
  29. case AArch64::X2: return AArch64::W2;
  30. case AArch64::X3: return AArch64::W3;
  31. case AArch64::X4: return AArch64::W4;
  32. case AArch64::X5: return AArch64::W5;
  33. case AArch64::X6: return AArch64::W6;
  34. case AArch64::X7: return AArch64::W7;
  35. case AArch64::X8: return AArch64::W8;
  36. case AArch64::X9: return AArch64::W9;
  37. case AArch64::X10: return AArch64::W10;
  38. case AArch64::X11: return AArch64::W11;
  39. case AArch64::X12: return AArch64::W12;
  40. case AArch64::X13: return AArch64::W13;
  41. case AArch64::X14: return AArch64::W14;
  42. case AArch64::X15: return AArch64::W15;
  43. case AArch64::X16: return AArch64::W16;
  44. case AArch64::X17: return AArch64::W17;
  45. case AArch64::X18: return AArch64::W18;
  46. case AArch64::X19: return AArch64::W19;
  47. case AArch64::X20: return AArch64::W20;
  48. case AArch64::X21: return AArch64::W21;
  49. case AArch64::X22: return AArch64::W22;
  50. case AArch64::X23: return AArch64::W23;
  51. case AArch64::X24: return AArch64::W24;
  52. case AArch64::X25: return AArch64::W25;
  53. case AArch64::X26: return AArch64::W26;
  54. case AArch64::X27: return AArch64::W27;
  55. case AArch64::X28: return AArch64::W28;
  56. case AArch64::FP: return AArch64::W29;
  57. case AArch64::LR: return AArch64::W30;
  58. case AArch64::SP: return AArch64::WSP;
  59. case AArch64::XZR: return AArch64::WZR;
  60. }
  61. // For anything else, return it unchanged.
  62. return Reg;
  63. }
  64. inline static unsigned getXRegFromWReg(unsigned Reg) {
  65. switch (Reg) {
  66. case AArch64::W0: return AArch64::X0;
  67. case AArch64::W1: return AArch64::X1;
  68. case AArch64::W2: return AArch64::X2;
  69. case AArch64::W3: return AArch64::X3;
  70. case AArch64::W4: return AArch64::X4;
  71. case AArch64::W5: return AArch64::X5;
  72. case AArch64::W6: return AArch64::X6;
  73. case AArch64::W7: return AArch64::X7;
  74. case AArch64::W8: return AArch64::X8;
  75. case AArch64::W9: return AArch64::X9;
  76. case AArch64::W10: return AArch64::X10;
  77. case AArch64::W11: return AArch64::X11;
  78. case AArch64::W12: return AArch64::X12;
  79. case AArch64::W13: return AArch64::X13;
  80. case AArch64::W14: return AArch64::X14;
  81. case AArch64::W15: return AArch64::X15;
  82. case AArch64::W16: return AArch64::X16;
  83. case AArch64::W17: return AArch64::X17;
  84. case AArch64::W18: return AArch64::X18;
  85. case AArch64::W19: return AArch64::X19;
  86. case AArch64::W20: return AArch64::X20;
  87. case AArch64::W21: return AArch64::X21;
  88. case AArch64::W22: return AArch64::X22;
  89. case AArch64::W23: return AArch64::X23;
  90. case AArch64::W24: return AArch64::X24;
  91. case AArch64::W25: return AArch64::X25;
  92. case AArch64::W26: return AArch64::X26;
  93. case AArch64::W27: return AArch64::X27;
  94. case AArch64::W28: return AArch64::X28;
  95. case AArch64::W29: return AArch64::FP;
  96. case AArch64::W30: return AArch64::LR;
  97. case AArch64::WSP: return AArch64::SP;
  98. case AArch64::WZR: return AArch64::XZR;
  99. }
  100. // For anything else, return it unchanged.
  101. return Reg;
  102. }
  103. inline static unsigned getXRegFromXRegTuple(unsigned RegTuple) {
  104. switch (RegTuple) {
  105. case AArch64::X0_X1_X2_X3_X4_X5_X6_X7: return AArch64::X0;
  106. case AArch64::X2_X3_X4_X5_X6_X7_X8_X9: return AArch64::X2;
  107. case AArch64::X4_X5_X6_X7_X8_X9_X10_X11: return AArch64::X4;
  108. case AArch64::X6_X7_X8_X9_X10_X11_X12_X13: return AArch64::X6;
  109. case AArch64::X8_X9_X10_X11_X12_X13_X14_X15: return AArch64::X8;
  110. case AArch64::X10_X11_X12_X13_X14_X15_X16_X17: return AArch64::X10;
  111. case AArch64::X12_X13_X14_X15_X16_X17_X18_X19: return AArch64::X12;
  112. case AArch64::X14_X15_X16_X17_X18_X19_X20_X21: return AArch64::X14;
  113. case AArch64::X16_X17_X18_X19_X20_X21_X22_X23: return AArch64::X16;
  114. case AArch64::X18_X19_X20_X21_X22_X23_X24_X25: return AArch64::X18;
  115. case AArch64::X20_X21_X22_X23_X24_X25_X26_X27: return AArch64::X20;
  116. case AArch64::X22_X23_X24_X25_X26_X27_X28_FP: return AArch64::X22;
  117. }
  118. // For anything else, return it unchanged.
  119. return RegTuple;
  120. }
  121. static inline unsigned getBRegFromDReg(unsigned Reg) {
  122. switch (Reg) {
  123. case AArch64::D0: return AArch64::B0;
  124. case AArch64::D1: return AArch64::B1;
  125. case AArch64::D2: return AArch64::B2;
  126. case AArch64::D3: return AArch64::B3;
  127. case AArch64::D4: return AArch64::B4;
  128. case AArch64::D5: return AArch64::B5;
  129. case AArch64::D6: return AArch64::B6;
  130. case AArch64::D7: return AArch64::B7;
  131. case AArch64::D8: return AArch64::B8;
  132. case AArch64::D9: return AArch64::B9;
  133. case AArch64::D10: return AArch64::B10;
  134. case AArch64::D11: return AArch64::B11;
  135. case AArch64::D12: return AArch64::B12;
  136. case AArch64::D13: return AArch64::B13;
  137. case AArch64::D14: return AArch64::B14;
  138. case AArch64::D15: return AArch64::B15;
  139. case AArch64::D16: return AArch64::B16;
  140. case AArch64::D17: return AArch64::B17;
  141. case AArch64::D18: return AArch64::B18;
  142. case AArch64::D19: return AArch64::B19;
  143. case AArch64::D20: return AArch64::B20;
  144. case AArch64::D21: return AArch64::B21;
  145. case AArch64::D22: return AArch64::B22;
  146. case AArch64::D23: return AArch64::B23;
  147. case AArch64::D24: return AArch64::B24;
  148. case AArch64::D25: return AArch64::B25;
  149. case AArch64::D26: return AArch64::B26;
  150. case AArch64::D27: return AArch64::B27;
  151. case AArch64::D28: return AArch64::B28;
  152. case AArch64::D29: return AArch64::B29;
  153. case AArch64::D30: return AArch64::B30;
  154. case AArch64::D31: return AArch64::B31;
  155. }
  156. // For anything else, return it unchanged.
  157. return Reg;
  158. }
  159. static inline unsigned getDRegFromBReg(unsigned Reg) {
  160. switch (Reg) {
  161. case AArch64::B0: return AArch64::D0;
  162. case AArch64::B1: return AArch64::D1;
  163. case AArch64::B2: return AArch64::D2;
  164. case AArch64::B3: return AArch64::D3;
  165. case AArch64::B4: return AArch64::D4;
  166. case AArch64::B5: return AArch64::D5;
  167. case AArch64::B6: return AArch64::D6;
  168. case AArch64::B7: return AArch64::D7;
  169. case AArch64::B8: return AArch64::D8;
  170. case AArch64::B9: return AArch64::D9;
  171. case AArch64::B10: return AArch64::D10;
  172. case AArch64::B11: return AArch64::D11;
  173. case AArch64::B12: return AArch64::D12;
  174. case AArch64::B13: return AArch64::D13;
  175. case AArch64::B14: return AArch64::D14;
  176. case AArch64::B15: return AArch64::D15;
  177. case AArch64::B16: return AArch64::D16;
  178. case AArch64::B17: return AArch64::D17;
  179. case AArch64::B18: return AArch64::D18;
  180. case AArch64::B19: return AArch64::D19;
  181. case AArch64::B20: return AArch64::D20;
  182. case AArch64::B21: return AArch64::D21;
  183. case AArch64::B22: return AArch64::D22;
  184. case AArch64::B23: return AArch64::D23;
  185. case AArch64::B24: return AArch64::D24;
  186. case AArch64::B25: return AArch64::D25;
  187. case AArch64::B26: return AArch64::D26;
  188. case AArch64::B27: return AArch64::D27;
  189. case AArch64::B28: return AArch64::D28;
  190. case AArch64::B29: return AArch64::D29;
  191. case AArch64::B30: return AArch64::D30;
  192. case AArch64::B31: return AArch64::D31;
  193. }
  194. // For anything else, return it unchanged.
  195. return Reg;
  196. }
  197. static inline bool atomicBarrierDroppedOnZero(unsigned Opcode) {
  198. switch (Opcode) {
  199. case AArch64::LDADDAB: case AArch64::LDADDAH:
  200. case AArch64::LDADDAW: case AArch64::LDADDAX:
  201. case AArch64::LDADDALB: case AArch64::LDADDALH:
  202. case AArch64::LDADDALW: case AArch64::LDADDALX:
  203. case AArch64::LDCLRAB: case AArch64::LDCLRAH:
  204. case AArch64::LDCLRAW: case AArch64::LDCLRAX:
  205. case AArch64::LDCLRALB: case AArch64::LDCLRALH:
  206. case AArch64::LDCLRALW: case AArch64::LDCLRALX:
  207. case AArch64::LDEORAB: case AArch64::LDEORAH:
  208. case AArch64::LDEORAW: case AArch64::LDEORAX:
  209. case AArch64::LDEORALB: case AArch64::LDEORALH:
  210. case AArch64::LDEORALW: case AArch64::LDEORALX:
  211. case AArch64::LDSETAB: case AArch64::LDSETAH:
  212. case AArch64::LDSETAW: case AArch64::LDSETAX:
  213. case AArch64::LDSETALB: case AArch64::LDSETALH:
  214. case AArch64::LDSETALW: case AArch64::LDSETALX:
  215. case AArch64::LDSMAXAB: case AArch64::LDSMAXAH:
  216. case AArch64::LDSMAXAW: case AArch64::LDSMAXAX:
  217. case AArch64::LDSMAXALB: case AArch64::LDSMAXALH:
  218. case AArch64::LDSMAXALW: case AArch64::LDSMAXALX:
  219. case AArch64::LDSMINAB: case AArch64::LDSMINAH:
  220. case AArch64::LDSMINAW: case AArch64::LDSMINAX:
  221. case AArch64::LDSMINALB: case AArch64::LDSMINALH:
  222. case AArch64::LDSMINALW: case AArch64::LDSMINALX:
  223. case AArch64::LDUMAXAB: case AArch64::LDUMAXAH:
  224. case AArch64::LDUMAXAW: case AArch64::LDUMAXAX:
  225. case AArch64::LDUMAXALB: case AArch64::LDUMAXALH:
  226. case AArch64::LDUMAXALW: case AArch64::LDUMAXALX:
  227. case AArch64::LDUMINAB: case AArch64::LDUMINAH:
  228. case AArch64::LDUMINAW: case AArch64::LDUMINAX:
  229. case AArch64::LDUMINALB: case AArch64::LDUMINALH:
  230. case AArch64::LDUMINALW: case AArch64::LDUMINALX:
  231. case AArch64::SWPAB: case AArch64::SWPAH:
  232. case AArch64::SWPAW: case AArch64::SWPAX:
  233. case AArch64::SWPALB: case AArch64::SWPALH:
  234. case AArch64::SWPALW: case AArch64::SWPALX:
  235. return true;
  236. }
  237. return false;
  238. }
  239. namespace AArch64CC {
  240. // The CondCodes constants map directly to the 4-bit encoding of the condition
  241. // field for predicated instructions.
  242. enum CondCode { // Meaning (integer) Meaning (floating-point)
  243. EQ = 0x0, // Equal Equal
  244. NE = 0x1, // Not equal Not equal, or unordered
  245. HS = 0x2, // Unsigned higher or same >, ==, or unordered
  246. LO = 0x3, // Unsigned lower Less than
  247. MI = 0x4, // Minus, negative Less than
  248. PL = 0x5, // Plus, positive or zero >, ==, or unordered
  249. VS = 0x6, // Overflow Unordered
  250. VC = 0x7, // No overflow Not unordered
  251. HI = 0x8, // Unsigned higher Greater than, or unordered
  252. LS = 0x9, // Unsigned lower or same Less than or equal
  253. GE = 0xa, // Greater than or equal Greater than or equal
  254. LT = 0xb, // Less than Less than, or unordered
  255. GT = 0xc, // Greater than Greater than
  256. LE = 0xd, // Less than or equal <, ==, or unordered
  257. AL = 0xe, // Always (unconditional) Always (unconditional)
  258. NV = 0xf, // Always (unconditional) Always (unconditional)
  259. // Note the NV exists purely to disassemble 0b1111. Execution is "always".
  260. Invalid,
  261. // Common aliases used for SVE.
  262. ANY_ACTIVE = NE, // (!Z)
  263. FIRST_ACTIVE = MI, // ( N)
  264. LAST_ACTIVE = LO, // (!C)
  265. NONE_ACTIVE = EQ // ( Z)
  266. };
  267. inline static const char *getCondCodeName(CondCode Code) {
  268. switch (Code) {
  269. default: llvm_unreachable("Unknown condition code");
  270. case EQ: return "eq";
  271. case NE: return "ne";
  272. case HS: return "hs";
  273. case LO: return "lo";
  274. case MI: return "mi";
  275. case PL: return "pl";
  276. case VS: return "vs";
  277. case VC: return "vc";
  278. case HI: return "hi";
  279. case LS: return "ls";
  280. case GE: return "ge";
  281. case LT: return "lt";
  282. case GT: return "gt";
  283. case LE: return "le";
  284. case AL: return "al";
  285. case NV: return "nv";
  286. }
  287. }
  288. inline static CondCode getInvertedCondCode(CondCode Code) {
  289. // To reverse a condition it's necessary to only invert the low bit:
  290. return static_cast<CondCode>(static_cast<unsigned>(Code) ^ 0x1);
  291. }
  292. /// Given a condition code, return NZCV flags that would satisfy that condition.
  293. /// The flag bits are in the format expected by the ccmp instructions.
  294. /// Note that many different flag settings can satisfy a given condition code,
  295. /// this function just returns one of them.
  296. inline static unsigned getNZCVToSatisfyCondCode(CondCode Code) {
  297. // NZCV flags encoded as expected by ccmp instructions, ARMv8 ISA 5.5.7.
  298. enum { N = 8, Z = 4, C = 2, V = 1 };
  299. switch (Code) {
  300. default: llvm_unreachable("Unknown condition code");
  301. case EQ: return Z; // Z == 1
  302. case NE: return 0; // Z == 0
  303. case HS: return C; // C == 1
  304. case LO: return 0; // C == 0
  305. case MI: return N; // N == 1
  306. case PL: return 0; // N == 0
  307. case VS: return V; // V == 1
  308. case VC: return 0; // V == 0
  309. case HI: return C; // C == 1 && Z == 0
  310. case LS: return 0; // C == 0 || Z == 1
  311. case GE: return 0; // N == V
  312. case LT: return N; // N != V
  313. case GT: return 0; // Z == 0 && N == V
  314. case LE: return Z; // Z == 1 || N != V
  315. }
  316. }
  317. } // end namespace AArch64CC
  318. struct SysAlias {
  319. const char *Name;
  320. uint16_t Encoding;
  321. FeatureBitset FeaturesRequired;
  322. constexpr SysAlias(const char *N, uint16_t E) : Name(N), Encoding(E) {}
  323. constexpr SysAlias(const char *N, uint16_t E, FeatureBitset F)
  324. : Name(N), Encoding(E), FeaturesRequired(F) {}
  325. bool haveFeatures(FeatureBitset ActiveFeatures) const {
  326. return (FeaturesRequired & ActiveFeatures) == FeaturesRequired;
  327. }
  328. FeatureBitset getRequiredFeatures() const { return FeaturesRequired; }
  329. };
  330. struct SysAliasReg : SysAlias {
  331. bool NeedsReg;
  332. constexpr SysAliasReg(const char *N, uint16_t E, bool R)
  333. : SysAlias(N, E), NeedsReg(R) {}
  334. constexpr SysAliasReg(const char *N, uint16_t E, bool R, FeatureBitset F)
  335. : SysAlias(N, E, F), NeedsReg(R) {}
  336. };
  337. struct SysAliasImm : SysAlias {
  338. uint16_t ImmValue;
  339. constexpr SysAliasImm(const char *N, uint16_t E, uint16_t I)
  340. : SysAlias(N, E), ImmValue(I) {}
  341. constexpr SysAliasImm(const char *N, uint16_t E, uint16_t I, FeatureBitset F)
  342. : SysAlias(N, E, F), ImmValue(I) {}
  343. };
  344. namespace AArch64SVCR {
  345. struct SVCR : SysAlias{
  346. using SysAlias::SysAlias;
  347. };
  348. #define GET_SVCR_DECL
  349. #include "AArch64GenSystemOperands.inc"
  350. }
  351. namespace AArch64AT{
  352. struct AT : SysAlias {
  353. using SysAlias::SysAlias;
  354. };
  355. #define GET_AT_DECL
  356. #include "AArch64GenSystemOperands.inc"
  357. }
  358. namespace AArch64DB {
  359. struct DB : SysAlias {
  360. using SysAlias::SysAlias;
  361. };
  362. #define GET_DB_DECL
  363. #include "AArch64GenSystemOperands.inc"
  364. }
  365. namespace AArch64DBnXS {
  366. struct DBnXS : SysAliasImm {
  367. using SysAliasImm::SysAliasImm;
  368. };
  369. #define GET_DBNXS_DECL
  370. #include "AArch64GenSystemOperands.inc"
  371. }
  372. namespace AArch64DC {
  373. struct DC : SysAlias {
  374. using SysAlias::SysAlias;
  375. };
  376. #define GET_DC_DECL
  377. #include "AArch64GenSystemOperands.inc"
  378. }
  379. namespace AArch64IC {
  380. struct IC : SysAliasReg {
  381. using SysAliasReg::SysAliasReg;
  382. };
  383. #define GET_IC_DECL
  384. #include "AArch64GenSystemOperands.inc"
  385. }
  386. namespace AArch64ISB {
  387. struct ISB : SysAlias {
  388. using SysAlias::SysAlias;
  389. };
  390. #define GET_ISB_DECL
  391. #include "AArch64GenSystemOperands.inc"
  392. }
  393. namespace AArch64TSB {
  394. struct TSB : SysAlias {
  395. using SysAlias::SysAlias;
  396. };
  397. #define GET_TSB_DECL
  398. #include "AArch64GenSystemOperands.inc"
  399. }
  400. namespace AArch64PRFM {
  401. struct PRFM : SysAlias {
  402. using SysAlias::SysAlias;
  403. };
  404. #define GET_PRFM_DECL
  405. #include "AArch64GenSystemOperands.inc"
  406. }
  407. namespace AArch64SVEPRFM {
  408. struct SVEPRFM : SysAlias {
  409. using SysAlias::SysAlias;
  410. };
  411. #define GET_SVEPRFM_DECL
  412. #include "AArch64GenSystemOperands.inc"
  413. }
  414. namespace AArch64SVEPredPattern {
  415. struct SVEPREDPAT {
  416. const char *Name;
  417. uint16_t Encoding;
  418. };
  419. #define GET_SVEPREDPAT_DECL
  420. #include "AArch64GenSystemOperands.inc"
  421. }
  422. /// Return the number of active elements for VL1 to VL256 predicate pattern,
  423. /// zero for all other patterns.
  424. inline unsigned getNumElementsFromSVEPredPattern(unsigned Pattern) {
  425. switch (Pattern) {
  426. default:
  427. return 0;
  428. case AArch64SVEPredPattern::vl1:
  429. case AArch64SVEPredPattern::vl2:
  430. case AArch64SVEPredPattern::vl3:
  431. case AArch64SVEPredPattern::vl4:
  432. case AArch64SVEPredPattern::vl5:
  433. case AArch64SVEPredPattern::vl6:
  434. case AArch64SVEPredPattern::vl7:
  435. case AArch64SVEPredPattern::vl8:
  436. return Pattern;
  437. case AArch64SVEPredPattern::vl16:
  438. return 16;
  439. case AArch64SVEPredPattern::vl32:
  440. return 32;
  441. case AArch64SVEPredPattern::vl64:
  442. return 64;
  443. case AArch64SVEPredPattern::vl128:
  444. return 128;
  445. case AArch64SVEPredPattern::vl256:
  446. return 256;
  447. }
  448. }
  449. /// Return specific VL predicate pattern based on the number of elements.
  450. inline Optional<unsigned>
  451. getSVEPredPatternFromNumElements(unsigned MinNumElts) {
  452. switch (MinNumElts) {
  453. default:
  454. return None;
  455. case 1:
  456. case 2:
  457. case 3:
  458. case 4:
  459. case 5:
  460. case 6:
  461. case 7:
  462. case 8:
  463. return MinNumElts;
  464. case 16:
  465. return AArch64SVEPredPattern::vl16;
  466. case 32:
  467. return AArch64SVEPredPattern::vl32;
  468. case 64:
  469. return AArch64SVEPredPattern::vl64;
  470. case 128:
  471. return AArch64SVEPredPattern::vl128;
  472. case 256:
  473. return AArch64SVEPredPattern::vl256;
  474. }
  475. }
  476. namespace AArch64ExactFPImm {
  477. struct ExactFPImm {
  478. const char *Name;
  479. int Enum;
  480. const char *Repr;
  481. };
  482. #define GET_EXACTFPIMM_DECL
  483. #include "AArch64GenSystemOperands.inc"
  484. }
  485. namespace AArch64PState {
  486. struct PState : SysAlias{
  487. using SysAlias::SysAlias;
  488. };
  489. #define GET_PSTATE_DECL
  490. #include "AArch64GenSystemOperands.inc"
  491. }
  492. namespace AArch64PSBHint {
  493. struct PSB : SysAlias {
  494. using SysAlias::SysAlias;
  495. };
  496. #define GET_PSB_DECL
  497. #include "AArch64GenSystemOperands.inc"
  498. }
  499. namespace AArch64BTIHint {
  500. struct BTI : SysAlias {
  501. using SysAlias::SysAlias;
  502. };
  503. #define GET_BTI_DECL
  504. #include "AArch64GenSystemOperands.inc"
  505. }
  506. namespace AArch64SE {
  507. enum ShiftExtSpecifiers {
  508. Invalid = -1,
  509. LSL,
  510. MSL,
  511. LSR,
  512. ASR,
  513. ROR,
  514. UXTB,
  515. UXTH,
  516. UXTW,
  517. UXTX,
  518. SXTB,
  519. SXTH,
  520. SXTW,
  521. SXTX
  522. };
  523. }
  524. namespace AArch64Layout {
  525. enum VectorLayout {
  526. Invalid = -1,
  527. VL_8B,
  528. VL_4H,
  529. VL_2S,
  530. VL_1D,
  531. VL_16B,
  532. VL_8H,
  533. VL_4S,
  534. VL_2D,
  535. // Bare layout for the 128-bit vector
  536. // (only show ".b", ".h", ".s", ".d" without vector number)
  537. VL_B,
  538. VL_H,
  539. VL_S,
  540. VL_D
  541. };
  542. }
  543. inline static const char *
  544. AArch64VectorLayoutToString(AArch64Layout::VectorLayout Layout) {
  545. switch (Layout) {
  546. case AArch64Layout::VL_8B: return ".8b";
  547. case AArch64Layout::VL_4H: return ".4h";
  548. case AArch64Layout::VL_2S: return ".2s";
  549. case AArch64Layout::VL_1D: return ".1d";
  550. case AArch64Layout::VL_16B: return ".16b";
  551. case AArch64Layout::VL_8H: return ".8h";
  552. case AArch64Layout::VL_4S: return ".4s";
  553. case AArch64Layout::VL_2D: return ".2d";
  554. case AArch64Layout::VL_B: return ".b";
  555. case AArch64Layout::VL_H: return ".h";
  556. case AArch64Layout::VL_S: return ".s";
  557. case AArch64Layout::VL_D: return ".d";
  558. default: llvm_unreachable("Unknown Vector Layout");
  559. }
  560. }
  561. inline static AArch64Layout::VectorLayout
  562. AArch64StringToVectorLayout(StringRef LayoutStr) {
  563. return StringSwitch<AArch64Layout::VectorLayout>(LayoutStr)
  564. .Case(".8b", AArch64Layout::VL_8B)
  565. .Case(".4h", AArch64Layout::VL_4H)
  566. .Case(".2s", AArch64Layout::VL_2S)
  567. .Case(".1d", AArch64Layout::VL_1D)
  568. .Case(".16b", AArch64Layout::VL_16B)
  569. .Case(".8h", AArch64Layout::VL_8H)
  570. .Case(".4s", AArch64Layout::VL_4S)
  571. .Case(".2d", AArch64Layout::VL_2D)
  572. .Case(".b", AArch64Layout::VL_B)
  573. .Case(".h", AArch64Layout::VL_H)
  574. .Case(".s", AArch64Layout::VL_S)
  575. .Case(".d", AArch64Layout::VL_D)
  576. .Default(AArch64Layout::Invalid);
  577. }
  578. namespace AArch64SysReg {
  579. struct SysReg {
  580. const char *Name;
  581. const char *AltName;
  582. unsigned Encoding;
  583. bool Readable;
  584. bool Writeable;
  585. FeatureBitset FeaturesRequired;
  586. bool haveFeatures(FeatureBitset ActiveFeatures) const {
  587. return (FeaturesRequired & ActiveFeatures) == FeaturesRequired;
  588. }
  589. };
  590. #define GET_SYSREG_DECL
  591. #include "AArch64GenSystemOperands.inc"
  592. const SysReg *lookupSysRegByName(StringRef);
  593. const SysReg *lookupSysRegByEncoding(uint16_t);
  594. uint32_t parseGenericRegister(StringRef Name);
  595. std::string genericRegisterString(uint32_t Bits);
  596. }
  597. namespace AArch64TLBI {
  598. struct TLBI : SysAliasReg {
  599. using SysAliasReg::SysAliasReg;
  600. };
  601. #define GET_TLBITable_DECL
  602. #include "AArch64GenSystemOperands.inc"
  603. }
  604. namespace AArch64PRCTX {
  605. struct PRCTX : SysAliasReg {
  606. using SysAliasReg::SysAliasReg;
  607. };
  608. #define GET_PRCTX_DECL
  609. #include "AArch64GenSystemOperands.inc"
  610. }
  611. namespace AArch64II {
  612. /// Target Operand Flag enum.
  613. enum TOF {
  614. //===------------------------------------------------------------------===//
  615. // AArch64 Specific MachineOperand flags.
  616. MO_NO_FLAG,
  617. MO_FRAGMENT = 0x7,
  618. /// MO_PAGE - A symbol operand with this flag represents the pc-relative
  619. /// offset of the 4K page containing the symbol. This is used with the
  620. /// ADRP instruction.
  621. MO_PAGE = 1,
  622. /// MO_PAGEOFF - A symbol operand with this flag represents the offset of
  623. /// that symbol within a 4K page. This offset is added to the page address
  624. /// to produce the complete address.
  625. MO_PAGEOFF = 2,
  626. /// MO_G3 - A symbol operand with this flag (granule 3) represents the high
  627. /// 16-bits of a 64-bit address, used in a MOVZ or MOVK instruction
  628. MO_G3 = 3,
  629. /// MO_G2 - A symbol operand with this flag (granule 2) represents the bits
  630. /// 32-47 of a 64-bit address, used in a MOVZ or MOVK instruction
  631. MO_G2 = 4,
  632. /// MO_G1 - A symbol operand with this flag (granule 1) represents the bits
  633. /// 16-31 of a 64-bit address, used in a MOVZ or MOVK instruction
  634. MO_G1 = 5,
  635. /// MO_G0 - A symbol operand with this flag (granule 0) represents the bits
  636. /// 0-15 of a 64-bit address, used in a MOVZ or MOVK instruction
  637. MO_G0 = 6,
  638. /// MO_HI12 - This flag indicates that a symbol operand represents the bits
  639. /// 13-24 of a 64-bit address, used in a arithmetic immediate-shifted-left-
  640. /// by-12-bits instruction.
  641. MO_HI12 = 7,
  642. /// MO_COFFSTUB - On a symbol operand "FOO", this indicates that the
  643. /// reference is actually to the ".refptr.FOO" symbol. This is used for
  644. /// stub symbols on windows.
  645. MO_COFFSTUB = 0x8,
  646. /// MO_GOT - This flag indicates that a symbol operand represents the
  647. /// address of the GOT entry for the symbol, rather than the address of
  648. /// the symbol itself.
  649. MO_GOT = 0x10,
  650. /// MO_NC - Indicates whether the linker is expected to check the symbol
  651. /// reference for overflow. For example in an ADRP/ADD pair of relocations
  652. /// the ADRP usually does check, but not the ADD.
  653. MO_NC = 0x20,
  654. /// MO_TLS - Indicates that the operand being accessed is some kind of
  655. /// thread-local symbol. On Darwin, only one type of thread-local access
  656. /// exists (pre linker-relaxation), but on ELF the TLSModel used for the
  657. /// referee will affect interpretation.
  658. MO_TLS = 0x40,
  659. /// MO_DLLIMPORT - On a symbol operand, this represents that the reference
  660. /// to the symbol is for an import stub. This is used for DLL import
  661. /// storage class indication on Windows.
  662. MO_DLLIMPORT = 0x80,
  663. /// MO_S - Indicates that the bits of the symbol operand represented by
  664. /// MO_G0 etc are signed.
  665. MO_S = 0x100,
  666. /// MO_PREL - Indicates that the bits of the symbol operand represented by
  667. /// MO_G0 etc are PC relative.
  668. MO_PREL = 0x200,
  669. /// MO_TAGGED - With MO_PAGE, indicates that the page includes a memory tag
  670. /// in bits 56-63.
  671. /// On a FrameIndex operand, indicates that the underlying memory is tagged
  672. /// with an unknown tag value (MTE); this needs to be lowered either to an
  673. /// SP-relative load or store instruction (which do not check tags), or to
  674. /// an LDG instruction to obtain the tag value.
  675. MO_TAGGED = 0x400,
  676. };
  677. } // end namespace AArch64II
  678. namespace AArch64 {
  679. // The number of bits in a SVE register is architecturally defined
  680. // to be a multiple of this value. If <M x t> has this number of bits,
  681. // a <n x M x t> vector can be stored in a SVE register without any
  682. // redundant bits. If <M x t> has this number of bits divided by P,
  683. // a <n x M x t> vector is stored in a SVE register by placing index i
  684. // in index i*P of a <n x (M*P) x t> vector. The other elements of the
  685. // <n x (M*P) x t> vector (such as index 1) are undefined.
  686. static constexpr unsigned SVEBitsPerBlock = 128;
  687. static constexpr unsigned SVEMaxBitsPerVector = 2048;
  688. } // end namespace AArch64
  689. } // end namespace llvm
  690. #endif