1 //===-- RISCVRegisterInfo.td - RISC-V Register defs --------*- tablegen -*-===//
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
7 //===----------------------------------------------------------------------===//
9 //===----------------------------------------------------------------------===//
10 // Declarations that describe the RISC-V register files
11 //===----------------------------------------------------------------------===//
13 let Namespace = "RISCV" in {
14 class RISCVReg<bits<5> Enc, string n, list<string> alt = []> : Register<n> {
15 let HWEncoding{4-0} = Enc;
19 class RISCVReg32<bits<5> Enc, string n, list<string> alt = []> : Register<n> {
20 let HWEncoding{4-0} = Enc;
24 // Because RISCVReg64 register have AsmName and AltNames that alias with their
25 // 32-bit sub-register, RISCVAsmParser will need to coerce a register number
26 // from a RISCVReg32 to the equivalent RISCVReg64 when appropriate.
27 def sub_32 : SubRegIndex<32>;
28 class RISCVReg64<RISCVReg32 subreg> : Register<""> {
29 let HWEncoding{4-0} = subreg.HWEncoding{4-0};
30 let SubRegs = [subreg];
31 let SubRegIndices = [sub_32];
32 let AsmName = subreg.AsmName;
33 let AltNames = subreg.AltNames;
36 def ABIRegAltName : RegAltNameIndex;
37 } // Namespace = "RISCV"
40 // CostPerUse is set higher for registers that may not be compressible as they
41 // are not part of GPRC, the most restrictive register class used by the
42 // compressed instruction set. This will influence the greedy register
43 // allocator to reduce the use of registers that can't be encoded in 16 bit
44 // instructions. This affects register allocation even when compressed
45 // instruction isn't targeted, we see no major negative codegen impact.
47 let RegAltNameIndices = [ABIRegAltName] in {
48 def X0 : RISCVReg<0, "x0", ["zero"]>, DwarfRegNum<[0]>;
49 let CostPerUse = 1 in {
50 def X1 : RISCVReg<1, "x1", ["ra"]>, DwarfRegNum<[1]>;
51 def X2 : RISCVReg<2, "x2", ["sp"]>, DwarfRegNum<[2]>;
52 def X3 : RISCVReg<3, "x3", ["gp"]>, DwarfRegNum<[3]>;
53 def X4 : RISCVReg<4, "x4", ["tp"]>, DwarfRegNum<[4]>;
54 def X5 : RISCVReg<5, "x5", ["t0"]>, DwarfRegNum<[5]>;
55 def X6 : RISCVReg<6, "x6", ["t1"]>, DwarfRegNum<[6]>;
56 def X7 : RISCVReg<7, "x7", ["t2"]>, DwarfRegNum<[7]>;
58 def X8 : RISCVReg<8, "x8", ["s0", "fp"]>, DwarfRegNum<[8]>;
59 def X9 : RISCVReg<9, "x9", ["s1"]>, DwarfRegNum<[9]>;
60 def X10 : RISCVReg<10,"x10", ["a0"]>, DwarfRegNum<[10]>;
61 def X11 : RISCVReg<11,"x11", ["a1"]>, DwarfRegNum<[11]>;
62 def X12 : RISCVReg<12,"x12", ["a2"]>, DwarfRegNum<[12]>;
63 def X13 : RISCVReg<13,"x13", ["a3"]>, DwarfRegNum<[13]>;
64 def X14 : RISCVReg<14,"x14", ["a4"]>, DwarfRegNum<[14]>;
65 def X15 : RISCVReg<15,"x15", ["a5"]>, DwarfRegNum<[15]>;
66 let CostPerUse = 1 in {
67 def X16 : RISCVReg<16,"x16", ["a6"]>, DwarfRegNum<[16]>;
68 def X17 : RISCVReg<17,"x17", ["a7"]>, DwarfRegNum<[17]>;
69 def X18 : RISCVReg<18,"x18", ["s2"]>, DwarfRegNum<[18]>;
70 def X19 : RISCVReg<19,"x19", ["s3"]>, DwarfRegNum<[19]>;
71 def X20 : RISCVReg<20,"x20", ["s4"]>, DwarfRegNum<[20]>;
72 def X21 : RISCVReg<21,"x21", ["s5"]>, DwarfRegNum<[21]>;
73 def X22 : RISCVReg<22,"x22", ["s6"]>, DwarfRegNum<[22]>;
74 def X23 : RISCVReg<23,"x23", ["s7"]>, DwarfRegNum<[23]>;
75 def X24 : RISCVReg<24,"x24", ["s8"]>, DwarfRegNum<[24]>;
76 def X25 : RISCVReg<25,"x25", ["s9"]>, DwarfRegNum<[25]>;
77 def X26 : RISCVReg<26,"x26", ["s10"]>, DwarfRegNum<[26]>;
78 def X27 : RISCVReg<27,"x27", ["s11"]>, DwarfRegNum<[27]>;
79 def X28 : RISCVReg<28,"x28", ["t3"]>, DwarfRegNum<[28]>;
80 def X29 : RISCVReg<29,"x29", ["t4"]>, DwarfRegNum<[29]>;
81 def X30 : RISCVReg<30,"x30", ["t5"]>, DwarfRegNum<[30]>;
82 def X31 : RISCVReg<31,"x31", ["t6"]>, DwarfRegNum<[31]>;
86 def XLenVT : ValueTypeByHwMode<[RV32, RV64, DefaultMode],
89 // The order of registers represents the preferred allocation sequence.
90 // Registers are listed in the order caller-save, callee-save, specials.
91 def GPR : RegisterClass<"RISCV", [XLenVT], 32, (add
92 (sequence "X%u", 10, 17),
93 (sequence "X%u", 5, 7),
94 (sequence "X%u", 28, 31),
95 (sequence "X%u", 8, 9),
96 (sequence "X%u", 18, 27),
97 (sequence "X%u", 0, 4)
99 let RegInfos = RegInfoByHwMode<
100 [RV32, RV64, DefaultMode],
101 [RegInfo<32,32,32>, RegInfo<64,64,64>, RegInfo<32,32,32>]>;
104 def GPRX0 : RegisterClass<"RISCV", [XLenVT], 32, (add X0)> {
105 let RegInfos = RegInfoByHwMode<
106 [RV32, RV64, DefaultMode],
107 [RegInfo<32,32,32>, RegInfo<64,64,64>, RegInfo<32,32,32>]>;
110 // The order of registers represents the preferred allocation sequence.
111 // Registers are listed in the order caller-save, callee-save, specials.
112 def GPRNoX0 : RegisterClass<"RISCV", [XLenVT], 32, (add
113 (sequence "X%u", 10, 17),
114 (sequence "X%u", 5, 7),
115 (sequence "X%u", 28, 31),
116 (sequence "X%u", 8, 9),
117 (sequence "X%u", 18, 27),
118 (sequence "X%u", 1, 4)
120 let RegInfos = RegInfoByHwMode<
121 [RV32, RV64, DefaultMode],
122 [RegInfo<32,32,32>, RegInfo<64,64,64>, RegInfo<32,32,32>]>;
125 def GPRNoX0X2 : RegisterClass<"RISCV", [XLenVT], 32, (add
126 (sequence "X%u", 10, 17),
127 (sequence "X%u", 5, 7),
128 (sequence "X%u", 28, 31),
129 (sequence "X%u", 8, 9),
130 (sequence "X%u", 18, 27),
133 let RegInfos = RegInfoByHwMode<
134 [RV32, RV64, DefaultMode],
135 [RegInfo<32,32,32>, RegInfo<64,64,64>, RegInfo<32,32,32>]>;
138 def GPRC : RegisterClass<"RISCV", [XLenVT], 32, (add
139 (sequence "X%u", 10, 15),
140 (sequence "X%u", 8, 9)
142 let RegInfos = RegInfoByHwMode<
143 [RV32, RV64, DefaultMode],
144 [RegInfo<32,32,32>, RegInfo<64,64,64>, RegInfo<32,32,32>]>;
147 // For indirect tail calls, we can't use callee-saved registers, as they are
148 // restored to the saved value before the tail call, which would clobber a call
150 def GPRTC : RegisterClass<"RISCV", [XLenVT], 32, (add
151 (sequence "X%u", 5, 7),
152 (sequence "X%u", 10, 17),
153 (sequence "X%u", 28, 31)
155 let RegInfos = RegInfoByHwMode<
156 [RV32, RV64, DefaultMode],
157 [RegInfo<32,32,32>, RegInfo<64,64,64>, RegInfo<32,32,32>]>;
160 def SP : RegisterClass<"RISCV", [XLenVT], 32, (add X2)> {
161 let RegInfos = RegInfoByHwMode<
162 [RV32, RV64, DefaultMode],
163 [RegInfo<32,32,32>, RegInfo<64,64,64>, RegInfo<32,32,32>]>;
166 // Floating point registers
167 let RegAltNameIndices = [ABIRegAltName] in {
168 def F0_F : RISCVReg32<0, "f0", ["ft0"]>, DwarfRegNum<[32]>;
169 def F1_F : RISCVReg32<1, "f1", ["ft1"]>, DwarfRegNum<[33]>;
170 def F2_F : RISCVReg32<2, "f2", ["ft2"]>, DwarfRegNum<[34]>;
171 def F3_F : RISCVReg32<3, "f3", ["ft3"]>, DwarfRegNum<[35]>;
172 def F4_F : RISCVReg32<4, "f4", ["ft4"]>, DwarfRegNum<[36]>;
173 def F5_F : RISCVReg32<5, "f5", ["ft5"]>, DwarfRegNum<[37]>;
174 def F6_F : RISCVReg32<6, "f6", ["ft6"]>, DwarfRegNum<[38]>;
175 def F7_F : RISCVReg32<7, "f7", ["ft7"]>, DwarfRegNum<[39]>;
176 def F8_F : RISCVReg32<8, "f8", ["fs0"]>, DwarfRegNum<[40]>;
177 def F9_F : RISCVReg32<9, "f9", ["fs1"]>, DwarfRegNum<[41]>;
178 def F10_F : RISCVReg32<10,"f10", ["fa0"]>, DwarfRegNum<[42]>;
179 def F11_F : RISCVReg32<11,"f11", ["fa1"]>, DwarfRegNum<[43]>;
180 def F12_F : RISCVReg32<12,"f12", ["fa2"]>, DwarfRegNum<[44]>;
181 def F13_F : RISCVReg32<13,"f13", ["fa3"]>, DwarfRegNum<[45]>;
182 def F14_F : RISCVReg32<14,"f14", ["fa4"]>, DwarfRegNum<[46]>;
183 def F15_F : RISCVReg32<15,"f15", ["fa5"]>, DwarfRegNum<[47]>;
184 def F16_F : RISCVReg32<16,"f16", ["fa6"]>, DwarfRegNum<[48]>;
185 def F17_F : RISCVReg32<17,"f17", ["fa7"]>, DwarfRegNum<[49]>;
186 def F18_F : RISCVReg32<18,"f18", ["fs2"]>, DwarfRegNum<[50]>;
187 def F19_F : RISCVReg32<19,"f19", ["fs3"]>, DwarfRegNum<[51]>;
188 def F20_F : RISCVReg32<20,"f20", ["fs4"]>, DwarfRegNum<[52]>;
189 def F21_F : RISCVReg32<21,"f21", ["fs5"]>, DwarfRegNum<[53]>;
190 def F22_F : RISCVReg32<22,"f22", ["fs6"]>, DwarfRegNum<[54]>;
191 def F23_F : RISCVReg32<23,"f23", ["fs7"]>, DwarfRegNum<[55]>;
192 def F24_F : RISCVReg32<24,"f24", ["fs8"]>, DwarfRegNum<[56]>;
193 def F25_F : RISCVReg32<25,"f25", ["fs9"]>, DwarfRegNum<[57]>;
194 def F26_F : RISCVReg32<26,"f26", ["fs10"]>, DwarfRegNum<[58]>;
195 def F27_F : RISCVReg32<27,"f27", ["fs11"]>, DwarfRegNum<[59]>;
196 def F28_F : RISCVReg32<28,"f28", ["ft8"]>, DwarfRegNum<[60]>;
197 def F29_F : RISCVReg32<29,"f29", ["ft9"]>, DwarfRegNum<[61]>;
198 def F30_F : RISCVReg32<30,"f30", ["ft10"]>, DwarfRegNum<[62]>;
199 def F31_F : RISCVReg32<31,"f31", ["ft11"]>, DwarfRegNum<[63]>;
201 foreach Index = 0-31 in {
202 def F#Index#_D : RISCVReg64<!cast<RISCVReg32>("F"#Index#"_F")>,
203 DwarfRegNum<[!add(Index, 32)]>;
207 // The order of registers represents the preferred allocation sequence,
208 // meaning caller-save regs are listed before callee-save.
209 def FPR32 : RegisterClass<"RISCV", [f32], 32, (add
210 (sequence "F%u_F", 0, 7),
211 (sequence "F%u_F", 10, 17),
212 (sequence "F%u_F", 28, 31),
213 (sequence "F%u_F", 8, 9),
214 (sequence "F%u_F", 18, 27)
217 def FPR32C : RegisterClass<"RISCV", [f32], 32, (add
218 (sequence "F%u_F", 10, 15),
219 (sequence "F%u_F", 8, 9)
222 // The order of registers represents the preferred allocation sequence,
223 // meaning caller-save regs are listed before callee-save.
224 def FPR64 : RegisterClass<"RISCV", [f64], 64, (add
225 (sequence "F%u_D", 0, 7),
226 (sequence "F%u_D", 10, 17),
227 (sequence "F%u_D", 28, 31),
228 (sequence "F%u_D", 8, 9),
229 (sequence "F%u_D", 18, 27)
232 def FPR64C : RegisterClass<"RISCV", [f64], 64, (add
233 (sequence "F%u_D", 10, 15),
234 (sequence "F%u_D", 8, 9)