AArch64BaseInfo.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //===-- AArch64BaseInfo.cpp - AArch64 Base encoding information------------===//
  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 provides basic encoding and assembly information for AArch64.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "AArch64BaseInfo.h"
  13. #include "llvm/ADT/ArrayRef.h"
  14. #include "llvm/ADT/SmallVector.h"
  15. #include "llvm/ADT/StringExtras.h"
  16. #include "llvm/Support/Regex.h"
  17. using namespace llvm;
  18. namespace llvm {
  19. namespace AArch64AT {
  20. #define GET_AT_IMPL
  21. #include "AArch64GenSystemOperands.inc"
  22. }
  23. }
  24. namespace llvm {
  25. namespace AArch64DBnXS {
  26. #define GET_DBNXS_IMPL
  27. #include "AArch64GenSystemOperands.inc"
  28. }
  29. }
  30. namespace llvm {
  31. namespace AArch64DB {
  32. #define GET_DB_IMPL
  33. #include "AArch64GenSystemOperands.inc"
  34. }
  35. }
  36. namespace llvm {
  37. namespace AArch64DC {
  38. #define GET_DC_IMPL
  39. #include "AArch64GenSystemOperands.inc"
  40. }
  41. }
  42. namespace llvm {
  43. namespace AArch64IC {
  44. #define GET_IC_IMPL
  45. #include "AArch64GenSystemOperands.inc"
  46. }
  47. }
  48. namespace llvm {
  49. namespace AArch64ISB {
  50. #define GET_ISB_IMPL
  51. #include "AArch64GenSystemOperands.inc"
  52. }
  53. }
  54. namespace llvm {
  55. namespace AArch64TSB {
  56. #define GET_TSB_IMPL
  57. #include "AArch64GenSystemOperands.inc"
  58. }
  59. }
  60. namespace llvm {
  61. namespace AArch64PRCTX {
  62. #define GET_PRCTX_IMPL
  63. #include "AArch64GenSystemOperands.inc"
  64. }
  65. }
  66. namespace llvm {
  67. namespace AArch64PRFM {
  68. #define GET_PRFM_IMPL
  69. #include "AArch64GenSystemOperands.inc"
  70. }
  71. }
  72. namespace llvm {
  73. namespace AArch64SVEPRFM {
  74. #define GET_SVEPRFM_IMPL
  75. #include "AArch64GenSystemOperands.inc"
  76. }
  77. }
  78. namespace llvm {
  79. namespace AArch64SVEPredPattern {
  80. #define GET_SVEPREDPAT_IMPL
  81. #include "AArch64GenSystemOperands.inc"
  82. }
  83. }
  84. namespace llvm {
  85. namespace AArch64ExactFPImm {
  86. #define GET_EXACTFPIMM_IMPL
  87. #include "AArch64GenSystemOperands.inc"
  88. }
  89. }
  90. namespace llvm {
  91. namespace AArch64PState {
  92. #define GET_PSTATE_IMPL
  93. #include "AArch64GenSystemOperands.inc"
  94. }
  95. }
  96. namespace llvm {
  97. namespace AArch64PSBHint {
  98. #define GET_PSB_IMPL
  99. #include "AArch64GenSystemOperands.inc"
  100. }
  101. }
  102. namespace llvm {
  103. namespace AArch64BTIHint {
  104. #define GET_BTI_IMPL
  105. #include "AArch64GenSystemOperands.inc"
  106. }
  107. }
  108. namespace llvm {
  109. namespace AArch64SysReg {
  110. #define GET_SYSREG_IMPL
  111. #include "AArch64GenSystemOperands.inc"
  112. }
  113. }
  114. uint32_t AArch64SysReg::parseGenericRegister(StringRef Name) {
  115. // Try to parse an S<op0>_<op1>_<Cn>_<Cm>_<op2> register name
  116. static const Regex GenericRegPattern("^S([0-3])_([0-7])_C([0-9]|1[0-5])_C([0-9]|1[0-5])_([0-7])$");
  117. std::string UpperName = Name.upper();
  118. SmallVector<StringRef, 5> Ops;
  119. if (!GenericRegPattern.match(UpperName, &Ops))
  120. return -1;
  121. uint32_t Op0 = 0, Op1 = 0, CRn = 0, CRm = 0, Op2 = 0;
  122. uint32_t Bits;
  123. Ops[1].getAsInteger(10, Op0);
  124. Ops[2].getAsInteger(10, Op1);
  125. Ops[3].getAsInteger(10, CRn);
  126. Ops[4].getAsInteger(10, CRm);
  127. Ops[5].getAsInteger(10, Op2);
  128. Bits = (Op0 << 14) | (Op1 << 11) | (CRn << 7) | (CRm << 3) | Op2;
  129. return Bits;
  130. }
  131. std::string AArch64SysReg::genericRegisterString(uint32_t Bits) {
  132. assert(Bits < 0x10000);
  133. uint32_t Op0 = (Bits >> 14) & 0x3;
  134. uint32_t Op1 = (Bits >> 11) & 0x7;
  135. uint32_t CRn = (Bits >> 7) & 0xf;
  136. uint32_t CRm = (Bits >> 3) & 0xf;
  137. uint32_t Op2 = Bits & 0x7;
  138. return "S" + utostr(Op0) + "_" + utostr(Op1) + "_C" + utostr(CRn) + "_C" +
  139. utostr(CRm) + "_" + utostr(Op2);
  140. }
  141. namespace llvm {
  142. namespace AArch64TLBI {
  143. #define GET_TLBITable_IMPL
  144. #include "AArch64GenSystemOperands.inc"
  145. }
  146. }
  147. namespace llvm {
  148. namespace AArch64SVCR {
  149. #define GET_SVCR_IMPL
  150. #include "AArch64GenSystemOperands.inc"
  151. }
  152. }