X86RegisterInfo.td 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. //===- X86RegisterInfo.td - Describe the X86 Register File --*- 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. // This file describes the X86 Register file, defining the registers themselves,
  10. // aliases between the registers, and the register classes built out of the
  11. // registers.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. class X86Reg<string n, bits<16> Enc, list<Register> subregs = []> : Register<n> {
  15. let Namespace = "X86";
  16. let HWEncoding = Enc;
  17. let SubRegs = subregs;
  18. }
  19. // Subregister indices.
  20. let Namespace = "X86" in {
  21. def sub_8bit : SubRegIndex<8>;
  22. def sub_8bit_hi : SubRegIndex<8, 8>;
  23. def sub_8bit_hi_phony : SubRegIndex<8, 8>;
  24. def sub_16bit : SubRegIndex<16>;
  25. def sub_16bit_hi : SubRegIndex<16, 16>;
  26. def sub_32bit : SubRegIndex<32>;
  27. def sub_xmm : SubRegIndex<128>;
  28. def sub_ymm : SubRegIndex<256>;
  29. def sub_mask_0 : SubRegIndex<-1>;
  30. def sub_mask_1 : SubRegIndex<-1, -1>;
  31. }
  32. //===----------------------------------------------------------------------===//
  33. // Register definitions...
  34. //
  35. // In the register alias definitions below, we define which registers alias
  36. // which others. We only specify which registers the small registers alias,
  37. // because the register file generator is smart enough to figure out that
  38. // AL aliases AX if we tell it that AX aliased AL (for example).
  39. // Dwarf numbering is different for 32-bit and 64-bit, and there are
  40. // variations by target as well. Currently the first entry is for X86-64,
  41. // second - for EH on X86-32/Darwin and third is 'generic' one (X86-32/Linux
  42. // and debug information on X86-32/Darwin)
  43. // 8-bit registers
  44. // Low registers
  45. def AL : X86Reg<"al", 0>;
  46. def DL : X86Reg<"dl", 2>;
  47. def CL : X86Reg<"cl", 1>;
  48. def BL : X86Reg<"bl", 3>;
  49. // High registers. On x86-64, these cannot be used in any instruction
  50. // with a REX prefix.
  51. def AH : X86Reg<"ah", 4>;
  52. def DH : X86Reg<"dh", 6>;
  53. def CH : X86Reg<"ch", 5>;
  54. def BH : X86Reg<"bh", 7>;
  55. // X86-64 only, requires REX.
  56. def SIL : X86Reg<"sil", 6>;
  57. def DIL : X86Reg<"dil", 7>;
  58. def BPL : X86Reg<"bpl", 5>;
  59. def SPL : X86Reg<"spl", 4>;
  60. def R8B : X86Reg<"r8b", 8>;
  61. def R9B : X86Reg<"r9b", 9>;
  62. def R10B : X86Reg<"r10b", 10>;
  63. def R11B : X86Reg<"r11b", 11>;
  64. def R12B : X86Reg<"r12b", 12>;
  65. def R13B : X86Reg<"r13b", 13>;
  66. def R14B : X86Reg<"r14b", 14>;
  67. def R15B : X86Reg<"r15b", 15>;
  68. let isArtificial = 1 in {
  69. // High byte of the low 16 bits of the super-register:
  70. def SIH : X86Reg<"", -1>;
  71. def DIH : X86Reg<"", -1>;
  72. def BPH : X86Reg<"", -1>;
  73. def SPH : X86Reg<"", -1>;
  74. def R8BH : X86Reg<"", -1>;
  75. def R9BH : X86Reg<"", -1>;
  76. def R10BH : X86Reg<"", -1>;
  77. def R11BH : X86Reg<"", -1>;
  78. def R12BH : X86Reg<"", -1>;
  79. def R13BH : X86Reg<"", -1>;
  80. def R14BH : X86Reg<"", -1>;
  81. def R15BH : X86Reg<"", -1>;
  82. // High word of the low 32 bits of the super-register:
  83. def HAX : X86Reg<"", -1>;
  84. def HDX : X86Reg<"", -1>;
  85. def HCX : X86Reg<"", -1>;
  86. def HBX : X86Reg<"", -1>;
  87. def HSI : X86Reg<"", -1>;
  88. def HDI : X86Reg<"", -1>;
  89. def HBP : X86Reg<"", -1>;
  90. def HSP : X86Reg<"", -1>;
  91. def HIP : X86Reg<"", -1>;
  92. def R8WH : X86Reg<"", -1>;
  93. def R9WH : X86Reg<"", -1>;
  94. def R10WH : X86Reg<"", -1>;
  95. def R11WH : X86Reg<"", -1>;
  96. def R12WH : X86Reg<"", -1>;
  97. def R13WH : X86Reg<"", -1>;
  98. def R14WH : X86Reg<"", -1>;
  99. def R15WH : X86Reg<"", -1>;
  100. }
  101. // 16-bit registers
  102. let SubRegIndices = [sub_8bit, sub_8bit_hi], CoveredBySubRegs = 1 in {
  103. def AX : X86Reg<"ax", 0, [AL,AH]>;
  104. def DX : X86Reg<"dx", 2, [DL,DH]>;
  105. def CX : X86Reg<"cx", 1, [CL,CH]>;
  106. def BX : X86Reg<"bx", 3, [BL,BH]>;
  107. }
  108. let SubRegIndices = [sub_8bit, sub_8bit_hi_phony], CoveredBySubRegs = 1 in {
  109. def SI : X86Reg<"si", 6, [SIL,SIH]>;
  110. def DI : X86Reg<"di", 7, [DIL,DIH]>;
  111. def BP : X86Reg<"bp", 5, [BPL,BPH]>;
  112. def SP : X86Reg<"sp", 4, [SPL,SPH]>;
  113. }
  114. def IP : X86Reg<"ip", 0>;
  115. // X86-64 only, requires REX.
  116. let SubRegIndices = [sub_8bit, sub_8bit_hi_phony], CoveredBySubRegs = 1 in {
  117. def R8W : X86Reg<"r8w", 8, [R8B,R8BH]>;
  118. def R9W : X86Reg<"r9w", 9, [R9B,R9BH]>;
  119. def R10W : X86Reg<"r10w", 10, [R10B,R10BH]>;
  120. def R11W : X86Reg<"r11w", 11, [R11B,R11BH]>;
  121. def R12W : X86Reg<"r12w", 12, [R12B,R12BH]>;
  122. def R13W : X86Reg<"r13w", 13, [R13B,R13BH]>;
  123. def R14W : X86Reg<"r14w", 14, [R14B,R14BH]>;
  124. def R15W : X86Reg<"r15w", 15, [R15B,R15BH]>;
  125. }
  126. // 32-bit registers
  127. let SubRegIndices = [sub_16bit, sub_16bit_hi], CoveredBySubRegs = 1 in {
  128. def EAX : X86Reg<"eax", 0, [AX, HAX]>, DwarfRegNum<[-2, 0, 0]>;
  129. def EDX : X86Reg<"edx", 2, [DX, HDX]>, DwarfRegNum<[-2, 2, 2]>;
  130. def ECX : X86Reg<"ecx", 1, [CX, HCX]>, DwarfRegNum<[-2, 1, 1]>;
  131. def EBX : X86Reg<"ebx", 3, [BX, HBX]>, DwarfRegNum<[-2, 3, 3]>;
  132. def ESI : X86Reg<"esi", 6, [SI, HSI]>, DwarfRegNum<[-2, 6, 6]>;
  133. def EDI : X86Reg<"edi", 7, [DI, HDI]>, DwarfRegNum<[-2, 7, 7]>;
  134. def EBP : X86Reg<"ebp", 5, [BP, HBP]>, DwarfRegNum<[-2, 4, 5]>;
  135. def ESP : X86Reg<"esp", 4, [SP, HSP]>, DwarfRegNum<[-2, 5, 4]>;
  136. def EIP : X86Reg<"eip", 0, [IP, HIP]>, DwarfRegNum<[-2, 8, 8]>;
  137. }
  138. // X86-64 only, requires REX
  139. let SubRegIndices = [sub_16bit, sub_16bit_hi], CoveredBySubRegs = 1 in {
  140. def R8D : X86Reg<"r8d", 8, [R8W,R8WH]>;
  141. def R9D : X86Reg<"r9d", 9, [R9W,R9WH]>;
  142. def R10D : X86Reg<"r10d", 10, [R10W,R10WH]>;
  143. def R11D : X86Reg<"r11d", 11, [R11W,R11WH]>;
  144. def R12D : X86Reg<"r12d", 12, [R12W,R12WH]>;
  145. def R13D : X86Reg<"r13d", 13, [R13W,R13WH]>;
  146. def R14D : X86Reg<"r14d", 14, [R14W,R14WH]>;
  147. def R15D : X86Reg<"r15d", 15, [R15W,R15WH]>;
  148. }
  149. // 64-bit registers, X86-64 only
  150. let SubRegIndices = [sub_32bit] in {
  151. def RAX : X86Reg<"rax", 0, [EAX]>, DwarfRegNum<[0, -2, -2]>;
  152. def RDX : X86Reg<"rdx", 2, [EDX]>, DwarfRegNum<[1, -2, -2]>;
  153. def RCX : X86Reg<"rcx", 1, [ECX]>, DwarfRegNum<[2, -2, -2]>;
  154. def RBX : X86Reg<"rbx", 3, [EBX]>, DwarfRegNum<[3, -2, -2]>;
  155. def RSI : X86Reg<"rsi", 6, [ESI]>, DwarfRegNum<[4, -2, -2]>;
  156. def RDI : X86Reg<"rdi", 7, [EDI]>, DwarfRegNum<[5, -2, -2]>;
  157. def RBP : X86Reg<"rbp", 5, [EBP]>, DwarfRegNum<[6, -2, -2]>;
  158. def RSP : X86Reg<"rsp", 4, [ESP]>, DwarfRegNum<[7, -2, -2]>;
  159. // These also require REX.
  160. def R8 : X86Reg<"r8", 8, [R8D]>, DwarfRegNum<[ 8, -2, -2]>;
  161. def R9 : X86Reg<"r9", 9, [R9D]>, DwarfRegNum<[ 9, -2, -2]>;
  162. def R10 : X86Reg<"r10", 10, [R10D]>, DwarfRegNum<[10, -2, -2]>;
  163. def R11 : X86Reg<"r11", 11, [R11D]>, DwarfRegNum<[11, -2, -2]>;
  164. def R12 : X86Reg<"r12", 12, [R12D]>, DwarfRegNum<[12, -2, -2]>;
  165. def R13 : X86Reg<"r13", 13, [R13D]>, DwarfRegNum<[13, -2, -2]>;
  166. def R14 : X86Reg<"r14", 14, [R14D]>, DwarfRegNum<[14, -2, -2]>;
  167. def R15 : X86Reg<"r15", 15, [R15D]>, DwarfRegNum<[15, -2, -2]>;
  168. def RIP : X86Reg<"rip", 0, [EIP]>, DwarfRegNum<[16, -2, -2]>;
  169. }
  170. // MMX Registers. These are actually aliased to ST0 .. ST7
  171. def MM0 : X86Reg<"mm0", 0>, DwarfRegNum<[41, 29, 29]>;
  172. def MM1 : X86Reg<"mm1", 1>, DwarfRegNum<[42, 30, 30]>;
  173. def MM2 : X86Reg<"mm2", 2>, DwarfRegNum<[43, 31, 31]>;
  174. def MM3 : X86Reg<"mm3", 3>, DwarfRegNum<[44, 32, 32]>;
  175. def MM4 : X86Reg<"mm4", 4>, DwarfRegNum<[45, 33, 33]>;
  176. def MM5 : X86Reg<"mm5", 5>, DwarfRegNum<[46, 34, 34]>;
  177. def MM6 : X86Reg<"mm6", 6>, DwarfRegNum<[47, 35, 35]>;
  178. def MM7 : X86Reg<"mm7", 7>, DwarfRegNum<[48, 36, 36]>;
  179. // Pseudo Floating Point registers
  180. def FP0 : X86Reg<"fp0", 0>;
  181. def FP1 : X86Reg<"fp1", 0>;
  182. def FP2 : X86Reg<"fp2", 0>;
  183. def FP3 : X86Reg<"fp3", 0>;
  184. def FP4 : X86Reg<"fp4", 0>;
  185. def FP5 : X86Reg<"fp5", 0>;
  186. def FP6 : X86Reg<"fp6", 0>;
  187. def FP7 : X86Reg<"fp7", 0>;
  188. // XMM Registers, used by the various SSE instruction set extensions.
  189. def XMM0: X86Reg<"xmm0", 0>, DwarfRegNum<[17, 21, 21]>;
  190. def XMM1: X86Reg<"xmm1", 1>, DwarfRegNum<[18, 22, 22]>;
  191. def XMM2: X86Reg<"xmm2", 2>, DwarfRegNum<[19, 23, 23]>;
  192. def XMM3: X86Reg<"xmm3", 3>, DwarfRegNum<[20, 24, 24]>;
  193. def XMM4: X86Reg<"xmm4", 4>, DwarfRegNum<[21, 25, 25]>;
  194. def XMM5: X86Reg<"xmm5", 5>, DwarfRegNum<[22, 26, 26]>;
  195. def XMM6: X86Reg<"xmm6", 6>, DwarfRegNum<[23, 27, 27]>;
  196. def XMM7: X86Reg<"xmm7", 7>, DwarfRegNum<[24, 28, 28]>;
  197. // X86-64 only
  198. def XMM8: X86Reg<"xmm8", 8>, DwarfRegNum<[25, -2, -2]>;
  199. def XMM9: X86Reg<"xmm9", 9>, DwarfRegNum<[26, -2, -2]>;
  200. def XMM10: X86Reg<"xmm10", 10>, DwarfRegNum<[27, -2, -2]>;
  201. def XMM11: X86Reg<"xmm11", 11>, DwarfRegNum<[28, -2, -2]>;
  202. def XMM12: X86Reg<"xmm12", 12>, DwarfRegNum<[29, -2, -2]>;
  203. def XMM13: X86Reg<"xmm13", 13>, DwarfRegNum<[30, -2, -2]>;
  204. def XMM14: X86Reg<"xmm14", 14>, DwarfRegNum<[31, -2, -2]>;
  205. def XMM15: X86Reg<"xmm15", 15>, DwarfRegNum<[32, -2, -2]>;
  206. def XMM16: X86Reg<"xmm16", 16>, DwarfRegNum<[67, -2, -2]>;
  207. def XMM17: X86Reg<"xmm17", 17>, DwarfRegNum<[68, -2, -2]>;
  208. def XMM18: X86Reg<"xmm18", 18>, DwarfRegNum<[69, -2, -2]>;
  209. def XMM19: X86Reg<"xmm19", 19>, DwarfRegNum<[70, -2, -2]>;
  210. def XMM20: X86Reg<"xmm20", 20>, DwarfRegNum<[71, -2, -2]>;
  211. def XMM21: X86Reg<"xmm21", 21>, DwarfRegNum<[72, -2, -2]>;
  212. def XMM22: X86Reg<"xmm22", 22>, DwarfRegNum<[73, -2, -2]>;
  213. def XMM23: X86Reg<"xmm23", 23>, DwarfRegNum<[74, -2, -2]>;
  214. def XMM24: X86Reg<"xmm24", 24>, DwarfRegNum<[75, -2, -2]>;
  215. def XMM25: X86Reg<"xmm25", 25>, DwarfRegNum<[76, -2, -2]>;
  216. def XMM26: X86Reg<"xmm26", 26>, DwarfRegNum<[77, -2, -2]>;
  217. def XMM27: X86Reg<"xmm27", 27>, DwarfRegNum<[78, -2, -2]>;
  218. def XMM28: X86Reg<"xmm28", 28>, DwarfRegNum<[79, -2, -2]>;
  219. def XMM29: X86Reg<"xmm29", 29>, DwarfRegNum<[80, -2, -2]>;
  220. def XMM30: X86Reg<"xmm30", 30>, DwarfRegNum<[81, -2, -2]>;
  221. def XMM31: X86Reg<"xmm31", 31>, DwarfRegNum<[82, -2, -2]>;
  222. // YMM0-15 registers, used by AVX instructions and
  223. // YMM16-31 registers, used by AVX-512 instructions.
  224. let SubRegIndices = [sub_xmm] in {
  225. foreach Index = 0-31 in {
  226. def YMM#Index : X86Reg<"ymm"#Index, Index, [!cast<X86Reg>("XMM"#Index)]>,
  227. DwarfRegAlias<!cast<X86Reg>("XMM"#Index)>;
  228. }
  229. }
  230. // ZMM Registers, used by AVX-512 instructions.
  231. let SubRegIndices = [sub_ymm] in {
  232. foreach Index = 0-31 in {
  233. def ZMM#Index : X86Reg<"zmm"#Index, Index, [!cast<X86Reg>("YMM"#Index)]>,
  234. DwarfRegAlias<!cast<X86Reg>("XMM"#Index)>;
  235. }
  236. }
  237. // Tile config registers.
  238. def TMMCFG: X86Reg<"tmmcfg", 0>;
  239. // Tile "registers".
  240. def TMM0: X86Reg<"tmm0", 0>;
  241. def TMM1: X86Reg<"tmm1", 1>;
  242. def TMM2: X86Reg<"tmm2", 2>;
  243. def TMM3: X86Reg<"tmm3", 3>;
  244. def TMM4: X86Reg<"tmm4", 4>;
  245. def TMM5: X86Reg<"tmm5", 5>;
  246. def TMM6: X86Reg<"tmm6", 6>;
  247. def TMM7: X86Reg<"tmm7", 7>;
  248. // Mask Registers, used by AVX-512 instructions.
  249. def K0 : X86Reg<"k0", 0>, DwarfRegNum<[118, 93, 93]>;
  250. def K1 : X86Reg<"k1", 1>, DwarfRegNum<[119, 94, 94]>;
  251. def K2 : X86Reg<"k2", 2>, DwarfRegNum<[120, 95, 95]>;
  252. def K3 : X86Reg<"k3", 3>, DwarfRegNum<[121, 96, 96]>;
  253. def K4 : X86Reg<"k4", 4>, DwarfRegNum<[122, 97, 97]>;
  254. def K5 : X86Reg<"k5", 5>, DwarfRegNum<[123, 98, 98]>;
  255. def K6 : X86Reg<"k6", 6>, DwarfRegNum<[124, 99, 99]>;
  256. def K7 : X86Reg<"k7", 7>, DwarfRegNum<[125, 100, 100]>;
  257. // Floating point stack registers. These don't map one-to-one to the FP
  258. // pseudo registers, but we still mark them as aliasing FP registers. That
  259. // way both kinds can be live without exceeding the stack depth. ST registers
  260. // are only live around inline assembly.
  261. def ST0 : X86Reg<"st", 0>, DwarfRegNum<[33, 12, 11]>;
  262. def ST1 : X86Reg<"st(1)", 1>, DwarfRegNum<[34, 13, 12]>;
  263. def ST2 : X86Reg<"st(2)", 2>, DwarfRegNum<[35, 14, 13]>;
  264. def ST3 : X86Reg<"st(3)", 3>, DwarfRegNum<[36, 15, 14]>;
  265. def ST4 : X86Reg<"st(4)", 4>, DwarfRegNum<[37, 16, 15]>;
  266. def ST5 : X86Reg<"st(5)", 5>, DwarfRegNum<[38, 17, 16]>;
  267. def ST6 : X86Reg<"st(6)", 6>, DwarfRegNum<[39, 18, 17]>;
  268. def ST7 : X86Reg<"st(7)", 7>, DwarfRegNum<[40, 19, 18]>;
  269. // Floating-point status word
  270. def FPSW : X86Reg<"fpsr", 0>;
  271. // Floating-point control word
  272. def FPCW : X86Reg<"fpcr", 0>;
  273. // SIMD Floating-point control register.
  274. // Note: We only model the "Uses" of the control bits: current rounding modes,
  275. // DAZ, FTZ and exception masks. We don't model the "Defs" of flag bits.
  276. def MXCSR : X86Reg<"mxcsr", 0>;
  277. // Status flags register.
  278. //
  279. // Note that some flags that are commonly thought of as part of the status
  280. // flags register are modeled separately. Typically this is due to instructions
  281. // reading and updating those flags independently of all the others. We don't
  282. // want to create false dependencies between these instructions and so we use
  283. // a separate register to model them.
  284. def EFLAGS : X86Reg<"flags", 0>, DwarfRegNum<[49, 9, 9]>;
  285. def _EFLAGS : X86Reg<"eflags", 0>, DwarfRegAlias<EFLAGS>;
  286. def RFLAGS : X86Reg<"rflags", 0>, DwarfRegNum<[49, -2, -2]>;
  287. // The direction flag.
  288. def DF : X86Reg<"dirflag", 0>;
  289. // Segment registers
  290. def CS : X86Reg<"cs", 1>;
  291. def DS : X86Reg<"ds", 3>;
  292. def SS : X86Reg<"ss", 2>;
  293. def ES : X86Reg<"es", 0>;
  294. def FS : X86Reg<"fs", 4>;
  295. def GS : X86Reg<"gs", 5>;
  296. def FS_BASE : X86Reg<"fs.base", 0>, DwarfRegNum<[58, -2, -2]>;
  297. def GS_BASE : X86Reg<"gs.base", 0>, DwarfRegNum<[59, -2, -2]>;
  298. // Debug registers
  299. def DR0 : X86Reg<"dr0", 0>;
  300. def DR1 : X86Reg<"dr1", 1>;
  301. def DR2 : X86Reg<"dr2", 2>;
  302. def DR3 : X86Reg<"dr3", 3>;
  303. def DR4 : X86Reg<"dr4", 4>;
  304. def DR5 : X86Reg<"dr5", 5>;
  305. def DR6 : X86Reg<"dr6", 6>;
  306. def DR7 : X86Reg<"dr7", 7>;
  307. def DR8 : X86Reg<"dr8", 8>;
  308. def DR9 : X86Reg<"dr9", 9>;
  309. def DR10 : X86Reg<"dr10", 10>;
  310. def DR11 : X86Reg<"dr11", 11>;
  311. def DR12 : X86Reg<"dr12", 12>;
  312. def DR13 : X86Reg<"dr13", 13>;
  313. def DR14 : X86Reg<"dr14", 14>;
  314. def DR15 : X86Reg<"dr15", 15>;
  315. // Control registers
  316. def CR0 : X86Reg<"cr0", 0>;
  317. def CR1 : X86Reg<"cr1", 1>;
  318. def CR2 : X86Reg<"cr2", 2>;
  319. def CR3 : X86Reg<"cr3", 3>;
  320. def CR4 : X86Reg<"cr4", 4>;
  321. def CR5 : X86Reg<"cr5", 5>;
  322. def CR6 : X86Reg<"cr6", 6>;
  323. def CR7 : X86Reg<"cr7", 7>;
  324. def CR8 : X86Reg<"cr8", 8>;
  325. def CR9 : X86Reg<"cr9", 9>;
  326. def CR10 : X86Reg<"cr10", 10>;
  327. def CR11 : X86Reg<"cr11", 11>;
  328. def CR12 : X86Reg<"cr12", 12>;
  329. def CR13 : X86Reg<"cr13", 13>;
  330. def CR14 : X86Reg<"cr14", 14>;
  331. def CR15 : X86Reg<"cr15", 15>;
  332. // Pseudo index registers
  333. def EIZ : X86Reg<"eiz", 4>;
  334. def RIZ : X86Reg<"riz", 4>;
  335. // CET registers - Shadow Stack Pointer
  336. def SSP : X86Reg<"ssp", 0>;
  337. //===----------------------------------------------------------------------===//
  338. // Register Class Definitions... now that we have all of the pieces, define the
  339. // top-level register classes. The order specified in the register list is
  340. // implicitly defined to be the register allocation order.
  341. //
  342. // List call-clobbered registers before callee-save registers. RBX, RBP, (and
  343. // R12, R13, R14, and R15 for X86-64) are callee-save registers.
  344. // In 64-mode, there are 12 additional i8 registers, SIL, DIL, BPL, SPL, and
  345. // R8B, ... R15B.
  346. // Allocate R12 and R13 last, as these require an extra byte when
  347. // encoded in x86_64 instructions.
  348. // FIXME: Allow AH, CH, DH, BH to be used as general-purpose registers in
  349. // 64-bit mode. The main complication is that they cannot be encoded in an
  350. // instruction requiring a REX prefix, while SIL, DIL, BPL, R8D, etc.
  351. // require a REX prefix. For example, "addb %ah, %dil" and "movzbl %ah, %r8d"
  352. // cannot be encoded.
  353. def GR8 : RegisterClass<"X86", [i8], 8,
  354. (add AL, CL, DL, AH, CH, DH, BL, BH, SIL, DIL, BPL, SPL,
  355. R8B, R9B, R10B, R11B, R14B, R15B, R12B, R13B)> {
  356. let AltOrders = [(sub GR8, AH, BH, CH, DH)];
  357. let AltOrderSelect = [{
  358. return MF.getSubtarget<X86Subtarget>().is64Bit();
  359. }];
  360. }
  361. let isAllocatable = 0 in
  362. def GRH8 : RegisterClass<"X86", [i8], 8,
  363. (add SIH, DIH, BPH, SPH, R8BH, R9BH, R10BH, R11BH,
  364. R12BH, R13BH, R14BH, R15BH)>;
  365. def GR16 : RegisterClass<"X86", [i16], 16,
  366. (add AX, CX, DX, SI, DI, BX, BP, SP,
  367. R8W, R9W, R10W, R11W, R14W, R15W, R12W, R13W)>;
  368. let isAllocatable = 0 in
  369. def GRH16 : RegisterClass<"X86", [i16], 16,
  370. (add HAX, HCX, HDX, HSI, HDI, HBX, HBP, HSP, HIP,
  371. R8WH, R9WH, R10WH, R11WH, R12WH, R13WH, R14WH,
  372. R15WH)>;
  373. def GR32 : RegisterClass<"X86", [i32], 32,
  374. (add EAX, ECX, EDX, ESI, EDI, EBX, EBP, ESP,
  375. R8D, R9D, R10D, R11D, R14D, R15D, R12D, R13D)>;
  376. // GR64 - 64-bit GPRs. This oddly includes RIP, which isn't accurate, since
  377. // RIP isn't really a register and it can't be used anywhere except in an
  378. // address, but it doesn't cause trouble.
  379. // FIXME: it *does* cause trouble - CheckBaseRegAndIndexReg() has extra
  380. // tests because of the inclusion of RIP in this register class.
  381. def GR64 : RegisterClass<"X86", [i64], 64,
  382. (add RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
  383. RBX, R14, R15, R12, R13, RBP, RSP, RIP)>;
  384. // GR64PLTSafe - 64-bit GPRs without R10, R11, RSP and RIP. Could be used when
  385. // emitting code for intrinsics, which use implict input registers.
  386. def GR64PLTSafe : RegisterClass<"X86", [i64], 64,
  387. (add RAX, RCX, RDX, RSI, RDI, R8, R9,
  388. RBX, R14, R15, R12, R13, RBP)>;
  389. // Segment registers for use by MOV instructions (and others) that have a
  390. // segment register as one operand. Always contain a 16-bit segment
  391. // descriptor.
  392. def SEGMENT_REG : RegisterClass<"X86", [i16], 16, (add CS, DS, SS, ES, FS, GS)>;
  393. // Debug registers.
  394. def DEBUG_REG : RegisterClass<"X86", [i32], 32, (sequence "DR%u", 0, 15)>;
  395. // Control registers.
  396. def CONTROL_REG : RegisterClass<"X86", [i64], 64, (sequence "CR%u", 0, 15)>;
  397. // GR8_ABCD_L, GR8_ABCD_H, GR16_ABCD, GR32_ABCD, GR64_ABCD - Subclasses of
  398. // GR8, GR16, GR32, and GR64 which contain just the "a" "b", "c", and "d"
  399. // registers. On x86-32, GR16_ABCD and GR32_ABCD are classes for registers
  400. // that support 8-bit subreg operations. On x86-64, GR16_ABCD, GR32_ABCD,
  401. // and GR64_ABCD are classes for registers that support 8-bit h-register
  402. // operations.
  403. def GR8_ABCD_L : RegisterClass<"X86", [i8], 8, (add AL, CL, DL, BL)>;
  404. def GR8_ABCD_H : RegisterClass<"X86", [i8], 8, (add AH, CH, DH, BH)>;
  405. def GR16_ABCD : RegisterClass<"X86", [i16], 16, (add AX, CX, DX, BX)>;
  406. def GR32_ABCD : RegisterClass<"X86", [i32], 32, (add EAX, ECX, EDX, EBX)>;
  407. def GR64_ABCD : RegisterClass<"X86", [i64], 64, (add RAX, RCX, RDX, RBX)>;
  408. def GR32_TC : RegisterClass<"X86", [i32], 32, (add EAX, ECX, EDX, ESP)>;
  409. def GR64_TC : RegisterClass<"X86", [i64], 64, (add RAX, RCX, RDX, RSI, RDI,
  410. R8, R9, R11, RIP, RSP)>;
  411. def GR64_TCW64 : RegisterClass<"X86", [i64], 64, (add RAX, RCX, RDX,
  412. R8, R9, R10, R11,
  413. RIP, RSP)>;
  414. // GR8_NOREX - GR8 registers which do not require a REX prefix.
  415. def GR8_NOREX : RegisterClass<"X86", [i8], 8,
  416. (add AL, CL, DL, AH, CH, DH, BL, BH)> {
  417. let AltOrders = [(sub GR8_NOREX, AH, BH, CH, DH)];
  418. let AltOrderSelect = [{
  419. return MF.getSubtarget<X86Subtarget>().is64Bit();
  420. }];
  421. }
  422. // GR16_NOREX - GR16 registers which do not require a REX prefix.
  423. def GR16_NOREX : RegisterClass<"X86", [i16], 16,
  424. (add AX, CX, DX, SI, DI, BX, BP, SP)>;
  425. // GR32_NOREX - GR32 registers which do not require a REX prefix.
  426. def GR32_NOREX : RegisterClass<"X86", [i32], 32,
  427. (add EAX, ECX, EDX, ESI, EDI, EBX, EBP, ESP)>;
  428. // GR64_NOREX - GR64 registers which do not require a REX prefix.
  429. def GR64_NOREX : RegisterClass<"X86", [i64], 64,
  430. (add RAX, RCX, RDX, RSI, RDI, RBX, RBP, RSP, RIP)>;
  431. // GR32_NOSP - GR32 registers except ESP.
  432. def GR32_NOSP : RegisterClass<"X86", [i32], 32, (sub GR32, ESP)>;
  433. // GR64_NOSP - GR64 registers except RSP (and RIP).
  434. def GR64_NOSP : RegisterClass<"X86", [i64], 64, (sub GR64, RSP, RIP)>;
  435. // GR32_NOREX_NOSP - GR32 registers which do not require a REX prefix except
  436. // ESP.
  437. def GR32_NOREX_NOSP : RegisterClass<"X86", [i32], 32,
  438. (and GR32_NOREX, GR32_NOSP)>;
  439. // GR64_NOREX_NOSP - GR64_NOREX registers except RSP.
  440. def GR64_NOREX_NOSP : RegisterClass<"X86", [i64], 64,
  441. (and GR64_NOREX, GR64_NOSP)>;
  442. // Register classes used for ABIs that use 32-bit address accesses,
  443. // while using the whole x84_64 ISA.
  444. // In such cases, it is fine to use RIP as we are sure the 32 high
  445. // bits are not set. We do not need variants for NOSP as RIP is not
  446. // allowed there.
  447. // RIP is not spilled anywhere for now, so stick to 32-bit alignment
  448. // to save on memory space.
  449. // FIXME: We could allow all 64bit registers, but we would need
  450. // something to check that the 32 high bits are not set,
  451. // which we do not have right now.
  452. def LOW32_ADDR_ACCESS : RegisterClass<"X86", [i32], 32, (add GR32, RIP)>;
  453. // When RBP is used as a base pointer in a 32-bit addresses environment,
  454. // this is also safe to use the full register to access addresses.
  455. // Since RBP will never be spilled, stick to a 32 alignment to save
  456. // on memory consumption.
  457. def LOW32_ADDR_ACCESS_RBP : RegisterClass<"X86", [i32], 32,
  458. (add LOW32_ADDR_ACCESS, RBP)>;
  459. // A class to support the 'A' assembler constraint: [ER]AX then [ER]DX.
  460. def GR32_AD : RegisterClass<"X86", [i32], 32, (add EAX, EDX)>;
  461. def GR64_AD : RegisterClass<"X86", [i64], 64, (add RAX, RDX)>;
  462. // Classes to support the 64-bit assembler constraint tied to a fixed
  463. // register in 32-bit mode. The second register is always the next in
  464. // the list. Wrap around causes an error.
  465. def GR32_DC : RegisterClass<"X86", [i32], 32, (add EDX, ECX)>;
  466. def GR32_CB : RegisterClass<"X86", [i32], 32, (add ECX, EBX)>;
  467. def GR32_BSI : RegisterClass<"X86", [i32], 32, (add EBX, ESI)>;
  468. def GR32_SIDI : RegisterClass<"X86", [i32], 32, (add ESI, EDI)>;
  469. def GR32_DIBP : RegisterClass<"X86", [i32], 32, (add EDI, EBP)>;
  470. def GR32_BPSP : RegisterClass<"X86", [i32], 32, (add EBP, ESP)>;
  471. // Scalar SSE2 floating point registers.
  472. def FR32 : RegisterClass<"X86", [f32], 32, (sequence "XMM%u", 0, 15)>;
  473. def FR64 : RegisterClass<"X86", [f64], 64, (add FR32)>;
  474. def FR16 : RegisterClass<"X86", [f16], 16, (add FR32)> {let Size = 32;}
  475. // FIXME: This sets up the floating point register files as though they are f64
  476. // values, though they really are f80 values. This will cause us to spill
  477. // values as 64-bit quantities instead of 80-bit quantities, which is much much
  478. // faster on common hardware. In reality, this should be controlled by a
  479. // command line option or something.
  480. def RFP32 : RegisterClass<"X86",[f32], 32, (sequence "FP%u", 0, 6)>;
  481. def RFP64 : RegisterClass<"X86",[f64], 32, (add RFP32)>;
  482. def RFP80 : RegisterClass<"X86",[f80], 32, (add RFP32)>;
  483. // st(7) may be is not allocatable.
  484. def RFP80_7 : RegisterClass<"X86",[f80], 32, (add FP7)> {
  485. let isAllocatable = 0;
  486. }
  487. // Floating point stack registers (these are not allocatable by the
  488. // register allocator - the floating point stackifier is responsible
  489. // for transforming FPn allocations to STn registers)
  490. def RST : RegisterClass<"X86", [f80, f64, f32], 32, (sequence "ST%u", 0, 7)> {
  491. let isAllocatable = 0;
  492. }
  493. // Helper to allow %st to print as %st(0) when its encoded in the instruction.
  494. def RSTi : RegisterOperand<RST, "printSTiRegOperand">;
  495. // Generic vector registers: VR64 and VR128.
  496. // Ensure that float types are declared first - only float is legal on SSE1.
  497. def VR64: RegisterClass<"X86", [x86mmx], 64, (sequence "MM%u", 0, 7)>;
  498. def VR128 : RegisterClass<"X86", [v4f32, v2f64, v8f16, v8bf16, v16i8, v8i16, v4i32, v2i64, f128],
  499. 128, (add FR32)>;
  500. def VR256 : RegisterClass<"X86", [v8f32, v4f64, v16f16, v16bf16, v32i8, v16i16, v8i32, v4i64],
  501. 256, (sequence "YMM%u", 0, 15)>;
  502. // Status flags registers.
  503. def CCR : RegisterClass<"X86", [i32], 32, (add EFLAGS)> {
  504. let CopyCost = -1; // Don't allow copying of status registers.
  505. let isAllocatable = 0;
  506. }
  507. def FPCCR : RegisterClass<"X86", [i16], 16, (add FPSW)> {
  508. let CopyCost = -1; // Don't allow copying of status registers.
  509. let isAllocatable = 0;
  510. }
  511. def DFCCR : RegisterClass<"X86", [i32], 32, (add DF)> {
  512. let CopyCost = -1; // Don't allow copying of status registers.
  513. let isAllocatable = 0;
  514. }
  515. // AVX-512 vector/mask registers.
  516. def VR512 : RegisterClass<"X86", [v16f32, v8f64, v32f16, v32bf16, v64i8, v32i16, v16i32, v8i64],
  517. 512, (sequence "ZMM%u", 0, 31)>;
  518. // Represents the lower 16 registers that have VEX/legacy encodable subregs.
  519. def VR512_0_15 : RegisterClass<"X86", [v16f32, v8f64, v64i8, v32i16, v16i32, v8i64],
  520. 512, (sequence "ZMM%u", 0, 15)>;
  521. // Scalar AVX-512 floating point registers.
  522. def FR32X : RegisterClass<"X86", [f32], 32, (sequence "XMM%u", 0, 31)>;
  523. def FR64X : RegisterClass<"X86", [f64], 64, (add FR32X)>;
  524. def FR16X : RegisterClass<"X86", [f16], 16, (add FR32X)> {let Size = 32;}
  525. // Extended VR128 and VR256 for AVX-512 instructions
  526. def VR128X : RegisterClass<"X86", [v4f32, v2f64, v8f16, v8bf16, v16i8, v8i16, v4i32, v2i64, f128],
  527. 128, (add FR32X)>;
  528. def VR256X : RegisterClass<"X86", [v8f32, v4f64, v16f16, v16bf16, v32i8, v16i16, v8i32, v4i64],
  529. 256, (sequence "YMM%u", 0, 31)>;
  530. // Mask registers
  531. def VK1 : RegisterClass<"X86", [v1i1], 16, (sequence "K%u", 0, 7)> {let Size = 16;}
  532. def VK2 : RegisterClass<"X86", [v2i1], 16, (add VK1)> {let Size = 16;}
  533. def VK4 : RegisterClass<"X86", [v4i1], 16, (add VK2)> {let Size = 16;}
  534. def VK8 : RegisterClass<"X86", [v8i1], 16, (add VK4)> {let Size = 16;}
  535. def VK16 : RegisterClass<"X86", [v16i1], 16, (add VK8)> {let Size = 16;}
  536. def VK32 : RegisterClass<"X86", [v32i1], 32, (add VK16)> {let Size = 32;}
  537. def VK64 : RegisterClass<"X86", [v64i1], 64, (add VK32)> {let Size = 64;}
  538. // Mask register pairs
  539. def KPAIRS : RegisterTuples<[sub_mask_0, sub_mask_1],
  540. [(add K0, K2, K4, K6), (add K1, K3, K5, K7)]>;
  541. def VK1PAIR : RegisterClass<"X86", [untyped], 16, (add KPAIRS)> {let Size = 32;}
  542. def VK2PAIR : RegisterClass<"X86", [untyped], 16, (add KPAIRS)> {let Size = 32;}
  543. def VK4PAIR : RegisterClass<"X86", [untyped], 16, (add KPAIRS)> {let Size = 32;}
  544. def VK8PAIR : RegisterClass<"X86", [untyped], 16, (add KPAIRS)> {let Size = 32;}
  545. def VK16PAIR : RegisterClass<"X86", [untyped], 16, (add KPAIRS)> {let Size = 32;}
  546. def VK1WM : RegisterClass<"X86", [v1i1], 16, (sub VK1, K0)> {let Size = 16;}
  547. def VK2WM : RegisterClass<"X86", [v2i1], 16, (sub VK2, K0)> {let Size = 16;}
  548. def VK4WM : RegisterClass<"X86", [v4i1], 16, (sub VK4, K0)> {let Size = 16;}
  549. def VK8WM : RegisterClass<"X86", [v8i1], 16, (sub VK8, K0)> {let Size = 16;}
  550. def VK16WM : RegisterClass<"X86", [v16i1], 16, (add VK8WM)> {let Size = 16;}
  551. def VK32WM : RegisterClass<"X86", [v32i1], 32, (add VK16WM)> {let Size = 32;}
  552. def VK64WM : RegisterClass<"X86", [v64i1], 64, (add VK32WM)> {let Size = 64;}
  553. // Tiles
  554. let CopyCost = -1 in // Don't allow copying of tile registers
  555. def TILE : RegisterClass<"X86", [x86amx], 8192,
  556. (sequence "TMM%u", 0, 7)> {let Size = 8192;}
  557. //===----------------------------------------------------------------------===//
  558. // Register categories.
  559. //
  560. // The TILE and VK*PAIR registers may not be "fixed", but we don't want them
  561. // anyway.
  562. def FixedRegisters : RegisterCategory<[DEBUG_REG, CONTROL_REG, CCR, FPCCR,
  563. DFCCR, TILE, VK1PAIR, VK2PAIR, VK4PAIR,
  564. VK8PAIR, VK16PAIR]>;
  565. def GeneralPurposeRegisters : RegisterCategory<[GR64, GR32, GR16, GR8]>;