LLVM API Documentation

X86RegisterInfo.cpp
Go to the documentation of this file.
00001 //===-- X86RegisterInfo.cpp - X86 Register Information --------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file contains the X86 implementation of the TargetRegisterInfo class.
00011 // This file is responsible for the frame pointer elimination optimization
00012 // on X86.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #include "X86RegisterInfo.h"
00017 #include "X86InstrBuilder.h"
00018 #include "X86MachineFunctionInfo.h"
00019 #include "X86Subtarget.h"
00020 #include "X86TargetMachine.h"
00021 #include "llvm/ADT/BitVector.h"
00022 #include "llvm/ADT/STLExtras.h"
00023 #include "llvm/CodeGen/MachineFrameInfo.h"
00024 #include "llvm/CodeGen/MachineFunction.h"
00025 #include "llvm/CodeGen/MachineFunctionPass.h"
00026 #include "llvm/CodeGen/MachineInstrBuilder.h"
00027 #include "llvm/CodeGen/MachineModuleInfo.h"
00028 #include "llvm/CodeGen/MachineRegisterInfo.h"
00029 #include "llvm/CodeGen/MachineValueType.h"
00030 #include "llvm/IR/Constants.h"
00031 #include "llvm/IR/Function.h"
00032 #include "llvm/IR/Type.h"
00033 #include "llvm/MC/MCAsmInfo.h"
00034 #include "llvm/Support/CommandLine.h"
00035 #include "llvm/Support/ErrorHandling.h"
00036 #include "llvm/Target/TargetFrameLowering.h"
00037 #include "llvm/Target/TargetInstrInfo.h"
00038 #include "llvm/Target/TargetMachine.h"
00039 #include "llvm/Target/TargetOptions.h"
00040 
00041 using namespace llvm;
00042 
00043 #define GET_REGINFO_TARGET_DESC
00044 #include "X86GenRegisterInfo.inc"
00045 
00046 cl::opt<bool>
00047 ForceStackAlign("force-align-stack",
00048                  cl::desc("Force align the stack to the minimum alignment"
00049                            " needed for the function."),
00050                  cl::init(false), cl::Hidden);
00051 
00052 static cl::opt<bool>
00053 EnableBasePointer("x86-use-base-pointer", cl::Hidden, cl::init(true),
00054           cl::desc("Enable use of a base pointer for complex stack frames"));
00055 
00056 X86RegisterInfo::X86RegisterInfo(const X86Subtarget &STI)
00057     : X86GenRegisterInfo(
00058           (STI.is64Bit() ? X86::RIP : X86::EIP),
00059           X86_MC::getDwarfRegFlavour(STI.getTargetTriple(), false),
00060           X86_MC::getDwarfRegFlavour(STI.getTargetTriple(), true),
00061           (STI.is64Bit() ? X86::RIP : X86::EIP)),
00062       Subtarget(STI) {
00063   X86_MC::InitLLVM2SEHRegisterMapping(this);
00064 
00065   // Cache some information.
00066   Is64Bit = Subtarget.is64Bit();
00067   IsWin64 = Subtarget.isTargetWin64();
00068 
00069   if (Is64Bit) {
00070     SlotSize = 8;
00071     StackPtr = (Subtarget.isTarget64BitLP64() || Subtarget.isTargetNaCl64()) ?
00072         X86::RSP : X86::ESP;
00073     FramePtr = (Subtarget.isTarget64BitLP64() || Subtarget.isTargetNaCl64()) ?
00074         X86::RBP : X86::EBP;
00075   } else {
00076     SlotSize = 4;
00077     StackPtr = X86::ESP;
00078     FramePtr = X86::EBP;
00079   }
00080   // Use a callee-saved register as the base pointer.  These registers must
00081   // not conflict with any ABI requirements.  For example, in 32-bit mode PIC
00082   // requires GOT in the EBX register before function calls via PLT GOT pointer.
00083   BasePtr = Is64Bit ? X86::RBX : X86::ESI;
00084 }
00085 
00086 bool
00087 X86RegisterInfo::trackLivenessAfterRegAlloc(const MachineFunction &MF) const {
00088   // ExeDepsFixer and PostRAScheduler require liveness.
00089   return true;
00090 }
00091 
00092 int
00093 X86RegisterInfo::getSEHRegNum(unsigned i) const {
00094   return getEncodingValue(i);
00095 }
00096 
00097 const TargetRegisterClass *
00098 X86RegisterInfo::getSubClassWithSubReg(const TargetRegisterClass *RC,
00099                                        unsigned Idx) const {
00100   // The sub_8bit sub-register index is more constrained in 32-bit mode.
00101   // It behaves just like the sub_8bit_hi index.
00102   if (!Is64Bit && Idx == X86::sub_8bit)
00103     Idx = X86::sub_8bit_hi;
00104 
00105   // Forward to TableGen's default version.
00106   return X86GenRegisterInfo::getSubClassWithSubReg(RC, Idx);
00107 }
00108 
00109 const TargetRegisterClass *
00110 X86RegisterInfo::getMatchingSuperRegClass(const TargetRegisterClass *A,
00111                                           const TargetRegisterClass *B,
00112                                           unsigned SubIdx) const {
00113   // The sub_8bit sub-register index is more constrained in 32-bit mode.
00114   if (!Is64Bit && SubIdx == X86::sub_8bit) {
00115     A = X86GenRegisterInfo::getSubClassWithSubReg(A, X86::sub_8bit_hi);
00116     if (!A)
00117       return nullptr;
00118   }
00119   return X86GenRegisterInfo::getMatchingSuperRegClass(A, B, SubIdx);
00120 }
00121 
00122 const TargetRegisterClass*
00123 X86RegisterInfo::getLargestLegalSuperClass(const TargetRegisterClass *RC) const{
00124   // Don't allow super-classes of GR8_NOREX.  This class is only used after
00125   // extrating sub_8bit_hi sub-registers.  The H sub-registers cannot be copied
00126   // to the full GR8 register class in 64-bit mode, so we cannot allow the
00127   // reigster class inflation.
00128   //
00129   // The GR8_NOREX class is always used in a way that won't be constrained to a
00130   // sub-class, so sub-classes like GR8_ABCD_L are allowed to expand to the
00131   // full GR8 class.
00132   if (RC == &X86::GR8_NOREXRegClass)
00133     return RC;
00134 
00135   const TargetRegisterClass *Super = RC;
00136   TargetRegisterClass::sc_iterator I = RC->getSuperClasses();
00137   do {
00138     switch (Super->getID()) {
00139     case X86::GR8RegClassID:
00140     case X86::GR16RegClassID:
00141     case X86::GR32RegClassID:
00142     case X86::GR64RegClassID:
00143     case X86::FR32RegClassID:
00144     case X86::FR64RegClassID:
00145     case X86::RFP32RegClassID:
00146     case X86::RFP64RegClassID:
00147     case X86::RFP80RegClassID:
00148     case X86::VR128RegClassID:
00149     case X86::VR256RegClassID:
00150       // Don't return a super-class that would shrink the spill size.
00151       // That can happen with the vector and float classes.
00152       if (Super->getSize() == RC->getSize())
00153         return Super;
00154     }
00155     Super = *I++;
00156   } while (Super);
00157   return RC;
00158 }
00159 
00160 const TargetRegisterClass *
00161 X86RegisterInfo::getPointerRegClass(const MachineFunction &MF,
00162                                     unsigned Kind) const {
00163   switch (Kind) {
00164   default: llvm_unreachable("Unexpected Kind in getPointerRegClass!");
00165   case 0: // Normal GPRs.
00166     if (Subtarget.isTarget64BitLP64())
00167       return &X86::GR64RegClass;
00168     return &X86::GR32RegClass;
00169   case 1: // Normal GPRs except the stack pointer (for encoding reasons).
00170     if (Subtarget.isTarget64BitLP64())
00171       return &X86::GR64_NOSPRegClass;
00172     return &X86::GR32_NOSPRegClass;
00173   case 2: // Available for tailcall (not callee-saved GPRs).
00174     if (Subtarget.isTargetWin64())
00175       return &X86::GR64_TCW64RegClass;
00176     else if (Subtarget.is64Bit())
00177       return &X86::GR64_TCRegClass;
00178 
00179     const Function *F = MF.getFunction();
00180     bool hasHipeCC = (F ? F->getCallingConv() == CallingConv::HiPE : false);
00181     if (hasHipeCC)
00182       return &X86::GR32RegClass;
00183     return &X86::GR32_TCRegClass;
00184   }
00185 }
00186 
00187 const TargetRegisterClass *
00188 X86RegisterInfo::getCrossCopyRegClass(const TargetRegisterClass *RC) const {
00189   if (RC == &X86::CCRRegClass) {
00190     if (Is64Bit)
00191       return &X86::GR64RegClass;
00192     else
00193       return &X86::GR32RegClass;
00194   }
00195   return RC;
00196 }
00197 
00198 unsigned
00199 X86RegisterInfo::getRegPressureLimit(const TargetRegisterClass *RC,
00200                                      MachineFunction &MF) const {
00201   const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering();
00202 
00203   unsigned FPDiff = TFI->hasFP(MF) ? 1 : 0;
00204   switch (RC->getID()) {
00205   default:
00206     return 0;
00207   case X86::GR32RegClassID:
00208     return 4 - FPDiff;
00209   case X86::GR64RegClassID:
00210     return 12 - FPDiff;
00211   case X86::VR128RegClassID:
00212     return Subtarget.is64Bit() ? 10 : 4;
00213   case X86::VR64RegClassID:
00214     return 4;
00215   }
00216 }
00217 
00218 const MCPhysReg *
00219 X86RegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
00220   bool HasAVX = Subtarget.hasAVX();
00221   bool HasAVX512 = Subtarget.hasAVX512();
00222 
00223   assert(MF && "MachineFunction required");
00224   switch (MF->getFunction()->getCallingConv()) {
00225   case CallingConv::GHC:
00226   case CallingConv::HiPE:
00227     return CSR_NoRegs_SaveList;
00228   case CallingConv::AnyReg:
00229     if (HasAVX)
00230       return CSR_64_AllRegs_AVX_SaveList;
00231     return CSR_64_AllRegs_SaveList;
00232   case CallingConv::PreserveMost:
00233     return CSR_64_RT_MostRegs_SaveList;
00234   case CallingConv::PreserveAll:
00235     if (HasAVX)
00236       return CSR_64_RT_AllRegs_AVX_SaveList;
00237     return CSR_64_RT_AllRegs_SaveList;
00238   case CallingConv::Intel_OCL_BI: {
00239     if (HasAVX512 && IsWin64)
00240       return CSR_Win64_Intel_OCL_BI_AVX512_SaveList;
00241     if (HasAVX512 && Is64Bit)
00242       return CSR_64_Intel_OCL_BI_AVX512_SaveList;
00243     if (HasAVX && IsWin64)
00244       return CSR_Win64_Intel_OCL_BI_AVX_SaveList;
00245     if (HasAVX && Is64Bit)
00246       return CSR_64_Intel_OCL_BI_AVX_SaveList;
00247     if (!HasAVX && !IsWin64 && Is64Bit)
00248       return CSR_64_Intel_OCL_BI_SaveList;
00249     break;
00250   }
00251   case CallingConv::Cold:
00252     if (Is64Bit)
00253       return CSR_64_MostRegs_SaveList;
00254     break;
00255   default:
00256     break;
00257   }
00258 
00259   bool CallsEHReturn = MF->getMMI().callsEHReturn();
00260   if (Is64Bit) {
00261     if (IsWin64)
00262       return CSR_Win64_SaveList;
00263     if (CallsEHReturn)
00264       return CSR_64EHRet_SaveList;
00265     return CSR_64_SaveList;
00266   }
00267   if (CallsEHReturn)
00268     return CSR_32EHRet_SaveList;
00269   return CSR_32_SaveList;
00270 }
00271 
00272 const uint32_t*
00273 X86RegisterInfo::getCallPreservedMask(CallingConv::ID CC) const {
00274   bool HasAVX = Subtarget.hasAVX();
00275   bool HasAVX512 = Subtarget.hasAVX512();
00276 
00277   switch (CC) {
00278   case CallingConv::GHC:
00279   case CallingConv::HiPE:
00280     return CSR_NoRegs_RegMask;
00281   case CallingConv::AnyReg:
00282     if (HasAVX)
00283       return CSR_64_AllRegs_AVX_RegMask;
00284     return CSR_64_AllRegs_RegMask;
00285   case CallingConv::PreserveMost:
00286     return CSR_64_RT_MostRegs_RegMask;
00287   case CallingConv::PreserveAll:
00288     if (HasAVX)
00289       return CSR_64_RT_AllRegs_AVX_RegMask;
00290     return CSR_64_RT_AllRegs_RegMask;
00291   case CallingConv::Intel_OCL_BI: {
00292     if (HasAVX512 && IsWin64)
00293       return CSR_Win64_Intel_OCL_BI_AVX512_RegMask;
00294     if (HasAVX512 && Is64Bit)
00295       return CSR_64_Intel_OCL_BI_AVX512_RegMask;
00296     if (HasAVX && IsWin64)
00297       return CSR_Win64_Intel_OCL_BI_AVX_RegMask;
00298     if (HasAVX && Is64Bit)
00299       return CSR_64_Intel_OCL_BI_AVX_RegMask;
00300     if (!HasAVX && !IsWin64 && Is64Bit)
00301       return CSR_64_Intel_OCL_BI_RegMask;
00302     break;
00303   }
00304   case CallingConv::Cold:
00305     if (Is64Bit)
00306       return CSR_64_MostRegs_RegMask;
00307     break;
00308   default:
00309     break;
00310   }
00311 
00312   // Unlike getCalleeSavedRegs(), we don't have MMI so we can't check
00313   // callsEHReturn().
00314   if (Is64Bit) {
00315     if (IsWin64)
00316       return CSR_Win64_RegMask;
00317     return CSR_64_RegMask;
00318   }
00319   return CSR_32_RegMask;
00320 }
00321 
00322 const uint32_t*
00323 X86RegisterInfo::getNoPreservedMask() const {
00324   return CSR_NoRegs_RegMask;
00325 }
00326 
00327 BitVector X86RegisterInfo::getReservedRegs(const MachineFunction &MF) const {
00328   BitVector Reserved(getNumRegs());
00329   const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering();
00330 
00331   // Set the stack-pointer register and its aliases as reserved.
00332   for (MCSubRegIterator I(X86::RSP, this, /*IncludeSelf=*/true); I.isValid();
00333        ++I)
00334     Reserved.set(*I);
00335 
00336   // Set the instruction pointer register and its aliases as reserved.
00337   for (MCSubRegIterator I(X86::RIP, this, /*IncludeSelf=*/true); I.isValid();
00338        ++I)
00339     Reserved.set(*I);
00340 
00341   // Set the frame-pointer register and its aliases as reserved if needed.
00342   if (TFI->hasFP(MF)) {
00343     for (MCSubRegIterator I(X86::RBP, this, /*IncludeSelf=*/true); I.isValid();
00344          ++I)
00345       Reserved.set(*I);
00346   }
00347 
00348   // Set the base-pointer register and its aliases as reserved if needed.
00349   if (hasBasePointer(MF)) {
00350     CallingConv::ID CC = MF.getFunction()->getCallingConv();
00351     const uint32_t* RegMask = getCallPreservedMask(CC);
00352     if (MachineOperand::clobbersPhysReg(RegMask, getBaseRegister()))
00353       report_fatal_error(
00354         "Stack realignment in presence of dynamic allocas is not supported with"
00355         "this calling convention.");
00356 
00357     for (MCSubRegIterator I(getBaseRegister(), this, /*IncludeSelf=*/true);
00358          I.isValid(); ++I)
00359       Reserved.set(*I);
00360   }
00361 
00362   // Mark the segment registers as reserved.
00363   Reserved.set(X86::CS);
00364   Reserved.set(X86::SS);
00365   Reserved.set(X86::DS);
00366   Reserved.set(X86::ES);
00367   Reserved.set(X86::FS);
00368   Reserved.set(X86::GS);
00369 
00370   // Mark the floating point stack registers as reserved.
00371   for (unsigned n = 0; n != 8; ++n)
00372     Reserved.set(X86::ST0 + n);
00373 
00374   // Reserve the registers that only exist in 64-bit mode.
00375   if (!Is64Bit) {
00376     // These 8-bit registers are part of the x86-64 extension even though their
00377     // super-registers are old 32-bits.
00378     Reserved.set(X86::SIL);
00379     Reserved.set(X86::DIL);
00380     Reserved.set(X86::BPL);
00381     Reserved.set(X86::SPL);
00382 
00383     for (unsigned n = 0; n != 8; ++n) {
00384       // R8, R9, ...
00385       for (MCRegAliasIterator AI(X86::R8 + n, this, true); AI.isValid(); ++AI)
00386         Reserved.set(*AI);
00387 
00388       // XMM8, XMM9, ...
00389       for (MCRegAliasIterator AI(X86::XMM8 + n, this, true); AI.isValid(); ++AI)
00390         Reserved.set(*AI);
00391     }
00392   }
00393   if (!Is64Bit || !Subtarget.hasAVX512()) {
00394     for (unsigned n = 16; n != 32; ++n) {
00395       for (MCRegAliasIterator AI(X86::XMM0 + n, this, true); AI.isValid(); ++AI)
00396         Reserved.set(*AI);
00397     }
00398   }
00399 
00400   return Reserved;
00401 }
00402 
00403 //===----------------------------------------------------------------------===//
00404 // Stack Frame Processing methods
00405 //===----------------------------------------------------------------------===//
00406 
00407 bool X86RegisterInfo::hasBasePointer(const MachineFunction &MF) const {
00408    const MachineFrameInfo *MFI = MF.getFrameInfo();
00409 
00410    if (!EnableBasePointer)
00411      return false;
00412 
00413    // When we need stack realignment, we can't address the stack from the frame
00414    // pointer.  When we have dynamic allocas or stack-adjusting inline asm, we
00415    // can't address variables from the stack pointer.  MS inline asm can
00416    // reference locals while also adjusting the stack pointer.  When we can't
00417    // use both the SP and the FP, we need a separate base pointer register.
00418    bool CantUseFP = needsStackRealignment(MF);
00419    bool CantUseSP =
00420        MFI->hasVarSizedObjects() || MFI->hasInlineAsmWithSPAdjust();
00421    return CantUseFP && CantUseSP;
00422 }
00423 
00424 bool X86RegisterInfo::canRealignStack(const MachineFunction &MF) const {
00425   if (MF.getFunction()->hasFnAttribute("no-realign-stack"))
00426     return false;
00427 
00428   const MachineFrameInfo *MFI = MF.getFrameInfo();
00429   const MachineRegisterInfo *MRI = &MF.getRegInfo();
00430 
00431   // Stack realignment requires a frame pointer.  If we already started
00432   // register allocation with frame pointer elimination, it is too late now.
00433   if (!MRI->canReserveReg(FramePtr))
00434     return false;
00435 
00436   // If a base pointer is necessary.  Check that it isn't too late to reserve
00437   // it.
00438   if (MFI->hasVarSizedObjects())
00439     return MRI->canReserveReg(BasePtr);
00440   return true;
00441 }
00442 
00443 bool X86RegisterInfo::needsStackRealignment(const MachineFunction &MF) const {
00444   const MachineFrameInfo *MFI = MF.getFrameInfo();
00445   const Function *F = MF.getFunction();
00446   unsigned StackAlign =
00447     MF.getSubtarget().getFrameLowering()->getStackAlignment();
00448   bool requiresRealignment =
00449     ((MFI->getMaxAlignment() > StackAlign) ||
00450      F->getAttributes().hasAttribute(AttributeSet::FunctionIndex,
00451                                      Attribute::StackAlignment));
00452 
00453   // If we've requested that we force align the stack do so now.
00454   if (ForceStackAlign)
00455     return canRealignStack(MF);
00456 
00457   return requiresRealignment && canRealignStack(MF);
00458 }
00459 
00460 bool X86RegisterInfo::hasReservedSpillSlot(const MachineFunction &MF,
00461                                            unsigned Reg, int &FrameIdx) const {
00462   // Since X86 defines assignCalleeSavedSpillSlots which always return true
00463   // this function neither used nor tested.
00464   llvm_unreachable("Unused function on X86. Otherwise need a test case.");
00465 }
00466 
00467 void
00468 X86RegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
00469                                      int SPAdj, unsigned FIOperandNum,
00470                                      RegScavenger *RS) const {
00471   assert(SPAdj == 0 && "Unexpected");
00472 
00473   MachineInstr &MI = *II;
00474   MachineFunction &MF = *MI.getParent()->getParent();
00475   const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering();
00476   int FrameIndex = MI.getOperand(FIOperandNum).getIndex();
00477   unsigned BasePtr;
00478 
00479   unsigned Opc = MI.getOpcode();
00480   bool AfterFPPop = Opc == X86::TAILJMPm64 || Opc == X86::TAILJMPm;
00481   if (hasBasePointer(MF))
00482     BasePtr = (FrameIndex < 0 ? FramePtr : getBaseRegister());
00483   else if (needsStackRealignment(MF))
00484     BasePtr = (FrameIndex < 0 ? FramePtr : StackPtr);
00485   else if (AfterFPPop)
00486     BasePtr = StackPtr;
00487   else
00488     BasePtr = (TFI->hasFP(MF) ? FramePtr : StackPtr);
00489 
00490   // For LEA64_32r when BasePtr is 32-bits (X32) we can use full-size 64-bit
00491   // register as source operand, semantic is the same and destination is
00492   // 32-bits. It saves one byte per lea in code since 0x67 prefix is avoided.
00493   if (Opc == X86::LEA64_32r && X86::GR32RegClass.contains(BasePtr))
00494     BasePtr = getX86SubSuperRegister(BasePtr, MVT::i64, false);
00495 
00496   // This must be part of a four operand memory reference.  Replace the
00497   // FrameIndex with base register with EBP.  Add an offset to the offset.
00498   MI.getOperand(FIOperandNum).ChangeToRegister(BasePtr, false);
00499 
00500   // Now add the frame object offset to the offset from EBP.
00501   int FIOffset;
00502   if (AfterFPPop) {
00503     // Tail call jmp happens after FP is popped.
00504     const MachineFrameInfo *MFI = MF.getFrameInfo();
00505     FIOffset = MFI->getObjectOffset(FrameIndex) - TFI->getOffsetOfLocalArea();
00506   } else
00507     FIOffset = TFI->getFrameIndexOffset(MF, FrameIndex);
00508 
00509   // The frame index format for stackmaps and patchpoints is different from the
00510   // X86 format. It only has a FI and an offset.
00511   if (Opc == TargetOpcode::STACKMAP || Opc == TargetOpcode::PATCHPOINT) {
00512     assert(BasePtr == FramePtr && "Expected the FP as base register");
00513     int64_t Offset = MI.getOperand(FIOperandNum + 1).getImm() + FIOffset;
00514     MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset);
00515     return;
00516   }
00517 
00518   if (MI.getOperand(FIOperandNum+3).isImm()) {
00519     // Offset is a 32-bit integer.
00520     int Imm = (int)(MI.getOperand(FIOperandNum + 3).getImm());
00521     int Offset = FIOffset + Imm;
00522     assert((!Is64Bit || isInt<32>((long long)FIOffset + Imm)) &&
00523            "Requesting 64-bit offset in 32-bit immediate!");
00524     MI.getOperand(FIOperandNum + 3).ChangeToImmediate(Offset);
00525   } else {
00526     // Offset is symbolic. This is extremely rare.
00527     uint64_t Offset = FIOffset +
00528       (uint64_t)MI.getOperand(FIOperandNum+3).getOffset();
00529     MI.getOperand(FIOperandNum + 3).setOffset(Offset);
00530   }
00531 }
00532 
00533 unsigned X86RegisterInfo::getFrameRegister(const MachineFunction &MF) const {
00534   const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering();
00535   return TFI->hasFP(MF) ? FramePtr : StackPtr;
00536 }
00537 
00538 namespace llvm {
00539 unsigned getX86SubSuperRegister(unsigned Reg, MVT::SimpleValueType VT,
00540                                 bool High) {
00541   switch (VT) {
00542   default: llvm_unreachable("Unexpected VT");
00543   case MVT::i8:
00544     if (High) {
00545       switch (Reg) {
00546       default: return getX86SubSuperRegister(Reg, MVT::i64);
00547       case X86::SIL: case X86::SI: case X86::ESI: case X86::RSI:
00548         return X86::SI;
00549       case X86::DIL: case X86::DI: case X86::EDI: case X86::RDI:
00550         return X86::DI;
00551       case X86::BPL: case X86::BP: case X86::EBP: case X86::RBP:
00552         return X86::BP;
00553       case X86::SPL: case X86::SP: case X86::ESP: case X86::RSP:
00554         return X86::SP;
00555       case X86::AH: case X86::AL: case X86::AX: case X86::EAX: case X86::RAX:
00556         return X86::AH;
00557       case X86::DH: case X86::DL: case X86::DX: case X86::EDX: case X86::RDX:
00558         return X86::DH;
00559       case X86::CH: case X86::CL: case X86::CX: case X86::ECX: case X86::RCX:
00560         return X86::CH;
00561       case X86::BH: case X86::BL: case X86::BX: case X86::EBX: case X86::RBX:
00562         return X86::BH;
00563       }
00564     } else {
00565       switch (Reg) {
00566       default: llvm_unreachable("Unexpected register");
00567       case X86::AH: case X86::AL: case X86::AX: case X86::EAX: case X86::RAX:
00568         return X86::AL;
00569       case X86::DH: case X86::DL: case X86::DX: case X86::EDX: case X86::RDX:
00570         return X86::DL;
00571       case X86::CH: case X86::CL: case X86::CX: case X86::ECX: case X86::RCX:
00572         return X86::CL;
00573       case X86::BH: case X86::BL: case X86::BX: case X86::EBX: case X86::RBX:
00574         return X86::BL;
00575       case X86::SIL: case X86::SI: case X86::ESI: case X86::RSI:
00576         return X86::SIL;
00577       case X86::DIL: case X86::DI: case X86::EDI: case X86::RDI:
00578         return X86::DIL;
00579       case X86::BPL: case X86::BP: case X86::EBP: case X86::RBP:
00580         return X86::BPL;
00581       case X86::SPL: case X86::SP: case X86::ESP: case X86::RSP:
00582         return X86::SPL;
00583       case X86::R8B: case X86::R8W: case X86::R8D: case X86::R8:
00584         return X86::R8B;
00585       case X86::R9B: case X86::R9W: case X86::R9D: case X86::R9:
00586         return X86::R9B;
00587       case X86::R10B: case X86::R10W: case X86::R10D: case X86::R10:
00588         return X86::R10B;
00589       case X86::R11B: case X86::R11W: case X86::R11D: case X86::R11:
00590         return X86::R11B;
00591       case X86::R12B: case X86::R12W: case X86::R12D: case X86::R12:
00592         return X86::R12B;
00593       case X86::R13B: case X86::R13W: case X86::R13D: case X86::R13:
00594         return X86::R13B;
00595       case X86::R14B: case X86::R14W: case X86::R14D: case X86::R14:
00596         return X86::R14B;
00597       case X86::R15B: case X86::R15W: case X86::R15D: case X86::R15:
00598         return X86::R15B;
00599       }
00600     }
00601   case MVT::i16:
00602     switch (Reg) {
00603     default: llvm_unreachable("Unexpected register");
00604     case X86::AH: case X86::AL: case X86::AX: case X86::EAX: case X86::RAX:
00605       return X86::AX;
00606     case X86::DH: case X86::DL: case X86::DX: case X86::EDX: case X86::RDX:
00607       return X86::DX;
00608     case X86::CH: case X86::CL: case X86::CX: case X86::ECX: case X86::RCX:
00609       return X86::CX;
00610     case X86::BH: case X86::BL: case X86::BX: case X86::EBX: case X86::RBX:
00611       return X86::BX;
00612     case X86::SIL: case X86::SI: case X86::ESI: case X86::RSI:
00613       return X86::SI;
00614     case X86::DIL: case X86::DI: case X86::EDI: case X86::RDI:
00615       return X86::DI;
00616     case X86::BPL: case X86::BP: case X86::EBP: case X86::RBP:
00617       return X86::BP;
00618     case X86::SPL: case X86::SP: case X86::ESP: case X86::RSP:
00619       return X86::SP;
00620     case X86::R8B: case X86::R8W: case X86::R8D: case X86::R8:
00621       return X86::R8W;
00622     case X86::R9B: case X86::R9W: case X86::R9D: case X86::R9:
00623       return X86::R9W;
00624     case X86::R10B: case X86::R10W: case X86::R10D: case X86::R10:
00625       return X86::R10W;
00626     case X86::R11B: case X86::R11W: case X86::R11D: case X86::R11:
00627       return X86::R11W;
00628     case X86::R12B: case X86::R12W: case X86::R12D: case X86::R12:
00629       return X86::R12W;
00630     case X86::R13B: case X86::R13W: case X86::R13D: case X86::R13:
00631       return X86::R13W;
00632     case X86::R14B: case X86::R14W: case X86::R14D: case X86::R14:
00633       return X86::R14W;
00634     case X86::R15B: case X86::R15W: case X86::R15D: case X86::R15:
00635       return X86::R15W;
00636     }
00637   case MVT::i32:
00638     switch (Reg) {
00639     default: llvm_unreachable("Unexpected register");
00640     case X86::AH: case X86::AL: case X86::AX: case X86::EAX: case X86::RAX:
00641       return X86::EAX;
00642     case X86::DH: case X86::DL: case X86::DX: case X86::EDX: case X86::RDX:
00643       return X86::EDX;
00644     case X86::CH: case X86::CL: case X86::CX: case X86::ECX: case X86::RCX:
00645       return X86::ECX;
00646     case X86::BH: case X86::BL: case X86::BX: case X86::EBX: case X86::RBX:
00647       return X86::EBX;
00648     case X86::SIL: case X86::SI: case X86::ESI: case X86::RSI:
00649       return X86::ESI;
00650     case X86::DIL: case X86::DI: case X86::EDI: case X86::RDI:
00651       return X86::EDI;
00652     case X86::BPL: case X86::BP: case X86::EBP: case X86::RBP:
00653       return X86::EBP;
00654     case X86::SPL: case X86::SP: case X86::ESP: case X86::RSP:
00655       return X86::ESP;
00656     case X86::R8B: case X86::R8W: case X86::R8D: case X86::R8:
00657       return X86::R8D;
00658     case X86::R9B: case X86::R9W: case X86::R9D: case X86::R9:
00659       return X86::R9D;
00660     case X86::R10B: case X86::R10W: case X86::R10D: case X86::R10:
00661       return X86::R10D;
00662     case X86::R11B: case X86::R11W: case X86::R11D: case X86::R11:
00663       return X86::R11D;
00664     case X86::R12B: case X86::R12W: case X86::R12D: case X86::R12:
00665       return X86::R12D;
00666     case X86::R13B: case X86::R13W: case X86::R13D: case X86::R13:
00667       return X86::R13D;
00668     case X86::R14B: case X86::R14W: case X86::R14D: case X86::R14:
00669       return X86::R14D;
00670     case X86::R15B: case X86::R15W: case X86::R15D: case X86::R15:
00671       return X86::R15D;
00672     }
00673   case MVT::i64:
00674     switch (Reg) {
00675     default: llvm_unreachable("Unexpected register");
00676     case X86::AH: case X86::AL: case X86::AX: case X86::EAX: case X86::RAX:
00677       return X86::RAX;
00678     case X86::DH: case X86::DL: case X86::DX: case X86::EDX: case X86::RDX:
00679       return X86::RDX;
00680     case X86::CH: case X86::CL: case X86::CX: case X86::ECX: case X86::RCX:
00681       return X86::RCX;
00682     case X86::BH: case X86::BL: case X86::BX: case X86::EBX: case X86::RBX:
00683       return X86::RBX;
00684     case X86::SIL: case X86::SI: case X86::ESI: case X86::RSI:
00685       return X86::RSI;
00686     case X86::DIL: case X86::DI: case X86::EDI: case X86::RDI:
00687       return X86::RDI;
00688     case X86::BPL: case X86::BP: case X86::EBP: case X86::RBP:
00689       return X86::RBP;
00690     case X86::SPL: case X86::SP: case X86::ESP: case X86::RSP:
00691       return X86::RSP;
00692     case X86::R8B: case X86::R8W: case X86::R8D: case X86::R8:
00693       return X86::R8;
00694     case X86::R9B: case X86::R9W: case X86::R9D: case X86::R9:
00695       return X86::R9;
00696     case X86::R10B: case X86::R10W: case X86::R10D: case X86::R10:
00697       return X86::R10;
00698     case X86::R11B: case X86::R11W: case X86::R11D: case X86::R11:
00699       return X86::R11;
00700     case X86::R12B: case X86::R12W: case X86::R12D: case X86::R12:
00701       return X86::R12;
00702     case X86::R13B: case X86::R13W: case X86::R13D: case X86::R13:
00703       return X86::R13;
00704     case X86::R14B: case X86::R14W: case X86::R14D: case X86::R14:
00705       return X86::R14;
00706     case X86::R15B: case X86::R15W: case X86::R15D: case X86::R15:
00707       return X86::R15;
00708     }
00709   }
00710 }
00711 
00712 unsigned get512BitSuperRegister(unsigned Reg) {
00713   if (Reg >= X86::XMM0 && Reg <= X86::XMM31)
00714     return X86::ZMM0 + (Reg - X86::XMM0);
00715   if (Reg >= X86::YMM0 && Reg <= X86::YMM31)
00716     return X86::ZMM0 + (Reg - X86::YMM0);
00717   if (Reg >= X86::ZMM0 && Reg <= X86::ZMM31)
00718     return Reg;
00719   llvm_unreachable("Unexpected SIMD register");
00720 }
00721 
00722 }