1 //===- X86RegisterInfo.td - Describe the X86 Register File --*- tablegen -*-==//
3 // The LLVM Compiler Infrastructure
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.
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. Thus it is not encoded here;
28 // see X86RegisterInfo::getDwarfRegNum.
32 def AL : Register<"AL">;
33 def DL : Register<"DL">;
34 def CL : Register<"CL">;
35 def BL : Register<"BL">;
38 def SIL : Register<"SIL">;
39 def DIL : Register<"DIL">;
40 def BPL : Register<"BPL">;
41 def SPL : Register<"SPL">;
42 def R8B : Register<"R8B">;
43 def R9B : Register<"R9B">;
44 def R10B : Register<"R10B">;
45 def R11B : Register<"R11B">;
46 def R12B : Register<"R12B">;
47 def R13B : Register<"R13B">;
48 def R14B : Register<"R14B">;
49 def R15B : Register<"R15B">;
51 // High registers X86-32 only
52 def AH : Register<"AH">;
53 def DH : Register<"DH">;
54 def CH : Register<"CH">;
55 def BH : Register<"BH">;
58 def AX : RegisterWithSubRegs<"AX", [AH,AL]>;
59 def DX : RegisterWithSubRegs<"DX", [DH,DL]>;
60 def CX : RegisterWithSubRegs<"CX", [CH,CL]>;
61 def BX : RegisterWithSubRegs<"BX", [BH,BL]>;
62 def SI : RegisterWithSubRegs<"SI", [SIL]>;
63 def DI : RegisterWithSubRegs<"DI", [DIL]>;
64 def BP : RegisterWithSubRegs<"BP", [BPL]>;
65 def SP : RegisterWithSubRegs<"SP", [SPL]>;
66 def IP : Register<"IP">;
69 def R8W : RegisterWithSubRegs<"R8W", [R8B]>;
70 def R9W : RegisterWithSubRegs<"R9W", [R9B]>;
71 def R10W : RegisterWithSubRegs<"R10W", [R10B]>;
72 def R11W : RegisterWithSubRegs<"R11W", [R11B]>;
73 def R12W : RegisterWithSubRegs<"R12W", [R12B]>;
74 def R13W : RegisterWithSubRegs<"R13W", [R13B]>;
75 def R14W : RegisterWithSubRegs<"R14W", [R14B]>;
76 def R15W : RegisterWithSubRegs<"R15W", [R15B]>;
79 def EAX : RegisterWithSubRegs<"EAX", [AX]>;
80 def EDX : RegisterWithSubRegs<"EDX", [DX]>;
81 def ECX : RegisterWithSubRegs<"ECX", [CX]>;
82 def EBX : RegisterWithSubRegs<"EBX", [BX]>;
83 def ESI : RegisterWithSubRegs<"ESI", [SI]>;
84 def EDI : RegisterWithSubRegs<"EDI", [DI]>;
85 def EBP : RegisterWithSubRegs<"EBP", [BP]>;
86 def ESP : RegisterWithSubRegs<"ESP", [SP]>;
87 def EIP : RegisterWithSubRegs<"EIP", [IP]>;
90 def R8D : RegisterWithSubRegs<"R8D", [R8W]>;
91 def R9D : RegisterWithSubRegs<"R9D", [R9W]>;
92 def R10D : RegisterWithSubRegs<"R10D", [R10W]>;
93 def R11D : RegisterWithSubRegs<"R11D", [R11W]>;
94 def R12D : RegisterWithSubRegs<"R12D", [R12W]>;
95 def R13D : RegisterWithSubRegs<"R13D", [R13W]>;
96 def R14D : RegisterWithSubRegs<"R14D", [R14W]>;
97 def R15D : RegisterWithSubRegs<"R15D", [R15W]>;
99 // 64-bit registers, X86-64 only
100 def RAX : RegisterWithSubRegs<"RAX", [EAX]>;
101 def RDX : RegisterWithSubRegs<"RDX", [EDX]>;
102 def RCX : RegisterWithSubRegs<"RCX", [ECX]>;
103 def RBX : RegisterWithSubRegs<"RBX", [EBX]>;
104 def RSI : RegisterWithSubRegs<"RSI", [ESI]>;
105 def RDI : RegisterWithSubRegs<"RDI", [EDI]>;
106 def RBP : RegisterWithSubRegs<"RBP", [EBP]>;
107 def RSP : RegisterWithSubRegs<"RSP", [ESP]>;
109 def R8 : RegisterWithSubRegs<"R8", [R8D]>;
110 def R9 : RegisterWithSubRegs<"R9", [R9D]>;
111 def R10 : RegisterWithSubRegs<"R10", [R10D]>;
112 def R11 : RegisterWithSubRegs<"R11", [R11D]>;
113 def R12 : RegisterWithSubRegs<"R12", [R12D]>;
114 def R13 : RegisterWithSubRegs<"R13", [R13D]>;
115 def R14 : RegisterWithSubRegs<"R14", [R14D]>;
116 def R15 : RegisterWithSubRegs<"R15", [R15D]>;
117 def RIP : RegisterWithSubRegs<"RIP", [EIP]>;
119 // MMX Registers. These are actually aliased to ST0 .. ST7
120 def MM0 : Register<"MM0">;
121 def MM1 : Register<"MM1">;
122 def MM2 : Register<"MM2">;
123 def MM3 : Register<"MM3">;
124 def MM4 : Register<"MM4">;
125 def MM5 : Register<"MM5">;
126 def MM6 : Register<"MM6">;
127 def MM7 : Register<"MM7">;
129 // Pseudo Floating Point registers
130 def FP0 : Register<"FP0">;
131 def FP1 : Register<"FP1">;
132 def FP2 : Register<"FP2">;
133 def FP3 : Register<"FP3">;
134 def FP4 : Register<"FP4">;
135 def FP5 : Register<"FP5">;
136 def FP6 : Register<"FP6">;
138 // XMM Registers, used by the various SSE instruction set extensions
139 def XMM0: Register<"XMM0">;
140 def XMM1: Register<"XMM1">;
141 def XMM2: Register<"XMM2">;
142 def XMM3: Register<"XMM3">;
143 def XMM4: Register<"XMM4">;
144 def XMM5: Register<"XMM5">;
145 def XMM6: Register<"XMM6">;
146 def XMM7: Register<"XMM7">;
149 def XMM8: Register<"XMM8">;
150 def XMM9: Register<"XMM9">;
151 def XMM10: Register<"XMM10">;
152 def XMM11: Register<"XMM11">;
153 def XMM12: Register<"XMM12">;
154 def XMM13: Register<"XMM13">;
155 def XMM14: Register<"XMM14">;
156 def XMM15: Register<"XMM15">;
158 // Floating point stack registers
159 def ST0 : Register<"ST(0)">;
160 def ST1 : Register<"ST(1)">;
161 def ST2 : Register<"ST(2)">;
162 def ST3 : Register<"ST(3)">;
163 def ST4 : Register<"ST(4)">;
164 def ST5 : Register<"ST(5)">;
165 def ST6 : Register<"ST(6)">;
166 def ST7 : Register<"ST(7)">;
168 // Status flags register
169 def EFLAGS : Register<"EFLAGS">;
173 //===----------------------------------------------------------------------===//
174 // Subregister Set Definitions... now that we have all of the pieces, define the
175 // sub registers for each register.
178 def : SubRegSet<1, [AX, CX, DX, BX, SP, BP, SI, DI,
179 R8W, R9W, R10W, R11W, R12W, R13W, R14W, R15W],
180 [AL, CL, DL, BL, SPL, BPL, SIL, DIL,
181 R8B, R9B, R10B, R11B, R12B, R13B, R14B, R15B]>;
183 // It's unclear if this subreg set is safe, given that not all registers
184 // in the class have an 'H' subreg.
185 // def : SubRegSet<2, [AX, CX, DX, BX],
186 // [AH, CH, DH, BH]>;
188 def : SubRegSet<1, [EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI,
189 R8D, R9D, R10D, R11D, R12D, R13D, R14D, R15D],
190 [AL, CL, DL, BL, SPL, BPL, SIL, DIL,
191 R8B, R9B, R10B, R11B, R12B, R13B, R14B, R15B]>;
193 def : SubRegSet<2, [EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI,
194 R8D, R9D, R10D, R11D, R12D, R13D, R14D, R15D],
195 [AX, CX, DX, BX, SP, BP, SI, DI,
196 R8W, R9W, R10W, R11W, R12W, R13W, R14W, R15W]>;
199 def : SubRegSet<1, [RAX, RCX, RDX, RBX, RSP, RBP, RSI, RDI,
200 R8, R9, R10, R11, R12, R13, R14, R15],
201 [AL, CL, DL, BL, SPL, BPL, SIL, DIL,
202 R8B, R9B, R10B, R11B, R12B, R13B, R14B, R15B]>;
204 def : SubRegSet<2, [RAX, RCX, RDX, RBX, RSP, RBP, RSI, RDI,
205 R8, R9, R10, R11, R12, R13, R14, R15],
206 [AX, CX, DX, BX, SP, BP, SI, DI,
207 R8W, R9W, R10W, R11W, R12W, R13W, R14W, R15W]>;
209 def : SubRegSet<3, [RAX, RCX, RDX, RBX, RSP, RBP, RSI, RDI,
210 R8, R9, R10, R11, R12, R13, R14, R15],
211 [EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI,
212 R8D, R9D, R10D, R11D, R12D, R13D, R14D, R15D]>;
214 //===----------------------------------------------------------------------===//
215 // Register Class Definitions... now that we have all of the pieces, define the
216 // top-level register classes. The order specified in the register list is
217 // implicitly defined to be the register allocation order.
220 // List call-clobbered registers before callee-save registers. RBX, RBP, (and
221 // R12, R13, R14, and R15 for X86-64) are callee-save registers.
222 // In 64-mode, there are 12 additional i8 registers, SIL, DIL, BPL, SPL, and
224 // FIXME: Allow AH, CH, DH, BH in 64-mode for non-REX instructions,
225 def GR8 : RegisterClass<"X86", [i8], 8,
226 [AL, CL, DL, BL, AH, CH, DH, BH, SIL, DIL, BPL, SPL,
227 R8B, R9B, R10B, R11B, R12B, R13B, R14B, R15B]> {
228 let MethodProtos = [{
229 iterator allocation_order_begin(const MachineFunction &MF) const;
230 iterator allocation_order_end(const MachineFunction &MF) const;
232 let MethodBodies = [{
233 // Does the function dedicate RBP / EBP to being a frame ptr?
234 // If so, don't allocate SPL or BPL.
235 static const unsigned X86_GR8_AO_64_fp[] =
236 {X86::AL, X86::CL, X86::DL, X86::SIL, X86::DIL,
237 X86::R8B, X86::R9B, X86::R10B, X86::R11B,
238 X86::BL, X86::R14B, X86::R15B, X86::R12B, X86::R13B};
239 // If not, just don't allocate SPL.
240 static const unsigned X86_GR8_AO_64[] =
241 {X86::AL, X86::CL, X86::DL, X86::SIL, X86::DIL,
242 X86::R8B, X86::R9B, X86::R10B, X86::R11B,
243 X86::BL, X86::R14B, X86::R15B, X86::R12B, X86::R13B, X86::BPL};
244 // In 32-mode, none of the 8-bit registers aliases EBP or ESP.
245 static const unsigned X86_GR8_AO_32[] =
246 {X86::AL, X86::CL, X86::DL, X86::AH, X86::CH, X86::DH, X86::BL, X86::BH};
249 GR8Class::allocation_order_begin(const MachineFunction &MF) const {
250 const TargetMachine &TM = MF.getTarget();
251 const MRegisterInfo *RI = TM.getRegisterInfo();
252 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
253 if (!Subtarget.is64Bit())
254 return X86_GR8_AO_32;
255 else if (RI->hasFP(MF))
256 return X86_GR8_AO_64_fp;
258 return X86_GR8_AO_64;
262 GR8Class::allocation_order_end(const MachineFunction &MF) const {
263 const TargetMachine &TM = MF.getTarget();
264 const MRegisterInfo *RI = TM.getRegisterInfo();
265 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
266 if (!Subtarget.is64Bit())
267 return X86_GR8_AO_32 + (sizeof(X86_GR8_AO_32) / sizeof(unsigned));
268 else if (RI->hasFP(MF))
269 return X86_GR8_AO_64_fp + (sizeof(X86_GR8_AO_64_fp) / sizeof(unsigned));
271 return X86_GR8_AO_64 + (sizeof(X86_GR8_AO_64) / sizeof(unsigned));
277 def GR16 : RegisterClass<"X86", [i16], 16,
278 [AX, CX, DX, SI, DI, BX, BP, SP,
279 R8W, R9W, R10W, R11W, R12W, R13W, R14W, R15W]> {
280 let SubRegClassList = [GR8];
281 let MethodProtos = [{
282 iterator allocation_order_begin(const MachineFunction &MF) const;
283 iterator allocation_order_end(const MachineFunction &MF) const;
285 let MethodBodies = [{
286 // Does the function dedicate RBP / EBP to being a frame ptr?
287 // If so, don't allocate SP or BP.
288 static const unsigned X86_GR16_AO_64_fp[] =
289 {X86::AX, X86::CX, X86::DX, X86::SI, X86::DI,
290 X86::R8W, X86::R9W, X86::R10W, X86::R11W,
291 X86::BX, X86::R14W, X86::R15W, X86::R12W, X86::R13W};
292 static const unsigned X86_GR16_AO_32_fp[] =
293 {X86::AX, X86::CX, X86::DX, X86::SI, X86::DI, X86::BX};
294 // If not, just don't allocate SPL.
295 static const unsigned X86_GR16_AO_64[] =
296 {X86::AX, X86::CX, X86::DX, X86::SI, X86::DI,
297 X86::R8W, X86::R9W, X86::R10W, X86::R11W,
298 X86::BX, X86::R14W, X86::R15W, X86::R12W, X86::R13W, X86::BP};
299 static const unsigned X86_GR16_AO_32[] =
300 {X86::AX, X86::CX, X86::DX, X86::SI, X86::DI, X86::BX, X86::BP};
303 GR16Class::allocation_order_begin(const MachineFunction &MF) const {
304 const TargetMachine &TM = MF.getTarget();
305 const MRegisterInfo *RI = TM.getRegisterInfo();
306 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
307 if (Subtarget.is64Bit()) {
309 return X86_GR16_AO_64_fp;
311 return X86_GR16_AO_64;
314 return X86_GR16_AO_32_fp;
316 return X86_GR16_AO_32;
321 GR16Class::allocation_order_end(const MachineFunction &MF) const {
322 const TargetMachine &TM = MF.getTarget();
323 const MRegisterInfo *RI = TM.getRegisterInfo();
324 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
325 if (Subtarget.is64Bit()) {
327 return X86_GR16_AO_64_fp+(sizeof(X86_GR16_AO_64_fp)/sizeof(unsigned));
329 return X86_GR16_AO_64 + (sizeof(X86_GR16_AO_64) / sizeof(unsigned));
332 return X86_GR16_AO_32_fp+(sizeof(X86_GR16_AO_32_fp)/sizeof(unsigned));
334 return X86_GR16_AO_32 + (sizeof(X86_GR16_AO_32) / sizeof(unsigned));
341 def GR32 : RegisterClass<"X86", [i32], 32,
342 [EAX, ECX, EDX, ESI, EDI, EBX, EBP, ESP,
343 R8D, R9D, R10D, R11D, R12D, R13D, R14D, R15D]> {
344 let SubRegClassList = [GR8, GR16];
345 let MethodProtos = [{
346 iterator allocation_order_begin(const MachineFunction &MF) const;
347 iterator allocation_order_end(const MachineFunction &MF) const;
349 let MethodBodies = [{
350 // Does the function dedicate RBP / EBP to being a frame ptr?
351 // If so, don't allocate ESP or EBP.
352 static const unsigned X86_GR32_AO_64_fp[] =
353 {X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI,
354 X86::R8D, X86::R9D, X86::R10D, X86::R11D,
355 X86::EBX, X86::R14D, X86::R15D, X86::R12D, X86::R13D};
356 static const unsigned X86_GR32_AO_32_fp[] =
357 {X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI, X86::EBX};
358 // If not, just don't allocate SPL.
359 static const unsigned X86_GR32_AO_64[] =
360 {X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI,
361 X86::R8D, X86::R9D, X86::R10D, X86::R11D,
362 X86::EBX, X86::R14D, X86::R15D, X86::R12D, X86::R13D, X86::EBP};
363 static const unsigned X86_GR32_AO_32[] =
364 {X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI, X86::EBX, X86::EBP};
367 GR32Class::allocation_order_begin(const MachineFunction &MF) const {
368 const TargetMachine &TM = MF.getTarget();
369 const MRegisterInfo *RI = TM.getRegisterInfo();
370 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
371 if (Subtarget.is64Bit()) {
373 return X86_GR32_AO_64_fp;
375 return X86_GR32_AO_64;
378 return X86_GR32_AO_32_fp;
380 return X86_GR32_AO_32;
385 GR32Class::allocation_order_end(const MachineFunction &MF) const {
386 const TargetMachine &TM = MF.getTarget();
387 const MRegisterInfo *RI = TM.getRegisterInfo();
388 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
389 if (Subtarget.is64Bit()) {
391 return X86_GR32_AO_64_fp+(sizeof(X86_GR32_AO_64_fp)/sizeof(unsigned));
393 return X86_GR32_AO_64 + (sizeof(X86_GR32_AO_64) / sizeof(unsigned));
396 return X86_GR32_AO_32_fp+(sizeof(X86_GR32_AO_32_fp)/sizeof(unsigned));
398 return X86_GR32_AO_32 + (sizeof(X86_GR32_AO_32) / sizeof(unsigned));
405 def GR64 : RegisterClass<"X86", [i64], 64,
406 [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
407 RBX, R14, R15, R12, R13, RBP, RSP]> {
408 let SubRegClassList = [GR8, GR16, GR32];
409 let MethodProtos = [{
410 iterator allocation_order_end(const MachineFunction &MF) const;
412 let MethodBodies = [{
414 GR64Class::allocation_order_end(const MachineFunction &MF) const {
415 const TargetMachine &TM = MF.getTarget();
416 const MRegisterInfo *RI = TM.getRegisterInfo();
417 if (RI->hasFP(MF)) // Does the function dedicate RBP to being a frame ptr?
418 return end()-2; // If so, don't allocate RSP or RBP
420 return end()-1; // If not, just don't allocate RSP
426 // GR16, GR32 subclasses which contain registers that have GR8 sub-registers.
427 // These should only be used for 32-bit mode.
428 def GR16_ : RegisterClass<"X86", [i16], 16, [AX, CX, DX, BX]> {
429 let SubRegClassList = [GR8];
431 def GR32_ : RegisterClass<"X86", [i32], 32, [EAX, ECX, EDX, EBX]> {
432 let SubRegClassList = [GR8, GR16];
435 // Scalar SSE2 floating point registers.
436 def FR32 : RegisterClass<"X86", [f32], 32,
437 [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
438 XMM8, XMM9, XMM10, XMM11,
439 XMM12, XMM13, XMM14, XMM15]> {
440 let MethodProtos = [{
441 iterator allocation_order_end(const MachineFunction &MF) const;
443 let MethodBodies = [{
445 FR32Class::allocation_order_end(const MachineFunction &MF) const {
446 const TargetMachine &TM = MF.getTarget();
447 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
448 if (!Subtarget.is64Bit())
449 return end()-8; // Only XMM0 to XMM7 are available in 32-bit mode.
456 def FR64 : RegisterClass<"X86", [f64], 64,
457 [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
458 XMM8, XMM9, XMM10, XMM11,
459 XMM12, XMM13, XMM14, XMM15]> {
460 let MethodProtos = [{
461 iterator allocation_order_end(const MachineFunction &MF) const;
463 let MethodBodies = [{
465 FR64Class::allocation_order_end(const MachineFunction &MF) const {
466 const TargetMachine &TM = MF.getTarget();
467 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
468 if (!Subtarget.is64Bit())
469 return end()-8; // Only XMM0 to XMM7 are available in 32-bit mode.
477 // FIXME: This sets up the floating point register files as though they are f64
478 // values, though they really are f80 values. This will cause us to spill
479 // values as 64-bit quantities instead of 80-bit quantities, which is much much
480 // faster on common hardware. In reality, this should be controlled by a
481 // command line option or something.
483 def RFP32 : RegisterClass<"X86", [f32], 32, [FP0, FP1, FP2, FP3, FP4, FP5, FP6]>;
484 def RFP64 : RegisterClass<"X86", [f64], 32, [FP0, FP1, FP2, FP3, FP4, FP5, FP6]>;
485 def RFP80 : RegisterClass<"X86", [f80], 32, [FP0, FP1, FP2, FP3, FP4, FP5, FP6]>;
487 // Floating point stack registers (these are not allocatable by the
488 // register allocator - the floating point stackifier is responsible
489 // for transforming FPn allocations to STn registers)
490 def RST : RegisterClass<"X86", [f64], 32,
491 [ST0, ST1, ST2, ST3, ST4, ST5, ST6, ST7]> {
492 let MethodProtos = [{
493 iterator allocation_order_end(const MachineFunction &MF) const;
495 let MethodBodies = [{
497 RSTClass::allocation_order_end(const MachineFunction &MF) const {
503 // Generic vector registers: VR64 and VR128.
504 def VR64 : RegisterClass<"X86", [v8i8, v4i16, v2i32, v1i64], 64,
505 [MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7]>;
506 def VR128 : RegisterClass<"X86", [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],128,
507 [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
508 XMM8, XMM9, XMM10, XMM11,
509 XMM12, XMM13, XMM14, XMM15]> {
510 let MethodProtos = [{
511 iterator allocation_order_end(const MachineFunction &MF) const;
513 let MethodBodies = [{
515 VR128Class::allocation_order_end(const MachineFunction &MF) const {
516 const TargetMachine &TM = MF.getTarget();
517 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>();
518 if (!Subtarget.is64Bit())
519 return end()-8; // Only XMM0 to XMM7 are available in 32-bit mode.
526 // Status flags registers.
527 def CCR : RegisterClass<"X86", [i32], 32, [EFLAGS]> {
528 let CopyCost = -1; // Don't allow copying of status registers.