1//===-- LoongArchRegisterInfo.td - LoongArch Register defs -*- 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//===----------------------------------------------------------------------===// 10// Declarations that describe the LoongArch register files 11//===----------------------------------------------------------------------===// 12 13let Namespace = "LoongArch" in { 14class LoongArchReg<bits<16> Enc, string n, list<string> alt = []> 15 : Register<n> { 16 let HWEncoding = Enc; 17 let AltNames = alt; 18} 19 20class LoongArchRegWithSubRegs<bits<16> Enc, string n, list<Register> subregs, 21 list<string> alt = []> 22 : RegisterWithSubRegs<n, subregs> { 23 let HWEncoding = Enc; 24 let AltNames = alt; 25} 26 27class LoongArchReg32<bits<16> Enc, string n, list<string> alt = []> 28 : Register<n> { 29 let HWEncoding = Enc; 30 let AltNames = alt; 31} 32 33def sub_32 : SubRegIndex<32>; 34class LoongArchReg64<LoongArchReg32 subreg> 35 : LoongArchRegWithSubRegs<subreg.HWEncoding, subreg.AsmName, [subreg], 36 subreg.AltNames> { 37 let SubRegIndices = [sub_32]; 38} 39 40def sub_64 : SubRegIndex<64>; 41class LoongArchReg128<LoongArchReg64 subreg, string n> 42 : LoongArchRegWithSubRegs<subreg.HWEncoding, n, [subreg]> { 43 let SubRegIndices = [sub_64]; 44} 45 46def sub_128 : SubRegIndex<128>; 47class LoongArchReg256<LoongArchReg128 subreg, string n> 48 : LoongArchRegWithSubRegs<subreg.HWEncoding, n, [subreg]> { 49 let SubRegIndices = [sub_128]; 50} 51 52let FallbackRegAltNameIndex = NoRegAltName in 53def RegAliasName : RegAltNameIndex; 54} // Namespace = "LoongArch" 55 56// Integer registers 57 58let RegAltNameIndices = [RegAliasName] in { 59 let isConstant = true in 60 def R0 : LoongArchReg<0, "r0", ["zero"]>, DwarfRegNum<[0]>; 61 def R1 : LoongArchReg<1, "r1", ["ra"]>, DwarfRegNum<[1]>; 62 def R2 : LoongArchReg<2, "r2", ["tp"]>, DwarfRegNum<[2]>; 63 def R3 : LoongArchReg<3, "r3", ["sp"]>, DwarfRegNum<[3]>; 64 def R4 : LoongArchReg<4, "r4", ["a0"]>, DwarfRegNum<[4]>; 65 def R5 : LoongArchReg<5, "r5", ["a1"]>, DwarfRegNum<[5]>; 66 def R6 : LoongArchReg<6, "r6", ["a2"]>, DwarfRegNum<[6]>; 67 def R7 : LoongArchReg<7, "r7", ["a3"]>, DwarfRegNum<[7]>; 68 def R8 : LoongArchReg<8, "r8", ["a4"]>, DwarfRegNum<[8]>; 69 def R9 : LoongArchReg<9, "r9", ["a5"]>, DwarfRegNum<[9]>; 70 def R10 : LoongArchReg<10, "r10", ["a6"]>, DwarfRegNum<[10]>; 71 def R11 : LoongArchReg<11, "r11", ["a7"]>, DwarfRegNum<[11]>; 72 def R12 : LoongArchReg<12, "r12", ["t0"]>, DwarfRegNum<[12]>; 73 def R13 : LoongArchReg<13, "r13", ["t1"]>, DwarfRegNum<[13]>; 74 def R14 : LoongArchReg<14, "r14", ["t2"]>, DwarfRegNum<[14]>; 75 def R15 : LoongArchReg<15, "r15", ["t3"]>, DwarfRegNum<[15]>; 76 def R16 : LoongArchReg<16, "r16", ["t4"]>, DwarfRegNum<[16]>; 77 def R17 : LoongArchReg<17, "r17", ["t5"]>, DwarfRegNum<[17]>; 78 def R18 : LoongArchReg<18, "r18", ["t6"]>, DwarfRegNum<[18]>; 79 def R19 : LoongArchReg<19, "r19", ["t7"]>, DwarfRegNum<[19]>; 80 def R20 : LoongArchReg<20, "r20", ["t8"]>, DwarfRegNum<[20]>; 81 def R21 : LoongArchReg<21, "r21", [""]>, DwarfRegNum<[21]>; 82 def R22 : LoongArchReg<22, "r22", ["fp", "s9"]>, DwarfRegNum<[22]>; 83 def R23 : LoongArchReg<23, "r23", ["s0"]>, DwarfRegNum<[23]>; 84 def R24 : LoongArchReg<24, "r24", ["s1"]>, DwarfRegNum<[24]>; 85 def R25 : LoongArchReg<25, "r25", ["s2"]>, DwarfRegNum<[25]>; 86 def R26 : LoongArchReg<26, "r26", ["s3"]>, DwarfRegNum<[26]>; 87 def R27 : LoongArchReg<27, "r27", ["s4"]>, DwarfRegNum<[27]>; 88 def R28 : LoongArchReg<28, "r28", ["s5"]>, DwarfRegNum<[28]>; 89 def R29 : LoongArchReg<29, "r29", ["s6"]>, DwarfRegNum<[29]>; 90 def R30 : LoongArchReg<30, "r30", ["s7"]>, DwarfRegNum<[30]>; 91 def R31 : LoongArchReg<31, "r31", ["s8"]>, DwarfRegNum<[31]>; 92} // RegAltNameIndices = [RegAliasName] 93 94def GRLenVT : ValueTypeByHwMode<[LA32, LA64], 95 [i32, i64]>; 96def GRLenRI : RegInfoByHwMode< 97 [LA32, LA64], 98 [RegInfo<32,32,32>, RegInfo<64,64,64>]>; 99 100// The order of registers represents the preferred allocation sequence. 101// Registers are listed in the order caller-save, callee-save, specials. 102def GPR : RegisterClass<"LoongArch", [GRLenVT], 32, (add 103 // Argument registers (a0...a7) 104 (sequence "R%u", 4, 11), 105 // Temporary registers (t0...t8) 106 (sequence "R%u", 12, 20), 107 // Static register (s9/fp, s0...s8) 108 (sequence "R%u", 22, 31), 109 // Specials (r0, ra, tp, sp) 110 (sequence "R%u", 0, 3), 111 // Reserved (Non-allocatable) 112 R21 113 )> { 114 let RegInfos = GRLenRI; 115} 116 117// GPR for indirect tail calls. We can't use callee-saved registers, as they are 118// restored to the saved value before the tail call, which would clobber a call 119// address. 120def GPRT : RegisterClass<"LoongArch", [GRLenVT], 32, (add 121 // a0...a7, t0...t8 122 (sequence "R%u", 4, 20) 123 )> { 124 let RegInfos = GRLenRI; 125} 126 127// Floating point registers 128 129let RegAltNameIndices = [RegAliasName] in { 130 def F0 : LoongArchReg32<0, "f0", ["fa0"]>, DwarfRegNum<[32]>; 131 def F1 : LoongArchReg32<1, "f1", ["fa1"]>, DwarfRegNum<[33]>; 132 def F2 : LoongArchReg32<2, "f2", ["fa2"]>, DwarfRegNum<[34]>; 133 def F3 : LoongArchReg32<3, "f3", ["fa3"]>, DwarfRegNum<[35]>; 134 def F4 : LoongArchReg32<4, "f4", ["fa4"]>, DwarfRegNum<[36]>; 135 def F5 : LoongArchReg32<5, "f5", ["fa5"]>, DwarfRegNum<[37]>; 136 def F6 : LoongArchReg32<6, "f6", ["fa6"]>, DwarfRegNum<[38]>; 137 def F7 : LoongArchReg32<7, "f7", ["fa7"]>, DwarfRegNum<[39]>; 138 def F8 : LoongArchReg32<8, "f8", ["ft0"]>, DwarfRegNum<[40]>; 139 def F9 : LoongArchReg32<9, "f9", ["ft1"]>, DwarfRegNum<[41]>; 140 def F10 : LoongArchReg32<10,"f10", ["ft2"]>, DwarfRegNum<[42]>; 141 def F11 : LoongArchReg32<11,"f11", ["ft3"]>, DwarfRegNum<[43]>; 142 def F12 : LoongArchReg32<12,"f12", ["ft4"]>, DwarfRegNum<[44]>; 143 def F13 : LoongArchReg32<13,"f13", ["ft5"]>, DwarfRegNum<[45]>; 144 def F14 : LoongArchReg32<14,"f14", ["ft6"]>, DwarfRegNum<[46]>; 145 def F15 : LoongArchReg32<15,"f15", ["ft7"]>, DwarfRegNum<[47]>; 146 def F16 : LoongArchReg32<16,"f16", ["ft8"]>, DwarfRegNum<[48]>; 147 def F17 : LoongArchReg32<17,"f17", ["ft9"]>, DwarfRegNum<[49]>; 148 def F18 : LoongArchReg32<18,"f18", ["ft10"]>, DwarfRegNum<[50]>; 149 def F19 : LoongArchReg32<19,"f19", ["ft11"]>, DwarfRegNum<[51]>; 150 def F20 : LoongArchReg32<20,"f20", ["ft12"]>, DwarfRegNum<[52]>; 151 def F21 : LoongArchReg32<21,"f21", ["ft13"]>, DwarfRegNum<[53]>; 152 def F22 : LoongArchReg32<22,"f22", ["ft14"]>, DwarfRegNum<[54]>; 153 def F23 : LoongArchReg32<23,"f23", ["ft15"]>, DwarfRegNum<[55]>; 154 def F24 : LoongArchReg32<24,"f24", ["fs0"]>, DwarfRegNum<[56]>; 155 def F25 : LoongArchReg32<25,"f25", ["fs1"]>, DwarfRegNum<[57]>; 156 def F26 : LoongArchReg32<26,"f26", ["fs2"]>, DwarfRegNum<[58]>; 157 def F27 : LoongArchReg32<27,"f27", ["fs3"]>, DwarfRegNum<[59]>; 158 def F28 : LoongArchReg32<28,"f28", ["fs4"]>, DwarfRegNum<[60]>; 159 def F29 : LoongArchReg32<29,"f29", ["fs5"]>, DwarfRegNum<[61]>; 160 def F30 : LoongArchReg32<30,"f30", ["fs6"]>, DwarfRegNum<[62]>; 161 def F31 : LoongArchReg32<31,"f31", ["fs7"]>, DwarfRegNum<[63]>; 162 163 foreach I = 0-31 in { 164 def F#I#_64 : LoongArchReg64<!cast<LoongArchReg32>("F"#I)>, 165 DwarfRegNum<[!add(I, 32)]>; 166 } 167} 168 169// The order of registers represents the preferred allocation sequence. 170def FPR32 : RegisterClass<"LoongArch", [f32], 32, (sequence "F%u", 0, 31)>; 171def FPR64 : RegisterClass<"LoongArch", [f64], 64, (sequence "F%u_64", 0, 31)>; 172 173// Condition flag registers 174 175foreach I = 0-7 in 176def FCC#I : LoongArchReg<I, "fcc"#I>; 177 178def CFR : RegisterClass<"LoongArch", [GRLenVT], 32, (sequence "FCC%u", 0, 7)> { 179 let RegInfos = GRLenRI; 180} 181 182// Control and status registers 183 184foreach I = 0-3 in 185def FCSR#I : LoongArchReg<I, "fcsr"#I>; 186 187let isAllocatable = false in 188def FCSR : RegisterClass<"LoongArch", [i32], 32, (sequence "FCSR%u", 0, 3)>; 189 190// LSX registers 191 192foreach I = 0-31 in 193def VR#I : LoongArchReg128<!cast<LoongArchReg64>("F"#I#"_64"), "vr"#I>, 194 DwarfRegAlias<!cast<LoongArchReg64>("F"#I#"_64")>; 195 196def LSX128 : RegisterClass<"LoongArch", 197 [v4f32, v2f64, v16i8, v8i16, v4i32, v2i64], 198 128, (sequence "VR%u", 0, 31)>; 199 200// LASX registers 201 202foreach I = 0-31 in 203def XR#I : LoongArchReg256<!cast<LoongArchReg128>("VR"#I), "xr"#I>, 204 DwarfRegAlias<!cast<LoongArchReg128>("VR"#I)>; 205 206def LASX256 : RegisterClass<"LoongArch", 207 [v8f32, v4f64, v32i8, v16i16, v8i32, v4i64], 208 256, (sequence "XR%u", 0, 31)>; 209 210// Scratchpad registers 211 212foreach I = 0-3 in 213def SCR#I : LoongArchReg<I, "scr"#I>; 214 215let isAllocatable = false, RegInfos = GRLenRI in 216def SCR : RegisterClass<"LoongArch", [GRLenVT], 32, (sequence "SCR%u", 0, 3)>; 217