1 //===- X86RegisterInfo.td - Describe the X86 Register File --*- tablegen -*-==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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
14 //===----------------------------------------------------------------------===//
16 //===----------------------------------------------------------------------===//
17 // Register definitions...
19 let Namespace = "X86" in {
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).
26 // Dwarf numbering is different for 32-bit and 64-bit, and there are
27 // variations by target as well. Currently the first entry is for X86-64,
28 // second - for EH on X86-32/Darwin and third is 'generic' one (X86-32/Linux
29 // and debug information on X86-32/Darwin)
33 def AL : Register<"al">, DwarfRegNum<[0, 0, 0]>;
34 def DL : Register<"dl">, DwarfRegNum<[1, 2, 2]>;
35 def CL : Register<"cl">, DwarfRegNum<[2, 1, 1]>;
36 def BL : Register<"bl">, DwarfRegNum<[3, 3, 3]>;
39 def SIL : Register<"sil">, DwarfRegNum<[4, 6, 6]>;
40 def DIL : Register<"dil">, DwarfRegNum<[5, 7, 7]>;
41 def BPL : Register<"bpl">, DwarfRegNum<[6, 4, 5]>;
42 def SPL : Register<"spl">, DwarfRegNum<[7, 5, 4]>;
43 def R8B : Register<"r8b">, DwarfRegNum<[8, -2, -2]>;
44 def R9B : Register<"r9b">, DwarfRegNum<[9, -2, -2]>;
45 def R10B : Register<"r10b">, DwarfRegNum<[10, -2, -2]>;
46 def R11B : Register<"r11b">, DwarfRegNum<[11, -2, -2]>;
47 def R12B : Register<"r12b">, DwarfRegNum<[12, -2, -2]>;
48 def R13B : Register<"r13b">, DwarfRegNum<[13, -2, -2]>;
49 def R14B : Register<"r14b">, DwarfRegNum<[14, -2, -2]>;
50 def R15B : Register<"r15b">, DwarfRegNum<[15, -2, -2]>;
52 // High registers. On x86-64, these cannot be used in any instruction
54 def AH : Register<"ah">, DwarfRegNum<[0, 0, 0]>;
55 def DH : Register<"dh">, DwarfRegNum<[1, 2, 2]>;
56 def CH : Register<"ch">, DwarfRegNum<[2, 1, 1]>;
57 def BH : Register<"bh">, DwarfRegNum<[3, 3, 3]>;
60 def AX : RegisterWithSubRegs<"ax", [AL,AH]>, DwarfRegNum<[0, 0, 0]>;
61 def DX : RegisterWithSubRegs<"dx", [DL,DH]>, DwarfRegNum<[1, 2, 2]>;
62 def CX : RegisterWithSubRegs<"cx", [CL,CH]>, DwarfRegNum<[2, 1, 1]>;
63 def BX : RegisterWithSubRegs<"bx", [BL,BH]>, DwarfRegNum<[3, 3, 3]>;
64 def SI : RegisterWithSubRegs<"si", [SIL]>, DwarfRegNum<[4, 6, 6]>;
65 def DI : RegisterWithSubRegs<"di", [DIL]>, DwarfRegNum<[5, 7, 7]>;
66 def BP : RegisterWithSubRegs<"bp", [BPL]>, DwarfRegNum<[6, 4, 5]>;
67 def SP : RegisterWithSubRegs<"sp", [SPL]>, DwarfRegNum<[7, 5, 4]>;
68 def IP : Register<"ip">, DwarfRegNum<[16]>;
71 def R8W : RegisterWithSubRegs<"r8w", [R8B]>, DwarfRegNum<[8, -2, -2]>;
72 def R9W : RegisterWithSubRegs<"r9w", [R9B]>, DwarfRegNum<[9, -2, -2]>;
73 def R10W : RegisterWithSubRegs<"r10w", [R10B]>, DwarfRegNum<[10, -2, -2]>;
74 def R11W : RegisterWithSubRegs<"r11w", [R11B]>, DwarfRegNum<[11, -2, -2]>;
75 def R12W : RegisterWithSubRegs<"r12w", [R12B]>, DwarfRegNum<[12, -2, -2]>;
76 def R13W : RegisterWithSubRegs<"r13w", [R13B]>, DwarfRegNum<[13, -2, -2]>;
77 def R14W : RegisterWithSubRegs<"r14w", [R14B]>, DwarfRegNum<[14, -2, -2]>;
78 def R15W : RegisterWithSubRegs<"r15w", [R15B]>, DwarfRegNum<[15, -2, -2]>;
81 def EAX : RegisterWithSubRegs<"eax", [AX]>, DwarfRegNum<[0, 0, 0]>;
82 def EDX : RegisterWithSubRegs<"edx", [DX]>, DwarfRegNum<[1, 2, 2]>;
83 def ECX : RegisterWithSubRegs<"ecx", [CX]>, DwarfRegNum<[2, 1, 1]>;
84 def EBX : RegisterWithSubRegs<"ebx", [BX]>, DwarfRegNum<[3, 3, 3]>;
85 def ESI : RegisterWithSubRegs<"esi", [SI]>, DwarfRegNum<[4, 6, 6]>;
86 def EDI : RegisterWithSubRegs<"edi", [DI]>, DwarfRegNum<[5, 7, 7]>;
87 def EBP : RegisterWithSubRegs<"ebp", [BP]>, DwarfRegNum<[6, 4, 5]>;
88 def ESP : RegisterWithSubRegs<"esp", [SP]>, DwarfRegNum<[7, 5, 4]>;
89 def EIP : RegisterWithSubRegs<"eip", [IP]>, DwarfRegNum<[16, 8, 8]>;
92 def R8D : RegisterWithSubRegs<"r8d", [R8W]>, DwarfRegNum<[8, -2, -2]>;
93 def R9D : RegisterWithSubRegs<"r9d", [R9W]>, DwarfRegNum<[9, -2, -2]>;
94 def R10D : RegisterWithSubRegs<"r10d", [R10W]>, DwarfRegNum<[10, -2, -2]>;
95 def R11D : RegisterWithSubRegs<"r11d", [R11W]>, DwarfRegNum<[11, -2, -2]>;
96 def R12D : RegisterWithSubRegs<"r12d", [R12W]>, DwarfRegNum<[12, -2, -2]>;
97 def R13D : RegisterWithSubRegs<"r13d", [R13W]>, DwarfRegNum<[13, -2, -2]>;
98 def R14D : RegisterWithSubRegs<"r14d", [R14W]>, DwarfRegNum<[14, -2, -2]>;
99 def R15D : RegisterWithSubRegs<"r15d", [R15W]>, DwarfRegNum<[15, -2, -2]>;
101 // 64-bit registers, X86-64 only
102 def RAX : RegisterWithSubRegs<"rax", [EAX]>, DwarfRegNum<[0, -2, -2]>;
103 def RDX : RegisterWithSubRegs<"rdx", [EDX]>, DwarfRegNum<[1, -2, -2]>;
104 def RCX : RegisterWithSubRegs<"rcx", [ECX]>, DwarfRegNum<[2, -2, -2]>;
105 def RBX : RegisterWithSubRegs<"rbx", [EBX]>, DwarfRegNum<[3, -2, -2]>;
106 def RSI : RegisterWithSubRegs<"rsi", [ESI]>, DwarfRegNum<[4, -2, -2]>;
107 def RDI : RegisterWithSubRegs<"rdi", [EDI]>, DwarfRegNum<[5, -2, -2]>;
108 def RBP : RegisterWithSubRegs<"rbp", [EBP]>, DwarfRegNum<[6, -2, -2]>;
109 def RSP : RegisterWithSubRegs<"rsp", [ESP]>, DwarfRegNum<[7, -2, -2]>;
111 def R8 : RegisterWithSubRegs<"r8", [R8D]>, DwarfRegNum<[8, -2, -2]>;
112 def R9 : RegisterWithSubRegs<"r9", [R9D]>, DwarfRegNum<[9, -2, -2]>;
113 def R10 : RegisterWithSubRegs<"r10", [R10D]>, DwarfRegNum<[10, -2, -2]>;
114 def R11 : RegisterWithSubRegs<"r11", [R11D]>, DwarfRegNum<[11, -2, -2]>;
115 def R12 : RegisterWithSubRegs<"r12", [R12D]>, DwarfRegNum<[12, -2, -2]>;
116 def R13 : RegisterWithSubRegs<"r13", [R13D]>, DwarfRegNum<[13, -2, -2]>;
117 def R14 : RegisterWithSubRegs<"r14", [R14D]>, DwarfRegNum<[14, -2, -2]>;
118 def R15 : RegisterWithSubRegs<"r15", [R15D]>, DwarfRegNum<[15, -2, -2]>;
119 def RIP : RegisterWithSubRegs<"rip", [EIP]>, DwarfRegNum<[16, -2, -2]>;
121 // MMX Registers. These are actually aliased to ST0 .. ST7
122 def MM0 : Register<"mm0">, DwarfRegNum<[41, 29, 29]>;
123 def MM1 : Register<"mm1">, DwarfRegNum<[42, 30, 30]>;
124 def MM2 : Register<"mm2">, DwarfRegNum<[43, 31, 31]>;
125 def MM3 : Register<"mm3">, DwarfRegNum<[44, 32, 32]>;
126 def MM4 : Register<"mm4">, DwarfRegNum<[45, 33, 33]>;
127 def MM5 : Register<"mm5">, DwarfRegNum<[46, 34, 34]>;
128 def MM6 : Register<"mm6">, DwarfRegNum<[47, 35, 35]>;
129 def MM7 : Register<"mm7">, DwarfRegNum<[48, 36, 36]>;
131 // Pseudo Floating Point registers
132 def FP0 : Register<"fp0">;
133 def FP1 : Register<"fp1">;
134 def FP2 : Register<"fp2">;
135 def FP3 : Register<"fp3">;
136 def FP4 : Register<"fp4">;
137 def FP5 : Register<"fp5">;
138 def FP6 : Register<"fp6">;
140 // XMM Registers, used by the various SSE instruction set extensions
141 def XMM0: Register<"xmm0">, DwarfRegNum<[17, 21, 21]>;
142 def XMM1: Register<"xmm1">, DwarfRegNum<[18, 22, 22]>;
143 def XMM2: Register<"xmm2">, DwarfRegNum<[19, 23, 23]>;
144 def XMM3: Register<"xmm3">, DwarfRegNum<[20, 24, 24]>;
145 def XMM4: Register<"xmm4">, DwarfRegNum<[21, 25, 25]>;
146 def XMM5: Register<"xmm5">, DwarfRegNum<[22, 26, 26]>;
147 def XMM6: Register<"xmm6">, DwarfRegNum<[23, 27, 27]>;
148 def XMM7: Register<"xmm7">, DwarfRegNum<[24, 28, 28]>;
151 def XMM8: Register<"xmm8">, DwarfRegNum<[25, -2, -2]>;
152 def XMM9: Register<"xmm9">, DwarfRegNum<[26, -2, -2]>;
153 def XMM10: Register<"xmm10">, DwarfRegNum<[27, -2, -2]>;
154 def XMM11: Register<"xmm11">, DwarfRegNum<[28, -2, -2]>;
155 def XMM12: Register<"xmm12">, DwarfRegNum<[29, -2, -2]>;
156 def XMM13: Register<"xmm13">, DwarfRegNum<[30, -2, -2]>;
157 def XMM14: Register<"xmm14">, DwarfRegNum<[31, -2, -2]>;
158 def XMM15: Register<"xmm15">, DwarfRegNum<[32, -2, -2]>;
160 // Floating point stack registers
161 def ST0 : Register<"st(0)">, DwarfRegNum<[33, 12, 11]>;
162 def ST1 : Register<"st(1)">, DwarfRegNum<[34, 13, 12]>;
163 def ST2 : Register<"st(2)">, DwarfRegNum<[35, 14, 13]>;
164 def ST3 : Register<"st(3)">, DwarfRegNum<[36, 15, 14]>;
165 def ST4 : Register<"st(4)">, DwarfRegNum<[37, 16, 15]>;
166 def ST5 : Register<"st(5)">, DwarfRegNum<[38, 17, 16]>;
167 def ST6 : Register<"st(6)">, DwarfRegNum<[39, 18, 17]>;
168 def ST7 : Register<"st(7)">, DwarfRegNum<[40, 19, 18]>;
170 // Status flags register
171 def EFLAGS : Register<"flags">;
174 def CS : Register<"cs">;
175 def DS : Register<"ds">;
176 def SS : Register<"ss">;
177 def ES : Register<"es">;
178 def FS : Register<"fs">;
179 def GS : Register<"gs">;
183 //===----------------------------------------------------------------------===//
184 // Subregister Set Definitions... now that we have all of the pieces, define the
185 // sub registers for each register.
188 def x86_subreg_8bit : PatLeaf<(i32 1)>;
189 def x86_subreg_8bit_hi : PatLeaf<(i32 2)>;
190 def x86_subreg_16bit : PatLeaf<(i32 3)>;
191 def x86_subreg_32bit : PatLeaf<(i32 4)>;
193 def : SubRegSet<1, [AX, CX, DX, BX, SP, BP, SI, DI,
194 R8W, R9W, R10W, R11W, R12W, R13W, R14W, R15W],
195 [AL, CL, DL, BL, SPL, BPL, SIL, DIL,
196 R8B, R9B, R10B, R11B, R12B, R13B, R14B, R15B]>;
198 def : SubRegSet<2, [AX, CX, DX, BX],
201 def : SubRegSet<1, [EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI,
202 R8D, R9D, R10D, R11D, R12D, R13D, R14D, R15D],
203 [AL, CL, DL, BL, SPL, BPL, SIL, DIL,
204 R8B, R9B, R10B, R11B, R12B, R13B, R14B, R15B]>;
206 def : SubRegSet<2, [EAX, ECX, EDX, EBX],
209 def : SubRegSet<3, [EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI,
210 R8D, R9D, R10D, R11D, R12D, R13D, R14D, R15D],
211 [AX, CX, DX, BX, SP, BP, SI, DI,
212 R8W, R9W, R10W, R11W, R12W, R13W, R14W, R15W]>;
214 def : SubRegSet<1, [RAX, RCX, RDX, RBX, RSP, RBP, RSI, RDI,
215 R8, R9, R10, R11, R12, R13, R14, R15],
216 [AL, CL, DL, BL, SPL, BPL, SIL, DIL,
217 R8B, R9B, R10B, R11B, R12B, R13B, R14B, R15B]>;
219 def : SubRegSet<2, [RAX, RCX, RDX, RBX],
222 def : SubRegSet<3, [RAX, RCX, RDX, RBX, RSP, RBP, RSI, RDI,
223 R8, R9, R10, R11, R12, R13, R14, R15],
224 [AX, CX, DX, BX, SP, BP, SI, DI,
225 R8W, R9W, R10W, R11W, R12W, R13W, R14W, R15W]>;
227 def : SubRegSet<4, [RAX, RCX, RDX, RBX, RSP, RBP, RSI, RDI,
228 R8, R9, R10, R11, R12, R13, R14, R15],
229 [EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI,
230 R8D, R9D, R10D, R11D, R12D, R13D, R14D, R15D]>;
232 //===----------------------------------------------------------------------===//
233 // Register Class Definitions... now that we have all of the pieces, define the
234 // top-level register classes. The order specified in the register list is
235 // implicitly defined to be the register allocation order.
238 // List call-clobbered registers before callee-save registers. RBX, RBP, (and
239 // R12, R13, R14, and R15 for X86-64) are callee-save registers.
240 // In 64-mode, there are 12 additional i8 registers, SIL, DIL, BPL, SPL, and
242 // Allocate R12 and R13 last, as these require an extra byte when
243 // encoded in x86_64 instructions.
244 // FIXME: Allow AH, CH, DH, BH to be used as general-purpose registers in
245 // 64-bit mode. The main complication is that they cannot be encoded in an
246 // instruction requiring a REX prefix, while SIL, DIL, BPL, R8D, etc.
247 // require a REX prefix. For example, "addb %ah, %dil" and "movzbl %ah, %r8d"
248 // cannot be encoded.
249 def GR8 : RegisterClass<"X86", [i8], 8,
250 [AL, CL, DL, BL, AH, CH, DH, BH, SIL, DIL, BPL, SPL,
251 R8B, R9B, R10B, R11B, R14B, R15B, R12B, R13B]> {
252 let MethodProtos = [{
253 iterator allocation_order_begin(const MachineFunction &MF) const;
254 iterator allocation_order_end(const MachineFunction &MF) const;
256 let MethodBodies = [{
257 // Does the function dedicate RBP / EBP to being a frame ptr?
258 // If so, don't allocate SPL or BPL.
259 static const unsigned X86_GR8_AO_64_fp[] = {
260 X86::AL, X86::CL, X86::DL, X86::SIL, X86::DIL,
261 X86::R8B, X86::R9B, X86::R10B, X86::R11B,
262 X86::BL, X86::R14B, X86::R15B, X86::R12B, X86::R13B
264 // If not, just don't allocate SPL.
265 static const unsigned X86_GR8_AO_64[] = {
266 X86::AL, X86::CL, X86::DL, X86::SIL, X86::DIL,
267 X86::R8B, X86::R9B, X86::R10B, X86::R11B,
268 X86::BL, X86::R14B, X86::R15B, X86::R12B, X86::R13B, X86::BPL
270 // In 32-mode, none of the 8-bit registers aliases EBP or ESP.
271 static const unsigned X86_GR8_AO_32[] = {
272 X86::AL, X86::CL, X86::DL, X86::AH, X86::CH, X86::DH, X86::BL, X86::BH
276 GR8Class::allocation_order_begin(const MachineFunction &MF) const {
277 const TargetMachine &TM = MF.getTarget();
278 const TargetRegisterInfo *RI = TM.getRegisterInfo();
279 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
280 if (!Subtarget.is64Bit())
281 return X86_GR8_AO_32;
282 else if (RI->hasFP(MF))
283 return X86_GR8_AO_64_fp;
285 return X86_GR8_AO_64;
289 GR8Class::allocation_order_end(const MachineFunction &MF) const {
290 const TargetMachine &TM = MF.getTarget();
291 const TargetRegisterInfo *RI = TM.getRegisterInfo();
292 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
293 if (!Subtarget.is64Bit())
294 return X86_GR8_AO_32 + (sizeof(X86_GR8_AO_32) / sizeof(unsigned));
295 else if (RI->hasFP(MF))
296 return X86_GR8_AO_64_fp + (sizeof(X86_GR8_AO_64_fp) / sizeof(unsigned));
298 return X86_GR8_AO_64 + (sizeof(X86_GR8_AO_64) / sizeof(unsigned));
304 def GR16 : RegisterClass<"X86", [i16], 16,
305 [AX, CX, DX, SI, DI, BX, BP, SP,
306 R8W, R9W, R10W, R11W, R14W, R15W, R12W, R13W]> {
307 let SubRegClassList = [GR8, GR8];
308 let MethodProtos = [{
309 iterator allocation_order_begin(const MachineFunction &MF) const;
310 iterator allocation_order_end(const MachineFunction &MF) const;
312 let MethodBodies = [{
313 // Does the function dedicate RBP / EBP to being a frame ptr?
314 // If so, don't allocate SP or BP.
315 static const unsigned X86_GR16_AO_64_fp[] = {
316 X86::AX, X86::CX, X86::DX, X86::SI, X86::DI,
317 X86::R8W, X86::R9W, X86::R10W, X86::R11W,
318 X86::BX, X86::R14W, X86::R15W, X86::R12W, X86::R13W
320 static const unsigned X86_GR16_AO_32_fp[] = {
321 X86::AX, X86::CX, X86::DX, X86::SI, X86::DI, X86::BX
323 // If not, just don't allocate SP.
324 static const unsigned X86_GR16_AO_64[] = {
325 X86::AX, X86::CX, X86::DX, X86::SI, X86::DI,
326 X86::R8W, X86::R9W, X86::R10W, X86::R11W,
327 X86::BX, X86::R14W, X86::R15W, X86::R12W, X86::R13W, X86::BP
329 static const unsigned X86_GR16_AO_32[] = {
330 X86::AX, X86::CX, X86::DX, X86::SI, X86::DI, X86::BX, X86::BP
334 GR16Class::allocation_order_begin(const MachineFunction &MF) const {
335 const TargetMachine &TM = MF.getTarget();
336 const TargetRegisterInfo *RI = TM.getRegisterInfo();
337 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
338 if (Subtarget.is64Bit()) {
340 return X86_GR16_AO_64_fp;
342 return X86_GR16_AO_64;
345 return X86_GR16_AO_32_fp;
347 return X86_GR16_AO_32;
352 GR16Class::allocation_order_end(const MachineFunction &MF) const {
353 const TargetMachine &TM = MF.getTarget();
354 const TargetRegisterInfo *RI = TM.getRegisterInfo();
355 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
356 if (Subtarget.is64Bit()) {
358 return X86_GR16_AO_64_fp+(sizeof(X86_GR16_AO_64_fp)/sizeof(unsigned));
360 return X86_GR16_AO_64 + (sizeof(X86_GR16_AO_64) / sizeof(unsigned));
363 return X86_GR16_AO_32_fp+(sizeof(X86_GR16_AO_32_fp)/sizeof(unsigned));
365 return X86_GR16_AO_32 + (sizeof(X86_GR16_AO_32) / sizeof(unsigned));
372 def GR32 : RegisterClass<"X86", [i32], 32,
373 [EAX, ECX, EDX, ESI, EDI, EBX, EBP, ESP,
374 R8D, R9D, R10D, R11D, R14D, R15D, R12D, R13D]> {
375 let SubRegClassList = [GR8, GR8, GR16];
376 let MethodProtos = [{
377 iterator allocation_order_begin(const MachineFunction &MF) const;
378 iterator allocation_order_end(const MachineFunction &MF) const;
380 let MethodBodies = [{
381 // Does the function dedicate RBP / EBP to being a frame ptr?
382 // If so, don't allocate ESP or EBP.
383 static const unsigned X86_GR32_AO_64_fp[] = {
384 X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI,
385 X86::R8D, X86::R9D, X86::R10D, X86::R11D,
386 X86::EBX, X86::R14D, X86::R15D, X86::R12D, X86::R13D
388 static const unsigned X86_GR32_AO_32_fp[] = {
389 X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI, X86::EBX
391 // If not, just don't allocate ESP.
392 static const unsigned X86_GR32_AO_64[] = {
393 X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI,
394 X86::R8D, X86::R9D, X86::R10D, X86::R11D,
395 X86::EBX, X86::R14D, X86::R15D, X86::R12D, X86::R13D, X86::EBP
397 static const unsigned X86_GR32_AO_32[] = {
398 X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI, X86::EBX, X86::EBP
402 GR32Class::allocation_order_begin(const MachineFunction &MF) const {
403 const TargetMachine &TM = MF.getTarget();
404 const TargetRegisterInfo *RI = TM.getRegisterInfo();
405 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
406 if (Subtarget.is64Bit()) {
408 return X86_GR32_AO_64_fp;
410 return X86_GR32_AO_64;
413 return X86_GR32_AO_32_fp;
415 return X86_GR32_AO_32;
420 GR32Class::allocation_order_end(const MachineFunction &MF) const {
421 const TargetMachine &TM = MF.getTarget();
422 const TargetRegisterInfo *RI = TM.getRegisterInfo();
423 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
424 if (Subtarget.is64Bit()) {
426 return X86_GR32_AO_64_fp+(sizeof(X86_GR32_AO_64_fp)/sizeof(unsigned));
428 return X86_GR32_AO_64 + (sizeof(X86_GR32_AO_64) / sizeof(unsigned));
431 return X86_GR32_AO_32_fp+(sizeof(X86_GR32_AO_32_fp)/sizeof(unsigned));
433 return X86_GR32_AO_32 + (sizeof(X86_GR32_AO_32) / sizeof(unsigned));
440 def GR64 : RegisterClass<"X86", [i64], 64,
441 [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
442 RBX, R14, R15, R12, R13, RBP, RSP]> {
443 let SubRegClassList = [GR8, GR8, GR16, GR32];
444 let MethodProtos = [{
445 iterator allocation_order_end(const MachineFunction &MF) const;
447 let MethodBodies = [{
449 GR64Class::allocation_order_end(const MachineFunction &MF) const {
450 const TargetMachine &TM = MF.getTarget();
451 const TargetRegisterInfo *RI = TM.getRegisterInfo();
452 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
453 if (!Subtarget.is64Bit())
454 return begin(); // None of these are allocatable in 32-bit.
455 if (RI->hasFP(MF)) // Does the function dedicate RBP to being a frame ptr?
456 return end()-2; // If so, don't allocate RSP or RBP
458 return end()-1; // If not, just don't allocate RSP
464 // GR8_ABCD_L, GR8_ABCD_H, GR16_ABCD, GR32_ABCD, GR64_ABCD - Subclasses of
465 // GR8, GR16, GR32, and GR64 which contain just the "a" "b", "c", and "d"
466 // registers. On x86-32, GR16_ABCD and GR32_ABCD are classes for registers
467 // that support 8-bit subreg operations. On x86-64, GR16_ABCD, GR32_ABCD,
468 // and GR64_ABCD are classes for registers that support 8-bit h-register
470 def GR8_ABCD_L : RegisterClass<"X86", [i8], 8, [AL, CL, DL, BL]> {
472 def GR8_ABCD_H : RegisterClass<"X86", [i8], 8, [AH, CH, DH, BH]> {
474 def GR16_ABCD : RegisterClass<"X86", [i16], 16, [AX, CX, DX, BX]> {
475 let SubRegClassList = [GR8_ABCD_L, GR8_ABCD_H];
477 def GR32_ABCD : RegisterClass<"X86", [i32], 32, [EAX, ECX, EDX, EBX]> {
478 let SubRegClassList = [GR8_ABCD_L, GR8_ABCD_H, GR16_ABCD];
480 def GR64_ABCD : RegisterClass<"X86", [i64], 64, [RAX, RCX, RDX, RBX]> {
481 let SubRegClassList = [GR8_ABCD_L, GR8_ABCD_H, GR16_ABCD, GR32_ABCD];
484 // GR8_NOREX, GR16_NOREX, GR32_NOREX, GR64_NOREX - Subclasses of
485 // GR8, GR16, GR32, and GR64 which contain only the first 8 GPRs.
486 // On x86-64, GR64_NOREX, GR32_NOREX and GR16_NOREX are the classes
487 // of registers which do not by themselves require a REX prefix.
488 def GR8_NOREX : RegisterClass<"X86", [i8], 8,
489 [AL, CL, DL, BL, AH, CH, DH, BH,
490 SIL, DIL, BPL, SPL]> {
491 let MethodProtos = [{
492 iterator allocation_order_begin(const MachineFunction &MF) const;
493 iterator allocation_order_end(const MachineFunction &MF) const;
495 let MethodBodies = [{
496 // Does the function dedicate RBP / EBP to being a frame ptr?
497 // If so, don't allocate SPL or BPL.
498 static const unsigned X86_GR8_NOREX_AO_64_fp[] = {
499 X86::AL, X86::CL, X86::DL, X86::SIL, X86::DIL, X86::BL
501 // If not, just don't allocate SPL.
502 static const unsigned X86_GR8_NOREX_AO_64[] = {
503 X86::AL, X86::CL, X86::DL, X86::SIL, X86::DIL, X86::BL, X86::BPL
505 // In 32-mode, none of the 8-bit registers aliases EBP or ESP.
506 static const unsigned X86_GR8_NOREX_AO_32[] = {
507 X86::AL, X86::CL, X86::DL, X86::AH, X86::CH, X86::DH, X86::BL, X86::BH
510 GR8_NOREXClass::iterator
511 GR8_NOREXClass::allocation_order_begin(const MachineFunction &MF) const {
512 const TargetMachine &TM = MF.getTarget();
513 const TargetRegisterInfo *RI = TM.getRegisterInfo();
514 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
515 if (!Subtarget.is64Bit())
516 return X86_GR8_NOREX_AO_32;
517 else if (RI->hasFP(MF))
518 return X86_GR8_NOREX_AO_64_fp;
520 return X86_GR8_NOREX_AO_64;
523 GR8_NOREXClass::iterator
524 GR8_NOREXClass::allocation_order_end(const MachineFunction &MF) const {
525 const TargetMachine &TM = MF.getTarget();
526 const TargetRegisterInfo *RI = TM.getRegisterInfo();
527 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
528 if (!Subtarget.is64Bit())
529 return X86_GR8_NOREX_AO_32 +
530 (sizeof(X86_GR8_NOREX_AO_32) / sizeof(unsigned));
531 else if (RI->hasFP(MF))
532 return X86_GR8_NOREX_AO_64_fp +
533 (sizeof(X86_GR8_NOREX_AO_64_fp) / sizeof(unsigned));
535 return X86_GR8_NOREX_AO_64 +
536 (sizeof(X86_GR8_NOREX_AO_64) / sizeof(unsigned));
540 def GR16_NOREX : RegisterClass<"X86", [i16], 16,
541 [AX, CX, DX, SI, DI, BX, BP, SP]> {
542 let SubRegClassList = [GR8_NOREX, GR8_NOREX];
543 let MethodProtos = [{
544 iterator allocation_order_begin(const MachineFunction &MF) const;
545 iterator allocation_order_end(const MachineFunction &MF) const;
547 let MethodBodies = [{
548 // Does the function dedicate RBP / EBP to being a frame ptr?
549 // If so, don't allocate SP or BP.
550 static const unsigned X86_GR16_AO_fp[] = {
551 X86::AX, X86::CX, X86::DX, X86::SI, X86::DI, X86::BX
553 // If not, just don't allocate SP.
554 static const unsigned X86_GR16_AO[] = {
555 X86::AX, X86::CX, X86::DX, X86::SI, X86::DI, X86::BX, X86::BP
558 GR16_NOREXClass::iterator
559 GR16_NOREXClass::allocation_order_begin(const MachineFunction &MF) const {
560 const TargetMachine &TM = MF.getTarget();
561 const TargetRegisterInfo *RI = TM.getRegisterInfo();
563 return X86_GR16_AO_fp;
568 GR16_NOREXClass::iterator
569 GR16_NOREXClass::allocation_order_end(const MachineFunction &MF) const {
570 const TargetMachine &TM = MF.getTarget();
571 const TargetRegisterInfo *RI = TM.getRegisterInfo();
573 return X86_GR16_AO_fp+(sizeof(X86_GR16_AO_fp)/sizeof(unsigned));
575 return X86_GR16_AO + (sizeof(X86_GR16_AO) / sizeof(unsigned));
579 // GR32_NOREX - GR32 registers which do not require a REX prefix.
580 def GR32_NOREX : RegisterClass<"X86", [i32], 32,
581 [EAX, ECX, EDX, ESI, EDI, EBX, EBP, ESP]> {
582 let SubRegClassList = [GR8_NOREX, GR8_NOREX, GR16_NOREX];
583 let MethodProtos = [{
584 iterator allocation_order_begin(const MachineFunction &MF) const;
585 iterator allocation_order_end(const MachineFunction &MF) const;
587 let MethodBodies = [{
588 // Does the function dedicate RBP / EBP to being a frame ptr?
589 // If so, don't allocate ESP or EBP.
590 static const unsigned X86_GR32_NOREX_AO_fp[] = {
591 X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI, X86::EBX
593 // If not, just don't allocate ESP.
594 static const unsigned X86_GR32_NOREX_AO[] = {
595 X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI, X86::EBX, X86::EBP
598 GR32_NOREXClass::iterator
599 GR32_NOREXClass::allocation_order_begin(const MachineFunction &MF) const {
600 const TargetMachine &TM = MF.getTarget();
601 const TargetRegisterInfo *RI = TM.getRegisterInfo();
603 return X86_GR32_NOREX_AO_fp;
605 return X86_GR32_NOREX_AO;
608 GR32_NOREXClass::iterator
609 GR32_NOREXClass::allocation_order_end(const MachineFunction &MF) const {
610 const TargetMachine &TM = MF.getTarget();
611 const TargetRegisterInfo *RI = TM.getRegisterInfo();
613 return X86_GR32_NOREX_AO_fp +
614 (sizeof(X86_GR32_NOREX_AO_fp) / sizeof(unsigned));
616 return X86_GR32_NOREX_AO +
617 (sizeof(X86_GR32_NOREX_AO) / sizeof(unsigned));
622 // GR64_NOREX - GR64 registers which do not require a REX prefix.
623 def GR64_NOREX : RegisterClass<"X86", [i64], 64,
624 [RAX, RCX, RDX, RSI, RDI, RBX, RBP, RSP]> {
625 let SubRegClassList = [GR8_NOREX, GR8_NOREX, GR16_NOREX, GR32_NOREX];
626 let MethodProtos = [{
627 iterator allocation_order_begin(const MachineFunction &MF) const;
628 iterator allocation_order_end(const MachineFunction &MF) const;
630 let MethodBodies = [{
631 // Does the function dedicate RBP / EBP to being a frame ptr?
632 // If so, don't allocate RSP or RBP.
633 static const unsigned X86_GR64_NOREX_AO_fp[] = {
634 X86::RAX, X86::RCX, X86::RDX, X86::RSI, X86::RDI, X86::RBX
636 // If not, just don't allocate RSP.
637 static const unsigned X86_GR64_NOREX_AO[] = {
638 X86::RAX, X86::RCX, X86::RDX, X86::RSI, X86::RDI, X86::RBX, X86::RBP
641 GR64_NOREXClass::iterator
642 GR64_NOREXClass::allocation_order_begin(const MachineFunction &MF) const {
643 const TargetMachine &TM = MF.getTarget();
644 const TargetRegisterInfo *RI = TM.getRegisterInfo();
646 return X86_GR64_NOREX_AO_fp;
648 return X86_GR64_NOREX_AO;
651 GR64_NOREXClass::iterator
652 GR64_NOREXClass::allocation_order_end(const MachineFunction &MF) const {
653 const TargetMachine &TM = MF.getTarget();
654 const TargetRegisterInfo *RI = TM.getRegisterInfo();
656 return X86_GR64_NOREX_AO_fp +
657 (sizeof(X86_GR64_NOREX_AO_fp) / sizeof(unsigned));
659 return X86_GR64_NOREX_AO +
660 (sizeof(X86_GR64_NOREX_AO) / sizeof(unsigned));
665 // A class to support the 'A' assembler constraint: EAX then EDX.
666 def GRAD : RegisterClass<"X86", [i32], 32, [EAX, EDX]>;
668 // Scalar SSE2 floating point registers.
669 def FR32 : RegisterClass<"X86", [f32], 32,
670 [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
671 XMM8, XMM9, XMM10, XMM11,
672 XMM12, XMM13, XMM14, XMM15]> {
673 let MethodProtos = [{
674 iterator allocation_order_end(const MachineFunction &MF) const;
676 let MethodBodies = [{
678 FR32Class::allocation_order_end(const MachineFunction &MF) const {
679 const TargetMachine &TM = MF.getTarget();
680 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
681 if (!Subtarget.is64Bit())
682 return end()-8; // Only XMM0 to XMM7 are available in 32-bit mode.
689 def FR64 : RegisterClass<"X86", [f64], 64,
690 [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
691 XMM8, XMM9, XMM10, XMM11,
692 XMM12, XMM13, XMM14, XMM15]> {
693 let MethodProtos = [{
694 iterator allocation_order_end(const MachineFunction &MF) const;
696 let MethodBodies = [{
698 FR64Class::allocation_order_end(const MachineFunction &MF) const {
699 const TargetMachine &TM = MF.getTarget();
700 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
701 if (!Subtarget.is64Bit())
702 return end()-8; // Only XMM0 to XMM7 are available in 32-bit mode.
710 // FIXME: This sets up the floating point register files as though they are f64
711 // values, though they really are f80 values. This will cause us to spill
712 // values as 64-bit quantities instead of 80-bit quantities, which is much much
713 // faster on common hardware. In reality, this should be controlled by a
714 // command line option or something.
716 def RFP32 : RegisterClass<"X86",[f32], 32, [FP0, FP1, FP2, FP3, FP4, FP5, FP6]>;
717 def RFP64 : RegisterClass<"X86",[f64], 32, [FP0, FP1, FP2, FP3, FP4, FP5, FP6]>;
718 def RFP80 : RegisterClass<"X86",[f80], 32, [FP0, FP1, FP2, FP3, FP4, FP5, FP6]>;
720 // Floating point stack registers (these are not allocatable by the
721 // register allocator - the floating point stackifier is responsible
722 // for transforming FPn allocations to STn registers)
723 def RST : RegisterClass<"X86", [f80, f64, f32], 32,
724 [ST0, ST1, ST2, ST3, ST4, ST5, ST6, ST7]> {
725 let MethodProtos = [{
726 iterator allocation_order_end(const MachineFunction &MF) const;
728 let MethodBodies = [{
730 RSTClass::allocation_order_end(const MachineFunction &MF) const {
736 // Generic vector registers: VR64 and VR128.
737 def VR64 : RegisterClass<"X86", [v8i8, v4i16, v2i32, v1i64, v2f32], 64,
738 [MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7]>;
739 def VR128 : RegisterClass<"X86", [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],128,
740 [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
741 XMM8, XMM9, XMM10, XMM11,
742 XMM12, XMM13, XMM14, XMM15]> {
743 let MethodProtos = [{
744 iterator allocation_order_end(const MachineFunction &MF) const;
746 let MethodBodies = [{
748 VR128Class::allocation_order_end(const MachineFunction &MF) const {
749 const TargetMachine &TM = MF.getTarget();
750 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
751 if (!Subtarget.is64Bit())
752 return end()-8; // Only XMM0 to XMM7 are available in 32-bit mode.
759 // Status flags registers.
760 def CCR : RegisterClass<"X86", [i32], 32, [EFLAGS]> {
761 let CopyCost = -1; // Don't allow copying of status registers.