LoongArchRegisterInfo.td 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //===-- LoongArchRegisterInfo.td - LoongArch Register defs -*- tablegen -*-===//
  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. // Declarations that describe the LoongArch register files
  10. //===----------------------------------------------------------------------===//
  11. let Namespace = "LoongArch" in {
  12. class LoongArchReg<bits<16> Enc, string n, list<string> alt = []>
  13. : Register<n> {
  14. let HWEncoding = Enc;
  15. let AltNames = alt;
  16. }
  17. class LoongArchReg32<bits<16> Enc, string n, list<string> alt = []>
  18. : Register<n> {
  19. let HWEncoding = Enc;
  20. let AltNames = alt;
  21. }
  22. def sub_32 : SubRegIndex<32>;
  23. class LoongArchReg64<LoongArchReg32 subreg>
  24. : Register<""> {
  25. let HWEncoding = subreg.HWEncoding;
  26. let SubRegs = [subreg];
  27. let SubRegIndices = [sub_32];
  28. let AsmName = subreg.AsmName;
  29. let AltNames = subreg.AltNames;
  30. }
  31. let FallbackRegAltNameIndex = NoRegAltName in
  32. def RegAliasName : RegAltNameIndex;
  33. } // Namespace = "LoongArch"
  34. // Integer registers
  35. let RegAltNameIndices = [RegAliasName] in {
  36. let isConstant = true in
  37. def R0 : LoongArchReg<0, "r0", ["zero"]>, DwarfRegNum<[0]>;
  38. def R1 : LoongArchReg<1, "r1", ["ra"]>, DwarfRegNum<[1]>;
  39. def R2 : LoongArchReg<2, "r2", ["tp"]>, DwarfRegNum<[2]>;
  40. def R3 : LoongArchReg<3, "r3", ["sp"]>, DwarfRegNum<[3]>;
  41. def R4 : LoongArchReg<4, "r4", ["a0"]>, DwarfRegNum<[4]>;
  42. def R5 : LoongArchReg<5, "r5", ["a1"]>, DwarfRegNum<[5]>;
  43. def R6 : LoongArchReg<6, "r6", ["a2"]>, DwarfRegNum<[6]>;
  44. def R7 : LoongArchReg<7, "r7", ["a3"]>, DwarfRegNum<[7]>;
  45. def R8 : LoongArchReg<8, "r8", ["a4"]>, DwarfRegNum<[8]>;
  46. def R9 : LoongArchReg<9, "r9", ["a5"]>, DwarfRegNum<[9]>;
  47. def R10 : LoongArchReg<10, "r10", ["a6"]>, DwarfRegNum<[10]>;
  48. def R11 : LoongArchReg<11, "r11", ["a7"]>, DwarfRegNum<[11]>;
  49. def R12 : LoongArchReg<12, "r12", ["t0"]>, DwarfRegNum<[12]>;
  50. def R13 : LoongArchReg<13, "r13", ["t1"]>, DwarfRegNum<[13]>;
  51. def R14 : LoongArchReg<14, "r14", ["t2"]>, DwarfRegNum<[14]>;
  52. def R15 : LoongArchReg<15, "r15", ["t3"]>, DwarfRegNum<[15]>;
  53. def R16 : LoongArchReg<16, "r16", ["t4"]>, DwarfRegNum<[16]>;
  54. def R17 : LoongArchReg<17, "r17", ["t5"]>, DwarfRegNum<[17]>;
  55. def R18 : LoongArchReg<18, "r18", ["t6"]>, DwarfRegNum<[18]>;
  56. def R19 : LoongArchReg<19, "r19", ["t7"]>, DwarfRegNum<[19]>;
  57. def R20 : LoongArchReg<20, "r20", ["t8"]>, DwarfRegNum<[20]>;
  58. def R21 : LoongArchReg<21, "r21", [""]>, DwarfRegNum<[21]>;
  59. def R22 : LoongArchReg<22, "r22", ["fp", "s9"]>, DwarfRegNum<[22]>;
  60. def R23 : LoongArchReg<23, "r23", ["s0"]>, DwarfRegNum<[23]>;
  61. def R24 : LoongArchReg<24, "r24", ["s1"]>, DwarfRegNum<[24]>;
  62. def R25 : LoongArchReg<25, "r25", ["s2"]>, DwarfRegNum<[25]>;
  63. def R26 : LoongArchReg<26, "r26", ["s3"]>, DwarfRegNum<[26]>;
  64. def R27 : LoongArchReg<27, "r27", ["s4"]>, DwarfRegNum<[27]>;
  65. def R28 : LoongArchReg<28, "r28", ["s5"]>, DwarfRegNum<[28]>;
  66. def R29 : LoongArchReg<29, "r29", ["s6"]>, DwarfRegNum<[29]>;
  67. def R30 : LoongArchReg<30, "r30", ["s7"]>, DwarfRegNum<[30]>;
  68. def R31 : LoongArchReg<31, "r31", ["s8"]>, DwarfRegNum<[31]>;
  69. } // RegAltNameIndices = [RegAliasName]
  70. def GRLenVT : ValueTypeByHwMode<[LA32, LA64],
  71. [i32, i64]>;
  72. def GRLenRI : RegInfoByHwMode<
  73. [LA32, LA64],
  74. [RegInfo<32,32,32>, RegInfo<64,64,64>]>;
  75. // The order of registers represents the preferred allocation sequence.
  76. // Registers are listed in the order caller-save, callee-save, specials.
  77. def GPR : RegisterClass<"LoongArch", [GRLenVT], 32, (add
  78. // Argument registers (a0...a7)
  79. (sequence "R%u", 4, 11),
  80. // Temporary registers (t0...t8)
  81. (sequence "R%u", 12, 20),
  82. // Static register (s9/fp, s0...s8)
  83. (sequence "R%u", 22, 31),
  84. // Specials (r0, ra, tp, sp)
  85. (sequence "R%u", 0, 3),
  86. // Reserved (Non-allocatable)
  87. R21
  88. )> {
  89. let RegInfos = GRLenRI;
  90. }
  91. // GPR for indirect tail calls. We can't use callee-saved registers, as they are
  92. // restored to the saved value before the tail call, which would clobber a call
  93. // address.
  94. def GPRT : RegisterClass<"LoongArch", [GRLenVT], 32, (add
  95. // a0...a7, t0...t8
  96. (sequence "R%u", 4, 20)
  97. )> {
  98. let RegInfos = GRLenRI;
  99. }
  100. // Floating point registers
  101. let RegAltNameIndices = [RegAliasName] in {
  102. def F0 : LoongArchReg32<0, "f0", ["fa0"]>, DwarfRegNum<[32]>;
  103. def F1 : LoongArchReg32<1, "f1", ["fa1"]>, DwarfRegNum<[33]>;
  104. def F2 : LoongArchReg32<2, "f2", ["fa2"]>, DwarfRegNum<[34]>;
  105. def F3 : LoongArchReg32<3, "f3", ["fa3"]>, DwarfRegNum<[35]>;
  106. def F4 : LoongArchReg32<4, "f4", ["fa4"]>, DwarfRegNum<[36]>;
  107. def F5 : LoongArchReg32<5, "f5", ["fa5"]>, DwarfRegNum<[37]>;
  108. def F6 : LoongArchReg32<6, "f6", ["fa6"]>, DwarfRegNum<[38]>;
  109. def F7 : LoongArchReg32<7, "f7", ["fa7"]>, DwarfRegNum<[39]>;
  110. def F8 : LoongArchReg32<8, "f8", ["ft0"]>, DwarfRegNum<[40]>;
  111. def F9 : LoongArchReg32<9, "f9", ["ft1"]>, DwarfRegNum<[41]>;
  112. def F10 : LoongArchReg32<10,"f10", ["ft2"]>, DwarfRegNum<[42]>;
  113. def F11 : LoongArchReg32<11,"f11", ["ft3"]>, DwarfRegNum<[43]>;
  114. def F12 : LoongArchReg32<12,"f12", ["ft4"]>, DwarfRegNum<[44]>;
  115. def F13 : LoongArchReg32<13,"f13", ["ft5"]>, DwarfRegNum<[45]>;
  116. def F14 : LoongArchReg32<14,"f14", ["ft6"]>, DwarfRegNum<[46]>;
  117. def F15 : LoongArchReg32<15,"f15", ["ft7"]>, DwarfRegNum<[47]>;
  118. def F16 : LoongArchReg32<16,"f16", ["ft8"]>, DwarfRegNum<[48]>;
  119. def F17 : LoongArchReg32<17,"f17", ["ft9"]>, DwarfRegNum<[49]>;
  120. def F18 : LoongArchReg32<18,"f18", ["ft10"]>, DwarfRegNum<[50]>;
  121. def F19 : LoongArchReg32<19,"f19", ["ft11"]>, DwarfRegNum<[51]>;
  122. def F20 : LoongArchReg32<20,"f20", ["ft12"]>, DwarfRegNum<[52]>;
  123. def F21 : LoongArchReg32<21,"f21", ["ft13"]>, DwarfRegNum<[53]>;
  124. def F22 : LoongArchReg32<22,"f22", ["ft14"]>, DwarfRegNum<[54]>;
  125. def F23 : LoongArchReg32<23,"f23", ["ft15"]>, DwarfRegNum<[55]>;
  126. def F24 : LoongArchReg32<24,"f24", ["fs0"]>, DwarfRegNum<[56]>;
  127. def F25 : LoongArchReg32<25,"f25", ["fs1"]>, DwarfRegNum<[57]>;
  128. def F26 : LoongArchReg32<26,"f26", ["fs2"]>, DwarfRegNum<[58]>;
  129. def F27 : LoongArchReg32<27,"f27", ["fs3"]>, DwarfRegNum<[59]>;
  130. def F28 : LoongArchReg32<28,"f28", ["fs4"]>, DwarfRegNum<[60]>;
  131. def F29 : LoongArchReg32<29,"f29", ["fs5"]>, DwarfRegNum<[61]>;
  132. def F30 : LoongArchReg32<30,"f30", ["fs6"]>, DwarfRegNum<[62]>;
  133. def F31 : LoongArchReg32<31,"f31", ["fs7"]>, DwarfRegNum<[63]>;
  134. foreach I = 0-31 in {
  135. def F#I#_64 : LoongArchReg64<!cast<LoongArchReg32>("F"#I)>,
  136. DwarfRegNum<[!add(I, 32)]>;
  137. }
  138. }
  139. // The order of registers represents the preferred allocation sequence.
  140. def FPR32 : RegisterClass<"LoongArch", [f32], 32, (sequence "F%u", 0, 31)>;
  141. def FPR64 : RegisterClass<"LoongArch", [f64], 64, (sequence "F%u_64", 0, 31)>;
  142. // Condition flag registers
  143. foreach I = 0-7 in
  144. def FCC#I : LoongArchReg<I, "fcc"#I>;
  145. def CFR : RegisterClass<"LoongArch", [GRLenVT], 32, (sequence "FCC%u", 0, 7)> {
  146. let RegInfos = GRLenRI;
  147. }
  148. // Control and status registers
  149. foreach I = 0-3 in
  150. def FCSR#I : LoongArchReg<I, "fcsr"#I>;
  151. let isAllocatable = false in
  152. def FCSR : RegisterClass<"LoongArch", [i32], 32, (sequence "FCSR%u", 0, 3)>;