HexagonRegisterInfo.cpp revision 27baab62e7d6267d9b18e4665c6bb1b75dae10d4
1b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum//==- HexagonRegisterInfo.cpp - Hexagon Register Information -----*- C++ -*-==// 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 "Hexagon.h" 16b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "HexagonRegisterInfo.h" 17b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "HexagonSubtarget.h" 18b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "HexagonTargetMachine.h" 19b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "HexagonMachineFunctionInfo.h" 20b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/CodeGen/MachineInstrBuilder.h" 21b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/CodeGen/MachineFunction.h" 22b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/CodeGen/MachineFrameInfo.h" 23b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/CodeGen/MachineRegisterInfo.h" 24b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/CodeGen/RegisterScavenging.h" 25b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/MC/MachineLocation.h" 26b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/Target/TargetInstrInfo.h" 27b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/Type.h" 28b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/ADT/BitVector.h" 29b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/ADT/STLExtras.h" 30b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/Support/CommandLine.h" 31b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/Support/ErrorHandling.h" 32b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/Target/TargetMachine.h" 33b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/Target/TargetOptions.h" 34b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include <iostream> 35b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 36b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/CodeGen/MachineFunctionPass.h" 37b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "llvm/Function.h" 38b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumusing namespace llvm; 39b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 40b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 41b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumHexagonRegisterInfo::HexagonRegisterInfo(HexagonSubtarget &st, 42b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const HexagonInstrInfo &tii) 43b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum : HexagonGenRegisterInfo(Hexagon::R31), 44b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Subtarget(st), 45b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TII(tii) { 46b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 47b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 48b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumconst unsigned* HexagonRegisterInfo::getCalleeSavedRegs(const MachineFunction 49b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum *MF) 50b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const { 51b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum static const unsigned CalleeSavedRegsV2[] = { 52b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Hexagon::R24, Hexagon::R25, Hexagon::R26, Hexagon::R27, 0 53b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum }; 54b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum static const unsigned CalleeSavedRegsV3[] = { 55b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19, 56b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23, 57b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Hexagon::R24, Hexagon::R25, Hexagon::R26, Hexagon::R27, 0 58b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum }; 59b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 60b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum switch(Subtarget.getHexagonArchVersion()) { 6127baab62e7d6267d9b18e4665c6bb1b75dae10d4Benjamin Kramer case HexagonSubtarget::V1: 6227baab62e7d6267d9b18e4665c6bb1b75dae10d4Benjamin Kramer break; 63b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case HexagonSubtarget::V2: 64b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return CalleeSavedRegsV2; 65b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case HexagonSubtarget::V3: 66b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case HexagonSubtarget::V4: 67b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return CalleeSavedRegsV3; 68b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 6927baab62e7d6267d9b18e4665c6bb1b75dae10d4Benjamin Kramer llvm_unreachable("Callee saved registers requested for unknown architecture " 7027baab62e7d6267d9b18e4665c6bb1b75dae10d4Benjamin Kramer "version"); 71b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 72b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 73b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumBitVector HexagonRegisterInfo::getReservedRegs(const MachineFunction &MF) 74b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const { 75b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BitVector Reserved(getNumRegs()); 76b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(HEXAGON_RESERVED_REG_1); 77b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(HEXAGON_RESERVED_REG_2); 78b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(Hexagon::R29); 79b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(Hexagon::R30); 80b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(Hexagon::R31); 81b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(Hexagon::D14); 82b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(Hexagon::D15); 83b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(Hexagon::LC0); 84b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(Hexagon::LC1); 85b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(Hexagon::SA0); 86b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Reserved.set(Hexagon::SA1); 87b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return Reserved; 88b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 89b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 90b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 91b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumconst TargetRegisterClass* const* 92b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumHexagonRegisterInfo::getCalleeSavedRegClasses(const MachineFunction *MF) const { 93b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum static const TargetRegisterClass * const CalleeSavedRegClassesV2[] = { 94b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum &Hexagon::IntRegsRegClass, &Hexagon::IntRegsRegClass, 95b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum &Hexagon::IntRegsRegClass, &Hexagon::IntRegsRegClass, 96b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum }; 97b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum static const TargetRegisterClass * const CalleeSavedRegClassesV3[] = { 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 &Hexagon::IntRegsRegClass, &Hexagon::IntRegsRegClass, 104b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum }; 105b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 106b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum switch(Subtarget.getHexagonArchVersion()) { 10727baab62e7d6267d9b18e4665c6bb1b75dae10d4Benjamin Kramer case HexagonSubtarget::V1: 10827baab62e7d6267d9b18e4665c6bb1b75dae10d4Benjamin Kramer break; 109b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case HexagonSubtarget::V2: 110b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return CalleeSavedRegClassesV2; 111b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case HexagonSubtarget::V3: 112b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum case HexagonSubtarget::V4: 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:: 120b4b54153ad760c69a00a08531abef4ed434a5092Tony LinthicumeliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, 121b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineBasicBlock::iterator I) const { 122b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineInstr &MI = *I; 123b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 124b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (MI.getOpcode() == Hexagon::ADJCALLSTACKDOWN) { 125b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Hexagon_TODO: add code 126b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } else if (MI.getOpcode() == Hexagon::ADJCALLSTACKUP) { 127b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Hexagon_TODO: add code 128b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } else { 129b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum assert(0 && "Cannot handle this call frame pseudo instruction"); 130b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 131b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MBB.erase(I); 132b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 133b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 134b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumvoid HexagonRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II, 135b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum int SPAdj, RegScavenger *RS) const { 136b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 137b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // 138b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Hexagon_TODO: Do we need to enforce this for Hexagon? 139b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum assert(SPAdj == 0 && "Unexpected"); 140b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 141b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 142b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum unsigned i = 0; 143b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineInstr &MI = *II; 144b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum while (!MI.getOperand(i).isFI()) { 145b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum ++i; 146b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!"); 147b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 148b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 149b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum int FrameIndex = MI.getOperand(i).getIndex(); 150b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 151b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Addressable stack objects are accessed using neg. offsets from %fp. 152b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineFunction &MF = *MI.getParent()->getParent(); 153b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum int Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex); 154b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineFrameInfo &MFI = *MF.getFrameInfo(); 155b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 156b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum unsigned FrameReg = getFrameRegister(MF); 157b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering(); 158b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (!TFI->hasFP(MF)) { 159b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // We will not reserve space on the stack for the lr and fp registers. 160b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Offset -= 2 * Hexagon_WordSize; 161b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 162b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 163b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum const unsigned FrameSize = MFI.getStackSize(); 164b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 165b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (!MFI.hasVarSizedObjects() && 166b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TII.isValidOffset(MI.getOpcode(), (FrameSize+Offset)) && 167b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum !TII.isSpillPredRegOp(&MI)) { 168b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Replace frame index with a stack pointer reference. 169b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI.getOperand(i).ChangeToRegister(getStackRegister(), false, false, true); 170b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI.getOperand(i+1).ChangeToImmediate(FrameSize+Offset); 171b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } else { 172b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Replace frame index with a frame pointer reference. 173b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (!TII.isValidOffset(MI.getOpcode(), Offset)) { 174b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 175b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // If the offset overflows, then correct it. 176b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // 177b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // For loads, we do not need a reserved register 178b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // r0 = memw(r30 + #10000) to: 179b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // 180b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // r0 = add(r30, #10000) 181b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // r0 = memw(r0) 182b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if ( (MI.getOpcode() == Hexagon::LDriw) || 183b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum (MI.getOpcode() == Hexagon::LDrid) || 184b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum (MI.getOpcode() == Hexagon::LDrih) || 185b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum (MI.getOpcode() == Hexagon::LDriuh) || 186b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum (MI.getOpcode() == Hexagon::LDrib) || 187b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum (MI.getOpcode() == Hexagon::LDriub) ) { 188b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum unsigned dstReg = (MI.getOpcode() == Hexagon::LDrid) ? 189b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum *getSubRegisters(MI.getOperand(0).getReg()) : 190b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI.getOperand(0).getReg(); 191b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 192b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Check if offset can fit in addi. 193b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (!TII.isValidOffset(Hexagon::ADD_ri, Offset)) { 194b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(*MI.getParent(), II, MI.getDebugLoc(), 195b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TII.get(Hexagon::CONST32_Int_Real), dstReg).addImm(Offset); 196b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(*MI.getParent(), II, MI.getDebugLoc(), 197b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TII.get(Hexagon::ADD_rr), 198b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum dstReg).addReg(FrameReg).addReg(dstReg); 199b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } else { 200b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(*MI.getParent(), II, MI.getDebugLoc(), 201b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TII.get(Hexagon::ADD_ri), 202b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum dstReg).addReg(FrameReg).addImm(Offset); 203b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 204b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 205b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI.getOperand(i).ChangeToRegister(dstReg, false, false, true); 206b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI.getOperand(i+1).ChangeToImmediate(0); 207b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } else if ((MI.getOpcode() == Hexagon::STriw) || 208b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum (MI.getOpcode() == Hexagon::STrid) || 209b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum (MI.getOpcode() == Hexagon::STrih) || 210b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum (MI.getOpcode() == Hexagon::STrib) || 211b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum (MI.getOpcode() == Hexagon::STriwt)) { 212b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // For stores, we need a reserved register. Change 213b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // memw(r30 + #10000) = r0 to: 214b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // 215b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // rs = add(r30, #10000); 216b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // memw(rs) = r0 217b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum unsigned resReg = HEXAGON_RESERVED_REG_1; 218b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 219b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // Check if offset can fit in addi. 220b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (!TII.isValidOffset(Hexagon::ADD_ri, Offset)) { 221b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(*MI.getParent(), II, MI.getDebugLoc(), 222b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TII.get(Hexagon::CONST32_Int_Real), resReg).addImm(Offset); 223b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(*MI.getParent(), II, MI.getDebugLoc(), 224b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TII.get(Hexagon::ADD_rr), 225b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum resReg).addReg(FrameReg).addReg(resReg); 226b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } else { 227b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(*MI.getParent(), II, MI.getDebugLoc(), 228b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TII.get(Hexagon::ADD_ri), 229b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum resReg).addReg(FrameReg).addImm(Offset); 230b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } 231b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI.getOperand(i).ChangeToRegister(resReg, false, false, true); 232b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI.getOperand(i+1).ChangeToImmediate(0); 233b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } else if (TII.isMemOp(&MI)) { 234b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum unsigned resReg = HEXAGON_RESERVED_REG_1; 235b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum if (!MFI.hasVarSizedObjects() && 236b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TII.isValidOffset(MI.getOpcode(), (FrameSize+Offset))) { 237b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI.getOperand(i).ChangeToRegister(getStackRegister(), false, false, 238b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum true); 239b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI.getOperand(i+1).ChangeToImmediate(FrameSize+Offset); 240b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } else if (!TII.isValidOffset(Hexagon::ADD_ri, Offset)) { 241b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(*MI.getParent(), II, MI.getDebugLoc(), 242b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TII.get(Hexagon::CONST32_Int_Real), resReg).addImm(Offset); 243b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(*MI.getParent(), II, MI.getDebugLoc(), 244b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TII.get(Hexagon::ADD_rr), 245b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum resReg).addReg(FrameReg).addReg(resReg); 246b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI.getOperand(i).ChangeToRegister(resReg, false, false, true); 247b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI.getOperand(i+1).ChangeToImmediate(0); 248b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum } else { 249b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum BuildMI(*MI.getParent(), II, MI.getDebugLoc(), 250b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum TII.get(Hexagon::ADD_ri), 251b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum resReg).addReg(FrameReg).addImm(Offset); 252b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI.getOperand(i).ChangeToRegister(resReg, false, false, true); 253b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI.getOperand(i+1).ChangeToImmediate(0); 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). 263b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI.getOperand(i).ChangeToRegister(dstReg, false, false, true); 264b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI.getOperand(i+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. 269b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI.getOperand(i).ChangeToRegister(FrameReg, false); 270b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MI.getOperand(i+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 Linthicumvoid HexagonRegisterInfo::getInitialFrameState(std::vector<MachineMove> 299b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum &Moves) const 300b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum{ 301b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum // VirtualFP = (R30 + #0). 302b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum unsigned FPReg = getFrameRegister(); 303b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineLocation Dst(MachineLocation::VirtualFP); 304b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum MachineLocation Src(FPReg, 0); 305b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum Moves.push_back(MachineMove(0, Dst, Src)); 306b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 307b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 308b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumunsigned HexagonRegisterInfo::getEHExceptionRegister() const { 309b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum assert(0 && "What is the exception register"); 310b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return 0; 311b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 312b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 313b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicumunsigned HexagonRegisterInfo::getEHHandlerRegister() const { 314b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum assert(0 && "What is the exception handler register"); 315b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum return 0; 316b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum} 317b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum 318d239ff67f210094c205be7e57332948caecf6a24Tony Linthicum#define GET_REGINFO_TARGET_DESC 319b4b54153ad760c69a00a08531abef4ed434a5092Tony Linthicum#include "HexagonGenRegisterInfo.inc" 320