xref: /freebsd/contrib/llvm-project/llvm/lib/Target/Hexagon/HexagonRegisterInfo.cpp (revision 8bcb0991864975618c09697b1aca10683346d9f0)
10b57cec5SDimitry Andric //===-- HexagonRegisterInfo.cpp - Hexagon Register Information ------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file contains the Hexagon implementation of the TargetRegisterInfo
100b57cec5SDimitry Andric // class.
110b57cec5SDimitry Andric //
120b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric #include "HexagonRegisterInfo.h"
150b57cec5SDimitry Andric #include "Hexagon.h"
160b57cec5SDimitry Andric #include "HexagonMachineFunctionInfo.h"
170b57cec5SDimitry Andric #include "HexagonSubtarget.h"
180b57cec5SDimitry Andric #include "HexagonTargetMachine.h"
190b57cec5SDimitry Andric #include "llvm/ADT/BitVector.h"
200b57cec5SDimitry Andric #include "llvm/ADT/STLExtras.h"
210b57cec5SDimitry Andric #include "llvm/CodeGen/LiveIntervals.h"
220b57cec5SDimitry Andric #include "llvm/CodeGen/MachineFrameInfo.h"
230b57cec5SDimitry Andric #include "llvm/CodeGen/MachineFunction.h"
240b57cec5SDimitry Andric #include "llvm/CodeGen/MachineFunctionPass.h"
250b57cec5SDimitry Andric #include "llvm/CodeGen/MachineInstrBuilder.h"
260b57cec5SDimitry Andric #include "llvm/CodeGen/MachineRegisterInfo.h"
270b57cec5SDimitry Andric #include "llvm/CodeGen/PseudoSourceValue.h"
280b57cec5SDimitry Andric #include "llvm/CodeGen/RegisterScavenging.h"
290b57cec5SDimitry Andric #include "llvm/CodeGen/TargetInstrInfo.h"
300b57cec5SDimitry Andric #include "llvm/IR/Function.h"
310b57cec5SDimitry Andric #include "llvm/IR/Type.h"
320b57cec5SDimitry Andric #include "llvm/MC/MachineLocation.h"
330b57cec5SDimitry Andric #include "llvm/Support/Debug.h"
340b57cec5SDimitry Andric #include "llvm/Support/ErrorHandling.h"
350b57cec5SDimitry Andric #include "llvm/Support/raw_ostream.h"
360b57cec5SDimitry Andric #include "llvm/Target/TargetMachine.h"
370b57cec5SDimitry Andric #include "llvm/Target/TargetOptions.h"
380b57cec5SDimitry Andric 
390b57cec5SDimitry Andric #define GET_REGINFO_TARGET_DESC
400b57cec5SDimitry Andric #include "HexagonGenRegisterInfo.inc"
410b57cec5SDimitry Andric 
420b57cec5SDimitry Andric using namespace llvm;
430b57cec5SDimitry Andric 
440b57cec5SDimitry Andric HexagonRegisterInfo::HexagonRegisterInfo(unsigned HwMode)
450b57cec5SDimitry Andric     : HexagonGenRegisterInfo(Hexagon::R31, 0/*DwarfFlavor*/, 0/*EHFlavor*/,
460b57cec5SDimitry Andric                              0/*PC*/, HwMode) {}
470b57cec5SDimitry Andric 
480b57cec5SDimitry Andric 
490b57cec5SDimitry Andric bool HexagonRegisterInfo::isEHReturnCalleeSaveReg(unsigned R) const {
500b57cec5SDimitry Andric   return R == Hexagon::R0 || R == Hexagon::R1 || R == Hexagon::R2 ||
510b57cec5SDimitry Andric          R == Hexagon::R3 || R == Hexagon::D0 || R == Hexagon::D1;
520b57cec5SDimitry Andric }
530b57cec5SDimitry Andric 
540b57cec5SDimitry Andric const MCPhysReg *
550b57cec5SDimitry Andric HexagonRegisterInfo::getCallerSavedRegs(const MachineFunction *MF,
560b57cec5SDimitry Andric       const TargetRegisterClass *RC) const {
570b57cec5SDimitry Andric   using namespace Hexagon;
580b57cec5SDimitry Andric 
590b57cec5SDimitry Andric   static const MCPhysReg Int32[] = {
600b57cec5SDimitry Andric     R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15, 0
610b57cec5SDimitry Andric   };
620b57cec5SDimitry Andric   static const MCPhysReg Int64[] = {
630b57cec5SDimitry Andric     D0, D1, D2, D3, D4, D5, D6, D7, 0
640b57cec5SDimitry Andric   };
650b57cec5SDimitry Andric   static const MCPhysReg Pred[] = {
660b57cec5SDimitry Andric     P0, P1, P2, P3, 0
670b57cec5SDimitry Andric   };
680b57cec5SDimitry Andric   static const MCPhysReg VecSgl[] = {
690b57cec5SDimitry Andric      V0,  V1,  V2,  V3,  V4,  V5,  V6,  V7,  V8,  V9, V10, V11, V12, V13,
700b57cec5SDimitry Andric     V14, V15, V16, V17, V18, V19, V20, V21, V22, V23, V24, V25, V26, V27,
710b57cec5SDimitry Andric     V28, V29, V30, V31,   0
720b57cec5SDimitry Andric   };
730b57cec5SDimitry Andric   static const MCPhysReg VecDbl[] = {
740b57cec5SDimitry Andric     W0, W1, W2, W3, W4, W5, W6, W7, W8, W9, W10, W11, W12, W13, W14, W15, 0
750b57cec5SDimitry Andric   };
760b57cec5SDimitry Andric 
770b57cec5SDimitry Andric   switch (RC->getID()) {
780b57cec5SDimitry Andric     case IntRegsRegClassID:
790b57cec5SDimitry Andric       return Int32;
800b57cec5SDimitry Andric     case DoubleRegsRegClassID:
810b57cec5SDimitry Andric       return Int64;
820b57cec5SDimitry Andric     case PredRegsRegClassID:
830b57cec5SDimitry Andric       return Pred;
840b57cec5SDimitry Andric     case HvxVRRegClassID:
850b57cec5SDimitry Andric       return VecSgl;
860b57cec5SDimitry Andric     case HvxWRRegClassID:
870b57cec5SDimitry Andric       return VecDbl;
880b57cec5SDimitry Andric     default:
890b57cec5SDimitry Andric       break;
900b57cec5SDimitry Andric   }
910b57cec5SDimitry Andric 
920b57cec5SDimitry Andric   static const MCPhysReg Empty[] = { 0 };
930b57cec5SDimitry Andric #ifndef NDEBUG
940b57cec5SDimitry Andric   dbgs() << "Register class: " << getRegClassName(RC) << "\n";
950b57cec5SDimitry Andric #endif
960b57cec5SDimitry Andric   llvm_unreachable("Unexpected register class");
970b57cec5SDimitry Andric   return Empty;
980b57cec5SDimitry Andric }
990b57cec5SDimitry Andric 
1000b57cec5SDimitry Andric 
1010b57cec5SDimitry Andric const MCPhysReg *
1020b57cec5SDimitry Andric HexagonRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
1030b57cec5SDimitry Andric   static const MCPhysReg CalleeSavedRegsV3[] = {
1040b57cec5SDimitry Andric     Hexagon::R16,   Hexagon::R17,   Hexagon::R18,   Hexagon::R19,
1050b57cec5SDimitry Andric     Hexagon::R20,   Hexagon::R21,   Hexagon::R22,   Hexagon::R23,
1060b57cec5SDimitry Andric     Hexagon::R24,   Hexagon::R25,   Hexagon::R26,   Hexagon::R27, 0
1070b57cec5SDimitry Andric   };
1080b57cec5SDimitry Andric 
1090b57cec5SDimitry Andric   // Functions that contain a call to __builtin_eh_return also save the first 4
1100b57cec5SDimitry Andric   // parameter registers.
1110b57cec5SDimitry Andric   static const MCPhysReg CalleeSavedRegsV3EHReturn[] = {
1120b57cec5SDimitry Andric     Hexagon::R0,    Hexagon::R1,    Hexagon::R2,    Hexagon::R3,
1130b57cec5SDimitry Andric     Hexagon::R16,   Hexagon::R17,   Hexagon::R18,   Hexagon::R19,
1140b57cec5SDimitry Andric     Hexagon::R20,   Hexagon::R21,   Hexagon::R22,   Hexagon::R23,
1150b57cec5SDimitry Andric     Hexagon::R24,   Hexagon::R25,   Hexagon::R26,   Hexagon::R27, 0
1160b57cec5SDimitry Andric   };
1170b57cec5SDimitry Andric 
1180b57cec5SDimitry Andric   bool HasEHReturn = MF->getInfo<HexagonMachineFunctionInfo>()->hasEHReturn();
1190b57cec5SDimitry Andric 
1200b57cec5SDimitry Andric   return HasEHReturn ? CalleeSavedRegsV3EHReturn : CalleeSavedRegsV3;
1210b57cec5SDimitry Andric }
1220b57cec5SDimitry Andric 
1230b57cec5SDimitry Andric 
1240b57cec5SDimitry Andric const uint32_t *HexagonRegisterInfo::getCallPreservedMask(
1250b57cec5SDimitry Andric       const MachineFunction &MF, CallingConv::ID) const {
1260b57cec5SDimitry Andric   return HexagonCSR_RegMask;
1270b57cec5SDimitry Andric }
1280b57cec5SDimitry Andric 
1290b57cec5SDimitry Andric 
1300b57cec5SDimitry Andric BitVector HexagonRegisterInfo::getReservedRegs(const MachineFunction &MF)
1310b57cec5SDimitry Andric   const {
1320b57cec5SDimitry Andric   BitVector Reserved(getNumRegs());
1330b57cec5SDimitry Andric   Reserved.set(Hexagon::R29);
1340b57cec5SDimitry Andric   Reserved.set(Hexagon::R30);
1350b57cec5SDimitry Andric   Reserved.set(Hexagon::R31);
1360b57cec5SDimitry Andric   Reserved.set(Hexagon::VTMP);
1370b57cec5SDimitry Andric 
1380b57cec5SDimitry Andric   // Guest registers.
1390b57cec5SDimitry Andric   Reserved.set(Hexagon::GELR);        // G0
1400b57cec5SDimitry Andric   Reserved.set(Hexagon::GSR);         // G1
1410b57cec5SDimitry Andric   Reserved.set(Hexagon::GOSP);        // G2
1420b57cec5SDimitry Andric   Reserved.set(Hexagon::G3);          // G3
1430b57cec5SDimitry Andric 
1440b57cec5SDimitry Andric   // Control registers.
1450b57cec5SDimitry Andric   Reserved.set(Hexagon::SA0);         // C0
1460b57cec5SDimitry Andric   Reserved.set(Hexagon::LC0);         // C1
1470b57cec5SDimitry Andric   Reserved.set(Hexagon::SA1);         // C2
1480b57cec5SDimitry Andric   Reserved.set(Hexagon::LC1);         // C3
1490b57cec5SDimitry Andric   Reserved.set(Hexagon::P3_0);        // C4
1500b57cec5SDimitry Andric   Reserved.set(Hexagon::USR);         // C8
1510b57cec5SDimitry Andric   Reserved.set(Hexagon::PC);          // C9
1520b57cec5SDimitry Andric   Reserved.set(Hexagon::UGP);         // C10
1530b57cec5SDimitry Andric   Reserved.set(Hexagon::GP);          // C11
1540b57cec5SDimitry Andric   Reserved.set(Hexagon::CS0);         // C12
1550b57cec5SDimitry Andric   Reserved.set(Hexagon::CS1);         // C13
1560b57cec5SDimitry Andric   Reserved.set(Hexagon::UPCYCLELO);   // C14
1570b57cec5SDimitry Andric   Reserved.set(Hexagon::UPCYCLEHI);   // C15
1580b57cec5SDimitry Andric   Reserved.set(Hexagon::FRAMELIMIT);  // C16
1590b57cec5SDimitry Andric   Reserved.set(Hexagon::FRAMEKEY);    // C17
1600b57cec5SDimitry Andric   Reserved.set(Hexagon::PKTCOUNTLO);  // C18
1610b57cec5SDimitry Andric   Reserved.set(Hexagon::PKTCOUNTHI);  // C19
1620b57cec5SDimitry Andric   Reserved.set(Hexagon::UTIMERLO);    // C30
1630b57cec5SDimitry Andric   Reserved.set(Hexagon::UTIMERHI);    // C31
1640b57cec5SDimitry Andric   // Out of the control registers, only C8 is explicitly defined in
1650b57cec5SDimitry Andric   // HexagonRegisterInfo.td. If others are defined, make sure to add
1660b57cec5SDimitry Andric   // them here as well.
1670b57cec5SDimitry Andric   Reserved.set(Hexagon::C8);
1680b57cec5SDimitry Andric   Reserved.set(Hexagon::USR_OVF);
1690b57cec5SDimitry Andric 
1700b57cec5SDimitry Andric   if (MF.getSubtarget<HexagonSubtarget>().hasReservedR19())
1710b57cec5SDimitry Andric     Reserved.set(Hexagon::R19);
1720b57cec5SDimitry Andric 
1730b57cec5SDimitry Andric   for (int x = Reserved.find_first(); x >= 0; x = Reserved.find_next(x))
1740b57cec5SDimitry Andric     markSuperRegs(Reserved, x);
1750b57cec5SDimitry Andric 
1760b57cec5SDimitry Andric   return Reserved;
1770b57cec5SDimitry Andric }
1780b57cec5SDimitry Andric 
1790b57cec5SDimitry Andric 
1800b57cec5SDimitry Andric void HexagonRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
1810b57cec5SDimitry Andric                                               int SPAdj, unsigned FIOp,
1820b57cec5SDimitry Andric                                               RegScavenger *RS) const {
1830b57cec5SDimitry Andric   //
1840b57cec5SDimitry Andric   // Hexagon_TODO: Do we need to enforce this for Hexagon?
1850b57cec5SDimitry Andric   assert(SPAdj == 0 && "Unexpected");
1860b57cec5SDimitry Andric 
1870b57cec5SDimitry Andric   MachineInstr &MI = *II;
1880b57cec5SDimitry Andric   MachineBasicBlock &MB = *MI.getParent();
1890b57cec5SDimitry Andric   MachineFunction &MF = *MB.getParent();
1900b57cec5SDimitry Andric   auto &HST = MF.getSubtarget<HexagonSubtarget>();
1910b57cec5SDimitry Andric   auto &HII = *HST.getInstrInfo();
1920b57cec5SDimitry Andric   auto &HFI = *HST.getFrameLowering();
1930b57cec5SDimitry Andric 
1940b57cec5SDimitry Andric   unsigned BP = 0;
1950b57cec5SDimitry Andric   int FI = MI.getOperand(FIOp).getIndex();
1960b57cec5SDimitry Andric   // Select the base pointer (BP) and calculate the actual offset from BP
1970b57cec5SDimitry Andric   // to the beginning of the object at index FI.
1980b57cec5SDimitry Andric   int Offset = HFI.getFrameIndexReference(MF, FI, BP);
1990b57cec5SDimitry Andric   // Add the offset from the instruction.
2000b57cec5SDimitry Andric   int RealOffset = Offset + MI.getOperand(FIOp+1).getImm();
2010b57cec5SDimitry Andric   bool IsKill = false;
2020b57cec5SDimitry Andric 
2030b57cec5SDimitry Andric   unsigned Opc = MI.getOpcode();
2040b57cec5SDimitry Andric   switch (Opc) {
2050b57cec5SDimitry Andric     case Hexagon::PS_fia:
2060b57cec5SDimitry Andric       MI.setDesc(HII.get(Hexagon::A2_addi));
2070b57cec5SDimitry Andric       MI.getOperand(FIOp).ChangeToImmediate(RealOffset);
2080b57cec5SDimitry Andric       MI.RemoveOperand(FIOp+1);
2090b57cec5SDimitry Andric       return;
2100b57cec5SDimitry Andric     case Hexagon::PS_fi:
2110b57cec5SDimitry Andric       // Set up the instruction for updating below.
2120b57cec5SDimitry Andric       MI.setDesc(HII.get(Hexagon::A2_addi));
2130b57cec5SDimitry Andric       break;
2140b57cec5SDimitry Andric   }
2150b57cec5SDimitry Andric 
2160b57cec5SDimitry Andric   if (!HII.isValidOffset(Opc, RealOffset, this)) {
2170b57cec5SDimitry Andric     // If the offset is not valid, calculate the address in a temporary
2180b57cec5SDimitry Andric     // register and use it with offset 0.
2190b57cec5SDimitry Andric     auto &MRI = MF.getRegInfo();
220*8bcb0991SDimitry Andric     Register TmpR = MRI.createVirtualRegister(&Hexagon::IntRegsRegClass);
2210b57cec5SDimitry Andric     const DebugLoc &DL = MI.getDebugLoc();
2220b57cec5SDimitry Andric     BuildMI(MB, II, DL, HII.get(Hexagon::A2_addi), TmpR)
2230b57cec5SDimitry Andric       .addReg(BP)
2240b57cec5SDimitry Andric       .addImm(RealOffset);
2250b57cec5SDimitry Andric     BP = TmpR;
2260b57cec5SDimitry Andric     RealOffset = 0;
2270b57cec5SDimitry Andric     IsKill = true;
2280b57cec5SDimitry Andric   }
2290b57cec5SDimitry Andric 
2300b57cec5SDimitry Andric   MI.getOperand(FIOp).ChangeToRegister(BP, false, false, IsKill);
2310b57cec5SDimitry Andric   MI.getOperand(FIOp+1).ChangeToImmediate(RealOffset);
2320b57cec5SDimitry Andric }
2330b57cec5SDimitry Andric 
2340b57cec5SDimitry Andric 
2350b57cec5SDimitry Andric bool HexagonRegisterInfo::shouldCoalesce(MachineInstr *MI,
2360b57cec5SDimitry Andric       const TargetRegisterClass *SrcRC, unsigned SubReg,
2370b57cec5SDimitry Andric       const TargetRegisterClass *DstRC, unsigned DstSubReg,
2380b57cec5SDimitry Andric       const TargetRegisterClass *NewRC, LiveIntervals &LIS) const {
2390b57cec5SDimitry Andric   // Coalescing will extend the live interval of the destination register.
2400b57cec5SDimitry Andric   // If the destination register is a vector pair, avoid introducing function
2410b57cec5SDimitry Andric   // calls into the interval, since it could result in a spilling of a pair
2420b57cec5SDimitry Andric   // instead of a single vector.
2430b57cec5SDimitry Andric   MachineFunction &MF = *MI->getParent()->getParent();
2440b57cec5SDimitry Andric   const HexagonSubtarget &HST = MF.getSubtarget<HexagonSubtarget>();
2450b57cec5SDimitry Andric   if (!HST.useHVXOps() || NewRC->getID() != Hexagon::HvxWRRegClass.getID())
2460b57cec5SDimitry Andric     return true;
2470b57cec5SDimitry Andric   bool SmallSrc = SrcRC->getID() == Hexagon::HvxVRRegClass.getID();
2480b57cec5SDimitry Andric   bool SmallDst = DstRC->getID() == Hexagon::HvxVRRegClass.getID();
2490b57cec5SDimitry Andric   if (!SmallSrc && !SmallDst)
2500b57cec5SDimitry Andric     return true;
2510b57cec5SDimitry Andric 
252*8bcb0991SDimitry Andric   Register DstReg = MI->getOperand(0).getReg();
253*8bcb0991SDimitry Andric   Register SrcReg = MI->getOperand(1).getReg();
2540b57cec5SDimitry Andric   const SlotIndexes &Indexes = *LIS.getSlotIndexes();
2550b57cec5SDimitry Andric   auto HasCall = [&Indexes] (const LiveInterval::Segment &S) {
2560b57cec5SDimitry Andric     for (SlotIndex I = S.start.getBaseIndex(), E = S.end.getBaseIndex();
2570b57cec5SDimitry Andric          I != E; I = I.getNextIndex()) {
2580b57cec5SDimitry Andric       if (const MachineInstr *MI = Indexes.getInstructionFromIndex(I))
2590b57cec5SDimitry Andric         if (MI->isCall())
2600b57cec5SDimitry Andric           return true;
2610b57cec5SDimitry Andric     }
2620b57cec5SDimitry Andric     return false;
2630b57cec5SDimitry Andric   };
2640b57cec5SDimitry Andric 
2650b57cec5SDimitry Andric   if (SmallSrc == SmallDst) {
2660b57cec5SDimitry Andric     // Both must be true, because the case for both being false was
2670b57cec5SDimitry Andric     // checked earlier. Both registers will be coalesced into a register
2680b57cec5SDimitry Andric     // of a wider class (HvxWR), and we don't want its live range to
2690b57cec5SDimitry Andric     // span over calls.
2700b57cec5SDimitry Andric     return !any_of(LIS.getInterval(DstReg), HasCall) &&
2710b57cec5SDimitry Andric            !any_of(LIS.getInterval(SrcReg), HasCall);
2720b57cec5SDimitry Andric   }
2730b57cec5SDimitry Andric 
2740b57cec5SDimitry Andric   // If one register is large (HvxWR) and the other is small (HvxVR), then
2750b57cec5SDimitry Andric   // coalescing is ok if the large is already live across a function call,
2760b57cec5SDimitry Andric   // or if the small one is not.
2770b57cec5SDimitry Andric   unsigned SmallReg = SmallSrc ? SrcReg : DstReg;
2780b57cec5SDimitry Andric   unsigned LargeReg = SmallSrc ? DstReg : SrcReg;
2790b57cec5SDimitry Andric   return  any_of(LIS.getInterval(LargeReg), HasCall) ||
2800b57cec5SDimitry Andric          !any_of(LIS.getInterval(SmallReg), HasCall);
2810b57cec5SDimitry Andric }
2820b57cec5SDimitry Andric 
2830b57cec5SDimitry Andric 
2840b57cec5SDimitry Andric unsigned HexagonRegisterInfo::getRARegister() const {
2850b57cec5SDimitry Andric   return Hexagon::R31;
2860b57cec5SDimitry Andric }
2870b57cec5SDimitry Andric 
2880b57cec5SDimitry Andric 
2890b57cec5SDimitry Andric Register HexagonRegisterInfo::getFrameRegister(const MachineFunction
2900b57cec5SDimitry Andric                                                &MF) const {
2910b57cec5SDimitry Andric   const HexagonFrameLowering *TFI = getFrameLowering(MF);
2920b57cec5SDimitry Andric   if (TFI->hasFP(MF))
2930b57cec5SDimitry Andric     return getFrameRegister();
2940b57cec5SDimitry Andric   return getStackRegister();
2950b57cec5SDimitry Andric }
2960b57cec5SDimitry Andric 
2970b57cec5SDimitry Andric 
2980b57cec5SDimitry Andric unsigned HexagonRegisterInfo::getFrameRegister() const {
2990b57cec5SDimitry Andric   return Hexagon::R30;
3000b57cec5SDimitry Andric }
3010b57cec5SDimitry Andric 
3020b57cec5SDimitry Andric 
3030b57cec5SDimitry Andric unsigned HexagonRegisterInfo::getStackRegister() const {
3040b57cec5SDimitry Andric   return Hexagon::R29;
3050b57cec5SDimitry Andric }
3060b57cec5SDimitry Andric 
3070b57cec5SDimitry Andric 
3080b57cec5SDimitry Andric unsigned HexagonRegisterInfo::getHexagonSubRegIndex(
3090b57cec5SDimitry Andric       const TargetRegisterClass &RC, unsigned GenIdx) const {
3100b57cec5SDimitry Andric   assert(GenIdx == Hexagon::ps_sub_lo || GenIdx == Hexagon::ps_sub_hi);
3110b57cec5SDimitry Andric 
3120b57cec5SDimitry Andric   static const unsigned ISub[] = { Hexagon::isub_lo, Hexagon::isub_hi };
3130b57cec5SDimitry Andric   static const unsigned VSub[] = { Hexagon::vsub_lo, Hexagon::vsub_hi };
3140b57cec5SDimitry Andric   static const unsigned WSub[] = { Hexagon::wsub_lo, Hexagon::wsub_hi };
3150b57cec5SDimitry Andric 
3160b57cec5SDimitry Andric   switch (RC.getID()) {
3170b57cec5SDimitry Andric     case Hexagon::CtrRegs64RegClassID:
3180b57cec5SDimitry Andric     case Hexagon::DoubleRegsRegClassID:
3190b57cec5SDimitry Andric       return ISub[GenIdx];
3200b57cec5SDimitry Andric     case Hexagon::HvxWRRegClassID:
3210b57cec5SDimitry Andric       return VSub[GenIdx];
3220b57cec5SDimitry Andric     case Hexagon::HvxVQRRegClassID:
3230b57cec5SDimitry Andric       return WSub[GenIdx];
3240b57cec5SDimitry Andric   }
3250b57cec5SDimitry Andric 
3260b57cec5SDimitry Andric   if (const TargetRegisterClass *SuperRC = *RC.getSuperClasses())
3270b57cec5SDimitry Andric     return getHexagonSubRegIndex(*SuperRC, GenIdx);
3280b57cec5SDimitry Andric 
3290b57cec5SDimitry Andric   llvm_unreachable("Invalid register class");
3300b57cec5SDimitry Andric }
3310b57cec5SDimitry Andric 
3320b57cec5SDimitry Andric bool HexagonRegisterInfo::useFPForScavengingIndex(const MachineFunction &MF)
3330b57cec5SDimitry Andric       const {
3340b57cec5SDimitry Andric   return MF.getSubtarget<HexagonSubtarget>().getFrameLowering()->hasFP(MF);
3350b57cec5SDimitry Andric }
3360b57cec5SDimitry Andric 
3370b57cec5SDimitry Andric const TargetRegisterClass *
3380b57cec5SDimitry Andric HexagonRegisterInfo::getPointerRegClass(const MachineFunction &MF,
3390b57cec5SDimitry Andric                                         unsigned Kind) const {
3400b57cec5SDimitry Andric   return &Hexagon::IntRegsRegClass;
3410b57cec5SDimitry Andric }
3420b57cec5SDimitry Andric 
3430b57cec5SDimitry Andric unsigned HexagonRegisterInfo::getFirstCallerSavedNonParamReg() const {
3440b57cec5SDimitry Andric   return Hexagon::R6;
3450b57cec5SDimitry Andric }
3460b57cec5SDimitry Andric 
347