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" |
Akira Hatanaka | 794bf17 | 2011-07-07 23:56:50 +0000 | [diff] [blame] | 15 | #include "InstPrinter/MipsInstPrinter.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "MipsAnalyzeImmediate.h" |
| 17 | #include "MipsMachineFunction.h" |
| 18 | #include "MipsTargetMachine.h" |
| 19 | #include "llvm/ADT/STLExtras.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Dan Gohman | 9911405 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 22 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | 3e74d6f | 2011-08-24 18:08:43 +0000 | [diff] [blame] | 23 | #include "llvm/Support/TargetRegistry.h" |
Evan Cheng | 22fee2d | 2011-06-28 20:07:07 +0000 | [diff] [blame] | 24 | |
Evan Cheng | 4db3cff | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 25 | #define GET_INSTRINFO_CTOR |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 26 | #include "MipsGenInstrInfo.inc" |
| 27 | |
| 28 | using namespace llvm; |
| 29 | |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 30 | MipsInstrInfo::MipsInstrInfo(MipsTargetMachine &tm, unsigned UncondBr) |
Evan Cheng | 4db3cff | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 31 | : MipsGenInstrInfo(Mips::ADJCALLSTACKDOWN, Mips::ADJCALLSTACKUP), |
Akira Hatanaka | 8589010 | 2012-07-31 23:41:32 +0000 | [diff] [blame] | 32 | TM(tm), UncondBrOpc(UncondBr) {} |
Akira Hatanaka | 794bf17 | 2011-07-07 23:56:50 +0000 | [diff] [blame] | 33 | |
Akira Hatanaka | af26626 | 2012-08-02 18:21:47 +0000 | [diff] [blame] | 34 | const MipsInstrInfo *MipsInstrInfo::create(MipsTargetMachine &TM) { |
| 35 | if (TM.getSubtargetImpl()->inMips16Mode()) |
| 36 | return llvm::createMips16InstrInfo(TM); |
| 37 | |
| 38 | return llvm::createMipsSEInstrInfo(TM); |
| 39 | } |
| 40 | |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 41 | bool MipsInstrInfo::isZeroImm(const MachineOperand &op) const { |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 42 | return op.isImm() && op.getImm() == 0; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 45 | /// insertNoop - If data hazard condition is found insert the target nop |
| 46 | /// instruction. |
| 47 | void MipsInstrInfo:: |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 48 | insertNoop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 49 | { |
Chris Lattner | c7f3ace | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 50 | DebugLoc DL; |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 51 | BuildMI(MBB, MI, DL, get(Mips::NOP)); |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 54 | MachineMemOperand *MipsInstrInfo::GetMemOperand(MachineBasicBlock &MBB, int FI, |
| 55 | unsigned Flag) const { |
Akira Hatanaka | fd1d925 | 2011-12-24 03:11:18 +0000 | [diff] [blame] | 56 | MachineFunction &MF = *MBB.getParent(); |
| 57 | MachineFrameInfo &MFI = *MF.getFrameInfo(); |
| 58 | unsigned Align = MFI.getObjectAlignment(FI); |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 59 | |
Akira Hatanaka | fd1d925 | 2011-12-24 03:11:18 +0000 | [diff] [blame] | 60 | return MF.getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), Flag, |
| 61 | MFI.getObjectSize(FI), Align); |
| 62 | } |
| 63 | |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 64 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 65 | // Branch Analysis |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 66 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 67 | |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 68 | void MipsInstrInfo::AnalyzeCondBr(const MachineInstr *Inst, unsigned Opc, |
| 69 | MachineBasicBlock *&BB, |
| 70 | SmallVectorImpl<MachineOperand> &Cond) const { |
Akira Hatanaka | 6daba28 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 71 | assert(getAnalyzableBrOpc(Opc) && "Not an analyzable branch"); |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 72 | int NumOp = Inst->getNumExplicitOperands(); |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 73 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 74 | // for both int and fp branches, the last explicit operand is the |
| 75 | // MBB. |
| 76 | BB = Inst->getOperand(NumOp-1).getMBB(); |
| 77 | Cond.push_back(MachineOperand::CreateImm(Opc)); |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 78 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 79 | for (int i=0; i<NumOp-1; i++) |
| 80 | Cond.push_back(Inst->getOperand(i)); |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 83 | bool MipsInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB, |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 84 | MachineBasicBlock *&TBB, |
| 85 | MachineBasicBlock *&FBB, |
Evan Cheng | dc54d31 | 2009-02-09 07:14:22 +0000 | [diff] [blame] | 86 | SmallVectorImpl<MachineOperand> &Cond, |
Akira Hatanaka | d0a4b60 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 87 | bool AllowModify) const { |
| 88 | SmallVector<MachineInstr*, 2> BranchInstrs; |
| 89 | BranchType BT = AnalyzeBranch(MBB, TBB, FBB, Cond, AllowModify, BranchInstrs); |
Akira Hatanaka | e6ac7d6 | 2012-09-13 17:12:37 +0000 | [diff] [blame] | 90 | |
Akira Hatanaka | d0a4b60 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 91 | return (BT == BT_None) || (BT == BT_Indirect); |
Jia Liu | bb481f8 | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 94 | void MipsInstrInfo::BuildCondBr(MachineBasicBlock &MBB, |
| 95 | MachineBasicBlock *TBB, DebugLoc DL, |
| 96 | const SmallVectorImpl<MachineOperand>& Cond) |
| 97 | const { |
| 98 | unsigned Opc = Cond[0].getImm(); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 99 | const MCInstrDesc &MCID = get(Opc); |
| 100 | MachineInstrBuilder MIB = BuildMI(&MBB, DL, MCID); |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 101 | |
Akira Hatanaka | e6ac7d6 | 2012-09-13 17:12:37 +0000 | [diff] [blame] | 102 | for (unsigned i = 1; i < Cond.size(); ++i) { |
| 103 | if (Cond[i].isReg()) |
| 104 | MIB.addReg(Cond[i].getReg()); |
| 105 | else if (Cond[i].isImm()) |
| 106 | MIB.addImm(Cond[i].getImm()); |
| 107 | else |
| 108 | assert(true && "Cannot copy operand"); |
| 109 | } |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 110 | MIB.addMBB(TBB); |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 113 | unsigned MipsInstrInfo:: |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 114 | InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
Owen Anderson | 44eb65c | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 115 | MachineBasicBlock *FBB, |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 116 | const SmallVectorImpl<MachineOperand> &Cond, |
| 117 | DebugLoc DL) const { |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 118 | // Shouldn't be a fall through. |
| 119 | assert(TBB && "InsertBranch must not be told to insert a fallthrough"); |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 120 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 121 | // # of condition operands: |
| 122 | // Unconditional branches: 0 |
| 123 | // Floating point branches: 1 (opc) |
| 124 | // Int BranchZero: 2 (opc, reg) |
| 125 | // Int Branch: 3 (opc, reg0, reg1) |
| 126 | assert((Cond.size() <= 3) && |
| 127 | "# of Mips branch conditions must be <= 3!"); |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 128 | |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 129 | // Two-way Conditional branch. |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 130 | if (FBB) { |
| 131 | BuildCondBr(MBB, TBB, DL, Cond); |
Akira Hatanaka | 6e55ff5 | 2011-12-12 22:39:35 +0000 | [diff] [blame] | 132 | BuildMI(&MBB, DL, get(UncondBrOpc)).addMBB(FBB); |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 133 | return 2; |
| 134 | } |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 135 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 136 | // One way branch. |
| 137 | // Unconditional branch. |
| 138 | if (Cond.empty()) |
Akira Hatanaka | 6e55ff5 | 2011-12-12 22:39:35 +0000 | [diff] [blame] | 139 | BuildMI(&MBB, DL, get(UncondBrOpc)).addMBB(TBB); |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 140 | else // Conditional branch. |
| 141 | BuildCondBr(MBB, TBB, DL, Cond); |
| 142 | return 1; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 143 | } |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 144 | |
| 145 | unsigned MipsInstrInfo:: |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 146 | RemoveBranch(MachineBasicBlock &MBB) const |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 147 | { |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 148 | MachineBasicBlock::reverse_iterator I = MBB.rbegin(), REnd = MBB.rend(); |
| 149 | MachineBasicBlock::reverse_iterator FirstBr; |
| 150 | unsigned removed; |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 151 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 152 | // Skip all the debug instructions. |
| 153 | while (I != REnd && I->isDebugValue()) |
| 154 | ++I; |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 155 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 156 | FirstBr = I; |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 157 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 158 | // Up to 2 branches are removed. |
| 159 | // Note that indirect branches are not removed. |
| 160 | for(removed = 0; I != REnd && removed < 2; ++I, ++removed) |
Akira Hatanaka | 6daba28 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 161 | if (!getAnalyzableBrOpc(I->getOpcode())) |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 162 | break; |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 163 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 164 | MBB.erase(I.base(), FirstBr.base()); |
| 165 | |
| 166 | return removed; |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 169 | /// ReverseBranchCondition - Return the inverse opcode of the |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 170 | /// specified Branch instruction. |
| 171 | bool MipsInstrInfo:: |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 172 | ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 173 | { |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 174 | assert( (Cond.size() && Cond.size() <= 3) && |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 175 | "Invalid Mips branch condition!"); |
Akira Hatanaka | 6daba28 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 176 | Cond[0].setImm(getOppositeBranchOpc(Cond[0].getImm())); |
Bruno Cardoso Lopes | 35d2a47 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 177 | return false; |
| 178 | } |
Dan Gohman | 9911405 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 179 | |
Akira Hatanaka | d0a4b60 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 180 | MipsInstrInfo::BranchType MipsInstrInfo:: |
| 181 | AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 182 | MachineBasicBlock *&FBB, SmallVectorImpl<MachineOperand> &Cond, |
| 183 | bool AllowModify, |
| 184 | SmallVectorImpl<MachineInstr*> &BranchInstrs) const { |
| 185 | |
| 186 | MachineBasicBlock::reverse_iterator I = MBB.rbegin(), REnd = MBB.rend(); |
| 187 | |
| 188 | // Skip all the debug instructions. |
| 189 | while (I != REnd && I->isDebugValue()) |
| 190 | ++I; |
| 191 | |
| 192 | if (I == REnd || !isUnpredicatedTerminator(&*I)) { |
| 193 | // This block ends with no branches (it just falls through to its succ). |
| 194 | // Leave TBB/FBB null. |
| 195 | TBB = FBB = NULL; |
| 196 | return BT_NoBranch; |
| 197 | } |
| 198 | |
| 199 | MachineInstr *LastInst = &*I; |
| 200 | unsigned LastOpc = LastInst->getOpcode(); |
| 201 | BranchInstrs.push_back(LastInst); |
| 202 | |
| 203 | // Not an analyzable branch (e.g., indirect jump). |
Akira Hatanaka | 6daba28 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 204 | if (!getAnalyzableBrOpc(LastOpc)) |
Akira Hatanaka | d0a4b60 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 205 | return LastInst->isIndirectBranch() ? BT_Indirect : BT_None; |
| 206 | |
| 207 | // Get the second to last instruction in the block. |
| 208 | unsigned SecondLastOpc = 0; |
| 209 | MachineInstr *SecondLastInst = NULL; |
| 210 | |
| 211 | if (++I != REnd) { |
| 212 | SecondLastInst = &*I; |
Akira Hatanaka | 6daba28 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 213 | SecondLastOpc = getAnalyzableBrOpc(SecondLastInst->getOpcode()); |
Akira Hatanaka | d0a4b60 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 214 | |
| 215 | // Not an analyzable branch (must be an indirect jump). |
| 216 | if (isUnpredicatedTerminator(SecondLastInst) && !SecondLastOpc) |
| 217 | return BT_None; |
| 218 | } |
| 219 | |
Akira Hatanaka | d0a4b60 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 220 | // If there is only one terminator instruction, process it. |
| 221 | if (!SecondLastOpc) { |
| 222 | // Unconditional branch |
| 223 | if (LastOpc == UncondBrOpc) { |
| 224 | TBB = LastInst->getOperand(0).getMBB(); |
| 225 | return BT_Uncond; |
| 226 | } |
| 227 | |
| 228 | // Conditional branch |
| 229 | AnalyzeCondBr(LastInst, LastOpc, TBB, Cond); |
| 230 | return BT_Cond; |
| 231 | } |
| 232 | |
| 233 | // If we reached here, there are two branches. |
| 234 | // If there are three terminators, we don't know what sort of block this is. |
| 235 | if (++I != REnd && isUnpredicatedTerminator(&*I)) |
| 236 | return BT_None; |
| 237 | |
Akira Hatanaka | 888e8fe | 2013-03-01 01:22:26 +0000 | [diff] [blame] | 238 | BranchInstrs.insert(BranchInstrs.begin(), SecondLastInst); |
| 239 | |
Akira Hatanaka | d0a4b60 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 240 | // If second to last instruction is an unconditional branch, |
| 241 | // analyze it and remove the last instruction. |
| 242 | if (SecondLastOpc == UncondBrOpc) { |
| 243 | // Return if the last instruction cannot be removed. |
| 244 | if (!AllowModify) |
| 245 | return BT_None; |
| 246 | |
| 247 | TBB = SecondLastInst->getOperand(0).getMBB(); |
| 248 | LastInst->eraseFromParent(); |
| 249 | BranchInstrs.pop_back(); |
| 250 | return BT_Uncond; |
| 251 | } |
| 252 | |
| 253 | // Conditional branch followed by an unconditional branch. |
| 254 | // The last one must be unconditional. |
| 255 | if (LastOpc != UncondBrOpc) |
| 256 | return BT_None; |
| 257 | |
| 258 | AnalyzeCondBr(SecondLastInst, SecondLastOpc, TBB, Cond); |
| 259 | FBB = LastInst->getOperand(0).getMBB(); |
| 260 | |
| 261 | return BT_CondUncond; |
| 262 | } |
| 263 | |
Akira Hatanaka | d4b48b2 | 2012-06-14 01:16:45 +0000 | [diff] [blame] | 264 | /// Return the number of bytes of code the specified instruction may be. |
| 265 | unsigned MipsInstrInfo::GetInstSizeInBytes(const MachineInstr *MI) const { |
| 266 | switch (MI->getOpcode()) { |
| 267 | default: |
| 268 | return MI->getDesc().getSize(); |
| 269 | case TargetOpcode::INLINEASM: { // Inline Asm: Variable size. |
| 270 | const MachineFunction *MF = MI->getParent()->getParent(); |
| 271 | const char *AsmStr = MI->getOperand(0).getSymbolName(); |
| 272 | return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo()); |
| 273 | } |
| 274 | } |
| 275 | } |
Akira Hatanaka | 151687c | 2013-05-13 17:57:42 +0000 | [diff] [blame] | 276 | |
| 277 | MachineInstrBuilder |
| 278 | MipsInstrInfo::genInstrWithNewOpc(unsigned NewOpc, |
| 279 | MachineBasicBlock::iterator I) const { |
| 280 | MachineInstrBuilder MIB; |
| 281 | MIB = BuildMI(*I->getParent(), I, I->getDebugLoc(), get(NewOpc)); |
| 282 | |
| 283 | for (unsigned J = 0, E = I->getDesc().getNumOperands(); J < E; ++J) |
| 284 | MIB.addOperand(I->getOperand(J)); |
| 285 | |
| 286 | MIB.setMemRefs(I->memoperands_begin(), I->memoperands_end()); |
| 287 | return MIB; |
| 288 | } |