]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/PowerPC/PPCRegisterInfo.td
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / PowerPC / PPCRegisterInfo.td
1 //===-- PPCRegisterInfo.td - The PowerPC Register File -----*- 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 //===----------------------------------------------------------------------===//
12
13 let Namespace = "PPC" in {
14 def sub_lt : SubRegIndex<1>;
15 def sub_gt : SubRegIndex<1, 1>;
16 def sub_eq : SubRegIndex<1, 2>;
17 def sub_un : SubRegIndex<1, 3>;
18 def sub_32 : SubRegIndex<32>;
19 def sub_64 : SubRegIndex<64>;
20 }
21
22
23 class PPCReg<string n> : Register<n> {
24   let Namespace = "PPC";
25 }
26
27 // We identify all our registers with a 5-bit ID, for consistency's sake.
28
29 // GPR - One of the 32 32-bit general-purpose registers
30 class GPR<bits<5> num, string n> : PPCReg<n> {
31   let HWEncoding{4-0} = num;
32 }
33
34 // GP8 - One of the 32 64-bit general-purpose registers
35 class GP8<GPR SubReg, string n> : PPCReg<n> {
36   let HWEncoding = SubReg.HWEncoding;
37   let SubRegs = [SubReg];
38   let SubRegIndices = [sub_32];
39 }
40
41 // SPE - One of the 32 64-bit general-purpose registers (SPE)
42 class SPE<GPR SubReg, string n> : PPCReg<n> {
43   let HWEncoding = SubReg.HWEncoding;
44   let SubRegs = [SubReg];
45   let SubRegIndices = [sub_32];
46 }
47
48 // SPR - One of the 32-bit special-purpose registers
49 class SPR<bits<10> num, string n> : PPCReg<n> {
50   let HWEncoding{9-0} = num;
51 }
52
53 // FPR - One of the 32 64-bit floating-point registers
54 class FPR<bits<5> num, string n> : PPCReg<n> {
55   let HWEncoding{4-0} = num;
56 }
57
58 // QFPR - One of the 32 256-bit floating-point vector registers (used for QPX)
59 class QFPR<FPR SubReg, string n> : PPCReg<n> {
60   let HWEncoding = SubReg.HWEncoding;
61   let SubRegs = [SubReg];
62   let SubRegIndices = [sub_64];
63 }
64
65 // VF - One of the 32 64-bit floating-point subregisters of the vector
66 // registers (used by VSX).
67 class VF<bits<5> num, string n> : PPCReg<n> {
68   let HWEncoding{4-0} = num;
69   let HWEncoding{5} = 1;
70 }
71
72 // VR - One of the 32 128-bit vector registers
73 class VR<VF SubReg, string n> : PPCReg<n> {
74   let HWEncoding{4-0} = SubReg.HWEncoding{4-0};
75   let HWEncoding{5} = 0;
76   let SubRegs = [SubReg];
77   let SubRegIndices = [sub_64];
78 }
79
80 // VSRL - One of the 32 128-bit VSX registers that overlap with the scalar
81 // floating-point registers.
82 class VSRL<FPR SubReg, string n> : PPCReg<n> {
83   let HWEncoding = SubReg.HWEncoding;
84   let SubRegs = [SubReg];
85   let SubRegIndices = [sub_64];
86 }
87
88 // VSXReg - One of the VSX registers in the range vs32-vs63 with numbering
89 // and encoding to match.
90 class VSXReg<bits<6> num, string n> : PPCReg<n> {
91   let HWEncoding{5-0} = num;
92 }
93
94 // CR - One of the 8 4-bit condition registers
95 class CR<bits<3> num, string n, list<Register> subregs> : PPCReg<n> {
96   let HWEncoding{2-0} = num;
97   let SubRegs = subregs;
98 }
99
100 // CRBIT - One of the 32 1-bit condition register fields
101 class CRBIT<bits<5> num, string n> : PPCReg<n> {
102   let HWEncoding{4-0} = num;
103 }
104
105 // General-purpose registers
106 foreach Index = 0-31 in {
107   def R#Index : GPR<Index, "r"#Index>, DwarfRegNum<[-2, Index]>;
108 }
109
110 // 64-bit General-purpose registers
111 foreach Index = 0-31 in {
112   def X#Index : GP8<!cast<GPR>("R"#Index), "r"#Index>,
113                     DwarfRegNum<[Index, -2]>;
114 }
115
116 // SPE registers
117 foreach Index = 0-31 in {
118   def S#Index : SPE<!cast<GPR>("R"#Index), "r"#Index>,
119                     DwarfRegNum<[!add(Index, 1200), !add(Index, 1200)]>;
120 }
121
122 // Floating-point registers
123 foreach Index = 0-31 in {
124   def F#Index : FPR<Index, "f"#Index>,
125                 DwarfRegNum<[!add(Index, 32), !add(Index, 32)]>;
126 }
127
128 // 64-bit Floating-point subregisters of Altivec registers
129 // Note: the register names are v0-v31 or vs32-vs63 depending on the use.
130 //       Custom C++ code is used to produce the correct name and encoding.
131 foreach Index = 0-31 in {
132   def VF#Index : VF<Index, "v" #Index>,
133                  DwarfRegNum<[!add(Index, 77), !add(Index, 77)]>;
134 }
135
136 // QPX Floating-point registers
137 foreach Index = 0-31 in {
138   def QF#Index : QFPR<!cast<FPR>("F"#Index), "q"#Index>,
139                  DwarfRegNum<[!add(Index, 32), !add(Index, 32)]>;
140 }
141
142 // Vector registers
143 foreach Index = 0-31 in {
144   def V#Index : VR<!cast<VF>("VF"#Index), "v"#Index>,
145                 DwarfRegNum<[!add(Index, 77), !add(Index, 77)]>;
146 }
147
148 // VSX registers
149 foreach Index = 0-31 in {
150   def VSL#Index : VSRL<!cast<FPR>("F"#Index), "vs"#Index>,
151                   DwarfRegAlias<!cast<FPR>("F"#Index)>;
152 }
153
154 // Dummy VSX registers, this defines string: "vs32"-"vs63", and is only used for
155 // asm printing.
156 foreach Index = 32-63 in {
157   def VSX#Index : VSXReg<Index, "vs"#Index>;
158 }
159
160 // The reprsentation of r0 when treated as the constant 0.
161 def ZERO  : GPR<0, "0">,    DwarfRegAlias<R0>;
162 def ZERO8 : GP8<ZERO, "0">, DwarfRegAlias<X0>;
163
164 // Representations of the frame pointer used by ISD::FRAMEADDR.
165 def FP   : GPR<0 /* arbitrary */, "**FRAME POINTER**">;
166 def FP8  : GP8<FP, "**FRAME POINTER**">;
167
168 // Representations of the base pointer used by setjmp.
169 def BP   : GPR<0 /* arbitrary */, "**BASE POINTER**">;
170 def BP8  : GP8<BP, "**BASE POINTER**">;
171
172 // Condition register bits
173 def CR0LT : CRBIT< 0, "0">;
174 def CR0GT : CRBIT< 1, "1">;
175 def CR0EQ : CRBIT< 2, "2">;
176 def CR0UN : CRBIT< 3, "3">;
177 def CR1LT : CRBIT< 4, "4">;
178 def CR1GT : CRBIT< 5, "5">;
179 def CR1EQ : CRBIT< 6, "6">;
180 def CR1UN : CRBIT< 7, "7">;
181 def CR2LT : CRBIT< 8, "8">;
182 def CR2GT : CRBIT< 9, "9">;
183 def CR2EQ : CRBIT<10, "10">;
184 def CR2UN : CRBIT<11, "11">;
185 def CR3LT : CRBIT<12, "12">;
186 def CR3GT : CRBIT<13, "13">;
187 def CR3EQ : CRBIT<14, "14">;
188 def CR3UN : CRBIT<15, "15">;
189 def CR4LT : CRBIT<16, "16">;
190 def CR4GT : CRBIT<17, "17">;
191 def CR4EQ : CRBIT<18, "18">;
192 def CR4UN : CRBIT<19, "19">;
193 def CR5LT : CRBIT<20, "20">;
194 def CR5GT : CRBIT<21, "21">;
195 def CR5EQ : CRBIT<22, "22">;
196 def CR5UN : CRBIT<23, "23">;
197 def CR6LT : CRBIT<24, "24">;
198 def CR6GT : CRBIT<25, "25">;
199 def CR6EQ : CRBIT<26, "26">;
200 def CR6UN : CRBIT<27, "27">;
201 def CR7LT : CRBIT<28, "28">;
202 def CR7GT : CRBIT<29, "29">;
203 def CR7EQ : CRBIT<30, "30">;
204 def CR7UN : CRBIT<31, "31">;
205
206 // Condition registers
207 let SubRegIndices = [sub_lt, sub_gt, sub_eq, sub_un] in {
208 def CR0 : CR<0, "cr0", [CR0LT, CR0GT, CR0EQ, CR0UN]>, DwarfRegNum<[68, 68]>;
209 def CR1 : CR<1, "cr1", [CR1LT, CR1GT, CR1EQ, CR1UN]>, DwarfRegNum<[69, 69]>;
210 def CR2 : CR<2, "cr2", [CR2LT, CR2GT, CR2EQ, CR2UN]>, DwarfRegNum<[70, 70]>;
211 def CR3 : CR<3, "cr3", [CR3LT, CR3GT, CR3EQ, CR3UN]>, DwarfRegNum<[71, 71]>;
212 def CR4 : CR<4, "cr4", [CR4LT, CR4GT, CR4EQ, CR4UN]>, DwarfRegNum<[72, 72]>;
213 def CR5 : CR<5, "cr5", [CR5LT, CR5GT, CR5EQ, CR5UN]>, DwarfRegNum<[73, 73]>;
214 def CR6 : CR<6, "cr6", [CR6LT, CR6GT, CR6EQ, CR6UN]>, DwarfRegNum<[74, 74]>;
215 def CR7 : CR<7, "cr7", [CR7LT, CR7GT, CR7EQ, CR7UN]>, DwarfRegNum<[75, 75]>;
216 }
217
218 // Link register
219 def LR  : SPR<8, "lr">, DwarfRegNum<[-2, 65]>;
220 //let Aliases = [LR] in
221 def LR8 : SPR<8, "lr">, DwarfRegNum<[65, -2]>;
222
223 // Count register
224 def CTR  : SPR<9, "ctr">, DwarfRegNum<[-2, 66]>;
225 def CTR8 : SPR<9, "ctr">, DwarfRegNum<[66, -2]>;
226
227 // VRsave register
228 def VRSAVE: SPR<256, "vrsave">, DwarfRegNum<[109]>;
229
230 // SPE extra registers
231 // SPE Accumulator for multiply-accumulate SPE operations.  Never directly
232 // accessed, so there's no real encoding for it.
233 def SPEACC: DwarfRegNum<[99, 111]>;
234 def SPEFSCR: SPR<512, "spefscr">, DwarfRegNum<[612, 112]>;
235
236 def XER: SPR<1, "xer">, DwarfRegNum<[76]>;
237
238 // Carry bit.  In the architecture this is really bit 0 of the XER register
239 // (which really is SPR register 1);  this is the only bit interesting to a
240 // compiler.
241 def CARRY: SPR<1, "xer">, DwarfRegNum<[76]> {
242   let Aliases = [XER];
243 }
244
245 // FP rounding mode:  bits 30 and 31 of the FP status and control register
246 // This is not allocated as a normal register; it appears only in
247 // Uses and Defs.  The ABI says it needs to be preserved by a function,
248 // but this is not achieved by saving and restoring it as with
249 // most registers, it has to be done in code; to make this work all the
250 // return and call instructions are described as Uses of RM, so instructions
251 // that do nothing but change RM will not get deleted.
252 def RM: PPCReg<"**ROUNDING MODE**">;
253
254 /// Register classes
255 // Allocate volatiles first
256 // then nonvolatiles in reverse order since stmw/lmw save from rN to r31
257 def GPRC : RegisterClass<"PPC", [i32], 32, (add (sequence "R%u", 2, 12),
258                                                 (sequence "R%u", 30, 13),
259                                                 R31, R0, R1, FP, BP)> {
260   // On non-Darwin PPC64 systems, R2 can be allocated, but must be restored, so
261   // put it at the end of the list.
262   let AltOrders = [(add (sub GPRC, R2), R2)];
263   let AltOrderSelect = [{
264     const PPCSubtarget &S = MF.getSubtarget<PPCSubtarget>();
265     return S.isPPC64() && S.isSVR4ABI();
266   }];
267 }
268
269 def G8RC : RegisterClass<"PPC", [i64], 64, (add (sequence "X%u", 2, 12),
270                                                 (sequence "X%u", 30, 14),
271                                                 X31, X13, X0, X1, FP8, BP8)> {
272   // On non-Darwin PPC64 systems, R2 can be allocated, but must be restored, so
273   // put it at the end of the list.
274   let AltOrders = [(add (sub G8RC, X2), X2)];
275   let AltOrderSelect = [{
276     const PPCSubtarget &S = MF.getSubtarget<PPCSubtarget>();
277     return S.isPPC64() && S.isSVR4ABI();
278   }];
279 }
280
281 // For some instructions r0 is special (representing the value 0 instead of
282 // the value in the r0 register), and we use these register subclasses to
283 // prevent r0 from being allocated for use by those instructions.
284 def GPRC_NOR0 : RegisterClass<"PPC", [i32], 32, (add (sub GPRC, R0), ZERO)> {
285   // On non-Darwin PPC64 systems, R2 can be allocated, but must be restored, so
286   // put it at the end of the list.
287   let AltOrders = [(add (sub GPRC_NOR0, R2), R2)];
288   let AltOrderSelect = [{
289     const PPCSubtarget &S = MF.getSubtarget<PPCSubtarget>();
290     return S.isPPC64() && S.isSVR4ABI();
291   }];
292 }
293
294 def G8RC_NOX0 : RegisterClass<"PPC", [i64], 64, (add (sub G8RC, X0), ZERO8)> {
295   // On non-Darwin PPC64 systems, R2 can be allocated, but must be restored, so
296   // put it at the end of the list.
297   let AltOrders = [(add (sub G8RC_NOX0, X2), X2)];
298   let AltOrderSelect = [{
299     const PPCSubtarget &S = MF.getSubtarget<PPCSubtarget>();
300     return S.isPPC64() && S.isSVR4ABI();
301   }];
302 }
303
304 def SPERC : RegisterClass<"PPC", [f64], 64, (add (sequence "S%u", 2, 12),
305                                                 (sequence "S%u", 30, 13),
306                                                 S31, S0, S1)>;
307
308 def SPE4RC : RegisterClass<"PPC", [f32], 32, (add GPRC)>;
309
310 // Allocate volatiles first, then non-volatiles in reverse order. With the SVR4
311 // ABI the size of the Floating-point register save area is determined by the
312 // allocated non-volatile register with the lowest register number, as FP
313 // register N is spilled to offset 8 * (32 - N) below the back chain word of the
314 // previous stack frame. By allocating non-volatiles in reverse order we make
315 // sure that the Floating-point register save area is always as small as
316 // possible because there aren't any unused spill slots.
317 def F8RC : RegisterClass<"PPC", [f64], 64, (add (sequence "F%u", 0, 13),
318                                                 (sequence "F%u", 31, 14))>;
319 def F4RC : RegisterClass<"PPC", [f32], 32, (add F8RC)>;
320
321 def VRRC : RegisterClass<"PPC",
322                          [v16i8,v8i16,v4i32,v2i64,v1i128,v4f32,v2f64, f128],
323                          128,
324                          (add V2, V3, V4, V5, V0, V1, V6, V7, V8, V9, V10, V11,
325                              V12, V13, V14, V15, V16, V17, V18, V19, V31, V30,
326                              V29, V28, V27, V26, V25, V24, V23, V22, V21, V20)>;
327
328 // VSX register classes (the allocation order mirrors that of the corresponding
329 // subregister classes).
330 def VSLRC : RegisterClass<"PPC", [v4i32,v4f32,v2f64,v2i64], 128,
331                           (add (sequence "VSL%u", 0, 13),
332                                (sequence "VSL%u", 31, 14))>;
333 def VSRC  : RegisterClass<"PPC", [v4i32,v4f32,v2f64,v2i64], 128,
334                           (add VSLRC, VRRC)>;
335
336 // Register classes for the 64-bit "scalar" VSX subregisters.
337 def VFRC :  RegisterClass<"PPC", [f64], 64,
338                           (add VF2, VF3, VF4, VF5, VF0, VF1, VF6, VF7,
339                                VF8, VF9, VF10, VF11, VF12, VF13, VF14,
340                                VF15, VF16, VF17, VF18, VF19, VF31, VF30,
341                                VF29, VF28, VF27, VF26, VF25, VF24, VF23,
342                                VF22, VF21, VF20)>;
343 def VSFRC : RegisterClass<"PPC", [f64], 64, (add F8RC, VFRC)>;
344
345 // Allow spilling GPR's into caller-saved VSR's.
346 def SPILLTOVSRRC : RegisterClass<"PPC", [i64, f64], 64, (add G8RC, (sub VSFRC,
347                                 (sequence "VF%u", 31, 20),
348                                 (sequence "F%u", 31, 14)))>;
349
350 // Register class for single precision scalars in VSX registers
351 def VSSRC : RegisterClass<"PPC", [f32], 32, (add VSFRC)>;
352
353 // For QPX
354 def QFRC : RegisterClass<"PPC", [v4f64], 256, (add (sequence "QF%u", 0, 13),
355                                                 (sequence "QF%u", 31, 14))>;
356 def QSRC : RegisterClass<"PPC", [v4f32], 128, (add QFRC)>;
357 def QBRC : RegisterClass<"PPC", [v4i1], 256, (add QFRC)> {
358   // These are actually stored as floating-point values where a positive
359   // number is true and anything else (including NaN) is false.
360   let Size = 256;
361 }
362
363 def CRBITRC : RegisterClass<"PPC", [i1], 32,
364   (add CR2LT, CR2GT, CR2EQ, CR2UN,
365        CR3LT, CR3GT, CR3EQ, CR3UN,
366        CR4LT, CR4GT, CR4EQ, CR4UN,
367        CR5LT, CR5GT, CR5EQ, CR5UN,
368        CR6LT, CR6GT, CR6EQ, CR6UN,
369        CR7LT, CR7GT, CR7EQ, CR7UN,
370        CR1LT, CR1GT, CR1EQ, CR1UN,
371        CR0LT, CR0GT, CR0EQ, CR0UN)> {
372   let Size = 32;
373 }
374
375 def CRRC : RegisterClass<"PPC", [i32], 32, (add CR0, CR1, CR5, CR6,
376                                                 CR7, CR2, CR3, CR4)>;
377
378 def CRRC0 : RegisterClass<"PPC", [i32], 32, (add CR0)>;
379
380 // The CTR registers are not allocatable because they're used by the
381 // decrement-and-branch instructions, and thus need to stay live across
382 // multiple basic blocks.
383 def CTRRC : RegisterClass<"PPC", [i32], 32, (add CTR)> {
384   let isAllocatable = 0;
385 }
386 def CTRRC8 : RegisterClass<"PPC", [i64], 64, (add CTR8)> {
387   let isAllocatable = 0;
388 }
389
390 def VRSAVERC : RegisterClass<"PPC", [i32], 32, (add VRSAVE)>;
391 def CARRYRC : RegisterClass<"PPC", [i32], 32, (add CARRY, XER)> {
392   let CopyCost = -1;
393 }
394