X86RegisterInfo.td revision d94c101abb2753e4d3cb7c7f436c7a38de94dc3c
1//===- X86RegisterInfo.td - Describe the X86 Register File --*- tablegen -*-==// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// 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// 19let 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 // 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) 30 31 // 8-bit registers 32 // Low registers 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]>; 37 38 // X86-64 only 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]>; 51 52 // High registers. On x86-64, these cannot be used in any instruction 53 // with a REX prefix. 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]>; 58 59 // 16-bit registers 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]>; 69 70 // X86-64 only 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]>; 79 80 // 32-bit registers 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]>; 90 91 // X86-64 only 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]>; 100 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]>; 110 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]>; 120 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]>; 130 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">; 139 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]>; 149 150 // X86-64 only 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]>; 159 160 // YMM Registers, used by AVX instructions 161 def YMM0: Register<"ymm0">, DwarfRegNum<[17, 21, 21]>; 162 def YMM1: Register<"ymm1">, DwarfRegNum<[18, 22, 22]>; 163 def YMM2: Register<"ymm2">, DwarfRegNum<[19, 23, 23]>; 164 def YMM3: Register<"ymm3">, DwarfRegNum<[20, 24, 24]>; 165 def YMM4: Register<"ymm4">, DwarfRegNum<[21, 25, 25]>; 166 def YMM5: Register<"ymm5">, DwarfRegNum<[22, 26, 26]>; 167 def YMM6: Register<"ymm6">, DwarfRegNum<[23, 27, 27]>; 168 def YMM7: Register<"ymm7">, DwarfRegNum<[24, 28, 28]>; 169 def YMM8: Register<"ymm8">, DwarfRegNum<[25, -2, -2]>; 170 def YMM9: Register<"ymm9">, DwarfRegNum<[26, -2, -2]>; 171 def YMM10: Register<"ymm10">, DwarfRegNum<[27, -2, -2]>; 172 def YMM11: Register<"ymm11">, DwarfRegNum<[28, -2, -2]>; 173 def YMM12: Register<"ymm12">, DwarfRegNum<[29, -2, -2]>; 174 def YMM13: Register<"ymm13">, DwarfRegNum<[30, -2, -2]>; 175 def YMM14: Register<"ymm14">, DwarfRegNum<[31, -2, -2]>; 176 def YMM15: Register<"ymm15">, DwarfRegNum<[32, -2, -2]>; 177 178 // Floating point stack registers 179 def ST0 : Register<"st(0)">, DwarfRegNum<[33, 12, 11]>; 180 def ST1 : Register<"st(1)">, DwarfRegNum<[34, 13, 12]>; 181 def ST2 : Register<"st(2)">, DwarfRegNum<[35, 14, 13]>; 182 def ST3 : Register<"st(3)">, DwarfRegNum<[36, 15, 14]>; 183 def ST4 : Register<"st(4)">, DwarfRegNum<[37, 16, 15]>; 184 def ST5 : Register<"st(5)">, DwarfRegNum<[38, 17, 16]>; 185 def ST6 : Register<"st(6)">, DwarfRegNum<[39, 18, 17]>; 186 def ST7 : Register<"st(7)">, DwarfRegNum<[40, 19, 18]>; 187 188 // Status flags register 189 def EFLAGS : Register<"flags">; 190 191 // Segment registers 192 def CS : Register<"cs">; 193 def DS : Register<"ds">; 194 def SS : Register<"ss">; 195 def ES : Register<"es">; 196 def FS : Register<"fs">; 197 def GS : Register<"gs">; 198} 199 200 201//===----------------------------------------------------------------------===// 202// Subregister Set Definitions... now that we have all of the pieces, define the 203// sub registers for each register. 204// 205 206def x86_subreg_8bit : PatLeaf<(i32 1)>; 207def x86_subreg_8bit_hi : PatLeaf<(i32 2)>; 208def x86_subreg_16bit : PatLeaf<(i32 3)>; 209def x86_subreg_32bit : PatLeaf<(i32 4)>; 210 211def : SubRegSet<1, [AX, CX, DX, BX, SP, BP, SI, DI, 212 R8W, R9W, R10W, R11W, R12W, R13W, R14W, R15W], 213 [AL, CL, DL, BL, SPL, BPL, SIL, DIL, 214 R8B, R9B, R10B, R11B, R12B, R13B, R14B, R15B]>; 215 216def : SubRegSet<2, [AX, CX, DX, BX], 217 [AH, CH, DH, BH]>; 218 219def : SubRegSet<1, [EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI, 220 R8D, R9D, R10D, R11D, R12D, R13D, R14D, R15D], 221 [AL, CL, DL, BL, SPL, BPL, SIL, DIL, 222 R8B, R9B, R10B, R11B, R12B, R13B, R14B, R15B]>; 223 224def : SubRegSet<2, [EAX, ECX, EDX, EBX], 225 [AH, CH, DH, BH]>; 226 227def : SubRegSet<3, [EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI, 228 R8D, R9D, R10D, R11D, R12D, R13D, R14D, R15D], 229 [AX, CX, DX, BX, SP, BP, SI, DI, 230 R8W, R9W, R10W, R11W, R12W, R13W, R14W, R15W]>; 231 232def : SubRegSet<1, [RAX, RCX, RDX, RBX, RSP, RBP, RSI, RDI, 233 R8, R9, R10, R11, R12, R13, R14, R15], 234 [AL, CL, DL, BL, SPL, BPL, SIL, DIL, 235 R8B, R9B, R10B, R11B, R12B, R13B, R14B, R15B]>; 236 237def : SubRegSet<2, [RAX, RCX, RDX, RBX], 238 [AH, CH, DH, BH]>; 239 240def : SubRegSet<3, [RAX, RCX, RDX, RBX, RSP, RBP, RSI, RDI, 241 R8, R9, R10, R11, R12, R13, R14, R15], 242 [AX, CX, DX, BX, SP, BP, SI, DI, 243 R8W, R9W, R10W, R11W, R12W, R13W, R14W, R15W]>; 244 245def : SubRegSet<4, [RAX, RCX, RDX, RBX, RSP, RBP, RSI, RDI, 246 R8, R9, R10, R11, R12, R13, R14, R15], 247 [EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI, 248 R8D, R9D, R10D, R11D, R12D, R13D, R14D, R15D]>; 249 250def : SubRegSet<1, [YMM0, YMM1, YMM2, YMM3, YMM4, YMM5, YMM6, YMM7, 251 YMM8, YMM9, YMM10, YMM11, YMM12, YMM13, YMM14, YMM15], 252 [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7, 253 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15]>; 254 255//===----------------------------------------------------------------------===// 256// Register Class Definitions... now that we have all of the pieces, define the 257// top-level register classes. The order specified in the register list is 258// implicitly defined to be the register allocation order. 259// 260 261// List call-clobbered registers before callee-save registers. RBX, RBP, (and 262// R12, R13, R14, and R15 for X86-64) are callee-save registers. 263// In 64-mode, there are 12 additional i8 registers, SIL, DIL, BPL, SPL, and 264// R8B, ... R15B. 265// Allocate R12 and R13 last, as these require an extra byte when 266// encoded in x86_64 instructions. 267// FIXME: Allow AH, CH, DH, BH to be used as general-purpose registers in 268// 64-bit mode. The main complication is that they cannot be encoded in an 269// instruction requiring a REX prefix, while SIL, DIL, BPL, R8D, etc. 270// require a REX prefix. For example, "addb %ah, %dil" and "movzbl %ah, %r8d" 271// cannot be encoded. 272def GR8 : RegisterClass<"X86", [i8], 8, 273 [AL, CL, DL, BL, AH, CH, DH, BH, SIL, DIL, BPL, SPL, 274 R8B, R9B, R10B, R11B, R14B, R15B, R12B, R13B]> { 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 SPL or BPL. 282 static const unsigned X86_GR8_AO_64_fp[] = { 283 X86::AL, X86::CL, X86::DL, X86::SIL, X86::DIL, 284 X86::R8B, X86::R9B, X86::R10B, X86::R11B, 285 X86::BL, X86::R14B, X86::R15B, X86::R12B, X86::R13B 286 }; 287 // If not, just don't allocate SPL. 288 static const unsigned X86_GR8_AO_64[] = { 289 X86::AL, X86::CL, X86::DL, X86::SIL, X86::DIL, 290 X86::R8B, X86::R9B, X86::R10B, X86::R11B, 291 X86::BL, X86::R14B, X86::R15B, X86::R12B, X86::R13B, X86::BPL 292 }; 293 // In 32-mode, none of the 8-bit registers aliases EBP or ESP. 294 static const unsigned X86_GR8_AO_32[] = { 295 X86::AL, X86::CL, X86::DL, X86::AH, X86::CH, X86::DH, X86::BL, X86::BH 296 }; 297 298 GR8Class::iterator 299 GR8Class::allocation_order_begin(const MachineFunction &MF) const { 300 const TargetMachine &TM = MF.getTarget(); 301 const TargetRegisterInfo *RI = TM.getRegisterInfo(); 302 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>(); 303 if (!Subtarget.is64Bit()) 304 return X86_GR8_AO_32; 305 else if (RI->hasFP(MF)) 306 return X86_GR8_AO_64_fp; 307 else 308 return X86_GR8_AO_64; 309 } 310 311 GR8Class::iterator 312 GR8Class::allocation_order_end(const MachineFunction &MF) const { 313 const TargetMachine &TM = MF.getTarget(); 314 const TargetRegisterInfo *RI = TM.getRegisterInfo(); 315 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>(); 316 if (!Subtarget.is64Bit()) 317 return X86_GR8_AO_32 + (sizeof(X86_GR8_AO_32) / sizeof(unsigned)); 318 else if (RI->hasFP(MF)) 319 return X86_GR8_AO_64_fp + (sizeof(X86_GR8_AO_64_fp) / sizeof(unsigned)); 320 else 321 return X86_GR8_AO_64 + (sizeof(X86_GR8_AO_64) / sizeof(unsigned)); 322 } 323 }]; 324} 325 326 327def GR16 : RegisterClass<"X86", [i16], 16, 328 [AX, CX, DX, SI, DI, BX, BP, SP, 329 R8W, R9W, R10W, R11W, R14W, R15W, R12W, R13W]> { 330 let SubRegClassList = [GR8, GR8]; 331 let MethodProtos = [{ 332 iterator allocation_order_begin(const MachineFunction &MF) const; 333 iterator allocation_order_end(const MachineFunction &MF) const; 334 }]; 335 let MethodBodies = [{ 336 // Does the function dedicate RBP / EBP to being a frame ptr? 337 // If so, don't allocate SP or BP. 338 static const unsigned X86_GR16_AO_64_fp[] = { 339 X86::AX, X86::CX, X86::DX, X86::SI, X86::DI, 340 X86::R8W, X86::R9W, X86::R10W, X86::R11W, 341 X86::BX, X86::R14W, X86::R15W, X86::R12W, X86::R13W 342 }; 343 static const unsigned X86_GR16_AO_32_fp[] = { 344 X86::AX, X86::CX, X86::DX, X86::SI, X86::DI, X86::BX 345 }; 346 // If not, just don't allocate SP. 347 static const unsigned X86_GR16_AO_64[] = { 348 X86::AX, X86::CX, X86::DX, X86::SI, X86::DI, 349 X86::R8W, X86::R9W, X86::R10W, X86::R11W, 350 X86::BX, X86::R14W, X86::R15W, X86::R12W, X86::R13W, X86::BP 351 }; 352 static const unsigned X86_GR16_AO_32[] = { 353 X86::AX, X86::CX, X86::DX, X86::SI, X86::DI, X86::BX, X86::BP 354 }; 355 356 GR16Class::iterator 357 GR16Class::allocation_order_begin(const MachineFunction &MF) const { 358 const TargetMachine &TM = MF.getTarget(); 359 const TargetRegisterInfo *RI = TM.getRegisterInfo(); 360 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>(); 361 if (Subtarget.is64Bit()) { 362 if (RI->hasFP(MF)) 363 return X86_GR16_AO_64_fp; 364 else 365 return X86_GR16_AO_64; 366 } else { 367 if (RI->hasFP(MF)) 368 return X86_GR16_AO_32_fp; 369 else 370 return X86_GR16_AO_32; 371 } 372 } 373 374 GR16Class::iterator 375 GR16Class::allocation_order_end(const MachineFunction &MF) const { 376 const TargetMachine &TM = MF.getTarget(); 377 const TargetRegisterInfo *RI = TM.getRegisterInfo(); 378 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>(); 379 if (Subtarget.is64Bit()) { 380 if (RI->hasFP(MF)) 381 return X86_GR16_AO_64_fp+(sizeof(X86_GR16_AO_64_fp)/sizeof(unsigned)); 382 else 383 return X86_GR16_AO_64 + (sizeof(X86_GR16_AO_64) / sizeof(unsigned)); 384 } else { 385 if (RI->hasFP(MF)) 386 return X86_GR16_AO_32_fp+(sizeof(X86_GR16_AO_32_fp)/sizeof(unsigned)); 387 else 388 return X86_GR16_AO_32 + (sizeof(X86_GR16_AO_32) / sizeof(unsigned)); 389 } 390 } 391 }]; 392} 393 394 395def GR32 : RegisterClass<"X86", [i32], 32, 396 [EAX, ECX, EDX, ESI, EDI, EBX, EBP, ESP, 397 R8D, R9D, R10D, R11D, R14D, R15D, R12D, R13D]> { 398 let SubRegClassList = [GR8, GR8, GR16]; 399 let MethodProtos = [{ 400 iterator allocation_order_begin(const MachineFunction &MF) const; 401 iterator allocation_order_end(const MachineFunction &MF) const; 402 }]; 403 let MethodBodies = [{ 404 // Does the function dedicate RBP / EBP to being a frame ptr? 405 // If so, don't allocate ESP or EBP. 406 static const unsigned X86_GR32_AO_64_fp[] = { 407 X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI, 408 X86::R8D, X86::R9D, X86::R10D, X86::R11D, 409 X86::EBX, X86::R14D, X86::R15D, X86::R12D, X86::R13D 410 }; 411 static const unsigned X86_GR32_AO_32_fp[] = { 412 X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI, X86::EBX 413 }; 414 // If not, just don't allocate ESP. 415 static const unsigned X86_GR32_AO_64[] = { 416 X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI, 417 X86::R8D, X86::R9D, X86::R10D, X86::R11D, 418 X86::EBX, X86::R14D, X86::R15D, X86::R12D, X86::R13D, X86::EBP 419 }; 420 static const unsigned X86_GR32_AO_32[] = { 421 X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI, X86::EBX, X86::EBP 422 }; 423 424 GR32Class::iterator 425 GR32Class::allocation_order_begin(const MachineFunction &MF) const { 426 const TargetMachine &TM = MF.getTarget(); 427 const TargetRegisterInfo *RI = TM.getRegisterInfo(); 428 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>(); 429 if (Subtarget.is64Bit()) { 430 if (RI->hasFP(MF)) 431 return X86_GR32_AO_64_fp; 432 else 433 return X86_GR32_AO_64; 434 } else { 435 if (RI->hasFP(MF)) 436 return X86_GR32_AO_32_fp; 437 else 438 return X86_GR32_AO_32; 439 } 440 } 441 442 GR32Class::iterator 443 GR32Class::allocation_order_end(const MachineFunction &MF) const { 444 const TargetMachine &TM = MF.getTarget(); 445 const TargetRegisterInfo *RI = TM.getRegisterInfo(); 446 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>(); 447 if (Subtarget.is64Bit()) { 448 if (RI->hasFP(MF)) 449 return X86_GR32_AO_64_fp+(sizeof(X86_GR32_AO_64_fp)/sizeof(unsigned)); 450 else 451 return X86_GR32_AO_64 + (sizeof(X86_GR32_AO_64) / sizeof(unsigned)); 452 } else { 453 if (RI->hasFP(MF)) 454 return X86_GR32_AO_32_fp+(sizeof(X86_GR32_AO_32_fp)/sizeof(unsigned)); 455 else 456 return X86_GR32_AO_32 + (sizeof(X86_GR32_AO_32) / sizeof(unsigned)); 457 } 458 } 459 }]; 460} 461 462 463def GR64 : RegisterClass<"X86", [i64], 64, 464 [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11, 465 RBX, R14, R15, R12, R13, RBP, RSP, RIP]> { 466 let SubRegClassList = [GR8, GR8, GR16, GR32]; 467 let MethodProtos = [{ 468 iterator allocation_order_end(const MachineFunction &MF) const; 469 }]; 470 let MethodBodies = [{ 471 GR64Class::iterator 472 GR64Class::allocation_order_end(const MachineFunction &MF) const { 473 const TargetMachine &TM = MF.getTarget(); 474 const TargetRegisterInfo *RI = TM.getRegisterInfo(); 475 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>(); 476 if (!Subtarget.is64Bit()) 477 return begin(); // None of these are allocatable in 32-bit. 478 if (RI->hasFP(MF)) // Does the function dedicate RBP to being a frame ptr? 479 return end()-3; // If so, don't allocate RIP, RSP or RBP 480 else 481 return end()-2; // If not, just don't allocate RIP or RSP 482 } 483 }]; 484} 485 486 487// GR8_ABCD_L, GR8_ABCD_H, GR16_ABCD, GR32_ABCD, GR64_ABCD - Subclasses of 488// GR8, GR16, GR32, and GR64 which contain just the "a" "b", "c", and "d" 489// registers. On x86-32, GR16_ABCD and GR32_ABCD are classes for registers 490// that support 8-bit subreg operations. On x86-64, GR16_ABCD, GR32_ABCD, 491// and GR64_ABCD are classes for registers that support 8-bit h-register 492// operations. 493def GR8_ABCD_L : RegisterClass<"X86", [i8], 8, [AL, CL, DL, BL]> { 494} 495def GR8_ABCD_H : RegisterClass<"X86", [i8], 8, [AH, CH, DH, BH]> { 496} 497def GR16_ABCD : RegisterClass<"X86", [i16], 16, [AX, CX, DX, BX]> { 498 let SubRegClassList = [GR8_ABCD_L, GR8_ABCD_H]; 499} 500def GR32_ABCD : RegisterClass<"X86", [i32], 32, [EAX, ECX, EDX, EBX]> { 501 let SubRegClassList = [GR8_ABCD_L, GR8_ABCD_H, GR16_ABCD]; 502} 503def GR64_ABCD : RegisterClass<"X86", [i64], 64, [RAX, RCX, RDX, RBX]> { 504 let SubRegClassList = [GR8_ABCD_L, GR8_ABCD_H, GR16_ABCD, GR32_ABCD]; 505} 506 507// GR8_NOREX, GR16_NOREX, GR32_NOREX, GR64_NOREX - Subclasses of 508// GR8, GR16, GR32, and GR64 which contain only the first 8 GPRs. 509// On x86-64, GR64_NOREX, GR32_NOREX and GR16_NOREX are the classes 510// of registers which do not by themselves require a REX prefix. 511def GR8_NOREX : RegisterClass<"X86", [i8], 8, 512 [AL, CL, DL, BL, AH, CH, DH, BH, 513 SIL, DIL, BPL, SPL]> { 514 let MethodProtos = [{ 515 iterator allocation_order_begin(const MachineFunction &MF) const; 516 iterator allocation_order_end(const MachineFunction &MF) const; 517 }]; 518 let MethodBodies = [{ 519 // Does the function dedicate RBP / EBP to being a frame ptr? 520 // If so, don't allocate SPL or BPL. 521 static const unsigned X86_GR8_NOREX_AO_64_fp[] = { 522 X86::AL, X86::CL, X86::DL, X86::SIL, X86::DIL, X86::BL 523 }; 524 // If not, just don't allocate SPL. 525 static const unsigned X86_GR8_NOREX_AO_64[] = { 526 X86::AL, X86::CL, X86::DL, X86::SIL, X86::DIL, X86::BL, X86::BPL 527 }; 528 // In 32-mode, none of the 8-bit registers aliases EBP or ESP. 529 static const unsigned X86_GR8_NOREX_AO_32[] = { 530 X86::AL, X86::CL, X86::DL, X86::AH, X86::CH, X86::DH, X86::BL, X86::BH 531 }; 532 533 GR8_NOREXClass::iterator 534 GR8_NOREXClass::allocation_order_begin(const MachineFunction &MF) const { 535 const TargetMachine &TM = MF.getTarget(); 536 const TargetRegisterInfo *RI = TM.getRegisterInfo(); 537 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>(); 538 if (!Subtarget.is64Bit()) 539 return X86_GR8_NOREX_AO_32; 540 else if (RI->hasFP(MF)) 541 return X86_GR8_NOREX_AO_64_fp; 542 else 543 return X86_GR8_NOREX_AO_64; 544 } 545 546 GR8_NOREXClass::iterator 547 GR8_NOREXClass::allocation_order_end(const MachineFunction &MF) const { 548 const TargetMachine &TM = MF.getTarget(); 549 const TargetRegisterInfo *RI = TM.getRegisterInfo(); 550 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>(); 551 if (!Subtarget.is64Bit()) 552 return X86_GR8_NOREX_AO_32 + 553 (sizeof(X86_GR8_NOREX_AO_32) / sizeof(unsigned)); 554 else if (RI->hasFP(MF)) 555 return X86_GR8_NOREX_AO_64_fp + 556 (sizeof(X86_GR8_NOREX_AO_64_fp) / sizeof(unsigned)); 557 else 558 return X86_GR8_NOREX_AO_64 + 559 (sizeof(X86_GR8_NOREX_AO_64) / sizeof(unsigned)); 560 } 561 }]; 562} 563def GR16_NOREX : RegisterClass<"X86", [i16], 16, 564 [AX, CX, DX, SI, DI, BX, BP, SP]> { 565 let SubRegClassList = [GR8_NOREX, GR8_NOREX]; 566 let MethodProtos = [{ 567 iterator allocation_order_begin(const MachineFunction &MF) const; 568 iterator allocation_order_end(const MachineFunction &MF) const; 569 }]; 570 let MethodBodies = [{ 571 // Does the function dedicate RBP / EBP to being a frame ptr? 572 // If so, don't allocate SP or BP. 573 static const unsigned X86_GR16_AO_fp[] = { 574 X86::AX, X86::CX, X86::DX, X86::SI, X86::DI, X86::BX 575 }; 576 // If not, just don't allocate SP. 577 static const unsigned X86_GR16_AO[] = { 578 X86::AX, X86::CX, X86::DX, X86::SI, X86::DI, X86::BX, X86::BP 579 }; 580 581 GR16_NOREXClass::iterator 582 GR16_NOREXClass::allocation_order_begin(const MachineFunction &MF) const { 583 const TargetMachine &TM = MF.getTarget(); 584 const TargetRegisterInfo *RI = TM.getRegisterInfo(); 585 if (RI->hasFP(MF)) 586 return X86_GR16_AO_fp; 587 else 588 return X86_GR16_AO; 589 } 590 591 GR16_NOREXClass::iterator 592 GR16_NOREXClass::allocation_order_end(const MachineFunction &MF) const { 593 const TargetMachine &TM = MF.getTarget(); 594 const TargetRegisterInfo *RI = TM.getRegisterInfo(); 595 if (RI->hasFP(MF)) 596 return X86_GR16_AO_fp+(sizeof(X86_GR16_AO_fp)/sizeof(unsigned)); 597 else 598 return X86_GR16_AO + (sizeof(X86_GR16_AO) / sizeof(unsigned)); 599 } 600 }]; 601} 602// GR32_NOREX - GR32 registers which do not require a REX prefix. 603def GR32_NOREX : RegisterClass<"X86", [i32], 32, 604 [EAX, ECX, EDX, ESI, EDI, EBX, EBP, ESP]> { 605 let SubRegClassList = [GR8_NOREX, GR8_NOREX, GR16_NOREX]; 606 let MethodProtos = [{ 607 iterator allocation_order_begin(const MachineFunction &MF) const; 608 iterator allocation_order_end(const MachineFunction &MF) const; 609 }]; 610 let MethodBodies = [{ 611 // Does the function dedicate RBP / EBP to being a frame ptr? 612 // If so, don't allocate ESP or EBP. 613 static const unsigned X86_GR32_NOREX_AO_fp[] = { 614 X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI, X86::EBX 615 }; 616 // If not, just don't allocate ESP. 617 static const unsigned X86_GR32_NOREX_AO[] = { 618 X86::EAX, X86::ECX, X86::EDX, X86::ESI, X86::EDI, X86::EBX, X86::EBP 619 }; 620 621 GR32_NOREXClass::iterator 622 GR32_NOREXClass::allocation_order_begin(const MachineFunction &MF) const { 623 const TargetMachine &TM = MF.getTarget(); 624 const TargetRegisterInfo *RI = TM.getRegisterInfo(); 625 if (RI->hasFP(MF)) 626 return X86_GR32_NOREX_AO_fp; 627 else 628 return X86_GR32_NOREX_AO; 629 } 630 631 GR32_NOREXClass::iterator 632 GR32_NOREXClass::allocation_order_end(const MachineFunction &MF) const { 633 const TargetMachine &TM = MF.getTarget(); 634 const TargetRegisterInfo *RI = TM.getRegisterInfo(); 635 if (RI->hasFP(MF)) 636 return X86_GR32_NOREX_AO_fp + 637 (sizeof(X86_GR32_NOREX_AO_fp) / sizeof(unsigned)); 638 else 639 return X86_GR32_NOREX_AO + 640 (sizeof(X86_GR32_NOREX_AO) / sizeof(unsigned)); 641 } 642 }]; 643} 644 645// GR64_NOREX - GR64 registers which do not require a REX prefix. 646def GR64_NOREX : RegisterClass<"X86", [i64], 64, 647 [RAX, RCX, RDX, RSI, RDI, RBX, RBP, RSP]> { 648 let SubRegClassList = [GR8_NOREX, GR8_NOREX, GR16_NOREX, GR32_NOREX]; 649 let MethodProtos = [{ 650 iterator allocation_order_begin(const MachineFunction &MF) const; 651 iterator allocation_order_end(const MachineFunction &MF) const; 652 }]; 653 let MethodBodies = [{ 654 // Does the function dedicate RBP / EBP to being a frame ptr? 655 // If so, don't allocate RSP or RBP. 656 static const unsigned X86_GR64_NOREX_AO_fp[] = { 657 X86::RAX, X86::RCX, X86::RDX, X86::RSI, X86::RDI, X86::RBX 658 }; 659 // If not, just don't allocate RSP. 660 static const unsigned X86_GR64_NOREX_AO[] = { 661 X86::RAX, X86::RCX, X86::RDX, X86::RSI, X86::RDI, X86::RBX, X86::RBP 662 }; 663 664 GR64_NOREXClass::iterator 665 GR64_NOREXClass::allocation_order_begin(const MachineFunction &MF) const { 666 const TargetMachine &TM = MF.getTarget(); 667 const TargetRegisterInfo *RI = TM.getRegisterInfo(); 668 if (RI->hasFP(MF)) 669 return X86_GR64_NOREX_AO_fp; 670 else 671 return X86_GR64_NOREX_AO; 672 } 673 674 GR64_NOREXClass::iterator 675 GR64_NOREXClass::allocation_order_end(const MachineFunction &MF) const { 676 const TargetMachine &TM = MF.getTarget(); 677 const TargetRegisterInfo *RI = TM.getRegisterInfo(); 678 if (RI->hasFP(MF)) 679 return X86_GR64_NOREX_AO_fp + 680 (sizeof(X86_GR64_NOREX_AO_fp) / sizeof(unsigned)); 681 else 682 return X86_GR64_NOREX_AO + 683 (sizeof(X86_GR64_NOREX_AO) / sizeof(unsigned)); 684 } 685 }]; 686} 687 688// A class to support the 'A' assembler constraint: EAX then EDX. 689def GRAD : RegisterClass<"X86", [i32], 32, [EAX, EDX]>; 690 691// Scalar SSE2 floating point registers. 692def FR32 : RegisterClass<"X86", [f32], 32, 693 [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7, 694 XMM8, XMM9, XMM10, XMM11, 695 XMM12, XMM13, XMM14, XMM15]> { 696 let MethodProtos = [{ 697 iterator allocation_order_end(const MachineFunction &MF) const; 698 }]; 699 let MethodBodies = [{ 700 FR32Class::iterator 701 FR32Class::allocation_order_end(const MachineFunction &MF) const { 702 const TargetMachine &TM = MF.getTarget(); 703 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>(); 704 if (!Subtarget.is64Bit()) 705 return end()-8; // Only XMM0 to XMM7 are available in 32-bit mode. 706 else 707 return end(); 708 } 709 }]; 710} 711 712def FR64 : RegisterClass<"X86", [f64], 64, 713 [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7, 714 XMM8, XMM9, XMM10, XMM11, 715 XMM12, XMM13, XMM14, XMM15]> { 716 let MethodProtos = [{ 717 iterator allocation_order_end(const MachineFunction &MF) const; 718 }]; 719 let MethodBodies = [{ 720 FR64Class::iterator 721 FR64Class::allocation_order_end(const MachineFunction &MF) const { 722 const TargetMachine &TM = MF.getTarget(); 723 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>(); 724 if (!Subtarget.is64Bit()) 725 return end()-8; // Only XMM0 to XMM7 are available in 32-bit mode. 726 else 727 return end(); 728 } 729 }]; 730} 731 732 733// FIXME: This sets up the floating point register files as though they are f64 734// values, though they really are f80 values. This will cause us to spill 735// values as 64-bit quantities instead of 80-bit quantities, which is much much 736// faster on common hardware. In reality, this should be controlled by a 737// command line option or something. 738 739def RFP32 : RegisterClass<"X86",[f32], 32, [FP0, FP1, FP2, FP3, FP4, FP5, FP6]>; 740def RFP64 : RegisterClass<"X86",[f64], 32, [FP0, FP1, FP2, FP3, FP4, FP5, FP6]>; 741def RFP80 : RegisterClass<"X86",[f80], 32, [FP0, FP1, FP2, FP3, FP4, FP5, FP6]>; 742 743// Floating point stack registers (these are not allocatable by the 744// register allocator - the floating point stackifier is responsible 745// for transforming FPn allocations to STn registers) 746def RST : RegisterClass<"X86", [f80, f64, f32], 32, 747 [ST0, ST1, ST2, ST3, ST4, ST5, ST6, ST7]> { 748 let MethodProtos = [{ 749 iterator allocation_order_end(const MachineFunction &MF) const; 750 }]; 751 let MethodBodies = [{ 752 RSTClass::iterator 753 RSTClass::allocation_order_end(const MachineFunction &MF) const { 754 return begin(); 755 } 756 }]; 757} 758 759// Generic vector registers: VR64 and VR128. 760def VR64 : RegisterClass<"X86", [v8i8, v4i16, v2i32, v1i64, v2f32], 64, 761 [MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7]>; 762def VR128 : RegisterClass<"X86", [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],128, 763 [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7, 764 XMM8, XMM9, XMM10, XMM11, 765 XMM12, XMM13, XMM14, XMM15]> { 766 let MethodProtos = [{ 767 iterator allocation_order_end(const MachineFunction &MF) const; 768 }]; 769 let MethodBodies = [{ 770 VR128Class::iterator 771 VR128Class::allocation_order_end(const MachineFunction &MF) const { 772 const TargetMachine &TM = MF.getTarget(); 773 const X86Subtarget &Subtarget = TM.getSubtarget<X86Subtarget>(); 774 if (!Subtarget.is64Bit()) 775 return end()-8; // Only XMM0 to XMM7 are available in 32-bit mode. 776 else 777 return end(); 778 } 779 }]; 780} 781def VR256 : RegisterClass<"X86", [ v8i32, v4i64, v8f32, v4f64],256, 782 [YMM0, YMM1, YMM2, YMM3, YMM4, YMM5, YMM6, YMM7, 783 YMM8, YMM9, YMM10, YMM11, 784 YMM12, YMM13, YMM14, YMM15]>; 785 786// Status flags registers. 787def CCR : RegisterClass<"X86", [i32], 32, [EFLAGS]> { 788 let CopyCost = -1; // Don't allow copying of status registers. 789} 790