Temporarily backing out this change until we know why some dejagnu tests are failing.
[oota-llvm.git] / lib / Target / X86 / X86RegisterInfo.td
1 //===- X86RegisterInfo.td - Describe the X86 Register File ------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the X86 Register file, defining the registers themselves,
11 // aliases between the registers, and the register classes built out of the
12 // registers.
13 //
14 //===----------------------------------------------------------------------===//
15
16 //===----------------------------------------------------------------------===//
17 //  Register definitions...
18 //
19 let Namespace = "X86" in {
20
21   // In the register alias definitions below, we define which registers alias
22   // which others.  We only specify which registers the small registers alias,
23   // because the register file generator is smart enough to figure out that
24   // AL aliases AX if we tell it that AX aliased AL (for example).
25
26   // FIXME: X86-64 have different Dwarf numbers.
27   // 8-bit registers
28   // Low registers
29   def AL : Register<"AL">, DwarfRegNum<0>;
30   def CL : Register<"CL">, DwarfRegNum<1>;
31   def DL : Register<"DL">, DwarfRegNum<2>;
32   def BL : Register<"BL">, DwarfRegNum<3>;
33
34   // X86-64 only
35   def SIL : Register<"SIL">, DwarfRegNum<4>;
36   def DIL : Register<"DIL">, DwarfRegNum<5>;
37   def BPL : Register<"BPL">, DwarfRegNum<6>;
38   def SPL : Register<"SPL">, DwarfRegNum<7>;
39   def R8B  : Register<"R8B">,  DwarfRegNum<8>;
40   def R9B  : Register<"R9B">,  DwarfRegNum<9>;
41   def R10B : Register<"R10B">, DwarfRegNum<10>;
42   def R11B : Register<"R11B">, DwarfRegNum<11>;
43   def R12B : Register<"R12B">, DwarfRegNum<12>;
44   def R13B : Register<"R13B">, DwarfRegNum<13>;
45   def R14B : Register<"R14B">, DwarfRegNum<14>;
46   def R15B : Register<"R15B">, DwarfRegNum<15>;
47
48   // High registers X86-32 only
49   def AH : Register<"AH">, DwarfRegNum<0>;
50   def CH : Register<"CH">, DwarfRegNum<1>;
51   def DH : Register<"DH">, DwarfRegNum<2>;
52   def BH : Register<"BH">, DwarfRegNum<3>;
53
54   // 16-bit registers
55   def AX : RegisterWithSubRegs<"AX", [AH,AL]>, DwarfRegNum<0>;
56   def CX : RegisterWithSubRegs<"CX", [CH,CL]>, DwarfRegNum<1>;
57   def DX : RegisterWithSubRegs<"DX", [DH,DL]>, DwarfRegNum<2>;
58   def BX : RegisterWithSubRegs<"BX", [BH,BL]>, DwarfRegNum<3>;
59   def SP : RegisterWithSubRegs<"SP", [SPL]>, DwarfRegNum<4>;
60   def BP : RegisterWithSubRegs<"BP", [BPL]>, DwarfRegNum<5>;
61   def SI : RegisterWithSubRegs<"SI", [SIL]>, DwarfRegNum<6>;
62   def DI : RegisterWithSubRegs<"DI", [DIL]>, DwarfRegNum<7>;
63   def IP : Register<"IP">, DwarfRegNum<8>;  
64   
65   // X86-64 only
66   def R8W  : RegisterWithSubRegs<"R8W", [R8B]>, DwarfRegNum<8>;
67   def R9W  : RegisterWithSubRegs<"R9W", [R9B]>, DwarfRegNum<9>;
68   def R10W : RegisterWithSubRegs<"R10W", [R10B]>, DwarfRegNum<10>;
69   def R11W : RegisterWithSubRegs<"R11W", [R11B]>, DwarfRegNum<11>;
70   def R12W : RegisterWithSubRegs<"R12W", [R12B]>, DwarfRegNum<12>;
71   def R13W : RegisterWithSubRegs<"R13W", [R13B]>, DwarfRegNum<13>;
72   def R14W : RegisterWithSubRegs<"R14W", [R14B]>, DwarfRegNum<14>;
73   def R15W : RegisterWithSubRegs<"R15W", [R15B]>, DwarfRegNum<15>;
74
75   // 32-bit registers
76   def EAX : RegisterWithSubRegs<"EAX", [AX]>, DwarfRegNum<0>;
77   def ECX : RegisterWithSubRegs<"ECX", [CX]>, DwarfRegNum<1>;
78   def EDX : RegisterWithSubRegs<"EDX", [DX]>, DwarfRegNum<2>;
79   def EBX : RegisterWithSubRegs<"EBX", [BX]>, DwarfRegNum<3>;
80   def ESP : RegisterWithSubRegs<"ESP", [SP]>, DwarfRegNum<4>;
81   def EBP : RegisterWithSubRegs<"EBP", [BP]>, DwarfRegNum<5>;
82   def ESI : RegisterWithSubRegs<"ESI", [SI]>, DwarfRegNum<6>;
83   def EDI : RegisterWithSubRegs<"EDI", [DI]>, DwarfRegNum<7>;
84   def EIP : RegisterWithSubRegs<"EIP", [IP]>, DwarfRegNum<8>;  
85   
86   // X86-64 only
87   def R8D  : RegisterWithSubRegs<"R8D", [R8W]>, DwarfRegNum<8>;
88   def R9D  : RegisterWithSubRegs<"R9D", [R9W]>, DwarfRegNum<9>;
89   def R10D : RegisterWithSubRegs<"R10D", [R10W]>, DwarfRegNum<10>;
90   def R11D : RegisterWithSubRegs<"R11D", [R11W]>, DwarfRegNum<11>;
91   def R12D : RegisterWithSubRegs<"R12D", [R12W]>, DwarfRegNum<12>;
92   def R13D : RegisterWithSubRegs<"R13D", [R13W]>, DwarfRegNum<13>;
93   def R14D : RegisterWithSubRegs<"R14D", [R14W]>, DwarfRegNum<14>;
94   def R15D : RegisterWithSubRegs<"R15D", [R15W]>, DwarfRegNum<15>;
95
96   // 64-bit registers, X86-64 only
97   def RAX : RegisterWithSubRegs<"RAX", [EAX]>, DwarfRegNum<0>;
98   def RDX : RegisterWithSubRegs<"RDX", [EDX]>, DwarfRegNum<1>;
99   def RCX : RegisterWithSubRegs<"RCX", [ECX]>, DwarfRegNum<2>;
100   def RBX : RegisterWithSubRegs<"RBX", [EBX]>, DwarfRegNum<3>;
101   def RSI : RegisterWithSubRegs<"RSI", [ESI]>, DwarfRegNum<4>;
102   def RDI : RegisterWithSubRegs<"RDI", [EDI]>, DwarfRegNum<5>;
103   def RBP : RegisterWithSubRegs<"RBP", [EBP]>, DwarfRegNum<6>;
104   def RSP : RegisterWithSubRegs<"RSP", [ESP]>, DwarfRegNum<7>;
105
106   def R8  : RegisterWithSubRegs<"R8", [R8D]>, DwarfRegNum<8>;
107   def R9  : RegisterWithSubRegs<"R9", [R9D]>, DwarfRegNum<9>;
108   def R10 : RegisterWithSubRegs<"R10", [R10D]>, DwarfRegNum<10>;
109   def R11 : RegisterWithSubRegs<"R11", [R11D]>, DwarfRegNum<11>;
110   def R12 : RegisterWithSubRegs<"R12", [R12D]>, DwarfRegNum<12>;
111   def R13 : RegisterWithSubRegs<"R13", [R13D]>, DwarfRegNum<13>;
112   def R14 : RegisterWithSubRegs<"R14", [R14D]>, DwarfRegNum<14>;
113   def R15 : RegisterWithSubRegs<"R15", [R15D]>, DwarfRegNum<15>;
114   def RIP : RegisterWithSubRegs<"RIP", [EIP]>,  DwarfRegNum<16>;
115
116   // MMX Registers. These are actually aliased to ST0 .. ST7
117   def MM0 : Register<"MM0">, DwarfRegNum<29>;
118   def MM1 : Register<"MM1">, DwarfRegNum<30>;
119   def MM2 : Register<"MM2">, DwarfRegNum<31>;
120   def MM3 : Register<"MM3">, DwarfRegNum<32>;
121   def MM4 : Register<"MM4">, DwarfRegNum<33>;
122   def MM5 : Register<"MM5">, DwarfRegNum<34>;
123   def MM6 : Register<"MM6">, DwarfRegNum<35>;
124   def MM7 : Register<"MM7">, DwarfRegNum<36>;
125   
126   // Pseudo Floating Point registers
127   def FP0 : Register<"FP0">, DwarfRegNum<-1>;
128   def FP1 : Register<"FP1">, DwarfRegNum<-1>;
129   def FP2 : Register<"FP2">, DwarfRegNum<-1>;
130   def FP3 : Register<"FP3">, DwarfRegNum<-1>;
131   def FP4 : Register<"FP4">, DwarfRegNum<-1>;
132   def FP5 : Register<"FP5">, DwarfRegNum<-1>;
133   def FP6 : Register<"FP6">, DwarfRegNum<-1>; 
134
135   // XMM Registers, used by the various SSE instruction set extensions
136   def XMM0: Register<"XMM0">, DwarfRegNum<17>;
137   def XMM1: Register<"XMM1">, DwarfRegNum<18>;
138   def XMM2: Register<"XMM2">, DwarfRegNum<19>;
139   def XMM3: Register<"XMM3">, DwarfRegNum<20>;
140   def XMM4: Register<"XMM4">, DwarfRegNum<21>;
141   def XMM5: Register<"XMM5">, DwarfRegNum<22>;
142   def XMM6: Register<"XMM6">, DwarfRegNum<23>;
143   def XMM7: Register<"XMM7">, DwarfRegNum<24>;
144
145   // X86-64 only
146   def XMM8:  Register<"XMM8">,  DwarfRegNum<25>;
147   def XMM9:  Register<"XMM9">,  DwarfRegNum<26>;
148   def XMM10: Register<"XMM10">, DwarfRegNum<27>;
149   def XMM11: Register<"XMM11">, DwarfRegNum<28>;
150   def XMM12: Register<"XMM12">, DwarfRegNum<29>;
151   def XMM13: Register<"XMM13">, DwarfRegNum<30>;
152   def XMM14: Register<"XMM14">, DwarfRegNum<31>;
153   def XMM15: Register<"XMM15">, DwarfRegNum<32>;
154
155   // Floating point stack registers
156   def ST0 : Register<"ST(0)">, DwarfRegNum<11>;
157   def ST1 : Register<"ST(1)">, DwarfRegNum<12>;
158   def ST2 : Register<"ST(2)">, DwarfRegNum<13>;
159   def ST3 : Register<"ST(3)">, DwarfRegNum<14>;
160   def ST4 : Register<"ST(4)">, DwarfRegNum<15>;
161   def ST5 : Register<"ST(5)">, DwarfRegNum<16>;
162   def ST6 : Register<"ST(6)">, DwarfRegNum<17>;
163   def ST7 : Register<"ST(7)">, DwarfRegNum<18>; 
164 }
165
166
167 //===----------------------------------------------------------------------===//
168 // Subregister Set Definitions... now that we have all of the pieces, define the
169 // sub registers for each register.
170 //
171
172 def : SubRegSet<1, [AX, CX, DX, BX, SP,  BP,  SI,  DI,  
173                     R8W, R9W, R10W, R11W, R12W, R13W, R14W, R15W],
174                    [AL, CL, DL, BL, SPL, BPL, SIL, DIL, 
175                     R8B, R9B, R10B, R11B, R12B, R13B, R14B, R15B]>;
176
177 // It's unclear if this subreg set is safe, given that not all registers
178 // in the class have an 'H' subreg.
179 // def : SubRegSet<2, [AX, CX, DX, BX],
180 //                    [AH, CH, DH, BH]>;
181
182 def : SubRegSet<1, [EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI,  
183                     R8D, R9D, R10D, R11D, R12D, R13D, R14D, R15D],
184                    [AL, CL, DL, BL, SPL, BPL, SIL, DIL, 
185                     R8B, R9B, R10B, R11B, R12B, R13B, R14B, R15B]>;
186
187 def : SubRegSet<2, [EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI,  
188                     R8D, R9D, R10D, R11D, R12D, R13D, R14D, R15D],
189                    [AX,  CX,  DX,  BX,  SP,  BP,  SI,  DI, 
190                     R8W, R9W, R10W, R11W, R12W, R13W, R14W, R15W]>;
191
192
193 def : SubRegSet<1, [RAX, RCX, RDX, RBX, RSP, RBP, RSI, RDI,  
194                     R8,  R9,  R10, R11, R12, R13, R14, R15],
195                    [AL, CL, DL, BL, SPL, BPL, SIL, DIL, 
196                     R8B, R9B, R10B, R11B, R12B, R13B, R14B, R15B]>;
197
198 def : SubRegSet<2, [RAX, RCX, RDX, RBX, RSP, RBP, RSI, RDI,  
199                     R8,  R9,  R10, R11, R12, R13, R14, R15],
200                    [AX,  CX,  DX,  BX,  SP,  BP,  SI,  DI, 
201                     R8W, R9W, R10W, R11W, R12W, R13W, R14W, R15W]>;
202                     
203 def : SubRegSet<3, [RAX, RCX, RDX, RBX, RSP, RBP, RSI, RDI,  
204                     R8,  R9,  R10, R11, R12, R13, R14, R15],
205                    [EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI, 
206                     R8D, R9D, R10D, R11D, R12D, R13D, R14D, R15D]>;
207
208 //===----------------------------------------------------------------------===//
209 // Register Class Definitions... now that we have all of the pieces, define the
210 // top-level register classes.  The order specified in the register list is
211 // implicitly defined to be the register allocation order.
212 //
213
214 // List call-clobbered registers before callee-save registers. RBX, RBP, (and 
215 // R12, R13, R14, and R15 for X86-64) are callee-save registers.
216 // In 64-mode, there are 12 additional i8 registers, SIL, DIL, BPL, SPL, and
217 // R8B, ... R15B. 
218 // FIXME: Allow AH, CH, DH, BH in 64-mode for non-REX instructions,
219 def GR8 : RegisterClass<"X86", [i8],  8,
220                         [AL, CL, DL, BL, AH, CH, DH, BH, SIL, DIL, BPL, SPL,
221                          R8B, R9B, R10B, R11B, R12B, R13B, R14B, R15B]> {
222   let MethodProtos = [{
223     iterator allocation_order_begin(const MachineFunction &MF) const;
224     iterator allocation_order_end(const MachineFunction &MF) const;
225   }];
226   let MethodBodies = [{
227       // Does the function dedicate RBP / EBP to being a frame ptr?
228       // If so, don't allocate SPL or BPL.
229       static const unsigned X86_GR8_AO_64_fp[] =
230       {X86::AL, X86::CL, X86::DL, X86::SIL, X86::DIL,
231        X86::R8B, X86::R9B, X86::R10B, X86::R11B,
232        X86::BL, X86::R14B, X86::R15B, X86::R12B, X86::R13B};
233       // If not, just don't allocate SPL.
234       static const unsigned X86_GR8_AO_64[] =
235       {X86::AL, X86::CL, X86::DL, X86::SIL, X86::DIL,
236        X86::R8B, X86::R9B, X86::R10B, X86::R11B,
237        X86::BL, X86::R14B, X86::R15B, X86::R12B, X86::R13B, X86::BPL};
238       // In 32-mode, none of the 8-bit registers aliases EBP or ESP.
239       static const unsigned X86_GR8_AO_32[] =
240       {X86::AL, X86::CL, X86::DL, X86::AH, X86::CH, X86::DH, X86::BL, X86::BH};
241
242     GR8Class::iterator
243     GR8Class::allocation_order_begin(const MachineFunction &MF) const {
244       const TargetMachine &TM = MF.getTarget();
245       const MRegisterInfo *RI = TM.getRegisterInfo();
246       const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
247       if (!Subtarget.is64Bit())
248         return X86_GR8_AO_32;
249       else if (RI->hasFP(MF))
250         return X86_GR8_AO_64_fp;
251       else
252         return X86_GR8_AO_64;
253     }
254
255     GR8Class::iterator
256     GR8Class::allocation_order_end(const MachineFunction &MF) const {
257       const TargetMachine &TM = MF.getTarget();
258       const MRegisterInfo *RI = TM.getRegisterInfo();
259       const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
260       if (!Subtarget.is64Bit())
261         return X86_GR8_AO_32 + (sizeof(X86_GR8_AO_32) / sizeof(unsigned));
262       else if (RI->hasFP(MF))
263         return X86_GR8_AO_64_fp + (sizeof(X86_GR8_AO_64_fp) / sizeof(unsigned));
264       else
265         return X86_GR8_AO_64 + (sizeof(X86_GR8_AO_64) / sizeof(unsigned));
266     }
267   }];
268 }
269
270
271 def GR16 : RegisterClass<"X86", [i16], 16,
272                          [AX, CX, DX, SI, DI, BX, BP, SP,
273                           R8W, R9W, R10W, R11W, R12W, R13W, R14W, R15W]> {
274   let SubRegClassList = [GR8];
275   let MethodProtos = [{
276     iterator allocation_order_begin(const MachineFunction &MF) const;
277     iterator allocation_order_end(const MachineFunction &MF) const;
278   }];
279   let MethodBodies = [{
280       // Does the function dedicate RBP / EBP to being a frame ptr?
281       // If so, don't allocate SP or BP.
282       static const unsigned X86_GR16_AO_64_fp[] =
283       {X86::AX, X86::CX, X86::DX, X86::SI, X86::DI,
284        X86::R8W, X86::R9W, X86::R10W, X86::R11W,
285        X86::BX, X86::R14W, X86::R15W, X86::R12W, X86::R13W};
286       static const unsigned X86_GR16_AO_32_fp[] =
287       {X86::AX, X86::CX, X86::DX, X86::SI, X86::DI, X86::BX};
288       // If not, just don't allocate SPL.
289       static const unsigned X86_GR16_AO_64[] =
290       {X86::AX, X86::CX, X86::DX, X86::SI, X86::DI,
291        X86::R8W, X86::R9W, X86::R10W, X86::R11W,
292        X86::BX, X86::R14W, X86::R15W, X86::R12W, X86::R13W, X86::BP};
293       static const unsigned X86_GR16_AO_32[] =
294       {X86::AX, X86::CX, X86::DX, X86::SI, X86::DI, X86::BX, X86::BP};
295
296     GR16Class::iterator
297     GR16Class::allocation_order_begin(const MachineFunction &MF) const {
298       const TargetMachine &TM = MF.getTarget();
299       const MRegisterInfo *RI = TM.getRegisterInfo();
300       const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
301       if (Subtarget.is64Bit()) {
302         if (RI->hasFP(MF))
303           return X86_GR16_AO_64_fp;
304         else
305           return X86_GR16_AO_64;
306       } else {
307         if (RI->hasFP(MF))
308           return X86_GR16_AO_32_fp;
309         else
310           return X86_GR16_AO_32;
311       }
312     }
313
314     GR16Class::iterator
315     GR16Class::allocation_order_end(const MachineFunction &MF) const {
316       const TargetMachine &TM = MF.getTarget();
317       const MRegisterInfo *RI = TM.getRegisterInfo();
318       const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
319       if (Subtarget.is64Bit()) {
320         if (RI->hasFP(MF))
321           return X86_GR16_AO_64_fp+(sizeof(X86_GR16_AO_64_fp)/sizeof(unsigned));
322         else
323           return X86_GR16_AO_64 + (sizeof(X86_GR16_AO_64) / sizeof(unsigned));
324       } else {
325         if (RI->hasFP(MF))
326           return X86_GR16_AO_32_fp+(sizeof(X86_GR16_AO_32_fp)/sizeof(unsigned));
327         else
328           return X86_GR16_AO_32 + (sizeof(X86_GR16_AO_32) / sizeof(unsigned));
329       }
330     }
331   }];
332 }
333
334
335 def GR32 : RegisterClass<"X86", [i32], 32, 
336                          [EAX, ECX, EDX, ESI, EDI, EBX, EBP, ESP,
337                           R8D, R9D, R10D, R11D, R12D, R13D, R14D, R15D]> {
338   let SubRegClassList = [GR8, GR16];
339   let MethodProtos = [{
340     iterator allocation_order_begin(const MachineFunction &MF) const;
341     iterator allocation_order_end(const MachineFunction &MF) const;
342   }];
343   let MethodBodies = [{
344       // Does the function dedicate RBP / EBP to being a frame ptr?
345       // If so, don't allocate ESP or EBP.
346       static const unsigned X86_GR32_AO_64_fp[] =
347       {X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI,
348        X86::R8D, X86::R9D, X86::R10D, X86::R11D,
349        X86::EBX, X86::R14D, X86::R15D, X86::R12D, X86::R13D};
350       static const unsigned X86_GR32_AO_32_fp[] =
351       {X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI, X86::EBX};
352       // If not, just don't allocate SPL.
353       static const unsigned X86_GR32_AO_64[] =
354       {X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI,
355        X86::R8D, X86::R9D, X86::R10D, X86::R11D,
356        X86::EBX, X86::R14D, X86::R15D, X86::R12D, X86::R13D, X86::EBP};
357       static const unsigned X86_GR32_AO_32[] =
358       {X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI, X86::EBX, X86::EBP};
359
360     GR32Class::iterator
361     GR32Class::allocation_order_begin(const MachineFunction &MF) const {
362       const TargetMachine &TM = MF.getTarget();
363       const MRegisterInfo *RI = TM.getRegisterInfo();
364       const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
365       if (Subtarget.is64Bit()) {
366         if (RI->hasFP(MF))
367           return X86_GR32_AO_64_fp;
368         else
369           return X86_GR32_AO_64;
370       } else {
371         if (RI->hasFP(MF))
372           return X86_GR32_AO_32_fp;
373         else
374           return X86_GR32_AO_32;
375       }
376     }
377
378     GR32Class::iterator
379     GR32Class::allocation_order_end(const MachineFunction &MF) const {
380       const TargetMachine &TM = MF.getTarget();
381       const MRegisterInfo *RI = TM.getRegisterInfo();
382       const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
383       if (Subtarget.is64Bit()) {
384         if (RI->hasFP(MF))
385           return X86_GR32_AO_64_fp+(sizeof(X86_GR32_AO_64_fp)/sizeof(unsigned));
386         else
387           return X86_GR32_AO_64 + (sizeof(X86_GR32_AO_64) / sizeof(unsigned));
388       } else {
389         if (RI->hasFP(MF))
390           return X86_GR32_AO_32_fp+(sizeof(X86_GR32_AO_32_fp)/sizeof(unsigned));
391         else
392           return X86_GR32_AO_32 + (sizeof(X86_GR32_AO_32) / sizeof(unsigned));
393       }
394     }
395   }];
396 }
397
398
399 def GR64 : RegisterClass<"X86", [i64], 64, 
400                          [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
401                           RBX, R14, R15, R12, R13, RBP, RSP]> {
402   let SubRegClassList = [GR8, GR16, GR32];
403   let MethodProtos = [{
404     iterator allocation_order_end(const MachineFunction &MF) const;
405   }];
406   let MethodBodies = [{
407     GR64Class::iterator
408     GR64Class::allocation_order_end(const MachineFunction &MF) const {
409       const TargetMachine &TM = MF.getTarget();
410       const MRegisterInfo *RI = TM.getRegisterInfo();
411       if (RI->hasFP(MF)) // Does the function dedicate RBP to being a frame ptr?
412         return end()-2;  // If so, don't allocate RSP or RBP
413       else
414         return end()-1;  // If not, just don't allocate RSP
415     }
416   }];
417 }
418
419
420 // GR16, GR32 subclasses which contain registers that have GR8 sub-registers.
421 // These should only be used for 32-bit mode.
422 def GR16_ : RegisterClass<"X86", [i16], 16, [AX, CX, DX, BX]> {
423   let SubRegClassList = [GR8];
424 }
425 def GR32_ : RegisterClass<"X86", [i32], 32, [EAX, ECX, EDX, EBX]> {
426   let SubRegClassList = [GR8, GR16];
427 }
428
429 // Scalar SSE2 floating point registers.
430 def FR32 : RegisterClass<"X86", [f32], 32,
431                          [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
432                           XMM8, XMM9, XMM10, XMM11,
433                           XMM12, XMM13, XMM14, XMM15]> {
434   let MethodProtos = [{
435     iterator allocation_order_end(const MachineFunction &MF) const;
436   }];
437   let MethodBodies = [{
438     FR32Class::iterator
439     FR32Class::allocation_order_end(const MachineFunction &MF) const {
440       const TargetMachine &TM = MF.getTarget();
441       const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
442       if (!Subtarget.is64Bit())
443         return end()-8; // Only XMM0 to XMM7 are available in 32-bit mode.
444       else
445         return end();
446     }
447   }];
448 }
449
450 def FR64 : RegisterClass<"X86", [f64], 64,
451                          [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
452                           XMM8, XMM9, XMM10, XMM11,
453                           XMM12, XMM13, XMM14, XMM15]> {
454   let MethodProtos = [{
455     iterator allocation_order_end(const MachineFunction &MF) const;
456   }];
457   let MethodBodies = [{
458     FR64Class::iterator
459     FR64Class::allocation_order_end(const MachineFunction &MF) const {
460       const TargetMachine &TM = MF.getTarget();
461       const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
462       if (!Subtarget.is64Bit())
463         return end()-8; // Only XMM0 to XMM7 are available in 32-bit mode.
464       else
465         return end();
466     }
467   }];
468 }
469
470
471 // FIXME: This sets up the floating point register files as though they are f64
472 // values, though they really are f80 values.  This will cause us to spill
473 // values as 64-bit quantities instead of 80-bit quantities, which is much much
474 // faster on common hardware.  In reality, this should be controlled by a
475 // command line option or something.
476
477 def RFP32 : RegisterClass<"X86", [f32], 32, [FP0, FP1, FP2, FP3, FP4, FP5, FP6]>;
478 def RFP64 : RegisterClass<"X86", [f64], 32, [FP0, FP1, FP2, FP3, FP4, FP5, FP6]>;
479 def RFP80 : RegisterClass<"X86", [f80], 32, [FP0, FP1, FP2, FP3, FP4, FP5, FP6]>;
480
481 // Floating point stack registers (these are not allocatable by the
482 // register allocator - the floating point stackifier is responsible
483 // for transforming FPn allocations to STn registers)
484 def RST : RegisterClass<"X86", [f64], 32,
485                         [ST0, ST1, ST2, ST3, ST4, ST5, ST6, ST7]> {
486     let MethodProtos = [{
487     iterator allocation_order_end(const MachineFunction &MF) const;
488   }];
489   let MethodBodies = [{
490     RSTClass::iterator
491     RSTClass::allocation_order_end(const MachineFunction &MF) const {
492       return begin();
493     }
494   }];
495 }
496
497 // Generic vector registers: VR64 and VR128.
498 def VR64  : RegisterClass<"X86", [v8i8, v4i16, v2i32, v1i64], 64,
499                           [MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7]>;
500 def VR128 : RegisterClass<"X86", [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],128,
501                           [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
502                            XMM8, XMM9, XMM10, XMM11,
503                            XMM12, XMM13, XMM14, XMM15]> {
504   let MethodProtos = [{
505     iterator allocation_order_end(const MachineFunction &MF) const;
506   }];
507   let MethodBodies = [{
508     VR128Class::iterator
509     VR128Class::allocation_order_end(const MachineFunction &MF) const {
510       const TargetMachine &TM = MF.getTarget();
511       const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
512       if (!Subtarget.is64Bit())
513         return end()-8; // Only XMM0 to XMM7 are available in 32-bit mode.
514       else
515         return end();
516     }
517   }];
518 }