xref: /freebsd/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVRegisterInfo.td (revision 5ffd83dbcc34f10e07f6d3e968ae6365869615f4)
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
190b57cec5SDimitry Andricclass RISCVReg32<bits<5> Enc, string n, list<string> alt = []> : Register<n> {
200b57cec5SDimitry Andric  let HWEncoding{4-0} = Enc;
210b57cec5SDimitry Andric  let AltNames = alt;
220b57cec5SDimitry Andric}
230b57cec5SDimitry Andric
240b57cec5SDimitry Andric// Because RISCVReg64 register have AsmName and AltNames that alias with their
250b57cec5SDimitry Andric// 32-bit sub-register, RISCVAsmParser will need to coerce a register number
260b57cec5SDimitry Andric// from a RISCVReg32 to the equivalent RISCVReg64 when appropriate.
270b57cec5SDimitry Andricdef sub_32 : SubRegIndex<32>;
280b57cec5SDimitry Andricclass RISCVReg64<RISCVReg32 subreg> : Register<""> {
290b57cec5SDimitry Andric  let HWEncoding{4-0} = subreg.HWEncoding{4-0};
300b57cec5SDimitry Andric  let SubRegs = [subreg];
310b57cec5SDimitry Andric  let SubRegIndices = [sub_32];
320b57cec5SDimitry Andric  let AsmName = subreg.AsmName;
330b57cec5SDimitry Andric  let AltNames = subreg.AltNames;
340b57cec5SDimitry Andric}
350b57cec5SDimitry Andric
36*5ffd83dbSDimitry Andricclass RISCVRegWithSubRegs<bits<5> Enc, string n, list<Register> subregs,
37*5ffd83dbSDimitry Andric                          list<string> alt = []>
38*5ffd83dbSDimitry Andric      : RegisterWithSubRegs<n, subregs> {
39*5ffd83dbSDimitry Andric  let HWEncoding{4-0} = Enc;
40*5ffd83dbSDimitry Andric  let AltNames = alt;
41*5ffd83dbSDimitry Andric}
42*5ffd83dbSDimitry Andric
430b57cec5SDimitry Andricdef ABIRegAltName : RegAltNameIndex;
44*5ffd83dbSDimitry Andric
45*5ffd83dbSDimitry Andricdef sub_vrm2    : SubRegIndex<64, -1>;
46*5ffd83dbSDimitry Andricdef sub_vrm2_hi : SubRegIndex<64, -1>;
47*5ffd83dbSDimitry Andricdef sub_vrm4    : SubRegIndex<128, -1>;
48*5ffd83dbSDimitry Andricdef sub_vrm4_hi : SubRegIndex<128, -1>;
49*5ffd83dbSDimitry Andricdef sub_vrm8    : SubRegIndex<256, -1>;
50*5ffd83dbSDimitry Andricdef sub_vrm8_hi : SubRegIndex<256, -1>;
510b57cec5SDimitry Andric} // Namespace = "RISCV"
520b57cec5SDimitry Andric
530b57cec5SDimitry Andric// Integer registers
540b57cec5SDimitry Andric// CostPerUse is set higher for registers that may not be compressible as they
550b57cec5SDimitry Andric// are not part of GPRC, the most restrictive register class used by the
560b57cec5SDimitry Andric// compressed instruction set. This will influence the greedy register
570b57cec5SDimitry Andric// allocator to reduce the use of registers that can't be encoded in 16 bit
580b57cec5SDimitry Andric// instructions. This affects register allocation even when compressed
590b57cec5SDimitry Andric// instruction isn't targeted, we see no major negative codegen impact.
600b57cec5SDimitry Andric
610b57cec5SDimitry Andriclet RegAltNameIndices = [ABIRegAltName] in {
620b57cec5SDimitry Andric  def X0  : RISCVReg<0, "x0", ["zero"]>, DwarfRegNum<[0]>;
630b57cec5SDimitry Andric  let CostPerUse = 1 in {
640b57cec5SDimitry Andric  def X1  : RISCVReg<1, "x1", ["ra"]>, DwarfRegNum<[1]>;
650b57cec5SDimitry Andric  def X2  : RISCVReg<2, "x2", ["sp"]>, DwarfRegNum<[2]>;
660b57cec5SDimitry Andric  def X3  : RISCVReg<3, "x3", ["gp"]>, DwarfRegNum<[3]>;
670b57cec5SDimitry Andric  def X4  : RISCVReg<4, "x4", ["tp"]>, DwarfRegNum<[4]>;
680b57cec5SDimitry Andric  def X5  : RISCVReg<5, "x5", ["t0"]>, DwarfRegNum<[5]>;
690b57cec5SDimitry Andric  def X6  : RISCVReg<6, "x6", ["t1"]>, DwarfRegNum<[6]>;
700b57cec5SDimitry Andric  def X7  : RISCVReg<7, "x7", ["t2"]>, DwarfRegNum<[7]>;
710b57cec5SDimitry Andric  }
720b57cec5SDimitry Andric  def X8  : RISCVReg<8, "x8", ["s0", "fp"]>, DwarfRegNum<[8]>;
730b57cec5SDimitry Andric  def X9  : RISCVReg<9, "x9", ["s1"]>, DwarfRegNum<[9]>;
740b57cec5SDimitry Andric  def X10 : RISCVReg<10,"x10", ["a0"]>, DwarfRegNum<[10]>;
750b57cec5SDimitry Andric  def X11 : RISCVReg<11,"x11", ["a1"]>, DwarfRegNum<[11]>;
760b57cec5SDimitry Andric  def X12 : RISCVReg<12,"x12", ["a2"]>, DwarfRegNum<[12]>;
770b57cec5SDimitry Andric  def X13 : RISCVReg<13,"x13", ["a3"]>, DwarfRegNum<[13]>;
780b57cec5SDimitry Andric  def X14 : RISCVReg<14,"x14", ["a4"]>, DwarfRegNum<[14]>;
790b57cec5SDimitry Andric  def X15 : RISCVReg<15,"x15", ["a5"]>, DwarfRegNum<[15]>;
800b57cec5SDimitry Andric  let CostPerUse = 1 in {
810b57cec5SDimitry Andric  def X16 : RISCVReg<16,"x16", ["a6"]>, DwarfRegNum<[16]>;
820b57cec5SDimitry Andric  def X17 : RISCVReg<17,"x17", ["a7"]>, DwarfRegNum<[17]>;
830b57cec5SDimitry Andric  def X18 : RISCVReg<18,"x18", ["s2"]>, DwarfRegNum<[18]>;
840b57cec5SDimitry Andric  def X19 : RISCVReg<19,"x19", ["s3"]>, DwarfRegNum<[19]>;
850b57cec5SDimitry Andric  def X20 : RISCVReg<20,"x20", ["s4"]>, DwarfRegNum<[20]>;
860b57cec5SDimitry Andric  def X21 : RISCVReg<21,"x21", ["s5"]>, DwarfRegNum<[21]>;
870b57cec5SDimitry Andric  def X22 : RISCVReg<22,"x22", ["s6"]>, DwarfRegNum<[22]>;
880b57cec5SDimitry Andric  def X23 : RISCVReg<23,"x23", ["s7"]>, DwarfRegNum<[23]>;
890b57cec5SDimitry Andric  def X24 : RISCVReg<24,"x24", ["s8"]>, DwarfRegNum<[24]>;
900b57cec5SDimitry Andric  def X25 : RISCVReg<25,"x25", ["s9"]>, DwarfRegNum<[25]>;
910b57cec5SDimitry Andric  def X26 : RISCVReg<26,"x26", ["s10"]>, DwarfRegNum<[26]>;
920b57cec5SDimitry Andric  def X27 : RISCVReg<27,"x27", ["s11"]>, DwarfRegNum<[27]>;
930b57cec5SDimitry Andric  def X28 : RISCVReg<28,"x28", ["t3"]>, DwarfRegNum<[28]>;
940b57cec5SDimitry Andric  def X29 : RISCVReg<29,"x29", ["t4"]>, DwarfRegNum<[29]>;
950b57cec5SDimitry Andric  def X30 : RISCVReg<30,"x30", ["t5"]>, DwarfRegNum<[30]>;
960b57cec5SDimitry Andric  def X31 : RISCVReg<31,"x31", ["t6"]>, DwarfRegNum<[31]>;
970b57cec5SDimitry Andric  }
980b57cec5SDimitry Andric}
990b57cec5SDimitry Andric
1000b57cec5SDimitry Andricdef XLenVT : ValueTypeByHwMode<[RV32, RV64, DefaultMode],
1010b57cec5SDimitry Andric                               [i32,  i64,  i32]>;
1020b57cec5SDimitry Andric
1030b57cec5SDimitry Andric// The order of registers represents the preferred allocation sequence.
1040b57cec5SDimitry Andric// Registers are listed in the order caller-save, callee-save, specials.
1050b57cec5SDimitry Andricdef GPR : RegisterClass<"RISCV", [XLenVT], 32, (add
1060b57cec5SDimitry Andric    (sequence "X%u", 10, 17),
1070b57cec5SDimitry Andric    (sequence "X%u", 5, 7),
1080b57cec5SDimitry Andric    (sequence "X%u", 28, 31),
1090b57cec5SDimitry Andric    (sequence "X%u", 8, 9),
1100b57cec5SDimitry Andric    (sequence "X%u", 18, 27),
1110b57cec5SDimitry Andric    (sequence "X%u", 0, 4)
1120b57cec5SDimitry Andric  )> {
1130b57cec5SDimitry Andric  let RegInfos = RegInfoByHwMode<
1140b57cec5SDimitry Andric      [RV32,              RV64,              DefaultMode],
1150b57cec5SDimitry Andric      [RegInfo<32,32,32>, RegInfo<64,64,64>, RegInfo<32,32,32>]>;
1160b57cec5SDimitry Andric}
1170b57cec5SDimitry Andric
1188bcb0991SDimitry Andricdef GPRX0 : RegisterClass<"RISCV", [XLenVT], 32, (add X0)> {
1198bcb0991SDimitry Andric  let RegInfos = RegInfoByHwMode<
1208bcb0991SDimitry Andric      [RV32,              RV64,              DefaultMode],
1218bcb0991SDimitry Andric      [RegInfo<32,32,32>, RegInfo<64,64,64>, RegInfo<32,32,32>]>;
1228bcb0991SDimitry Andric}
1238bcb0991SDimitry Andric
1240b57cec5SDimitry Andric// The order of registers represents the preferred allocation sequence.
1250b57cec5SDimitry Andric// Registers are listed in the order caller-save, callee-save, specials.
1260b57cec5SDimitry Andricdef GPRNoX0 : RegisterClass<"RISCV", [XLenVT], 32, (add
1270b57cec5SDimitry Andric    (sequence "X%u", 10, 17),
1280b57cec5SDimitry Andric    (sequence "X%u", 5, 7),
1290b57cec5SDimitry Andric    (sequence "X%u", 28, 31),
1300b57cec5SDimitry Andric    (sequence "X%u", 8, 9),
1310b57cec5SDimitry Andric    (sequence "X%u", 18, 27),
1320b57cec5SDimitry Andric    (sequence "X%u", 1, 4)
1330b57cec5SDimitry Andric  )> {
1340b57cec5SDimitry Andric  let RegInfos = RegInfoByHwMode<
1350b57cec5SDimitry Andric      [RV32,              RV64,              DefaultMode],
1360b57cec5SDimitry Andric      [RegInfo<32,32,32>, RegInfo<64,64,64>, RegInfo<32,32,32>]>;
1370b57cec5SDimitry Andric}
1380b57cec5SDimitry Andric
1390b57cec5SDimitry Andricdef GPRNoX0X2 : RegisterClass<"RISCV", [XLenVT], 32, (add
1400b57cec5SDimitry Andric    (sequence "X%u", 10, 17),
1410b57cec5SDimitry Andric    (sequence "X%u", 5, 7),
1420b57cec5SDimitry Andric    (sequence "X%u", 28, 31),
1430b57cec5SDimitry Andric    (sequence "X%u", 8, 9),
1440b57cec5SDimitry Andric    (sequence "X%u", 18, 27),
1450b57cec5SDimitry Andric    X1, X3, X4
1460b57cec5SDimitry Andric  )> {
1470b57cec5SDimitry Andric  let RegInfos = RegInfoByHwMode<
1480b57cec5SDimitry Andric      [RV32,              RV64,              DefaultMode],
1490b57cec5SDimitry Andric      [RegInfo<32,32,32>, RegInfo<64,64,64>, RegInfo<32,32,32>]>;
1500b57cec5SDimitry Andric}
1510b57cec5SDimitry Andric
1520b57cec5SDimitry Andricdef GPRC : RegisterClass<"RISCV", [XLenVT], 32, (add
1530b57cec5SDimitry Andric    (sequence "X%u", 10, 15),
1540b57cec5SDimitry Andric    (sequence "X%u", 8, 9)
1550b57cec5SDimitry Andric  )> {
1560b57cec5SDimitry Andric  let RegInfos = RegInfoByHwMode<
1570b57cec5SDimitry Andric      [RV32,              RV64,              DefaultMode],
1580b57cec5SDimitry Andric      [RegInfo<32,32,32>, RegInfo<64,64,64>, RegInfo<32,32,32>]>;
1590b57cec5SDimitry Andric}
1600b57cec5SDimitry Andric
1610b57cec5SDimitry Andric// For indirect tail calls, we can't use callee-saved registers, as they are
1620b57cec5SDimitry Andric// restored to the saved value before the tail call, which would clobber a call
1630b57cec5SDimitry Andric// address.
1640b57cec5SDimitry Andricdef GPRTC : RegisterClass<"RISCV", [XLenVT], 32, (add
1650b57cec5SDimitry Andric    (sequence "X%u", 5, 7),
1660b57cec5SDimitry Andric    (sequence "X%u", 10, 17),
1670b57cec5SDimitry Andric    (sequence "X%u", 28, 31)
1680b57cec5SDimitry Andric  )> {
1690b57cec5SDimitry Andric  let RegInfos = RegInfoByHwMode<
1700b57cec5SDimitry Andric      [RV32,              RV64,              DefaultMode],
1710b57cec5SDimitry Andric      [RegInfo<32,32,32>, RegInfo<64,64,64>, RegInfo<32,32,32>]>;
1720b57cec5SDimitry Andric}
1730b57cec5SDimitry Andric
1740b57cec5SDimitry Andricdef SP : RegisterClass<"RISCV", [XLenVT], 32, (add X2)> {
1750b57cec5SDimitry Andric  let RegInfos = RegInfoByHwMode<
1760b57cec5SDimitry Andric      [RV32,              RV64,              DefaultMode],
1770b57cec5SDimitry Andric      [RegInfo<32,32,32>, RegInfo<64,64,64>, RegInfo<32,32,32>]>;
1780b57cec5SDimitry Andric}
1790b57cec5SDimitry Andric
1800b57cec5SDimitry Andric// Floating point registers
1810b57cec5SDimitry Andriclet RegAltNameIndices = [ABIRegAltName] in {
1828bcb0991SDimitry Andric  def F0_F  : RISCVReg32<0, "f0", ["ft0"]>, DwarfRegNum<[32]>;
1838bcb0991SDimitry Andric  def F1_F  : RISCVReg32<1, "f1", ["ft1"]>, DwarfRegNum<[33]>;
1848bcb0991SDimitry Andric  def F2_F  : RISCVReg32<2, "f2", ["ft2"]>, DwarfRegNum<[34]>;
1858bcb0991SDimitry Andric  def F3_F  : RISCVReg32<3, "f3", ["ft3"]>, DwarfRegNum<[35]>;
1868bcb0991SDimitry Andric  def F4_F  : RISCVReg32<4, "f4", ["ft4"]>, DwarfRegNum<[36]>;
1878bcb0991SDimitry Andric  def F5_F  : RISCVReg32<5, "f5", ["ft5"]>, DwarfRegNum<[37]>;
1888bcb0991SDimitry Andric  def F6_F  : RISCVReg32<6, "f6", ["ft6"]>, DwarfRegNum<[38]>;
1898bcb0991SDimitry Andric  def F7_F  : RISCVReg32<7, "f7", ["ft7"]>, DwarfRegNum<[39]>;
1908bcb0991SDimitry Andric  def F8_F  : RISCVReg32<8, "f8", ["fs0"]>, DwarfRegNum<[40]>;
1918bcb0991SDimitry Andric  def F9_F  : RISCVReg32<9, "f9", ["fs1"]>, DwarfRegNum<[41]>;
1928bcb0991SDimitry Andric  def F10_F : RISCVReg32<10,"f10", ["fa0"]>, DwarfRegNum<[42]>;
1938bcb0991SDimitry Andric  def F11_F : RISCVReg32<11,"f11", ["fa1"]>, DwarfRegNum<[43]>;
1948bcb0991SDimitry Andric  def F12_F : RISCVReg32<12,"f12", ["fa2"]>, DwarfRegNum<[44]>;
1958bcb0991SDimitry Andric  def F13_F : RISCVReg32<13,"f13", ["fa3"]>, DwarfRegNum<[45]>;
1968bcb0991SDimitry Andric  def F14_F : RISCVReg32<14,"f14", ["fa4"]>, DwarfRegNum<[46]>;
1978bcb0991SDimitry Andric  def F15_F : RISCVReg32<15,"f15", ["fa5"]>, DwarfRegNum<[47]>;
1988bcb0991SDimitry Andric  def F16_F : RISCVReg32<16,"f16", ["fa6"]>, DwarfRegNum<[48]>;
1998bcb0991SDimitry Andric  def F17_F : RISCVReg32<17,"f17", ["fa7"]>, DwarfRegNum<[49]>;
2008bcb0991SDimitry Andric  def F18_F : RISCVReg32<18,"f18", ["fs2"]>, DwarfRegNum<[50]>;
2018bcb0991SDimitry Andric  def F19_F : RISCVReg32<19,"f19", ["fs3"]>, DwarfRegNum<[51]>;
2028bcb0991SDimitry Andric  def F20_F : RISCVReg32<20,"f20", ["fs4"]>, DwarfRegNum<[52]>;
2038bcb0991SDimitry Andric  def F21_F : RISCVReg32<21,"f21", ["fs5"]>, DwarfRegNum<[53]>;
2048bcb0991SDimitry Andric  def F22_F : RISCVReg32<22,"f22", ["fs6"]>, DwarfRegNum<[54]>;
2058bcb0991SDimitry Andric  def F23_F : RISCVReg32<23,"f23", ["fs7"]>, DwarfRegNum<[55]>;
2068bcb0991SDimitry Andric  def F24_F : RISCVReg32<24,"f24", ["fs8"]>, DwarfRegNum<[56]>;
2078bcb0991SDimitry Andric  def F25_F : RISCVReg32<25,"f25", ["fs9"]>, DwarfRegNum<[57]>;
2088bcb0991SDimitry Andric  def F26_F : RISCVReg32<26,"f26", ["fs10"]>, DwarfRegNum<[58]>;
2098bcb0991SDimitry Andric  def F27_F : RISCVReg32<27,"f27", ["fs11"]>, DwarfRegNum<[59]>;
2108bcb0991SDimitry Andric  def F28_F : RISCVReg32<28,"f28", ["ft8"]>, DwarfRegNum<[60]>;
2118bcb0991SDimitry Andric  def F29_F : RISCVReg32<29,"f29", ["ft9"]>, DwarfRegNum<[61]>;
2128bcb0991SDimitry Andric  def F30_F : RISCVReg32<30,"f30", ["ft10"]>, DwarfRegNum<[62]>;
2138bcb0991SDimitry Andric  def F31_F : RISCVReg32<31,"f31", ["ft11"]>, DwarfRegNum<[63]>;
2140b57cec5SDimitry Andric
2150b57cec5SDimitry Andric  foreach Index = 0-31 in {
2168bcb0991SDimitry Andric    def F#Index#_D : RISCVReg64<!cast<RISCVReg32>("F"#Index#"_F")>,
2170b57cec5SDimitry Andric      DwarfRegNum<[!add(Index, 32)]>;
2180b57cec5SDimitry Andric  }
2190b57cec5SDimitry Andric}
2200b57cec5SDimitry Andric
2210b57cec5SDimitry Andric// The order of registers represents the preferred allocation sequence,
2220b57cec5SDimitry Andric// meaning caller-save regs are listed before callee-save.
2230b57cec5SDimitry Andricdef FPR32 : RegisterClass<"RISCV", [f32], 32, (add
2248bcb0991SDimitry Andric    (sequence "F%u_F", 0, 7),
2258bcb0991SDimitry Andric    (sequence "F%u_F", 10, 17),
2268bcb0991SDimitry Andric    (sequence "F%u_F", 28, 31),
2278bcb0991SDimitry Andric    (sequence "F%u_F", 8, 9),
2288bcb0991SDimitry Andric    (sequence "F%u_F", 18, 27)
2290b57cec5SDimitry Andric)>;
2300b57cec5SDimitry Andric
2310b57cec5SDimitry Andricdef FPR32C : RegisterClass<"RISCV", [f32], 32, (add
2328bcb0991SDimitry Andric  (sequence "F%u_F", 10, 15),
2338bcb0991SDimitry Andric  (sequence "F%u_F", 8, 9)
2340b57cec5SDimitry Andric)>;
2350b57cec5SDimitry Andric
2360b57cec5SDimitry Andric// The order of registers represents the preferred allocation sequence,
2370b57cec5SDimitry Andric// meaning caller-save regs are listed before callee-save.
2380b57cec5SDimitry Andricdef FPR64 : RegisterClass<"RISCV", [f64], 64, (add
2398bcb0991SDimitry Andric    (sequence "F%u_D", 0, 7),
2408bcb0991SDimitry Andric    (sequence "F%u_D", 10, 17),
2418bcb0991SDimitry Andric    (sequence "F%u_D", 28, 31),
2428bcb0991SDimitry Andric    (sequence "F%u_D", 8, 9),
2438bcb0991SDimitry Andric    (sequence "F%u_D", 18, 27)
2440b57cec5SDimitry Andric)>;
2450b57cec5SDimitry Andric
2460b57cec5SDimitry Andricdef FPR64C : RegisterClass<"RISCV", [f64], 64, (add
2478bcb0991SDimitry Andric  (sequence "F%u_D", 10, 15),
2488bcb0991SDimitry Andric  (sequence "F%u_D", 8, 9)
2490b57cec5SDimitry Andric)>;
250*5ffd83dbSDimitry Andric
251*5ffd83dbSDimitry Andric// Vector registers
252*5ffd83dbSDimitry Andriclet RegAltNameIndices = [ABIRegAltName] in {
253*5ffd83dbSDimitry Andric  foreach Index = 0-31 in {
254*5ffd83dbSDimitry Andric    def V#Index : RISCVReg<Index, "v"#Index, ["v"#Index]>, DwarfRegNum<[!add(Index, 64)]>;
255*5ffd83dbSDimitry Andric  }
256*5ffd83dbSDimitry Andric
257*5ffd83dbSDimitry Andric  foreach Index = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22,
258*5ffd83dbSDimitry Andric                   24, 26, 28, 30] in {
259*5ffd83dbSDimitry Andric    def V#Index#M2 : RISCVRegWithSubRegs<Index, "v"#Index,
260*5ffd83dbSDimitry Andric                       [!cast<Register>("V"#Index),
261*5ffd83dbSDimitry Andric                        !cast<Register>("V"#!add(Index, 1))],
262*5ffd83dbSDimitry Andric                       ["v"#Index]>,
263*5ffd83dbSDimitry Andric                     DwarfRegAlias<!cast<Register>("V"#Index)> {
264*5ffd83dbSDimitry Andric      let SubRegIndices = [sub_vrm2, sub_vrm2_hi];
265*5ffd83dbSDimitry Andric    }
266*5ffd83dbSDimitry Andric  }
267*5ffd83dbSDimitry Andric
268*5ffd83dbSDimitry Andric  foreach Index = [0, 4, 8, 12, 16, 20, 24, 28] in {
269*5ffd83dbSDimitry Andric    def V#Index#M4 : RISCVRegWithSubRegs<Index, "v"#Index,
270*5ffd83dbSDimitry Andric                       [!cast<Register>("V"#Index#"M2"),
271*5ffd83dbSDimitry Andric                        !cast<Register>("V"#!add(Index, 2)#"M2")],
272*5ffd83dbSDimitry Andric                       ["v"#Index]>,
273*5ffd83dbSDimitry Andric                     DwarfRegAlias<!cast<Register>("V"#Index)> {
274*5ffd83dbSDimitry Andric      let SubRegIndices = [sub_vrm4, sub_vrm4_hi];
275*5ffd83dbSDimitry Andric    }
276*5ffd83dbSDimitry Andric  }
277*5ffd83dbSDimitry Andric
278*5ffd83dbSDimitry Andric  foreach Index = [0, 8, 16, 24] in {
279*5ffd83dbSDimitry Andric    def V#Index#M8 : RISCVRegWithSubRegs<Index, "v"#Index,
280*5ffd83dbSDimitry Andric                       [!cast<Register>("V"#Index#"M4"),
281*5ffd83dbSDimitry Andric                        !cast<Register>("V"#!add(Index, 4)#"M4")],
282*5ffd83dbSDimitry Andric                       ["v"#Index]>,
283*5ffd83dbSDimitry Andric                     DwarfRegAlias<!cast<Register>("V"#Index)> {
284*5ffd83dbSDimitry Andric      let SubRegIndices = [sub_vrm8, sub_vrm8_hi];
285*5ffd83dbSDimitry Andric    }
286*5ffd83dbSDimitry Andric  }
287*5ffd83dbSDimitry Andric
288*5ffd83dbSDimitry Andric  def VTYPE  : RISCVReg<0, "vtype", ["vtype"]>;
289*5ffd83dbSDimitry Andric  def VL     : RISCVReg<0, "vl", ["vl"]>;
290*5ffd83dbSDimitry Andric}
291*5ffd83dbSDimitry Andric
292*5ffd83dbSDimitry Andricclass RegisterTypes<list<ValueType> reg_types> {
293*5ffd83dbSDimitry Andric  list<ValueType> types = reg_types;
294*5ffd83dbSDimitry Andric}
295*5ffd83dbSDimitry Andric
296*5ffd83dbSDimitry Andric// The order of registers represents the preferred allocation sequence,
297*5ffd83dbSDimitry Andric// meaning caller-save regs are listed before callee-save.
298*5ffd83dbSDimitry Andricdef VR : RegisterClass<"RISCV", [nxv8i8, nxv4i16, nxv2i32, nxv1i64],
299*5ffd83dbSDimitry Andric                         64, (add
300*5ffd83dbSDimitry Andric    (sequence "V%u", 25, 31),
301*5ffd83dbSDimitry Andric    (sequence "V%u", 8, 24),
302*5ffd83dbSDimitry Andric    (sequence "V%u", 0, 7)
303*5ffd83dbSDimitry Andric  )> {
304*5ffd83dbSDimitry Andric  let Size = 64;
305*5ffd83dbSDimitry Andric}
306*5ffd83dbSDimitry Andric
307*5ffd83dbSDimitry Andricdef VRM2 : RegisterClass<"RISCV", [nxv16i8, nxv8i16, nxv4i32, nxv2i64], 64,
308*5ffd83dbSDimitry Andric                         (add V26M2, V28M2, V30M2, V8M2, V10M2, V12M2, V14M2, V16M2,
309*5ffd83dbSDimitry Andric                              V18M2, V20M2, V22M2, V24M2, V0M2, V2M2, V4M2, V6M2)> {
310*5ffd83dbSDimitry Andric  let Size = 128;
311*5ffd83dbSDimitry Andric}
312*5ffd83dbSDimitry Andric
313*5ffd83dbSDimitry Andricdef VRM4 : RegisterClass<"RISCV", [nxv32i8, nxv16i16, nxv8i32, nxv4i64], 64,
314*5ffd83dbSDimitry Andric                         (add V28M4, V8M4, V12M4, V16M4, V20M4, V24M4, V0M4, V4M4)> {
315*5ffd83dbSDimitry Andric  let Size = 256;
316*5ffd83dbSDimitry Andric}
317*5ffd83dbSDimitry Andric
318*5ffd83dbSDimitry Andricdef VRM8 : RegisterClass<"RISCV", [nxv32i16, nxv16i32, nxv8i64], 64,
319*5ffd83dbSDimitry Andric                         (add V8M8, V16M8, V24M8, V0M8)> {
320*5ffd83dbSDimitry Andric  let Size = 512;
321*5ffd83dbSDimitry Andric}
322*5ffd83dbSDimitry Andric
323*5ffd83dbSDimitry Andricdef VMaskVT : RegisterTypes<[nxv1i1, nxv2i1, nxv4i1, nxv8i1, nxv16i1, nxv32i1]>;
324*5ffd83dbSDimitry Andric
325*5ffd83dbSDimitry Andricdef VM : RegisterClass<"RISCV", VMaskVT.types, 64, (add
326*5ffd83dbSDimitry Andric    (sequence "V%u", 25, 31),
327*5ffd83dbSDimitry Andric    (sequence "V%u", 8, 24),
328*5ffd83dbSDimitry Andric    (sequence "V%u", 0, 7))> {
329*5ffd83dbSDimitry Andric  let Size = 64;
330*5ffd83dbSDimitry Andric}
331*5ffd83dbSDimitry Andric
332*5ffd83dbSDimitry Andricdef VMV0 : RegisterClass<"RISCV", VMaskVT.types, 64, (add V0)> {
333*5ffd83dbSDimitry Andric  let Size = 64;
334*5ffd83dbSDimitry Andric}
335