1*0b57cec5SDimitry Andric//===-- RISCVRegisterInfo.td - RISC-V Register defs --------*- tablegen -*-===// 2*0b57cec5SDimitry Andric// 3*0b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 5*0b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0b57cec5SDimitry Andric// 7*0b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 8*0b57cec5SDimitry Andric 9*0b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 10*0b57cec5SDimitry Andric// Declarations that describe the RISC-V register files 11*0b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 12*0b57cec5SDimitry Andric 13*0b57cec5SDimitry Andriclet Namespace = "RISCV" in { 14*0b57cec5SDimitry Andricclass RISCVReg<bits<5> Enc, string n, list<string> alt = []> : Register<n> { 15*0b57cec5SDimitry Andric let HWEncoding{4-0} = Enc; 16*0b57cec5SDimitry Andric let AltNames = alt; 17*0b57cec5SDimitry Andric} 18*0b57cec5SDimitry Andric 19*0b57cec5SDimitry Andricclass RISCVReg32<bits<5> Enc, string n, list<string> alt = []> : Register<n> { 20*0b57cec5SDimitry Andric let HWEncoding{4-0} = Enc; 21*0b57cec5SDimitry Andric let AltNames = alt; 22*0b57cec5SDimitry Andric} 23*0b57cec5SDimitry Andric 24*0b57cec5SDimitry Andric// Because RISCVReg64 register have AsmName and AltNames that alias with their 25*0b57cec5SDimitry Andric// 32-bit sub-register, RISCVAsmParser will need to coerce a register number 26*0b57cec5SDimitry Andric// from a RISCVReg32 to the equivalent RISCVReg64 when appropriate. 27*0b57cec5SDimitry Andricdef sub_32 : SubRegIndex<32>; 28*0b57cec5SDimitry Andricclass RISCVReg64<RISCVReg32 subreg> : Register<""> { 29*0b57cec5SDimitry Andric let HWEncoding{4-0} = subreg.HWEncoding{4-0}; 30*0b57cec5SDimitry Andric let SubRegs = [subreg]; 31*0b57cec5SDimitry Andric let SubRegIndices = [sub_32]; 32*0b57cec5SDimitry Andric let AsmName = subreg.AsmName; 33*0b57cec5SDimitry Andric let AltNames = subreg.AltNames; 34*0b57cec5SDimitry Andric} 35*0b57cec5SDimitry Andric 36*0b57cec5SDimitry Andricdef ABIRegAltName : RegAltNameIndex; 37*0b57cec5SDimitry Andric} // Namespace = "RISCV" 38*0b57cec5SDimitry Andric 39*0b57cec5SDimitry Andric// Integer registers 40*0b57cec5SDimitry Andric// CostPerUse is set higher for registers that may not be compressible as they 41*0b57cec5SDimitry Andric// are not part of GPRC, the most restrictive register class used by the 42*0b57cec5SDimitry Andric// compressed instruction set. This will influence the greedy register 43*0b57cec5SDimitry Andric// allocator to reduce the use of registers that can't be encoded in 16 bit 44*0b57cec5SDimitry Andric// instructions. This affects register allocation even when compressed 45*0b57cec5SDimitry Andric// instruction isn't targeted, we see no major negative codegen impact. 46*0b57cec5SDimitry Andric 47*0b57cec5SDimitry Andriclet RegAltNameIndices = [ABIRegAltName] in { 48*0b57cec5SDimitry Andric def X0 : RISCVReg<0, "x0", ["zero"]>, DwarfRegNum<[0]>; 49*0b57cec5SDimitry Andric let CostPerUse = 1 in { 50*0b57cec5SDimitry Andric def X1 : RISCVReg<1, "x1", ["ra"]>, DwarfRegNum<[1]>; 51*0b57cec5SDimitry Andric def X2 : RISCVReg<2, "x2", ["sp"]>, DwarfRegNum<[2]>; 52*0b57cec5SDimitry Andric def X3 : RISCVReg<3, "x3", ["gp"]>, DwarfRegNum<[3]>; 53*0b57cec5SDimitry Andric def X4 : RISCVReg<4, "x4", ["tp"]>, DwarfRegNum<[4]>; 54*0b57cec5SDimitry Andric def X5 : RISCVReg<5, "x5", ["t0"]>, DwarfRegNum<[5]>; 55*0b57cec5SDimitry Andric def X6 : RISCVReg<6, "x6", ["t1"]>, DwarfRegNum<[6]>; 56*0b57cec5SDimitry Andric def X7 : RISCVReg<7, "x7", ["t2"]>, DwarfRegNum<[7]>; 57*0b57cec5SDimitry Andric } 58*0b57cec5SDimitry Andric def X8 : RISCVReg<8, "x8", ["s0", "fp"]>, DwarfRegNum<[8]>; 59*0b57cec5SDimitry Andric def X9 : RISCVReg<9, "x9", ["s1"]>, DwarfRegNum<[9]>; 60*0b57cec5SDimitry Andric def X10 : RISCVReg<10,"x10", ["a0"]>, DwarfRegNum<[10]>; 61*0b57cec5SDimitry Andric def X11 : RISCVReg<11,"x11", ["a1"]>, DwarfRegNum<[11]>; 62*0b57cec5SDimitry Andric def X12 : RISCVReg<12,"x12", ["a2"]>, DwarfRegNum<[12]>; 63*0b57cec5SDimitry Andric def X13 : RISCVReg<13,"x13", ["a3"]>, DwarfRegNum<[13]>; 64*0b57cec5SDimitry Andric def X14 : RISCVReg<14,"x14", ["a4"]>, DwarfRegNum<[14]>; 65*0b57cec5SDimitry Andric def X15 : RISCVReg<15,"x15", ["a5"]>, DwarfRegNum<[15]>; 66*0b57cec5SDimitry Andric let CostPerUse = 1 in { 67*0b57cec5SDimitry Andric def X16 : RISCVReg<16,"x16", ["a6"]>, DwarfRegNum<[16]>; 68*0b57cec5SDimitry Andric def X17 : RISCVReg<17,"x17", ["a7"]>, DwarfRegNum<[17]>; 69*0b57cec5SDimitry Andric def X18 : RISCVReg<18,"x18", ["s2"]>, DwarfRegNum<[18]>; 70*0b57cec5SDimitry Andric def X19 : RISCVReg<19,"x19", ["s3"]>, DwarfRegNum<[19]>; 71*0b57cec5SDimitry Andric def X20 : RISCVReg<20,"x20", ["s4"]>, DwarfRegNum<[20]>; 72*0b57cec5SDimitry Andric def X21 : RISCVReg<21,"x21", ["s5"]>, DwarfRegNum<[21]>; 73*0b57cec5SDimitry Andric def X22 : RISCVReg<22,"x22", ["s6"]>, DwarfRegNum<[22]>; 74*0b57cec5SDimitry Andric def X23 : RISCVReg<23,"x23", ["s7"]>, DwarfRegNum<[23]>; 75*0b57cec5SDimitry Andric def X24 : RISCVReg<24,"x24", ["s8"]>, DwarfRegNum<[24]>; 76*0b57cec5SDimitry Andric def X25 : RISCVReg<25,"x25", ["s9"]>, DwarfRegNum<[25]>; 77*0b57cec5SDimitry Andric def X26 : RISCVReg<26,"x26", ["s10"]>, DwarfRegNum<[26]>; 78*0b57cec5SDimitry Andric def X27 : RISCVReg<27,"x27", ["s11"]>, DwarfRegNum<[27]>; 79*0b57cec5SDimitry Andric def X28 : RISCVReg<28,"x28", ["t3"]>, DwarfRegNum<[28]>; 80*0b57cec5SDimitry Andric def X29 : RISCVReg<29,"x29", ["t4"]>, DwarfRegNum<[29]>; 81*0b57cec5SDimitry Andric def X30 : RISCVReg<30,"x30", ["t5"]>, DwarfRegNum<[30]>; 82*0b57cec5SDimitry Andric def X31 : RISCVReg<31,"x31", ["t6"]>, DwarfRegNum<[31]>; 83*0b57cec5SDimitry Andric } 84*0b57cec5SDimitry Andric} 85*0b57cec5SDimitry Andric 86*0b57cec5SDimitry Andricdef XLenVT : ValueTypeByHwMode<[RV32, RV64, DefaultMode], 87*0b57cec5SDimitry Andric [i32, i64, i32]>; 88*0b57cec5SDimitry Andric 89*0b57cec5SDimitry Andric// The order of registers represents the preferred allocation sequence. 90*0b57cec5SDimitry Andric// Registers are listed in the order caller-save, callee-save, specials. 91*0b57cec5SDimitry Andricdef GPR : RegisterClass<"RISCV", [XLenVT], 32, (add 92*0b57cec5SDimitry Andric (sequence "X%u", 10, 17), 93*0b57cec5SDimitry Andric (sequence "X%u", 5, 7), 94*0b57cec5SDimitry Andric (sequence "X%u", 28, 31), 95*0b57cec5SDimitry Andric (sequence "X%u", 8, 9), 96*0b57cec5SDimitry Andric (sequence "X%u", 18, 27), 97*0b57cec5SDimitry Andric (sequence "X%u", 0, 4) 98*0b57cec5SDimitry Andric )> { 99*0b57cec5SDimitry Andric let RegInfos = RegInfoByHwMode< 100*0b57cec5SDimitry Andric [RV32, RV64, DefaultMode], 101*0b57cec5SDimitry Andric [RegInfo<32,32,32>, RegInfo<64,64,64>, RegInfo<32,32,32>]>; 102*0b57cec5SDimitry Andric} 103*0b57cec5SDimitry Andric 104*0b57cec5SDimitry Andric// The order of registers represents the preferred allocation sequence. 105*0b57cec5SDimitry Andric// Registers are listed in the order caller-save, callee-save, specials. 106*0b57cec5SDimitry Andricdef GPRNoX0 : RegisterClass<"RISCV", [XLenVT], 32, (add 107*0b57cec5SDimitry Andric (sequence "X%u", 10, 17), 108*0b57cec5SDimitry Andric (sequence "X%u", 5, 7), 109*0b57cec5SDimitry Andric (sequence "X%u", 28, 31), 110*0b57cec5SDimitry Andric (sequence "X%u", 8, 9), 111*0b57cec5SDimitry Andric (sequence "X%u", 18, 27), 112*0b57cec5SDimitry Andric (sequence "X%u", 1, 4) 113*0b57cec5SDimitry Andric )> { 114*0b57cec5SDimitry Andric let RegInfos = RegInfoByHwMode< 115*0b57cec5SDimitry Andric [RV32, RV64, DefaultMode], 116*0b57cec5SDimitry Andric [RegInfo<32,32,32>, RegInfo<64,64,64>, RegInfo<32,32,32>]>; 117*0b57cec5SDimitry Andric} 118*0b57cec5SDimitry Andric 119*0b57cec5SDimitry Andricdef GPRNoX0X2 : RegisterClass<"RISCV", [XLenVT], 32, (add 120*0b57cec5SDimitry Andric (sequence "X%u", 10, 17), 121*0b57cec5SDimitry Andric (sequence "X%u", 5, 7), 122*0b57cec5SDimitry Andric (sequence "X%u", 28, 31), 123*0b57cec5SDimitry Andric (sequence "X%u", 8, 9), 124*0b57cec5SDimitry Andric (sequence "X%u", 18, 27), 125*0b57cec5SDimitry Andric X1, X3, X4 126*0b57cec5SDimitry Andric )> { 127*0b57cec5SDimitry Andric let RegInfos = RegInfoByHwMode< 128*0b57cec5SDimitry Andric [RV32, RV64, DefaultMode], 129*0b57cec5SDimitry Andric [RegInfo<32,32,32>, RegInfo<64,64,64>, RegInfo<32,32,32>]>; 130*0b57cec5SDimitry Andric} 131*0b57cec5SDimitry Andric 132*0b57cec5SDimitry Andricdef GPRC : RegisterClass<"RISCV", [XLenVT], 32, (add 133*0b57cec5SDimitry Andric (sequence "X%u", 10, 15), 134*0b57cec5SDimitry Andric (sequence "X%u", 8, 9) 135*0b57cec5SDimitry Andric )> { 136*0b57cec5SDimitry Andric let RegInfos = RegInfoByHwMode< 137*0b57cec5SDimitry Andric [RV32, RV64, DefaultMode], 138*0b57cec5SDimitry Andric [RegInfo<32,32,32>, RegInfo<64,64,64>, RegInfo<32,32,32>]>; 139*0b57cec5SDimitry Andric} 140*0b57cec5SDimitry Andric 141*0b57cec5SDimitry Andric// For indirect tail calls, we can't use callee-saved registers, as they are 142*0b57cec5SDimitry Andric// restored to the saved value before the tail call, which would clobber a call 143*0b57cec5SDimitry Andric// address. 144*0b57cec5SDimitry Andricdef GPRTC : RegisterClass<"RISCV", [XLenVT], 32, (add 145*0b57cec5SDimitry Andric (sequence "X%u", 5, 7), 146*0b57cec5SDimitry Andric (sequence "X%u", 10, 17), 147*0b57cec5SDimitry Andric (sequence "X%u", 28, 31) 148*0b57cec5SDimitry Andric )> { 149*0b57cec5SDimitry Andric let RegInfos = RegInfoByHwMode< 150*0b57cec5SDimitry Andric [RV32, RV64, DefaultMode], 151*0b57cec5SDimitry Andric [RegInfo<32,32,32>, RegInfo<64,64,64>, RegInfo<32,32,32>]>; 152*0b57cec5SDimitry Andric} 153*0b57cec5SDimitry Andric 154*0b57cec5SDimitry Andricdef SP : RegisterClass<"RISCV", [XLenVT], 32, (add X2)> { 155*0b57cec5SDimitry Andric let RegInfos = RegInfoByHwMode< 156*0b57cec5SDimitry Andric [RV32, RV64, DefaultMode], 157*0b57cec5SDimitry Andric [RegInfo<32,32,32>, RegInfo<64,64,64>, RegInfo<32,32,32>]>; 158*0b57cec5SDimitry Andric} 159*0b57cec5SDimitry Andric 160*0b57cec5SDimitry Andric// Floating point registers 161*0b57cec5SDimitry Andriclet RegAltNameIndices = [ABIRegAltName] in { 162*0b57cec5SDimitry Andric def F0_32 : RISCVReg32<0, "f0", ["ft0"]>, DwarfRegNum<[32]>; 163*0b57cec5SDimitry Andric def F1_32 : RISCVReg32<1, "f1", ["ft1"]>, DwarfRegNum<[33]>; 164*0b57cec5SDimitry Andric def F2_32 : RISCVReg32<2, "f2", ["ft2"]>, DwarfRegNum<[34]>; 165*0b57cec5SDimitry Andric def F3_32 : RISCVReg32<3, "f3", ["ft3"]>, DwarfRegNum<[35]>; 166*0b57cec5SDimitry Andric def F4_32 : RISCVReg32<4, "f4", ["ft4"]>, DwarfRegNum<[36]>; 167*0b57cec5SDimitry Andric def F5_32 : RISCVReg32<5, "f5", ["ft5"]>, DwarfRegNum<[37]>; 168*0b57cec5SDimitry Andric def F6_32 : RISCVReg32<6, "f6", ["ft6"]>, DwarfRegNum<[38]>; 169*0b57cec5SDimitry Andric def F7_32 : RISCVReg32<7, "f7", ["ft7"]>, DwarfRegNum<[39]>; 170*0b57cec5SDimitry Andric def F8_32 : RISCVReg32<8, "f8", ["fs0"]>, DwarfRegNum<[40]>; 171*0b57cec5SDimitry Andric def F9_32 : RISCVReg32<9, "f9", ["fs1"]>, DwarfRegNum<[41]>; 172*0b57cec5SDimitry Andric def F10_32 : RISCVReg32<10,"f10", ["fa0"]>, DwarfRegNum<[42]>; 173*0b57cec5SDimitry Andric def F11_32 : RISCVReg32<11,"f11", ["fa1"]>, DwarfRegNum<[43]>; 174*0b57cec5SDimitry Andric def F12_32 : RISCVReg32<12,"f12", ["fa2"]>, DwarfRegNum<[44]>; 175*0b57cec5SDimitry Andric def F13_32 : RISCVReg32<13,"f13", ["fa3"]>, DwarfRegNum<[45]>; 176*0b57cec5SDimitry Andric def F14_32 : RISCVReg32<14,"f14", ["fa4"]>, DwarfRegNum<[46]>; 177*0b57cec5SDimitry Andric def F15_32 : RISCVReg32<15,"f15", ["fa5"]>, DwarfRegNum<[47]>; 178*0b57cec5SDimitry Andric def F16_32 : RISCVReg32<16,"f16", ["fa6"]>, DwarfRegNum<[48]>; 179*0b57cec5SDimitry Andric def F17_32 : RISCVReg32<17,"f17", ["fa7"]>, DwarfRegNum<[49]>; 180*0b57cec5SDimitry Andric def F18_32 : RISCVReg32<18,"f18", ["fs2"]>, DwarfRegNum<[50]>; 181*0b57cec5SDimitry Andric def F19_32 : RISCVReg32<19,"f19", ["fs3"]>, DwarfRegNum<[51]>; 182*0b57cec5SDimitry Andric def F20_32 : RISCVReg32<20,"f20", ["fs4"]>, DwarfRegNum<[52]>; 183*0b57cec5SDimitry Andric def F21_32 : RISCVReg32<21,"f21", ["fs5"]>, DwarfRegNum<[53]>; 184*0b57cec5SDimitry Andric def F22_32 : RISCVReg32<22,"f22", ["fs6"]>, DwarfRegNum<[54]>; 185*0b57cec5SDimitry Andric def F23_32 : RISCVReg32<23,"f23", ["fs7"]>, DwarfRegNum<[55]>; 186*0b57cec5SDimitry Andric def F24_32 : RISCVReg32<24,"f24", ["fs8"]>, DwarfRegNum<[56]>; 187*0b57cec5SDimitry Andric def F25_32 : RISCVReg32<25,"f25", ["fs9"]>, DwarfRegNum<[57]>; 188*0b57cec5SDimitry Andric def F26_32 : RISCVReg32<26,"f26", ["fs10"]>, DwarfRegNum<[58]>; 189*0b57cec5SDimitry Andric def F27_32 : RISCVReg32<27,"f27", ["fs11"]>, DwarfRegNum<[59]>; 190*0b57cec5SDimitry Andric def F28_32 : RISCVReg32<28,"f28", ["ft8"]>, DwarfRegNum<[60]>; 191*0b57cec5SDimitry Andric def F29_32 : RISCVReg32<29,"f29", ["ft9"]>, DwarfRegNum<[61]>; 192*0b57cec5SDimitry Andric def F30_32 : RISCVReg32<30,"f30", ["ft10"]>, DwarfRegNum<[62]>; 193*0b57cec5SDimitry Andric def F31_32 : RISCVReg32<31,"f31", ["ft11"]>, DwarfRegNum<[63]>; 194*0b57cec5SDimitry Andric 195*0b57cec5SDimitry Andric foreach Index = 0-31 in { 196*0b57cec5SDimitry Andric def F#Index#_64 : RISCVReg64<!cast<RISCVReg32>("F"#Index#"_32")>, 197*0b57cec5SDimitry Andric DwarfRegNum<[!add(Index, 32)]>; 198*0b57cec5SDimitry Andric } 199*0b57cec5SDimitry Andric} 200*0b57cec5SDimitry Andric 201*0b57cec5SDimitry Andric// The order of registers represents the preferred allocation sequence, 202*0b57cec5SDimitry Andric// meaning caller-save regs are listed before callee-save. 203*0b57cec5SDimitry Andricdef FPR32 : RegisterClass<"RISCV", [f32], 32, (add 204*0b57cec5SDimitry Andric (sequence "F%u_32", 0, 7), 205*0b57cec5SDimitry Andric (sequence "F%u_32", 10, 17), 206*0b57cec5SDimitry Andric (sequence "F%u_32", 28, 31), 207*0b57cec5SDimitry Andric (sequence "F%u_32", 8, 9), 208*0b57cec5SDimitry Andric (sequence "F%u_32", 18, 27) 209*0b57cec5SDimitry Andric)>; 210*0b57cec5SDimitry Andric 211*0b57cec5SDimitry Andricdef FPR32C : RegisterClass<"RISCV", [f32], 32, (add 212*0b57cec5SDimitry Andric (sequence "F%u_32", 10, 15), 213*0b57cec5SDimitry Andric (sequence "F%u_32", 8, 9) 214*0b57cec5SDimitry Andric)>; 215*0b57cec5SDimitry Andric 216*0b57cec5SDimitry Andric// The order of registers represents the preferred allocation sequence, 217*0b57cec5SDimitry Andric// meaning caller-save regs are listed before callee-save. 218*0b57cec5SDimitry Andricdef FPR64 : RegisterClass<"RISCV", [f64], 64, (add 219*0b57cec5SDimitry Andric (sequence "F%u_64", 0, 7), 220*0b57cec5SDimitry Andric (sequence "F%u_64", 10, 17), 221*0b57cec5SDimitry Andric (sequence "F%u_64", 28, 31), 222*0b57cec5SDimitry Andric (sequence "F%u_64", 8, 9), 223*0b57cec5SDimitry Andric (sequence "F%u_64", 18, 27) 224*0b57cec5SDimitry Andric)>; 225*0b57cec5SDimitry Andric 226*0b57cec5SDimitry Andricdef FPR64C : RegisterClass<"RISCV", [f64], 64, (add 227*0b57cec5SDimitry Andric (sequence "F%u_64", 10, 15), 228*0b57cec5SDimitry Andric (sequence "F%u_64", 8, 9) 229*0b57cec5SDimitry Andric)>; 230