MipsRegisterInfo.td revision 208954
1//===- MipsRegisterInfo.td - Mips Register defs -----------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10//===----------------------------------------------------------------------===// 11// Declarations that describe the MIPS register file 12//===----------------------------------------------------------------------===// 13 14// We have banks of 32 registers each. 15class MipsReg<string n> : Register<n> { 16 field bits<5> Num; 17 let Namespace = "Mips"; 18} 19 20class MipsRegWithSubRegs<string n, list<Register> subregs> 21 : RegisterWithSubRegs<n, subregs> { 22 field bits<5> Num; 23 let Namespace = "Mips"; 24} 25 26// Mips CPU Registers 27class MipsGPRReg<bits<5> num, string n> : MipsReg<n> { 28 let Num = num; 29} 30 31// Mips 32-bit FPU Registers 32class FPR<bits<5> num, string n> : MipsReg<n> { 33 let Num = num; 34} 35 36// Mips 64-bit (aliased) FPU Registers 37let Namespace = "Mips" in { 38def sub_fpeven : SubRegIndex; 39def sub_fpodd : SubRegIndex; 40} 41class AFPR<bits<5> num, string n, list<Register> subregs> 42 : MipsRegWithSubRegs<n, subregs> { 43 let Num = num; 44 let SubRegIndices = [sub_fpeven, sub_fpodd]; 45} 46 47//===----------------------------------------------------------------------===// 48// Registers 49//===----------------------------------------------------------------------===// 50 51let Namespace = "Mips" in { 52 53 // General Purpose Registers 54 def ZERO : MipsGPRReg< 0, "ZERO">, DwarfRegNum<[0]>; 55 def AT : MipsGPRReg< 1, "AT">, DwarfRegNum<[1]>; 56 def V0 : MipsGPRReg< 2, "2">, DwarfRegNum<[2]>; 57 def V1 : MipsGPRReg< 3, "3">, DwarfRegNum<[3]>; 58 def A0 : MipsGPRReg< 4, "4">, DwarfRegNum<[5]>; 59 def A1 : MipsGPRReg< 5, "5">, DwarfRegNum<[5]>; 60 def A2 : MipsGPRReg< 6, "6">, DwarfRegNum<[6]>; 61 def A3 : MipsGPRReg< 7, "7">, DwarfRegNum<[7]>; 62 def T0 : MipsGPRReg< 8, "8">, DwarfRegNum<[8]>; 63 def T1 : MipsGPRReg< 9, "9">, DwarfRegNum<[9]>; 64 def T2 : MipsGPRReg< 10, "10">, DwarfRegNum<[10]>; 65 def T3 : MipsGPRReg< 11, "11">, DwarfRegNum<[11]>; 66 def T4 : MipsGPRReg< 12, "12">, DwarfRegNum<[12]>; 67 def T5 : MipsGPRReg< 13, "13">, DwarfRegNum<[13]>; 68 def T6 : MipsGPRReg< 14, "14">, DwarfRegNum<[14]>; 69 def T7 : MipsGPRReg< 15, "15">, DwarfRegNum<[15]>; 70 def S0 : MipsGPRReg< 16, "16">, DwarfRegNum<[16]>; 71 def S1 : MipsGPRReg< 17, "17">, DwarfRegNum<[17]>; 72 def S2 : MipsGPRReg< 18, "18">, DwarfRegNum<[18]>; 73 def S3 : MipsGPRReg< 19, "19">, DwarfRegNum<[19]>; 74 def S4 : MipsGPRReg< 20, "20">, DwarfRegNum<[20]>; 75 def S5 : MipsGPRReg< 21, "21">, DwarfRegNum<[21]>; 76 def S6 : MipsGPRReg< 22, "22">, DwarfRegNum<[22]>; 77 def S7 : MipsGPRReg< 23, "23">, DwarfRegNum<[23]>; 78 def T8 : MipsGPRReg< 24, "24">, DwarfRegNum<[24]>; 79 def T9 : MipsGPRReg< 25, "25">, DwarfRegNum<[25]>; 80 def K0 : MipsGPRReg< 26, "26">, DwarfRegNum<[26]>; 81 def K1 : MipsGPRReg< 27, "27">, DwarfRegNum<[27]>; 82 def GP : MipsGPRReg< 28, "GP">, DwarfRegNum<[28]>; 83 def SP : MipsGPRReg< 29, "SP">, DwarfRegNum<[29]>; 84 def FP : MipsGPRReg< 30, "FP">, DwarfRegNum<[30]>; 85 def RA : MipsGPRReg< 31, "RA">, DwarfRegNum<[31]>; 86 87 /// Mips Single point precision FPU Registers 88 def F0 : FPR< 0, "F0">, DwarfRegNum<[32]>; 89 def F1 : FPR< 1, "F1">, DwarfRegNum<[33]>; 90 def F2 : FPR< 2, "F2">, DwarfRegNum<[34]>; 91 def F3 : FPR< 3, "F3">, DwarfRegNum<[35]>; 92 def F4 : FPR< 4, "F4">, DwarfRegNum<[36]>; 93 def F5 : FPR< 5, "F5">, DwarfRegNum<[37]>; 94 def F6 : FPR< 6, "F6">, DwarfRegNum<[38]>; 95 def F7 : FPR< 7, "F7">, DwarfRegNum<[39]>; 96 def F8 : FPR< 8, "F8">, DwarfRegNum<[40]>; 97 def F9 : FPR< 9, "F9">, DwarfRegNum<[41]>; 98 def F10 : FPR<10, "F10">, DwarfRegNum<[42]>; 99 def F11 : FPR<11, "F11">, DwarfRegNum<[43]>; 100 def F12 : FPR<12, "F12">, DwarfRegNum<[44]>; 101 def F13 : FPR<13, "F13">, DwarfRegNum<[45]>; 102 def F14 : FPR<14, "F14">, DwarfRegNum<[46]>; 103 def F15 : FPR<15, "F15">, DwarfRegNum<[47]>; 104 def F16 : FPR<16, "F16">, DwarfRegNum<[48]>; 105 def F17 : FPR<17, "F17">, DwarfRegNum<[49]>; 106 def F18 : FPR<18, "F18">, DwarfRegNum<[50]>; 107 def F19 : FPR<19, "F19">, DwarfRegNum<[51]>; 108 def F20 : FPR<20, "F20">, DwarfRegNum<[52]>; 109 def F21 : FPR<21, "F21">, DwarfRegNum<[53]>; 110 def F22 : FPR<22, "F22">, DwarfRegNum<[54]>; 111 def F23 : FPR<23, "F23">, DwarfRegNum<[55]>; 112 def F24 : FPR<24, "F24">, DwarfRegNum<[56]>; 113 def F25 : FPR<25, "F25">, DwarfRegNum<[57]>; 114 def F26 : FPR<26, "F26">, DwarfRegNum<[58]>; 115 def F27 : FPR<27, "F27">, DwarfRegNum<[59]>; 116 def F28 : FPR<28, "F28">, DwarfRegNum<[60]>; 117 def F29 : FPR<29, "F29">, DwarfRegNum<[61]>; 118 def F30 : FPR<30, "F30">, DwarfRegNum<[62]>; 119 def F31 : FPR<31, "F31">, DwarfRegNum<[63]>; 120 121 /// Mips Double point precision FPU Registers (aliased 122 /// with the single precision to hold 64 bit values) 123 def D0 : AFPR< 0, "F0", [F0, F1]>, DwarfRegNum<[32]>; 124 def D1 : AFPR< 2, "F2", [F2, F3]>, DwarfRegNum<[34]>; 125 def D2 : AFPR< 4, "F4", [F4, F5]>, DwarfRegNum<[36]>; 126 def D3 : AFPR< 6, "F6", [F6, F7]>, DwarfRegNum<[38]>; 127 def D4 : AFPR< 8, "F8", [F8, F9]>, DwarfRegNum<[40]>; 128 def D5 : AFPR<10, "F10", [F10, F11]>, DwarfRegNum<[42]>; 129 def D6 : AFPR<12, "F12", [F12, F13]>, DwarfRegNum<[44]>; 130 def D7 : AFPR<14, "F14", [F14, F15]>, DwarfRegNum<[46]>; 131 def D8 : AFPR<16, "F16", [F16, F17]>, DwarfRegNum<[48]>; 132 def D9 : AFPR<18, "F18", [F18, F19]>, DwarfRegNum<[50]>; 133 def D10 : AFPR<20, "F20", [F20, F21]>, DwarfRegNum<[52]>; 134 def D11 : AFPR<22, "F22", [F22, F23]>, DwarfRegNum<[54]>; 135 def D12 : AFPR<24, "F24", [F24, F25]>, DwarfRegNum<[56]>; 136 def D13 : AFPR<26, "F26", [F26, F27]>, DwarfRegNum<[58]>; 137 def D14 : AFPR<28, "F28", [F28, F29]>, DwarfRegNum<[60]>; 138 def D15 : AFPR<30, "F30", [F30, F31]>, DwarfRegNum<[62]>; 139 140 // Hi/Lo registers 141 def HI : Register<"hi">, DwarfRegNum<[64]>; 142 def LO : Register<"lo">, DwarfRegNum<[65]>; 143 144 // Status flags register 145 def FCR31 : Register<"31">; 146} 147 148//===----------------------------------------------------------------------===// 149// Register Classes 150//===----------------------------------------------------------------------===// 151 152def CPURegs : RegisterClass<"Mips", [i32], 32, 153 // Return Values and Arguments 154 [V0, V1, A0, A1, A2, A3, 155 // Not preserved across procedure calls 156 T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, 157 // Callee save 158 S0, S1, S2, S3, S4, S5, S6, S7, 159 // Reserved 160 ZERO, AT, K0, K1, GP, SP, FP, RA]> 161{ 162 let MethodProtos = [{ 163 iterator allocation_order_end(const MachineFunction &MF) const; 164 }]; 165 let MethodBodies = [{ 166 CPURegsClass::iterator 167 CPURegsClass::allocation_order_end(const MachineFunction &MF) const { 168 // The last 8 registers on the list above are reserved 169 return end()-8; 170 } 171 }]; 172} 173 174// 64bit fp: 175// * FGR64 - 32 64-bit registers 176// * AFGR64 - 16 32-bit even registers (32-bit FP Mode) 177// 178// 32bit fp: 179// * FGR32 - 16 32-bit even registers 180// * FGR32 - 32 32-bit registers (single float only mode) 181def FGR32 : RegisterClass<"Mips", [f32], 32, 182 // Return Values and Arguments 183 [F0, F1, F2, F3, F12, F13, F14, F15, 184 // Not preserved across procedure calls 185 F4, F5, F6, F7, F8, F9, F10, F11, F16, F17, F18, F19, 186 // Callee save 187 F20, F21, F22, F23, F24, F25, F26, F27, F28, F29, F30, 188 // Reserved 189 F31]> 190{ 191 let MethodProtos = [{ 192 iterator allocation_order_begin(const MachineFunction &MF) const; 193 iterator allocation_order_end(const MachineFunction &MF) const; 194 }]; 195 let MethodBodies = [{ 196 197 static const unsigned MIPS_FGR32[] = { 198 Mips::F0, Mips::F1, Mips::F2, Mips::F3, Mips::F12, Mips::F13, 199 Mips::F14, Mips::F15, Mips::F4, Mips::F5, Mips::F6, Mips::F7, 200 Mips::F8, Mips::F9, Mips::F10, Mips::F11, Mips::F16, Mips::F17, 201 Mips::F18, Mips::F19, Mips::F20, Mips::F21, Mips::F22, Mips::F23, 202 Mips::F24, Mips::F25, Mips::F26, Mips::F27, Mips::F28, Mips::F29, 203 Mips::F30 204 }; 205 206 static const unsigned MIPS_SVR4_FGR32[] = { 207 Mips::F0, Mips::F2, Mips::F12, Mips::F14, Mips::F4, 208 Mips::F6, Mips::F8, Mips::F10, Mips::F16, Mips::F18, 209 Mips::F20, Mips::F22, Mips::F24, Mips::F26, Mips::F28, Mips::F30, 210 }; 211 212 FGR32Class::iterator 213 FGR32Class::allocation_order_begin(const MachineFunction &MF) const { 214 const TargetMachine &TM = MF.getTarget(); 215 const MipsSubtarget &Subtarget = TM.getSubtarget<MipsSubtarget>(); 216 217 if (Subtarget.isSingleFloat()) 218 return MIPS_FGR32; 219 else 220 return MIPS_SVR4_FGR32; 221 } 222 223 FGR32Class::iterator 224 FGR32Class::allocation_order_end(const MachineFunction &MF) const { 225 const TargetMachine &TM = MF.getTarget(); 226 const MipsSubtarget &Subtarget = TM.getSubtarget<MipsSubtarget>(); 227 228 if (Subtarget.isSingleFloat()) 229 return MIPS_FGR32 + (sizeof(MIPS_FGR32) / sizeof(unsigned)); 230 else 231 return MIPS_SVR4_FGR32 + (sizeof(MIPS_SVR4_FGR32) / sizeof(unsigned)); 232 } 233 }]; 234} 235 236def AFGR64 : RegisterClass<"Mips", [f64], 64, 237 // Return Values and Arguments 238 [D0, D1, D6, D7, 239 // Not preserved across procedure calls 240 D2, D3, D4, D5, D8, D9, 241 // Callee save 242 D10, D11, D12, D13, D14, 243 // Reserved 244 D15]> 245{ 246 let SubRegClasses = [(FGR32 sub_fpeven, sub_fpodd)]; 247 let MethodProtos = [{ 248 iterator allocation_order_end(const MachineFunction &MF) const; 249 }]; 250 let MethodBodies = [{ 251 AFGR64Class::iterator 252 AFGR64Class::allocation_order_end(const MachineFunction &MF) const { 253 // The last register on the list above is reserved 254 return end()-1; 255 } 256 }]; 257} 258 259// Condition Register for floating point operations 260def CCR : RegisterClass<"Mips", [i32], 32, [FCR31]>; 261 262// Hi/Lo Registers 263def HILO : RegisterClass<"Mips", [i32], 32, [HI, LO]>; 264 265