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 // Subregister indices.
22 def sub_8bit : SubRegIndex;
23 def sub_8bit_hi : SubRegIndex;
24 def sub_16bit : SubRegIndex;
25 def sub_32bit : SubRegIndex;
27 def sub_ss : SubRegIndex;
28 def sub_sd : SubRegIndex;
29 def sub_xmm : SubRegIndex;
32 // In the register alias definitions below, we define which registers alias
33 // which others. We only specify which registers the small registers alias,
34 // because the register file generator is smart enough to figure out that
35 // AL aliases AX if we tell it that AX aliased AL (for example).
37 // Dwarf numbering is different for 32-bit and 64-bit, and there are
38 // variations by target as well. Currently the first entry is for X86-64,
39 // second - for EH on X86-32/Darwin and third is 'generic' one (X86-32/Linux
40 // and debug information on X86-32/Darwin)
44 def AL : Register<"al">, DwarfRegNum<[0, 0, 0]>;
45 def DL : Register<"dl">, DwarfRegNum<[1, 2, 2]>;
46 def CL : Register<"cl">, DwarfRegNum<[2, 1, 1]>;
47 def BL : Register<"bl">, DwarfRegNum<[3, 3, 3]>;
50 def SIL : Register<"sil">, DwarfRegNum<[4, 6, 6]>;
51 def DIL : Register<"dil">, DwarfRegNum<[5, 7, 7]>;
52 def BPL : Register<"bpl">, DwarfRegNum<[6, 4, 5]>;
53 def SPL : Register<"spl">, DwarfRegNum<[7, 5, 4]>;
54 def R8B : Register<"r8b">, DwarfRegNum<[8, -2, -2]>;
55 def R9B : Register<"r9b">, DwarfRegNum<[9, -2, -2]>;
56 def R10B : Register<"r10b">, DwarfRegNum<[10, -2, -2]>;
57 def R11B : Register<"r11b">, DwarfRegNum<[11, -2, -2]>;
58 def R12B : Register<"r12b">, DwarfRegNum<[12, -2, -2]>;
59 def R13B : Register<"r13b">, DwarfRegNum<[13, -2, -2]>;
60 def R14B : Register<"r14b">, DwarfRegNum<[14, -2, -2]>;
61 def R15B : Register<"r15b">, DwarfRegNum<[15, -2, -2]>;
63 // High registers. On x86-64, these cannot be used in any instruction
65 def AH : Register<"ah">, DwarfRegNum<[0, 0, 0]>;
66 def DH : Register<"dh">, DwarfRegNum<[1, 2, 2]>;
67 def CH : Register<"ch">, DwarfRegNum<[2, 1, 1]>;
68 def BH : Register<"bh">, DwarfRegNum<[3, 3, 3]>;
71 let SubRegIndices = [sub_8bit, sub_8bit_hi] in {
72 def AX : RegisterWithSubRegs<"ax", [AL,AH]>, DwarfRegNum<[0, 0, 0]>;
73 def DX : RegisterWithSubRegs<"dx", [DL,DH]>, DwarfRegNum<[1, 2, 2]>;
74 def CX : RegisterWithSubRegs<"cx", [CL,CH]>, DwarfRegNum<[2, 1, 1]>;
75 def BX : RegisterWithSubRegs<"bx", [BL,BH]>, DwarfRegNum<[3, 3, 3]>;
77 let SubRegIndices = [sub_8bit] in {
78 def SI : RegisterWithSubRegs<"si", [SIL]>, DwarfRegNum<[4, 6, 6]>;
79 def DI : RegisterWithSubRegs<"di", [DIL]>, DwarfRegNum<[5, 7, 7]>;
80 def BP : RegisterWithSubRegs<"bp", [BPL]>, DwarfRegNum<[6, 4, 5]>;
81 def SP : RegisterWithSubRegs<"sp", [SPL]>, DwarfRegNum<[7, 5, 4]>;
83 def IP : Register<"ip">, DwarfRegNum<[16]>;
86 let SubRegIndices = [sub_8bit] in {
87 def R8W : RegisterWithSubRegs<"r8w", [R8B]>, DwarfRegNum<[8, -2, -2]>;
88 def R9W : RegisterWithSubRegs<"r9w", [R9B]>, DwarfRegNum<[9, -2, -2]>;
89 def R10W : RegisterWithSubRegs<"r10w", [R10B]>, DwarfRegNum<[10, -2, -2]>;
90 def R11W : RegisterWithSubRegs<"r11w", [R11B]>, DwarfRegNum<[11, -2, -2]>;
91 def R12W : RegisterWithSubRegs<"r12w", [R12B]>, DwarfRegNum<[12, -2, -2]>;
92 def R13W : RegisterWithSubRegs<"r13w", [R13B]>, DwarfRegNum<[13, -2, -2]>;
93 def R14W : RegisterWithSubRegs<"r14w", [R14B]>, DwarfRegNum<[14, -2, -2]>;
94 def R15W : RegisterWithSubRegs<"r15w", [R15B]>, DwarfRegNum<[15, -2, -2]>;
97 let SubRegIndices = [sub_16bit] in {
98 def EAX : RegisterWithSubRegs<"eax", [AX]>, DwarfRegNum<[0, 0, 0]>;
99 def EDX : RegisterWithSubRegs<"edx", [DX]>, DwarfRegNum<[1, 2, 2]>;
100 def ECX : RegisterWithSubRegs<"ecx", [CX]>, DwarfRegNum<[2, 1, 1]>;
101 def EBX : RegisterWithSubRegs<"ebx", [BX]>, DwarfRegNum<[3, 3, 3]>;
102 def ESI : RegisterWithSubRegs<"esi", [SI]>, DwarfRegNum<[4, 6, 6]>;
103 def EDI : RegisterWithSubRegs<"edi", [DI]>, DwarfRegNum<[5, 7, 7]>;
104 def EBP : RegisterWithSubRegs<"ebp", [BP]>, DwarfRegNum<[6, 4, 5]>;
105 def ESP : RegisterWithSubRegs<"esp", [SP]>, DwarfRegNum<[7, 5, 4]>;
106 def EIP : RegisterWithSubRegs<"eip", [IP]>, DwarfRegNum<[16, 8, 8]>;
109 def R8D : RegisterWithSubRegs<"r8d", [R8W]>, DwarfRegNum<[8, -2, -2]>;
110 def R9D : RegisterWithSubRegs<"r9d", [R9W]>, DwarfRegNum<[9, -2, -2]>;
111 def R10D : RegisterWithSubRegs<"r10d", [R10W]>, DwarfRegNum<[10, -2, -2]>;
112 def R11D : RegisterWithSubRegs<"r11d", [R11W]>, DwarfRegNum<[11, -2, -2]>;
113 def R12D : RegisterWithSubRegs<"r12d", [R12W]>, DwarfRegNum<[12, -2, -2]>;
114 def R13D : RegisterWithSubRegs<"r13d", [R13W]>, DwarfRegNum<[13, -2, -2]>;
115 def R14D : RegisterWithSubRegs<"r14d", [R14W]>, DwarfRegNum<[14, -2, -2]>;
116 def R15D : RegisterWithSubRegs<"r15d", [R15W]>, DwarfRegNum<[15, -2, -2]>;
119 // 64-bit registers, X86-64 only
120 let SubRegIndices = [sub_32bit] in {
121 def RAX : RegisterWithSubRegs<"rax", [EAX]>, DwarfRegNum<[0, -2, -2]>;
122 def RDX : RegisterWithSubRegs<"rdx", [EDX]>, DwarfRegNum<[1, -2, -2]>;
123 def RCX : RegisterWithSubRegs<"rcx", [ECX]>, DwarfRegNum<[2, -2, -2]>;
124 def RBX : RegisterWithSubRegs<"rbx", [EBX]>, DwarfRegNum<[3, -2, -2]>;
125 def RSI : RegisterWithSubRegs<"rsi", [ESI]>, DwarfRegNum<[4, -2, -2]>;
126 def RDI : RegisterWithSubRegs<"rdi", [EDI]>, DwarfRegNum<[5, -2, -2]>;
127 def RBP : RegisterWithSubRegs<"rbp", [EBP]>, DwarfRegNum<[6, -2, -2]>;
128 def RSP : RegisterWithSubRegs<"rsp", [ESP]>, DwarfRegNum<[7, -2, -2]>;
130 def R8 : RegisterWithSubRegs<"r8", [R8D]>, DwarfRegNum<[8, -2, -2]>;
131 def R9 : RegisterWithSubRegs<"r9", [R9D]>, DwarfRegNum<[9, -2, -2]>;
132 def R10 : RegisterWithSubRegs<"r10", [R10D]>, DwarfRegNum<[10, -2, -2]>;
133 def R11 : RegisterWithSubRegs<"r11", [R11D]>, DwarfRegNum<[11, -2, -2]>;
134 def R12 : RegisterWithSubRegs<"r12", [R12D]>, DwarfRegNum<[12, -2, -2]>;
135 def R13 : RegisterWithSubRegs<"r13", [R13D]>, DwarfRegNum<[13, -2, -2]>;
136 def R14 : RegisterWithSubRegs<"r14", [R14D]>, DwarfRegNum<[14, -2, -2]>;
137 def R15 : RegisterWithSubRegs<"r15", [R15D]>, DwarfRegNum<[15, -2, -2]>;
138 def RIP : RegisterWithSubRegs<"rip", [EIP]>, DwarfRegNum<[16, -2, -2]>;
141 // MMX Registers. These are actually aliased to ST0 .. ST7
142 def MM0 : Register<"mm0">, DwarfRegNum<[41, 29, 29]>;
143 def MM1 : Register<"mm1">, DwarfRegNum<[42, 30, 30]>;
144 def MM2 : Register<"mm2">, DwarfRegNum<[43, 31, 31]>;
145 def MM3 : Register<"mm3">, DwarfRegNum<[44, 32, 32]>;
146 def MM4 : Register<"mm4">, DwarfRegNum<[45, 33, 33]>;
147 def MM5 : Register<"mm5">, DwarfRegNum<[46, 34, 34]>;
148 def MM6 : Register<"mm6">, DwarfRegNum<[47, 35, 35]>;
149 def MM7 : Register<"mm7">, DwarfRegNum<[48, 36, 36]>;
151 // Pseudo Floating Point registers
152 def FP0 : Register<"fp0">;
153 def FP1 : Register<"fp1">;
154 def FP2 : Register<"fp2">;
155 def FP3 : Register<"fp3">;
156 def FP4 : Register<"fp4">;
157 def FP5 : Register<"fp5">;
158 def FP6 : Register<"fp6">;
160 // XMM Registers, used by the various SSE instruction set extensions.
161 // The sub_ss and sub_sd subregs are the same registers with another regclass.
162 let CompositeIndices = [(sub_ss), (sub_sd)] in {
163 def XMM0: Register<"xmm0">, DwarfRegNum<[17, 21, 21]>;
164 def XMM1: Register<"xmm1">, DwarfRegNum<[18, 22, 22]>;
165 def XMM2: Register<"xmm2">, DwarfRegNum<[19, 23, 23]>;
166 def XMM3: Register<"xmm3">, DwarfRegNum<[20, 24, 24]>;
167 def XMM4: Register<"xmm4">, DwarfRegNum<[21, 25, 25]>;
168 def XMM5: Register<"xmm5">, DwarfRegNum<[22, 26, 26]>;
169 def XMM6: Register<"xmm6">, DwarfRegNum<[23, 27, 27]>;
170 def XMM7: Register<"xmm7">, DwarfRegNum<[24, 28, 28]>;
173 def XMM8: Register<"xmm8">, DwarfRegNum<[25, -2, -2]>;
174 def XMM9: Register<"xmm9">, DwarfRegNum<[26, -2, -2]>;
175 def XMM10: Register<"xmm10">, DwarfRegNum<[27, -2, -2]>;
176 def XMM11: Register<"xmm11">, DwarfRegNum<[28, -2, -2]>;
177 def XMM12: Register<"xmm12">, DwarfRegNum<[29, -2, -2]>;
178 def XMM13: Register<"xmm13">, DwarfRegNum<[30, -2, -2]>;
179 def XMM14: Register<"xmm14">, DwarfRegNum<[31, -2, -2]>;
180 def XMM15: Register<"xmm15">, DwarfRegNum<[32, -2, -2]>;
183 // YMM Registers, used by AVX instructions
184 let SubRegIndices = [sub_xmm] in {
185 def YMM0: RegisterWithSubRegs<"ymm0", [XMM0]>, DwarfRegNum<[17, 21, 21]>;
186 def YMM1: RegisterWithSubRegs<"ymm1", [XMM1]>, DwarfRegNum<[18, 22, 22]>;
187 def YMM2: RegisterWithSubRegs<"ymm2", [XMM2]>, DwarfRegNum<[19, 23, 23]>;
188 def YMM3: RegisterWithSubRegs<"ymm3", [XMM3]>, DwarfRegNum<[20, 24, 24]>;
189 def YMM4: RegisterWithSubRegs<"ymm4", [XMM4]>, DwarfRegNum<[21, 25, 25]>;
190 def YMM5: RegisterWithSubRegs<"ymm5", [XMM5]>, DwarfRegNum<[22, 26, 26]>;
191 def YMM6: RegisterWithSubRegs<"ymm6", [XMM6]>, DwarfRegNum<[23, 27, 27]>;
192 def YMM7: RegisterWithSubRegs<"ymm7", [XMM7]>, DwarfRegNum<[24, 28, 28]>;
193 def YMM8: RegisterWithSubRegs<"ymm8", [XMM8]>, DwarfRegNum<[25, -2, -2]>;
194 def YMM9: RegisterWithSubRegs<"ymm9", [XMM9]>, DwarfRegNum<[26, -2, -2]>;
195 def YMM10: RegisterWithSubRegs<"ymm10", [XMM10]>, DwarfRegNum<[27, -2, -2]>;
196 def YMM11: RegisterWithSubRegs<"ymm11", [XMM11]>, DwarfRegNum<[28, -2, -2]>;
197 def YMM12: RegisterWithSubRegs<"ymm12", [XMM12]>, DwarfRegNum<[29, -2, -2]>;
198 def YMM13: RegisterWithSubRegs<"ymm13", [XMM13]>, DwarfRegNum<[30, -2, -2]>;
199 def YMM14: RegisterWithSubRegs<"ymm14", [XMM14]>, DwarfRegNum<[31, -2, -2]>;
200 def YMM15: RegisterWithSubRegs<"ymm15", [XMM15]>, DwarfRegNum<[32, -2, -2]>;
203 // Floating point stack registers
204 def ST0 : Register<"st(0)">, DwarfRegNum<[33, 12, 11]>;
205 def ST1 : Register<"st(1)">, DwarfRegNum<[34, 13, 12]>;
206 def ST2 : Register<"st(2)">, DwarfRegNum<[35, 14, 13]>;
207 def ST3 : Register<"st(3)">, DwarfRegNum<[36, 15, 14]>;
208 def ST4 : Register<"st(4)">, DwarfRegNum<[37, 16, 15]>;
209 def ST5 : Register<"st(5)">, DwarfRegNum<[38, 17, 16]>;
210 def ST6 : Register<"st(6)">, DwarfRegNum<[39, 18, 17]>;
211 def ST7 : Register<"st(7)">, DwarfRegNum<[40, 19, 18]>;
213 // Status flags register
214 def EFLAGS : Register<"flags">;
217 def CS : Register<"cs">;
218 def DS : Register<"ds">;
219 def SS : Register<"ss">;
220 def ES : Register<"es">;
221 def FS : Register<"fs">;
222 def GS : Register<"gs">;
225 def DR0 : Register<"dr0">;
226 def DR1 : Register<"dr1">;
227 def DR2 : Register<"dr2">;
228 def DR3 : Register<"dr3">;
229 def DR4 : Register<"dr4">;
230 def DR5 : Register<"dr5">;
231 def DR6 : Register<"dr6">;
232 def DR7 : Register<"dr7">;
235 def CR0 : Register<"cr0">;
236 def CR1 : Register<"cr1">;
237 def CR2 : Register<"cr2">;
238 def CR3 : Register<"cr3">;
239 def CR4 : Register<"cr4">;
240 def CR5 : Register<"cr5">;
241 def CR6 : Register<"cr6">;
242 def CR7 : Register<"cr7">;
243 def CR8 : Register<"cr8">;
244 def CR9 : Register<"cr9">;
245 def CR10 : Register<"cr10">;
246 def CR11 : Register<"cr11">;
247 def CR12 : Register<"cr12">;
248 def CR13 : Register<"cr13">;
249 def CR14 : Register<"cr14">;
250 def CR15 : Register<"cr15">;
252 // Pseudo index registers
253 def EIZ : Register<"eiz">;
254 def RIZ : Register<"riz">;
258 //===----------------------------------------------------------------------===//
259 // Register Class Definitions... now that we have all of the pieces, define the
260 // top-level register classes. The order specified in the register list is
261 // implicitly defined to be the register allocation order.
264 // List call-clobbered registers before callee-save registers. RBX, RBP, (and
265 // R12, R13, R14, and R15 for X86-64) are callee-save registers.
266 // In 64-mode, there are 12 additional i8 registers, SIL, DIL, BPL, SPL, and
268 // Allocate R12 and R13 last, as these require an extra byte when
269 // encoded in x86_64 instructions.
270 // FIXME: Allow AH, CH, DH, BH to be used as general-purpose registers in
271 // 64-bit mode. The main complication is that they cannot be encoded in an
272 // instruction requiring a REX prefix, while SIL, DIL, BPL, R8D, etc.
273 // require a REX prefix. For example, "addb %ah, %dil" and "movzbl %ah, %r8d"
274 // cannot be encoded.
275 def GR8 : RegisterClass<"X86", [i8], 8,
276 [AL, CL, DL, AH, CH, DH, BL, BH, SIL, DIL, BPL, SPL,
277 R8B, R9B, R10B, R11B, R14B, R15B, R12B, R13B]> {
278 let MethodProtos = [{
279 iterator allocation_order_begin(const MachineFunction &MF) const;
280 iterator allocation_order_end(const MachineFunction &MF) const;
282 let MethodBodies = [{
283 static const unsigned X86_GR8_AO_64[] = {
284 X86::AL, X86::CL, X86::DL, X86::SIL, X86::DIL,
285 X86::R8B, X86::R9B, X86::R10B, X86::R11B,
286 X86::BL, X86::R14B, X86::R15B, X86::R12B, X86::R13B, X86::BPL
290 GR8Class::allocation_order_begin(const MachineFunction &MF) const {
291 const TargetMachine &TM = MF.getTarget();
292 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
293 if (Subtarget.is64Bit())
294 return X86_GR8_AO_64;
300 GR8Class::allocation_order_end(const MachineFunction &MF) const {
301 const TargetMachine &TM = MF.getTarget();
302 const TargetRegisterInfo *RI = TM.getRegisterInfo();
303 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
304 const X86MachineFunctionInfo *MFI = MF.getInfo<X86MachineFunctionInfo>();
305 // Does the function dedicate RBP / EBP to being a frame ptr?
306 if (!Subtarget.is64Bit())
307 // In 32-mode, none of the 8-bit registers aliases EBP or ESP.
309 else if (RI->hasFP(MF) || MFI->getReserveFP())
310 // If so, don't allocate SPL or BPL.
311 return array_endof(X86_GR8_AO_64) - 1;
313 // If not, just don't allocate SPL.
314 return array_endof(X86_GR8_AO_64);
319 def GR16 : RegisterClass<"X86", [i16], 16,
320 [AX, CX, DX, SI, DI, BX, BP, SP,
321 R8W, R9W, R10W, R11W, R14W, R15W, R12W, R13W]> {
322 let SubRegClasses = [(GR8 sub_8bit, sub_8bit_hi)];
323 let MethodProtos = [{
324 iterator allocation_order_begin(const MachineFunction &MF) const;
325 iterator allocation_order_end(const MachineFunction &MF) const;
327 let MethodBodies = [{
328 static const unsigned X86_GR16_AO_64[] = {
329 X86::AX, X86::CX, X86::DX, X86::SI, X86::DI,
330 X86::R8W, X86::R9W, X86::R10W, X86::R11W,
331 X86::BX, X86::R14W, X86::R15W, X86::R12W, X86::R13W, X86::BP
335 GR16Class::allocation_order_begin(const MachineFunction &MF) const {
336 const TargetMachine &TM = MF.getTarget();
337 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
338 if (Subtarget.is64Bit())
339 return X86_GR16_AO_64;
345 GR16Class::allocation_order_end(const MachineFunction &MF) const {
346 const TargetMachine &TM = MF.getTarget();
347 const TargetRegisterInfo *RI = TM.getRegisterInfo();
348 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
349 const X86MachineFunctionInfo *MFI = MF.getInfo<X86MachineFunctionInfo>();
350 if (Subtarget.is64Bit()) {
351 // Does the function dedicate RBP to being a frame ptr?
352 if (RI->hasFP(MF) || MFI->getReserveFP())
353 // If so, don't allocate SP or BP.
354 return array_endof(X86_GR16_AO_64) - 1;
356 // If not, just don't allocate SP.
357 return array_endof(X86_GR16_AO_64);
359 // Does the function dedicate EBP to being a frame ptr?
360 if (RI->hasFP(MF) || MFI->getReserveFP())
361 // If so, don't allocate SP or BP.
364 // If not, just don't allocate SP.
371 def GR32 : RegisterClass<"X86", [i32], 32,
372 [EAX, ECX, EDX, ESI, EDI, EBX, EBP, ESP,
373 R8D, R9D, R10D, R11D, R14D, R15D, R12D, R13D]> {
374 let SubRegClasses = [(GR8 sub_8bit, sub_8bit_hi), (GR16 sub_16bit)];
375 let MethodProtos = [{
376 iterator allocation_order_begin(const MachineFunction &MF) const;
377 iterator allocation_order_end(const MachineFunction &MF) const;
379 let MethodBodies = [{
380 static const unsigned X86_GR32_AO_64[] = {
381 X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI,
382 X86::R8D, X86::R9D, X86::R10D, X86::R11D,
383 X86::EBX, X86::R14D, X86::R15D, X86::R12D, X86::R13D, X86::EBP
387 GR32Class::allocation_order_begin(const MachineFunction &MF) const {
388 const TargetMachine &TM = MF.getTarget();
389 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
390 if (Subtarget.is64Bit())
391 return X86_GR32_AO_64;
397 GR32Class::allocation_order_end(const MachineFunction &MF) const {
398 const TargetMachine &TM = MF.getTarget();
399 const TargetRegisterInfo *RI = TM.getRegisterInfo();
400 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
401 const X86MachineFunctionInfo *MFI = MF.getInfo<X86MachineFunctionInfo>();
402 if (Subtarget.is64Bit()) {
403 // Does the function dedicate RBP to being a frame ptr?
404 if (RI->hasFP(MF) || MFI->getReserveFP())
405 // If so, don't allocate ESP or EBP.
406 return array_endof(X86_GR32_AO_64) - 1;
408 // If not, just don't allocate ESP.
409 return array_endof(X86_GR32_AO_64);
411 // Does the function dedicate EBP to being a frame ptr?
412 if (RI->hasFP(MF) || MFI->getReserveFP())
413 // If so, don't allocate ESP or EBP.
416 // If not, just don't allocate ESP.
423 // GR64 - 64-bit GPRs. This oddly includes RIP, which isn't accurate, since
424 // RIP isn't really a register and it can't be used anywhere except in an
425 // address, but it doesn't cause trouble.
426 def GR64 : RegisterClass<"X86", [i64], 64,
427 [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
428 RBX, R14, R15, R12, R13, RBP, RSP, RIP]> {
429 let SubRegClasses = [(GR8 sub_8bit, sub_8bit_hi),
432 let MethodProtos = [{
433 iterator allocation_order_end(const MachineFunction &MF) const;
435 let MethodBodies = [{
437 GR64Class::allocation_order_end(const MachineFunction &MF) const {
438 const TargetMachine &TM = MF.getTarget();
439 const TargetRegisterInfo *RI = TM.getRegisterInfo();
440 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
441 const X86MachineFunctionInfo *MFI = MF.getInfo<X86MachineFunctionInfo>();
442 if (!Subtarget.is64Bit())
443 return begin(); // None of these are allocatable in 32-bit.
444 // Does the function dedicate RBP to being a frame ptr?
445 if (RI->hasFP(MF) || MFI->getReserveFP())
446 return end()-3; // If so, don't allocate RIP, RSP or RBP
448 return end()-2; // If not, just don't allocate RIP or RSP
453 // Segment registers for use by MOV instructions (and others) that have a
454 // segment register as one operand. Always contain a 16-bit segment
456 def SEGMENT_REG : RegisterClass<"X86", [i16], 16, [CS, DS, SS, ES, FS, GS]> {
460 def DEBUG_REG : RegisterClass<"X86", [i32], 32,
461 [DR0, DR1, DR2, DR3, DR4, DR5, DR6, DR7]> {
464 // Control registers.
465 def CONTROL_REG : RegisterClass<"X86", [i64], 64,
466 [CR0, CR1, CR2, CR3, CR4, CR5, CR6, CR7, CR8,
467 CR9, CR10, CR11, CR12, CR13, CR14, CR15]> {
470 // GR8_ABCD_L, GR8_ABCD_H, GR16_ABCD, GR32_ABCD, GR64_ABCD - Subclasses of
471 // GR8, GR16, GR32, and GR64 which contain just the "a" "b", "c", and "d"
472 // registers. On x86-32, GR16_ABCD and GR32_ABCD are classes for registers
473 // that support 8-bit subreg operations. On x86-64, GR16_ABCD, GR32_ABCD,
474 // and GR64_ABCD are classes for registers that support 8-bit h-register
476 def GR8_ABCD_L : RegisterClass<"X86", [i8], 8, [AL, CL, DL, BL]> {
478 def GR8_ABCD_H : RegisterClass<"X86", [i8], 8, [AH, CH, DH, BH]> {
480 def GR16_ABCD : RegisterClass<"X86", [i16], 16, [AX, CX, DX, BX]> {
481 let SubRegClasses = [(GR8_ABCD_L sub_8bit), (GR8_ABCD_H sub_8bit_hi)];
483 def GR32_ABCD : RegisterClass<"X86", [i32], 32, [EAX, ECX, EDX, EBX]> {
484 let SubRegClasses = [(GR8_ABCD_L sub_8bit),
485 (GR8_ABCD_H sub_8bit_hi),
486 (GR16_ABCD sub_16bit)];
488 def GR64_ABCD : RegisterClass<"X86", [i64], 64, [RAX, RCX, RDX, RBX]> {
489 let SubRegClasses = [(GR8_ABCD_L sub_8bit),
490 (GR8_ABCD_H sub_8bit_hi),
491 (GR16_ABCD sub_16bit),
492 (GR32_ABCD sub_32bit)];
494 def GR32_TC : RegisterClass<"X86", [i32], 32, [EAX, ECX, EDX]> {
495 let SubRegClasses = [(GR8 sub_8bit, sub_8bit_hi), (GR16 sub_16bit)];
497 def GR64_TC : RegisterClass<"X86", [i64], 64, [RAX, RCX, RDX, RSI, RDI,
499 let SubRegClasses = [(GR8 sub_8bit, sub_8bit_hi),
501 (GR32_TC sub_32bit)];
504 // GR8_NOREX - GR8 registers which do not require a REX prefix.
505 def GR8_NOREX : RegisterClass<"X86", [i8], 8,
506 [AL, CL, DL, AH, CH, DH, BL, BH]> {
507 let MethodProtos = [{
508 iterator allocation_order_begin(const MachineFunction &MF) const;
509 iterator allocation_order_end(const MachineFunction &MF) const;
511 let MethodBodies = [{
512 // In 64-bit mode, it's not safe to blindly allocate H registers.
513 static const unsigned X86_GR8_NOREX_AO_64[] = {
514 X86::AL, X86::CL, X86::DL, X86::BL
517 GR8_NOREXClass::iterator
518 GR8_NOREXClass::allocation_order_begin(const MachineFunction &MF) const {
519 const TargetMachine &TM = MF.getTarget();
520 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
521 if (Subtarget.is64Bit())
522 return X86_GR8_NOREX_AO_64;
527 GR8_NOREXClass::iterator
528 GR8_NOREXClass::allocation_order_end(const MachineFunction &MF) const {
529 const TargetMachine &TM = MF.getTarget();
530 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
531 if (Subtarget.is64Bit())
532 return array_endof(X86_GR8_NOREX_AO_64);
538 // GR16_NOREX - GR16 registers which do not require a REX prefix.
539 def GR16_NOREX : RegisterClass<"X86", [i16], 16,
540 [AX, CX, DX, SI, DI, BX, BP, SP]> {
541 let SubRegClasses = [(GR8_NOREX sub_8bit, sub_8bit_hi)];
542 let MethodProtos = [{
543 iterator allocation_order_end(const MachineFunction &MF) const;
545 let MethodBodies = [{
546 GR16_NOREXClass::iterator
547 GR16_NOREXClass::allocation_order_end(const MachineFunction &MF) const {
548 const TargetMachine &TM = MF.getTarget();
549 const TargetRegisterInfo *RI = TM.getRegisterInfo();
550 const X86MachineFunctionInfo *MFI = MF.getInfo<X86MachineFunctionInfo>();
551 // Does the function dedicate RBP / EBP to being a frame ptr?
552 if (RI->hasFP(MF) || MFI->getReserveFP())
553 // If so, don't allocate SP or BP.
556 // If not, just don't allocate SP.
561 // GR32_NOREX - GR32 registers which do not require a REX prefix.
562 def GR32_NOREX : RegisterClass<"X86", [i32], 32,
563 [EAX, ECX, EDX, ESI, EDI, EBX, EBP, ESP]> {
564 let SubRegClasses = [(GR8_NOREX sub_8bit, sub_8bit_hi),
565 (GR16_NOREX sub_16bit)];
566 let MethodProtos = [{
567 iterator allocation_order_end(const MachineFunction &MF) const;
569 let MethodBodies = [{
570 GR32_NOREXClass::iterator
571 GR32_NOREXClass::allocation_order_end(const MachineFunction &MF) const {
572 const TargetMachine &TM = MF.getTarget();
573 const TargetRegisterInfo *RI = TM.getRegisterInfo();
574 const X86MachineFunctionInfo *MFI = MF.getInfo<X86MachineFunctionInfo>();
575 // Does the function dedicate RBP / EBP to being a frame ptr?
576 if (RI->hasFP(MF) || MFI->getReserveFP())
577 // If so, don't allocate ESP or EBP.
580 // If not, just don't allocate ESP.
585 // GR64_NOREX - GR64 registers which do not require a REX prefix.
586 def GR64_NOREX : RegisterClass<"X86", [i64], 64,
587 [RAX, RCX, RDX, RSI, RDI, RBX, RBP, RSP, RIP]> {
588 let SubRegClasses = [(GR8_NOREX sub_8bit, sub_8bit_hi),
589 (GR16_NOREX sub_16bit),
590 (GR32_NOREX sub_32bit)];
591 let MethodProtos = [{
592 iterator allocation_order_end(const MachineFunction &MF) const;
594 let MethodBodies = [{
595 GR64_NOREXClass::iterator
596 GR64_NOREXClass::allocation_order_end(const MachineFunction &MF) const {
597 const TargetMachine &TM = MF.getTarget();
598 const TargetRegisterInfo *RI = TM.getRegisterInfo();
599 const X86MachineFunctionInfo *MFI = MF.getInfo<X86MachineFunctionInfo>();
600 // Does the function dedicate RBP to being a frame ptr?
601 if (RI->hasFP(MF) || MFI->getReserveFP())
602 // If so, don't allocate RIP, RSP or RBP.
605 // If not, just don't allocate RIP or RSP.
611 // GR32_NOSP - GR32 registers except ESP.
612 def GR32_NOSP : RegisterClass<"X86", [i32], 32,
613 [EAX, ECX, EDX, ESI, EDI, EBX, EBP,
614 R8D, R9D, R10D, R11D, R14D, R15D, R12D, R13D]> {
615 let SubRegClasses = [(GR8 sub_8bit, sub_8bit_hi), (GR16 sub_16bit)];
616 let MethodProtos = [{
617 iterator allocation_order_begin(const MachineFunction &MF) const;
618 iterator allocation_order_end(const MachineFunction &MF) const;
620 let MethodBodies = [{
621 static const unsigned X86_GR32_NOSP_AO_64[] = {
622 X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI,
623 X86::R8D, X86::R9D, X86::R10D, X86::R11D,
624 X86::EBX, X86::R14D, X86::R15D, X86::R12D, X86::R13D, X86::EBP
627 GR32_NOSPClass::iterator
628 GR32_NOSPClass::allocation_order_begin(const MachineFunction &MF) const {
629 const TargetMachine &TM = MF.getTarget();
630 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
631 if (Subtarget.is64Bit())
632 return X86_GR32_NOSP_AO_64;
637 GR32_NOSPClass::iterator
638 GR32_NOSPClass::allocation_order_end(const MachineFunction &MF) const {
639 const TargetMachine &TM = MF.getTarget();
640 const TargetRegisterInfo *RI = TM.getRegisterInfo();
641 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
642 const X86MachineFunctionInfo *MFI = MF.getInfo<X86MachineFunctionInfo>();
643 if (Subtarget.is64Bit()) {
644 // Does the function dedicate RBP to being a frame ptr?
645 if (RI->hasFP(MF) || MFI->getReserveFP())
646 // If so, don't allocate EBP.
647 return array_endof(X86_GR32_NOSP_AO_64) - 1;
649 // If not, any reg in this class is ok.
650 return array_endof(X86_GR32_NOSP_AO_64);
652 // Does the function dedicate EBP to being a frame ptr?
653 if (RI->hasFP(MF) || MFI->getReserveFP())
654 // If so, don't allocate EBP.
657 // If not, any reg in this class is ok.
664 // GR64_NOSP - GR64 registers except RSP (and RIP).
665 def GR64_NOSP : RegisterClass<"X86", [i64], 64,
666 [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
667 RBX, R14, R15, R12, R13, RBP]> {
668 let SubRegClasses = [(GR8 sub_8bit, sub_8bit_hi),
670 (GR32_NOSP sub_32bit)];
671 let MethodProtos = [{
672 iterator allocation_order_end(const MachineFunction &MF) const;
674 let MethodBodies = [{
675 GR64_NOSPClass::iterator
676 GR64_NOSPClass::allocation_order_end(const MachineFunction &MF) const {
677 const TargetMachine &TM = MF.getTarget();
678 const TargetRegisterInfo *RI = TM.getRegisterInfo();
679 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
680 const X86MachineFunctionInfo *MFI = MF.getInfo<X86MachineFunctionInfo>();
681 if (!Subtarget.is64Bit())
682 return begin(); // None of these are allocatable in 32-bit.
683 // Does the function dedicate RBP to being a frame ptr?
684 if (RI->hasFP(MF) || MFI->getReserveFP())
685 return end()-1; // If so, don't allocate RBP
687 return end(); // If not, any reg in this class is ok.
692 // GR64_NOREX_NOSP - GR64_NOREX registers except RSP.
693 def GR64_NOREX_NOSP : RegisterClass<"X86", [i64], 64,
694 [RAX, RCX, RDX, RSI, RDI, RBX, RBP]> {
695 let SubRegClasses = [(GR8_NOREX sub_8bit, sub_8bit_hi),
696 (GR16_NOREX sub_16bit),
697 (GR32_NOREX sub_32bit)];
698 let MethodProtos = [{
699 iterator allocation_order_end(const MachineFunction &MF) const;
701 let MethodBodies = [{
702 GR64_NOREX_NOSPClass::iterator
703 GR64_NOREX_NOSPClass::allocation_order_end(const MachineFunction &MF) const
705 const TargetMachine &TM = MF.getTarget();
706 const TargetRegisterInfo *RI = TM.getRegisterInfo();
707 const X86MachineFunctionInfo *MFI = MF.getInfo<X86MachineFunctionInfo>();
708 // Does the function dedicate RBP to being a frame ptr?
709 if (RI->hasFP(MF) || MFI->getReserveFP())
710 // If so, don't allocate RBP.
713 // If not, any reg in this class is ok.
719 // A class to support the 'A' assembler constraint: EAX then EDX.
720 def GR32_AD : RegisterClass<"X86", [i32], 32, [EAX, EDX]> {
721 let SubRegClasses = [(GR8_ABCD_L sub_8bit),
722 (GR8_ABCD_H sub_8bit_hi),
723 (GR16_ABCD sub_16bit)];
726 // Scalar SSE2 floating point registers.
727 def FR32 : RegisterClass<"X86", [f32], 32,
728 [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
729 XMM8, XMM9, XMM10, XMM11,
730 XMM12, XMM13, XMM14, XMM15]> {
731 let MethodProtos = [{
732 iterator allocation_order_end(const MachineFunction &MF) const;
734 let MethodBodies = [{
736 FR32Class::allocation_order_end(const MachineFunction &MF) const {
737 const TargetMachine &TM = MF.getTarget();
738 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
739 if (!Subtarget.is64Bit())
740 return end()-8; // Only XMM0 to XMM7 are available in 32-bit mode.
747 def FR64 : RegisterClass<"X86", [f64], 64,
748 [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
749 XMM8, XMM9, XMM10, XMM11,
750 XMM12, XMM13, XMM14, XMM15]> {
751 let MethodProtos = [{
752 iterator allocation_order_end(const MachineFunction &MF) const;
754 let MethodBodies = [{
756 FR64Class::allocation_order_end(const MachineFunction &MF) const {
757 const TargetMachine &TM = MF.getTarget();
758 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
759 if (!Subtarget.is64Bit())
760 return end()-8; // Only XMM0 to XMM7 are available in 32-bit mode.
768 // FIXME: This sets up the floating point register files as though they are f64
769 // values, though they really are f80 values. This will cause us to spill
770 // values as 64-bit quantities instead of 80-bit quantities, which is much much
771 // faster on common hardware. In reality, this should be controlled by a
772 // command line option or something.
774 def RFP32 : RegisterClass<"X86",[f32], 32, [FP0, FP1, FP2, FP3, FP4, FP5, FP6]>;
775 def RFP64 : RegisterClass<"X86",[f64], 32, [FP0, FP1, FP2, FP3, FP4, FP5, FP6]>;
776 def RFP80 : RegisterClass<"X86",[f80], 32, [FP0, FP1, FP2, FP3, FP4, FP5, FP6]>;
778 // Floating point stack registers (these are not allocatable by the
779 // register allocator - the floating point stackifier is responsible
780 // for transforming FPn allocations to STn registers)
781 def RST : RegisterClass<"X86", [f80, f64, f32], 32,
782 [ST0, ST1, ST2, ST3, ST4, ST5, ST6, ST7]> {
783 let MethodProtos = [{
784 iterator allocation_order_end(const MachineFunction &MF) const;
786 let MethodBodies = [{
788 RSTClass::allocation_order_end(const MachineFunction &MF) const {
794 // Generic vector registers: VR64 and VR128.
795 def VR64: RegisterClass<"X86", [x86mmx], 64,
796 [MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7]>;
797 def VR128 : RegisterClass<"X86", [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],128,
798 [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
799 XMM8, XMM9, XMM10, XMM11,
800 XMM12, XMM13, XMM14, XMM15]> {
801 let SubRegClasses = [(FR32 sub_ss), (FR64 sub_sd)];
803 let MethodProtos = [{
804 iterator allocation_order_end(const MachineFunction &MF) const;
806 let MethodBodies = [{
808 VR128Class::allocation_order_end(const MachineFunction &MF) const {
809 const TargetMachine &TM = MF.getTarget();
810 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
811 if (!Subtarget.is64Bit())
812 return end()-8; // Only XMM0 to XMM7 are available in 32-bit mode.
819 def VR256 : RegisterClass<"X86", [v32i8, v8i32, v4i64, v8f32, v4f64], 256,
820 [YMM0, YMM1, YMM2, YMM3, YMM4, YMM5, YMM6, YMM7,
821 YMM8, YMM9, YMM10, YMM11,
822 YMM12, YMM13, YMM14, YMM15]> {
823 let SubRegClasses = [(FR32 sub_ss), (FR64 sub_sd), (VR128 sub_xmm)];
825 let MethodProtos = [{
826 iterator allocation_order_end(const MachineFunction &MF) const;
828 let MethodBodies = [{
830 VR256Class::allocation_order_end(const MachineFunction &MF) const {
831 const TargetMachine &TM = MF.getTarget();
832 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
833 if (!Subtarget.is64Bit())
834 return end()-8; // Only YMM0 to YMM7 are available in 32-bit mode.
841 // Status flags registers.
842 def CCR : RegisterClass<"X86", [i32], 32, [EFLAGS]> {
843 let CopyCost = -1; // Don't allow copying of status registers.
845 // EFLAGS is not allocatable.
846 let MethodProtos = [{
847 iterator allocation_order_end(const MachineFunction &MF) const;
849 let MethodBodies = [{
851 CCRClass::allocation_order_end(const MachineFunction &MF) const {
852 return allocation_order_begin(MF);