xref: /freebsd/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVRegisterInfo.td (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
10b57cec5SDimitry Andric//===-- RISCVRegisterInfo.td - RISC-V Register defs --------*- tablegen -*-===//
20b57cec5SDimitry Andric//
30b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric//
70b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric
90b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
100b57cec5SDimitry Andric//  Declarations that describe the RISC-V register files
110b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric
130b57cec5SDimitry Andriclet Namespace = "RISCV" in {
140b57cec5SDimitry Andricclass RISCVReg<bits<5> Enc, string n, list<string> alt = []> : Register<n> {
150b57cec5SDimitry Andric  let HWEncoding{4-0} = Enc;
160b57cec5SDimitry Andric  let AltNames = alt;
170b57cec5SDimitry Andric}
180b57cec5SDimitry Andric
195ffd83dbSDimitry Andricclass RISCVRegWithSubRegs<bits<5> Enc, string n, list<Register> subregs,
205ffd83dbSDimitry Andric                          list<string> alt = []>
215ffd83dbSDimitry Andric      : RegisterWithSubRegs<n, subregs> {
225ffd83dbSDimitry Andric  let HWEncoding{4-0} = Enc;
235ffd83dbSDimitry Andric  let AltNames = alt;
245ffd83dbSDimitry Andric}
255ffd83dbSDimitry Andric
26*06c3fb27SDimitry Andricclass RISCVReg16<bits<5> Enc, string n, list<string> alt = []> : Register<n> {
27*06c3fb27SDimitry Andric  let HWEncoding{4-0} = Enc;
28*06c3fb27SDimitry Andric  let AltNames = alt;
29*06c3fb27SDimitry Andric}
30*06c3fb27SDimitry Andric
31*06c3fb27SDimitry Andricdef sub_16 : SubRegIndex<16>;
32*06c3fb27SDimitry Andricclass RISCVReg32<RISCVReg16 subreg>
33*06c3fb27SDimitry Andric  : RISCVRegWithSubRegs<subreg.HWEncoding{4-0}, subreg.AsmName, [subreg],
34*06c3fb27SDimitry Andric                        subreg.AltNames> {
35*06c3fb27SDimitry Andric  let SubRegIndices = [sub_16];
36*06c3fb27SDimitry Andric}
37*06c3fb27SDimitry Andric
38*06c3fb27SDimitry Andric// Because RISCVReg64 register have AsmName and AltNames that alias with their
39*06c3fb27SDimitry Andric// 16/32-bit sub-register, RISCVAsmParser will need to coerce a register number
40*06c3fb27SDimitry Andric// from a RISCVReg16/RISCVReg32 to the equivalent RISCVReg64 when appropriate.
41*06c3fb27SDimitry Andricdef sub_32 : SubRegIndex<32>;
42*06c3fb27SDimitry Andricclass RISCVReg64<RISCVReg32 subreg>
43*06c3fb27SDimitry Andric  : RISCVRegWithSubRegs<subreg.HWEncoding{4-0}, subreg.AsmName, [subreg],
44*06c3fb27SDimitry Andric                        subreg.AltNames> {
45*06c3fb27SDimitry Andric  let SubRegIndices = [sub_32];
46*06c3fb27SDimitry Andric}
47*06c3fb27SDimitry Andric
48*06c3fb27SDimitry Andriclet FallbackRegAltNameIndex = NoRegAltName in
490b57cec5SDimitry Andricdef ABIRegAltName : RegAltNameIndex;
505ffd83dbSDimitry Andric
51fe6060f1SDimitry Andricdef sub_vrm4_0 : SubRegIndex<256>;
52fe6060f1SDimitry Andricdef sub_vrm4_1 : SubRegIndex<256, 256>;
53fe6060f1SDimitry Andricdef sub_vrm2_0 : SubRegIndex<128>;
54fe6060f1SDimitry Andricdef sub_vrm2_1 : SubRegIndex<128, 128>;
55fe6060f1SDimitry Andricdef sub_vrm2_2 : ComposedSubRegIndex<sub_vrm4_1, sub_vrm2_0>;
56fe6060f1SDimitry Andricdef sub_vrm2_3 : ComposedSubRegIndex<sub_vrm4_1, sub_vrm2_1>;
57fe6060f1SDimitry Andricdef sub_vrm1_0 : SubRegIndex<64>;
58fe6060f1SDimitry Andricdef sub_vrm1_1 : SubRegIndex<64, 64>;
59fe6060f1SDimitry Andricdef sub_vrm1_2 : ComposedSubRegIndex<sub_vrm2_1, sub_vrm1_0>;
60fe6060f1SDimitry Andricdef sub_vrm1_3 : ComposedSubRegIndex<sub_vrm2_1, sub_vrm1_1>;
61fe6060f1SDimitry Andricdef sub_vrm1_4 : ComposedSubRegIndex<sub_vrm2_2, sub_vrm1_0>;
62fe6060f1SDimitry Andricdef sub_vrm1_5 : ComposedSubRegIndex<sub_vrm2_2, sub_vrm1_1>;
63fe6060f1SDimitry Andricdef sub_vrm1_6 : ComposedSubRegIndex<sub_vrm2_3, sub_vrm1_0>;
64fe6060f1SDimitry Andricdef sub_vrm1_7 : ComposedSubRegIndex<sub_vrm2_3, sub_vrm1_1>;
65e8d8bef9SDimitry Andric
66d56accc7SDimitry Andricdef sub_32_hi  : SubRegIndex<32, 32>;
670b57cec5SDimitry Andric} // Namespace = "RISCV"
680b57cec5SDimitry Andric
690b57cec5SDimitry Andric// Integer registers
700b57cec5SDimitry Andric// CostPerUse is set higher for registers that may not be compressible as they
710b57cec5SDimitry Andric// are not part of GPRC, the most restrictive register class used by the
720b57cec5SDimitry Andric// compressed instruction set. This will influence the greedy register
730b57cec5SDimitry Andric// allocator to reduce the use of registers that can't be encoded in 16 bit
7404eeddc0SDimitry Andric// instructions.
750b57cec5SDimitry Andric
760b57cec5SDimitry Andriclet RegAltNameIndices = [ABIRegAltName] in {
77bdd1243dSDimitry Andric  let isConstant = true in
780b57cec5SDimitry Andric  def X0  : RISCVReg<0, "x0", ["zero"]>, DwarfRegNum<[0]>;
7904eeddc0SDimitry Andric  let CostPerUse = [0, 1] in {
800b57cec5SDimitry Andric  def X1  : RISCVReg<1, "x1", ["ra"]>, DwarfRegNum<[1]>;
810b57cec5SDimitry Andric  def X2  : RISCVReg<2, "x2", ["sp"]>, DwarfRegNum<[2]>;
820b57cec5SDimitry Andric  def X3  : RISCVReg<3, "x3", ["gp"]>, DwarfRegNum<[3]>;
830b57cec5SDimitry Andric  def X4  : RISCVReg<4, "x4", ["tp"]>, DwarfRegNum<[4]>;
840b57cec5SDimitry Andric  def X5  : RISCVReg<5, "x5", ["t0"]>, DwarfRegNum<[5]>;
850b57cec5SDimitry Andric  def X6  : RISCVReg<6, "x6", ["t1"]>, DwarfRegNum<[6]>;
860b57cec5SDimitry Andric  def X7  : RISCVReg<7, "x7", ["t2"]>, DwarfRegNum<[7]>;
870b57cec5SDimitry Andric  }
880b57cec5SDimitry Andric  def X8  : RISCVReg<8, "x8", ["s0", "fp"]>, DwarfRegNum<[8]>;
890b57cec5SDimitry Andric  def X9  : RISCVReg<9, "x9", ["s1"]>, DwarfRegNum<[9]>;
900b57cec5SDimitry Andric  def X10 : RISCVReg<10,"x10", ["a0"]>, DwarfRegNum<[10]>;
910b57cec5SDimitry Andric  def X11 : RISCVReg<11,"x11", ["a1"]>, DwarfRegNum<[11]>;
920b57cec5SDimitry Andric  def X12 : RISCVReg<12,"x12", ["a2"]>, DwarfRegNum<[12]>;
930b57cec5SDimitry Andric  def X13 : RISCVReg<13,"x13", ["a3"]>, DwarfRegNum<[13]>;
940b57cec5SDimitry Andric  def X14 : RISCVReg<14,"x14", ["a4"]>, DwarfRegNum<[14]>;
950b57cec5SDimitry Andric  def X15 : RISCVReg<15,"x15", ["a5"]>, DwarfRegNum<[15]>;
9604eeddc0SDimitry Andric  let CostPerUse = [0, 1] in {
970b57cec5SDimitry Andric  def X16 : RISCVReg<16,"x16", ["a6"]>, DwarfRegNum<[16]>;
980b57cec5SDimitry Andric  def X17 : RISCVReg<17,"x17", ["a7"]>, DwarfRegNum<[17]>;
990b57cec5SDimitry Andric  def X18 : RISCVReg<18,"x18", ["s2"]>, DwarfRegNum<[18]>;
1000b57cec5SDimitry Andric  def X19 : RISCVReg<19,"x19", ["s3"]>, DwarfRegNum<[19]>;
1010b57cec5SDimitry Andric  def X20 : RISCVReg<20,"x20", ["s4"]>, DwarfRegNum<[20]>;
1020b57cec5SDimitry Andric  def X21 : RISCVReg<21,"x21", ["s5"]>, DwarfRegNum<[21]>;
1030b57cec5SDimitry Andric  def X22 : RISCVReg<22,"x22", ["s6"]>, DwarfRegNum<[22]>;
1040b57cec5SDimitry Andric  def X23 : RISCVReg<23,"x23", ["s7"]>, DwarfRegNum<[23]>;
1050b57cec5SDimitry Andric  def X24 : RISCVReg<24,"x24", ["s8"]>, DwarfRegNum<[24]>;
1060b57cec5SDimitry Andric  def X25 : RISCVReg<25,"x25", ["s9"]>, DwarfRegNum<[25]>;
1070b57cec5SDimitry Andric  def X26 : RISCVReg<26,"x26", ["s10"]>, DwarfRegNum<[26]>;
1080b57cec5SDimitry Andric  def X27 : RISCVReg<27,"x27", ["s11"]>, DwarfRegNum<[27]>;
1090b57cec5SDimitry Andric  def X28 : RISCVReg<28,"x28", ["t3"]>, DwarfRegNum<[28]>;
1100b57cec5SDimitry Andric  def X29 : RISCVReg<29,"x29", ["t4"]>, DwarfRegNum<[29]>;
1110b57cec5SDimitry Andric  def X30 : RISCVReg<30,"x30", ["t5"]>, DwarfRegNum<[30]>;
1120b57cec5SDimitry Andric  def X31 : RISCVReg<31,"x31", ["t6"]>, DwarfRegNum<[31]>;
1130b57cec5SDimitry Andric  }
1140b57cec5SDimitry Andric}
1150b57cec5SDimitry Andric
116e8d8bef9SDimitry Andricdef XLenVT : ValueTypeByHwMode<[RV32, RV64],
117e8d8bef9SDimitry Andric                               [i32,  i64]>;
118*06c3fb27SDimitry Andric// Allow f64 in GPR for ZDINX on RV64.
119*06c3fb27SDimitry Andricdef XLenFVT : ValueTypeByHwMode<[RV64],
120*06c3fb27SDimitry Andric                                [f64]>;
121fe6060f1SDimitry Andricdef XLenRI : RegInfoByHwMode<
122fe6060f1SDimitry Andric      [RV32,              RV64],
123fe6060f1SDimitry Andric      [RegInfo<32,32,32>, RegInfo<64,64,64>]>;
1240b57cec5SDimitry Andric
125*06c3fb27SDimitry Andricclass GPRRegisterClass<dag regList>
126*06c3fb27SDimitry Andric    : RegisterClass<"RISCV", [XLenVT, XLenFVT, i32], 32, regList> {
127*06c3fb27SDimitry Andric  let RegInfos = XLenRI;
128*06c3fb27SDimitry Andric}
129*06c3fb27SDimitry Andric
1300b57cec5SDimitry Andric// The order of registers represents the preferred allocation sequence.
1310b57cec5SDimitry Andric// Registers are listed in the order caller-save, callee-save, specials.
132*06c3fb27SDimitry Andricdef GPR : GPRRegisterClass<(add (sequence "X%u", 10, 17),
1330b57cec5SDimitry Andric                                (sequence "X%u", 5, 7),
1340b57cec5SDimitry Andric                                (sequence "X%u", 28, 31),
1350b57cec5SDimitry Andric                                (sequence "X%u", 8, 9),
1360b57cec5SDimitry Andric                                (sequence "X%u", 18, 27),
137*06c3fb27SDimitry Andric                                (sequence "X%u", 0, 4))>;
1380b57cec5SDimitry Andric
139*06c3fb27SDimitry Andricdef GPRX0 : GPRRegisterClass<(add X0)>;
1408bcb0991SDimitry Andric
141*06c3fb27SDimitry Andricdef GPRNoX0 : GPRRegisterClass<(sub GPR, X0)>;
1420b57cec5SDimitry Andric
143*06c3fb27SDimitry Andricdef GPRNoX0X2 : GPRRegisterClass<(sub GPR, X0, X2)>;
144fe6060f1SDimitry Andric
145fe6060f1SDimitry Andric// Don't use X1 or X5 for JALR since that is a hint to pop the return address
146fe6060f1SDimitry Andric// stack on some microarchitectures. Also remove the reserved registers X0, X2,
147fe6060f1SDimitry Andric// X3, and X4 as it reduces the number of register classes that get synthesized
148fe6060f1SDimitry Andric// by tablegen.
149*06c3fb27SDimitry Andricdef GPRJALR : GPRRegisterClass<(sub GPR, (sequence "X%u", 0, 5))>;
1500b57cec5SDimitry Andric
151*06c3fb27SDimitry Andricdef GPRC : GPRRegisterClass<(add (sequence "X%u", 10, 15),
152*06c3fb27SDimitry Andric                                 (sequence "X%u", 8, 9))>;
1530b57cec5SDimitry Andric
1540b57cec5SDimitry Andric// For indirect tail calls, we can't use callee-saved registers, as they are
1550b57cec5SDimitry Andric// restored to the saved value before the tail call, which would clobber a call
156fe6060f1SDimitry Andric// address. We shouldn't use x5 since that is a hint for to pop the return
157fe6060f1SDimitry Andric// address stack on some microarchitectures.
158*06c3fb27SDimitry Andricdef GPRTC : GPRRegisterClass<(add (sequence "X%u", 6, 7),
1590b57cec5SDimitry Andric                                  (sequence "X%u", 10, 17),
160*06c3fb27SDimitry Andric                                  (sequence "X%u", 28, 31))>;
1610b57cec5SDimitry Andric
162*06c3fb27SDimitry Andricdef SP : GPRRegisterClass<(add X2)>;
163*06c3fb27SDimitry Andric
164*06c3fb27SDimitry Andric// Saved Registers from s0 to s7, for C.MVA01S07 instruction in Zcmp extension
165*06c3fb27SDimitry Andricdef SR07 : GPRRegisterClass<(add (sequence "X%u", 8, 9),
166*06c3fb27SDimitry Andric                                 (sequence "X%u", 18, 23))>;
167*06c3fb27SDimitry Andric
168*06c3fb27SDimitry Andric// Registers saveable by PUSH/POP instruction in Zcmp extension
169*06c3fb27SDimitry Andricdef PGPR : RegisterClass<"RISCV", [XLenVT], 32, (add
170*06c3fb27SDimitry Andric    (sequence "X%u", 8, 9),
171*06c3fb27SDimitry Andric    (sequence "X%u", 18, 27),
172*06c3fb27SDimitry Andric    X1
173*06c3fb27SDimitry Andric  )> {
174fe6060f1SDimitry Andric  let RegInfos = XLenRI;
1750b57cec5SDimitry Andric}
1760b57cec5SDimitry Andric
1770b57cec5SDimitry Andric// Floating point registers
1780b57cec5SDimitry Andriclet RegAltNameIndices = [ABIRegAltName] in {
179e8d8bef9SDimitry Andric  def F0_H  : RISCVReg16<0, "f0", ["ft0"]>, DwarfRegNum<[32]>;
180e8d8bef9SDimitry Andric  def F1_H  : RISCVReg16<1, "f1", ["ft1"]>, DwarfRegNum<[33]>;
181e8d8bef9SDimitry Andric  def F2_H  : RISCVReg16<2, "f2", ["ft2"]>, DwarfRegNum<[34]>;
182e8d8bef9SDimitry Andric  def F3_H  : RISCVReg16<3, "f3", ["ft3"]>, DwarfRegNum<[35]>;
183e8d8bef9SDimitry Andric  def F4_H  : RISCVReg16<4, "f4", ["ft4"]>, DwarfRegNum<[36]>;
184e8d8bef9SDimitry Andric  def F5_H  : RISCVReg16<5, "f5", ["ft5"]>, DwarfRegNum<[37]>;
185e8d8bef9SDimitry Andric  def F6_H  : RISCVReg16<6, "f6", ["ft6"]>, DwarfRegNum<[38]>;
186e8d8bef9SDimitry Andric  def F7_H  : RISCVReg16<7, "f7", ["ft7"]>, DwarfRegNum<[39]>;
187e8d8bef9SDimitry Andric  def F8_H  : RISCVReg16<8, "f8", ["fs0"]>, DwarfRegNum<[40]>;
188e8d8bef9SDimitry Andric  def F9_H  : RISCVReg16<9, "f9", ["fs1"]>, DwarfRegNum<[41]>;
189e8d8bef9SDimitry Andric  def F10_H : RISCVReg16<10,"f10", ["fa0"]>, DwarfRegNum<[42]>;
190e8d8bef9SDimitry Andric  def F11_H : RISCVReg16<11,"f11", ["fa1"]>, DwarfRegNum<[43]>;
191e8d8bef9SDimitry Andric  def F12_H : RISCVReg16<12,"f12", ["fa2"]>, DwarfRegNum<[44]>;
192e8d8bef9SDimitry Andric  def F13_H : RISCVReg16<13,"f13", ["fa3"]>, DwarfRegNum<[45]>;
193e8d8bef9SDimitry Andric  def F14_H : RISCVReg16<14,"f14", ["fa4"]>, DwarfRegNum<[46]>;
194e8d8bef9SDimitry Andric  def F15_H : RISCVReg16<15,"f15", ["fa5"]>, DwarfRegNum<[47]>;
195e8d8bef9SDimitry Andric  def F16_H : RISCVReg16<16,"f16", ["fa6"]>, DwarfRegNum<[48]>;
196e8d8bef9SDimitry Andric  def F17_H : RISCVReg16<17,"f17", ["fa7"]>, DwarfRegNum<[49]>;
197e8d8bef9SDimitry Andric  def F18_H : RISCVReg16<18,"f18", ["fs2"]>, DwarfRegNum<[50]>;
198e8d8bef9SDimitry Andric  def F19_H : RISCVReg16<19,"f19", ["fs3"]>, DwarfRegNum<[51]>;
199e8d8bef9SDimitry Andric  def F20_H : RISCVReg16<20,"f20", ["fs4"]>, DwarfRegNum<[52]>;
200e8d8bef9SDimitry Andric  def F21_H : RISCVReg16<21,"f21", ["fs5"]>, DwarfRegNum<[53]>;
201e8d8bef9SDimitry Andric  def F22_H : RISCVReg16<22,"f22", ["fs6"]>, DwarfRegNum<[54]>;
202e8d8bef9SDimitry Andric  def F23_H : RISCVReg16<23,"f23", ["fs7"]>, DwarfRegNum<[55]>;
203e8d8bef9SDimitry Andric  def F24_H : RISCVReg16<24,"f24", ["fs8"]>, DwarfRegNum<[56]>;
204e8d8bef9SDimitry Andric  def F25_H : RISCVReg16<25,"f25", ["fs9"]>, DwarfRegNum<[57]>;
205e8d8bef9SDimitry Andric  def F26_H : RISCVReg16<26,"f26", ["fs10"]>, DwarfRegNum<[58]>;
206e8d8bef9SDimitry Andric  def F27_H : RISCVReg16<27,"f27", ["fs11"]>, DwarfRegNum<[59]>;
207e8d8bef9SDimitry Andric  def F28_H : RISCVReg16<28,"f28", ["ft8"]>, DwarfRegNum<[60]>;
208e8d8bef9SDimitry Andric  def F29_H : RISCVReg16<29,"f29", ["ft9"]>, DwarfRegNum<[61]>;
209e8d8bef9SDimitry Andric  def F30_H : RISCVReg16<30,"f30", ["ft10"]>, DwarfRegNum<[62]>;
210e8d8bef9SDimitry Andric  def F31_H : RISCVReg16<31,"f31", ["ft11"]>, DwarfRegNum<[63]>;
211e8d8bef9SDimitry Andric
212e8d8bef9SDimitry Andric  foreach Index = 0-31 in {
213e8d8bef9SDimitry Andric    def F#Index#_F : RISCVReg32<!cast<RISCVReg16>("F"#Index#"_H")>,
214e8d8bef9SDimitry Andric      DwarfRegNum<[!add(Index, 32)]>;
215e8d8bef9SDimitry Andric  }
2160b57cec5SDimitry Andric
2170b57cec5SDimitry Andric  foreach Index = 0-31 in {
2188bcb0991SDimitry Andric    def F#Index#_D : RISCVReg64<!cast<RISCVReg32>("F"#Index#"_F")>,
2190b57cec5SDimitry Andric      DwarfRegNum<[!add(Index, 32)]>;
2200b57cec5SDimitry Andric  }
2210b57cec5SDimitry Andric}
2220b57cec5SDimitry Andric
2230b57cec5SDimitry Andric// The order of registers represents the preferred allocation sequence,
2240b57cec5SDimitry Andric// meaning caller-save regs are listed before callee-save.
225*06c3fb27SDimitry Andric// We start by allocating argument registers in reverse order since they are
226*06c3fb27SDimitry Andric// compressible.
227*06c3fb27SDimitry Andricdef FPR16 : RegisterClass<"RISCV", [f16, bf16], 16, (add
228*06c3fb27SDimitry Andric    (sequence "F%u_H", 15, 10), // fa5-fa0
229*06c3fb27SDimitry Andric    (sequence "F%u_H", 0, 7),   // ft0-f7
230*06c3fb27SDimitry Andric    (sequence "F%u_H", 16, 17), // fa6-fa7
231*06c3fb27SDimitry Andric    (sequence "F%u_H", 28, 31), // ft8-ft11
232*06c3fb27SDimitry Andric    (sequence "F%u_H", 8, 9),   // fs0-fs1
233*06c3fb27SDimitry Andric    (sequence "F%u_H", 18, 27)  // fs2-fs11
234e8d8bef9SDimitry Andric)>;
235e8d8bef9SDimitry Andric
2360b57cec5SDimitry Andricdef FPR32 : RegisterClass<"RISCV", [f32], 32, (add
237*06c3fb27SDimitry Andric    (sequence "F%u_F", 15, 10),
2388bcb0991SDimitry Andric    (sequence "F%u_F", 0, 7),
239*06c3fb27SDimitry Andric    (sequence "F%u_F", 16, 17),
2408bcb0991SDimitry Andric    (sequence "F%u_F", 28, 31),
2418bcb0991SDimitry Andric    (sequence "F%u_F", 8, 9),
2428bcb0991SDimitry Andric    (sequence "F%u_F", 18, 27)
2430b57cec5SDimitry Andric)>;
2440b57cec5SDimitry Andric
2450b57cec5SDimitry Andricdef FPR32C : RegisterClass<"RISCV", [f32], 32, (add
246*06c3fb27SDimitry Andric  (sequence "F%u_F", 15, 10),
2478bcb0991SDimitry Andric  (sequence "F%u_F", 8, 9)
2480b57cec5SDimitry Andric)>;
2490b57cec5SDimitry Andric
2500b57cec5SDimitry Andric// The order of registers represents the preferred allocation sequence,
2510b57cec5SDimitry Andric// meaning caller-save regs are listed before callee-save.
2520b57cec5SDimitry Andricdef FPR64 : RegisterClass<"RISCV", [f64], 64, (add
253*06c3fb27SDimitry Andric    (sequence "F%u_D", 15, 10),
2548bcb0991SDimitry Andric    (sequence "F%u_D", 0, 7),
255*06c3fb27SDimitry Andric    (sequence "F%u_D", 16, 17),
2568bcb0991SDimitry Andric    (sequence "F%u_D", 28, 31),
2578bcb0991SDimitry Andric    (sequence "F%u_D", 8, 9),
2588bcb0991SDimitry Andric    (sequence "F%u_D", 18, 27)
2590b57cec5SDimitry Andric)>;
2600b57cec5SDimitry Andric
2610b57cec5SDimitry Andricdef FPR64C : RegisterClass<"RISCV", [f64], 64, (add
262*06c3fb27SDimitry Andric  (sequence "F%u_D", 15, 10),
2638bcb0991SDimitry Andric  (sequence "F%u_D", 8, 9)
2640b57cec5SDimitry Andric)>;
2655ffd83dbSDimitry Andric
266e8d8bef9SDimitry Andric// Vector type mapping to LLVM types.
267e8d8bef9SDimitry Andric//
268fe6060f1SDimitry Andric// The V vector extension requires that VLEN >= 128 and <= 65536.
269e8d8bef9SDimitry Andric// Additionally, the only supported ELEN values are 32 and 64,
270e8d8bef9SDimitry Andric// thus `vscale` can be defined as VLEN/64,
271e8d8bef9SDimitry Andric// allowing the same types with either ELEN value.
272e8d8bef9SDimitry Andric//
273e8d8bef9SDimitry Andric//         MF8    MF4     MF2     M1      M2      M4       M8
274e8d8bef9SDimitry Andric// i64*    N/A    N/A     N/A     nxv1i64 nxv2i64 nxv4i64  nxv8i64
275e8d8bef9SDimitry Andric// i32     N/A    N/A     nxv1i32 nxv2i32 nxv4i32 nxv8i32  nxv16i32
276e8d8bef9SDimitry Andric// i16     N/A    nxv1i16 nxv2i16 nxv4i16 nxv8i16 nxv16i16 nxv32i16
277e8d8bef9SDimitry Andric// i8      nxv1i8 nxv2i8  nxv4i8  nxv8i8  nxv16i8 nxv32i8  nxv64i8
278e8d8bef9SDimitry Andric// double* N/A    N/A     N/A     nxv1f64 nxv2f64 nxv4f64  nxv8f64
279e8d8bef9SDimitry Andric// float   N/A    N/A     nxv1f32 nxv2f32 nxv4f32 nxv8f32  nxv16f32
280e8d8bef9SDimitry Andric// half    N/A    nxv1f16 nxv2f16 nxv4f16 nxv8f16 nxv16f16 nxv32f16
281e8d8bef9SDimitry Andric// * ELEN=64
282e8d8bef9SDimitry Andric
283e8d8bef9SDimitry Andricdefvar vint8mf8_t = nxv1i8;
284e8d8bef9SDimitry Andricdefvar vint8mf4_t = nxv2i8;
285e8d8bef9SDimitry Andricdefvar vint8mf2_t = nxv4i8;
286e8d8bef9SDimitry Andricdefvar vint8m1_t = nxv8i8;
287e8d8bef9SDimitry Andricdefvar vint8m2_t = nxv16i8;
288e8d8bef9SDimitry Andricdefvar vint8m4_t = nxv32i8;
289e8d8bef9SDimitry Andricdefvar vint8m8_t = nxv64i8;
290e8d8bef9SDimitry Andric
291e8d8bef9SDimitry Andricdefvar vint16mf4_t = nxv1i16;
292e8d8bef9SDimitry Andricdefvar vint16mf2_t = nxv2i16;
293e8d8bef9SDimitry Andricdefvar vint16m1_t  = nxv4i16;
294e8d8bef9SDimitry Andricdefvar vint16m2_t  = nxv8i16;
295e8d8bef9SDimitry Andricdefvar vint16m4_t  = nxv16i16;
296e8d8bef9SDimitry Andricdefvar vint16m8_t  = nxv32i16;
297e8d8bef9SDimitry Andric
298e8d8bef9SDimitry Andricdefvar vint32mf2_t = nxv1i32;
299e8d8bef9SDimitry Andricdefvar vint32m1_t  = nxv2i32;
300e8d8bef9SDimitry Andricdefvar vint32m2_t  = nxv4i32;
301e8d8bef9SDimitry Andricdefvar vint32m4_t  = nxv8i32;
302e8d8bef9SDimitry Andricdefvar vint32m8_t  = nxv16i32;
303e8d8bef9SDimitry Andric
304e8d8bef9SDimitry Andricdefvar vint64m1_t = nxv1i64;
305e8d8bef9SDimitry Andricdefvar vint64m2_t = nxv2i64;
306e8d8bef9SDimitry Andricdefvar vint64m4_t = nxv4i64;
307e8d8bef9SDimitry Andricdefvar vint64m8_t = nxv8i64;
308e8d8bef9SDimitry Andric
309e8d8bef9SDimitry Andricdefvar vfloat16mf4_t = nxv1f16;
310e8d8bef9SDimitry Andricdefvar vfloat16mf2_t = nxv2f16;
311e8d8bef9SDimitry Andricdefvar vfloat16m1_t  = nxv4f16;
312e8d8bef9SDimitry Andricdefvar vfloat16m2_t  = nxv8f16;
313e8d8bef9SDimitry Andricdefvar vfloat16m4_t  = nxv16f16;
314e8d8bef9SDimitry Andricdefvar vfloat16m8_t  = nxv32f16;
315e8d8bef9SDimitry Andric
316e8d8bef9SDimitry Andricdefvar vfloat32mf2_t = nxv1f32;
317e8d8bef9SDimitry Andricdefvar vfloat32m1_t  = nxv2f32;
318e8d8bef9SDimitry Andricdefvar vfloat32m2_t  = nxv4f32;
319e8d8bef9SDimitry Andricdefvar vfloat32m4_t  = nxv8f32;
320e8d8bef9SDimitry Andricdefvar vfloat32m8_t  = nxv16f32;
321e8d8bef9SDimitry Andric
322e8d8bef9SDimitry Andricdefvar vfloat64m1_t = nxv1f64;
323e8d8bef9SDimitry Andricdefvar vfloat64m2_t = nxv2f64;
324e8d8bef9SDimitry Andricdefvar vfloat64m4_t = nxv4f64;
325e8d8bef9SDimitry Andricdefvar vfloat64m8_t = nxv8f64;
326e8d8bef9SDimitry Andric
327e8d8bef9SDimitry Andricdefvar vbool1_t  = nxv64i1;
328e8d8bef9SDimitry Andricdefvar vbool2_t  = nxv32i1;
329e8d8bef9SDimitry Andricdefvar vbool4_t  = nxv16i1;
330e8d8bef9SDimitry Andricdefvar vbool8_t  = nxv8i1;
331e8d8bef9SDimitry Andricdefvar vbool16_t = nxv4i1;
332e8d8bef9SDimitry Andricdefvar vbool32_t = nxv2i1;
333e8d8bef9SDimitry Andricdefvar vbool64_t = nxv1i1;
334e8d8bef9SDimitry Andric
335e8d8bef9SDimitry Andric// There is no need to define register classes for fractional LMUL.
336*06c3fb27SDimitry Andricdefvar LMULList = [1, 2, 4, 8];
337e8d8bef9SDimitry Andric
338e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
339e8d8bef9SDimitry Andric// Utility classes for segment load/store.
340e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
341e8d8bef9SDimitry Andric// The set of legal NF for LMUL = lmul.
342e8d8bef9SDimitry Andric// LMUL == 1, NF = 2, 3, 4, 5, 6, 7, 8
343e8d8bef9SDimitry Andric// LMUL == 2, NF = 2, 3, 4
344e8d8bef9SDimitry Andric// LMUL == 4, NF = 2
345e8d8bef9SDimitry Andricclass NFList<int lmul> {
346e8d8bef9SDimitry Andric  list<int> L = !cond(!eq(lmul, 1): [2, 3, 4, 5, 6, 7, 8],
347e8d8bef9SDimitry Andric                      !eq(lmul, 2): [2, 3, 4],
348e8d8bef9SDimitry Andric                      !eq(lmul, 4): [2],
349e8d8bef9SDimitry Andric                      !eq(lmul, 8): []);
350e8d8bef9SDimitry Andric}
351e8d8bef9SDimitry Andric
352e8d8bef9SDimitry Andric// Generate [start, end) SubRegIndex list.
353349cc55cSDimitry Andricclass SubRegSet<int nf, int lmul> {
354e8d8bef9SDimitry Andric  list<SubRegIndex> L = !foldl([]<SubRegIndex>,
355e8d8bef9SDimitry Andric                               [0, 1, 2, 3, 4, 5, 6, 7],
356e8d8bef9SDimitry Andric                               AccList, i,
357e8d8bef9SDimitry Andric                               !listconcat(AccList,
358e8d8bef9SDimitry Andric                                 !if(!lt(i, nf),
359e8d8bef9SDimitry Andric                                   [!cast<SubRegIndex>("sub_vrm" # lmul # "_" # i)],
360e8d8bef9SDimitry Andric                                   [])));
361e8d8bef9SDimitry Andric}
362e8d8bef9SDimitry Andric
363349cc55cSDimitry Andric// Collect the valid indexes into 'R' under NF and LMUL values from TUPLE_INDEX.
364349cc55cSDimitry Andric// When NF = 2, the valid TUPLE_INDEX is 0 and 1.
365349cc55cSDimitry Andric// For example, when LMUL = 4, the potential valid indexes is
366349cc55cSDimitry Andric// [8, 12, 16, 20, 24, 28, 4]. However, not all these indexes are valid under
367349cc55cSDimitry Andric// NF = 2. For example, 28 is not valid under LMUL = 4, NF = 2 and TUPLE_INDEX = 0.
368349cc55cSDimitry Andric// The filter is
369349cc55cSDimitry Andric//   (tuple_index + i) x lmul <= (tuple_index x lmul) + 32 - (nf x lmul)
370349cc55cSDimitry Andric//
371349cc55cSDimitry Andric// Use START = 0, LMUL = 4 and NF = 2 as the example,
372349cc55cSDimitry Andric//   i x 4 <= 24
373349cc55cSDimitry Andric// The class will return [8, 12, 16, 20, 24, 4].
374349cc55cSDimitry Andric// Use START = 1, LMUL = 4 and NF = 2 as the example,
375349cc55cSDimitry Andric//   (1 + i) x 4 <= 28
376349cc55cSDimitry Andric// The class will return [12, 16, 20, 24, 28, 8].
377349cc55cSDimitry Andric//
378349cc55cSDimitry Andricclass IndexSet<int tuple_index, int nf, int lmul, bit isV0 = false> {
379e8d8bef9SDimitry Andric  list<int> R =
380e8d8bef9SDimitry Andric    !foldl([]<int>,
381349cc55cSDimitry Andric              !if(isV0, [0],
382349cc55cSDimitry Andric                !cond(
383349cc55cSDimitry Andric                  !eq(lmul, 1):
384349cc55cSDimitry Andric                  [8, 9, 10, 11, 12, 13, 14, 15,
385349cc55cSDimitry Andric                   16, 17, 18, 19, 20, 21, 22, 23,
386349cc55cSDimitry Andric                   24, 25, 26, 27, 28, 29, 30, 31,
387349cc55cSDimitry Andric                   1, 2, 3, 4, 5, 6, 7],
388349cc55cSDimitry Andric                  !eq(lmul, 2):
389349cc55cSDimitry Andric                  [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3],
390349cc55cSDimitry Andric                  !eq(lmul, 4):
391349cc55cSDimitry Andric                  [2, 3, 4, 5, 6, 7, 1])),
392e8d8bef9SDimitry Andric              L, i,
393e8d8bef9SDimitry Andric              !listconcat(L,
394349cc55cSDimitry Andric                          !if(!le(!mul(!add(i, tuple_index), lmul),
395349cc55cSDimitry Andric                                  !sub(!add(32, !mul(tuple_index, lmul)), !mul(nf, lmul))),
396349cc55cSDimitry Andric                              [!mul(!add(i, tuple_index), lmul)], [])));
397e8d8bef9SDimitry Andric}
398e8d8bef9SDimitry Andric
399349cc55cSDimitry Andric// This class returns a list of vector register collections.
400349cc55cSDimitry Andric// For example, for NF = 2 and LMUL = 4,
401349cc55cSDimitry Andric// it will return
402349cc55cSDimitry Andric//   ([ V8M4, V12M4, V16M4, V20M4, V24M4, V4M4],
403349cc55cSDimitry Andric//    [V12M4, V16M4, V20M4, V24M4, V28M4, V8M4])
404349cc55cSDimitry Andric//
405349cc55cSDimitry Andricclass VRegList<list<dag> LIn, int start, int nf, int lmul, bit isV0> {
406e8d8bef9SDimitry Andric  list<dag> L =
407e8d8bef9SDimitry Andric    !if(!ge(start, nf),
408e8d8bef9SDimitry Andric        LIn,
409e8d8bef9SDimitry Andric        !listconcat(
410e8d8bef9SDimitry Andric          [!dag(add,
411349cc55cSDimitry Andric                !foreach(i, IndexSet<start, nf, lmul, isV0>.R,
412e8d8bef9SDimitry Andric                  !cast<Register>("V" # i # !cond(!eq(lmul, 2): "M2",
413e8d8bef9SDimitry Andric                                                  !eq(lmul, 4): "M4",
414e8d8bef9SDimitry Andric                                                  true: ""))),
415fe6060f1SDimitry Andric                !listsplat("",
416349cc55cSDimitry Andric                  !size(IndexSet<start, nf, lmul, isV0>.R)))],
417349cc55cSDimitry Andric          VRegList<LIn, !add(start, 1), nf, lmul, isV0>.L));
418e8d8bef9SDimitry Andric}
419e8d8bef9SDimitry Andric
4205ffd83dbSDimitry Andric// Vector registers
4215ffd83dbSDimitry Andricforeach Index = 0-31 in {
422*06c3fb27SDimitry Andric  def V#Index : RISCVReg<Index, "v"#Index>, DwarfRegNum<[!add(Index, 96)]>;
4235ffd83dbSDimitry Andric}
4245ffd83dbSDimitry Andric
4255ffd83dbSDimitry Andricforeach Index = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22,
4265ffd83dbSDimitry Andric                 24, 26, 28, 30] in {
4275ffd83dbSDimitry Andric  def V#Index#M2 : RISCVRegWithSubRegs<Index, "v"#Index,
4285ffd83dbSDimitry Andric                     [!cast<Register>("V"#Index),
429*06c3fb27SDimitry Andric                      !cast<Register>("V"#!add(Index, 1))]>,
4305ffd83dbSDimitry Andric                   DwarfRegAlias<!cast<Register>("V"#Index)> {
431e8d8bef9SDimitry Andric    let SubRegIndices = [sub_vrm1_0, sub_vrm1_1];
4325ffd83dbSDimitry Andric  }
4335ffd83dbSDimitry Andric}
4345ffd83dbSDimitry Andric
4355ffd83dbSDimitry Andricforeach Index = [0, 4, 8, 12, 16, 20, 24, 28] in {
4365ffd83dbSDimitry Andric  def V#Index#M4 : RISCVRegWithSubRegs<Index, "v"#Index,
4375ffd83dbSDimitry Andric                     [!cast<Register>("V"#Index#"M2"),
438*06c3fb27SDimitry Andric                      !cast<Register>("V"#!add(Index, 2)#"M2")]>,
4395ffd83dbSDimitry Andric                   DwarfRegAlias<!cast<Register>("V"#Index)> {
440e8d8bef9SDimitry Andric    let SubRegIndices = [sub_vrm2_0, sub_vrm2_1];
4415ffd83dbSDimitry Andric  }
4425ffd83dbSDimitry Andric}
4435ffd83dbSDimitry Andric
4445ffd83dbSDimitry Andricforeach Index = [0, 8, 16, 24] in {
4455ffd83dbSDimitry Andric  def V#Index#M8 : RISCVRegWithSubRegs<Index, "v"#Index,
4465ffd83dbSDimitry Andric                     [!cast<Register>("V"#Index#"M4"),
447*06c3fb27SDimitry Andric                      !cast<Register>("V"#!add(Index, 4)#"M4")]>,
4485ffd83dbSDimitry Andric                   DwarfRegAlias<!cast<Register>("V"#Index)> {
449e8d8bef9SDimitry Andric    let SubRegIndices = [sub_vrm4_0, sub_vrm4_1];
4505ffd83dbSDimitry Andric  }
4515ffd83dbSDimitry Andric}
4525ffd83dbSDimitry Andric
453*06c3fb27SDimitry Andricdef VTYPE  : RISCVReg<0, "vtype">;
454*06c3fb27SDimitry Andricdef VL     : RISCVReg<0, "vl">;
455*06c3fb27SDimitry Andricdef VXSAT  : RISCVReg<0, "vxsat">;
456*06c3fb27SDimitry Andricdef VXRM   : RISCVReg<0, "vxrm">;
457bdd1243dSDimitry Andriclet isConstant = true in
458*06c3fb27SDimitry Andricdef VLENB  : RISCVReg<0, "vlenb">,
4594824e7fdSDimitry Andric             DwarfRegNum<[!add(4096, SysRegVLENB.Encoding)]>;
4605ffd83dbSDimitry Andric
46181ad6265SDimitry Andricdef VCSR : RegisterClass<"RISCV", [XLenVT], 32,
46281ad6265SDimitry Andric                          (add VTYPE, VL, VLENB)> {
46381ad6265SDimitry Andric  let RegInfos = XLenRI;
46481ad6265SDimitry Andric}
46581ad6265SDimitry Andric
46681ad6265SDimitry Andric
467e8d8bef9SDimitry Andricforeach m = [1, 2, 4] in {
468e8d8bef9SDimitry Andric  foreach n = NFList<m>.L in {
469fe6060f1SDimitry Andric    def "VN" # n # "M" # m # "NoV0": RegisterTuples<
470349cc55cSDimitry Andric                                       SubRegSet<n, m>.L,
471349cc55cSDimitry Andric                                       VRegList<[], 0, n, m, false>.L>;
472fe6060f1SDimitry Andric    def "VN" # n # "M" # m # "V0" : RegisterTuples<
473349cc55cSDimitry Andric                                       SubRegSet<n, m>.L,
474349cc55cSDimitry Andric                                       VRegList<[], 0, n, m, true>.L>;
475e8d8bef9SDimitry Andric  }
4765ffd83dbSDimitry Andric}
4775ffd83dbSDimitry Andric
478e8d8bef9SDimitry Andricclass VReg<list<ValueType> regTypes, dag regList, int Vlmul>
479e8d8bef9SDimitry Andric  : RegisterClass<"RISCV",
480e8d8bef9SDimitry Andric                  regTypes,
481e8d8bef9SDimitry Andric                  64, // The maximum supported ELEN is 64.
482e8d8bef9SDimitry Andric                  regList> {
483e8d8bef9SDimitry Andric  int VLMul = Vlmul;
484e8d8bef9SDimitry Andric  int Size = !mul(Vlmul, 64);
485e8d8bef9SDimitry Andric}
486e8d8bef9SDimitry Andric
487bdd1243dSDimitry Andricdefvar VMaskVTs = [vbool1_t, vbool2_t, vbool4_t, vbool8_t, vbool16_t,
488bdd1243dSDimitry Andric                   vbool32_t, vbool64_t];
489bdd1243dSDimitry Andric
490bdd1243dSDimitry Andricdefvar VM1VTs = [vint8m1_t, vint16m1_t, vint32m1_t, vint64m1_t,
491fe6060f1SDimitry Andric                 vfloat16m1_t, vfloat32m1_t, vfloat64m1_t,
492fe6060f1SDimitry Andric                 vint8mf2_t, vint8mf4_t, vint8mf8_t,
493e8d8bef9SDimitry Andric                 vint16mf2_t, vint16mf4_t, vint32mf2_t,
494bdd1243dSDimitry Andric                 vfloat16mf4_t, vfloat16mf2_t, vfloat32mf2_t];
495bdd1243dSDimitry Andric
496bdd1243dSDimitry Andricdefvar VM2VTs = [vint8m2_t, vint16m2_t, vint32m2_t, vint64m2_t,
497bdd1243dSDimitry Andric                 vfloat16m2_t, vfloat32m2_t, vfloat64m2_t];
498bdd1243dSDimitry Andric
499bdd1243dSDimitry Andricdefvar VM4VTs = [vint8m4_t, vint16m4_t, vint32m4_t, vint64m4_t,
500bdd1243dSDimitry Andric                 vfloat16m4_t, vfloat32m4_t, vfloat64m4_t];
501bdd1243dSDimitry Andric
502bdd1243dSDimitry Andricdefvar VM8VTs = [vint8m8_t, vint16m8_t, vint32m8_t, vint64m8_t,
503bdd1243dSDimitry Andric                 vfloat16m8_t, vfloat32m8_t, vfloat64m8_t];
504bdd1243dSDimitry Andric
505bdd1243dSDimitry Andricdef VR : VReg<!listconcat(VM1VTs, VMaskVTs),
506349cc55cSDimitry Andric              (add (sequence "V%u", 8, 31),
507e8d8bef9SDimitry Andric                   (sequence "V%u", 0, 7)), 1>;
5085ffd83dbSDimitry Andric
509bdd1243dSDimitry Andricdef VRNoV0 : VReg<!listconcat(VM1VTs, VMaskVTs),
510349cc55cSDimitry Andric                  (add (sequence "V%u", 8, 31),
511e8d8bef9SDimitry Andric                       (sequence "V%u", 1, 7)), 1>;
512e8d8bef9SDimitry Andric
513bdd1243dSDimitry Andricdef VRM2 : VReg<VM2VTs, (add (sequence "V%uM2", 8, 31, 2),
514349cc55cSDimitry Andric                             (sequence "V%uM2", 0, 7, 2)), 2>;
5155ffd83dbSDimitry Andric
516bdd1243dSDimitry Andricdef VRM2NoV0 : VReg<VM2VTs, (add (sequence "V%uM2", 8, 31, 2),
517349cc55cSDimitry Andric                                 (sequence "V%uM2", 2, 7, 2)), 2>;
5185ffd83dbSDimitry Andric
519bdd1243dSDimitry Andricdef VRM4 : VReg<VM4VTs,
520349cc55cSDimitry Andric             (add V8M4, V12M4, V16M4, V20M4, V24M4, V28M4, V0M4, V4M4), 4>;
5215ffd83dbSDimitry Andric
522bdd1243dSDimitry Andricdef VRM4NoV0 : VReg<VM4VTs,
523349cc55cSDimitry Andric             (add V8M4, V12M4, V16M4, V20M4, V24M4, V28M4, V4M4), 4>;
5245ffd83dbSDimitry Andric
525bdd1243dSDimitry Andricdef VRM8 : VReg<VM8VTs, (add V8M8, V16M8, V24M8, V0M8), 8>;
526e8d8bef9SDimitry Andric
527bdd1243dSDimitry Andricdef VRM8NoV0 : VReg<VM8VTs, (add V8M8, V16M8, V24M8), 8>;
528e8d8bef9SDimitry Andric
529e8d8bef9SDimitry Andricdef VMV0 : RegisterClass<"RISCV", VMaskVTs, 64, (add V0)> {
5305ffd83dbSDimitry Andric  let Size = 64;
5315ffd83dbSDimitry Andric}
5325ffd83dbSDimitry Andric
533d56accc7SDimitry Andriclet RegInfos = XLenRI in {
534d56accc7SDimitry Andricdef GPRF16  : RegisterClass<"RISCV", [f16], 16, (add GPR)>;
535d56accc7SDimitry Andricdef GPRF32  : RegisterClass<"RISCV", [f32], 32, (add GPR)>;
536d56accc7SDimitry Andric} // RegInfos = XLenRI
537d56accc7SDimitry Andric
538*06c3fb27SDimitry Andric// Dummy zero register for use in the register pair containing X0 (as X1 is
539*06c3fb27SDimitry Andric// not read to or written when the X0 register pair is used).
540*06c3fb27SDimitry Andricdef DUMMY_REG_PAIR_WITH_X0 : RISCVReg<0, "0">;
541*06c3fb27SDimitry Andric
542*06c3fb27SDimitry Andric// Must add DUMMY_REG_PAIR_WITH_X0 to a separate register class to prevent the
543*06c3fb27SDimitry Andric// register's existence from changing codegen (due to the regPressureSetLimit
544*06c3fb27SDimitry Andric// for the GPR register class being altered).
545*06c3fb27SDimitry Andricdef GPRAll : GPRRegisterClass<(add GPR, DUMMY_REG_PAIR_WITH_X0)>;
546*06c3fb27SDimitry Andric
547d56accc7SDimitry Andriclet RegAltNameIndices = [ABIRegAltName] in {
548*06c3fb27SDimitry Andric  def X0_PD : RISCVRegWithSubRegs<0, X0.AsmName,
549*06c3fb27SDimitry Andric                                     [X0, DUMMY_REG_PAIR_WITH_X0],
550*06c3fb27SDimitry Andric                                     X0.AltNames> {
551*06c3fb27SDimitry Andric    let SubRegIndices = [sub_32, sub_32_hi];
552*06c3fb27SDimitry Andric    let CoveredBySubRegs = 1;
553*06c3fb27SDimitry Andric  }
554*06c3fb27SDimitry Andric  foreach I = 1-15 in {
555*06c3fb27SDimitry Andric    defvar Index = !shl(I, 1);
556d56accc7SDimitry Andric    defvar Reg = !cast<Register>("X"#Index);
557*06c3fb27SDimitry Andric    defvar RegP1 = !cast<Register>("X"#!add(Index,1));
558d56accc7SDimitry Andric    def X#Index#_PD : RISCVRegWithSubRegs<Index, Reg.AsmName,
559*06c3fb27SDimitry Andric                                          [Reg, RegP1],
560d56accc7SDimitry Andric                                          Reg.AltNames> {
561d56accc7SDimitry Andric      let SubRegIndices = [sub_32, sub_32_hi];
562*06c3fb27SDimitry Andric      let CoveredBySubRegs = 1;
563d56accc7SDimitry Andric    }
564d56accc7SDimitry Andric  }
565d56accc7SDimitry Andric}
566d56accc7SDimitry Andric
567d56accc7SDimitry Andriclet RegInfos = RegInfoByHwMode<[RV64], [RegInfo<64, 64, 64>]> in
568d56accc7SDimitry Andricdef GPRPF64 : RegisterClass<"RISCV", [f64], 64, (add
569d56accc7SDimitry Andric    X10_PD, X12_PD, X14_PD, X16_PD,
570d56accc7SDimitry Andric    X6_PD,
571d56accc7SDimitry Andric    X28_PD, X30_PD,
572d56accc7SDimitry Andric    X8_PD,
573d56accc7SDimitry Andric    X18_PD, X20_PD, X22_PD, X24_PD, X26_PD,
574d56accc7SDimitry Andric    X0_PD, X2_PD, X4_PD
575d56accc7SDimitry Andric)>;
576d56accc7SDimitry Andric
577fe6060f1SDimitry Andric// The register class is added for inline assembly for vector mask types.
5780eae32dcSDimitry Andricdef VM : VReg<VMaskVTs,
579349cc55cSDimitry Andric           (add (sequence "V%u", 8, 31),
580fe6060f1SDimitry Andric                (sequence "V%u", 0, 7)), 1>;
581fe6060f1SDimitry Andric
582*06c3fb27SDimitry Andricforeach m = LMULList in {
583e8d8bef9SDimitry Andric  foreach nf = NFList<m>.L in {
584fe6060f1SDimitry Andric    def "VRN" # nf # "M" # m # "NoV0": VReg<[untyped],
585fe6060f1SDimitry Andric                               (add !cast<RegisterTuples>("VN" # nf # "M" # m # "NoV0")),
586e8d8bef9SDimitry Andric                                    !mul(nf, m)>;
587349cc55cSDimitry Andric    def "VRN" # nf # "M" # m: VReg<[untyped],
588349cc55cSDimitry Andric                               (add !cast<RegisterTuples>("VN" # nf # "M" # m # "NoV0"),
589349cc55cSDimitry Andric                                    !cast<RegisterTuples>("VN" # nf # "M" # m # "V0")),
590349cc55cSDimitry Andric                                    !mul(nf, m)>;
591e8d8bef9SDimitry Andric  }
5925ffd83dbSDimitry Andric}
593fe6060f1SDimitry Andric
594fe6060f1SDimitry Andric// Special registers
595fe6060f1SDimitry Andricdef FFLAGS : RISCVReg<0, "fflags">;
596fe6060f1SDimitry Andricdef FRM    : RISCVReg<0, "frm">;
597