1 //===- ARMRegisterInfo.td - ARM Register defs -------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the "Instituto Nokia de Tecnologia" and
6 // is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
12 // Declarations that describe the ARM register file
13 //===----------------------------------------------------------------------===//
15 // Registers are identified with 4-bit ID numbers.
16 class ARMReg<bits<4> num, string n, list<Register> aliases = []> : Register<n> {
18 let Namespace = "ARM";
19 let Aliases = aliases;
22 class ARMFReg<bits<5> num, string n> : Register<n> {
24 let Namespace = "ARM";
28 def R0 : ARMReg< 0, "r0">, DwarfRegNum<0>;
29 def R1 : ARMReg< 1, "r1">, DwarfRegNum<1>;
30 def R2 : ARMReg< 2, "r2">, DwarfRegNum<2>;
31 def R3 : ARMReg< 3, "r3">, DwarfRegNum<3>;
32 def R4 : ARMReg< 4, "r4">, DwarfRegNum<4>;
33 def R5 : ARMReg< 5, "r5">, DwarfRegNum<5>;
34 def R6 : ARMReg< 6, "r6">, DwarfRegNum<6>;
35 def R7 : ARMReg< 7, "r7">, DwarfRegNum<7>;
36 def R8 : ARMReg< 8, "r8">, DwarfRegNum<8>;
37 def R9 : ARMReg< 9, "r9">, DwarfRegNum<9>;
38 def R10 : ARMReg<10, "r10">, DwarfRegNum<10>;
39 def R11 : ARMReg<11, "r11">, DwarfRegNum<11>;
40 def R12 : ARMReg<12, "r12">, DwarfRegNum<12>;
41 def SP : ARMReg<13, "sp">, DwarfRegNum<13>;
42 def LR : ARMReg<14, "lr">, DwarfRegNum<14>;
43 def PC : ARMReg<15, "pc">, DwarfRegNum<15>;
46 def S0 : ARMFReg< 0, "s0">; def S1 : ARMFReg< 1, "s1">;
47 def S2 : ARMFReg< 2, "s2">; def S3 : ARMFReg< 3, "s3">;
48 def S4 : ARMFReg< 4, "s4">; def S5 : ARMFReg< 5, "s5">;
49 def S6 : ARMFReg< 6, "s6">; def S7 : ARMFReg< 7, "s7">;
50 def S8 : ARMFReg< 8, "s8">; def S9 : ARMFReg< 9, "s9">;
51 def S10 : ARMFReg<10, "s10">; def S11 : ARMFReg<11, "s11">;
52 def S12 : ARMFReg<12, "s12">; def S13 : ARMFReg<13, "s13">;
53 def S14 : ARMFReg<14, "s14">; def S15 : ARMFReg<15, "s15">;
54 def S16 : ARMFReg<16, "s16">; def S17 : ARMFReg<17, "s17">;
55 def S18 : ARMFReg<18, "s18">; def S19 : ARMFReg<19, "s19">;
56 def S20 : ARMFReg<20, "s20">; def S21 : ARMFReg<21, "s21">;
57 def S22 : ARMFReg<22, "s22">; def S23 : ARMFReg<23, "s23">;
58 def S24 : ARMFReg<24, "s24">; def S25 : ARMFReg<25, "s25">;
59 def S26 : ARMFReg<26, "s26">; def S27 : ARMFReg<27, "s27">;
60 def S28 : ARMFReg<28, "s28">; def S29 : ARMFReg<29, "s29">;
61 def S30 : ARMFReg<30, "s30">; def S31 : ARMFReg<31, "s31">;
63 // Aliases of the F* registers used to hold 64-bit fp values (doubles)
64 def D0 : ARMReg< 0, "d0", [S0, S1]>;
65 def D1 : ARMReg< 1, "d1", [S2, S3]>;
66 def D2 : ARMReg< 2, "d2", [S4, S5]>;
67 def D3 : ARMReg< 3, "d3", [S6, S7]>;
68 def D4 : ARMReg< 4, "d4", [S8, S9]>;
69 def D5 : ARMReg< 5, "d5", [S10, S11]>;
70 def D6 : ARMReg< 6, "d6", [S12, S13]>;
71 def D7 : ARMReg< 7, "d7", [S14, S15]>;
72 def D8 : ARMReg< 8, "d8", [S16, S17]>;
73 def D9 : ARMReg< 9, "d9", [S18, S19]>;
74 def D10 : ARMReg<10, "d10", [S20, S21]>;
75 def D11 : ARMReg<11, "d11", [S22, S23]>;
76 def D12 : ARMReg<12, "d12", [S24, S25]>;
77 def D13 : ARMReg<13, "d13", [S26, S27]>;
78 def D14 : ARMReg<14, "d14", [S28, S29]>;
79 def D15 : ARMReg<15, "d15", [S30, S31]>;
83 // pc == Program Counter
84 // lr == Link Register
85 // sp == Stack Pointer
86 // r12 == ip (scratch)
87 // r7 == Frame Pointer (thumb-style backtraces)
88 // r11 == Frame Pointer (arm-style backtraces)
91 def GPR : RegisterClass<"ARM", [i32], 32, [R0, R1, R2, R3, R4, R5, R6,
92 R7, R8, R9, R10, R12, R11,
95 iterator allocation_order_begin(const MachineFunction &MF) const;
96 iterator allocation_order_end(const MachineFunction &MF) const;
98 // FIXME: We are reserving r12 in case the PEI needs to use it to
99 // generate large stack offset. Make it available once we have register
100 // scavenging. Similarly r3 is reserved in Thumb mode for now.
101 let MethodBodies = [{
102 // FP is R11, R9 is available.
103 static const unsigned ARM_GPR_AO_1[] = {
104 ARM::R3, ARM::R2, ARM::R1, ARM::R0,
105 ARM::R4, ARM::R5, ARM::R6, ARM::R7,
106 ARM::R8, ARM::R9, ARM::R10,
108 // FP is R11, R9 is not available.
109 static const unsigned ARM_GPR_AO_2[] = {
110 ARM::R3, ARM::R2, ARM::R1, ARM::R0,
111 ARM::R4, ARM::R5, ARM::R6, ARM::R7,
114 // FP is R7, R9 is available.
115 static const unsigned ARM_GPR_AO_3[] = {
116 ARM::R3, ARM::R2, ARM::R1, ARM::R0,
117 ARM::R4, ARM::R5, ARM::R6, ARM::R8,
118 ARM::R9, ARM::R10,ARM::R11,
120 // FP is R7, R9 is not available.
121 static const unsigned ARM_GPR_AO_4[] = {
122 ARM::R3, ARM::R2, ARM::R1, ARM::R0,
123 ARM::R4, ARM::R5, ARM::R6, ARM::R8,
127 // FP is R11, R9 is available, R12 is available.
128 static const unsigned ARM_GPR_AO_5[] = {
129 ARM::R3, ARM::R2, ARM::R1, ARM::R0,
130 ARM::R4, ARM::R5, ARM::R6, ARM::R7,
131 ARM::R8, ARM::R9, ARM::R10,ARM::R12,
133 // FP is R11, R9 is not available, R12 is available.
134 static const unsigned ARM_GPR_AO_6[] = {
135 ARM::R3, ARM::R2, ARM::R1, ARM::R0,
136 ARM::R4, ARM::R5, ARM::R6, ARM::R7,
137 ARM::R8, ARM::R10,ARM::R12,
139 // FP is R7, R9 is available, R12 is available.
140 static const unsigned ARM_GPR_AO_7[] = {
141 ARM::R3, ARM::R2, ARM::R1, ARM::R0,
142 ARM::R4, ARM::R5, ARM::R6, ARM::R8,
143 ARM::R9, ARM::R10,ARM::R11,ARM::R12,
145 // FP is R7, R9 is not available, R12 is available.
146 static const unsigned ARM_GPR_AO_8[] = {
147 ARM::R3, ARM::R2, ARM::R1, ARM::R0,
148 ARM::R4, ARM::R5, ARM::R6, ARM::R8,
149 ARM::R10,ARM::R11,ARM::R12,
152 // FP is R7, only low registers available.
153 static const unsigned THUMB_GPR_AO[] = {
154 ARM::R2, ARM::R1, ARM::R0,
155 ARM::R4, ARM::R5, ARM::R6, ARM::R7 };
158 GPRClass::allocation_order_begin(const MachineFunction &MF) const {
159 const TargetMachine &TM = MF.getTarget();
160 const MRegisterInfo *RI = TM.getRegisterInfo();
161 const ARMSubtarget &Subtarget = TM.getSubtarget<ARMSubtarget>();
162 if (Subtarget.isThumb())
164 if (Subtarget.useThumbBacktraces()) {
165 if (Subtarget.isR9Reserved())
166 return RI->requiresRegisterScavenging() ? ARM_GPR_AO_8 : ARM_GPR_AO_4;
168 return RI->requiresRegisterScavenging() ? ARM_GPR_AO_7 : ARM_GPR_AO_3;
170 if (Subtarget.isR9Reserved())
171 return RI->requiresRegisterScavenging() ? ARM_GPR_AO_6 : ARM_GPR_AO_2;
173 return RI->requiresRegisterScavenging() ? ARM_GPR_AO_5 : ARM_GPR_AO_1;
178 GPRClass::allocation_order_end(const MachineFunction &MF) const {
179 const TargetMachine &TM = MF.getTarget();
180 const MRegisterInfo *RI = TM.getRegisterInfo();
181 const ARMSubtarget &Subtarget = TM.getSubtarget<ARMSubtarget>();
182 GPRClass::iterator I;
183 if (Subtarget.isThumb())
184 I = THUMB_GPR_AO + (sizeof(THUMB_GPR_AO)/sizeof(unsigned));
185 else if (Subtarget.useThumbBacktraces()) {
186 if (Subtarget.isR9Reserved()) {
187 if (RI->requiresRegisterScavenging())
188 I = ARM_GPR_AO_8 + (sizeof(ARM_GPR_AO_8)/sizeof(unsigned));
190 I = ARM_GPR_AO_4 + (sizeof(ARM_GPR_AO_4)/sizeof(unsigned));
192 if (RI->requiresRegisterScavenging())
193 I = ARM_GPR_AO_7 + (sizeof(ARM_GPR_AO_7)/sizeof(unsigned));
195 I = ARM_GPR_AO_3 + (sizeof(ARM_GPR_AO_3)/sizeof(unsigned));
198 if (Subtarget.isR9Reserved()) {
199 if (RI->requiresRegisterScavenging())
200 I = ARM_GPR_AO_6 + (sizeof(ARM_GPR_AO_6)/sizeof(unsigned));
202 I = ARM_GPR_AO_2 + (sizeof(ARM_GPR_AO_2)/sizeof(unsigned));
204 if (RI->requiresRegisterScavenging())
205 I = ARM_GPR_AO_5 + (sizeof(ARM_GPR_AO_5)/sizeof(unsigned));
207 I = ARM_GPR_AO_1 + (sizeof(ARM_GPR_AO_1)/sizeof(unsigned));
211 // Mac OS X requires FP not to be clobbered for backtracing purpose.
212 return (Subtarget.isTargetDarwin() || RI->hasFP(MF)) ? I-1 : I;
217 def SPR : RegisterClass<"ARM", [f32], 32, [S0, S1, S2, S3, S4, S5, S6, S7, S8,
218 S9, S10, S11, S12, S13, S14, S15, S16, S17, S18, S19, S20, S21, S22,
219 S23, S24, S25, S26, S27, S28, S29, S30, S31]>;
221 // ARM requires only word alignment for double. It's more performant if it
222 // is double-word alignment though.
223 def DPR : RegisterClass<"ARM", [f64], 64, [D0, D1, D2, D3, D4, D5, D6, D7, D8,
224 D9, D10, D11, D12, D13, D14, D15]>;