1//===- ARMRegisterInfo.td - ARM Register defs --------------*- tablegen -*-===// 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 ARM register file 12//===----------------------------------------------------------------------===// 13 14// Registers are identified with 4-bit ID numbers. 15class ARMReg<bits<4> num, string n, list<Register> subregs = []> : Register<n> { 16 field bits<4> Num; 17 let Namespace = "ARM"; 18 let SubRegs = subregs; 19} 20 21class ARMFReg<bits<6> num, string n> : Register<n> { 22 field bits<6> Num; 23 let Namespace = "ARM"; 24} 25 26// Subregister indices. 27let Namespace = "ARM" in { 28// Note: Code depends on these having consecutive numbers. 29def ssub_0 : SubRegIndex; 30def ssub_1 : SubRegIndex; 31def ssub_2 : SubRegIndex; // In a Q reg. 32def ssub_3 : SubRegIndex; 33 34def dsub_0 : SubRegIndex; 35def dsub_1 : SubRegIndex; 36def dsub_2 : SubRegIndex; 37def dsub_3 : SubRegIndex; 38def dsub_4 : SubRegIndex; 39def dsub_5 : SubRegIndex; 40def dsub_6 : SubRegIndex; 41def dsub_7 : SubRegIndex; 42 43def qsub_0 : SubRegIndex; 44def qsub_1 : SubRegIndex; 45def qsub_2 : SubRegIndex; 46def qsub_3 : SubRegIndex; 47 48def qqsub_0 : SubRegIndex; 49def qqsub_1 : SubRegIndex; 50} 51 52// Integer registers 53def R0 : ARMReg< 0, "r0">, DwarfRegNum<[0]>; 54def R1 : ARMReg< 1, "r1">, DwarfRegNum<[1]>; 55def R2 : ARMReg< 2, "r2">, DwarfRegNum<[2]>; 56def R3 : ARMReg< 3, "r3">, DwarfRegNum<[3]>; 57def R4 : ARMReg< 4, "r4">, DwarfRegNum<[4]>; 58def R5 : ARMReg< 5, "r5">, DwarfRegNum<[5]>; 59def R6 : ARMReg< 6, "r6">, DwarfRegNum<[6]>; 60def R7 : ARMReg< 7, "r7">, DwarfRegNum<[7]>; 61// These require 32-bit instructions. 62let CostPerUse = 1 in { 63def R8 : ARMReg< 8, "r8">, DwarfRegNum<[8]>; 64def R9 : ARMReg< 9, "r9">, DwarfRegNum<[9]>; 65def R10 : ARMReg<10, "r10">, DwarfRegNum<[10]>; 66def R11 : ARMReg<11, "r11">, DwarfRegNum<[11]>; 67def R12 : ARMReg<12, "r12">, DwarfRegNum<[12]>; 68def SP : ARMReg<13, "sp">, DwarfRegNum<[13]>; 69def LR : ARMReg<14, "lr">, DwarfRegNum<[14]>; 70def PC : ARMReg<15, "pc">, DwarfRegNum<[15]>; 71} 72 73// Float registers 74def S0 : ARMFReg< 0, "s0">; def S1 : ARMFReg< 1, "s1">; 75def S2 : ARMFReg< 2, "s2">; def S3 : ARMFReg< 3, "s3">; 76def S4 : ARMFReg< 4, "s4">; def S5 : ARMFReg< 5, "s5">; 77def S6 : ARMFReg< 6, "s6">; def S7 : ARMFReg< 7, "s7">; 78def S8 : ARMFReg< 8, "s8">; def S9 : ARMFReg< 9, "s9">; 79def S10 : ARMFReg<10, "s10">; def S11 : ARMFReg<11, "s11">; 80def S12 : ARMFReg<12, "s12">; def S13 : ARMFReg<13, "s13">; 81def S14 : ARMFReg<14, "s14">; def S15 : ARMFReg<15, "s15">; 82def S16 : ARMFReg<16, "s16">; def S17 : ARMFReg<17, "s17">; 83def S18 : ARMFReg<18, "s18">; def S19 : ARMFReg<19, "s19">; 84def S20 : ARMFReg<20, "s20">; def S21 : ARMFReg<21, "s21">; 85def S22 : ARMFReg<22, "s22">; def S23 : ARMFReg<23, "s23">; 86def S24 : ARMFReg<24, "s24">; def S25 : ARMFReg<25, "s25">; 87def S26 : ARMFReg<26, "s26">; def S27 : ARMFReg<27, "s27">; 88def S28 : ARMFReg<28, "s28">; def S29 : ARMFReg<29, "s29">; 89def S30 : ARMFReg<30, "s30">; def S31 : ARMFReg<31, "s31">; 90 91// Aliases of the F* registers used to hold 64-bit fp values (doubles) 92let SubRegIndices = [ssub_0, ssub_1] in { 93def D0 : ARMReg< 0, "d0", [S0, S1]>, DwarfRegNum<[256]>; 94def D1 : ARMReg< 1, "d1", [S2, S3]>, DwarfRegNum<[257]>; 95def D2 : ARMReg< 2, "d2", [S4, S5]>, DwarfRegNum<[258]>; 96def D3 : ARMReg< 3, "d3", [S6, S7]>, DwarfRegNum<[259]>; 97def D4 : ARMReg< 4, "d4", [S8, S9]>, DwarfRegNum<[260]>; 98def D5 : ARMReg< 5, "d5", [S10, S11]>, DwarfRegNum<[261]>; 99def D6 : ARMReg< 6, "d6", [S12, S13]>, DwarfRegNum<[262]>; 100def D7 : ARMReg< 7, "d7", [S14, S15]>, DwarfRegNum<[263]>; 101def D8 : ARMReg< 8, "d8", [S16, S17]>, DwarfRegNum<[264]>; 102def D9 : ARMReg< 9, "d9", [S18, S19]>, DwarfRegNum<[265]>; 103def D10 : ARMReg<10, "d10", [S20, S21]>, DwarfRegNum<[266]>; 104def D11 : ARMReg<11, "d11", [S22, S23]>, DwarfRegNum<[267]>; 105def D12 : ARMReg<12, "d12", [S24, S25]>, DwarfRegNum<[268]>; 106def D13 : ARMReg<13, "d13", [S26, S27]>, DwarfRegNum<[269]>; 107def D14 : ARMReg<14, "d14", [S28, S29]>, DwarfRegNum<[270]>; 108def D15 : ARMReg<15, "d15", [S30, S31]>, DwarfRegNum<[271]>; 109} 110 111// VFP3 defines 16 additional double registers 112def D16 : ARMFReg<16, "d16">, DwarfRegNum<[272]>; 113def D17 : ARMFReg<17, "d17">, DwarfRegNum<[273]>; 114def D18 : ARMFReg<18, "d18">, DwarfRegNum<[274]>; 115def D19 : ARMFReg<19, "d19">, DwarfRegNum<[275]>; 116def D20 : ARMFReg<20, "d20">, DwarfRegNum<[276]>; 117def D21 : ARMFReg<21, "d21">, DwarfRegNum<[277]>; 118def D22 : ARMFReg<22, "d22">, DwarfRegNum<[278]>; 119def D23 : ARMFReg<23, "d23">, DwarfRegNum<[279]>; 120def D24 : ARMFReg<24, "d24">, DwarfRegNum<[280]>; 121def D25 : ARMFReg<25, "d25">, DwarfRegNum<[281]>; 122def D26 : ARMFReg<26, "d26">, DwarfRegNum<[282]>; 123def D27 : ARMFReg<27, "d27">, DwarfRegNum<[283]>; 124def D28 : ARMFReg<28, "d28">, DwarfRegNum<[284]>; 125def D29 : ARMFReg<29, "d29">, DwarfRegNum<[285]>; 126def D30 : ARMFReg<30, "d30">, DwarfRegNum<[286]>; 127def D31 : ARMFReg<31, "d31">, DwarfRegNum<[287]>; 128 129// Advanced SIMD (NEON) defines 16 quad-word aliases 130let SubRegIndices = [dsub_0, dsub_1], 131 CompositeIndices = [(ssub_2 dsub_1, ssub_0), 132 (ssub_3 dsub_1, ssub_1)] in { 133def Q0 : ARMReg< 0, "q0", [D0, D1]>; 134def Q1 : ARMReg< 1, "q1", [D2, D3]>; 135def Q2 : ARMReg< 2, "q2", [D4, D5]>; 136def Q3 : ARMReg< 3, "q3", [D6, D7]>; 137def Q4 : ARMReg< 4, "q4", [D8, D9]>; 138def Q5 : ARMReg< 5, "q5", [D10, D11]>; 139def Q6 : ARMReg< 6, "q6", [D12, D13]>; 140def Q7 : ARMReg< 7, "q7", [D14, D15]>; 141} 142let SubRegIndices = [dsub_0, dsub_1] in { 143def Q8 : ARMReg< 8, "q8", [D16, D17]>; 144def Q9 : ARMReg< 9, "q9", [D18, D19]>; 145def Q10 : ARMReg<10, "q10", [D20, D21]>; 146def Q11 : ARMReg<11, "q11", [D22, D23]>; 147def Q12 : ARMReg<12, "q12", [D24, D25]>; 148def Q13 : ARMReg<13, "q13", [D26, D27]>; 149def Q14 : ARMReg<14, "q14", [D28, D29]>; 150def Q15 : ARMReg<15, "q15", [D30, D31]>; 151} 152 153// Pseudo 256-bit registers to represent pairs of Q registers. These should 154// never be present in the emitted code. 155// These are used for NEON load / store instructions, e.g., vld4, vst3. 156// NOTE: It's possible to define more QQ registers since technically the 157// starting D register number doesn't have to be multiple of 4, e.g., 158// D1, D2, D3, D4 would be a legal quad, but that would make the subregister 159// stuff very messy. 160let SubRegIndices = [qsub_0, qsub_1], 161 CompositeIndices = [(dsub_2 qsub_1, dsub_0), (dsub_3 qsub_1, dsub_1)] in { 162def QQ0 : ARMReg<0, "qq0", [Q0, Q1]>; 163def QQ1 : ARMReg<1, "qq1", [Q2, Q3]>; 164def QQ2 : ARMReg<2, "qq2", [Q4, Q5]>; 165def QQ3 : ARMReg<3, "qq3", [Q6, Q7]>; 166def QQ4 : ARMReg<4, "qq4", [Q8, Q9]>; 167def QQ5 : ARMReg<5, "qq5", [Q10, Q11]>; 168def QQ6 : ARMReg<6, "qq6", [Q12, Q13]>; 169def QQ7 : ARMReg<7, "qq7", [Q14, Q15]>; 170} 171 172// Pseudo 512-bit registers to represent four consecutive Q registers. 173let SubRegIndices = [qqsub_0, qqsub_1], 174 CompositeIndices = [(qsub_2 qqsub_1, qsub_0), (qsub_3 qqsub_1, qsub_1), 175 (dsub_4 qqsub_1, dsub_0), (dsub_5 qqsub_1, dsub_1), 176 (dsub_6 qqsub_1, dsub_2), (dsub_7 qqsub_1, dsub_3)] in { 177def QQQQ0 : ARMReg<0, "qqqq0", [QQ0, QQ1]>; 178def QQQQ1 : ARMReg<1, "qqqq1", [QQ2, QQ3]>; 179def QQQQ2 : ARMReg<2, "qqqq2", [QQ4, QQ5]>; 180def QQQQ3 : ARMReg<3, "qqqq3", [QQ6, QQ7]>; 181} 182 183// Current Program Status Register. 184def CPSR : ARMReg<0, "cpsr">; 185def APSR : ARMReg<1, "apsr">; 186def SPSR : ARMReg<2, "spsr">; 187def FPSCR : ARMReg<3, "fpscr">; 188def ITSTATE : ARMReg<4, "itstate">; 189 190// Special Registers - only available in privileged mode. 191def FPSID : ARMReg<0, "fpsid">; 192def FPEXC : ARMReg<8, "fpexc">; 193 194// Register classes. 195// 196// pc == Program Counter 197// lr == Link Register 198// sp == Stack Pointer 199// r12 == ip (scratch) 200// r7 == Frame Pointer (thumb-style backtraces) 201// r9 == May be reserved as Thread Register 202// r11 == Frame Pointer (arm-style backtraces) 203// r10 == Stack Limit 204// 205def GPR : RegisterClass<"ARM", [i32], 32, (add (sequence "R%u", 0, 12), 206 SP, LR, PC)> { 207 // Allocate LR as the first CSR since it is always saved anyway. 208 // For Thumb1 mode, we don't want to allocate hi regs at all, as we don't 209 // know how to spill them. If we make our prologue/epilogue code smarter at 210 // some point, we can go back to using the above allocation orders for the 211 // Thumb1 instructions that know how to use hi regs. 212 let AltOrders = [(add LR, GPR), (trunc GPR, 8)]; 213 let AltOrderSelect = [{ 214 return 1 + MF.getTarget().getSubtarget<ARMSubtarget>().isThumb1Only(); 215 }]; 216} 217 218// GPRs without the PC. Some ARM instructions do not allow the PC in 219// certain operand slots, particularly as the destination. Primarily 220// useful for disassembly. 221def GPRnopc : RegisterClass<"ARM", [i32], 32, (sub GPR, PC)> { 222 let AltOrders = [(add LR, GPRnopc), (trunc GPRnopc, 8)]; 223 let AltOrderSelect = [{ 224 return 1 + MF.getTarget().getSubtarget<ARMSubtarget>().isThumb1Only(); 225 }]; 226} 227 228// GPRsp - Only the SP is legal. Used by Thumb1 instructions that want the 229// implied SP argument list. 230// FIXME: It would be better to not use this at all and refactor the 231// instructions to not have SP an an explicit argument. That makes 232// frame index resolution a bit trickier, though. 233def GPRsp : RegisterClass<"ARM", [i32], 32, (add SP)>; 234 235// restricted GPR register class. Many Thumb2 instructions allow the full 236// register range for operands, but have undefined behaviours when PC 237// or SP (R13 or R15) are used. The ARM ISA refers to these operands 238// via the BadReg() pseudo-code description. 239def rGPR : RegisterClass<"ARM", [i32], 32, (sub GPR, SP, PC)> { 240 let AltOrders = [(add LR, rGPR), (trunc rGPR, 8)]; 241 let AltOrderSelect = [{ 242 return 1 + MF.getTarget().getSubtarget<ARMSubtarget>().isThumb1Only(); 243 }]; 244} 245 246// Thumb registers are R0-R7 normally. Some instructions can still use 247// the general GPR register class above (MOV, e.g.) 248def tGPR : RegisterClass<"ARM", [i32], 32, (trunc GPR, 8)>; 249 250// The high registers in thumb mode, R8-R15. 251def hGPR : RegisterClass<"ARM", [i32], 32, (sub GPR, tGPR)>; 252 253// For tail calls, we can't use callee-saved registers, as they are restored 254// to the saved value before the tail call, which would clobber a call address. 255// Note, getMinimalPhysRegClass(R0) returns tGPR because of the names of 256// this class and the preceding one(!) This is what we want. 257def tcGPR : RegisterClass<"ARM", [i32], 32, (add R0, R1, R2, R3, R9, R12)> { 258 let AltOrders = [(and tcGPR, tGPR)]; 259 let AltOrderSelect = [{ 260 return MF.getTarget().getSubtarget<ARMSubtarget>().isThumb1Only(); 261 }]; 262} 263 264// Scalar single precision floating point register class.. 265def SPR : RegisterClass<"ARM", [f32], 32, (sequence "S%u", 0, 31)>; 266 267// Subset of SPR which can be used as a source of NEON scalars for 16-bit 268// operations 269def SPR_8 : RegisterClass<"ARM", [f32], 32, (trunc SPR, 16)>; 270 271// Scalar double precision floating point / generic 64-bit vector register 272// class. 273// ARM requires only word alignment for double. It's more performant if it 274// is double-word alignment though. 275def DPR : RegisterClass<"ARM", [f64, v8i8, v4i16, v2i32, v1i64, v2f32], 64, 276 (sequence "D%u", 0, 31)> { 277 // Allocate non-VFP2 registers D16-D31 first. 278 let AltOrders = [(rotl DPR, 16)]; 279 let AltOrderSelect = [{ return 1; }]; 280} 281 282// Subset of DPR that are accessible with VFP2 (and so that also have 283// 32-bit SPR subregs). 284def DPR_VFP2 : RegisterClass<"ARM", [f64, v8i8, v4i16, v2i32, v1i64, v2f32], 64, 285 (trunc DPR, 16)> { 286 let SubRegClasses = [(SPR ssub_0, ssub_1)]; 287} 288 289// Subset of DPR which can be used as a source of NEON scalars for 16-bit 290// operations 291def DPR_8 : RegisterClass<"ARM", [f64, v8i8, v4i16, v2i32, v1i64, v2f32], 64, 292 (trunc DPR, 8)> { 293 let SubRegClasses = [(SPR_8 ssub_0, ssub_1)]; 294} 295 296// Generic 128-bit vector register class. 297def QPR : RegisterClass<"ARM", [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], 128, 298 (sequence "Q%u", 0, 15)> { 299 let SubRegClasses = [(DPR dsub_0, dsub_1)]; 300 // Allocate non-VFP2 aliases Q8-Q15 first. 301 let AltOrders = [(rotl QPR, 8)]; 302 let AltOrderSelect = [{ return 1; }]; 303} 304 305// Subset of QPR that have 32-bit SPR subregs. 306def QPR_VFP2 : RegisterClass<"ARM", [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], 307 128, (trunc QPR, 8)> { 308 let SubRegClasses = [(SPR ssub_0, ssub_1, ssub_2, ssub_3), 309 (DPR_VFP2 dsub_0, dsub_1)]; 310} 311 312// Subset of QPR that have DPR_8 and SPR_8 subregs. 313def QPR_8 : RegisterClass<"ARM", [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], 314 128, (trunc QPR, 4)> { 315 let SubRegClasses = [(SPR_8 ssub_0, ssub_1, ssub_2, ssub_3), 316 (DPR_8 dsub_0, dsub_1)]; 317} 318 319// Pseudo 256-bit vector register class to model pairs of Q registers 320// (4 consecutive D registers). 321def QQPR : RegisterClass<"ARM", [v4i64], 256, (sequence "QQ%u", 0, 7)> { 322 let SubRegClasses = [(DPR dsub_0, dsub_1, dsub_2, dsub_3), 323 (QPR qsub_0, qsub_1)]; 324 // Allocate non-VFP2 aliases first. 325 let AltOrders = [(rotl QQPR, 4)]; 326 let AltOrderSelect = [{ return 1; }]; 327} 328 329// Subset of QQPR that have 32-bit SPR subregs. 330def QQPR_VFP2 : RegisterClass<"ARM", [v4i64], 256, (trunc QQPR, 4)> { 331 let SubRegClasses = [(SPR ssub_0, ssub_1, ssub_2, ssub_3), 332 (DPR_VFP2 dsub_0, dsub_1, dsub_2, dsub_3), 333 (QPR_VFP2 qsub_0, qsub_1)]; 334 335} 336 337// Pseudo 512-bit vector register class to model 4 consecutive Q registers 338// (8 consecutive D registers). 339def QQQQPR : RegisterClass<"ARM", [v8i64], 256, (sequence "QQQQ%u", 0, 3)> { 340 let SubRegClasses = [(DPR dsub_0, dsub_1, dsub_2, dsub_3, 341 dsub_4, dsub_5, dsub_6, dsub_7), 342 (QPR qsub_0, qsub_1, qsub_2, qsub_3)]; 343 // Allocate non-VFP2 aliases first. 344 let AltOrders = [(rotl QQQQPR, 2)]; 345 let AltOrderSelect = [{ return 1; }]; 346} 347 348// Condition code registers. 349def CCR : RegisterClass<"ARM", [i32], 32, (add CPSR)> { 350 let CopyCost = -1; // Don't allow copying of status registers. 351 let isAllocatable = 0; 352} 353