X86RegisterInfo.cpp revision 4ee451de366474b9c228b4e5fa573795a715216d
1//===- X86RegisterInfo.cpp - X86 Register Information -----------*- C++ -*-===// 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 contains the X86 implementation of the MRegisterInfo class. This 11// file is responsible for the frame pointer elimination optimization on X86. 12// 13//===----------------------------------------------------------------------===// 14 15#include "X86.h" 16#include "X86RegisterInfo.h" 17#include "X86InstrBuilder.h" 18#include "X86MachineFunctionInfo.h" 19#include "X86Subtarget.h" 20#include "X86TargetMachine.h" 21#include "llvm/Constants.h" 22#include "llvm/Function.h" 23#include "llvm/Type.h" 24#include "llvm/CodeGen/ValueTypes.h" 25#include "llvm/CodeGen/MachineInstrBuilder.h" 26#include "llvm/CodeGen/MachineFunction.h" 27#include "llvm/CodeGen/MachineFrameInfo.h" 28#include "llvm/CodeGen/MachineLocation.h" 29#include "llvm/CodeGen/SSARegMap.h" 30#include "llvm/Target/TargetAsmInfo.h" 31#include "llvm/Target/TargetFrameInfo.h" 32#include "llvm/Target/TargetInstrInfo.h" 33#include "llvm/Target/TargetMachine.h" 34#include "llvm/Target/TargetOptions.h" 35#include "llvm/Support/CommandLine.h" 36#include "llvm/ADT/BitVector.h" 37#include "llvm/ADT/STLExtras.h" 38using namespace llvm; 39 40namespace { 41 cl::opt<bool> 42 NoFusing("disable-spill-fusing", 43 cl::desc("Disable fusing of spill code into instructions")); 44 cl::opt<bool> 45 PrintFailedFusing("print-failed-fuse-candidates", 46 cl::desc("Print instructions that the allocator wants to" 47 " fuse, but the X86 backend currently can't"), 48 cl::Hidden); 49} 50 51X86RegisterInfo::X86RegisterInfo(X86TargetMachine &tm, 52 const TargetInstrInfo &tii) 53 : X86GenRegisterInfo(X86::ADJCALLSTACKDOWN, X86::ADJCALLSTACKUP), 54 TM(tm), TII(tii) { 55 // Cache some information. 56 const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>(); 57 Is64Bit = Subtarget->is64Bit(); 58 StackAlign = TM.getFrameInfo()->getStackAlignment(); 59 if (Is64Bit) { 60 SlotSize = 8; 61 StackPtr = X86::RSP; 62 FramePtr = X86::RBP; 63 } else { 64 SlotSize = 4; 65 StackPtr = X86::ESP; 66 FramePtr = X86::EBP; 67 } 68 69 SmallVector<unsigned,16> AmbEntries; 70 static const unsigned OpTbl2Addr[][2] = { 71 { X86::ADC32ri, X86::ADC32mi }, 72 { X86::ADC32ri8, X86::ADC32mi8 }, 73 { X86::ADC32rr, X86::ADC32mr }, 74 { X86::ADC64ri32, X86::ADC64mi32 }, 75 { X86::ADC64ri8, X86::ADC64mi8 }, 76 { X86::ADC64rr, X86::ADC64mr }, 77 { X86::ADD16ri, X86::ADD16mi }, 78 { X86::ADD16ri8, X86::ADD16mi8 }, 79 { X86::ADD16rr, X86::ADD16mr }, 80 { X86::ADD32ri, X86::ADD32mi }, 81 { X86::ADD32ri8, X86::ADD32mi8 }, 82 { X86::ADD32rr, X86::ADD32mr }, 83 { X86::ADD64ri32, X86::ADD64mi32 }, 84 { X86::ADD64ri8, X86::ADD64mi8 }, 85 { X86::ADD64rr, X86::ADD64mr }, 86 { X86::ADD8ri, X86::ADD8mi }, 87 { X86::ADD8rr, X86::ADD8mr }, 88 { X86::AND16ri, X86::AND16mi }, 89 { X86::AND16ri8, X86::AND16mi8 }, 90 { X86::AND16rr, X86::AND16mr }, 91 { X86::AND32ri, X86::AND32mi }, 92 { X86::AND32ri8, X86::AND32mi8 }, 93 { X86::AND32rr, X86::AND32mr }, 94 { X86::AND64ri32, X86::AND64mi32 }, 95 { X86::AND64ri8, X86::AND64mi8 }, 96 { X86::AND64rr, X86::AND64mr }, 97 { X86::AND8ri, X86::AND8mi }, 98 { X86::AND8rr, X86::AND8mr }, 99 { X86::DEC16r, X86::DEC16m }, 100 { X86::DEC32r, X86::DEC32m }, 101 { X86::DEC64_16r, X86::DEC64_16m }, 102 { X86::DEC64_32r, X86::DEC64_32m }, 103 { X86::DEC64r, X86::DEC64m }, 104 { X86::DEC8r, X86::DEC8m }, 105 { X86::INC16r, X86::INC16m }, 106 { X86::INC32r, X86::INC32m }, 107 { X86::INC64_16r, X86::INC64_16m }, 108 { X86::INC64_32r, X86::INC64_32m }, 109 { X86::INC64r, X86::INC64m }, 110 { X86::INC8r, X86::INC8m }, 111 { X86::NEG16r, X86::NEG16m }, 112 { X86::NEG32r, X86::NEG32m }, 113 { X86::NEG64r, X86::NEG64m }, 114 { X86::NEG8r, X86::NEG8m }, 115 { X86::NOT16r, X86::NOT16m }, 116 { X86::NOT32r, X86::NOT32m }, 117 { X86::NOT64r, X86::NOT64m }, 118 { X86::NOT8r, X86::NOT8m }, 119 { X86::OR16ri, X86::OR16mi }, 120 { X86::OR16ri8, X86::OR16mi8 }, 121 { X86::OR16rr, X86::OR16mr }, 122 { X86::OR32ri, X86::OR32mi }, 123 { X86::OR32ri8, X86::OR32mi8 }, 124 { X86::OR32rr, X86::OR32mr }, 125 { X86::OR64ri32, X86::OR64mi32 }, 126 { X86::OR64ri8, X86::OR64mi8 }, 127 { X86::OR64rr, X86::OR64mr }, 128 { X86::OR8ri, X86::OR8mi }, 129 { X86::OR8rr, X86::OR8mr }, 130 { X86::ROL16r1, X86::ROL16m1 }, 131 { X86::ROL16rCL, X86::ROL16mCL }, 132 { X86::ROL16ri, X86::ROL16mi }, 133 { X86::ROL32r1, X86::ROL32m1 }, 134 { X86::ROL32rCL, X86::ROL32mCL }, 135 { X86::ROL32ri, X86::ROL32mi }, 136 { X86::ROL64r1, X86::ROL64m1 }, 137 { X86::ROL64rCL, X86::ROL64mCL }, 138 { X86::ROL64ri, X86::ROL64mi }, 139 { X86::ROL8r1, X86::ROL8m1 }, 140 { X86::ROL8rCL, X86::ROL8mCL }, 141 { X86::ROL8ri, X86::ROL8mi }, 142 { X86::ROR16r1, X86::ROR16m1 }, 143 { X86::ROR16rCL, X86::ROR16mCL }, 144 { X86::ROR16ri, X86::ROR16mi }, 145 { X86::ROR32r1, X86::ROR32m1 }, 146 { X86::ROR32rCL, X86::ROR32mCL }, 147 { X86::ROR32ri, X86::ROR32mi }, 148 { X86::ROR64r1, X86::ROR64m1 }, 149 { X86::ROR64rCL, X86::ROR64mCL }, 150 { X86::ROR64ri, X86::ROR64mi }, 151 { X86::ROR8r1, X86::ROR8m1 }, 152 { X86::ROR8rCL, X86::ROR8mCL }, 153 { X86::ROR8ri, X86::ROR8mi }, 154 { X86::SAR16r1, X86::SAR16m1 }, 155 { X86::SAR16rCL, X86::SAR16mCL }, 156 { X86::SAR16ri, X86::SAR16mi }, 157 { X86::SAR32r1, X86::SAR32m1 }, 158 { X86::SAR32rCL, X86::SAR32mCL }, 159 { X86::SAR32ri, X86::SAR32mi }, 160 { X86::SAR64r1, X86::SAR64m1 }, 161 { X86::SAR64rCL, X86::SAR64mCL }, 162 { X86::SAR64ri, X86::SAR64mi }, 163 { X86::SAR8r1, X86::SAR8m1 }, 164 { X86::SAR8rCL, X86::SAR8mCL }, 165 { X86::SAR8ri, X86::SAR8mi }, 166 { X86::SBB32ri, X86::SBB32mi }, 167 { X86::SBB32ri8, X86::SBB32mi8 }, 168 { X86::SBB32rr, X86::SBB32mr }, 169 { X86::SBB64ri32, X86::SBB64mi32 }, 170 { X86::SBB64ri8, X86::SBB64mi8 }, 171 { X86::SBB64rr, X86::SBB64mr }, 172 { X86::SHL16r1, X86::SHL16m1 }, 173 { X86::SHL16rCL, X86::SHL16mCL }, 174 { X86::SHL16ri, X86::SHL16mi }, 175 { X86::SHL32r1, X86::SHL32m1 }, 176 { X86::SHL32rCL, X86::SHL32mCL }, 177 { X86::SHL32ri, X86::SHL32mi }, 178 { X86::SHL64r1, X86::SHL64m1 }, 179 { X86::SHL64rCL, X86::SHL64mCL }, 180 { X86::SHL64ri, X86::SHL64mi }, 181 { X86::SHL8r1, X86::SHL8m1 }, 182 { X86::SHL8rCL, X86::SHL8mCL }, 183 { X86::SHL8ri, X86::SHL8mi }, 184 { X86::SHLD16rrCL, X86::SHLD16mrCL }, 185 { X86::SHLD16rri8, X86::SHLD16mri8 }, 186 { X86::SHLD32rrCL, X86::SHLD32mrCL }, 187 { X86::SHLD32rri8, X86::SHLD32mri8 }, 188 { X86::SHLD64rrCL, X86::SHLD64mrCL }, 189 { X86::SHLD64rri8, X86::SHLD64mri8 }, 190 { X86::SHR16r1, X86::SHR16m1 }, 191 { X86::SHR16rCL, X86::SHR16mCL }, 192 { X86::SHR16ri, X86::SHR16mi }, 193 { X86::SHR32r1, X86::SHR32m1 }, 194 { X86::SHR32rCL, X86::SHR32mCL }, 195 { X86::SHR32ri, X86::SHR32mi }, 196 { X86::SHR64r1, X86::SHR64m1 }, 197 { X86::SHR64rCL, X86::SHR64mCL }, 198 { X86::SHR64ri, X86::SHR64mi }, 199 { X86::SHR8r1, X86::SHR8m1 }, 200 { X86::SHR8rCL, X86::SHR8mCL }, 201 { X86::SHR8ri, X86::SHR8mi }, 202 { X86::SHRD16rrCL, X86::SHRD16mrCL }, 203 { X86::SHRD16rri8, X86::SHRD16mri8 }, 204 { X86::SHRD32rrCL, X86::SHRD32mrCL }, 205 { X86::SHRD32rri8, X86::SHRD32mri8 }, 206 { X86::SHRD64rrCL, X86::SHRD64mrCL }, 207 { X86::SHRD64rri8, X86::SHRD64mri8 }, 208 { X86::SUB16ri, X86::SUB16mi }, 209 { X86::SUB16ri8, X86::SUB16mi8 }, 210 { X86::SUB16rr, X86::SUB16mr }, 211 { X86::SUB32ri, X86::SUB32mi }, 212 { X86::SUB32ri8, X86::SUB32mi8 }, 213 { X86::SUB32rr, X86::SUB32mr }, 214 { X86::SUB64ri32, X86::SUB64mi32 }, 215 { X86::SUB64ri8, X86::SUB64mi8 }, 216 { X86::SUB64rr, X86::SUB64mr }, 217 { X86::SUB8ri, X86::SUB8mi }, 218 { X86::SUB8rr, X86::SUB8mr }, 219 { X86::XOR16ri, X86::XOR16mi }, 220 { X86::XOR16ri8, X86::XOR16mi8 }, 221 { X86::XOR16rr, X86::XOR16mr }, 222 { X86::XOR32ri, X86::XOR32mi }, 223 { X86::XOR32ri8, X86::XOR32mi8 }, 224 { X86::XOR32rr, X86::XOR32mr }, 225 { X86::XOR64ri32, X86::XOR64mi32 }, 226 { X86::XOR64ri8, X86::XOR64mi8 }, 227 { X86::XOR64rr, X86::XOR64mr }, 228 { X86::XOR8ri, X86::XOR8mi }, 229 { X86::XOR8rr, X86::XOR8mr } 230 }; 231 232 for (unsigned i = 0, e = array_lengthof(OpTbl2Addr); i != e; ++i) { 233 unsigned RegOp = OpTbl2Addr[i][0]; 234 unsigned MemOp = OpTbl2Addr[i][1]; 235 if (!RegOp2MemOpTable2Addr.insert(std::make_pair((unsigned*)RegOp, MemOp))) 236 assert(false && "Duplicated entries?"); 237 unsigned AuxInfo = 0 | (1 << 4) | (1 << 5); // Index 0,folded load and store 238 if (!MemOp2RegOpTable.insert(std::make_pair((unsigned*)MemOp, 239 std::make_pair(RegOp, AuxInfo)))) 240 AmbEntries.push_back(MemOp); 241 } 242 243 // If the third value is 1, then it's folding either a load or a store. 244 static const unsigned OpTbl0[][3] = { 245 { X86::CALL32r, X86::CALL32m, 1 }, 246 { X86::CALL64r, X86::CALL64m, 1 }, 247 { X86::CMP16ri, X86::CMP16mi, 1 }, 248 { X86::CMP16ri8, X86::CMP16mi8, 1 }, 249 { X86::CMP32ri, X86::CMP32mi, 1 }, 250 { X86::CMP32ri8, X86::CMP32mi8, 1 }, 251 { X86::CMP64ri32, X86::CMP64mi32, 1 }, 252 { X86::CMP64ri8, X86::CMP64mi8, 1 }, 253 { X86::CMP8ri, X86::CMP8mi, 1 }, 254 { X86::DIV16r, X86::DIV16m, 1 }, 255 { X86::DIV32r, X86::DIV32m, 1 }, 256 { X86::DIV64r, X86::DIV64m, 1 }, 257 { X86::DIV8r, X86::DIV8m, 1 }, 258 { X86::FsMOVAPDrr, X86::MOVSDmr, 0 }, 259 { X86::FsMOVAPSrr, X86::MOVSSmr, 0 }, 260 { X86::IDIV16r, X86::IDIV16m, 1 }, 261 { X86::IDIV32r, X86::IDIV32m, 1 }, 262 { X86::IDIV64r, X86::IDIV64m, 1 }, 263 { X86::IDIV8r, X86::IDIV8m, 1 }, 264 { X86::IMUL16r, X86::IMUL16m, 1 }, 265 { X86::IMUL32r, X86::IMUL32m, 1 }, 266 { X86::IMUL64r, X86::IMUL64m, 1 }, 267 { X86::IMUL8r, X86::IMUL8m, 1 }, 268 { X86::JMP32r, X86::JMP32m, 1 }, 269 { X86::JMP64r, X86::JMP64m, 1 }, 270 { X86::MOV16ri, X86::MOV16mi, 0 }, 271 { X86::MOV16rr, X86::MOV16mr, 0 }, 272 { X86::MOV16to16_, X86::MOV16_mr, 0 }, 273 { X86::MOV32ri, X86::MOV32mi, 0 }, 274 { X86::MOV32rr, X86::MOV32mr, 0 }, 275 { X86::MOV32to32_, X86::MOV32_mr, 0 }, 276 { X86::MOV64ri32, X86::MOV64mi32, 0 }, 277 { X86::MOV64rr, X86::MOV64mr, 0 }, 278 { X86::MOV8ri, X86::MOV8mi, 0 }, 279 { X86::MOV8rr, X86::MOV8mr, 0 }, 280 { X86::MOVAPDrr, X86::MOVAPDmr, 0 }, 281 { X86::MOVAPSrr, X86::MOVAPSmr, 0 }, 282 { X86::MOVPDI2DIrr, X86::MOVPDI2DImr, 0 }, 283 { X86::MOVPQIto64rr,X86::MOVPQI2QImr, 0 }, 284 { X86::MOVPS2SSrr, X86::MOVPS2SSmr, 0 }, 285 { X86::MOVSDrr, X86::MOVSDmr, 0 }, 286 { X86::MOVSDto64rr, X86::MOVSDto64mr, 0 }, 287 { X86::MOVSS2DIrr, X86::MOVSS2DImr, 0 }, 288 { X86::MOVSSrr, X86::MOVSSmr, 0 }, 289 { X86::MOVUPDrr, X86::MOVUPDmr, 0 }, 290 { X86::MOVUPSrr, X86::MOVUPSmr, 0 }, 291 { X86::MUL16r, X86::MUL16m, 1 }, 292 { X86::MUL32r, X86::MUL32m, 1 }, 293 { X86::MUL64r, X86::MUL64m, 1 }, 294 { X86::MUL8r, X86::MUL8m, 1 }, 295 { X86::SETAEr, X86::SETAEm, 0 }, 296 { X86::SETAr, X86::SETAm, 0 }, 297 { X86::SETBEr, X86::SETBEm, 0 }, 298 { X86::SETBr, X86::SETBm, 0 }, 299 { X86::SETEr, X86::SETEm, 0 }, 300 { X86::SETGEr, X86::SETGEm, 0 }, 301 { X86::SETGr, X86::SETGm, 0 }, 302 { X86::SETLEr, X86::SETLEm, 0 }, 303 { X86::SETLr, X86::SETLm, 0 }, 304 { X86::SETNEr, X86::SETNEm, 0 }, 305 { X86::SETNPr, X86::SETNPm, 0 }, 306 { X86::SETNSr, X86::SETNSm, 0 }, 307 { X86::SETPr, X86::SETPm, 0 }, 308 { X86::SETSr, X86::SETSm, 0 }, 309 { X86::TAILJMPr, X86::TAILJMPm, 1 }, 310 { X86::TEST16ri, X86::TEST16mi, 1 }, 311 { X86::TEST32ri, X86::TEST32mi, 1 }, 312 { X86::TEST64ri32, X86::TEST64mi32, 1 }, 313 { X86::TEST8ri, X86::TEST8mi, 1 }, 314 { X86::XCHG16rr, X86::XCHG16mr, 0 }, 315 { X86::XCHG32rr, X86::XCHG32mr, 0 }, 316 { X86::XCHG64rr, X86::XCHG64mr, 0 }, 317 { X86::XCHG8rr, X86::XCHG8mr, 0 } 318 }; 319 320 for (unsigned i = 0, e = array_lengthof(OpTbl0); i != e; ++i) { 321 unsigned RegOp = OpTbl0[i][0]; 322 unsigned MemOp = OpTbl0[i][1]; 323 if (!RegOp2MemOpTable0.insert(std::make_pair((unsigned*)RegOp, MemOp))) 324 assert(false && "Duplicated entries?"); 325 unsigned FoldedLoad = OpTbl0[i][2]; 326 // Index 0, folded load or store. 327 unsigned AuxInfo = 0 | (FoldedLoad << 4) | ((FoldedLoad^1) << 5); 328 if (RegOp != X86::FsMOVAPDrr && RegOp != X86::FsMOVAPSrr) 329 if (!MemOp2RegOpTable.insert(std::make_pair((unsigned*)MemOp, 330 std::make_pair(RegOp, AuxInfo)))) 331 AmbEntries.push_back(MemOp); 332 } 333 334 static const unsigned OpTbl1[][2] = { 335 { X86::CMP16rr, X86::CMP16rm }, 336 { X86::CMP32rr, X86::CMP32rm }, 337 { X86::CMP64rr, X86::CMP64rm }, 338 { X86::CMP8rr, X86::CMP8rm }, 339 { X86::CVTSD2SSrr, X86::CVTSD2SSrm }, 340 { X86::CVTSI2SD64rr, X86::CVTSI2SD64rm }, 341 { X86::CVTSI2SDrr, X86::CVTSI2SDrm }, 342 { X86::CVTSI2SS64rr, X86::CVTSI2SS64rm }, 343 { X86::CVTSI2SSrr, X86::CVTSI2SSrm }, 344 { X86::CVTSS2SDrr, X86::CVTSS2SDrm }, 345 { X86::CVTTSD2SI64rr, X86::CVTTSD2SI64rm }, 346 { X86::CVTTSD2SIrr, X86::CVTTSD2SIrm }, 347 { X86::CVTTSS2SI64rr, X86::CVTTSS2SI64rm }, 348 { X86::CVTTSS2SIrr, X86::CVTTSS2SIrm }, 349 { X86::FsMOVAPDrr, X86::MOVSDrm }, 350 { X86::FsMOVAPSrr, X86::MOVSSrm }, 351 { X86::IMUL16rri, X86::IMUL16rmi }, 352 { X86::IMUL16rri8, X86::IMUL16rmi8 }, 353 { X86::IMUL32rri, X86::IMUL32rmi }, 354 { X86::IMUL32rri8, X86::IMUL32rmi8 }, 355 { X86::IMUL64rri32, X86::IMUL64rmi32 }, 356 { X86::IMUL64rri8, X86::IMUL64rmi8 }, 357 { X86::Int_CMPSDrr, X86::Int_CMPSDrm }, 358 { X86::Int_CMPSSrr, X86::Int_CMPSSrm }, 359 { X86::Int_COMISDrr, X86::Int_COMISDrm }, 360 { X86::Int_COMISSrr, X86::Int_COMISSrm }, 361 { X86::Int_CVTDQ2PDrr, X86::Int_CVTDQ2PDrm }, 362 { X86::Int_CVTDQ2PSrr, X86::Int_CVTDQ2PSrm }, 363 { X86::Int_CVTPD2DQrr, X86::Int_CVTPD2DQrm }, 364 { X86::Int_CVTPD2PSrr, X86::Int_CVTPD2PSrm }, 365 { X86::Int_CVTPS2DQrr, X86::Int_CVTPS2DQrm }, 366 { X86::Int_CVTPS2PDrr, X86::Int_CVTPS2PDrm }, 367 { X86::Int_CVTSD2SI64rr,X86::Int_CVTSD2SI64rm }, 368 { X86::Int_CVTSD2SIrr, X86::Int_CVTSD2SIrm }, 369 { X86::Int_CVTSD2SSrr, X86::Int_CVTSD2SSrm }, 370 { X86::Int_CVTSI2SD64rr,X86::Int_CVTSI2SD64rm }, 371 { X86::Int_CVTSI2SDrr, X86::Int_CVTSI2SDrm }, 372 { X86::Int_CVTSI2SS64rr,X86::Int_CVTSI2SS64rm }, 373 { X86::Int_CVTSI2SSrr, X86::Int_CVTSI2SSrm }, 374 { X86::Int_CVTSS2SDrr, X86::Int_CVTSS2SDrm }, 375 { X86::Int_CVTSS2SI64rr,X86::Int_CVTSS2SI64rm }, 376 { X86::Int_CVTSS2SIrr, X86::Int_CVTSS2SIrm }, 377 { X86::Int_CVTTPD2DQrr, X86::Int_CVTTPD2DQrm }, 378 { X86::Int_CVTTPS2DQrr, X86::Int_CVTTPS2DQrm }, 379 { X86::Int_CVTTSD2SI64rr,X86::Int_CVTTSD2SI64rm }, 380 { X86::Int_CVTTSD2SIrr, X86::Int_CVTTSD2SIrm }, 381 { X86::Int_CVTTSS2SI64rr,X86::Int_CVTTSS2SI64rm }, 382 { X86::Int_CVTTSS2SIrr, X86::Int_CVTTSS2SIrm }, 383 { X86::Int_UCOMISDrr, X86::Int_UCOMISDrm }, 384 { X86::Int_UCOMISSrr, X86::Int_UCOMISSrm }, 385 { X86::MOV16rr, X86::MOV16rm }, 386 { X86::MOV16to16_, X86::MOV16_rm }, 387 { X86::MOV32rr, X86::MOV32rm }, 388 { X86::MOV32to32_, X86::MOV32_rm }, 389 { X86::MOV64rr, X86::MOV64rm }, 390 { X86::MOV64toPQIrr, X86::MOVQI2PQIrm }, 391 { X86::MOV64toSDrr, X86::MOV64toSDrm }, 392 { X86::MOV8rr, X86::MOV8rm }, 393 { X86::MOVAPDrr, X86::MOVAPDrm }, 394 { X86::MOVAPSrr, X86::MOVAPSrm }, 395 { X86::MOVDDUPrr, X86::MOVDDUPrm }, 396 { X86::MOVDI2PDIrr, X86::MOVDI2PDIrm }, 397 { X86::MOVDI2SSrr, X86::MOVDI2SSrm }, 398 { X86::MOVSD2PDrr, X86::MOVSD2PDrm }, 399 { X86::MOVSDrr, X86::MOVSDrm }, 400 { X86::MOVSHDUPrr, X86::MOVSHDUPrm }, 401 { X86::MOVSLDUPrr, X86::MOVSLDUPrm }, 402 { X86::MOVSS2PSrr, X86::MOVSS2PSrm }, 403 { X86::MOVSSrr, X86::MOVSSrm }, 404 { X86::MOVSX16rr8, X86::MOVSX16rm8 }, 405 { X86::MOVSX32rr16, X86::MOVSX32rm16 }, 406 { X86::MOVSX32rr8, X86::MOVSX32rm8 }, 407 { X86::MOVSX64rr16, X86::MOVSX64rm16 }, 408 { X86::MOVSX64rr32, X86::MOVSX64rm32 }, 409 { X86::MOVSX64rr8, X86::MOVSX64rm8 }, 410 { X86::MOVUPDrr, X86::MOVUPDrm }, 411 { X86::MOVUPSrr, X86::MOVUPSrm }, 412 { X86::MOVZDI2PDIrr, X86::MOVZDI2PDIrm }, 413 { X86::MOVZQI2PQIrr, X86::MOVZQI2PQIrm }, 414 { X86::MOVZPQILo2PQIrr, X86::MOVZPQILo2PQIrm }, 415 { X86::MOVZX16rr8, X86::MOVZX16rm8 }, 416 { X86::MOVZX32rr16, X86::MOVZX32rm16 }, 417 { X86::MOVZX32rr8, X86::MOVZX32rm8 }, 418 { X86::MOVZX64rr16, X86::MOVZX64rm16 }, 419 { X86::MOVZX64rr8, X86::MOVZX64rm8 }, 420 { X86::PSHUFDri, X86::PSHUFDmi }, 421 { X86::PSHUFHWri, X86::PSHUFHWmi }, 422 { X86::PSHUFLWri, X86::PSHUFLWmi }, 423 { X86::PsMOVZX64rr32, X86::PsMOVZX64rm32 }, 424 { X86::RCPPSr, X86::RCPPSm }, 425 { X86::RCPPSr_Int, X86::RCPPSm_Int }, 426 { X86::RSQRTPSr, X86::RSQRTPSm }, 427 { X86::RSQRTPSr_Int, X86::RSQRTPSm_Int }, 428 { X86::RSQRTSSr, X86::RSQRTSSm }, 429 { X86::RSQRTSSr_Int, X86::RSQRTSSm_Int }, 430 { X86::SQRTPDr, X86::SQRTPDm }, 431 { X86::SQRTPDr_Int, X86::SQRTPDm_Int }, 432 { X86::SQRTPSr, X86::SQRTPSm }, 433 { X86::SQRTPSr_Int, X86::SQRTPSm_Int }, 434 { X86::SQRTSDr, X86::SQRTSDm }, 435 { X86::SQRTSDr_Int, X86::SQRTSDm_Int }, 436 { X86::SQRTSSr, X86::SQRTSSm }, 437 { X86::SQRTSSr_Int, X86::SQRTSSm_Int }, 438 { X86::TEST16rr, X86::TEST16rm }, 439 { X86::TEST32rr, X86::TEST32rm }, 440 { X86::TEST64rr, X86::TEST64rm }, 441 { X86::TEST8rr, X86::TEST8rm }, 442 // FIXME: TEST*rr EAX,EAX ---> CMP [mem], 0 443 { X86::UCOMISDrr, X86::UCOMISDrm }, 444 { X86::UCOMISSrr, X86::UCOMISSrm }, 445 { X86::XCHG16rr, X86::XCHG16rm }, 446 { X86::XCHG32rr, X86::XCHG32rm }, 447 { X86::XCHG64rr, X86::XCHG64rm }, 448 { X86::XCHG8rr, X86::XCHG8rm } 449 }; 450 451 for (unsigned i = 0, e = array_lengthof(OpTbl1); i != e; ++i) { 452 unsigned RegOp = OpTbl1[i][0]; 453 unsigned MemOp = OpTbl1[i][1]; 454 if (!RegOp2MemOpTable1.insert(std::make_pair((unsigned*)RegOp, MemOp))) 455 assert(false && "Duplicated entries?"); 456 unsigned AuxInfo = 1 | (1 << 4); // Index 1, folded load 457 if (RegOp != X86::FsMOVAPDrr && RegOp != X86::FsMOVAPSrr) 458 if (!MemOp2RegOpTable.insert(std::make_pair((unsigned*)MemOp, 459 std::make_pair(RegOp, AuxInfo)))) 460 AmbEntries.push_back(MemOp); 461 } 462 463 static const unsigned OpTbl2[][2] = { 464 { X86::ADC32rr, X86::ADC32rm }, 465 { X86::ADC64rr, X86::ADC64rm }, 466 { X86::ADD16rr, X86::ADD16rm }, 467 { X86::ADD32rr, X86::ADD32rm }, 468 { X86::ADD64rr, X86::ADD64rm }, 469 { X86::ADD8rr, X86::ADD8rm }, 470 { X86::ADDPDrr, X86::ADDPDrm }, 471 { X86::ADDPSrr, X86::ADDPSrm }, 472 { X86::ADDSDrr, X86::ADDSDrm }, 473 { X86::ADDSSrr, X86::ADDSSrm }, 474 { X86::ADDSUBPDrr, X86::ADDSUBPDrm }, 475 { X86::ADDSUBPSrr, X86::ADDSUBPSrm }, 476 { X86::AND16rr, X86::AND16rm }, 477 { X86::AND32rr, X86::AND32rm }, 478 { X86::AND64rr, X86::AND64rm }, 479 { X86::AND8rr, X86::AND8rm }, 480 { X86::ANDNPDrr, X86::ANDNPDrm }, 481 { X86::ANDNPSrr, X86::ANDNPSrm }, 482 { X86::ANDPDrr, X86::ANDPDrm }, 483 { X86::ANDPSrr, X86::ANDPSrm }, 484 { X86::CMOVA16rr, X86::CMOVA16rm }, 485 { X86::CMOVA32rr, X86::CMOVA32rm }, 486 { X86::CMOVA64rr, X86::CMOVA64rm }, 487 { X86::CMOVAE16rr, X86::CMOVAE16rm }, 488 { X86::CMOVAE32rr, X86::CMOVAE32rm }, 489 { X86::CMOVAE64rr, X86::CMOVAE64rm }, 490 { X86::CMOVB16rr, X86::CMOVB16rm }, 491 { X86::CMOVB32rr, X86::CMOVB32rm }, 492 { X86::CMOVB64rr, X86::CMOVB64rm }, 493 { X86::CMOVBE16rr, X86::CMOVBE16rm }, 494 { X86::CMOVBE32rr, X86::CMOVBE32rm }, 495 { X86::CMOVBE64rr, X86::CMOVBE64rm }, 496 { X86::CMOVE16rr, X86::CMOVE16rm }, 497 { X86::CMOVE32rr, X86::CMOVE32rm }, 498 { X86::CMOVE64rr, X86::CMOVE64rm }, 499 { X86::CMOVG16rr, X86::CMOVG16rm }, 500 { X86::CMOVG32rr, X86::CMOVG32rm }, 501 { X86::CMOVG64rr, X86::CMOVG64rm }, 502 { X86::CMOVGE16rr, X86::CMOVGE16rm }, 503 { X86::CMOVGE32rr, X86::CMOVGE32rm }, 504 { X86::CMOVGE64rr, X86::CMOVGE64rm }, 505 { X86::CMOVL16rr, X86::CMOVL16rm }, 506 { X86::CMOVL32rr, X86::CMOVL32rm }, 507 { X86::CMOVL64rr, X86::CMOVL64rm }, 508 { X86::CMOVLE16rr, X86::CMOVLE16rm }, 509 { X86::CMOVLE32rr, X86::CMOVLE32rm }, 510 { X86::CMOVLE64rr, X86::CMOVLE64rm }, 511 { X86::CMOVNE16rr, X86::CMOVNE16rm }, 512 { X86::CMOVNE32rr, X86::CMOVNE32rm }, 513 { X86::CMOVNE64rr, X86::CMOVNE64rm }, 514 { X86::CMOVNP16rr, X86::CMOVNP16rm }, 515 { X86::CMOVNP32rr, X86::CMOVNP32rm }, 516 { X86::CMOVNP64rr, X86::CMOVNP64rm }, 517 { X86::CMOVNS16rr, X86::CMOVNS16rm }, 518 { X86::CMOVNS32rr, X86::CMOVNS32rm }, 519 { X86::CMOVNS64rr, X86::CMOVNS64rm }, 520 { X86::CMOVP16rr, X86::CMOVP16rm }, 521 { X86::CMOVP32rr, X86::CMOVP32rm }, 522 { X86::CMOVP64rr, X86::CMOVP64rm }, 523 { X86::CMOVS16rr, X86::CMOVS16rm }, 524 { X86::CMOVS32rr, X86::CMOVS32rm }, 525 { X86::CMOVS64rr, X86::CMOVS64rm }, 526 { X86::CMPPDrri, X86::CMPPDrmi }, 527 { X86::CMPPSrri, X86::CMPPSrmi }, 528 { X86::CMPSDrr, X86::CMPSDrm }, 529 { X86::CMPSSrr, X86::CMPSSrm }, 530 { X86::DIVPDrr, X86::DIVPDrm }, 531 { X86::DIVPSrr, X86::DIVPSrm }, 532 { X86::DIVSDrr, X86::DIVSDrm }, 533 { X86::DIVSSrr, X86::DIVSSrm }, 534 { X86::HADDPDrr, X86::HADDPDrm }, 535 { X86::HADDPSrr, X86::HADDPSrm }, 536 { X86::HSUBPDrr, X86::HSUBPDrm }, 537 { X86::HSUBPSrr, X86::HSUBPSrm }, 538 { X86::IMUL16rr, X86::IMUL16rm }, 539 { X86::IMUL32rr, X86::IMUL32rm }, 540 { X86::IMUL64rr, X86::IMUL64rm }, 541 { X86::MAXPDrr, X86::MAXPDrm }, 542 { X86::MAXPDrr_Int, X86::MAXPDrm_Int }, 543 { X86::MAXPSrr, X86::MAXPSrm }, 544 { X86::MAXPSrr_Int, X86::MAXPSrm_Int }, 545 { X86::MAXSDrr, X86::MAXSDrm }, 546 { X86::MAXSDrr_Int, X86::MAXSDrm_Int }, 547 { X86::MAXSSrr, X86::MAXSSrm }, 548 { X86::MAXSSrr_Int, X86::MAXSSrm_Int }, 549 { X86::MINPDrr, X86::MINPDrm }, 550 { X86::MINPDrr_Int, X86::MINPDrm_Int }, 551 { X86::MINPSrr, X86::MINPSrm }, 552 { X86::MINPSrr_Int, X86::MINPSrm_Int }, 553 { X86::MINSDrr, X86::MINSDrm }, 554 { X86::MINSDrr_Int, X86::MINSDrm_Int }, 555 { X86::MINSSrr, X86::MINSSrm }, 556 { X86::MINSSrr_Int, X86::MINSSrm_Int }, 557 { X86::MULPDrr, X86::MULPDrm }, 558 { X86::MULPSrr, X86::MULPSrm }, 559 { X86::MULSDrr, X86::MULSDrm }, 560 { X86::MULSSrr, X86::MULSSrm }, 561 { X86::OR16rr, X86::OR16rm }, 562 { X86::OR32rr, X86::OR32rm }, 563 { X86::OR64rr, X86::OR64rm }, 564 { X86::OR8rr, X86::OR8rm }, 565 { X86::ORPDrr, X86::ORPDrm }, 566 { X86::ORPSrr, X86::ORPSrm }, 567 { X86::PACKSSDWrr, X86::PACKSSDWrm }, 568 { X86::PACKSSWBrr, X86::PACKSSWBrm }, 569 { X86::PACKUSWBrr, X86::PACKUSWBrm }, 570 { X86::PADDBrr, X86::PADDBrm }, 571 { X86::PADDDrr, X86::PADDDrm }, 572 { X86::PADDQrr, X86::PADDQrm }, 573 { X86::PADDSBrr, X86::PADDSBrm }, 574 { X86::PADDSWrr, X86::PADDSWrm }, 575 { X86::PADDWrr, X86::PADDWrm }, 576 { X86::PANDNrr, X86::PANDNrm }, 577 { X86::PANDrr, X86::PANDrm }, 578 { X86::PAVGBrr, X86::PAVGBrm }, 579 { X86::PAVGWrr, X86::PAVGWrm }, 580 { X86::PCMPEQBrr, X86::PCMPEQBrm }, 581 { X86::PCMPEQDrr, X86::PCMPEQDrm }, 582 { X86::PCMPEQWrr, X86::PCMPEQWrm }, 583 { X86::PCMPGTBrr, X86::PCMPGTBrm }, 584 { X86::PCMPGTDrr, X86::PCMPGTDrm }, 585 { X86::PCMPGTWrr, X86::PCMPGTWrm }, 586 { X86::PINSRWrri, X86::PINSRWrmi }, 587 { X86::PMADDWDrr, X86::PMADDWDrm }, 588 { X86::PMAXSWrr, X86::PMAXSWrm }, 589 { X86::PMAXUBrr, X86::PMAXUBrm }, 590 { X86::PMINSWrr, X86::PMINSWrm }, 591 { X86::PMINUBrr, X86::PMINUBrm }, 592 { X86::PMULHUWrr, X86::PMULHUWrm }, 593 { X86::PMULHWrr, X86::PMULHWrm }, 594 { X86::PMULLWrr, X86::PMULLWrm }, 595 { X86::PMULUDQrr, X86::PMULUDQrm }, 596 { X86::PORrr, X86::PORrm }, 597 { X86::PSADBWrr, X86::PSADBWrm }, 598 { X86::PSLLDrr, X86::PSLLDrm }, 599 { X86::PSLLQrr, X86::PSLLQrm }, 600 { X86::PSLLWrr, X86::PSLLWrm }, 601 { X86::PSRADrr, X86::PSRADrm }, 602 { X86::PSRAWrr, X86::PSRAWrm }, 603 { X86::PSRLDrr, X86::PSRLDrm }, 604 { X86::PSRLQrr, X86::PSRLQrm }, 605 { X86::PSRLWrr, X86::PSRLWrm }, 606 { X86::PSUBBrr, X86::PSUBBrm }, 607 { X86::PSUBDrr, X86::PSUBDrm }, 608 { X86::PSUBSBrr, X86::PSUBSBrm }, 609 { X86::PSUBSWrr, X86::PSUBSWrm }, 610 { X86::PSUBWrr, X86::PSUBWrm }, 611 { X86::PUNPCKHBWrr, X86::PUNPCKHBWrm }, 612 { X86::PUNPCKHDQrr, X86::PUNPCKHDQrm }, 613 { X86::PUNPCKHQDQrr, X86::PUNPCKHQDQrm }, 614 { X86::PUNPCKHWDrr, X86::PUNPCKHWDrm }, 615 { X86::PUNPCKLBWrr, X86::PUNPCKLBWrm }, 616 { X86::PUNPCKLDQrr, X86::PUNPCKLDQrm }, 617 { X86::PUNPCKLQDQrr, X86::PUNPCKLQDQrm }, 618 { X86::PUNPCKLWDrr, X86::PUNPCKLWDrm }, 619 { X86::PXORrr, X86::PXORrm }, 620 { X86::SBB32rr, X86::SBB32rm }, 621 { X86::SBB64rr, X86::SBB64rm }, 622 { X86::SHUFPDrri, X86::SHUFPDrmi }, 623 { X86::SHUFPSrri, X86::SHUFPSrmi }, 624 { X86::SUB16rr, X86::SUB16rm }, 625 { X86::SUB32rr, X86::SUB32rm }, 626 { X86::SUB64rr, X86::SUB64rm }, 627 { X86::SUB8rr, X86::SUB8rm }, 628 { X86::SUBPDrr, X86::SUBPDrm }, 629 { X86::SUBPSrr, X86::SUBPSrm }, 630 { X86::SUBSDrr, X86::SUBSDrm }, 631 { X86::SUBSSrr, X86::SUBSSrm }, 632 // FIXME: TEST*rr -> swapped operand of TEST*mr. 633 { X86::UNPCKHPDrr, X86::UNPCKHPDrm }, 634 { X86::UNPCKHPSrr, X86::UNPCKHPSrm }, 635 { X86::UNPCKLPDrr, X86::UNPCKLPDrm }, 636 { X86::UNPCKLPSrr, X86::UNPCKLPSrm }, 637 { X86::XOR16rr, X86::XOR16rm }, 638 { X86::XOR32rr, X86::XOR32rm }, 639 { X86::XOR64rr, X86::XOR64rm }, 640 { X86::XOR8rr, X86::XOR8rm }, 641 { X86::XORPDrr, X86::XORPDrm }, 642 { X86::XORPSrr, X86::XORPSrm } 643 }; 644 645 for (unsigned i = 0, e = array_lengthof(OpTbl2); i != e; ++i) { 646 unsigned RegOp = OpTbl2[i][0]; 647 unsigned MemOp = OpTbl2[i][1]; 648 if (!RegOp2MemOpTable2.insert(std::make_pair((unsigned*)RegOp, MemOp))) 649 assert(false && "Duplicated entries?"); 650 unsigned AuxInfo = 2 | (1 << 4); // Index 1, folded load 651 if (!MemOp2RegOpTable.insert(std::make_pair((unsigned*)MemOp, 652 std::make_pair(RegOp, AuxInfo)))) 653 AmbEntries.push_back(MemOp); 654 } 655 656 // Remove ambiguous entries. 657 assert(AmbEntries.empty() && "Duplicated entries in unfolding maps?"); 658} 659 660// getDwarfRegNum - This function maps LLVM register identifiers to the 661// Dwarf specific numbering, used in debug info and exception tables. 662 663int X86RegisterInfo::getDwarfRegNum(unsigned RegNo, bool isEH) const { 664 const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>(); 665 unsigned Flavour = DWARFFlavour::X86_64; 666 if (!Subtarget->is64Bit()) { 667 if (Subtarget->isTargetDarwin()) { 668 Flavour = DWARFFlavour::X86_32_Darwin; 669 } else if (Subtarget->isTargetCygMing()) { 670 // Unsupported by now, just quick fallback 671 Flavour = DWARFFlavour::X86_32_ELF; 672 } else { 673 Flavour = DWARFFlavour::X86_32_ELF; 674 } 675 } 676 677 return X86GenRegisterInfo::getDwarfRegNumFull(RegNo, Flavour); 678} 679 680// getX86RegNum - This function maps LLVM register identifiers to their X86 681// specific numbering, which is used in various places encoding instructions. 682// 683unsigned X86RegisterInfo::getX86RegNum(unsigned RegNo) { 684 switch(RegNo) { 685 case X86::RAX: case X86::EAX: case X86::AX: case X86::AL: return N86::EAX; 686 case X86::RCX: case X86::ECX: case X86::CX: case X86::CL: return N86::ECX; 687 case X86::RDX: case X86::EDX: case X86::DX: case X86::DL: return N86::EDX; 688 case X86::RBX: case X86::EBX: case X86::BX: case X86::BL: return N86::EBX; 689 case X86::RSP: case X86::ESP: case X86::SP: case X86::SPL: case X86::AH: 690 return N86::ESP; 691 case X86::RBP: case X86::EBP: case X86::BP: case X86::BPL: case X86::CH: 692 return N86::EBP; 693 case X86::RSI: case X86::ESI: case X86::SI: case X86::SIL: case X86::DH: 694 return N86::ESI; 695 case X86::RDI: case X86::EDI: case X86::DI: case X86::DIL: case X86::BH: 696 return N86::EDI; 697 698 case X86::R8: case X86::R8D: case X86::R8W: case X86::R8B: 699 return N86::EAX; 700 case X86::R9: case X86::R9D: case X86::R9W: case X86::R9B: 701 return N86::ECX; 702 case X86::R10: case X86::R10D: case X86::R10W: case X86::R10B: 703 return N86::EDX; 704 case X86::R11: case X86::R11D: case X86::R11W: case X86::R11B: 705 return N86::EBX; 706 case X86::R12: case X86::R12D: case X86::R12W: case X86::R12B: 707 return N86::ESP; 708 case X86::R13: case X86::R13D: case X86::R13W: case X86::R13B: 709 return N86::EBP; 710 case X86::R14: case X86::R14D: case X86::R14W: case X86::R14B: 711 return N86::ESI; 712 case X86::R15: case X86::R15D: case X86::R15W: case X86::R15B: 713 return N86::EDI; 714 715 case X86::ST0: case X86::ST1: case X86::ST2: case X86::ST3: 716 case X86::ST4: case X86::ST5: case X86::ST6: case X86::ST7: 717 return RegNo-X86::ST0; 718 719 case X86::XMM0: case X86::XMM8: case X86::MM0: 720 return 0; 721 case X86::XMM1: case X86::XMM9: case X86::MM1: 722 return 1; 723 case X86::XMM2: case X86::XMM10: case X86::MM2: 724 return 2; 725 case X86::XMM3: case X86::XMM11: case X86::MM3: 726 return 3; 727 case X86::XMM4: case X86::XMM12: case X86::MM4: 728 return 4; 729 case X86::XMM5: case X86::XMM13: case X86::MM5: 730 return 5; 731 case X86::XMM6: case X86::XMM14: case X86::MM6: 732 return 6; 733 case X86::XMM7: case X86::XMM15: case X86::MM7: 734 return 7; 735 736 default: 737 assert(isVirtualRegister(RegNo) && "Unknown physical register!"); 738 assert(0 && "Register allocator hasn't allocated reg correctly yet!"); 739 return 0; 740 } 741} 742 743bool X86RegisterInfo::spillCalleeSavedRegisters(MachineBasicBlock &MBB, 744 MachineBasicBlock::iterator MI, 745 const std::vector<CalleeSavedInfo> &CSI) const { 746 if (CSI.empty()) 747 return false; 748 749 MachineFunction &MF = *MBB.getParent(); 750 X86MachineFunctionInfo *X86FI = MF.getInfo<X86MachineFunctionInfo>(); 751 X86FI->setCalleeSavedFrameSize(CSI.size() * SlotSize); 752 unsigned Opc = Is64Bit ? X86::PUSH64r : X86::PUSH32r; 753 for (unsigned i = CSI.size(); i != 0; --i) { 754 unsigned Reg = CSI[i-1].getReg(); 755 // Add the callee-saved register as live-in. It's killed at the spill. 756 MBB.addLiveIn(Reg); 757 BuildMI(MBB, MI, TII.get(Opc)).addReg(Reg); 758 } 759 return true; 760} 761 762bool X86RegisterInfo::restoreCalleeSavedRegisters(MachineBasicBlock &MBB, 763 MachineBasicBlock::iterator MI, 764 const std::vector<CalleeSavedInfo> &CSI) const { 765 if (CSI.empty()) 766 return false; 767 768 unsigned Opc = Is64Bit ? X86::POP64r : X86::POP32r; 769 for (unsigned i = 0, e = CSI.size(); i != e; ++i) { 770 unsigned Reg = CSI[i].getReg(); 771 BuildMI(MBB, MI, TII.get(Opc), Reg); 772 } 773 return true; 774} 775 776static const MachineInstrBuilder &X86InstrAddOperand(MachineInstrBuilder &MIB, 777 MachineOperand &MO) { 778 if (MO.isRegister()) 779 MIB = MIB.addReg(MO.getReg(), MO.isDef(), MO.isImplicit(), 780 false, false, MO.getSubReg()); 781 else if (MO.isImmediate()) 782 MIB = MIB.addImm(MO.getImm()); 783 else if (MO.isFrameIndex()) 784 MIB = MIB.addFrameIndex(MO.getFrameIndex()); 785 else if (MO.isGlobalAddress()) 786 MIB = MIB.addGlobalAddress(MO.getGlobal(), MO.getOffset()); 787 else if (MO.isConstantPoolIndex()) 788 MIB = MIB.addConstantPoolIndex(MO.getConstantPoolIndex(), MO.getOffset()); 789 else if (MO.isJumpTableIndex()) 790 MIB = MIB.addJumpTableIndex(MO.getJumpTableIndex()); 791 else if (MO.isExternalSymbol()) 792 MIB = MIB.addExternalSymbol(MO.getSymbolName()); 793 else 794 assert(0 && "Unknown operand for X86InstrAddOperand!"); 795 796 return MIB; 797} 798 799static unsigned getStoreRegOpcode(const TargetRegisterClass *RC, 800 unsigned StackAlign) { 801 unsigned Opc = 0; 802 if (RC == &X86::GR64RegClass) { 803 Opc = X86::MOV64mr; 804 } else if (RC == &X86::GR32RegClass) { 805 Opc = X86::MOV32mr; 806 } else if (RC == &X86::GR16RegClass) { 807 Opc = X86::MOV16mr; 808 } else if (RC == &X86::GR8RegClass) { 809 Opc = X86::MOV8mr; 810 } else if (RC == &X86::GR32_RegClass) { 811 Opc = X86::MOV32_mr; 812 } else if (RC == &X86::GR16_RegClass) { 813 Opc = X86::MOV16_mr; 814 } else if (RC == &X86::RFP80RegClass) { 815 Opc = X86::ST_FpP80m; // pops 816 } else if (RC == &X86::RFP64RegClass) { 817 Opc = X86::ST_Fp64m; 818 } else if (RC == &X86::RFP32RegClass) { 819 Opc = X86::ST_Fp32m; 820 } else if (RC == &X86::FR32RegClass) { 821 Opc = X86::MOVSSmr; 822 } else if (RC == &X86::FR64RegClass) { 823 Opc = X86::MOVSDmr; 824 } else if (RC == &X86::VR128RegClass) { 825 // FIXME: Use movaps once we are capable of selectively 826 // aligning functions that spill SSE registers on 16-byte boundaries. 827 Opc = StackAlign >= 16 ? X86::MOVAPSmr : X86::MOVUPSmr; 828 } else if (RC == &X86::VR64RegClass) { 829 Opc = X86::MMX_MOVQ64mr; 830 } else { 831 assert(0 && "Unknown regclass"); 832 abort(); 833 } 834 835 return Opc; 836} 837 838void X86RegisterInfo::storeRegToStackSlot(MachineBasicBlock &MBB, 839 MachineBasicBlock::iterator MI, 840 unsigned SrcReg, bool isKill, int FrameIdx, 841 const TargetRegisterClass *RC) const { 842 unsigned Opc = getStoreRegOpcode(RC, StackAlign); 843 addFrameReference(BuildMI(MBB, MI, TII.get(Opc)), FrameIdx) 844 .addReg(SrcReg, false, false, isKill); 845} 846 847void X86RegisterInfo::storeRegToAddr(MachineFunction &MF, unsigned SrcReg, 848 bool isKill, 849 SmallVectorImpl<MachineOperand> &Addr, 850 const TargetRegisterClass *RC, 851 SmallVectorImpl<MachineInstr*> &NewMIs) const { 852 unsigned Opc = getStoreRegOpcode(RC, StackAlign); 853 MachineInstrBuilder MIB = BuildMI(TII.get(Opc)); 854 for (unsigned i = 0, e = Addr.size(); i != e; ++i) 855 MIB = X86InstrAddOperand(MIB, Addr[i]); 856 MIB.addReg(SrcReg, false, false, isKill); 857 NewMIs.push_back(MIB); 858} 859 860static unsigned getLoadRegOpcode(const TargetRegisterClass *RC, 861 unsigned StackAlign) { 862 unsigned Opc = 0; 863 if (RC == &X86::GR64RegClass) { 864 Opc = X86::MOV64rm; 865 } else if (RC == &X86::GR32RegClass) { 866 Opc = X86::MOV32rm; 867 } else if (RC == &X86::GR16RegClass) { 868 Opc = X86::MOV16rm; 869 } else if (RC == &X86::GR8RegClass) { 870 Opc = X86::MOV8rm; 871 } else if (RC == &X86::GR32_RegClass) { 872 Opc = X86::MOV32_rm; 873 } else if (RC == &X86::GR16_RegClass) { 874 Opc = X86::MOV16_rm; 875 } else if (RC == &X86::RFP80RegClass) { 876 Opc = X86::LD_Fp80m; 877 } else if (RC == &X86::RFP64RegClass) { 878 Opc = X86::LD_Fp64m; 879 } else if (RC == &X86::RFP32RegClass) { 880 Opc = X86::LD_Fp32m; 881 } else if (RC == &X86::FR32RegClass) { 882 Opc = X86::MOVSSrm; 883 } else if (RC == &X86::FR64RegClass) { 884 Opc = X86::MOVSDrm; 885 } else if (RC == &X86::VR128RegClass) { 886 // FIXME: Use movaps once we are capable of selectively 887 // aligning functions that spill SSE registers on 16-byte boundaries. 888 Opc = StackAlign >= 16 ? X86::MOVAPSrm : X86::MOVUPSrm; 889 } else if (RC == &X86::VR64RegClass) { 890 Opc = X86::MMX_MOVQ64rm; 891 } else { 892 assert(0 && "Unknown regclass"); 893 abort(); 894 } 895 896 return Opc; 897} 898 899void X86RegisterInfo::loadRegFromStackSlot(MachineBasicBlock &MBB, 900 MachineBasicBlock::iterator MI, 901 unsigned DestReg, int FrameIdx, 902 const TargetRegisterClass *RC) const{ 903 unsigned Opc = getLoadRegOpcode(RC, StackAlign); 904 addFrameReference(BuildMI(MBB, MI, TII.get(Opc), DestReg), FrameIdx); 905} 906 907void X86RegisterInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg, 908 SmallVectorImpl<MachineOperand> &Addr, 909 const TargetRegisterClass *RC, 910 SmallVectorImpl<MachineInstr*> &NewMIs) const { 911 unsigned Opc = getLoadRegOpcode(RC, StackAlign); 912 MachineInstrBuilder MIB = BuildMI(TII.get(Opc), DestReg); 913 for (unsigned i = 0, e = Addr.size(); i != e; ++i) 914 MIB = X86InstrAddOperand(MIB, Addr[i]); 915 NewMIs.push_back(MIB); 916} 917 918void X86RegisterInfo::copyRegToReg(MachineBasicBlock &MBB, 919 MachineBasicBlock::iterator MI, 920 unsigned DestReg, unsigned SrcReg, 921 const TargetRegisterClass *DestRC, 922 const TargetRegisterClass *SrcRC) const { 923 if (DestRC != SrcRC) { 924 // Moving EFLAGS to / from another register requires a push and a pop. 925 if (SrcRC == &X86::CCRRegClass) { 926 assert(SrcReg == X86::EFLAGS); 927 if (DestRC == &X86::GR64RegClass) { 928 BuildMI(MBB, MI, TII.get(X86::PUSHFQ)); 929 BuildMI(MBB, MI, TII.get(X86::POP64r), DestReg); 930 return; 931 } else if (DestRC == &X86::GR32RegClass) { 932 BuildMI(MBB, MI, TII.get(X86::PUSHFD)); 933 BuildMI(MBB, MI, TII.get(X86::POP32r), DestReg); 934 return; 935 } 936 } else if (DestRC == &X86::CCRRegClass) { 937 assert(DestReg == X86::EFLAGS); 938 if (SrcRC == &X86::GR64RegClass) { 939 BuildMI(MBB, MI, TII.get(X86::PUSH64r)).addReg(SrcReg); 940 BuildMI(MBB, MI, TII.get(X86::POPFQ)); 941 return; 942 } else if (SrcRC == &X86::GR32RegClass) { 943 BuildMI(MBB, MI, TII.get(X86::PUSH32r)).addReg(SrcReg); 944 BuildMI(MBB, MI, TII.get(X86::POPFD)); 945 return; 946 } 947 } 948 cerr << "Not yet supported!"; 949 abort(); 950 } 951 952 unsigned Opc; 953 if (DestRC == &X86::GR64RegClass) { 954 Opc = X86::MOV64rr; 955 } else if (DestRC == &X86::GR32RegClass) { 956 Opc = X86::MOV32rr; 957 } else if (DestRC == &X86::GR16RegClass) { 958 Opc = X86::MOV16rr; 959 } else if (DestRC == &X86::GR8RegClass) { 960 Opc = X86::MOV8rr; 961 } else if (DestRC == &X86::GR32_RegClass) { 962 Opc = X86::MOV32_rr; 963 } else if (DestRC == &X86::GR16_RegClass) { 964 Opc = X86::MOV16_rr; 965 } else if (DestRC == &X86::RFP32RegClass) { 966 Opc = X86::MOV_Fp3232; 967 } else if (DestRC == &X86::RFP64RegClass || DestRC == &X86::RSTRegClass) { 968 Opc = X86::MOV_Fp6464; 969 } else if (DestRC == &X86::RFP80RegClass) { 970 Opc = X86::MOV_Fp8080; 971 } else if (DestRC == &X86::FR32RegClass) { 972 Opc = X86::FsMOVAPSrr; 973 } else if (DestRC == &X86::FR64RegClass) { 974 Opc = X86::FsMOVAPDrr; 975 } else if (DestRC == &X86::VR128RegClass) { 976 Opc = X86::MOVAPSrr; 977 } else if (DestRC == &X86::VR64RegClass) { 978 Opc = X86::MMX_MOVQ64rr; 979 } else { 980 assert(0 && "Unknown regclass"); 981 abort(); 982 } 983 BuildMI(MBB, MI, TII.get(Opc), DestReg).addReg(SrcReg); 984} 985 986const TargetRegisterClass * 987X86RegisterInfo::getCrossCopyRegClass(const TargetRegisterClass *RC) const { 988 if (RC == &X86::CCRRegClass) 989 if (Is64Bit) 990 return &X86::GR64RegClass; 991 else 992 return &X86::GR32RegClass; 993 return NULL; 994} 995 996void X86RegisterInfo::reMaterialize(MachineBasicBlock &MBB, 997 MachineBasicBlock::iterator I, 998 unsigned DestReg, 999 const MachineInstr *Orig) const { 1000 // MOV32r0 etc. are implemented with xor which clobbers condition code. 1001 // Re-materialize them as movri instructions to avoid side effects. 1002 switch (Orig->getOpcode()) { 1003 case X86::MOV8r0: 1004 BuildMI(MBB, I, TII.get(X86::MOV8ri), DestReg).addImm(0); 1005 break; 1006 case X86::MOV16r0: 1007 BuildMI(MBB, I, TII.get(X86::MOV16ri), DestReg).addImm(0); 1008 break; 1009 case X86::MOV32r0: 1010 BuildMI(MBB, I, TII.get(X86::MOV32ri), DestReg).addImm(0); 1011 break; 1012 case X86::MOV64r0: 1013 BuildMI(MBB, I, TII.get(X86::MOV64ri32), DestReg).addImm(0); 1014 break; 1015 default: { 1016 MachineInstr *MI = Orig->clone(); 1017 MI->getOperand(0).setReg(DestReg); 1018 MBB.insert(I, MI); 1019 break; 1020 } 1021 } 1022} 1023 1024static MachineInstr *FuseTwoAddrInst(unsigned Opcode, 1025 SmallVector<MachineOperand,4> &MOs, 1026 MachineInstr *MI, const TargetInstrInfo &TII) { 1027 // Create the base instruction with the memory operand as the first part. 1028 MachineInstr *NewMI = new MachineInstr(TII.get(Opcode), true); 1029 MachineInstrBuilder MIB(NewMI); 1030 unsigned NumAddrOps = MOs.size(); 1031 for (unsigned i = 0; i != NumAddrOps; ++i) 1032 MIB = X86InstrAddOperand(MIB, MOs[i]); 1033 if (NumAddrOps < 4) // FrameIndex only 1034 MIB.addImm(1).addReg(0).addImm(0); 1035 1036 // Loop over the rest of the ri operands, converting them over. 1037 unsigned NumOps = TII.getNumOperands(MI->getOpcode())-2; 1038 for (unsigned i = 0; i != NumOps; ++i) { 1039 MachineOperand &MO = MI->getOperand(i+2); 1040 MIB = X86InstrAddOperand(MIB, MO); 1041 } 1042 for (unsigned i = NumOps+2, e = MI->getNumOperands(); i != e; ++i) { 1043 MachineOperand &MO = MI->getOperand(i); 1044 MIB = X86InstrAddOperand(MIB, MO); 1045 } 1046 return MIB; 1047} 1048 1049static MachineInstr *FuseInst(unsigned Opcode, unsigned OpNo, 1050 SmallVector<MachineOperand,4> &MOs, 1051 MachineInstr *MI, const TargetInstrInfo &TII) { 1052 MachineInstr *NewMI = new MachineInstr(TII.get(Opcode), true); 1053 MachineInstrBuilder MIB(NewMI); 1054 1055 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { 1056 MachineOperand &MO = MI->getOperand(i); 1057 if (i == OpNo) { 1058 assert(MO.isRegister() && "Expected to fold into reg operand!"); 1059 unsigned NumAddrOps = MOs.size(); 1060 for (unsigned i = 0; i != NumAddrOps; ++i) 1061 MIB = X86InstrAddOperand(MIB, MOs[i]); 1062 if (NumAddrOps < 4) // FrameIndex only 1063 MIB.addImm(1).addReg(0).addImm(0); 1064 } else { 1065 MIB = X86InstrAddOperand(MIB, MO); 1066 } 1067 } 1068 return MIB; 1069} 1070 1071static MachineInstr *MakeM0Inst(const TargetInstrInfo &TII, unsigned Opcode, 1072 SmallVector<MachineOperand,4> &MOs, 1073 MachineInstr *MI) { 1074 MachineInstrBuilder MIB = BuildMI(TII.get(Opcode)); 1075 1076 unsigned NumAddrOps = MOs.size(); 1077 for (unsigned i = 0; i != NumAddrOps; ++i) 1078 MIB = X86InstrAddOperand(MIB, MOs[i]); 1079 if (NumAddrOps < 4) // FrameIndex only 1080 MIB.addImm(1).addReg(0).addImm(0); 1081 return MIB.addImm(0); 1082} 1083 1084MachineInstr* 1085X86RegisterInfo::foldMemoryOperand(MachineInstr *MI, unsigned i, 1086 SmallVector<MachineOperand,4> &MOs) const { 1087 const DenseMap<unsigned*, unsigned> *OpcodeTablePtr = NULL; 1088 bool isTwoAddrFold = false; 1089 unsigned NumOps = TII.getNumOperands(MI->getOpcode()); 1090 bool isTwoAddr = NumOps > 1 && 1091 MI->getInstrDescriptor()->getOperandConstraint(1, TOI::TIED_TO) != -1; 1092 1093 MachineInstr *NewMI = NULL; 1094 // Folding a memory location into the two-address part of a two-address 1095 // instruction is different than folding it other places. It requires 1096 // replacing the *two* registers with the memory location. 1097 if (isTwoAddr && NumOps >= 2 && i < 2 && 1098 MI->getOperand(0).isRegister() && 1099 MI->getOperand(1).isRegister() && 1100 MI->getOperand(0).getReg() == MI->getOperand(1).getReg()) { 1101 OpcodeTablePtr = &RegOp2MemOpTable2Addr; 1102 isTwoAddrFold = true; 1103 } else if (i == 0) { // If operand 0 1104 if (MI->getOpcode() == X86::MOV16r0) 1105 NewMI = MakeM0Inst(TII, X86::MOV16mi, MOs, MI); 1106 else if (MI->getOpcode() == X86::MOV32r0) 1107 NewMI = MakeM0Inst(TII, X86::MOV32mi, MOs, MI); 1108 else if (MI->getOpcode() == X86::MOV64r0) 1109 NewMI = MakeM0Inst(TII, X86::MOV64mi32, MOs, MI); 1110 else if (MI->getOpcode() == X86::MOV8r0) 1111 NewMI = MakeM0Inst(TII, X86::MOV8mi, MOs, MI); 1112 if (NewMI) { 1113 NewMI->copyKillDeadInfo(MI); 1114 return NewMI; 1115 } 1116 1117 OpcodeTablePtr = &RegOp2MemOpTable0; 1118 } else if (i == 1) { 1119 OpcodeTablePtr = &RegOp2MemOpTable1; 1120 } else if (i == 2) { 1121 OpcodeTablePtr = &RegOp2MemOpTable2; 1122 } 1123 1124 // If table selected... 1125 if (OpcodeTablePtr) { 1126 // Find the Opcode to fuse 1127 DenseMap<unsigned*, unsigned>::iterator I = 1128 OpcodeTablePtr->find((unsigned*)MI->getOpcode()); 1129 if (I != OpcodeTablePtr->end()) { 1130 if (isTwoAddrFold) 1131 NewMI = FuseTwoAddrInst(I->second, MOs, MI, TII); 1132 else 1133 NewMI = FuseInst(I->second, i, MOs, MI, TII); 1134 NewMI->copyKillDeadInfo(MI); 1135 return NewMI; 1136 } 1137 } 1138 1139 // No fusion 1140 if (PrintFailedFusing) 1141 cerr << "We failed to fuse (" 1142 << ((i == 1) ? "r" : "s") << "): " << *MI; 1143 return NULL; 1144} 1145 1146 1147MachineInstr* X86RegisterInfo::foldMemoryOperand(MachineInstr *MI, 1148 SmallVectorImpl<unsigned> &Ops, 1149 int FrameIndex) const { 1150 // Check switch flag 1151 if (NoFusing) return NULL; 1152 1153 if (Ops.size() == 2 && Ops[0] == 0 && Ops[1] == 1) { 1154 unsigned NewOpc = 0; 1155 switch (MI->getOpcode()) { 1156 default: return NULL; 1157 case X86::TEST8rr: NewOpc = X86::CMP8ri; break; 1158 case X86::TEST16rr: NewOpc = X86::CMP16ri; break; 1159 case X86::TEST32rr: NewOpc = X86::CMP32ri; break; 1160 case X86::TEST64rr: NewOpc = X86::CMP64ri32; break; 1161 } 1162 // Change to CMPXXri r, 0 first. 1163 MI->setInstrDescriptor(TII.get(NewOpc)); 1164 MI->getOperand(1).ChangeToImmediate(0); 1165 } else if (Ops.size() != 1) 1166 return NULL; 1167 1168 SmallVector<MachineOperand,4> MOs; 1169 MOs.push_back(MachineOperand::CreateFrameIndex(FrameIndex)); 1170 return foldMemoryOperand(MI, Ops[0], MOs); 1171} 1172 1173MachineInstr* X86RegisterInfo::foldMemoryOperand(MachineInstr *MI, 1174 SmallVectorImpl<unsigned> &Ops, 1175 MachineInstr *LoadMI) const { 1176 // Check switch flag 1177 if (NoFusing) return NULL; 1178 1179 if (Ops.size() == 2 && Ops[0] == 0 && Ops[1] == 1) { 1180 unsigned NewOpc = 0; 1181 switch (MI->getOpcode()) { 1182 default: return NULL; 1183 case X86::TEST8rr: NewOpc = X86::CMP8ri; break; 1184 case X86::TEST16rr: NewOpc = X86::CMP16ri; break; 1185 case X86::TEST32rr: NewOpc = X86::CMP32ri; break; 1186 case X86::TEST64rr: NewOpc = X86::CMP64ri32; break; 1187 } 1188 // Change to CMPXXri r, 0 first. 1189 MI->setInstrDescriptor(TII.get(NewOpc)); 1190 MI->getOperand(1).ChangeToImmediate(0); 1191 } else if (Ops.size() != 1) 1192 return NULL; 1193 1194 SmallVector<MachineOperand,4> MOs; 1195 unsigned NumOps = TII.getNumOperands(LoadMI->getOpcode()); 1196 for (unsigned i = NumOps - 4; i != NumOps; ++i) 1197 MOs.push_back(LoadMI->getOperand(i)); 1198 return foldMemoryOperand(MI, Ops[0], MOs); 1199} 1200 1201 1202bool X86RegisterInfo::canFoldMemoryOperand(MachineInstr *MI, 1203 SmallVectorImpl<unsigned> &Ops) const { 1204 // Check switch flag 1205 if (NoFusing) return 0; 1206 1207 if (Ops.size() == 2 && Ops[0] == 0 && Ops[1] == 1) { 1208 switch (MI->getOpcode()) { 1209 default: return false; 1210 case X86::TEST8rr: 1211 case X86::TEST16rr: 1212 case X86::TEST32rr: 1213 case X86::TEST64rr: 1214 return true; 1215 } 1216 } 1217 1218 if (Ops.size() != 1) 1219 return false; 1220 1221 unsigned OpNum = Ops[0]; 1222 unsigned Opc = MI->getOpcode(); 1223 unsigned NumOps = TII.getNumOperands(Opc); 1224 bool isTwoAddr = NumOps > 1 && 1225 TII.getOperandConstraint(Opc, 1, TOI::TIED_TO) != -1; 1226 1227 // Folding a memory location into the two-address part of a two-address 1228 // instruction is different than folding it other places. It requires 1229 // replacing the *two* registers with the memory location. 1230 const DenseMap<unsigned*, unsigned> *OpcodeTablePtr = NULL; 1231 if (isTwoAddr && NumOps >= 2 && OpNum < 2) { 1232 OpcodeTablePtr = &RegOp2MemOpTable2Addr; 1233 } else if (OpNum == 0) { // If operand 0 1234 switch (Opc) { 1235 case X86::MOV16r0: 1236 case X86::MOV32r0: 1237 case X86::MOV64r0: 1238 case X86::MOV8r0: 1239 return true; 1240 default: break; 1241 } 1242 OpcodeTablePtr = &RegOp2MemOpTable0; 1243 } else if (OpNum == 1) { 1244 OpcodeTablePtr = &RegOp2MemOpTable1; 1245 } else if (OpNum == 2) { 1246 OpcodeTablePtr = &RegOp2MemOpTable2; 1247 } 1248 1249 if (OpcodeTablePtr) { 1250 // Find the Opcode to fuse 1251 DenseMap<unsigned*, unsigned>::iterator I = 1252 OpcodeTablePtr->find((unsigned*)Opc); 1253 if (I != OpcodeTablePtr->end()) 1254 return true; 1255 } 1256 return false; 1257} 1258 1259bool X86RegisterInfo::unfoldMemoryOperand(MachineFunction &MF, MachineInstr *MI, 1260 unsigned Reg, bool UnfoldLoad, bool UnfoldStore, 1261 SmallVectorImpl<MachineInstr*> &NewMIs) const { 1262 DenseMap<unsigned*, std::pair<unsigned,unsigned> >::iterator I = 1263 MemOp2RegOpTable.find((unsigned*)MI->getOpcode()); 1264 if (I == MemOp2RegOpTable.end()) 1265 return false; 1266 unsigned Opc = I->second.first; 1267 unsigned Index = I->second.second & 0xf; 1268 bool FoldedLoad = I->second.second & (1 << 4); 1269 bool FoldedStore = I->second.second & (1 << 5); 1270 if (UnfoldLoad && !FoldedLoad) 1271 return false; 1272 UnfoldLoad &= FoldedLoad; 1273 if (UnfoldStore && !FoldedStore) 1274 return false; 1275 UnfoldStore &= FoldedStore; 1276 1277 const TargetInstrDescriptor &TID = TII.get(Opc); 1278 const TargetOperandInfo &TOI = TID.OpInfo[Index]; 1279 const TargetRegisterClass *RC = (TOI.Flags & M_LOOK_UP_PTR_REG_CLASS) 1280 ? TII.getPointerRegClass() : getRegClass(TOI.RegClass); 1281 SmallVector<MachineOperand,4> AddrOps; 1282 SmallVector<MachineOperand,2> BeforeOps; 1283 SmallVector<MachineOperand,2> AfterOps; 1284 SmallVector<MachineOperand,4> ImpOps; 1285 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { 1286 MachineOperand &Op = MI->getOperand(i); 1287 if (i >= Index && i < Index+4) 1288 AddrOps.push_back(Op); 1289 else if (Op.isRegister() && Op.isImplicit()) 1290 ImpOps.push_back(Op); 1291 else if (i < Index) 1292 BeforeOps.push_back(Op); 1293 else if (i > Index) 1294 AfterOps.push_back(Op); 1295 } 1296 1297 // Emit the load instruction. 1298 if (UnfoldLoad) { 1299 loadRegFromAddr(MF, Reg, AddrOps, RC, NewMIs); 1300 if (UnfoldStore) { 1301 // Address operands cannot be marked isKill. 1302 for (unsigned i = 1; i != 5; ++i) { 1303 MachineOperand &MO = NewMIs[0]->getOperand(i); 1304 if (MO.isRegister()) 1305 MO.unsetIsKill(); 1306 } 1307 } 1308 } 1309 1310 // Emit the data processing instruction. 1311 MachineInstr *DataMI = new MachineInstr(TID, true); 1312 MachineInstrBuilder MIB(DataMI); 1313 1314 if (FoldedStore) 1315 MIB.addReg(Reg, true); 1316 for (unsigned i = 0, e = BeforeOps.size(); i != e; ++i) 1317 MIB = X86InstrAddOperand(MIB, BeforeOps[i]); 1318 if (FoldedLoad) 1319 MIB.addReg(Reg); 1320 for (unsigned i = 0, e = AfterOps.size(); i != e; ++i) 1321 MIB = X86InstrAddOperand(MIB, AfterOps[i]); 1322 for (unsigned i = 0, e = ImpOps.size(); i != e; ++i) { 1323 MachineOperand &MO = ImpOps[i]; 1324 MIB.addReg(MO.getReg(), MO.isDef(), true, MO.isKill(), MO.isDead()); 1325 } 1326 // Change CMP32ri r, 0 back to TEST32rr r, r, etc. 1327 unsigned NewOpc = 0; 1328 switch (DataMI->getOpcode()) { 1329 default: break; 1330 case X86::CMP64ri32: 1331 case X86::CMP32ri: 1332 case X86::CMP16ri: 1333 case X86::CMP8ri: { 1334 MachineOperand &MO0 = DataMI->getOperand(0); 1335 MachineOperand &MO1 = DataMI->getOperand(1); 1336 if (MO1.getImm() == 0) { 1337 switch (DataMI->getOpcode()) { 1338 default: break; 1339 case X86::CMP64ri32: NewOpc = X86::TEST64rr; break; 1340 case X86::CMP32ri: NewOpc = X86::TEST32rr; break; 1341 case X86::CMP16ri: NewOpc = X86::TEST16rr; break; 1342 case X86::CMP8ri: NewOpc = X86::TEST8rr; break; 1343 } 1344 DataMI->setInstrDescriptor(TII.get(NewOpc)); 1345 MO1.ChangeToRegister(MO0.getReg(), false); 1346 } 1347 } 1348 } 1349 NewMIs.push_back(DataMI); 1350 1351 // Emit the store instruction. 1352 if (UnfoldStore) { 1353 const TargetOperandInfo &DstTOI = TID.OpInfo[0]; 1354 const TargetRegisterClass *DstRC = (DstTOI.Flags & M_LOOK_UP_PTR_REG_CLASS) 1355 ? TII.getPointerRegClass() : getRegClass(DstTOI.RegClass); 1356 storeRegToAddr(MF, Reg, true, AddrOps, DstRC, NewMIs); 1357 } 1358 1359 return true; 1360} 1361 1362 1363bool 1364X86RegisterInfo::unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N, 1365 SmallVectorImpl<SDNode*> &NewNodes) const { 1366 if (!N->isTargetOpcode()) 1367 return false; 1368 1369 DenseMap<unsigned*, std::pair<unsigned,unsigned> >::iterator I = 1370 MemOp2RegOpTable.find((unsigned*)N->getTargetOpcode()); 1371 if (I == MemOp2RegOpTable.end()) 1372 return false; 1373 unsigned Opc = I->second.first; 1374 unsigned Index = I->second.second & 0xf; 1375 bool FoldedLoad = I->second.second & (1 << 4); 1376 bool FoldedStore = I->second.second & (1 << 5); 1377 const TargetInstrDescriptor &TID = TII.get(Opc); 1378 const TargetOperandInfo &TOI = TID.OpInfo[Index]; 1379 const TargetRegisterClass *RC = (TOI.Flags & M_LOOK_UP_PTR_REG_CLASS) 1380 ? TII.getPointerRegClass() : getRegClass(TOI.RegClass); 1381 std::vector<SDOperand> AddrOps; 1382 std::vector<SDOperand> BeforeOps; 1383 std::vector<SDOperand> AfterOps; 1384 unsigned NumOps = N->getNumOperands(); 1385 for (unsigned i = 0; i != NumOps-1; ++i) { 1386 SDOperand Op = N->getOperand(i); 1387 if (i >= Index && i < Index+4) 1388 AddrOps.push_back(Op); 1389 else if (i < Index) 1390 BeforeOps.push_back(Op); 1391 else if (i > Index) 1392 AfterOps.push_back(Op); 1393 } 1394 SDOperand Chain = N->getOperand(NumOps-1); 1395 AddrOps.push_back(Chain); 1396 1397 // Emit the load instruction. 1398 SDNode *Load = 0; 1399 if (FoldedLoad) { 1400 MVT::ValueType VT = *RC->vt_begin(); 1401 Load = DAG.getTargetNode(getLoadRegOpcode(RC, StackAlign), VT, MVT::Other, 1402 &AddrOps[0], AddrOps.size()); 1403 NewNodes.push_back(Load); 1404 } 1405 1406 // Emit the data processing instruction. 1407 std::vector<MVT::ValueType> VTs; 1408 const TargetRegisterClass *DstRC = 0; 1409 if (TID.numDefs > 0) { 1410 const TargetOperandInfo &DstTOI = TID.OpInfo[0]; 1411 DstRC = (DstTOI.Flags & M_LOOK_UP_PTR_REG_CLASS) 1412 ? TII.getPointerRegClass() : getRegClass(DstTOI.RegClass); 1413 VTs.push_back(*DstRC->vt_begin()); 1414 } 1415 for (unsigned i = 0, e = N->getNumValues(); i != e; ++i) { 1416 MVT::ValueType VT = N->getValueType(i); 1417 if (VT != MVT::Other && i >= TID.numDefs) 1418 VTs.push_back(VT); 1419 } 1420 if (Load) 1421 BeforeOps.push_back(SDOperand(Load, 0)); 1422 std::copy(AfterOps.begin(), AfterOps.end(), std::back_inserter(BeforeOps)); 1423 SDNode *NewNode= DAG.getTargetNode(Opc, VTs, &BeforeOps[0], BeforeOps.size()); 1424 NewNodes.push_back(NewNode); 1425 1426 // Emit the store instruction. 1427 if (FoldedStore) { 1428 AddrOps.pop_back(); 1429 AddrOps.push_back(SDOperand(NewNode, 0)); 1430 AddrOps.push_back(Chain); 1431 SDNode *Store = DAG.getTargetNode(getStoreRegOpcode(DstRC, StackAlign), 1432 MVT::Other, &AddrOps[0], AddrOps.size()); 1433 NewNodes.push_back(Store); 1434 } 1435 1436 return true; 1437} 1438 1439unsigned X86RegisterInfo::getOpcodeAfterMemoryUnfold(unsigned Opc, 1440 bool UnfoldLoad, bool UnfoldStore) const { 1441 DenseMap<unsigned*, std::pair<unsigned,unsigned> >::iterator I = 1442 MemOp2RegOpTable.find((unsigned*)Opc); 1443 if (I == MemOp2RegOpTable.end()) 1444 return 0; 1445 bool FoldedLoad = I->second.second & (1 << 4); 1446 bool FoldedStore = I->second.second & (1 << 5); 1447 if (UnfoldLoad && !FoldedLoad) 1448 return 0; 1449 if (UnfoldStore && !FoldedStore) 1450 return 0; 1451 return I->second.first; 1452} 1453 1454const unsigned * 1455X86RegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const { 1456 static const unsigned CalleeSavedRegs32Bit[] = { 1457 X86::ESI, X86::EDI, X86::EBX, X86::EBP, 0 1458 }; 1459 1460 static const unsigned CalleeSavedRegs32EHRet[] = { 1461 X86::EAX, X86::EDX, X86::ESI, X86::EDI, X86::EBX, X86::EBP, 0 1462 }; 1463 1464 static const unsigned CalleeSavedRegs64Bit[] = { 1465 X86::RBX, X86::R12, X86::R13, X86::R14, X86::R15, X86::RBP, 0 1466 }; 1467 1468 if (Is64Bit) 1469 return CalleeSavedRegs64Bit; 1470 else { 1471 if (MF) { 1472 MachineFrameInfo *MFI = MF->getFrameInfo(); 1473 MachineModuleInfo *MMI = MFI->getMachineModuleInfo(); 1474 if (MMI && MMI->callsEHReturn()) 1475 return CalleeSavedRegs32EHRet; 1476 } 1477 return CalleeSavedRegs32Bit; 1478 } 1479} 1480 1481const TargetRegisterClass* const* 1482X86RegisterInfo::getCalleeSavedRegClasses(const MachineFunction *MF) const { 1483 static const TargetRegisterClass * const CalleeSavedRegClasses32Bit[] = { 1484 &X86::GR32RegClass, &X86::GR32RegClass, 1485 &X86::GR32RegClass, &X86::GR32RegClass, 0 1486 }; 1487 static const TargetRegisterClass * const CalleeSavedRegClasses32EHRet[] = { 1488 &X86::GR32RegClass, &X86::GR32RegClass, 1489 &X86::GR32RegClass, &X86::GR32RegClass, 1490 &X86::GR32RegClass, &X86::GR32RegClass, 0 1491 }; 1492 static const TargetRegisterClass * const CalleeSavedRegClasses64Bit[] = { 1493 &X86::GR64RegClass, &X86::GR64RegClass, 1494 &X86::GR64RegClass, &X86::GR64RegClass, 1495 &X86::GR64RegClass, &X86::GR64RegClass, 0 1496 }; 1497 1498 if (Is64Bit) 1499 return CalleeSavedRegClasses64Bit; 1500 else { 1501 if (MF) { 1502 MachineFrameInfo *MFI = MF->getFrameInfo(); 1503 MachineModuleInfo *MMI = MFI->getMachineModuleInfo(); 1504 if (MMI && MMI->callsEHReturn()) 1505 return CalleeSavedRegClasses32EHRet; 1506 } 1507 return CalleeSavedRegClasses32Bit; 1508 } 1509 1510} 1511 1512BitVector X86RegisterInfo::getReservedRegs(const MachineFunction &MF) const { 1513 BitVector Reserved(getNumRegs()); 1514 Reserved.set(X86::RSP); 1515 Reserved.set(X86::ESP); 1516 Reserved.set(X86::SP); 1517 Reserved.set(X86::SPL); 1518 if (hasFP(MF)) { 1519 Reserved.set(X86::RBP); 1520 Reserved.set(X86::EBP); 1521 Reserved.set(X86::BP); 1522 Reserved.set(X86::BPL); 1523 } 1524 return Reserved; 1525} 1526 1527//===----------------------------------------------------------------------===// 1528// Stack Frame Processing methods 1529//===----------------------------------------------------------------------===// 1530 1531// hasFP - Return true if the specified function should have a dedicated frame 1532// pointer register. This is true if the function has variable sized allocas or 1533// if frame pointer elimination is disabled. 1534// 1535bool X86RegisterInfo::hasFP(const MachineFunction &MF) const { 1536 MachineFrameInfo *MFI = MF.getFrameInfo(); 1537 MachineModuleInfo *MMI = MFI->getMachineModuleInfo(); 1538 1539 return (NoFramePointerElim || 1540 MFI->hasVarSizedObjects() || 1541 MF.getInfo<X86MachineFunctionInfo>()->getForceFramePointer() || 1542 (MMI && MMI->callsUnwindInit())); 1543} 1544 1545bool X86RegisterInfo::hasReservedCallFrame(MachineFunction &MF) const { 1546 return !MF.getFrameInfo()->hasVarSizedObjects(); 1547} 1548 1549void X86RegisterInfo:: 1550eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, 1551 MachineBasicBlock::iterator I) const { 1552 if (!hasReservedCallFrame(MF)) { 1553 // If the stack pointer can be changed after prologue, turn the 1554 // adjcallstackup instruction into a 'sub ESP, <amt>' and the 1555 // adjcallstackdown instruction into 'add ESP, <amt>' 1556 // TODO: consider using push / pop instead of sub + store / add 1557 MachineInstr *Old = I; 1558 uint64_t Amount = Old->getOperand(0).getImm(); 1559 if (Amount != 0) { 1560 // We need to keep the stack aligned properly. To do this, we round the 1561 // amount of space needed for the outgoing arguments up to the next 1562 // alignment boundary. 1563 Amount = (Amount+StackAlign-1)/StackAlign*StackAlign; 1564 1565 MachineInstr *New = 0; 1566 if (Old->getOpcode() == X86::ADJCALLSTACKDOWN) { 1567 New=BuildMI(TII.get(Is64Bit ? X86::SUB64ri32 : X86::SUB32ri), StackPtr) 1568 .addReg(StackPtr).addImm(Amount); 1569 } else { 1570 assert(Old->getOpcode() == X86::ADJCALLSTACKUP); 1571 // factor out the amount the callee already popped. 1572 uint64_t CalleeAmt = Old->getOperand(1).getImm(); 1573 Amount -= CalleeAmt; 1574 if (Amount) { 1575 unsigned Opc = (Amount < 128) ? 1576 (Is64Bit ? X86::ADD64ri8 : X86::ADD32ri8) : 1577 (Is64Bit ? X86::ADD64ri32 : X86::ADD32ri); 1578 New = BuildMI(TII.get(Opc), StackPtr).addReg(StackPtr).addImm(Amount); 1579 } 1580 } 1581 1582 // Replace the pseudo instruction with a new instruction... 1583 if (New) MBB.insert(I, New); 1584 } 1585 } else if (I->getOpcode() == X86::ADJCALLSTACKUP) { 1586 // If we are performing frame pointer elimination and if the callee pops 1587 // something off the stack pointer, add it back. We do this until we have 1588 // more advanced stack pointer tracking ability. 1589 if (uint64_t CalleeAmt = I->getOperand(1).getImm()) { 1590 unsigned Opc = (CalleeAmt < 128) ? 1591 (Is64Bit ? X86::SUB64ri8 : X86::SUB32ri8) : 1592 (Is64Bit ? X86::SUB64ri32 : X86::SUB32ri); 1593 MachineInstr *New = 1594 BuildMI(TII.get(Opc), StackPtr).addReg(StackPtr).addImm(CalleeAmt); 1595 MBB.insert(I, New); 1596 } 1597 } 1598 1599 MBB.erase(I); 1600} 1601 1602void X86RegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II, 1603 int SPAdj, RegScavenger *RS) const{ 1604 assert(SPAdj == 0 && "Unexpected"); 1605 1606 unsigned i = 0; 1607 MachineInstr &MI = *II; 1608 MachineFunction &MF = *MI.getParent()->getParent(); 1609 while (!MI.getOperand(i).isFrameIndex()) { 1610 ++i; 1611 assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!"); 1612 } 1613 1614 int FrameIndex = MI.getOperand(i).getFrameIndex(); 1615 // This must be part of a four operand memory reference. Replace the 1616 // FrameIndex with base register with EBP. Add an offset to the offset. 1617 MI.getOperand(i).ChangeToRegister(hasFP(MF) ? FramePtr : StackPtr, false); 1618 1619 // Now add the frame object offset to the offset from EBP. 1620 int64_t Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex) + 1621 MI.getOperand(i+3).getImm()+SlotSize; 1622 1623 if (!hasFP(MF)) 1624 Offset += MF.getFrameInfo()->getStackSize(); 1625 else { 1626 Offset += SlotSize; // Skip the saved EBP 1627 // Skip the RETADDR move area 1628 X86MachineFunctionInfo *X86FI = MF.getInfo<X86MachineFunctionInfo>(); 1629 int TailCallReturnAddrDelta = X86FI->getTCReturnAddrDelta(); 1630 if (TailCallReturnAddrDelta < 0) Offset -= TailCallReturnAddrDelta; 1631 } 1632 1633 MI.getOperand(i+3).ChangeToImmediate(Offset); 1634} 1635 1636void 1637X86RegisterInfo::processFunctionBeforeFrameFinalized(MachineFunction &MF) const{ 1638 X86MachineFunctionInfo *X86FI = MF.getInfo<X86MachineFunctionInfo>(); 1639 int32_t TailCallReturnAddrDelta = X86FI->getTCReturnAddrDelta(); 1640 if (TailCallReturnAddrDelta < 0) { 1641 // create RETURNADDR area 1642 // arg 1643 // arg 1644 // RETADDR 1645 // { ... 1646 // RETADDR area 1647 // ... 1648 // } 1649 // [EBP] 1650 MF.getFrameInfo()-> 1651 CreateFixedObject(-TailCallReturnAddrDelta, 1652 (-1*SlotSize)+TailCallReturnAddrDelta); 1653 } 1654 if (hasFP(MF)) { 1655 assert((TailCallReturnAddrDelta <= 0) && 1656 "The Delta should always be zero or negative"); 1657 // Create a frame entry for the EBP register that must be saved. 1658 int FrameIdx = MF.getFrameInfo()->CreateFixedObject(SlotSize, 1659 (int)SlotSize * -2+ 1660 TailCallReturnAddrDelta); 1661 assert(FrameIdx == MF.getFrameInfo()->getObjectIndexBegin() && 1662 "Slot for EBP register must be last in order to be found!"); 1663 } 1664} 1665 1666/// emitSPUpdate - Emit a series of instructions to increment / decrement the 1667/// stack pointer by a constant value. 1668static 1669void emitSPUpdate(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, 1670 unsigned StackPtr, int64_t NumBytes, bool Is64Bit, 1671 const TargetInstrInfo &TII) { 1672 bool isSub = NumBytes < 0; 1673 uint64_t Offset = isSub ? -NumBytes : NumBytes; 1674 unsigned Opc = isSub 1675 ? ((Offset < 128) ? 1676 (Is64Bit ? X86::SUB64ri8 : X86::SUB32ri8) : 1677 (Is64Bit ? X86::SUB64ri32 : X86::SUB32ri)) 1678 : ((Offset < 128) ? 1679 (Is64Bit ? X86::ADD64ri8 : X86::ADD32ri8) : 1680 (Is64Bit ? X86::ADD64ri32 : X86::ADD32ri)); 1681 uint64_t Chunk = (1LL << 31) - 1; 1682 1683 while (Offset) { 1684 uint64_t ThisVal = (Offset > Chunk) ? Chunk : Offset; 1685 BuildMI(MBB, MBBI, TII.get(Opc), StackPtr).addReg(StackPtr).addImm(ThisVal); 1686 Offset -= ThisVal; 1687 } 1688} 1689 1690// mergeSPUpdatesUp - Merge two stack-manipulating instructions upper iterator. 1691static 1692void mergeSPUpdatesUp(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, 1693 unsigned StackPtr, uint64_t *NumBytes = NULL) { 1694 if (MBBI == MBB.begin()) return; 1695 1696 MachineBasicBlock::iterator PI = prior(MBBI); 1697 unsigned Opc = PI->getOpcode(); 1698 if ((Opc == X86::ADD64ri32 || Opc == X86::ADD64ri8 || 1699 Opc == X86::ADD32ri || Opc == X86::ADD32ri8) && 1700 PI->getOperand(0).getReg() == StackPtr) { 1701 if (NumBytes) 1702 *NumBytes += PI->getOperand(2).getImm(); 1703 MBB.erase(PI); 1704 } else if ((Opc == X86::SUB64ri32 || Opc == X86::SUB64ri8 || 1705 Opc == X86::SUB32ri || Opc == X86::SUB32ri8) && 1706 PI->getOperand(0).getReg() == StackPtr) { 1707 if (NumBytes) 1708 *NumBytes -= PI->getOperand(2).getImm(); 1709 MBB.erase(PI); 1710 } 1711} 1712 1713// mergeSPUpdatesUp - Merge two stack-manipulating instructions lower iterator. 1714static 1715void mergeSPUpdatesDown(MachineBasicBlock &MBB, 1716 MachineBasicBlock::iterator &MBBI, 1717 unsigned StackPtr, uint64_t *NumBytes = NULL) { 1718 return; 1719 1720 if (MBBI == MBB.end()) return; 1721 1722 MachineBasicBlock::iterator NI = next(MBBI); 1723 if (NI == MBB.end()) return; 1724 1725 unsigned Opc = NI->getOpcode(); 1726 if ((Opc == X86::ADD64ri32 || Opc == X86::ADD64ri8 || 1727 Opc == X86::ADD32ri || Opc == X86::ADD32ri8) && 1728 NI->getOperand(0).getReg() == StackPtr) { 1729 if (NumBytes) 1730 *NumBytes -= NI->getOperand(2).getImm(); 1731 MBB.erase(NI); 1732 MBBI = NI; 1733 } else if ((Opc == X86::SUB64ri32 || Opc == X86::SUB64ri8 || 1734 Opc == X86::SUB32ri || Opc == X86::SUB32ri8) && 1735 NI->getOperand(0).getReg() == StackPtr) { 1736 if (NumBytes) 1737 *NumBytes += NI->getOperand(2).getImm(); 1738 MBB.erase(NI); 1739 MBBI = NI; 1740 } 1741} 1742 1743/// mergeSPUpdates - Checks the instruction before/after the passed 1744/// instruction. If it is an ADD/SUB instruction it is deleted 1745/// argument and the stack adjustment is returned as a positive value for ADD 1746/// and a negative for SUB. 1747static int mergeSPUpdates(MachineBasicBlock &MBB, 1748 MachineBasicBlock::iterator &MBBI, 1749 unsigned StackPtr, 1750 bool doMergeWithPrevious) { 1751 1752 if ((doMergeWithPrevious && MBBI == MBB.begin()) || 1753 (!doMergeWithPrevious && MBBI == MBB.end())) 1754 return 0; 1755 1756 int Offset = 0; 1757 1758 MachineBasicBlock::iterator PI = doMergeWithPrevious ? prior(MBBI) : MBBI; 1759 MachineBasicBlock::iterator NI = doMergeWithPrevious ? 0 : next(MBBI); 1760 unsigned Opc = PI->getOpcode(); 1761 if ((Opc == X86::ADD64ri32 || Opc == X86::ADD64ri8 || 1762 Opc == X86::ADD32ri || Opc == X86::ADD32ri8) && 1763 PI->getOperand(0).getReg() == StackPtr){ 1764 Offset += PI->getOperand(2).getImm(); 1765 MBB.erase(PI); 1766 if (!doMergeWithPrevious) MBBI = NI; 1767 } else if ((Opc == X86::SUB64ri32 || Opc == X86::SUB64ri8 || 1768 Opc == X86::SUB32ri || Opc == X86::SUB32ri8) && 1769 PI->getOperand(0).getReg() == StackPtr) { 1770 Offset -= PI->getOperand(2).getImm(); 1771 MBB.erase(PI); 1772 if (!doMergeWithPrevious) MBBI = NI; 1773 } 1774 1775 return Offset; 1776} 1777 1778void X86RegisterInfo::emitPrologue(MachineFunction &MF) const { 1779 MachineBasicBlock &MBB = MF.front(); // Prolog goes in entry BB 1780 MachineFrameInfo *MFI = MF.getFrameInfo(); 1781 const Function* Fn = MF.getFunction(); 1782 const X86Subtarget* Subtarget = &MF.getTarget().getSubtarget<X86Subtarget>(); 1783 MachineModuleInfo *MMI = MFI->getMachineModuleInfo(); 1784 X86MachineFunctionInfo *X86FI = MF.getInfo<X86MachineFunctionInfo>(); 1785 MachineBasicBlock::iterator MBBI = MBB.begin(); 1786 1787 // Prepare for frame info. 1788 unsigned FrameLabelId = 0; 1789 1790 // Get the number of bytes to allocate from the FrameInfo. 1791 uint64_t StackSize = MFI->getStackSize(); 1792 // Add RETADDR move area to callee saved frame size. 1793 int TailCallReturnAddrDelta = X86FI->getTCReturnAddrDelta(); 1794 if (TailCallReturnAddrDelta < 0) 1795 X86FI->setCalleeSavedFrameSize( 1796 X86FI->getCalleeSavedFrameSize() +(-TailCallReturnAddrDelta)); 1797 uint64_t NumBytes = StackSize - X86FI->getCalleeSavedFrameSize(); 1798 1799 // Insert stack pointer adjustment for later moving of return addr. Only 1800 // applies to tail call optimized functions where the callee argument stack 1801 // size is bigger than the callers. 1802 if (TailCallReturnAddrDelta < 0) { 1803 BuildMI(MBB, MBBI, TII.get(Is64Bit? X86::SUB64ri32 : X86::SUB32ri), 1804 StackPtr).addReg(StackPtr).addImm(-TailCallReturnAddrDelta); 1805 } 1806 1807 if (hasFP(MF)) { 1808 // Get the offset of the stack slot for the EBP register... which is 1809 // guaranteed to be the last slot by processFunctionBeforeFrameFinalized. 1810 // Update the frame offset adjustment. 1811 MFI->setOffsetAdjustment(SlotSize-NumBytes); 1812 1813 // Save EBP into the appropriate stack slot... 1814 BuildMI(MBB, MBBI, TII.get(Is64Bit ? X86::PUSH64r : X86::PUSH32r)) 1815 .addReg(FramePtr); 1816 NumBytes -= SlotSize; 1817 1818 if (MMI && MMI->needsFrameInfo()) { 1819 // Mark effective beginning of when frame pointer becomes valid. 1820 FrameLabelId = MMI->NextLabelID(); 1821 BuildMI(MBB, MBBI, TII.get(X86::LABEL)).addImm(FrameLabelId); 1822 } 1823 1824 // Update EBP with the new base value... 1825 BuildMI(MBB, MBBI, TII.get(Is64Bit ? X86::MOV64rr : X86::MOV32rr), FramePtr) 1826 .addReg(StackPtr); 1827 } 1828 1829 unsigned ReadyLabelId = 0; 1830 if (MMI && MMI->needsFrameInfo()) { 1831 // Mark effective beginning of when frame pointer is ready. 1832 ReadyLabelId = MMI->NextLabelID(); 1833 BuildMI(MBB, MBBI, TII.get(X86::LABEL)).addImm(ReadyLabelId); 1834 } 1835 1836 // Skip the callee-saved push instructions. 1837 while (MBBI != MBB.end() && 1838 (MBBI->getOpcode() == X86::PUSH32r || 1839 MBBI->getOpcode() == X86::PUSH64r)) 1840 ++MBBI; 1841 1842 if (NumBytes) { // adjust stack pointer: ESP -= numbytes 1843 if (NumBytes >= 4096 && Subtarget->isTargetCygMing()) { 1844 // Check, whether EAX is livein for this function 1845 bool isEAXAlive = false; 1846 for (MachineFunction::livein_iterator II = MF.livein_begin(), 1847 EE = MF.livein_end(); (II != EE) && !isEAXAlive; ++II) { 1848 unsigned Reg = II->first; 1849 isEAXAlive = (Reg == X86::EAX || Reg == X86::AX || 1850 Reg == X86::AH || Reg == X86::AL); 1851 } 1852 1853 // Function prologue calls _alloca to probe the stack when allocating 1854 // more than 4k bytes in one go. Touching the stack at 4K increments is 1855 // necessary to ensure that the guard pages used by the OS virtual memory 1856 // manager are allocated in correct sequence. 1857 if (!isEAXAlive) { 1858 BuildMI(MBB, MBBI, TII.get(X86::MOV32ri), X86::EAX).addImm(NumBytes); 1859 BuildMI(MBB, MBBI, TII.get(X86::CALLpcrel32)) 1860 .addExternalSymbol("_alloca"); 1861 } else { 1862 // Save EAX 1863 BuildMI(MBB, MBBI, TII.get(X86::PUSH32r), X86::EAX); 1864 // Allocate NumBytes-4 bytes on stack. We'll also use 4 already 1865 // allocated bytes for EAX. 1866 BuildMI(MBB, MBBI, TII.get(X86::MOV32ri), X86::EAX).addImm(NumBytes-4); 1867 BuildMI(MBB, MBBI, TII.get(X86::CALLpcrel32)) 1868 .addExternalSymbol("_alloca"); 1869 // Restore EAX 1870 MachineInstr *MI = addRegOffset(BuildMI(TII.get(X86::MOV32rm),X86::EAX), 1871 StackPtr, NumBytes-4); 1872 MBB.insert(MBBI, MI); 1873 } 1874 } else { 1875 // If there is an SUB32ri of ESP immediately before this instruction, 1876 // merge the two. This can be the case when tail call elimination is 1877 // enabled and the callee has more arguments then the caller. 1878 NumBytes -= mergeSPUpdates(MBB, MBBI, StackPtr, true); 1879 // If there is an ADD32ri or SUB32ri of ESP immediately after this 1880 // instruction, merge the two instructions. 1881 mergeSPUpdatesDown(MBB, MBBI, StackPtr, &NumBytes); 1882 1883 if (NumBytes) 1884 emitSPUpdate(MBB, MBBI, StackPtr, -(int64_t)NumBytes, Is64Bit, TII); 1885 } 1886 } 1887 1888 if (MMI && MMI->needsFrameInfo()) { 1889 std::vector<MachineMove> &Moves = MMI->getFrameMoves(); 1890 const TargetData *TD = MF.getTarget().getTargetData(); 1891 1892 // Calculate amount of bytes used for return address storing 1893 int stackGrowth = 1894 (MF.getTarget().getFrameInfo()->getStackGrowthDirection() == 1895 TargetFrameInfo::StackGrowsUp ? 1896 TD->getPointerSize() : -TD->getPointerSize()); 1897 1898 if (StackSize) { 1899 // Show update of SP. 1900 if (hasFP(MF)) { 1901 // Adjust SP 1902 MachineLocation SPDst(MachineLocation::VirtualFP); 1903 MachineLocation SPSrc(MachineLocation::VirtualFP, 2*stackGrowth); 1904 Moves.push_back(MachineMove(FrameLabelId, SPDst, SPSrc)); 1905 } else { 1906 MachineLocation SPDst(MachineLocation::VirtualFP); 1907 MachineLocation SPSrc(MachineLocation::VirtualFP, -StackSize+stackGrowth); 1908 Moves.push_back(MachineMove(FrameLabelId, SPDst, SPSrc)); 1909 } 1910 } else { 1911 //FIXME: Verify & implement for FP 1912 MachineLocation SPDst(StackPtr); 1913 MachineLocation SPSrc(StackPtr, stackGrowth); 1914 Moves.push_back(MachineMove(FrameLabelId, SPDst, SPSrc)); 1915 } 1916 1917 // Add callee saved registers to move list. 1918 const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo(); 1919 1920 // FIXME: This is dirty hack. The code itself is pretty mess right now. 1921 // It should be rewritten from scratch and generalized sometimes. 1922 1923 // Determine maximum offset (minumum due to stack growth) 1924 int64_t MaxOffset = 0; 1925 for (unsigned I = 0, E = CSI.size(); I!=E; ++I) 1926 MaxOffset = std::min(MaxOffset, 1927 MFI->getObjectOffset(CSI[I].getFrameIdx())); 1928 1929 // Calculate offsets 1930 int64_t saveAreaOffset = (hasFP(MF) ? 3 : 2)*stackGrowth; 1931 for (unsigned I = 0, E = CSI.size(); I!=E; ++I) { 1932 int64_t Offset = MFI->getObjectOffset(CSI[I].getFrameIdx()); 1933 unsigned Reg = CSI[I].getReg(); 1934 Offset = (MaxOffset-Offset+saveAreaOffset); 1935 MachineLocation CSDst(MachineLocation::VirtualFP, Offset); 1936 MachineLocation CSSrc(Reg); 1937 Moves.push_back(MachineMove(FrameLabelId, CSDst, CSSrc)); 1938 } 1939 1940 if (hasFP(MF)) { 1941 // Save FP 1942 MachineLocation FPDst(MachineLocation::VirtualFP, 2*stackGrowth); 1943 MachineLocation FPSrc(FramePtr); 1944 Moves.push_back(MachineMove(ReadyLabelId, FPDst, FPSrc)); 1945 } 1946 1947 MachineLocation FPDst(hasFP(MF) ? FramePtr : StackPtr); 1948 MachineLocation FPSrc(MachineLocation::VirtualFP); 1949 Moves.push_back(MachineMove(ReadyLabelId, FPDst, FPSrc)); 1950 } 1951 1952 // If it's main() on Cygwin\Mingw32 we should align stack as well 1953 if (Fn->hasExternalLinkage() && Fn->getName() == "main" && 1954 Subtarget->isTargetCygMing()) { 1955 BuildMI(MBB, MBBI, TII.get(X86::AND32ri), X86::ESP) 1956 .addReg(X86::ESP).addImm(-StackAlign); 1957 1958 // Probe the stack 1959 BuildMI(MBB, MBBI, TII.get(X86::MOV32ri), X86::EAX).addImm(StackAlign); 1960 BuildMI(MBB, MBBI, TII.get(X86::CALLpcrel32)).addExternalSymbol("_alloca"); 1961 } 1962} 1963 1964void X86RegisterInfo::emitEpilogue(MachineFunction &MF, 1965 MachineBasicBlock &MBB) const { 1966 const MachineFrameInfo *MFI = MF.getFrameInfo(); 1967 const Function* Fn = MF.getFunction(); 1968 X86MachineFunctionInfo *X86FI = MF.getInfo<X86MachineFunctionInfo>(); 1969 const X86Subtarget* Subtarget = &MF.getTarget().getSubtarget<X86Subtarget>(); 1970 MachineBasicBlock::iterator MBBI = prior(MBB.end()); 1971 unsigned RetOpcode = MBBI->getOpcode(); 1972 1973 switch (RetOpcode) { 1974 case X86::RET: 1975 case X86::RETI: 1976 case X86::TCRETURNdi: 1977 case X86::TCRETURNri: 1978 case X86::TCRETURNri64: 1979 case X86::TCRETURNdi64: 1980 case X86::EH_RETURN: 1981 case X86::TAILJMPd: 1982 case X86::TAILJMPr: 1983 case X86::TAILJMPm: break; // These are ok 1984 default: 1985 assert(0 && "Can only insert epilog into returning blocks"); 1986 } 1987 1988 // Get the number of bytes to allocate from the FrameInfo 1989 uint64_t StackSize = MFI->getStackSize(); 1990 unsigned CSSize = X86FI->getCalleeSavedFrameSize(); 1991 uint64_t NumBytes = StackSize - CSSize; 1992 1993 if (hasFP(MF)) { 1994 // pop EBP. 1995 BuildMI(MBB, MBBI, TII.get(Is64Bit ? X86::POP64r : X86::POP32r), FramePtr); 1996 NumBytes -= SlotSize; 1997 } 1998 1999 // Skip the callee-saved pop instructions. 2000 while (MBBI != MBB.begin()) { 2001 MachineBasicBlock::iterator PI = prior(MBBI); 2002 unsigned Opc = PI->getOpcode(); 2003 if (Opc != X86::POP32r && Opc != X86::POP64r && !TII.isTerminatorInstr(Opc)) 2004 break; 2005 --MBBI; 2006 } 2007 2008 // If there is an ADD32ri or SUB32ri of ESP immediately before this 2009 // instruction, merge the two instructions. 2010 if (NumBytes || MFI->hasVarSizedObjects()) 2011 mergeSPUpdatesUp(MBB, MBBI, StackPtr, &NumBytes); 2012 2013 // If dynamic alloca is used, then reset esp to point to the last callee-saved 2014 // slot before popping them off! Also, if it's main() on Cygwin/Mingw32 we 2015 // aligned stack in the prologue, - revert stack changes back. Note: we're 2016 // assuming, that frame pointer was forced for main() 2017 if (MFI->hasVarSizedObjects() || 2018 (Fn->hasExternalLinkage() && Fn->getName() == "main" && 2019 Subtarget->isTargetCygMing())) { 2020 unsigned Opc = Is64Bit ? X86::LEA64r : X86::LEA32r; 2021 if (CSSize) { 2022 MachineInstr *MI = addRegOffset(BuildMI(TII.get(Opc), StackPtr), 2023 FramePtr, -CSSize); 2024 MBB.insert(MBBI, MI); 2025 } else 2026 BuildMI(MBB, MBBI, TII.get(Is64Bit ? X86::MOV64rr : X86::MOV32rr),StackPtr). 2027 addReg(FramePtr); 2028 2029 NumBytes = 0; 2030 } 2031 2032 // adjust stack pointer back: ESP += numbytes 2033 if (NumBytes) 2034 emitSPUpdate(MBB, MBBI, StackPtr, NumBytes, Is64Bit, TII); 2035 2036 // We're returning from function via eh_return. 2037 if (RetOpcode == X86::EH_RETURN) { 2038 MBBI = prior(MBB.end()); 2039 MachineOperand &DestAddr = MBBI->getOperand(0); 2040 assert(DestAddr.isRegister() && "Offset should be in register!"); 2041 BuildMI(MBB, MBBI, TII.get(Is64Bit ? X86::MOV64rr : X86::MOV32rr),StackPtr). 2042 addReg(DestAddr.getReg()); 2043 // Tail call return: adjust the stack pointer and jump to callee 2044 } else if (RetOpcode == X86::TCRETURNri || RetOpcode == X86::TCRETURNdi || 2045 RetOpcode== X86::TCRETURNri64 || RetOpcode == X86::TCRETURNdi64) { 2046 MBBI = prior(MBB.end()); 2047 MachineOperand &JumpTarget = MBBI->getOperand(0); 2048 MachineOperand &StackAdjust = MBBI->getOperand(1); 2049 assert( StackAdjust.isImmediate() && "Expecting immediate value."); 2050 2051 // Adjust stack pointer. 2052 int StackAdj = StackAdjust.getImm(); 2053 int MaxTCDelta = X86FI->getTCReturnAddrDelta(); 2054 int Offset = 0; 2055 assert(MaxTCDelta <= 0 && "MaxTCDelta should never be positive"); 2056 // Incoporate the retaddr area. 2057 Offset = StackAdj-MaxTCDelta; 2058 assert(Offset >= 0 && "Offset should never be negative"); 2059 if (Offset) { 2060 // Check for possible merge with preceeding ADD instruction. 2061 Offset += mergeSPUpdates(MBB, MBBI, StackPtr, true); 2062 emitSPUpdate(MBB, MBBI, StackPtr, Offset, Is64Bit, TII); 2063 } 2064 // Jump to label or value in register. 2065 if (RetOpcode == X86::TCRETURNdi|| RetOpcode == X86::TCRETURNdi64) 2066 BuildMI(MBB, MBBI, TII.get(X86::TAILJMPd)). 2067 addGlobalAddress(JumpTarget.getGlobal(), JumpTarget.getOffset()); 2068 else if (RetOpcode== X86::TCRETURNri64) { 2069 BuildMI(MBB, MBBI, TII.get(X86::TAILJMPr64), JumpTarget.getReg()); 2070 } else 2071 BuildMI(MBB, MBBI, TII.get(X86::TAILJMPr), JumpTarget.getReg()); 2072 // Delete the pseudo instruction TCRETURN. 2073 MBB.erase(MBBI); 2074 } else if ((RetOpcode == X86::RET || RetOpcode == X86::RETI) && 2075 (X86FI->getTCReturnAddrDelta() < 0)) { 2076 // Add the return addr area delta back since we are not tail calling. 2077 int delta = -1*X86FI->getTCReturnAddrDelta(); 2078 MBBI = prior(MBB.end()); 2079 // Check for possible merge with preceeding ADD instruction. 2080 delta += mergeSPUpdates(MBB, MBBI, StackPtr, true); 2081 emitSPUpdate(MBB, MBBI, StackPtr, delta, Is64Bit, TII); 2082 } 2083} 2084 2085unsigned X86RegisterInfo::getRARegister() const { 2086 if (Is64Bit) 2087 return X86::RIP; // Should have dwarf #16 2088 else 2089 return X86::EIP; // Should have dwarf #8 2090} 2091 2092unsigned X86RegisterInfo::getFrameRegister(MachineFunction &MF) const { 2093 return hasFP(MF) ? FramePtr : StackPtr; 2094} 2095 2096void X86RegisterInfo::getInitialFrameState(std::vector<MachineMove> &Moves) 2097 const { 2098 // Calculate amount of bytes used for return address storing 2099 int stackGrowth = (Is64Bit ? -8 : -4); 2100 2101 // Initial state of the frame pointer is esp+4. 2102 MachineLocation Dst(MachineLocation::VirtualFP); 2103 MachineLocation Src(StackPtr, stackGrowth); 2104 Moves.push_back(MachineMove(0, Dst, Src)); 2105 2106 // Add return address to move list 2107 MachineLocation CSDst(StackPtr, stackGrowth); 2108 MachineLocation CSSrc(getRARegister()); 2109 Moves.push_back(MachineMove(0, CSDst, CSSrc)); 2110} 2111 2112unsigned X86RegisterInfo::getEHExceptionRegister() const { 2113 assert(0 && "What is the exception register"); 2114 return 0; 2115} 2116 2117unsigned X86RegisterInfo::getEHHandlerRegister() const { 2118 assert(0 && "What is the exception handler register"); 2119 return 0; 2120} 2121 2122namespace llvm { 2123unsigned getX86SubSuperRegister(unsigned Reg, MVT::ValueType VT, bool High) { 2124 switch (VT) { 2125 default: return Reg; 2126 case MVT::i8: 2127 if (High) { 2128 switch (Reg) { 2129 default: return 0; 2130 case X86::AH: case X86::AL: case X86::AX: case X86::EAX: case X86::RAX: 2131 return X86::AH; 2132 case X86::DH: case X86::DL: case X86::DX: case X86::EDX: case X86::RDX: 2133 return X86::DH; 2134 case X86::CH: case X86::CL: case X86::CX: case X86::ECX: case X86::RCX: 2135 return X86::CH; 2136 case X86::BH: case X86::BL: case X86::BX: case X86::EBX: case X86::RBX: 2137 return X86::BH; 2138 } 2139 } else { 2140 switch (Reg) { 2141 default: return 0; 2142 case X86::AH: case X86::AL: case X86::AX: case X86::EAX: case X86::RAX: 2143 return X86::AL; 2144 case X86::DH: case X86::DL: case X86::DX: case X86::EDX: case X86::RDX: 2145 return X86::DL; 2146 case X86::CH: case X86::CL: case X86::CX: case X86::ECX: case X86::RCX: 2147 return X86::CL; 2148 case X86::BH: case X86::BL: case X86::BX: case X86::EBX: case X86::RBX: 2149 return X86::BL; 2150 case X86::SIL: case X86::SI: case X86::ESI: case X86::RSI: 2151 return X86::SIL; 2152 case X86::DIL: case X86::DI: case X86::EDI: case X86::RDI: 2153 return X86::DIL; 2154 case X86::BPL: case X86::BP: case X86::EBP: case X86::RBP: 2155 return X86::BPL; 2156 case X86::SPL: case X86::SP: case X86::ESP: case X86::RSP: 2157 return X86::SPL; 2158 case X86::R8B: case X86::R8W: case X86::R8D: case X86::R8: 2159 return X86::R8B; 2160 case X86::R9B: case X86::R9W: case X86::R9D: case X86::R9: 2161 return X86::R9B; 2162 case X86::R10B: case X86::R10W: case X86::R10D: case X86::R10: 2163 return X86::R10B; 2164 case X86::R11B: case X86::R11W: case X86::R11D: case X86::R11: 2165 return X86::R11B; 2166 case X86::R12B: case X86::R12W: case X86::R12D: case X86::R12: 2167 return X86::R12B; 2168 case X86::R13B: case X86::R13W: case X86::R13D: case X86::R13: 2169 return X86::R13B; 2170 case X86::R14B: case X86::R14W: case X86::R14D: case X86::R14: 2171 return X86::R14B; 2172 case X86::R15B: case X86::R15W: case X86::R15D: case X86::R15: 2173 return X86::R15B; 2174 } 2175 } 2176 case MVT::i16: 2177 switch (Reg) { 2178 default: return Reg; 2179 case X86::AH: case X86::AL: case X86::AX: case X86::EAX: case X86::RAX: 2180 return X86::AX; 2181 case X86::DH: case X86::DL: case X86::DX: case X86::EDX: case X86::RDX: 2182 return X86::DX; 2183 case X86::CH: case X86::CL: case X86::CX: case X86::ECX: case X86::RCX: 2184 return X86::CX; 2185 case X86::BH: case X86::BL: case X86::BX: case X86::EBX: case X86::RBX: 2186 return X86::BX; 2187 case X86::SIL: case X86::SI: case X86::ESI: case X86::RSI: 2188 return X86::SI; 2189 case X86::DIL: case X86::DI: case X86::EDI: case X86::RDI: 2190 return X86::DI; 2191 case X86::BPL: case X86::BP: case X86::EBP: case X86::RBP: 2192 return X86::BP; 2193 case X86::SPL: case X86::SP: case X86::ESP: case X86::RSP: 2194 return X86::SP; 2195 case X86::R8B: case X86::R8W: case X86::R8D: case X86::R8: 2196 return X86::R8W; 2197 case X86::R9B: case X86::R9W: case X86::R9D: case X86::R9: 2198 return X86::R9W; 2199 case X86::R10B: case X86::R10W: case X86::R10D: case X86::R10: 2200 return X86::R10W; 2201 case X86::R11B: case X86::R11W: case X86::R11D: case X86::R11: 2202 return X86::R11W; 2203 case X86::R12B: case X86::R12W: case X86::R12D: case X86::R12: 2204 return X86::R12W; 2205 case X86::R13B: case X86::R13W: case X86::R13D: case X86::R13: 2206 return X86::R13W; 2207 case X86::R14B: case X86::R14W: case X86::R14D: case X86::R14: 2208 return X86::R14W; 2209 case X86::R15B: case X86::R15W: case X86::R15D: case X86::R15: 2210 return X86::R15W; 2211 } 2212 case MVT::i32: 2213 switch (Reg) { 2214 default: return Reg; 2215 case X86::AH: case X86::AL: case X86::AX: case X86::EAX: case X86::RAX: 2216 return X86::EAX; 2217 case X86::DH: case X86::DL: case X86::DX: case X86::EDX: case X86::RDX: 2218 return X86::EDX; 2219 case X86::CH: case X86::CL: case X86::CX: case X86::ECX: case X86::RCX: 2220 return X86::ECX; 2221 case X86::BH: case X86::BL: case X86::BX: case X86::EBX: case X86::RBX: 2222 return X86::EBX; 2223 case X86::SIL: case X86::SI: case X86::ESI: case X86::RSI: 2224 return X86::ESI; 2225 case X86::DIL: case X86::DI: case X86::EDI: case X86::RDI: 2226 return X86::EDI; 2227 case X86::BPL: case X86::BP: case X86::EBP: case X86::RBP: 2228 return X86::EBP; 2229 case X86::SPL: case X86::SP: case X86::ESP: case X86::RSP: 2230 return X86::ESP; 2231 case X86::R8B: case X86::R8W: case X86::R8D: case X86::R8: 2232 return X86::R8D; 2233 case X86::R9B: case X86::R9W: case X86::R9D: case X86::R9: 2234 return X86::R9D; 2235 case X86::R10B: case X86::R10W: case X86::R10D: case X86::R10: 2236 return X86::R10D; 2237 case X86::R11B: case X86::R11W: case X86::R11D: case X86::R11: 2238 return X86::R11D; 2239 case X86::R12B: case X86::R12W: case X86::R12D: case X86::R12: 2240 return X86::R12D; 2241 case X86::R13B: case X86::R13W: case X86::R13D: case X86::R13: 2242 return X86::R13D; 2243 case X86::R14B: case X86::R14W: case X86::R14D: case X86::R14: 2244 return X86::R14D; 2245 case X86::R15B: case X86::R15W: case X86::R15D: case X86::R15: 2246 return X86::R15D; 2247 } 2248 case MVT::i64: 2249 switch (Reg) { 2250 default: return Reg; 2251 case X86::AH: case X86::AL: case X86::AX: case X86::EAX: case X86::RAX: 2252 return X86::RAX; 2253 case X86::DH: case X86::DL: case X86::DX: case X86::EDX: case X86::RDX: 2254 return X86::RDX; 2255 case X86::CH: case X86::CL: case X86::CX: case X86::ECX: case X86::RCX: 2256 return X86::RCX; 2257 case X86::BH: case X86::BL: case X86::BX: case X86::EBX: case X86::RBX: 2258 return X86::RBX; 2259 case X86::SIL: case X86::SI: case X86::ESI: case X86::RSI: 2260 return X86::RSI; 2261 case X86::DIL: case X86::DI: case X86::EDI: case X86::RDI: 2262 return X86::RDI; 2263 case X86::BPL: case X86::BP: case X86::EBP: case X86::RBP: 2264 return X86::RBP; 2265 case X86::SPL: case X86::SP: case X86::ESP: case X86::RSP: 2266 return X86::RSP; 2267 case X86::R8B: case X86::R8W: case X86::R8D: case X86::R8: 2268 return X86::R8; 2269 case X86::R9B: case X86::R9W: case X86::R9D: case X86::R9: 2270 return X86::R9; 2271 case X86::R10B: case X86::R10W: case X86::R10D: case X86::R10: 2272 return X86::R10; 2273 case X86::R11B: case X86::R11W: case X86::R11D: case X86::R11: 2274 return X86::R11; 2275 case X86::R12B: case X86::R12W: case X86::R12D: case X86::R12: 2276 return X86::R12; 2277 case X86::R13B: case X86::R13W: case X86::R13D: case X86::R13: 2278 return X86::R13; 2279 case X86::R14B: case X86::R14W: case X86::R14D: case X86::R14: 2280 return X86::R14; 2281 case X86::R15B: case X86::R15W: case X86::R15D: case X86::R15: 2282 return X86::R15; 2283 } 2284 } 2285 2286 return Reg; 2287} 2288} 2289 2290#include "X86GenRegisterInfo.inc" 2291 2292