Jia Liu | c570711 | 2012-02-17 08:55:11 +0000 | [diff] [blame] | 1 | //===-- MipsInstrInfo.cpp - Mips Instruction Information ------------------===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 7 | // |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file contains the Mips implementation of the TargetInstrInfo class. |
| 11 | // |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 13 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 14 | #include "MipsInstrInfo.h" |
Bruno Cardoso Lopes | 43d526d | 2008-07-14 14:42:54 +0000 | [diff] [blame] | 15 | #include "MipsTargetMachine.h" |
Dan Gohman | 9911405 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 16 | #include "MipsMachineFunction.h" |
Akira Hatanaka | 794bf17 | 2011-07-07 23:56:50 +0000 | [diff] [blame] | 17 | #include "InstPrinter/MipsInstPrinter.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Dan Gohman | 9911405 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 20 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | 3e74d6f | 2011-08-24 18:08:43 +0000 | [diff] [blame] | 21 | #include "llvm/Support/TargetRegistry.h" |
Evan Cheng | 59ee62d | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/STLExtras.h" |
Evan Cheng | 22fee2d | 2011-06-28 20:07:07 +0000 | [diff] [blame] | 23 | |
Evan Cheng | 4db3cff | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 24 | #define GET_INSTRINFO_CTOR |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 25 | #include "MipsGenInstrInfo.inc" |
| 26 | |
| 27 | using namespace llvm; |
| 28 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 29 | MipsInstrInfo::MipsInstrInfo(MipsTargetMachine &tm) |
Evan Cheng | 4db3cff | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 30 | : MipsGenInstrInfo(Mips::ADJCALLSTACKDOWN, Mips::ADJCALLSTACKUP), |
Akira Hatanaka | 43aed32 | 2011-10-11 00:37:28 +0000 | [diff] [blame] | 31 | TM(tm), IsN64(TM.getSubtarget<MipsSubtarget>().isABI_N64()), |
Akira Hatanaka | 6e55ff5 | 2011-12-12 22:39:35 +0000 | [diff] [blame] | 32 | RI(*TM.getSubtargetImpl(), *this), |
| 33 | UncondBrOpc(TM.getRelocationModel() == Reloc::PIC_ ? Mips::B : Mips::J) {} |
Akira Hatanaka | 794bf17 | 2011-07-07 23:56:50 +0000 | [diff] [blame] | 34 | |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 35 | const MipsRegisterInfo &MipsInstrInfo::getRegisterInfo() const { |
Akira Hatanaka | 794bf17 | 2011-07-07 23:56:50 +0000 | [diff] [blame] | 36 | return RI; |
| 37 | } |
| 38 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 39 | static bool isZeroImm(const MachineOperand &op) { |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 40 | return op.isImm() && op.getImm() == 0; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 43 | /// isLoadFromStackSlot - If the specified machine instruction is a direct |
| 44 | /// load from a stack slot, return the virtual or physical register number of |
| 45 | /// the destination along with the FrameIndex of the loaded stack slot. If |
| 46 | /// not, return 0. This predicate must return 0 if the instruction has |
| 47 | /// any side effects other than loading from the stack slot. |
| 48 | unsigned MipsInstrInfo:: |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 49 | isLoadFromStackSlot(const MachineInstr *MI, int &FrameIndex) const |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 50 | { |
Akira Hatanaka | 1acb7df | 2011-10-11 01:12:52 +0000 | [diff] [blame] | 51 | unsigned Opc = MI->getOpcode(); |
| 52 | |
| 53 | if ((Opc == Mips::LW) || (Opc == Mips::LW_P8) || (Opc == Mips::LD) || |
| 54 | (Opc == Mips::LD_P8) || (Opc == Mips::LWC1) || (Opc == Mips::LWC1_P8) || |
| 55 | (Opc == Mips::LDC1) || (Opc == Mips::LDC164) || |
| 56 | (Opc == Mips::LDC164_P8)) { |
Akira Hatanaka | d3ac47f | 2011-07-07 18:57:00 +0000 | [diff] [blame] | 57 | if ((MI->getOperand(1).isFI()) && // is a stack slot |
| 58 | (MI->getOperand(2).isImm()) && // the imm is zero |
| 59 | (isZeroImm(MI->getOperand(2)))) { |
| 60 | FrameIndex = MI->getOperand(1).getIndex(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 61 | return MI->getOperand(0).getReg(); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | /// isStoreToStackSlot - If the specified machine instruction is a direct |
| 69 | /// store to a stack slot, return the virtual or physical register number of |
| 70 | /// the source reg along with the FrameIndex of the loaded stack slot. If |
| 71 | /// not, return 0. This predicate must return 0 if the instruction has |
| 72 | /// any side effects other than storing to the stack slot. |
| 73 | unsigned MipsInstrInfo:: |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 74 | isStoreToStackSlot(const MachineInstr *MI, int &FrameIndex) const |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 75 | { |
Akira Hatanaka | 1acb7df | 2011-10-11 01:12:52 +0000 | [diff] [blame] | 76 | unsigned Opc = MI->getOpcode(); |
| 77 | |
| 78 | if ((Opc == Mips::SW) || (Opc == Mips::SW_P8) || (Opc == Mips::SD) || |
| 79 | (Opc == Mips::SD_P8) || (Opc == Mips::SWC1) || (Opc == Mips::SWC1_P8) || |
| 80 | (Opc == Mips::SDC1) || (Opc == Mips::SDC164) || |
| 81 | (Opc == Mips::SDC164_P8)) { |
Akira Hatanaka | d3ac47f | 2011-07-07 18:57:00 +0000 | [diff] [blame] | 82 | if ((MI->getOperand(1).isFI()) && // is a stack slot |
| 83 | (MI->getOperand(2).isImm()) && // the imm is zero |
| 84 | (isZeroImm(MI->getOperand(2)))) { |
| 85 | FrameIndex = MI->getOperand(1).getIndex(); |
Bruno Cardoso Lopes | 91ef849 | 2008-08-02 19:42:36 +0000 | [diff] [blame] | 86 | return MI->getOperand(0).getReg(); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | return 0; |
| 90 | } |
| 91 | |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 92 | /// insertNoop - If data hazard condition is found insert the target nop |
| 93 | /// instruction. |
| 94 | void MipsInstrInfo:: |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 95 | insertNoop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 96 | { |
Chris Lattner | c7f3ace | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 97 | DebugLoc DL; |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 98 | BuildMI(MBB, MI, DL, get(Mips::NOP)); |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Jakob Stoklund Olesen | 273c14f | 2010-07-11 01:08:31 +0000 | [diff] [blame] | 101 | void MipsInstrInfo:: |
| 102 | copyPhysReg(MachineBasicBlock &MBB, |
| 103 | MachineBasicBlock::iterator I, DebugLoc DL, |
| 104 | unsigned DestReg, unsigned SrcReg, |
| 105 | bool KillSrc) const { |
Akira Hatanaka | 2ad7668 | 2011-10-03 20:38:08 +0000 | [diff] [blame] | 106 | unsigned Opc = 0, ZeroReg = 0; |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 107 | |
Akira Hatanaka | 2ad7668 | 2011-10-03 20:38:08 +0000 | [diff] [blame] | 108 | if (Mips::CPURegsRegClass.contains(DestReg)) { // Copy to CPU Reg. |
| 109 | if (Mips::CPURegsRegClass.contains(SrcReg)) |
| 110 | Opc = Mips::ADDu, ZeroReg = Mips::ZERO; |
| 111 | else if (Mips::CCRRegClass.contains(SrcReg)) |
| 112 | Opc = Mips::CFC1; |
Jakob Stoklund Olesen | 273c14f | 2010-07-11 01:08:31 +0000 | [diff] [blame] | 113 | else if (Mips::FGR32RegClass.contains(SrcReg)) |
Akira Hatanaka | 2ad7668 | 2011-10-03 20:38:08 +0000 | [diff] [blame] | 114 | Opc = Mips::MFC1; |
Jakob Stoklund Olesen | 273c14f | 2010-07-11 01:08:31 +0000 | [diff] [blame] | 115 | else if (SrcReg == Mips::HI) |
Akira Hatanaka | 2ad7668 | 2011-10-03 20:38:08 +0000 | [diff] [blame] | 116 | Opc = Mips::MFHI, SrcReg = 0; |
Jakob Stoklund Olesen | 273c14f | 2010-07-11 01:08:31 +0000 | [diff] [blame] | 117 | else if (SrcReg == Mips::LO) |
Akira Hatanaka | 2ad7668 | 2011-10-03 20:38:08 +0000 | [diff] [blame] | 118 | Opc = Mips::MFLO, SrcReg = 0; |
Jakob Stoklund Olesen | 273c14f | 2010-07-11 01:08:31 +0000 | [diff] [blame] | 119 | } |
Akira Hatanaka | 2ad7668 | 2011-10-03 20:38:08 +0000 | [diff] [blame] | 120 | else if (Mips::CPURegsRegClass.contains(SrcReg)) { // Copy from CPU Reg. |
Jakob Stoklund Olesen | 273c14f | 2010-07-11 01:08:31 +0000 | [diff] [blame] | 121 | if (Mips::CCRRegClass.contains(DestReg)) |
Akira Hatanaka | 2ad7668 | 2011-10-03 20:38:08 +0000 | [diff] [blame] | 122 | Opc = Mips::CTC1; |
Jakob Stoklund Olesen | 273c14f | 2010-07-11 01:08:31 +0000 | [diff] [blame] | 123 | else if (Mips::FGR32RegClass.contains(DestReg)) |
Akira Hatanaka | 2ad7668 | 2011-10-03 20:38:08 +0000 | [diff] [blame] | 124 | Opc = Mips::MTC1; |
Jakob Stoklund Olesen | 273c14f | 2010-07-11 01:08:31 +0000 | [diff] [blame] | 125 | else if (DestReg == Mips::HI) |
Akira Hatanaka | 2ad7668 | 2011-10-03 20:38:08 +0000 | [diff] [blame] | 126 | Opc = Mips::MTHI, DestReg = 0; |
Jakob Stoklund Olesen | 273c14f | 2010-07-11 01:08:31 +0000 | [diff] [blame] | 127 | else if (DestReg == Mips::LO) |
Akira Hatanaka | 2ad7668 | 2011-10-03 20:38:08 +0000 | [diff] [blame] | 128 | Opc = Mips::MTLO, DestReg = 0; |
| 129 | } |
| 130 | else if (Mips::FGR32RegClass.contains(DestReg, SrcReg)) |
Akira Hatanaka | 4391bb7 | 2011-10-08 03:50:18 +0000 | [diff] [blame] | 131 | Opc = Mips::FMOV_S; |
Akira Hatanaka | 2ad7668 | 2011-10-03 20:38:08 +0000 | [diff] [blame] | 132 | else if (Mips::AFGR64RegClass.contains(DestReg, SrcReg)) |
| 133 | Opc = Mips::FMOV_D32; |
Akira Hatanaka | 29d525a | 2011-11-07 21:35:45 +0000 | [diff] [blame] | 134 | else if (Mips::FGR64RegClass.contains(DestReg, SrcReg)) |
| 135 | Opc = Mips::FMOV_D64; |
Akira Hatanaka | 2ad7668 | 2011-10-03 20:38:08 +0000 | [diff] [blame] | 136 | else if (Mips::CCRRegClass.contains(DestReg, SrcReg)) |
| 137 | Opc = Mips::MOVCCRToCCR; |
| 138 | else if (Mips::CPU64RegsRegClass.contains(DestReg)) { // Copy to CPU64 Reg. |
| 139 | if (Mips::CPU64RegsRegClass.contains(SrcReg)) |
| 140 | Opc = Mips::DADDu, ZeroReg = Mips::ZERO_64; |
| 141 | else if (SrcReg == Mips::HI64) |
| 142 | Opc = Mips::MFHI64, SrcReg = 0; |
| 143 | else if (SrcReg == Mips::LO64) |
| 144 | Opc = Mips::MFLO64, SrcReg = 0; |
Akira Hatanaka | 29d525a | 2011-11-07 21:35:45 +0000 | [diff] [blame] | 145 | else if (Mips::FGR64RegClass.contains(SrcReg)) |
| 146 | Opc = Mips::DMFC1; |
Akira Hatanaka | 2ad7668 | 2011-10-03 20:38:08 +0000 | [diff] [blame] | 147 | } |
| 148 | else if (Mips::CPU64RegsRegClass.contains(SrcReg)) { // Copy from CPU64 Reg. |
| 149 | if (DestReg == Mips::HI64) |
| 150 | Opc = Mips::MTHI64, DestReg = 0; |
| 151 | else if (DestReg == Mips::LO64) |
| 152 | Opc = Mips::MTLO64, DestReg = 0; |
Akira Hatanaka | 29d525a | 2011-11-07 21:35:45 +0000 | [diff] [blame] | 153 | else if (Mips::FGR64RegClass.contains(DestReg)) |
| 154 | Opc = Mips::DMTC1; |
Jakob Stoklund Olesen | 273c14f | 2010-07-11 01:08:31 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Akira Hatanaka | 2ad7668 | 2011-10-03 20:38:08 +0000 | [diff] [blame] | 157 | assert(Opc && "Cannot copy registers"); |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 158 | |
Akira Hatanaka | 2ad7668 | 2011-10-03 20:38:08 +0000 | [diff] [blame] | 159 | MachineInstrBuilder MIB = BuildMI(MBB, I, DL, get(Opc)); |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 160 | |
Akira Hatanaka | 2ad7668 | 2011-10-03 20:38:08 +0000 | [diff] [blame] | 161 | if (DestReg) |
| 162 | MIB.addReg(DestReg, RegState::Define); |
Jakob Stoklund Olesen | 273c14f | 2010-07-11 01:08:31 +0000 | [diff] [blame] | 163 | |
Akira Hatanaka | 2ad7668 | 2011-10-03 20:38:08 +0000 | [diff] [blame] | 164 | if (ZeroReg) |
| 165 | MIB.addReg(ZeroReg); |
| 166 | |
| 167 | if (SrcReg) |
| 168 | MIB.addReg(SrcReg, getKillRegState(KillSrc)); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Akira Hatanaka | fd1d925 | 2011-12-24 03:11:18 +0000 | [diff] [blame] | 171 | static MachineMemOperand* GetMemOperand(MachineBasicBlock &MBB, int FI, |
| 172 | unsigned Flag) { |
| 173 | MachineFunction &MF = *MBB.getParent(); |
| 174 | MachineFrameInfo &MFI = *MF.getFrameInfo(); |
| 175 | unsigned Align = MFI.getObjectAlignment(FI); |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 176 | |
Akira Hatanaka | fd1d925 | 2011-12-24 03:11:18 +0000 | [diff] [blame] | 177 | return MF.getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), Flag, |
| 178 | MFI.getObjectSize(FI), Align); |
| 179 | } |
| 180 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 181 | void MipsInstrInfo:: |
| 182 | storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 183 | unsigned SrcReg, bool isKill, int FI, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 184 | const TargetRegisterClass *RC, |
| 185 | const TargetRegisterInfo *TRI) const { |
Chris Lattner | c7f3ace | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 186 | DebugLoc DL; |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 187 | if (I != MBB.end()) DL = I->getDebugLoc(); |
Akira Hatanaka | fd1d925 | 2011-12-24 03:11:18 +0000 | [diff] [blame] | 188 | MachineMemOperand *MMO = GetMemOperand(MBB, FI, MachineMemOperand::MOStore); |
| 189 | |
Akira Hatanaka | 43aed32 | 2011-10-11 00:37:28 +0000 | [diff] [blame] | 190 | unsigned Opc = 0; |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 191 | |
Akira Hatanaka | 66e19c3 | 2012-05-16 22:19:56 +0000 | [diff] [blame] | 192 | if (Mips::CPURegsRegClass.hasSubClassEq(RC)) |
Akira Hatanaka | 43aed32 | 2011-10-11 00:37:28 +0000 | [diff] [blame] | 193 | Opc = IsN64 ? Mips::SW_P8 : Mips::SW; |
Akira Hatanaka | 66e19c3 | 2012-05-16 22:19:56 +0000 | [diff] [blame] | 194 | else if (Mips::CPU64RegsRegClass.hasSubClassEq(RC)) |
Akira Hatanaka | 43aed32 | 2011-10-11 00:37:28 +0000 | [diff] [blame] | 195 | Opc = IsN64 ? Mips::SD_P8 : Mips::SD; |
Akira Hatanaka | 66e19c3 | 2012-05-16 22:19:56 +0000 | [diff] [blame] | 196 | else if (Mips::FGR32RegClass.hasSubClassEq(RC)) |
Akira Hatanaka | 1acb7df | 2011-10-11 01:12:52 +0000 | [diff] [blame] | 197 | Opc = IsN64 ? Mips::SWC1_P8 : Mips::SWC1; |
Akira Hatanaka | 66e19c3 | 2012-05-16 22:19:56 +0000 | [diff] [blame] | 198 | else if (Mips::AFGR64RegClass.hasSubClassEq(RC)) |
Akira Hatanaka | 43aed32 | 2011-10-11 00:37:28 +0000 | [diff] [blame] | 199 | Opc = Mips::SDC1; |
Akira Hatanaka | 66e19c3 | 2012-05-16 22:19:56 +0000 | [diff] [blame] | 200 | else if (Mips::FGR64RegClass.hasSubClassEq(RC)) |
Akira Hatanaka | 1acb7df | 2011-10-11 01:12:52 +0000 | [diff] [blame] | 201 | Opc = IsN64 ? Mips::SDC164_P8 : Mips::SDC164; |
Akira Hatanaka | 43aed32 | 2011-10-11 00:37:28 +0000 | [diff] [blame] | 202 | |
| 203 | assert(Opc && "Register class not handled!"); |
| 204 | BuildMI(MBB, I, DL, get(Opc)).addReg(SrcReg, getKillRegState(isKill)) |
Akira Hatanaka | fd1d925 | 2011-12-24 03:11:18 +0000 | [diff] [blame] | 205 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 208 | void MipsInstrInfo:: |
| 209 | loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 210 | unsigned DestReg, int FI, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 211 | const TargetRegisterClass *RC, |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 212 | const TargetRegisterInfo *TRI) const |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 213 | { |
Chris Lattner | c7f3ace | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 214 | DebugLoc DL; |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 215 | if (I != MBB.end()) DL = I->getDebugLoc(); |
Akira Hatanaka | fd1d925 | 2011-12-24 03:11:18 +0000 | [diff] [blame] | 216 | MachineMemOperand *MMO = GetMemOperand(MBB, FI, MachineMemOperand::MOLoad); |
Akira Hatanaka | 43aed32 | 2011-10-11 00:37:28 +0000 | [diff] [blame] | 217 | unsigned Opc = 0; |
Bruno Cardoso Lopes | 302525b | 2009-11-25 00:36:00 +0000 | [diff] [blame] | 218 | |
Akira Hatanaka | 66e19c3 | 2012-05-16 22:19:56 +0000 | [diff] [blame] | 219 | if (Mips::CPURegsRegClass.hasSubClassEq(RC)) |
Akira Hatanaka | 43aed32 | 2011-10-11 00:37:28 +0000 | [diff] [blame] | 220 | Opc = IsN64 ? Mips::LW_P8 : Mips::LW; |
Akira Hatanaka | 66e19c3 | 2012-05-16 22:19:56 +0000 | [diff] [blame] | 221 | else if (Mips::CPU64RegsRegClass.hasSubClassEq(RC)) |
Akira Hatanaka | 43aed32 | 2011-10-11 00:37:28 +0000 | [diff] [blame] | 222 | Opc = IsN64 ? Mips::LD_P8 : Mips::LD; |
Akira Hatanaka | 66e19c3 | 2012-05-16 22:19:56 +0000 | [diff] [blame] | 223 | else if (Mips::FGR32RegClass.hasSubClassEq(RC)) |
Akira Hatanaka | 1acb7df | 2011-10-11 01:12:52 +0000 | [diff] [blame] | 224 | Opc = IsN64 ? Mips::LWC1_P8 : Mips::LWC1; |
Akira Hatanaka | 66e19c3 | 2012-05-16 22:19:56 +0000 | [diff] [blame] | 225 | else if (Mips::AFGR64RegClass.hasSubClassEq(RC)) |
Akira Hatanaka | 43aed32 | 2011-10-11 00:37:28 +0000 | [diff] [blame] | 226 | Opc = Mips::LDC1; |
Akira Hatanaka | 66e19c3 | 2012-05-16 22:19:56 +0000 | [diff] [blame] | 227 | else if (Mips::FGR64RegClass.hasSubClassEq(RC)) |
Akira Hatanaka | 1acb7df | 2011-10-11 01:12:52 +0000 | [diff] [blame] | 228 | Opc = IsN64 ? Mips::LDC164_P8 : Mips::LDC164; |
Akira Hatanaka | 43aed32 | 2011-10-11 00:37:28 +0000 | [diff] [blame] | 229 | |
| 230 | assert(Opc && "Register class not handled!"); |
Akira Hatanaka | fd1d925 | 2011-12-24 03:11:18 +0000 | [diff] [blame] | 231 | BuildMI(MBB, I, DL, get(Opc), DestReg).addFrameIndex(FI).addImm(0) |
| 232 | .addMemOperand(MMO); |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Akira Hatanaka | 564f690 | 2012-05-25 20:52:52 +0000 | [diff] [blame^] | 235 | void MipsInstrInfo::ExpandExtractElementF64(MachineBasicBlock &MBB, |
| 236 | MachineBasicBlock::iterator I) const { |
| 237 | const TargetInstrInfo *TII = TM.getInstrInfo(); |
| 238 | unsigned DstReg = I->getOperand(0).getReg(); |
| 239 | unsigned SrcReg = I->getOperand(1).getReg(); |
| 240 | unsigned N = I->getOperand(2).getImm(); |
| 241 | const MCInstrDesc& Mfc1Tdd = TII->get(Mips::MFC1); |
| 242 | DebugLoc dl = I->getDebugLoc(); |
| 243 | const uint16_t* SubReg = TM.getRegisterInfo()->getSubRegisters(SrcReg); |
| 244 | |
| 245 | BuildMI(MBB, I, dl, Mfc1Tdd, DstReg).addReg(*(SubReg + N)); |
| 246 | } |
| 247 | |
| 248 | void MipsInstrInfo::ExpandBuildPairF64(MachineBasicBlock &MBB, |
| 249 | MachineBasicBlock::iterator I) const { |
| 250 | const TargetInstrInfo *TII = TM.getInstrInfo(); |
| 251 | unsigned DstReg = I->getOperand(0).getReg(); |
| 252 | unsigned LoReg = I->getOperand(1).getReg(), HiReg = I->getOperand(2).getReg(); |
| 253 | const MCInstrDesc& Mtc1Tdd = TII->get(Mips::MTC1); |
| 254 | DebugLoc dl = I->getDebugLoc(); |
| 255 | const uint16_t* SubReg = |
| 256 | TM.getRegisterInfo()->getSubRegisters(DstReg); |
| 257 | |
| 258 | // mtc1 Lo, $fp |
| 259 | // mtc1 Hi, $fp + 1 |
| 260 | BuildMI(MBB, I, dl, Mtc1Tdd, *SubReg).addReg(LoReg); |
| 261 | BuildMI(MBB, I, dl, Mtc1Tdd, *(SubReg + 1)).addReg(HiReg); |
| 262 | } |
| 263 | |
| 264 | bool MipsInstrInfo::expandPostRAPseudo(MachineBasicBlock::iterator MI) const { |
| 265 | MachineBasicBlock &MBB = *MI->getParent(); |
| 266 | |
| 267 | switch(MI->getDesc().getOpcode()) { |
| 268 | default: |
| 269 | return false; |
| 270 | case Mips::BuildPairF64: |
| 271 | ExpandBuildPairF64(MBB, MI); |
| 272 | break; |
| 273 | case Mips::ExtractElementF64: |
| 274 | ExpandExtractElementF64(MBB, MI); |
| 275 | break; |
| 276 | } |
| 277 | |
| 278 | MBB.erase(MI); |
| 279 | return true; |
| 280 | } |
| 281 | |
Akira Hatanaka | c4f24eb | 2011-07-01 01:04:43 +0000 | [diff] [blame] | 282 | MachineInstr* |
| 283 | MipsInstrInfo::emitFrameIndexDebugValue(MachineFunction &MF, int FrameIx, |
| 284 | uint64_t Offset, const MDNode *MDPtr, |
| 285 | DebugLoc DL) const { |
| 286 | MachineInstrBuilder MIB = BuildMI(MF, DL, get(Mips::DBG_VALUE)) |
| 287 | .addFrameIndex(FrameIx).addImm(0).addImm(Offset).addMetadata(MDPtr); |
| 288 | return &*MIB; |
| 289 | } |
| 290 | |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 291 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 292 | // Branch Analysis |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 293 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 294 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 295 | static unsigned GetAnalyzableBrOpc(unsigned Opc) { |
Akira Hatanaka | 3e3427a | 2011-10-11 18:49:17 +0000 | [diff] [blame] | 296 | return (Opc == Mips::BEQ || Opc == Mips::BNE || Opc == Mips::BGTZ || |
| 297 | Opc == Mips::BGEZ || Opc == Mips::BLTZ || Opc == Mips::BLEZ || |
| 298 | Opc == Mips::BEQ64 || Opc == Mips::BNE64 || Opc == Mips::BGTZ64 || |
| 299 | Opc == Mips::BGEZ64 || Opc == Mips::BLTZ64 || Opc == Mips::BLEZ64 || |
Akira Hatanaka | 6e55ff5 | 2011-12-12 22:39:35 +0000 | [diff] [blame] | 300 | Opc == Mips::BC1T || Opc == Mips::BC1F || Opc == Mips::B || |
| 301 | Opc == Mips::J) ? |
Akira Hatanaka | 3e3427a | 2011-10-11 18:49:17 +0000 | [diff] [blame] | 302 | Opc : 0; |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 303 | } |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 304 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 305 | /// GetOppositeBranchOpc - Return the inverse of the specified |
| 306 | /// opcode, e.g. turning BEQ to BNE. |
| 307 | unsigned Mips::GetOppositeBranchOpc(unsigned Opc) |
| 308 | { |
| 309 | switch (Opc) { |
Akira Hatanaka | 8209968 | 2011-12-19 19:52:25 +0000 | [diff] [blame] | 310 | default: llvm_unreachable("Illegal opcode!"); |
| 311 | case Mips::BEQ: return Mips::BNE; |
| 312 | case Mips::BNE: return Mips::BEQ; |
| 313 | case Mips::BGTZ: return Mips::BLEZ; |
| 314 | case Mips::BGEZ: return Mips::BLTZ; |
| 315 | case Mips::BLTZ: return Mips::BGEZ; |
| 316 | case Mips::BLEZ: return Mips::BGTZ; |
| 317 | case Mips::BEQ64: return Mips::BNE64; |
| 318 | case Mips::BNE64: return Mips::BEQ64; |
| 319 | case Mips::BGTZ64: return Mips::BLEZ64; |
| 320 | case Mips::BGEZ64: return Mips::BLTZ64; |
| 321 | case Mips::BLTZ64: return Mips::BGEZ64; |
| 322 | case Mips::BLEZ64: return Mips::BGTZ64; |
| 323 | case Mips::BC1T: return Mips::BC1F; |
| 324 | case Mips::BC1F: return Mips::BC1T; |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 328 | static void AnalyzeCondBr(const MachineInstr* Inst, unsigned Opc, |
| 329 | MachineBasicBlock *&BB, |
| 330 | SmallVectorImpl<MachineOperand>& Cond) { |
| 331 | assert(GetAnalyzableBrOpc(Opc) && "Not an analyzable branch"); |
| 332 | int NumOp = Inst->getNumExplicitOperands(); |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 333 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 334 | // for both int and fp branches, the last explicit operand is the |
| 335 | // MBB. |
| 336 | BB = Inst->getOperand(NumOp-1).getMBB(); |
| 337 | Cond.push_back(MachineOperand::CreateImm(Opc)); |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 338 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 339 | for (int i=0; i<NumOp-1; i++) |
| 340 | Cond.push_back(Inst->getOperand(i)); |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 341 | } |
| 342 | |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 343 | bool MipsInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB, |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 344 | MachineBasicBlock *&TBB, |
| 345 | MachineBasicBlock *&FBB, |
Evan Cheng | dc54d31 | 2009-02-09 07:14:22 +0000 | [diff] [blame] | 346 | SmallVectorImpl<MachineOperand> &Cond, |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 347 | bool AllowModify) const |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 348 | { |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 349 | MachineBasicBlock::reverse_iterator I = MBB.rbegin(), REnd = MBB.rend(); |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 350 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 351 | // Skip all the debug instructions. |
| 352 | while (I != REnd && I->isDebugValue()) |
| 353 | ++I; |
| 354 | |
| 355 | if (I == REnd || !isUnpredicatedTerminator(&*I)) { |
| 356 | // If this block ends with no branches (it just falls through to its succ) |
| 357 | // just return false, leaving TBB/FBB null. |
| 358 | TBB = FBB = NULL; |
| 359 | return false; |
| 360 | } |
| 361 | |
| 362 | MachineInstr *LastInst = &*I; |
| 363 | unsigned LastOpc = LastInst->getOpcode(); |
| 364 | |
| 365 | // Not an analyzable branch (must be an indirect jump). |
| 366 | if (!GetAnalyzableBrOpc(LastOpc)) |
| 367 | return true; |
| 368 | |
| 369 | // Get the second to last instruction in the block. |
| 370 | unsigned SecondLastOpc = 0; |
| 371 | MachineInstr *SecondLastInst = NULL; |
| 372 | |
| 373 | if (++I != REnd) { |
| 374 | SecondLastInst = &*I; |
| 375 | SecondLastOpc = GetAnalyzableBrOpc(SecondLastInst->getOpcode()); |
| 376 | |
| 377 | // Not an analyzable branch (must be an indirect jump). |
| 378 | if (isUnpredicatedTerminator(SecondLastInst) && !SecondLastOpc) |
| 379 | return true; |
| 380 | } |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 381 | |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 382 | // If there is only one terminator instruction, process it. |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 383 | if (!SecondLastOpc) { |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 384 | // Unconditional branch |
Akira Hatanaka | 6e55ff5 | 2011-12-12 22:39:35 +0000 | [diff] [blame] | 385 | if (LastOpc == UncondBrOpc) { |
Chris Lattner | 8aa797a | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 386 | TBB = LastInst->getOperand(0).getMBB(); |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 387 | return false; |
| 388 | } |
| 389 | |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 390 | // Conditional branch |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 391 | AnalyzeCondBr(LastInst, LastOpc, TBB, Cond); |
| 392 | return false; |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 393 | } |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 394 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 395 | // If we reached here, there are two branches. |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 396 | // If there are three terminators, we don't know what sort of block this is. |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 397 | if (++I != REnd && isUnpredicatedTerminator(&*I)) |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 398 | return true; |
| 399 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 400 | // If second to last instruction is an unconditional branch, |
| 401 | // analyze it and remove the last instruction. |
Akira Hatanaka | 6e55ff5 | 2011-12-12 22:39:35 +0000 | [diff] [blame] | 402 | if (SecondLastOpc == UncondBrOpc) { |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 403 | // Return if the last instruction cannot be removed. |
| 404 | if (!AllowModify) |
| 405 | return true; |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 406 | |
Chris Lattner | 8aa797a | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 407 | TBB = SecondLastInst->getOperand(0).getMBB(); |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 408 | LastInst->eraseFromParent(); |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 409 | return false; |
| 410 | } |
| 411 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 412 | // Conditional branch followed by an unconditional branch. |
| 413 | // The last one must be unconditional. |
Akira Hatanaka | 6e55ff5 | 2011-12-12 22:39:35 +0000 | [diff] [blame] | 414 | if (LastOpc != UncondBrOpc) |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 415 | return true; |
| 416 | |
| 417 | AnalyzeCondBr(SecondLastInst, SecondLastOpc, TBB, Cond); |
| 418 | FBB = LastInst->getOperand(0).getMBB(); |
| 419 | |
| 420 | return false; |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 421 | } |
| 422 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 423 | void MipsInstrInfo::BuildCondBr(MachineBasicBlock &MBB, |
| 424 | MachineBasicBlock *TBB, DebugLoc DL, |
| 425 | const SmallVectorImpl<MachineOperand>& Cond) |
| 426 | const { |
| 427 | unsigned Opc = Cond[0].getImm(); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 428 | const MCInstrDesc &MCID = get(Opc); |
| 429 | MachineInstrBuilder MIB = BuildMI(&MBB, DL, MCID); |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 430 | |
| 431 | for (unsigned i = 1; i < Cond.size(); ++i) |
| 432 | MIB.addReg(Cond[i].getReg()); |
| 433 | |
| 434 | MIB.addMBB(TBB); |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 435 | } |
| 436 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 437 | unsigned MipsInstrInfo:: |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 438 | InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
Owen Anderson | 44eb65c | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 439 | MachineBasicBlock *FBB, |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 440 | const SmallVectorImpl<MachineOperand> &Cond, |
| 441 | DebugLoc DL) const { |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 442 | // Shouldn't be a fall through. |
| 443 | assert(TBB && "InsertBranch must not be told to insert a fallthrough"); |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 444 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 445 | // # of condition operands: |
| 446 | // Unconditional branches: 0 |
| 447 | // Floating point branches: 1 (opc) |
| 448 | // Int BranchZero: 2 (opc, reg) |
| 449 | // Int Branch: 3 (opc, reg0, reg1) |
| 450 | assert((Cond.size() <= 3) && |
| 451 | "# of Mips branch conditions must be <= 3!"); |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 452 | |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 453 | // Two-way Conditional branch. |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 454 | if (FBB) { |
| 455 | BuildCondBr(MBB, TBB, DL, Cond); |
Akira Hatanaka | 6e55ff5 | 2011-12-12 22:39:35 +0000 | [diff] [blame] | 456 | BuildMI(&MBB, DL, get(UncondBrOpc)).addMBB(FBB); |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 457 | return 2; |
| 458 | } |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 459 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 460 | // One way branch. |
| 461 | // Unconditional branch. |
| 462 | if (Cond.empty()) |
Akira Hatanaka | 6e55ff5 | 2011-12-12 22:39:35 +0000 | [diff] [blame] | 463 | BuildMI(&MBB, DL, get(UncondBrOpc)).addMBB(TBB); |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 464 | else // Conditional branch. |
| 465 | BuildCondBr(MBB, TBB, DL, Cond); |
| 466 | return 1; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 467 | } |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 468 | |
| 469 | unsigned MipsInstrInfo:: |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 470 | RemoveBranch(MachineBasicBlock &MBB) const |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 471 | { |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 472 | MachineBasicBlock::reverse_iterator I = MBB.rbegin(), REnd = MBB.rend(); |
| 473 | MachineBasicBlock::reverse_iterator FirstBr; |
| 474 | unsigned removed; |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 475 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 476 | // Skip all the debug instructions. |
| 477 | while (I != REnd && I->isDebugValue()) |
| 478 | ++I; |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 479 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 480 | FirstBr = I; |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 481 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 482 | // Up to 2 branches are removed. |
| 483 | // Note that indirect branches are not removed. |
| 484 | for(removed = 0; I != REnd && removed < 2; ++I, ++removed) |
| 485 | if (!GetAnalyzableBrOpc(I->getOpcode())) |
| 486 | break; |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 487 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 488 | MBB.erase(I.base(), FirstBr.base()); |
| 489 | |
| 490 | return removed; |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 493 | /// ReverseBranchCondition - Return the inverse opcode of the |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 494 | /// specified Branch instruction. |
| 495 | bool MipsInstrInfo:: |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 496 | ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 497 | { |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 498 | assert( (Cond.size() && Cond.size() <= 3) && |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 499 | "Invalid Mips branch condition!"); |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 500 | Cond[0].setImm(Mips::GetOppositeBranchOpc(Cond[0].getImm())); |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 501 | return false; |
| 502 | } |
Dan Gohman | 9911405 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 503 | |