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