Jia Liu | 9f61011 | 2012-02-17 08:55:11 +0000 | [diff] [blame] | 1 | //===-- MipsInstrInfo.cpp - Mips Instruction Information ------------------===// |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 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 | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 7 | // |
Akira Hatanaka | e248912 | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file contains the Mips implementation of the TargetInstrInfo class. |
| 11 | // |
Akira Hatanaka | e248912 | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 13 | |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 14 | #include "MipsInstrInfo.h" |
Akira Hatanaka | 9c6028f | 2011-07-07 23:56:50 +0000 | [diff] [blame] | 15 | #include "InstPrinter/MipsInstPrinter.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "MipsMachineFunction.h" |
Eric Christopher | d8abc3a | 2015-01-08 18:18:54 +0000 | [diff] [blame] | 17 | #include "MipsSubtarget.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/STLExtras.h" |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Dan Gohman | d5ca7064 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Torok Edwin | 56d0659 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 21 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | 2bb4035 | 2011-08-24 18:08:43 +0000 | [diff] [blame] | 22 | #include "llvm/Support/TargetRegistry.h" |
Evan Cheng | 1e210d0 | 2011-06-28 20:07:07 +0000 | [diff] [blame] | 23 | |
Chandler Carruth | d174b72 | 2014-04-22 02:03:14 +0000 | [diff] [blame] | 24 | using namespace llvm; |
| 25 | |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 26 | #define GET_INSTRINFO_CTOR_DTOR |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 27 | #include "MipsGenInstrInfo.inc" |
| 28 | |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 29 | // Pin the vtable to this file. |
| 30 | void MipsInstrInfo::anchor() {} |
| 31 | |
Eric Christopher | 675cb4d | 2014-07-18 23:25:00 +0000 | [diff] [blame] | 32 | MipsInstrInfo::MipsInstrInfo(const MipsSubtarget &STI, unsigned UncondBr) |
| 33 | : MipsGenInstrInfo(Mips::ADJCALLSTACKDOWN, Mips::ADJCALLSTACKUP), |
| 34 | Subtarget(STI), UncondBrOpc(UncondBr) {} |
Akira Hatanaka | 9c6028f | 2011-07-07 23:56:50 +0000 | [diff] [blame] | 35 | |
Eric Christopher | 675cb4d | 2014-07-18 23:25:00 +0000 | [diff] [blame] | 36 | const MipsInstrInfo *MipsInstrInfo::create(MipsSubtarget &STI) { |
| 37 | if (STI.inMips16Mode()) |
| 38 | return llvm::createMips16InstrInfo(STI); |
Akira Hatanaka | fab8929 | 2012-08-02 18:21:47 +0000 | [diff] [blame] | 39 | |
Eric Christopher | 675cb4d | 2014-07-18 23:25:00 +0000 | [diff] [blame] | 40 | return llvm::createMipsSEInstrInfo(STI); |
Akira Hatanaka | fab8929 | 2012-08-02 18:21:47 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 43 | bool MipsInstrInfo::isZeroImm(const MachineOperand &op) const { |
Dan Gohman | 0d1e9a8 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 44 | return op.isImm() && op.getImm() == 0; |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Bruno Cardoso Lopes | 7b616f5 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 47 | /// insertNoop - If data hazard condition is found insert the target nop |
| 48 | /// instruction. |
Simon Dardis | 9a3f32c | 2016-03-29 13:02:19 +0000 | [diff] [blame] | 49 | // FIXME: This appears to be dead code. |
Bruno Cardoso Lopes | 7b616f5 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 50 | void MipsInstrInfo:: |
Bruno Cardoso Lopes | ed874ef | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 51 | insertNoop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const |
Bruno Cardoso Lopes | 7b616f5 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 52 | { |
Chris Lattner | 6f306d7 | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 53 | DebugLoc DL; |
Bill Wendling | f6d609a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 54 | BuildMI(MBB, MI, DL, get(Mips::NOP)); |
Bruno Cardoso Lopes | 7b616f5 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Justin Lebar | 0af80cd | 2016-07-15 18:26:59 +0000 | [diff] [blame] | 57 | MachineMemOperand * |
| 58 | MipsInstrInfo::GetMemOperand(MachineBasicBlock &MBB, int FI, |
| 59 | MachineMemOperand::Flags Flags) const { |
Akira Hatanaka | 1cf7576 | 2011-12-24 03:11:18 +0000 | [diff] [blame] | 60 | MachineFunction &MF = *MBB.getParent(); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 61 | MachineFrameInfo &MFI = MF.getFrameInfo(); |
Akira Hatanaka | 1cf7576 | 2011-12-24 03:11:18 +0000 | [diff] [blame] | 62 | unsigned Align = MFI.getObjectAlignment(FI); |
Jia Liu | f54f60f | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 63 | |
Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 64 | return MF.getMachineMemOperand(MachinePointerInfo::getFixedStack(MF, FI), |
Justin Lebar | 0af80cd | 2016-07-15 18:26:59 +0000 | [diff] [blame] | 65 | Flags, MFI.getObjectSize(FI), Align); |
Akira Hatanaka | 1cf7576 | 2011-12-24 03:11:18 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Akira Hatanaka | e248912 | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 68 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 7b616f5 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 69 | // Branch Analysis |
Akira Hatanaka | e248912 | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 70 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 7b616f5 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 71 | |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 72 | void MipsInstrInfo::AnalyzeCondBr(const MachineInstr *Inst, unsigned Opc, |
| 73 | MachineBasicBlock *&BB, |
| 74 | SmallVectorImpl<MachineOperand> &Cond) const { |
Akira Hatanaka | 067d815 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 75 | assert(getAnalyzableBrOpc(Opc) && "Not an analyzable branch"); |
Akira Hatanaka | 93f898f | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 76 | int NumOp = Inst->getNumExplicitOperands(); |
Jia Liu | f54f60f | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 77 | |
Akira Hatanaka | 93f898f | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 78 | // for both int and fp branches, the last explicit operand is the |
| 79 | // MBB. |
| 80 | BB = Inst->getOperand(NumOp-1).getMBB(); |
| 81 | Cond.push_back(MachineOperand::CreateImm(Opc)); |
Bruno Cardoso Lopes | bcaf6e5 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 82 | |
Akira Hatanaka | 93f898f | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 83 | for (int i=0; i<NumOp-1; i++) |
| 84 | Cond.push_back(Inst->getOperand(i)); |
Bruno Cardoso Lopes | 7b616f5 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Jacques Pienaar | 71c30a1 | 2016-07-15 14:41:04 +0000 | [diff] [blame] | 87 | bool MipsInstrInfo::analyzeBranch(MachineBasicBlock &MBB, |
Bruno Cardoso Lopes | 7b616f5 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 88 | MachineBasicBlock *&TBB, |
| 89 | MachineBasicBlock *&FBB, |
Evan Cheng | 64dfcac | 2009-02-09 07:14:22 +0000 | [diff] [blame] | 90 | SmallVectorImpl<MachineOperand> &Cond, |
Akira Hatanaka | 7320b23 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 91 | bool AllowModify) const { |
| 92 | SmallVector<MachineInstr*, 2> BranchInstrs; |
Jacques Pienaar | 71c30a1 | 2016-07-15 14:41:04 +0000 | [diff] [blame] | 93 | BranchType BT = analyzeBranch(MBB, TBB, FBB, Cond, AllowModify, BranchInstrs); |
Akira Hatanaka | fcdd9b1 | 2012-09-13 17:12:37 +0000 | [diff] [blame] | 94 | |
Akira Hatanaka | 7320b23 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 95 | return (BT == BT_None) || (BT == BT_Indirect); |
Jia Liu | f54f60f | 2012-02-28 07:46:26 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 98 | void MipsInstrInfo::BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| 99 | const DebugLoc &DL, |
| 100 | ArrayRef<MachineOperand> Cond) const { |
Akira Hatanaka | 93f898f | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 101 | unsigned Opc = Cond[0].getImm(); |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 102 | const MCInstrDesc &MCID = get(Opc); |
| 103 | MachineInstrBuilder MIB = BuildMI(&MBB, DL, MCID); |
Akira Hatanaka | 93f898f | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 104 | |
Akira Hatanaka | fcdd9b1 | 2012-09-13 17:12:37 +0000 | [diff] [blame] | 105 | for (unsigned i = 1; i < Cond.size(); ++i) { |
| 106 | if (Cond[i].isReg()) |
| 107 | MIB.addReg(Cond[i].getReg()); |
| 108 | else if (Cond[i].isImm()) |
| 109 | MIB.addImm(Cond[i].getImm()); |
| 110 | else |
Craig Topper | beb77bd | 2016-04-24 04:38:29 +0000 | [diff] [blame] | 111 | assert(false && "Cannot copy operand"); |
Akira Hatanaka | fcdd9b1 | 2012-09-13 17:12:37 +0000 | [diff] [blame] | 112 | } |
Akira Hatanaka | 93f898f | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 113 | MIB.addMBB(TBB); |
Bruno Cardoso Lopes | 7b616f5 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Matt Arsenault | e8e0f5c | 2016-09-14 17:24:15 +0000 | [diff] [blame] | 116 | unsigned MipsInstrInfo::insertBranch(MachineBasicBlock &MBB, |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 117 | MachineBasicBlock *TBB, |
| 118 | MachineBasicBlock *FBB, |
| 119 | ArrayRef<MachineOperand> Cond, |
Matt Arsenault | a2b036e | 2016-09-14 17:23:48 +0000 | [diff] [blame] | 120 | const DebugLoc &DL, |
| 121 | int *BytesAdded) const { |
Bruno Cardoso Lopes | 7b616f5 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 122 | // Shouldn't be a fall through. |
Matt Arsenault | e8e0f5c | 2016-09-14 17:24:15 +0000 | [diff] [blame] | 123 | assert(TBB && "insertBranch must not be told to insert a fallthrough"); |
Matt Arsenault | a2b036e | 2016-09-14 17:23:48 +0000 | [diff] [blame] | 124 | assert(!BytesAdded && "code size not handled"); |
Bruno Cardoso Lopes | 7b616f5 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 125 | |
Akira Hatanaka | 93f898f | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 126 | // # of condition operands: |
| 127 | // Unconditional branches: 0 |
| 128 | // Floating point branches: 1 (opc) |
| 129 | // Int BranchZero: 2 (opc, reg) |
| 130 | // Int Branch: 3 (opc, reg0, reg1) |
| 131 | assert((Cond.size() <= 3) && |
| 132 | "# of Mips branch conditions must be <= 3!"); |
Bruno Cardoso Lopes | ed874ef | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 133 | |
Bruno Cardoso Lopes | 7b616f5 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 134 | // Two-way Conditional branch. |
Akira Hatanaka | 93f898f | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 135 | if (FBB) { |
| 136 | BuildCondBr(MBB, TBB, DL, Cond); |
Akira Hatanaka | 5d5e0d8 | 2011-12-12 22:39:35 +0000 | [diff] [blame] | 137 | BuildMI(&MBB, DL, get(UncondBrOpc)).addMBB(FBB); |
Akira Hatanaka | 93f898f | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 138 | return 2; |
| 139 | } |
Bruno Cardoso Lopes | 7b616f5 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 140 | |
Akira Hatanaka | 93f898f | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 141 | // One way branch. |
| 142 | // Unconditional branch. |
| 143 | if (Cond.empty()) |
Akira Hatanaka | 5d5e0d8 | 2011-12-12 22:39:35 +0000 | [diff] [blame] | 144 | BuildMI(&MBB, DL, get(UncondBrOpc)).addMBB(TBB); |
Akira Hatanaka | 93f898f | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 145 | else // Conditional branch. |
| 146 | BuildCondBr(MBB, TBB, DL, Cond); |
| 147 | return 1; |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 148 | } |
Bruno Cardoso Lopes | 7b616f5 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 149 | |
Matt Arsenault | 1b9fc8e | 2016-09-14 20:43:16 +0000 | [diff] [blame] | 150 | unsigned MipsInstrInfo::removeBranch(MachineBasicBlock &MBB, |
Matt Arsenault | a2b036e | 2016-09-14 17:23:48 +0000 | [diff] [blame] | 151 | int *BytesRemoved) const { |
| 152 | assert(!BytesRemoved && "code size not handled"); |
| 153 | |
Akira Hatanaka | 93f898f | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 154 | MachineBasicBlock::reverse_iterator I = MBB.rbegin(), REnd = MBB.rend(); |
Akira Hatanaka | 93f898f | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 155 | unsigned removed; |
Bruno Cardoso Lopes | ed874ef | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 156 | |
Akira Hatanaka | 93f898f | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 157 | // Skip all the debug instructions. |
| 158 | while (I != REnd && I->isDebugValue()) |
| 159 | ++I; |
Bruno Cardoso Lopes | ed874ef | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 160 | |
Duncan P. N. Exon Smith | 1872096 | 2016-09-11 18:51:28 +0000 | [diff] [blame] | 161 | if (I == REnd) |
| 162 | return 0; |
| 163 | |
| 164 | MachineBasicBlock::iterator FirstBr = ++I.getReverse(); |
Bruno Cardoso Lopes | ed874ef | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 165 | |
Akira Hatanaka | 93f898f | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 166 | // Up to 2 branches are removed. |
| 167 | // Note that indirect branches are not removed. |
Eric Christopher | 675cb4d | 2014-07-18 23:25:00 +0000 | [diff] [blame] | 168 | for (removed = 0; I != REnd && removed < 2; ++I, ++removed) |
Akira Hatanaka | 067d815 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 169 | if (!getAnalyzableBrOpc(I->getOpcode())) |
Akira Hatanaka | 93f898f | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 170 | break; |
Bruno Cardoso Lopes | ed874ef | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 171 | |
Duncan P. N. Exon Smith | 1872096 | 2016-09-11 18:51:28 +0000 | [diff] [blame] | 172 | MBB.erase((--I).getReverse(), FirstBr); |
Akira Hatanaka | 93f898f | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 173 | |
| 174 | return removed; |
Bruno Cardoso Lopes | 7b616f5 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Matt Arsenault | 1b9fc8e | 2016-09-14 20:43:16 +0000 | [diff] [blame] | 177 | /// reverseBranchCondition - Return the inverse opcode of the |
Bruno Cardoso Lopes | 7b616f5 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 178 | /// specified Branch instruction. |
Matt Arsenault | 1b9fc8e | 2016-09-14 20:43:16 +0000 | [diff] [blame] | 179 | bool MipsInstrInfo::reverseBranchCondition( |
Eric Christopher | 754d54f | 2014-07-18 20:35:49 +0000 | [diff] [blame] | 180 | SmallVectorImpl<MachineOperand> &Cond) const { |
Akira Hatanaka | 93f898f | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 181 | assert( (Cond.size() && Cond.size() <= 3) && |
Bruno Cardoso Lopes | 7b616f5 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 182 | "Invalid Mips branch condition!"); |
Akira Hatanaka | 067d815 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 183 | Cond[0].setImm(getOppositeBranchOpc(Cond[0].getImm())); |
Bruno Cardoso Lopes | 7b616f5 | 2007-08-18 01:56:48 +0000 | [diff] [blame] | 184 | return false; |
| 185 | } |
Dan Gohman | d5ca7064 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 186 | |
Jacques Pienaar | 71c30a1 | 2016-07-15 14:41:04 +0000 | [diff] [blame] | 187 | MipsInstrInfo::BranchType MipsInstrInfo::analyzeBranch( |
Eric Christopher | 754d54f | 2014-07-18 20:35:49 +0000 | [diff] [blame] | 188 | MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, |
| 189 | SmallVectorImpl<MachineOperand> &Cond, bool AllowModify, |
| 190 | SmallVectorImpl<MachineInstr *> &BranchInstrs) const { |
Akira Hatanaka | 7320b23 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 191 | |
| 192 | MachineBasicBlock::reverse_iterator I = MBB.rbegin(), REnd = MBB.rend(); |
| 193 | |
| 194 | // Skip all the debug instructions. |
| 195 | while (I != REnd && I->isDebugValue()) |
| 196 | ++I; |
| 197 | |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 198 | if (I == REnd || !isUnpredicatedTerminator(*I)) { |
Akira Hatanaka | 7320b23 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 199 | // This block ends with no branches (it just falls through to its succ). |
| 200 | // Leave TBB/FBB null. |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 201 | TBB = FBB = nullptr; |
Akira Hatanaka | 7320b23 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 202 | return BT_NoBranch; |
| 203 | } |
| 204 | |
| 205 | MachineInstr *LastInst = &*I; |
| 206 | unsigned LastOpc = LastInst->getOpcode(); |
| 207 | BranchInstrs.push_back(LastInst); |
| 208 | |
| 209 | // Not an analyzable branch (e.g., indirect jump). |
Akira Hatanaka | 067d815 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 210 | if (!getAnalyzableBrOpc(LastOpc)) |
Akira Hatanaka | 7320b23 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 211 | return LastInst->isIndirectBranch() ? BT_Indirect : BT_None; |
| 212 | |
| 213 | // Get the second to last instruction in the block. |
| 214 | unsigned SecondLastOpc = 0; |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 215 | MachineInstr *SecondLastInst = nullptr; |
Akira Hatanaka | 7320b23 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 216 | |
| 217 | if (++I != REnd) { |
| 218 | SecondLastInst = &*I; |
Akira Hatanaka | 067d815 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 219 | SecondLastOpc = getAnalyzableBrOpc(SecondLastInst->getOpcode()); |
Akira Hatanaka | 7320b23 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 220 | |
| 221 | // Not an analyzable branch (must be an indirect jump). |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 222 | if (isUnpredicatedTerminator(*SecondLastInst) && !SecondLastOpc) |
Akira Hatanaka | 7320b23 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 223 | return BT_None; |
| 224 | } |
| 225 | |
Akira Hatanaka | 7320b23 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 226 | // If there is only one terminator instruction, process it. |
| 227 | if (!SecondLastOpc) { |
Matheus Almeida | 6de62d3 | 2013-10-01 12:53:00 +0000 | [diff] [blame] | 228 | // Unconditional branch. |
Daniel Sanders | f9d8b8c | 2016-05-06 13:23:51 +0000 | [diff] [blame] | 229 | if (LastInst->isUnconditionalBranch()) { |
Akira Hatanaka | 7320b23 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 230 | TBB = LastInst->getOperand(0).getMBB(); |
| 231 | return BT_Uncond; |
| 232 | } |
| 233 | |
| 234 | // Conditional branch |
| 235 | AnalyzeCondBr(LastInst, LastOpc, TBB, Cond); |
| 236 | return BT_Cond; |
| 237 | } |
| 238 | |
| 239 | // If we reached here, there are two branches. |
| 240 | // If there are three terminators, we don't know what sort of block this is. |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 241 | if (++I != REnd && isUnpredicatedTerminator(*I)) |
Akira Hatanaka | 7320b23 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 242 | return BT_None; |
| 243 | |
Akira Hatanaka | 28dc83c | 2013-03-01 01:22:26 +0000 | [diff] [blame] | 244 | BranchInstrs.insert(BranchInstrs.begin(), SecondLastInst); |
| 245 | |
Akira Hatanaka | 7320b23 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 246 | // If second to last instruction is an unconditional branch, |
| 247 | // analyze it and remove the last instruction. |
Daniel Sanders | f9d8b8c | 2016-05-06 13:23:51 +0000 | [diff] [blame] | 248 | if (SecondLastInst->isUnconditionalBranch()) { |
Akira Hatanaka | 7320b23 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 249 | // Return if the last instruction cannot be removed. |
| 250 | if (!AllowModify) |
| 251 | return BT_None; |
| 252 | |
| 253 | TBB = SecondLastInst->getOperand(0).getMBB(); |
| 254 | LastInst->eraseFromParent(); |
| 255 | BranchInstrs.pop_back(); |
| 256 | return BT_Uncond; |
| 257 | } |
| 258 | |
| 259 | // Conditional branch followed by an unconditional branch. |
| 260 | // The last one must be unconditional. |
Daniel Sanders | f9d8b8c | 2016-05-06 13:23:51 +0000 | [diff] [blame] | 261 | if (!LastInst->isUnconditionalBranch()) |
Akira Hatanaka | 7320b23 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 262 | return BT_None; |
| 263 | |
| 264 | AnalyzeCondBr(SecondLastInst, SecondLastOpc, TBB, Cond); |
| 265 | FBB = LastInst->getOperand(0).getMBB(); |
| 266 | |
| 267 | return BT_CondUncond; |
| 268 | } |
| 269 | |
Daniel Sanders | e8efff3 | 2016-03-14 16:24:05 +0000 | [diff] [blame] | 270 | /// Return the corresponding compact (no delay slot) form of a branch. |
| 271 | unsigned MipsInstrInfo::getEquivalentCompactForm( |
| 272 | const MachineBasicBlock::iterator I) const { |
| 273 | unsigned Opcode = I->getOpcode(); |
Simon Dardis | d9d41f5 | 2016-04-05 12:50:29 +0000 | [diff] [blame] | 274 | bool canUseShortMicroMipsCTI = false; |
Daniel Sanders | e8efff3 | 2016-03-14 16:24:05 +0000 | [diff] [blame] | 275 | |
Simon Dardis | d9d41f5 | 2016-04-05 12:50:29 +0000 | [diff] [blame] | 276 | if (Subtarget.inMicroMipsMode()) { |
| 277 | switch (Opcode) { |
| 278 | case Mips::BNE: |
Hrvoje Varga | 2db00ce | 2016-07-22 07:18:33 +0000 | [diff] [blame] | 279 | case Mips::BNE_MM: |
Simon Dardis | d9d41f5 | 2016-04-05 12:50:29 +0000 | [diff] [blame] | 280 | case Mips::BEQ: |
Hrvoje Varga | 2db00ce | 2016-07-22 07:18:33 +0000 | [diff] [blame] | 281 | case Mips::BEQ_MM: |
Simon Dardis | d9d41f5 | 2016-04-05 12:50:29 +0000 | [diff] [blame] | 282 | // microMIPS has NE,EQ branches that do not have delay slots provided one |
| 283 | // of the operands is zero. |
| 284 | if (I->getOperand(1).getReg() == Subtarget.getABI().GetZeroReg()) |
| 285 | canUseShortMicroMipsCTI = true; |
| 286 | break; |
| 287 | // For microMIPS the PseudoReturn and PseudoIndirectBranch are always |
| 288 | // expanded to JR_MM, so they can be replaced with JRC16_MM. |
| 289 | case Mips::JR: |
| 290 | case Mips::PseudoReturn: |
| 291 | case Mips::PseudoIndirectBranch: |
Simon Dardis | ea34315 | 2016-08-18 13:22:43 +0000 | [diff] [blame] | 292 | case Mips::TAILCALLREG: |
Simon Dardis | d9d41f5 | 2016-04-05 12:50:29 +0000 | [diff] [blame] | 293 | canUseShortMicroMipsCTI = true; |
| 294 | break; |
| 295 | } |
| 296 | } |
| 297 | |
Simon Dardis | 669d8dd | 2016-05-18 10:38:01 +0000 | [diff] [blame] | 298 | // MIPSR6 forbids both operands being the zero register. |
| 299 | if (Subtarget.hasMips32r6() && (I->getNumOperands() > 1) && |
| 300 | (I->getOperand(0).isReg() && |
| 301 | (I->getOperand(0).getReg() == Mips::ZERO || |
| 302 | I->getOperand(0).getReg() == Mips::ZERO_64)) && |
| 303 | (I->getOperand(1).isReg() && |
| 304 | (I->getOperand(1).getReg() == Mips::ZERO || |
| 305 | I->getOperand(1).getReg() == Mips::ZERO_64))) |
| 306 | return 0; |
| 307 | |
Simon Dardis | d9d41f5 | 2016-04-05 12:50:29 +0000 | [diff] [blame] | 308 | if (Subtarget.hasMips32r6() || canUseShortMicroMipsCTI) { |
Daniel Sanders | e8efff3 | 2016-03-14 16:24:05 +0000 | [diff] [blame] | 309 | switch (Opcode) { |
| 310 | case Mips::B: |
| 311 | return Mips::BC; |
| 312 | case Mips::BAL: |
| 313 | return Mips::BALC; |
| 314 | case Mips::BEQ: |
Hrvoje Varga | 2db00ce | 2016-07-22 07:18:33 +0000 | [diff] [blame] | 315 | case Mips::BEQ_MM: |
Simon Dardis | d9d41f5 | 2016-04-05 12:50:29 +0000 | [diff] [blame] | 316 | if (canUseShortMicroMipsCTI) |
Daniel Sanders | e8efff3 | 2016-03-14 16:24:05 +0000 | [diff] [blame] | 317 | return Mips::BEQZC_MM; |
Simon Dardis | 03676dc | 2016-05-31 09:54:55 +0000 | [diff] [blame] | 318 | else if (I->getOperand(0).getReg() == I->getOperand(1).getReg()) |
| 319 | return 0; |
| 320 | return Mips::BEQC; |
Daniel Sanders | e8efff3 | 2016-03-14 16:24:05 +0000 | [diff] [blame] | 321 | case Mips::BNE: |
Hrvoje Varga | 2db00ce | 2016-07-22 07:18:33 +0000 | [diff] [blame] | 322 | case Mips::BNE_MM: |
Simon Dardis | d9d41f5 | 2016-04-05 12:50:29 +0000 | [diff] [blame] | 323 | if (canUseShortMicroMipsCTI) |
Daniel Sanders | e8efff3 | 2016-03-14 16:24:05 +0000 | [diff] [blame] | 324 | return Mips::BNEZC_MM; |
Simon Dardis | 03676dc | 2016-05-31 09:54:55 +0000 | [diff] [blame] | 325 | else if (I->getOperand(0).getReg() == I->getOperand(1).getReg()) |
| 326 | return 0; |
| 327 | return Mips::BNEC; |
Daniel Sanders | e8efff3 | 2016-03-14 16:24:05 +0000 | [diff] [blame] | 328 | case Mips::BGE: |
Simon Dardis | 669d8dd | 2016-05-18 10:38:01 +0000 | [diff] [blame] | 329 | if (I->getOperand(0).getReg() == I->getOperand(1).getReg()) |
| 330 | return 0; |
Daniel Sanders | e8efff3 | 2016-03-14 16:24:05 +0000 | [diff] [blame] | 331 | return Mips::BGEC; |
| 332 | case Mips::BGEU: |
Simon Dardis | 669d8dd | 2016-05-18 10:38:01 +0000 | [diff] [blame] | 333 | if (I->getOperand(0).getReg() == I->getOperand(1).getReg()) |
| 334 | return 0; |
Daniel Sanders | e8efff3 | 2016-03-14 16:24:05 +0000 | [diff] [blame] | 335 | return Mips::BGEUC; |
| 336 | case Mips::BGEZ: |
| 337 | return Mips::BGEZC; |
| 338 | case Mips::BGTZ: |
| 339 | return Mips::BGTZC; |
| 340 | case Mips::BLEZ: |
| 341 | return Mips::BLEZC; |
| 342 | case Mips::BLT: |
Simon Dardis | 669d8dd | 2016-05-18 10:38:01 +0000 | [diff] [blame] | 343 | if (I->getOperand(0).getReg() == I->getOperand(1).getReg()) |
| 344 | return 0; |
Daniel Sanders | e8efff3 | 2016-03-14 16:24:05 +0000 | [diff] [blame] | 345 | return Mips::BLTC; |
| 346 | case Mips::BLTU: |
Simon Dardis | 669d8dd | 2016-05-18 10:38:01 +0000 | [diff] [blame] | 347 | if (I->getOperand(0).getReg() == I->getOperand(1).getReg()) |
| 348 | return 0; |
Daniel Sanders | e8efff3 | 2016-03-14 16:24:05 +0000 | [diff] [blame] | 349 | return Mips::BLTUC; |
| 350 | case Mips::BLTZ: |
| 351 | return Mips::BLTZC; |
Simon Dardis | 68a204d | 2016-07-26 10:25:07 +0000 | [diff] [blame] | 352 | case Mips::BEQ64: |
| 353 | if (I->getOperand(0).getReg() == I->getOperand(1).getReg()) |
| 354 | return 0; |
| 355 | return Mips::BEQC64; |
| 356 | case Mips::BNE64: |
| 357 | if (I->getOperand(0).getReg() == I->getOperand(1).getReg()) |
| 358 | return 0; |
| 359 | return Mips::BNEC64; |
| 360 | case Mips::BGTZ64: |
| 361 | return Mips::BGTZC64; |
| 362 | case Mips::BGEZ64: |
| 363 | return Mips::BGEZC64; |
| 364 | case Mips::BLTZ64: |
| 365 | return Mips::BLTZC64; |
| 366 | case Mips::BLEZ64: |
| 367 | return Mips::BLEZC64; |
Simon Dardis | d9d41f5 | 2016-04-05 12:50:29 +0000 | [diff] [blame] | 368 | // For MIPSR6, the instruction 'jic' can be used for these cases. Some |
| 369 | // tools will accept 'jrc reg' as an alias for 'jic 0, $reg'. |
| 370 | case Mips::JR: |
| 371 | case Mips::PseudoReturn: |
| 372 | case Mips::PseudoIndirectBranch: |
Simon Dardis | ea34315 | 2016-08-18 13:22:43 +0000 | [diff] [blame] | 373 | case Mips::TAILCALLREG: |
Simon Dardis | d9d41f5 | 2016-04-05 12:50:29 +0000 | [diff] [blame] | 374 | if (canUseShortMicroMipsCTI) |
| 375 | return Mips::JRC16_MM; |
| 376 | return Mips::JIC; |
| 377 | case Mips::JALRPseudo: |
| 378 | return Mips::JIALC; |
| 379 | case Mips::JR64: |
| 380 | case Mips::PseudoReturn64: |
| 381 | case Mips::PseudoIndirectBranch64: |
Simon Dardis | ea34315 | 2016-08-18 13:22:43 +0000 | [diff] [blame] | 382 | case Mips::TAILCALLREG64: |
Simon Dardis | d9d41f5 | 2016-04-05 12:50:29 +0000 | [diff] [blame] | 383 | return Mips::JIC64; |
| 384 | case Mips::JALR64Pseudo: |
| 385 | return Mips::JIALC64; |
Simon Dardis | 669d8dd | 2016-05-18 10:38:01 +0000 | [diff] [blame] | 386 | default: |
Daniel Sanders | e8efff3 | 2016-03-14 16:24:05 +0000 | [diff] [blame] | 387 | return 0; |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | /// Predicate for distingushing between control transfer instructions and all |
| 395 | /// other instructions for handling forbidden slots. Consider inline assembly |
| 396 | /// as unsafe as well. |
| 397 | bool MipsInstrInfo::SafeInForbiddenSlot(const MachineInstr &MI) const { |
| 398 | if (MI.isInlineAsm()) |
| 399 | return false; |
| 400 | |
| 401 | return (MI.getDesc().TSFlags & MipsII::IsCTI) == 0; |
| 402 | |
| 403 | } |
| 404 | |
| 405 | /// Predicate for distingushing instructions that have forbidden slots. |
| 406 | bool MipsInstrInfo::HasForbiddenSlot(const MachineInstr &MI) const { |
| 407 | return (MI.getDesc().TSFlags & MipsII::HasForbiddenSlot) != 0; |
| 408 | } |
| 409 | |
Akira Hatanaka | acd1a7d | 2012-06-14 01:16:45 +0000 | [diff] [blame] | 410 | /// Return the number of bytes of code the specified instruction may be. |
Sjoerd Meijer | 89217f8 | 2016-07-28 16:32:22 +0000 | [diff] [blame] | 411 | unsigned MipsInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const { |
Duncan P. N. Exon Smith | 670900b | 2016-07-15 23:09:47 +0000 | [diff] [blame] | 412 | switch (MI.getOpcode()) { |
Akira Hatanaka | acd1a7d | 2012-06-14 01:16:45 +0000 | [diff] [blame] | 413 | default: |
Duncan P. N. Exon Smith | 670900b | 2016-07-15 23:09:47 +0000 | [diff] [blame] | 414 | return MI.getDesc().getSize(); |
Akira Hatanaka | acd1a7d | 2012-06-14 01:16:45 +0000 | [diff] [blame] | 415 | case TargetOpcode::INLINEASM: { // Inline Asm: Variable size. |
Duncan P. N. Exon Smith | 670900b | 2016-07-15 23:09:47 +0000 | [diff] [blame] | 416 | const MachineFunction *MF = MI.getParent()->getParent(); |
| 417 | const char *AsmStr = MI.getOperand(0).getSymbolName(); |
Akira Hatanaka | acd1a7d | 2012-06-14 01:16:45 +0000 | [diff] [blame] | 418 | return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo()); |
| 419 | } |
Reed Kotler | 91ae982 | 2013-10-27 21:57:36 +0000 | [diff] [blame] | 420 | case Mips::CONSTPOOL_ENTRY: |
| 421 | // If this machine instr is a constant pool entry, its size is recorded as |
| 422 | // operand #2. |
Duncan P. N. Exon Smith | 670900b | 2016-07-15 23:09:47 +0000 | [diff] [blame] | 423 | return MI.getOperand(2).getImm(); |
Akira Hatanaka | acd1a7d | 2012-06-14 01:16:45 +0000 | [diff] [blame] | 424 | } |
| 425 | } |
Akira Hatanaka | 310e26a | 2013-05-13 17:57:42 +0000 | [diff] [blame] | 426 | |
| 427 | MachineInstrBuilder |
| 428 | MipsInstrInfo::genInstrWithNewOpc(unsigned NewOpc, |
| 429 | MachineBasicBlock::iterator I) const { |
| 430 | MachineInstrBuilder MIB; |
Daniel Sanders | e8efff3 | 2016-03-14 16:24:05 +0000 | [diff] [blame] | 431 | |
Simon Dardis | 68a204d | 2016-07-26 10:25:07 +0000 | [diff] [blame] | 432 | // Certain branches have two forms: e.g beq $1, $zero, dest vs beqz $1, dest |
Daniel Sanders | e8efff3 | 2016-03-14 16:24:05 +0000 | [diff] [blame] | 433 | // Pick the zero form of the branch for readable assembly and for greater |
| 434 | // branch distance in non-microMIPS mode. |
Simon Dardis | 4893aff | 2016-08-16 17:16:11 +0000 | [diff] [blame] | 435 | // Additional MIPSR6 does not permit the use of register $zero for compact |
| 436 | // branches. |
Simon Dardis | d9d41f5 | 2016-04-05 12:50:29 +0000 | [diff] [blame] | 437 | // FIXME: Certain atomic sequences on mips64 generate 32bit references to |
| 438 | // Mips::ZERO, which is incorrect. This test should be updated to use |
| 439 | // Subtarget.getABI().GetZeroReg() when those atomic sequences and others |
| 440 | // are fixed. |
Simon Dardis | 4893aff | 2016-08-16 17:16:11 +0000 | [diff] [blame] | 441 | int ZeroOperandPosition = -1; |
| 442 | bool BranchWithZeroOperand = false; |
| 443 | if (I->isBranch() && !I->isPseudo()) { |
| 444 | auto TRI = I->getParent()->getParent()->getSubtarget().getRegisterInfo(); |
| 445 | ZeroOperandPosition = I->findRegisterUseOperandIdx(Mips::ZERO, false, TRI); |
| 446 | BranchWithZeroOperand = ZeroOperandPosition != -1; |
| 447 | } |
Simon Dardis | d9d41f5 | 2016-04-05 12:50:29 +0000 | [diff] [blame] | 448 | |
| 449 | if (BranchWithZeroOperand) { |
Daniel Sanders | e8efff3 | 2016-03-14 16:24:05 +0000 | [diff] [blame] | 450 | switch (NewOpc) { |
| 451 | case Mips::BEQC: |
| 452 | NewOpc = Mips::BEQZC; |
| 453 | break; |
| 454 | case Mips::BNEC: |
| 455 | NewOpc = Mips::BNEZC; |
| 456 | break; |
| 457 | case Mips::BGEC: |
| 458 | NewOpc = Mips::BGEZC; |
| 459 | break; |
| 460 | case Mips::BLTC: |
| 461 | NewOpc = Mips::BLTZC; |
| 462 | break; |
Simon Dardis | 68a204d | 2016-07-26 10:25:07 +0000 | [diff] [blame] | 463 | case Mips::BEQC64: |
| 464 | NewOpc = Mips::BEQZC64; |
| 465 | break; |
| 466 | case Mips::BNEC64: |
| 467 | NewOpc = Mips::BNEZC64; |
| 468 | break; |
Daniel Sanders | e8efff3 | 2016-03-14 16:24:05 +0000 | [diff] [blame] | 469 | } |
| 470 | } |
| 471 | |
Akira Hatanaka | 310e26a | 2013-05-13 17:57:42 +0000 | [diff] [blame] | 472 | MIB = BuildMI(*I->getParent(), I, I->getDebugLoc(), get(NewOpc)); |
| 473 | |
Simon Dardis | d9d41f5 | 2016-04-05 12:50:29 +0000 | [diff] [blame] | 474 | // For MIPSR6 JI*C requires an immediate 0 as an operand, JIALC(64) an |
| 475 | // immediate 0 as an operand and requires the removal of it's %RA<imp-def> |
| 476 | // implicit operand as copying the implicit operations of the instructio we're |
| 477 | // looking at will give us the correct flags. |
| 478 | if (NewOpc == Mips::JIC || NewOpc == Mips::JIALC || NewOpc == Mips::JIC64 || |
| 479 | NewOpc == Mips::JIALC64) { |
| 480 | |
| 481 | if (NewOpc == Mips::JIALC || NewOpc == Mips::JIALC64) |
| 482 | MIB->RemoveOperand(0); |
| 483 | |
| 484 | for (unsigned J = 0, E = I->getDesc().getNumOperands(); J < E; ++J) { |
Diana Picus | 116bbab | 2017-01-13 09:58:52 +0000 | [diff] [blame] | 485 | MIB.add(I->getOperand(J)); |
Simon Dardis | d9d41f5 | 2016-04-05 12:50:29 +0000 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | MIB.addImm(0); |
| 489 | |
Simon Dardis | d9d41f5 | 2016-04-05 12:50:29 +0000 | [diff] [blame] | 490 | } else { |
Simon Dardis | d9d41f5 | 2016-04-05 12:50:29 +0000 | [diff] [blame] | 491 | for (unsigned J = 0, E = I->getDesc().getNumOperands(); J < E; ++J) { |
Simon Dardis | 4893aff | 2016-08-16 17:16:11 +0000 | [diff] [blame] | 492 | if (BranchWithZeroOperand && (unsigned)ZeroOperandPosition == J) |
| 493 | continue; |
| 494 | |
Diana Picus | 116bbab | 2017-01-13 09:58:52 +0000 | [diff] [blame] | 495 | MIB.add(I->getOperand(J)); |
Simon Dardis | d9d41f5 | 2016-04-05 12:50:29 +0000 | [diff] [blame] | 496 | } |
| 497 | } |
| 498 | |
| 499 | MIB.copyImplicitOps(*I); |
Akira Hatanaka | 310e26a | 2013-05-13 17:57:42 +0000 | [diff] [blame] | 500 | |
| 501 | MIB.setMemRefs(I->memoperands_begin(), I->memoperands_end()); |
| 502 | return MIB; |
| 503 | } |
Petar Jovanovic | 9bff3b7 | 2017-03-31 14:31:55 +0000 | [diff] [blame^] | 504 | |
| 505 | bool MipsInstrInfo::findCommutedOpIndices(MachineInstr &MI, unsigned &SrcOpIdx1, |
| 506 | unsigned &SrcOpIdx2) const { |
| 507 | assert(!MI.isBundle() && |
| 508 | "TargetInstrInfo::findCommutedOpIndices() can't handle bundles"); |
| 509 | |
| 510 | const MCInstrDesc &MCID = MI.getDesc(); |
| 511 | if (!MCID.isCommutable()) |
| 512 | return false; |
| 513 | |
| 514 | switch (MI.getOpcode()) { |
| 515 | case Mips::DPADD_U_H: |
| 516 | case Mips::DPADD_U_W: |
| 517 | case Mips::DPADD_U_D: |
| 518 | case Mips::DPADD_S_H: |
| 519 | case Mips::DPADD_S_W: |
| 520 | case Mips::DPADD_S_D: { |
| 521 | // The first operand is both input and output, so it should not commute |
| 522 | if (!fixCommutedOpIndices(SrcOpIdx1, SrcOpIdx2, 2, 3)) |
| 523 | return false; |
| 524 | |
| 525 | if (!MI.getOperand(SrcOpIdx1).isReg() || !MI.getOperand(SrcOpIdx2).isReg()) |
| 526 | return false; |
| 527 | return true; |
| 528 | } |
| 529 | } |
| 530 | return TargetInstrInfo::findCommutedOpIndices(MI, SrcOpIdx1, SrcOpIdx2); |
| 531 | } |