131d157ae1ac2cd9c787dc3c1d28e64c682803844Jia Liu//===-- HexagonRegisterInfo.cpp - Hexagon Register Information ------------===// 2b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// 3b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// The LLVM Compiler Infrastructure 4b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// 5b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// This file is distributed under the University of Illinois Open Source 6b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// License. See LICENSE.TXT for details. 7b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// 8b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum//===----------------------------------------------------------------------===// 9b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// 10b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// This file contains the Hexagon implementation of the TargetRegisterInfo 11b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// class. 12b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum// 13b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum//===----------------------------------------------------------------------===// 14b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 15b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "HexagonRegisterInfo.h" 1679aa3417eb6f58d668aadfedf075240a41d35a26Craig Topper#include "Hexagon.h" 17b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "HexagonSubtarget.h" 18b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "HexagonTargetMachine.h" 1997e602b574b38d57384f0f877700357531a3d23eJyotsna Verma#include "HexagonMachineFunctionInfo.h" 20f3fd7ee415ec8a6475a060e29959d04d6158f45fBenjamin Kramer#include "llvm/ADT/BitVector.h" 21f3fd7ee415ec8a6475a060e29959d04d6158f45fBenjamin Kramer#include "llvm/ADT/STLExtras.h" 2297e602b574b38d57384f0f877700357531a3d23eJyotsna Verma#include "llvm/CodeGen/MachineInstrBuilder.h" 23b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/CodeGen/MachineFunction.h" 24f3fd7ee415ec8a6475a060e29959d04d6158f45fBenjamin Kramer#include "llvm/CodeGen/MachineFunctionPass.h" 2597e602b574b38d57384f0f877700357531a3d23eJyotsna Verma#include "llvm/CodeGen/MachineFrameInfo.h" 26b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/CodeGen/MachineRegisterInfo.h" 2797e602b574b38d57384f0f877700357531a3d23eJyotsna Verma#include "llvm/CodeGen/PseudoSourceValue.h" 28b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/CodeGen/RegisterScavenging.h" 290b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Function.h" 300b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Type.h" 31b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/MC/MachineLocation.h" 32b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/Target/TargetInstrInfo.h" 33b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/Target/TargetMachine.h" 34b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/Target/TargetOptions.h" 3597e602b574b38d57384f0f877700357531a3d23eJyotsna Verma#include "llvm/Support/CommandLine.h" 3697e602b574b38d57384f0f877700357531a3d23eJyotsna Verma#include "llvm/Support/ErrorHandling.h" 37b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 38b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumusing namespace llvm; 39b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 40b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 4154a56fad36a32f12709da5f96998336f08524be9Bill WendlingHexagonRegisterInfo::HexagonRegisterInfo(HexagonSubtarget &st) 42b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum : HexagonGenRegisterInfo(Hexagon::R31), 4354a56fad36a32f12709da5f96998336f08524be9Bill Wendling Subtarget(st) { 44b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 45b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 46015f228861ef9b337366f92f637d4e8d624bb006Craig Topperconst uint16_t* HexagonRegisterInfo::getCalleeSavedRegs(const MachineFunction 47b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum *MF) 48b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const { 49015f228861ef9b337366f92f637d4e8d624bb006Craig Topper static const uint16_t CalleeSavedRegsV2[] = { 50015f228861ef9b337366f92f637d4e8d624bb006Craig Topper Hexagon::R24, Hexagon::R25, Hexagon::R26, Hexagon::R27, 0 51b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum }; 52015f228861ef9b337366f92f637d4e8d624bb006Craig Topper static const uint16_t CalleeSavedRegsV3[] = { 53b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19, 54b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23, 55b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Hexagon::R24, Hexagon::R25, Hexagon::R26, Hexagon::R27, 0 56b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum }; 57b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 58b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum switch(Subtarget.getHexagonArchVersion()) { 5927baab62e7d6267d9b18e4665c6bb1b75dae10d4Benjamin Kramer case HexagonSubtarget::V1: 6027baab62e7d6267d9b18e4665c6bb1b75dae10d4Benjamin Kramer break; 61b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case HexagonSubtarget::V2: 62b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return CalleeSavedRegsV2; 63b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case HexagonSubtarget::V3: 64b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case HexagonSubtarget::V4: 657517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande case HexagonSubtarget::V5: 66b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return CalleeSavedRegsV3; 67b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 6827baab62e7d6267d9b18e4665c6bb1b75dae10d4Benjamin Kramer llvm_unreachable("Callee saved registers requested for unknown architecture " 6927baab62e7d6267d9b18e4665c6bb1b75dae10d4Benjamin Kramer "version"); 70b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 71b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 72b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumBitVector HexagonRegisterInfo::getReservedRegs(const MachineFunction &MF) 73b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const { 74b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BitVector Reserved(getNumRegs()); 75b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(HEXAGON_RESERVED_REG_1); 76b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(HEXAGON_RESERVED_REG_2); 77b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(Hexagon::R29); 78b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(Hexagon::R30); 79b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(Hexagon::R31); 80b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(Hexagon::D14); 81b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(Hexagon::D15); 82b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(Hexagon::LC0); 83b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(Hexagon::LC1); 84b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(Hexagon::SA0); 85b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(Hexagon::SA1); 86b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return Reserved; 87b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 88b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 89b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 90b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumconst TargetRegisterClass* const* 91b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumHexagonRegisterInfo::getCalleeSavedRegClasses(const MachineFunction *MF) const { 92b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum static const TargetRegisterClass * const CalleeSavedRegClassesV2[] = { 93b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum &Hexagon::IntRegsRegClass, &Hexagon::IntRegsRegClass, 94b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum &Hexagon::IntRegsRegClass, &Hexagon::IntRegsRegClass, 95b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum }; 96b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum static const TargetRegisterClass * const CalleeSavedRegClassesV3[] = { 97b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum &Hexagon::IntRegsRegClass, &Hexagon::IntRegsRegClass, 98b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum &Hexagon::IntRegsRegClass, &Hexagon::IntRegsRegClass, 99b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum &Hexagon::IntRegsRegClass, &Hexagon::IntRegsRegClass, 100b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum &Hexagon::IntRegsRegClass, &Hexagon::IntRegsRegClass, 101b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum &Hexagon::IntRegsRegClass, &Hexagon::IntRegsRegClass, 102b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum &Hexagon::IntRegsRegClass, &Hexagon::IntRegsRegClass, 103b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum }; 104b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 105b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum switch(Subtarget.getHexagonArchVersion()) { 10627baab62e7d6267d9b18e4665c6bb1b75dae10d4Benjamin Kramer case HexagonSubtarget::V1: 10727baab62e7d6267d9b18e4665c6bb1b75dae10d4Benjamin Kramer break; 108b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case HexagonSubtarget::V2: 109b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return CalleeSavedRegClassesV2; 110b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case HexagonSubtarget::V3: 111b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case HexagonSubtarget::V4: 1127517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande case HexagonSubtarget::V5: 113b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return CalleeSavedRegClassesV3; 114b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 11527baab62e7d6267d9b18e4665c6bb1b75dae10d4Benjamin Kramer llvm_unreachable("Callee saved register classes requested for unknown " 11627baab62e7d6267d9b18e4665c6bb1b75dae10d4Benjamin Kramer "architecture version"); 117b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 118b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 119b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumvoid HexagonRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II, 120108fb3202af6f500073cdbb7be32c25d7a273a2eChad Rosier int SPAdj, unsigned FIOperandNum, 121108fb3202af6f500073cdbb7be32c25d7a273a2eChad Rosier RegScavenger *RS) const { 122b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // 123b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Hexagon_TODO: Do we need to enforce this for Hexagon? 124b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum assert(SPAdj == 0 && "Unexpected"); 125b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 126b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineInstr &MI = *II; 127108fb3202af6f500073cdbb7be32c25d7a273a2eChad Rosier int FrameIndex = MI.getOperand(FIOperandNum).getIndex(); 128b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 129b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Addressable stack objects are accessed using neg. offsets from %fp. 130b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineFunction &MF = *MI.getParent()->getParent(); 13154a56fad36a32f12709da5f96998336f08524be9Bill Wendling const HexagonInstrInfo &TII = 13254a56fad36a32f12709da5f96998336f08524be9Bill Wendling *static_cast<const HexagonInstrInfo*>(MF.getTarget().getInstrInfo()); 133b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum int Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex); 134b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineFrameInfo &MFI = *MF.getFrameInfo(); 135b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 136b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum unsigned FrameReg = getFrameRegister(MF); 137b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering(); 138b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (!TFI->hasFP(MF)) { 139b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // We will not reserve space on the stack for the lr and fp registers. 140b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Offset -= 2 * Hexagon_WordSize; 141b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 142b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 143b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const unsigned FrameSize = MFI.getStackSize(); 144b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 145b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (!MFI.hasVarSizedObjects() && 146b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TII.isValidOffset(MI.getOpcode(), (FrameSize+Offset)) && 147b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum !TII.isSpillPredRegOp(&MI)) { 148b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Replace frame index with a stack pointer reference. 149108fb3202af6f500073cdbb7be32c25d7a273a2eChad Rosier MI.getOperand(FIOperandNum).ChangeToRegister(getStackRegister(), false, 150108fb3202af6f500073cdbb7be32c25d7a273a2eChad Rosier false, true); 151108fb3202af6f500073cdbb7be32c25d7a273a2eChad Rosier MI.getOperand(FIOperandNum + 1).ChangeToImmediate(FrameSize+Offset); 152b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } else { 153b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Replace frame index with a frame pointer reference. 154b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (!TII.isValidOffset(MI.getOpcode(), Offset)) { 155b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 156b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // If the offset overflows, then correct it. 157b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // 158b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // For loads, we do not need a reserved register 159b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // r0 = memw(r30 + #10000) to: 160b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // 161b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // r0 = add(r30, #10000) 162b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // r0 = memw(r0) 163b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if ( (MI.getOpcode() == Hexagon::LDriw) || 1647517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande (MI.getOpcode() == Hexagon::LDrid) || 1657517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande (MI.getOpcode() == Hexagon::LDrih) || 1667517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande (MI.getOpcode() == Hexagon::LDriuh) || 1677517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande (MI.getOpcode() == Hexagon::LDrib) || 1687517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande (MI.getOpcode() == Hexagon::LDriub) || 1697517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande (MI.getOpcode() == Hexagon::LDriw_f) || 1707517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande (MI.getOpcode() == Hexagon::LDrid_f)) { 171b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum unsigned dstReg = (MI.getOpcode() == Hexagon::LDrid) ? 1726c823822cdab902e8ecc52603f9c24a0e4b95d42Jakob Stoklund Olesen getSubReg(MI.getOperand(0).getReg(), Hexagon::subreg_loreg) : 173b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI.getOperand(0).getReg(); 174b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 175b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Check if offset can fit in addi. 176b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (!TII.isValidOffset(Hexagon::ADD_ri, Offset)) { 177b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(*MI.getParent(), II, MI.getDebugLoc(), 178b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TII.get(Hexagon::CONST32_Int_Real), dstReg).addImm(Offset); 179b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(*MI.getParent(), II, MI.getDebugLoc(), 180b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TII.get(Hexagon::ADD_rr), 181b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum dstReg).addReg(FrameReg).addReg(dstReg); 182b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } else { 183b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(*MI.getParent(), II, MI.getDebugLoc(), 184b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TII.get(Hexagon::ADD_ri), 185b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum dstReg).addReg(FrameReg).addImm(Offset); 186b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 187b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 188108fb3202af6f500073cdbb7be32c25d7a273a2eChad Rosier MI.getOperand(FIOperandNum).ChangeToRegister(dstReg, false, false,true); 189108fb3202af6f500073cdbb7be32c25d7a273a2eChad Rosier MI.getOperand(FIOperandNum+1).ChangeToImmediate(0); 1907517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande } else if ((MI.getOpcode() == Hexagon::STriw_indexed) || 1917517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande (MI.getOpcode() == Hexagon::STriw) || 192b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum (MI.getOpcode() == Hexagon::STrid) || 193b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum (MI.getOpcode() == Hexagon::STrih) || 1947517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande (MI.getOpcode() == Hexagon::STrib) || 1957517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande (MI.getOpcode() == Hexagon::STrid_f) || 1967517bbc91ae1c60d3c7df8b11642c7a5bb3d5a71Sirish Pande (MI.getOpcode() == Hexagon::STriw_f)) { 197b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // For stores, we need a reserved register. Change 198b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // memw(r30 + #10000) = r0 to: 199b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // 200b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // rs = add(r30, #10000); 201b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // memw(rs) = r0 202b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum unsigned resReg = HEXAGON_RESERVED_REG_1; 203b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 204b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Check if offset can fit in addi. 205b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (!TII.isValidOffset(Hexagon::ADD_ri, Offset)) { 206b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(*MI.getParent(), II, MI.getDebugLoc(), 207b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TII.get(Hexagon::CONST32_Int_Real), resReg).addImm(Offset); 208b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(*MI.getParent(), II, MI.getDebugLoc(), 209b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TII.get(Hexagon::ADD_rr), 210b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum resReg).addReg(FrameReg).addReg(resReg); 211b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } else { 212b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(*MI.getParent(), II, MI.getDebugLoc(), 213b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TII.get(Hexagon::ADD_ri), 214b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum resReg).addReg(FrameReg).addImm(Offset); 215b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 216108fb3202af6f500073cdbb7be32c25d7a273a2eChad Rosier MI.getOperand(FIOperandNum).ChangeToRegister(resReg, false, false,true); 217108fb3202af6f500073cdbb7be32c25d7a273a2eChad Rosier MI.getOperand(FIOperandNum+1).ChangeToImmediate(0); 218b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } else if (TII.isMemOp(&MI)) { 21997e602b574b38d57384f0f877700357531a3d23eJyotsna Verma // use the constant extender if the instruction provides it 22097e602b574b38d57384f0f877700357531a3d23eJyotsna Verma // and we are V4TOps. 22197e602b574b38d57384f0f877700357531a3d23eJyotsna Verma if (Subtarget.hasV4TOps()) { 22297e602b574b38d57384f0f877700357531a3d23eJyotsna Verma if (TII.isConstExtended(&MI)) { 22397e602b574b38d57384f0f877700357531a3d23eJyotsna Verma MI.getOperand(FIOperandNum).ChangeToRegister(FrameReg, false); 22497e602b574b38d57384f0f877700357531a3d23eJyotsna Verma MI.getOperand(FIOperandNum+1).ChangeToImmediate(Offset); 22597e602b574b38d57384f0f877700357531a3d23eJyotsna Verma TII.immediateExtend(&MI); 22697e602b574b38d57384f0f877700357531a3d23eJyotsna Verma } else { 22797e602b574b38d57384f0f877700357531a3d23eJyotsna Verma llvm_unreachable("Need to implement for memops"); 22897e602b574b38d57384f0f877700357531a3d23eJyotsna Verma } 229b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } else { 23097e602b574b38d57384f0f877700357531a3d23eJyotsna Verma // Only V3 and older instructions here. 23197e602b574b38d57384f0f877700357531a3d23eJyotsna Verma unsigned ResReg = HEXAGON_RESERVED_REG_1; 23297e602b574b38d57384f0f877700357531a3d23eJyotsna Verma if (!MFI.hasVarSizedObjects() && 23397e602b574b38d57384f0f877700357531a3d23eJyotsna Verma TII.isValidOffset(MI.getOpcode(), (FrameSize+Offset))) { 23497e602b574b38d57384f0f877700357531a3d23eJyotsna Verma MI.getOperand(FIOperandNum).ChangeToRegister(getStackRegister(), 23597e602b574b38d57384f0f877700357531a3d23eJyotsna Verma false, false, false); 23697e602b574b38d57384f0f877700357531a3d23eJyotsna Verma MI.getOperand(FIOperandNum+1).ChangeToImmediate(FrameSize+Offset); 23797e602b574b38d57384f0f877700357531a3d23eJyotsna Verma } else if (!TII.isValidOffset(Hexagon::ADD_ri, Offset)) { 23897e602b574b38d57384f0f877700357531a3d23eJyotsna Verma BuildMI(*MI.getParent(), II, MI.getDebugLoc(), 23997e602b574b38d57384f0f877700357531a3d23eJyotsna Verma TII.get(Hexagon::CONST32_Int_Real), ResReg).addImm(Offset); 24097e602b574b38d57384f0f877700357531a3d23eJyotsna Verma BuildMI(*MI.getParent(), II, MI.getDebugLoc(), 24197e602b574b38d57384f0f877700357531a3d23eJyotsna Verma TII.get(Hexagon::ADD_rr), ResReg).addReg(FrameReg). 24297e602b574b38d57384f0f877700357531a3d23eJyotsna Verma addReg(ResReg); 24397e602b574b38d57384f0f877700357531a3d23eJyotsna Verma MI.getOperand(FIOperandNum).ChangeToRegister(ResReg, false, false, 24497e602b574b38d57384f0f877700357531a3d23eJyotsna Verma true); 24597e602b574b38d57384f0f877700357531a3d23eJyotsna Verma MI.getOperand(FIOperandNum+1).ChangeToImmediate(0); 24697e602b574b38d57384f0f877700357531a3d23eJyotsna Verma } else { 24797e602b574b38d57384f0f877700357531a3d23eJyotsna Verma BuildMI(*MI.getParent(), II, MI.getDebugLoc(), 24897e602b574b38d57384f0f877700357531a3d23eJyotsna Verma TII.get(Hexagon::ADD_ri), ResReg).addReg(FrameReg). 24997e602b574b38d57384f0f877700357531a3d23eJyotsna Verma addImm(Offset); 25097e602b574b38d57384f0f877700357531a3d23eJyotsna Verma MI.getOperand(FIOperandNum).ChangeToRegister(ResReg, false, false, 25197e602b574b38d57384f0f877700357531a3d23eJyotsna Verma true); 25297e602b574b38d57384f0f877700357531a3d23eJyotsna Verma MI.getOperand(FIOperandNum+1).ChangeToImmediate(0); 25397e602b574b38d57384f0f877700357531a3d23eJyotsna Verma } 254b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 255b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } else { 256b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum unsigned dstReg = MI.getOperand(0).getReg(); 257b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(*MI.getParent(), II, MI.getDebugLoc(), 258b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TII.get(Hexagon::CONST32_Int_Real), dstReg).addImm(Offset); 259b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(*MI.getParent(), II, MI.getDebugLoc(), 260b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TII.get(Hexagon::ADD_rr), 261b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum dstReg).addReg(FrameReg).addReg(dstReg); 262b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Can we delete MI??? r2 = add (r2, #0). 263108fb3202af6f500073cdbb7be32c25d7a273a2eChad Rosier MI.getOperand(FIOperandNum).ChangeToRegister(dstReg, false, false,true); 264108fb3202af6f500073cdbb7be32c25d7a273a2eChad Rosier MI.getOperand(FIOperandNum+1).ChangeToImmediate(0); 265b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 266b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } else { 267b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // If the offset is small enough to fit in the immediate field, directly 268b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // encode it. 269108fb3202af6f500073cdbb7be32c25d7a273a2eChad Rosier MI.getOperand(FIOperandNum).ChangeToRegister(FrameReg, false); 270108fb3202af6f500073cdbb7be32c25d7a273a2eChad Rosier MI.getOperand(FIOperandNum+1).ChangeToImmediate(Offset); 271b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 272b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 273b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 274b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 275b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 276b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumunsigned HexagonRegisterInfo::getRARegister() const { 277b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return Hexagon::R31; 278b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 279b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 280b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumunsigned HexagonRegisterInfo::getFrameRegister(const MachineFunction 281b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum &MF) const { 282b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering(); 283b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (TFI->hasFP(MF)) { 284b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return Hexagon::R30; 285b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 286b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 287b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return Hexagon::R29; 288b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 289b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 290b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumunsigned HexagonRegisterInfo::getFrameRegister() const { 291b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return Hexagon::R30; 292b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 293b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 294b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumunsigned HexagonRegisterInfo::getStackRegister() const { 295b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return Hexagon::R29; 296b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 297b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 298b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumunsigned HexagonRegisterInfo::getEHExceptionRegister() const { 299bc2198133a1836598b54b943420748e75d5dea94Craig Topper llvm_unreachable("What is the exception register"); 300b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 301b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 302b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumunsigned HexagonRegisterInfo::getEHHandlerRegister() const { 303bc2198133a1836598b54b943420748e75d5dea94Craig Topper llvm_unreachable("What is the exception handler register"); 304b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 305b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 306d239ff67f210094c205be7e57332948caecf6a24Tony Linthicum#define GET_REGINFO_TARGET_DESC 307b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "HexagonGenRegisterInfo.inc" 308