Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 1 | //===-- MipsSEInstrInfo.cpp - Mips32/64 Instruction Information -----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains the Mips32/64 implementation of the TargetInstrInfo class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "MipsSEInstrInfo.h" |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 15 | #include "InstPrinter/MipsInstPrinter.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "MipsMachineFunction.h" |
| 17 | #include "MipsTargetMachine.h" |
| 18 | #include "llvm/ADT/STLExtras.h" |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 20 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Akira Hatanaka | 42f562a | 2013-05-13 18:23:35 +0000 | [diff] [blame] | 21 | #include "llvm/Support/CommandLine.h" |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 22 | #include "llvm/Support/ErrorHandling.h" |
| 23 | #include "llvm/Support/TargetRegistry.h" |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 24 | |
| 25 | using namespace llvm; |
| 26 | |
Akira Hatanaka | 42f562a | 2013-05-13 18:23:35 +0000 | [diff] [blame] | 27 | static cl::opt<bool> NoDPLoadStore("mno-ldc1-sdc1", cl::init(false), |
| 28 | cl::desc("Expand double precision loads and " |
| 29 | "stores to their single precision " |
| 30 | "counterparts.")); |
| 31 | |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 32 | MipsSEInstrInfo::MipsSEInstrInfo(MipsTargetMachine &tm) |
| 33 | : MipsInstrInfo(tm, |
| 34 | tm.getRelocationModel() == Reloc::PIC_ ? Mips::B : Mips::J), |
Bill Wendling | 41e632d | 2013-06-07 07:04:14 +0000 | [diff] [blame] | 35 | RI(*tm.getSubtargetImpl()), |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 36 | IsN64(tm.getSubtarget<MipsSubtarget>().isABI_N64()) {} |
| 37 | |
Akira Hatanaka | 8589010 | 2012-07-31 23:41:32 +0000 | [diff] [blame] | 38 | const MipsRegisterInfo &MipsSEInstrInfo::getRegisterInfo() const { |
| 39 | return RI; |
| 40 | } |
| 41 | |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 42 | /// isLoadFromStackSlot - If the specified machine instruction is a direct |
| 43 | /// load from a stack slot, return the virtual or physical register number of |
| 44 | /// the destination along with the FrameIndex of the loaded stack slot. If |
| 45 | /// not, return 0. This predicate must return 0 if the instruction has |
| 46 | /// any side effects other than loading from the stack slot. |
| 47 | unsigned MipsSEInstrInfo:: |
| 48 | isLoadFromStackSlot(const MachineInstr *MI, int &FrameIndex) const |
| 49 | { |
| 50 | unsigned Opc = MI->getOpcode(); |
| 51 | |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame^] | 52 | if ((Opc == Mips::LW) || (Opc == Mips::LD) || |
| 53 | (Opc == Mips::LWC1) || (Opc == Mips::LDC1) || (Opc == Mips::LDC164)) { |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 54 | if ((MI->getOperand(1).isFI()) && // is a stack slot |
| 55 | (MI->getOperand(2).isImm()) && // the imm is zero |
| 56 | (isZeroImm(MI->getOperand(2)))) { |
| 57 | FrameIndex = MI->getOperand(1).getIndex(); |
| 58 | return MI->getOperand(0).getReg(); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | /// isStoreToStackSlot - If the specified machine instruction is a direct |
| 66 | /// store to a stack slot, return the virtual or physical register number of |
| 67 | /// the source reg along with the FrameIndex of the loaded stack slot. If |
| 68 | /// not, return 0. This predicate must return 0 if the instruction has |
| 69 | /// any side effects other than storing to the stack slot. |
| 70 | unsigned MipsSEInstrInfo:: |
| 71 | isStoreToStackSlot(const MachineInstr *MI, int &FrameIndex) const |
| 72 | { |
| 73 | unsigned Opc = MI->getOpcode(); |
| 74 | |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame^] | 75 | if ((Opc == Mips::SW) || (Opc == Mips::SD) || |
| 76 | (Opc == Mips::SWC1) || (Opc == Mips::SDC1) || (Opc == Mips::SDC164)) { |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 77 | if ((MI->getOperand(1).isFI()) && // is a stack slot |
| 78 | (MI->getOperand(2).isImm()) && // the imm is zero |
| 79 | (isZeroImm(MI->getOperand(2)))) { |
| 80 | FrameIndex = MI->getOperand(1).getIndex(); |
| 81 | return MI->getOperand(0).getReg(); |
| 82 | } |
| 83 | } |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | void MipsSEInstrInfo::copyPhysReg(MachineBasicBlock &MBB, |
| 88 | MachineBasicBlock::iterator I, DebugLoc DL, |
| 89 | unsigned DestReg, unsigned SrcReg, |
| 90 | bool KillSrc) const { |
| 91 | unsigned Opc = 0, ZeroReg = 0; |
| 92 | |
Akira Hatanaka | 1858786 | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 93 | if (Mips::GPR32RegClass.contains(DestReg)) { // Copy to CPU Reg. |
| 94 | if (Mips::GPR32RegClass.contains(SrcReg)) |
Akira Hatanaka | 0b92642 | 2013-07-22 18:52:22 +0000 | [diff] [blame] | 95 | Opc = Mips::ADDu, ZeroReg = Mips::ZERO; |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 96 | else if (Mips::CCRRegClass.contains(SrcReg)) |
| 97 | Opc = Mips::CFC1; |
| 98 | else if (Mips::FGR32RegClass.contains(SrcReg)) |
| 99 | Opc = Mips::MFC1; |
Akira Hatanaka | cbaf6d0 | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 100 | else if (Mips::HI32RegClass.contains(SrcReg)) |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 101 | Opc = Mips::MFHI, SrcReg = 0; |
Akira Hatanaka | cbaf6d0 | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 102 | else if (Mips::LO32RegClass.contains(SrcReg)) |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 103 | Opc = Mips::MFLO, SrcReg = 0; |
Akira Hatanaka | cbaf6d0 | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 104 | else if (Mips::HI32DSPRegClass.contains(SrcReg)) |
Akira Hatanaka | c147c1b | 2013-04-30 23:22:09 +0000 | [diff] [blame] | 105 | Opc = Mips::MFHI_DSP; |
Akira Hatanaka | cbaf6d0 | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 106 | else if (Mips::LO32DSPRegClass.contains(SrcReg)) |
Akira Hatanaka | c147c1b | 2013-04-30 23:22:09 +0000 | [diff] [blame] | 107 | Opc = Mips::MFLO_DSP; |
Akira Hatanaka | 99ad6ac | 2013-05-02 23:07:05 +0000 | [diff] [blame] | 108 | else if (Mips::DSPCCRegClass.contains(SrcReg)) { |
| 109 | BuildMI(MBB, I, DL, get(Mips::RDDSP), DestReg).addImm(1 << 4) |
| 110 | .addReg(SrcReg, RegState::Implicit | getKillRegState(KillSrc)); |
| 111 | return; |
| 112 | } |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 113 | } |
Akira Hatanaka | 1858786 | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 114 | else if (Mips::GPR32RegClass.contains(SrcReg)) { // Copy from CPU Reg. |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 115 | if (Mips::CCRRegClass.contains(DestReg)) |
| 116 | Opc = Mips::CTC1; |
| 117 | else if (Mips::FGR32RegClass.contains(DestReg)) |
| 118 | Opc = Mips::MTC1; |
Akira Hatanaka | cbaf6d0 | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 119 | else if (Mips::HI32RegClass.contains(DestReg)) |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 120 | Opc = Mips::MTHI, DestReg = 0; |
Akira Hatanaka | cbaf6d0 | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 121 | else if (Mips::LO32RegClass.contains(DestReg)) |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 122 | Opc = Mips::MTLO, DestReg = 0; |
Akira Hatanaka | cbaf6d0 | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 123 | else if (Mips::HI32DSPRegClass.contains(DestReg)) |
Akira Hatanaka | c147c1b | 2013-04-30 23:22:09 +0000 | [diff] [blame] | 124 | Opc = Mips::MTHI_DSP; |
Akira Hatanaka | cbaf6d0 | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 125 | else if (Mips::LO32DSPRegClass.contains(DestReg)) |
Akira Hatanaka | c147c1b | 2013-04-30 23:22:09 +0000 | [diff] [blame] | 126 | Opc = Mips::MTLO_DSP; |
Akira Hatanaka | 99ad6ac | 2013-05-02 23:07:05 +0000 | [diff] [blame] | 127 | else if (Mips::DSPCCRegClass.contains(DestReg)) { |
| 128 | BuildMI(MBB, I, DL, get(Mips::WRDSP)) |
| 129 | .addReg(SrcReg, getKillRegState(KillSrc)).addImm(1 << 4) |
| 130 | .addReg(DestReg, RegState::ImplicitDefine); |
| 131 | return; |
| 132 | } |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 133 | } |
| 134 | else if (Mips::FGR32RegClass.contains(DestReg, SrcReg)) |
| 135 | Opc = Mips::FMOV_S; |
| 136 | else if (Mips::AFGR64RegClass.contains(DestReg, SrcReg)) |
| 137 | Opc = Mips::FMOV_D32; |
| 138 | else if (Mips::FGR64RegClass.contains(DestReg, SrcReg)) |
| 139 | Opc = Mips::FMOV_D64; |
Akira Hatanaka | 1858786 | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 140 | else if (Mips::GPR64RegClass.contains(DestReg)) { // Copy to CPU64 Reg. |
| 141 | if (Mips::GPR64RegClass.contains(SrcReg)) |
Akira Hatanaka | 0b92642 | 2013-07-22 18:52:22 +0000 | [diff] [blame] | 142 | Opc = Mips::DADDu, ZeroReg = Mips::ZERO_64; |
Akira Hatanaka | cbaf6d0 | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 143 | else if (Mips::HI64RegClass.contains(SrcReg)) |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 144 | Opc = Mips::MFHI64, SrcReg = 0; |
Akira Hatanaka | cbaf6d0 | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 145 | else if (Mips::LO64RegClass.contains(SrcReg)) |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 146 | Opc = Mips::MFLO64, SrcReg = 0; |
| 147 | else if (Mips::FGR64RegClass.contains(SrcReg)) |
| 148 | Opc = Mips::DMFC1; |
| 149 | } |
Akira Hatanaka | 1858786 | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 150 | else if (Mips::GPR64RegClass.contains(SrcReg)) { // Copy from CPU64 Reg. |
Akira Hatanaka | cbaf6d0 | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 151 | if (Mips::HI64RegClass.contains(DestReg)) |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 152 | Opc = Mips::MTHI64, DestReg = 0; |
Akira Hatanaka | cbaf6d0 | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 153 | else if (Mips::LO64RegClass.contains(DestReg)) |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 154 | Opc = Mips::MTLO64, DestReg = 0; |
| 155 | else if (Mips::FGR64RegClass.contains(DestReg)) |
| 156 | Opc = Mips::DMTC1; |
| 157 | } |
| 158 | |
| 159 | assert(Opc && "Cannot copy registers"); |
| 160 | |
| 161 | MachineInstrBuilder MIB = BuildMI(MBB, I, DL, get(Opc)); |
| 162 | |
| 163 | if (DestReg) |
| 164 | MIB.addReg(DestReg, RegState::Define); |
| 165 | |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 166 | if (SrcReg) |
| 167 | MIB.addReg(SrcReg, getKillRegState(KillSrc)); |
Akira Hatanaka | 68fe665 | 2012-12-20 04:06:06 +0000 | [diff] [blame] | 168 | |
| 169 | if (ZeroReg) |
| 170 | MIB.addReg(ZeroReg); |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | void MipsSEInstrInfo:: |
Akira Hatanaka | c713e99 | 2013-03-29 02:14:12 +0000 | [diff] [blame] | 174 | storeRegToStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 175 | unsigned SrcReg, bool isKill, int FI, |
| 176 | const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, |
| 177 | int64_t Offset) const { |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 178 | DebugLoc DL; |
| 179 | if (I != MBB.end()) DL = I->getDebugLoc(); |
| 180 | MachineMemOperand *MMO = GetMemOperand(MBB, FI, MachineMemOperand::MOStore); |
| 181 | |
| 182 | unsigned Opc = 0; |
| 183 | |
Akira Hatanaka | 1858786 | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 184 | if (Mips::GPR32RegClass.hasSubClassEq(RC)) |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame^] | 185 | Opc = Mips::SW; |
Akira Hatanaka | 1858786 | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 186 | else if (Mips::GPR64RegClass.hasSubClassEq(RC)) |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame^] | 187 | Opc = Mips::SD; |
Akira Hatanaka | 491d049 | 2013-08-08 21:54:26 +0000 | [diff] [blame] | 188 | else if (Mips::ACC64RegClass.hasSubClassEq(RC)) |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame^] | 189 | Opc = Mips::STORE_ACC64; |
Akira Hatanaka | 491d049 | 2013-08-08 21:54:26 +0000 | [diff] [blame] | 190 | else if (Mips::ACC64DSPRegClass.hasSubClassEq(RC)) |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame^] | 191 | Opc = Mips::STORE_ACC64DSP; |
Akira Hatanaka | 491d049 | 2013-08-08 21:54:26 +0000 | [diff] [blame] | 192 | else if (Mips::ACC128RegClass.hasSubClassEq(RC)) |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame^] | 193 | Opc = Mips::STORE_ACC128; |
Akira Hatanaka | 99ad6ac | 2013-05-02 23:07:05 +0000 | [diff] [blame] | 194 | else if (Mips::DSPCCRegClass.hasSubClassEq(RC)) |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame^] | 195 | Opc = Mips::STORE_CCOND_DSP; |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 196 | else if (Mips::FGR32RegClass.hasSubClassEq(RC)) |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame^] | 197 | Opc = Mips::SWC1; |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 198 | else if (Mips::AFGR64RegClass.hasSubClassEq(RC)) |
| 199 | Opc = Mips::SDC1; |
| 200 | else if (Mips::FGR64RegClass.hasSubClassEq(RC)) |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame^] | 201 | Opc = Mips::SDC164; |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 202 | |
| 203 | assert(Opc && "Register class not handled!"); |
| 204 | BuildMI(MBB, I, DL, get(Opc)).addReg(SrcReg, getKillRegState(isKill)) |
Akira Hatanaka | c713e99 | 2013-03-29 02:14:12 +0000 | [diff] [blame] | 205 | .addFrameIndex(FI).addImm(Offset).addMemOperand(MMO); |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | void MipsSEInstrInfo:: |
Akira Hatanaka | c713e99 | 2013-03-29 02:14:12 +0000 | [diff] [blame] | 209 | loadRegFromStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 210 | unsigned DestReg, int FI, const TargetRegisterClass *RC, |
| 211 | const TargetRegisterInfo *TRI, int64_t Offset) const { |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 212 | DebugLoc DL; |
| 213 | if (I != MBB.end()) DL = I->getDebugLoc(); |
| 214 | MachineMemOperand *MMO = GetMemOperand(MBB, FI, MachineMemOperand::MOLoad); |
| 215 | unsigned Opc = 0; |
| 216 | |
Akira Hatanaka | 1858786 | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 217 | if (Mips::GPR32RegClass.hasSubClassEq(RC)) |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame^] | 218 | Opc = Mips::LW; |
Akira Hatanaka | 1858786 | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 219 | else if (Mips::GPR64RegClass.hasSubClassEq(RC)) |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame^] | 220 | Opc = Mips::LD; |
Akira Hatanaka | 491d049 | 2013-08-08 21:54:26 +0000 | [diff] [blame] | 221 | else if (Mips::ACC64RegClass.hasSubClassEq(RC)) |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame^] | 222 | Opc = Mips::LOAD_ACC64; |
Akira Hatanaka | 491d049 | 2013-08-08 21:54:26 +0000 | [diff] [blame] | 223 | else if (Mips::ACC64DSPRegClass.hasSubClassEq(RC)) |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame^] | 224 | Opc = Mips::LOAD_ACC64DSP; |
Akira Hatanaka | 491d049 | 2013-08-08 21:54:26 +0000 | [diff] [blame] | 225 | else if (Mips::ACC128RegClass.hasSubClassEq(RC)) |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame^] | 226 | Opc = Mips::LOAD_ACC128; |
Akira Hatanaka | 99ad6ac | 2013-05-02 23:07:05 +0000 | [diff] [blame] | 227 | else if (Mips::DSPCCRegClass.hasSubClassEq(RC)) |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame^] | 228 | Opc = Mips::LOAD_CCOND_DSP; |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 229 | else if (Mips::FGR32RegClass.hasSubClassEq(RC)) |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame^] | 230 | Opc = Mips::LWC1; |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 231 | else if (Mips::AFGR64RegClass.hasSubClassEq(RC)) |
| 232 | Opc = Mips::LDC1; |
| 233 | else if (Mips::FGR64RegClass.hasSubClassEq(RC)) |
Akira Hatanaka | a98a486 | 2013-08-20 21:08:22 +0000 | [diff] [blame^] | 234 | Opc = Mips::LDC164; |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 235 | |
| 236 | assert(Opc && "Register class not handled!"); |
Akira Hatanaka | c713e99 | 2013-03-29 02:14:12 +0000 | [diff] [blame] | 237 | BuildMI(MBB, I, DL, get(Opc), DestReg).addFrameIndex(FI).addImm(Offset) |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 238 | .addMemOperand(MMO); |
| 239 | } |
| 240 | |
| 241 | bool MipsSEInstrInfo::expandPostRAPseudo(MachineBasicBlock::iterator MI) const { |
| 242 | MachineBasicBlock &MBB = *MI->getParent(); |
| 243 | |
| 244 | switch(MI->getDesc().getOpcode()) { |
| 245 | default: |
| 246 | return false; |
| 247 | case Mips::RetRA: |
Akira Hatanaka | 6daba28 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 248 | expandRetRA(MBB, MI, Mips::RET); |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 249 | break; |
Akira Hatanaka | ec4db6a | 2013-05-16 19:48:37 +0000 | [diff] [blame] | 250 | case Mips::PseudoCVT_S_W: |
Akira Hatanaka | 7462a87 | 2013-06-08 00:14:54 +0000 | [diff] [blame] | 251 | expandCvtFPInt(MBB, MI, Mips::CVT_S_W, Mips::MTC1, false); |
Akira Hatanaka | ec4db6a | 2013-05-16 19:48:37 +0000 | [diff] [blame] | 252 | break; |
| 253 | case Mips::PseudoCVT_D32_W: |
Akira Hatanaka | 7462a87 | 2013-06-08 00:14:54 +0000 | [diff] [blame] | 254 | expandCvtFPInt(MBB, MI, Mips::CVT_D32_W, Mips::MTC1, false); |
Akira Hatanaka | ec4db6a | 2013-05-16 19:48:37 +0000 | [diff] [blame] | 255 | break; |
| 256 | case Mips::PseudoCVT_S_L: |
Akira Hatanaka | 7462a87 | 2013-06-08 00:14:54 +0000 | [diff] [blame] | 257 | expandCvtFPInt(MBB, MI, Mips::CVT_S_L, Mips::DMTC1, true); |
Akira Hatanaka | ec4db6a | 2013-05-16 19:48:37 +0000 | [diff] [blame] | 258 | break; |
| 259 | case Mips::PseudoCVT_D64_W: |
Akira Hatanaka | 7462a87 | 2013-06-08 00:14:54 +0000 | [diff] [blame] | 260 | expandCvtFPInt(MBB, MI, Mips::CVT_D64_W, Mips::MTC1, true); |
Akira Hatanaka | ec4db6a | 2013-05-16 19:48:37 +0000 | [diff] [blame] | 261 | break; |
| 262 | case Mips::PseudoCVT_D64_L: |
Akira Hatanaka | 7462a87 | 2013-06-08 00:14:54 +0000 | [diff] [blame] | 263 | expandCvtFPInt(MBB, MI, Mips::CVT_D64_L, Mips::DMTC1, true); |
Akira Hatanaka | ec4db6a | 2013-05-16 19:48:37 +0000 | [diff] [blame] | 264 | break; |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 265 | case Mips::BuildPairF64: |
Akira Hatanaka | 6daba28 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 266 | expandBuildPairF64(MBB, MI); |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 267 | break; |
| 268 | case Mips::ExtractElementF64: |
Akira Hatanaka | 6daba28 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 269 | expandExtractElementF64(MBB, MI); |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 270 | break; |
Akira Hatanaka | 42f562a | 2013-05-13 18:23:35 +0000 | [diff] [blame] | 271 | case Mips::PseudoLDC1: |
| 272 | expandDPLoadStore(MBB, MI, Mips::LDC1, Mips::LWC1); |
| 273 | break; |
| 274 | case Mips::PseudoSDC1: |
| 275 | expandDPLoadStore(MBB, MI, Mips::SDC1, Mips::SWC1); |
| 276 | break; |
Akira Hatanaka | 544cc21 | 2013-01-30 00:26:49 +0000 | [diff] [blame] | 277 | case Mips::MIPSeh_return32: |
| 278 | case Mips::MIPSeh_return64: |
Akira Hatanaka | 6daba28 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 279 | expandEhReturn(MBB, MI); |
Akira Hatanaka | 544cc21 | 2013-01-30 00:26:49 +0000 | [diff] [blame] | 280 | break; |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | MBB.erase(MI); |
| 284 | return true; |
| 285 | } |
| 286 | |
Akira Hatanaka | 6daba28 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 287 | /// getOppositeBranchOpc - Return the inverse of the specified |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 288 | /// opcode, e.g. turning BEQ to BNE. |
Akira Hatanaka | 6daba28 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 289 | unsigned MipsSEInstrInfo::getOppositeBranchOpc(unsigned Opc) const { |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 290 | switch (Opc) { |
| 291 | default: llvm_unreachable("Illegal opcode!"); |
| 292 | case Mips::BEQ: return Mips::BNE; |
| 293 | case Mips::BNE: return Mips::BEQ; |
| 294 | case Mips::BGTZ: return Mips::BLEZ; |
| 295 | case Mips::BGEZ: return Mips::BLTZ; |
| 296 | case Mips::BLTZ: return Mips::BGEZ; |
| 297 | case Mips::BLEZ: return Mips::BGTZ; |
| 298 | case Mips::BEQ64: return Mips::BNE64; |
| 299 | case Mips::BNE64: return Mips::BEQ64; |
| 300 | case Mips::BGTZ64: return Mips::BLEZ64; |
| 301 | case Mips::BGEZ64: return Mips::BLTZ64; |
| 302 | case Mips::BLTZ64: return Mips::BGEZ64; |
| 303 | case Mips::BLEZ64: return Mips::BGTZ64; |
| 304 | case Mips::BC1T: return Mips::BC1F; |
| 305 | case Mips::BC1F: return Mips::BC1T; |
| 306 | } |
| 307 | } |
| 308 | |
Akira Hatanaka | 7174622 | 2012-07-31 23:52:55 +0000 | [diff] [blame] | 309 | /// Adjust SP by Amount bytes. |
| 310 | void MipsSEInstrInfo::adjustStackPtr(unsigned SP, int64_t Amount, |
| 311 | MachineBasicBlock &MBB, |
| 312 | MachineBasicBlock::iterator I) const { |
| 313 | const MipsSubtarget &STI = TM.getSubtarget<MipsSubtarget>(); |
| 314 | DebugLoc DL = I != MBB.end() ? I->getDebugLoc() : DebugLoc(); |
| 315 | unsigned ADDu = STI.isABI_N64() ? Mips::DADDu : Mips::ADDu; |
| 316 | unsigned ADDiu = STI.isABI_N64() ? Mips::DADDiu : Mips::ADDiu; |
| 317 | |
| 318 | if (isInt<16>(Amount))// addi sp, sp, amount |
| 319 | BuildMI(MBB, I, DL, get(ADDiu), SP).addReg(SP).addImm(Amount); |
| 320 | else { // Expand immediate that doesn't fit in 16-bit. |
Akira Hatanaka | fc4eafa | 2012-08-23 00:21:05 +0000 | [diff] [blame] | 321 | unsigned Reg = loadImmediate(Amount, MBB, I, DL, 0); |
Akira Hatanaka | 11a45c2 | 2012-11-03 00:05:43 +0000 | [diff] [blame] | 322 | BuildMI(MBB, I, DL, get(ADDu), SP).addReg(SP).addReg(Reg, RegState::Kill); |
Akira Hatanaka | 7174622 | 2012-07-31 23:52:55 +0000 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
Akira Hatanaka | fc4eafa | 2012-08-23 00:21:05 +0000 | [diff] [blame] | 326 | /// This function generates the sequence of instructions needed to get the |
| 327 | /// result of adding register REG and immediate IMM. |
| 328 | unsigned |
| 329 | MipsSEInstrInfo::loadImmediate(int64_t Imm, MachineBasicBlock &MBB, |
| 330 | MachineBasicBlock::iterator II, DebugLoc DL, |
| 331 | unsigned *NewImm) const { |
| 332 | MipsAnalyzeImmediate AnalyzeImm; |
| 333 | const MipsSubtarget &STI = TM.getSubtarget<MipsSubtarget>(); |
Akira Hatanaka | 11a45c2 | 2012-11-03 00:05:43 +0000 | [diff] [blame] | 334 | MachineRegisterInfo &RegInfo = MBB.getParent()->getRegInfo(); |
Akira Hatanaka | fc4eafa | 2012-08-23 00:21:05 +0000 | [diff] [blame] | 335 | unsigned Size = STI.isABI_N64() ? 64 : 32; |
| 336 | unsigned LUi = STI.isABI_N64() ? Mips::LUi64 : Mips::LUi; |
| 337 | unsigned ZEROReg = STI.isABI_N64() ? Mips::ZERO_64 : Mips::ZERO; |
Akira Hatanaka | 11a45c2 | 2012-11-03 00:05:43 +0000 | [diff] [blame] | 338 | const TargetRegisterClass *RC = STI.isABI_N64() ? |
Akira Hatanaka | 1858786 | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 339 | &Mips::GPR64RegClass : &Mips::GPR32RegClass; |
Akira Hatanaka | fc4eafa | 2012-08-23 00:21:05 +0000 | [diff] [blame] | 340 | bool LastInstrIsADDiu = NewImm; |
| 341 | |
| 342 | const MipsAnalyzeImmediate::InstSeq &Seq = |
| 343 | AnalyzeImm.Analyze(Imm, Size, LastInstrIsADDiu); |
| 344 | MipsAnalyzeImmediate::InstSeq::const_iterator Inst = Seq.begin(); |
| 345 | |
| 346 | assert(Seq.size() && (!LastInstrIsADDiu || (Seq.size() > 1))); |
| 347 | |
| 348 | // The first instruction can be a LUi, which is different from other |
| 349 | // instructions (ADDiu, ORI and SLL) in that it does not have a register |
| 350 | // operand. |
Akira Hatanaka | 11a45c2 | 2012-11-03 00:05:43 +0000 | [diff] [blame] | 351 | unsigned Reg = RegInfo.createVirtualRegister(RC); |
| 352 | |
Akira Hatanaka | fc4eafa | 2012-08-23 00:21:05 +0000 | [diff] [blame] | 353 | if (Inst->Opc == LUi) |
Akira Hatanaka | 11a45c2 | 2012-11-03 00:05:43 +0000 | [diff] [blame] | 354 | BuildMI(MBB, II, DL, get(LUi), Reg).addImm(SignExtend64<16>(Inst->ImmOpnd)); |
Akira Hatanaka | fc4eafa | 2012-08-23 00:21:05 +0000 | [diff] [blame] | 355 | else |
Akira Hatanaka | 11a45c2 | 2012-11-03 00:05:43 +0000 | [diff] [blame] | 356 | BuildMI(MBB, II, DL, get(Inst->Opc), Reg).addReg(ZEROReg) |
Akira Hatanaka | fc4eafa | 2012-08-23 00:21:05 +0000 | [diff] [blame] | 357 | .addImm(SignExtend64<16>(Inst->ImmOpnd)); |
| 358 | |
| 359 | // Build the remaining instructions in Seq. |
| 360 | for (++Inst; Inst != Seq.end() - LastInstrIsADDiu; ++Inst) |
Akira Hatanaka | 11a45c2 | 2012-11-03 00:05:43 +0000 | [diff] [blame] | 361 | BuildMI(MBB, II, DL, get(Inst->Opc), Reg).addReg(Reg, RegState::Kill) |
Akira Hatanaka | fc4eafa | 2012-08-23 00:21:05 +0000 | [diff] [blame] | 362 | .addImm(SignExtend64<16>(Inst->ImmOpnd)); |
| 363 | |
| 364 | if (LastInstrIsADDiu) |
| 365 | *NewImm = Inst->ImmOpnd; |
| 366 | |
Akira Hatanaka | 11a45c2 | 2012-11-03 00:05:43 +0000 | [diff] [blame] | 367 | return Reg; |
Akira Hatanaka | fc4eafa | 2012-08-23 00:21:05 +0000 | [diff] [blame] | 368 | } |
| 369 | |
Akira Hatanaka | 6daba28 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 370 | unsigned MipsSEInstrInfo::getAnalyzableBrOpc(unsigned Opc) const { |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 371 | return (Opc == Mips::BEQ || Opc == Mips::BNE || Opc == Mips::BGTZ || |
| 372 | Opc == Mips::BGEZ || Opc == Mips::BLTZ || Opc == Mips::BLEZ || |
| 373 | Opc == Mips::BEQ64 || Opc == Mips::BNE64 || Opc == Mips::BGTZ64 || |
| 374 | Opc == Mips::BGEZ64 || Opc == Mips::BLTZ64 || Opc == Mips::BLEZ64 || |
| 375 | Opc == Mips::BC1T || Opc == Mips::BC1F || Opc == Mips::B || |
| 376 | Opc == Mips::J) ? |
| 377 | Opc : 0; |
| 378 | } |
| 379 | |
Akira Hatanaka | 6daba28 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 380 | void MipsSEInstrInfo::expandRetRA(MachineBasicBlock &MBB, |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 381 | MachineBasicBlock::iterator I, |
| 382 | unsigned Opc) const { |
| 383 | BuildMI(MBB, I, I->getDebugLoc(), get(Opc)).addReg(Mips::RA); |
| 384 | } |
| 385 | |
Akira Hatanaka | 4cef3d8 | 2013-06-11 18:48:16 +0000 | [diff] [blame] | 386 | std::pair<bool, bool> |
| 387 | MipsSEInstrInfo::compareOpndSize(unsigned Opc, |
| 388 | const MachineFunction &MF) const { |
Akira Hatanaka | 7462a87 | 2013-06-08 00:14:54 +0000 | [diff] [blame] | 389 | const MCInstrDesc &Desc = get(Opc); |
| 390 | assert(Desc.NumOperands == 2 && "Unary instruction expected."); |
Akira Hatanaka | 4cef3d8 | 2013-06-11 18:48:16 +0000 | [diff] [blame] | 391 | const MipsRegisterInfo *RI = &getRegisterInfo(); |
| 392 | unsigned DstRegSize = getRegClass(Desc, 0, RI, MF)->getSize(); |
| 393 | unsigned SrcRegSize = getRegClass(Desc, 1, RI, MF)->getSize(); |
Akira Hatanaka | 7462a87 | 2013-06-08 00:14:54 +0000 | [diff] [blame] | 394 | |
| 395 | return std::make_pair(DstRegSize > SrcRegSize, DstRegSize < SrcRegSize); |
| 396 | } |
| 397 | |
Akira Hatanaka | ec4db6a | 2013-05-16 19:48:37 +0000 | [diff] [blame] | 398 | void MipsSEInstrInfo::expandCvtFPInt(MachineBasicBlock &MBB, |
| 399 | MachineBasicBlock::iterator I, |
| 400 | unsigned CvtOpc, unsigned MovOpc, |
Akira Hatanaka | ec4db6a | 2013-05-16 19:48:37 +0000 | [diff] [blame] | 401 | bool IsI64) const { |
| 402 | const MCInstrDesc &CvtDesc = get(CvtOpc), &MovDesc = get(MovOpc); |
| 403 | const MachineOperand &Dst = I->getOperand(0), &Src = I->getOperand(1); |
| 404 | unsigned DstReg = Dst.getReg(), SrcReg = Src.getReg(), TmpReg = DstReg; |
| 405 | unsigned KillSrc = getKillRegState(Src.isKill()); |
| 406 | DebugLoc DL = I->getDebugLoc(); |
| 407 | unsigned SubIdx = (IsI64 ? Mips::sub_32 : Mips::sub_fpeven); |
Akira Hatanaka | 7462a87 | 2013-06-08 00:14:54 +0000 | [diff] [blame] | 408 | bool DstIsLarger, SrcIsLarger; |
| 409 | |
Akira Hatanaka | 4cef3d8 | 2013-06-11 18:48:16 +0000 | [diff] [blame] | 410 | tie(DstIsLarger, SrcIsLarger) = compareOpndSize(CvtOpc, *MBB.getParent()); |
Akira Hatanaka | ec4db6a | 2013-05-16 19:48:37 +0000 | [diff] [blame] | 411 | |
| 412 | if (DstIsLarger) |
| 413 | TmpReg = getRegisterInfo().getSubReg(DstReg, SubIdx); |
| 414 | |
| 415 | if (SrcIsLarger) |
| 416 | DstReg = getRegisterInfo().getSubReg(DstReg, SubIdx); |
| 417 | |
| 418 | BuildMI(MBB, I, DL, MovDesc, TmpReg).addReg(SrcReg, KillSrc); |
| 419 | BuildMI(MBB, I, DL, CvtDesc, DstReg).addReg(TmpReg, RegState::Kill); |
| 420 | } |
| 421 | |
Akira Hatanaka | 6daba28 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 422 | void MipsSEInstrInfo::expandExtractElementF64(MachineBasicBlock &MBB, |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 423 | MachineBasicBlock::iterator I) const { |
| 424 | unsigned DstReg = I->getOperand(0).getReg(); |
| 425 | unsigned SrcReg = I->getOperand(1).getReg(); |
| 426 | unsigned N = I->getOperand(2).getImm(); |
| 427 | const MCInstrDesc& Mfc1Tdd = get(Mips::MFC1); |
| 428 | DebugLoc dl = I->getDebugLoc(); |
| 429 | |
| 430 | assert(N < 2 && "Invalid immediate"); |
| 431 | unsigned SubIdx = N ? Mips::sub_fpodd : Mips::sub_fpeven; |
| 432 | unsigned SubReg = getRegisterInfo().getSubReg(SrcReg, SubIdx); |
| 433 | |
| 434 | BuildMI(MBB, I, dl, Mfc1Tdd, DstReg).addReg(SubReg); |
| 435 | } |
| 436 | |
Akira Hatanaka | 6daba28 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 437 | void MipsSEInstrInfo::expandBuildPairF64(MachineBasicBlock &MBB, |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 438 | MachineBasicBlock::iterator I) const { |
| 439 | unsigned DstReg = I->getOperand(0).getReg(); |
| 440 | unsigned LoReg = I->getOperand(1).getReg(), HiReg = I->getOperand(2).getReg(); |
| 441 | const MCInstrDesc& Mtc1Tdd = get(Mips::MTC1); |
| 442 | DebugLoc dl = I->getDebugLoc(); |
| 443 | const TargetRegisterInfo &TRI = getRegisterInfo(); |
| 444 | |
| 445 | // mtc1 Lo, $fp |
| 446 | // mtc1 Hi, $fp + 1 |
| 447 | BuildMI(MBB, I, dl, Mtc1Tdd, TRI.getSubReg(DstReg, Mips::sub_fpeven)) |
| 448 | .addReg(LoReg); |
| 449 | BuildMI(MBB, I, dl, Mtc1Tdd, TRI.getSubReg(DstReg, Mips::sub_fpodd)) |
| 450 | .addReg(HiReg); |
| 451 | } |
Akira Hatanaka | af26626 | 2012-08-02 18:21:47 +0000 | [diff] [blame] | 452 | |
Akira Hatanaka | 42f562a | 2013-05-13 18:23:35 +0000 | [diff] [blame] | 453 | /// Add 4 to the displacement of operand MO. |
| 454 | static void fixDisp(MachineOperand &MO) { |
| 455 | switch (MO.getType()) { |
| 456 | default: |
| 457 | llvm_unreachable("Unhandled operand type."); |
| 458 | case MachineOperand::MO_Immediate: |
| 459 | MO.setImm(MO.getImm() + 4); |
| 460 | break; |
| 461 | case MachineOperand::MO_GlobalAddress: |
| 462 | case MachineOperand::MO_ConstantPoolIndex: |
| 463 | case MachineOperand::MO_BlockAddress: |
| 464 | case MachineOperand::MO_TargetIndex: |
| 465 | case MachineOperand::MO_ExternalSymbol: |
| 466 | MO.setOffset(MO.getOffset() + 4); |
| 467 | break; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | void MipsSEInstrInfo::expandDPLoadStore(MachineBasicBlock &MBB, |
| 472 | MachineBasicBlock::iterator I, |
| 473 | unsigned OpcD, unsigned OpcS) const { |
| 474 | // If NoDPLoadStore is false, just change the opcode. |
| 475 | if (!NoDPLoadStore) { |
| 476 | genInstrWithNewOpc(OpcD, I); |
| 477 | return; |
| 478 | } |
| 479 | |
| 480 | // Expand a double precision FP load or store to two single precision |
| 481 | // instructions. |
| 482 | |
| 483 | const TargetRegisterInfo &TRI = getRegisterInfo(); |
| 484 | const MachineOperand &ValReg = I->getOperand(0); |
| 485 | unsigned LoReg = TRI.getSubReg(ValReg.getReg(), Mips::sub_fpeven); |
| 486 | unsigned HiReg = TRI.getSubReg(ValReg.getReg(), Mips::sub_fpodd); |
| 487 | |
| 488 | if (!TM.getSubtarget<MipsSubtarget>().isLittle()) |
| 489 | std::swap(LoReg, HiReg); |
| 490 | |
| 491 | // Create an instruction which loads from or stores to the lower memory |
| 492 | // address. |
| 493 | MachineInstrBuilder MIB = genInstrWithNewOpc(OpcS, I); |
| 494 | MIB->getOperand(0).setReg(LoReg); |
| 495 | |
| 496 | // Create an instruction which loads from or stores to the higher memory |
| 497 | // address. |
| 498 | MIB = genInstrWithNewOpc(OpcS, I); |
| 499 | MIB->getOperand(0).setReg(HiReg); |
| 500 | fixDisp(MIB->getOperand(2)); |
| 501 | } |
| 502 | |
Akira Hatanaka | 6daba28 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 503 | void MipsSEInstrInfo::expandEhReturn(MachineBasicBlock &MBB, |
Akira Hatanaka | 544cc21 | 2013-01-30 00:26:49 +0000 | [diff] [blame] | 504 | MachineBasicBlock::iterator I) const { |
| 505 | // This pseudo instruction is generated as part of the lowering of |
| 506 | // ISD::EH_RETURN. We convert it to a stack increment by OffsetReg, and |
| 507 | // indirect jump to TargetReg |
| 508 | const MipsSubtarget &STI = TM.getSubtarget<MipsSubtarget>(); |
| 509 | unsigned ADDU = STI.isABI_N64() ? Mips::DADDu : Mips::ADDu; |
Akira Hatanaka | 544cc21 | 2013-01-30 00:26:49 +0000 | [diff] [blame] | 510 | unsigned JR = STI.isABI_N64() ? Mips::JR64 : Mips::JR; |
| 511 | unsigned SP = STI.isABI_N64() ? Mips::SP_64 : Mips::SP; |
| 512 | unsigned RA = STI.isABI_N64() ? Mips::RA_64 : Mips::RA; |
Akira Hatanaka | 67fdafe | 2013-04-02 23:02:07 +0000 | [diff] [blame] | 513 | unsigned T9 = STI.isABI_N64() ? Mips::T9_64 : Mips::T9; |
Akira Hatanaka | 544cc21 | 2013-01-30 00:26:49 +0000 | [diff] [blame] | 514 | unsigned ZERO = STI.isABI_N64() ? Mips::ZERO_64 : Mips::ZERO; |
| 515 | unsigned OffsetReg = I->getOperand(0).getReg(); |
| 516 | unsigned TargetReg = I->getOperand(1).getReg(); |
| 517 | |
Akira Hatanaka | 0b92642 | 2013-07-22 18:52:22 +0000 | [diff] [blame] | 518 | // addu $ra, $v0, $zero |
Akira Hatanaka | 544cc21 | 2013-01-30 00:26:49 +0000 | [diff] [blame] | 519 | // addu $sp, $sp, $v1 |
| 520 | // jr $ra |
Akira Hatanaka | 67fdafe | 2013-04-02 23:02:07 +0000 | [diff] [blame] | 521 | if (TM.getRelocationModel() == Reloc::PIC_) |
Akira Hatanaka | 0b92642 | 2013-07-22 18:52:22 +0000 | [diff] [blame] | 522 | BuildMI(MBB, I, I->getDebugLoc(), TM.getInstrInfo()->get(ADDU), T9) |
Akira Hatanaka | 67fdafe | 2013-04-02 23:02:07 +0000 | [diff] [blame] | 523 | .addReg(TargetReg).addReg(ZERO); |
Akira Hatanaka | 0b92642 | 2013-07-22 18:52:22 +0000 | [diff] [blame] | 524 | BuildMI(MBB, I, I->getDebugLoc(), TM.getInstrInfo()->get(ADDU), RA) |
Akira Hatanaka | 544cc21 | 2013-01-30 00:26:49 +0000 | [diff] [blame] | 525 | .addReg(TargetReg).addReg(ZERO); |
| 526 | BuildMI(MBB, I, I->getDebugLoc(), TM.getInstrInfo()->get(ADDU), SP) |
| 527 | .addReg(SP).addReg(OffsetReg); |
| 528 | BuildMI(MBB, I, I->getDebugLoc(), TM.getInstrInfo()->get(JR)).addReg(RA); |
| 529 | } |
| 530 | |
Akira Hatanaka | af26626 | 2012-08-02 18:21:47 +0000 | [diff] [blame] | 531 | const MipsInstrInfo *llvm::createMipsSEInstrInfo(MipsTargetMachine &TM) { |
| 532 | return new MipsSEInstrInfo(TM); |
| 533 | } |