Jia Liu | b22310f | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 1 | //===-- HexagonInstrInfo.cpp - Hexagon Instruction Information ------------===// |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 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 Hexagon implementation of the TargetInstrInfo class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 14 | #include "HexagonInstrInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "Hexagon.h" |
Craig Topper | b25fda9 | 2012-03-17 18:46:09 +0000 | [diff] [blame] | 16 | #include "HexagonRegisterInfo.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 17 | #include "HexagonSubtarget.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/STLExtras.h" |
| 19 | #include "llvm/ADT/SmallVector.h" |
Benjamin Kramer | ae87d7b | 2012-02-06 10:19:29 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/DFAPacketizer.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/MachineMemOperand.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/PseudoSourceValue.h" |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 26 | #include "llvm/Support/Debug.h" |
Benjamin Kramer | ae87d7b | 2012-02-06 10:19:29 +0000 | [diff] [blame] | 27 | #include "llvm/Support/MathExtras.h" |
Reid Kleckner | 1c76f155 | 2013-05-03 00:54:56 +0000 | [diff] [blame] | 28 | #include "llvm/Support/raw_ostream.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 29 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 30 | using namespace llvm; |
| 31 | |
Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 32 | #define DEBUG_TYPE "hexagon-instrinfo" |
| 33 | |
Chandler Carruth | d174b72 | 2014-04-22 02:03:14 +0000 | [diff] [blame] | 34 | #define GET_INSTRINFO_CTOR_DTOR |
| 35 | #define GET_INSTRMAP_INFO |
| 36 | #include "HexagonGenInstrInfo.inc" |
| 37 | #include "HexagonGenDFAPacketizer.inc" |
| 38 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 39 | /// |
| 40 | /// Constants for Hexagon instructions. |
| 41 | /// |
| 42 | const int Hexagon_MEMW_OFFSET_MAX = 4095; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 43 | const int Hexagon_MEMW_OFFSET_MIN = -4096; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 44 | const int Hexagon_MEMD_OFFSET_MAX = 8191; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 45 | const int Hexagon_MEMD_OFFSET_MIN = -8192; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 46 | const int Hexagon_MEMH_OFFSET_MAX = 2047; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 47 | const int Hexagon_MEMH_OFFSET_MIN = -2048; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 48 | const int Hexagon_MEMB_OFFSET_MAX = 1023; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 49 | const int Hexagon_MEMB_OFFSET_MIN = -1024; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 50 | const int Hexagon_ADDI_OFFSET_MAX = 32767; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 51 | const int Hexagon_ADDI_OFFSET_MIN = -32768; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 52 | const int Hexagon_MEMD_AUTOINC_MAX = 56; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 53 | const int Hexagon_MEMD_AUTOINC_MIN = -64; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 54 | const int Hexagon_MEMW_AUTOINC_MAX = 28; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 55 | const int Hexagon_MEMW_AUTOINC_MIN = -32; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 56 | const int Hexagon_MEMH_AUTOINC_MAX = 14; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 57 | const int Hexagon_MEMH_AUTOINC_MIN = -16; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 58 | const int Hexagon_MEMB_AUTOINC_MAX = 7; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 59 | const int Hexagon_MEMB_AUTOINC_MIN = -8; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 60 | |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 61 | // Pin the vtable to this file. |
| 62 | void HexagonInstrInfo::anchor() {} |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 63 | |
| 64 | HexagonInstrInfo::HexagonInstrInfo(HexagonSubtarget &ST) |
Eric Christopher | c4d3140 | 2015-03-10 23:45:55 +0000 | [diff] [blame^] | 65 | : HexagonGenInstrInfo(Hexagon::ADJCALLSTACKDOWN, Hexagon::ADJCALLSTACKUP), |
| 66 | RI(), Subtarget(ST) {} |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 67 | |
| 68 | /// isLoadFromStackSlot - If the specified machine instruction is a direct |
| 69 | /// load from a stack slot, return the virtual or physical register number of |
| 70 | /// the destination 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 loading from the stack slot. |
| 73 | unsigned HexagonInstrInfo::isLoadFromStackSlot(const MachineInstr *MI, |
| 74 | int &FrameIndex) const { |
| 75 | |
| 76 | |
| 77 | switch (MI->getOpcode()) { |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 78 | default: break; |
Colin LeMahieu | 026e88d | 2014-12-23 20:02:16 +0000 | [diff] [blame] | 79 | case Hexagon::L2_loadri_io: |
Colin LeMahieu | 947cd70 | 2014-12-23 20:44:59 +0000 | [diff] [blame] | 80 | case Hexagon::L2_loadrd_io: |
Colin LeMahieu | 8e39cad | 2014-12-23 17:25:57 +0000 | [diff] [blame] | 81 | case Hexagon::L2_loadrh_io: |
Colin LeMahieu | 4b1eac4 | 2014-12-22 21:40:43 +0000 | [diff] [blame] | 82 | case Hexagon::L2_loadrb_io: |
Colin LeMahieu | af1e5de | 2014-12-22 21:20:03 +0000 | [diff] [blame] | 83 | case Hexagon::L2_loadrub_io: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 84 | if (MI->getOperand(2).isFI() && |
| 85 | MI->getOperand(1).isImm() && (MI->getOperand(1).getImm() == 0)) { |
| 86 | FrameIndex = MI->getOperand(2).getIndex(); |
| 87 | return MI->getOperand(0).getReg(); |
| 88 | } |
| 89 | break; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 90 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | |
| 95 | /// isStoreToStackSlot - If the specified machine instruction is a direct |
| 96 | /// store to a stack slot, return the virtual or physical register number of |
| 97 | /// the source reg along with the FrameIndex of the loaded stack slot. If |
| 98 | /// not, return 0. This predicate must return 0 if the instruction has |
| 99 | /// any side effects other than storing to the stack slot. |
| 100 | unsigned HexagonInstrInfo::isStoreToStackSlot(const MachineInstr *MI, |
| 101 | int &FrameIndex) const { |
| 102 | switch (MI->getOpcode()) { |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 103 | default: break; |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 104 | case Hexagon::S2_storeri_io: |
| 105 | case Hexagon::S2_storerd_io: |
| 106 | case Hexagon::S2_storerh_io: |
| 107 | case Hexagon::S2_storerb_io: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 108 | if (MI->getOperand(2).isFI() && |
| 109 | MI->getOperand(1).isImm() && (MI->getOperand(1).getImm() == 0)) { |
Sirish Pande | 8bb9745 | 2012-05-12 05:54:15 +0000 | [diff] [blame] | 110 | FrameIndex = MI->getOperand(0).getIndex(); |
| 111 | return MI->getOperand(2).getReg(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 112 | } |
| 113 | break; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 114 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | |
| 119 | unsigned |
| 120 | HexagonInstrInfo::InsertBranch(MachineBasicBlock &MBB,MachineBasicBlock *TBB, |
| 121 | MachineBasicBlock *FBB, |
| 122 | const SmallVectorImpl<MachineOperand> &Cond, |
| 123 | DebugLoc DL) const{ |
| 124 | |
Colin LeMahieu | db0b13c | 2014-12-10 21:24:10 +0000 | [diff] [blame] | 125 | int BOpc = Hexagon::J2_jump; |
| 126 | int BccOpc = Hexagon::J2_jumpt; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 127 | |
| 128 | assert(TBB && "InsertBranch must not be told to insert a fallthrough"); |
| 129 | |
| 130 | int regPos = 0; |
| 131 | // Check if ReverseBranchCondition has asked to reverse this branch |
| 132 | // If we want to reverse the branch an odd number of times, we want |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 133 | // JMP_f. |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 134 | if (!Cond.empty() && Cond[0].isImm() && Cond[0].getImm() == 0) { |
Colin LeMahieu | db0b13c | 2014-12-10 21:24:10 +0000 | [diff] [blame] | 135 | BccOpc = Hexagon::J2_jumpf; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 136 | regPos = 1; |
| 137 | } |
| 138 | |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 139 | if (!FBB) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 140 | if (Cond.empty()) { |
| 141 | // Due to a bug in TailMerging/CFG Optimization, we need to add a |
| 142 | // special case handling of a predicated jump followed by an |
| 143 | // unconditional jump. If not, Tail Merging and CFG Optimization go |
| 144 | // into an infinite loop. |
| 145 | MachineBasicBlock *NewTBB, *NewFBB; |
| 146 | SmallVector<MachineOperand, 4> Cond; |
| 147 | MachineInstr *Term = MBB.getFirstTerminator(); |
| 148 | if (isPredicated(Term) && !AnalyzeBranch(MBB, NewTBB, NewFBB, Cond, |
| 149 | false)) { |
| 150 | MachineBasicBlock *NextBB = |
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 151 | std::next(MachineFunction::iterator(&MBB)); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 152 | if (NewTBB == NextBB) { |
| 153 | ReverseBranchCondition(Cond); |
| 154 | RemoveBranch(MBB); |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 155 | return InsertBranch(MBB, TBB, nullptr, Cond, DL); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | BuildMI(&MBB, DL, get(BOpc)).addMBB(TBB); |
| 159 | } else { |
| 160 | BuildMI(&MBB, DL, |
| 161 | get(BccOpc)).addReg(Cond[regPos].getReg()).addMBB(TBB); |
| 162 | } |
| 163 | return 1; |
| 164 | } |
| 165 | |
| 166 | BuildMI(&MBB, DL, get(BccOpc)).addReg(Cond[regPos].getReg()).addMBB(TBB); |
| 167 | BuildMI(&MBB, DL, get(BOpc)).addMBB(FBB); |
| 168 | |
| 169 | return 2; |
| 170 | } |
| 171 | |
| 172 | |
| 173 | bool HexagonInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB, |
| 174 | MachineBasicBlock *&TBB, |
| 175 | MachineBasicBlock *&FBB, |
| 176 | SmallVectorImpl<MachineOperand> &Cond, |
| 177 | bool AllowModify) const { |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 178 | TBB = nullptr; |
| 179 | FBB = nullptr; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 180 | |
| 181 | // If the block has no terminators, it just falls into the block after it. |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 182 | MachineBasicBlock::instr_iterator I = MBB.instr_end(); |
| 183 | if (I == MBB.instr_begin()) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 184 | return false; |
| 185 | |
| 186 | // A basic block may looks like this: |
| 187 | // |
| 188 | // [ insn |
| 189 | // EH_LABEL |
| 190 | // insn |
| 191 | // insn |
| 192 | // insn |
| 193 | // EH_LABEL |
| 194 | // insn ] |
| 195 | // |
| 196 | // It has two succs but does not have a terminator |
| 197 | // Don't know how to handle it. |
| 198 | do { |
| 199 | --I; |
| 200 | if (I->isEHLabel()) |
| 201 | return true; |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 202 | } while (I != MBB.instr_begin()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 203 | |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 204 | I = MBB.instr_end(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 205 | --I; |
| 206 | |
| 207 | while (I->isDebugValue()) { |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 208 | if (I == MBB.instr_begin()) |
| 209 | return false; |
| 210 | --I; |
| 211 | } |
Colin LeMahieu | 7b1799c | 2015-03-09 22:05:21 +0000 | [diff] [blame] | 212 | |
| 213 | bool JumpToBlock = I->getOpcode() == Hexagon::J2_jump && |
| 214 | I->getOperand(0).isMBB(); |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 215 | // Delete the JMP if it's equivalent to a fall-through. |
Colin LeMahieu | 7b1799c | 2015-03-09 22:05:21 +0000 | [diff] [blame] | 216 | if (AllowModify && JumpToBlock && |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 217 | MBB.isLayoutSuccessor(I->getOperand(0).getMBB())) { |
| 218 | DEBUG(dbgs()<< "\nErasing the jump to successor block\n";); |
| 219 | I->eraseFromParent(); |
| 220 | I = MBB.instr_end(); |
| 221 | if (I == MBB.instr_begin()) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 222 | return false; |
| 223 | --I; |
| 224 | } |
| 225 | if (!isUnpredicatedTerminator(I)) |
| 226 | return false; |
| 227 | |
| 228 | // Get the last instruction in the block. |
| 229 | MachineInstr *LastInst = I; |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 230 | MachineInstr *SecondLastInst = nullptr; |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 231 | // Find one more terminator if present. |
| 232 | do { |
| 233 | if (&*I != LastInst && !I->isBundle() && isUnpredicatedTerminator(I)) { |
| 234 | if (!SecondLastInst) |
| 235 | SecondLastInst = I; |
| 236 | else |
| 237 | // This is a third branch. |
| 238 | return true; |
| 239 | } |
| 240 | if (I == MBB.instr_begin()) |
| 241 | break; |
| 242 | --I; |
| 243 | } while(I); |
| 244 | |
| 245 | int LastOpcode = LastInst->getOpcode(); |
Colin LeMahieu | 7b1799c | 2015-03-09 22:05:21 +0000 | [diff] [blame] | 246 | int SecLastOpcode = SecondLastInst ? SecondLastInst->getOpcode() : 0; |
| 247 | // If the branch target is not a basic block, it could be a tail call. |
| 248 | // (It is, if the target is a function.) |
| 249 | if (LastOpcode == Hexagon::J2_jump && !LastInst->getOperand(0).isMBB()) |
| 250 | return true; |
| 251 | if (SecLastOpcode == Hexagon::J2_jump && |
| 252 | !SecondLastInst->getOperand(0).isMBB()) |
| 253 | return true; |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 254 | |
| 255 | bool LastOpcodeHasJMP_c = PredOpcodeHasJMP_c(LastOpcode); |
| 256 | bool LastOpcodeHasNot = PredOpcodeHasNot(LastOpcode); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 257 | |
| 258 | // If there is only one terminator instruction, process it. |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 259 | if (LastInst && !SecondLastInst) { |
Colin LeMahieu | db0b13c | 2014-12-10 21:24:10 +0000 | [diff] [blame] | 260 | if (LastOpcode == Hexagon::J2_jump) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 261 | TBB = LastInst->getOperand(0).getMBB(); |
| 262 | return false; |
| 263 | } |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 264 | if (LastOpcode == Hexagon::ENDLOOP0) { |
| 265 | TBB = LastInst->getOperand(0).getMBB(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 266 | Cond.push_back(LastInst->getOperand(0)); |
| 267 | return false; |
| 268 | } |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 269 | if (LastOpcodeHasJMP_c) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 270 | TBB = LastInst->getOperand(1).getMBB(); |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 271 | if (LastOpcodeHasNot) { |
| 272 | Cond.push_back(MachineOperand::CreateImm(0)); |
| 273 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 274 | Cond.push_back(LastInst->getOperand(0)); |
| 275 | return false; |
| 276 | } |
| 277 | // Otherwise, don't know what this is. |
| 278 | return true; |
| 279 | } |
| 280 | |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 281 | bool SecLastOpcodeHasJMP_c = PredOpcodeHasJMP_c(SecLastOpcode); |
| 282 | bool SecLastOpcodeHasNot = PredOpcodeHasNot(SecLastOpcode); |
Colin LeMahieu | db0b13c | 2014-12-10 21:24:10 +0000 | [diff] [blame] | 283 | if (SecLastOpcodeHasJMP_c && (LastOpcode == Hexagon::J2_jump)) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 284 | TBB = SecondLastInst->getOperand(1).getMBB(); |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 285 | if (SecLastOpcodeHasNot) |
| 286 | Cond.push_back(MachineOperand::CreateImm(0)); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 287 | Cond.push_back(SecondLastInst->getOperand(0)); |
| 288 | FBB = LastInst->getOperand(0).getMBB(); |
| 289 | return false; |
| 290 | } |
| 291 | |
| 292 | // If the block ends with two Hexagon:JMPs, handle it. The second one is not |
| 293 | // executed, so remove it. |
Colin LeMahieu | db0b13c | 2014-12-10 21:24:10 +0000 | [diff] [blame] | 294 | if (SecLastOpcode == Hexagon::J2_jump && LastOpcode == Hexagon::J2_jump) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 295 | TBB = SecondLastInst->getOperand(0).getMBB(); |
| 296 | I = LastInst; |
| 297 | if (AllowModify) |
| 298 | I->eraseFromParent(); |
| 299 | return false; |
| 300 | } |
| 301 | |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 302 | // If the block ends with an ENDLOOP, and JMP, handle it. |
| 303 | if (SecLastOpcode == Hexagon::ENDLOOP0 && |
Colin LeMahieu | db0b13c | 2014-12-10 21:24:10 +0000 | [diff] [blame] | 304 | LastOpcode == Hexagon::J2_jump) { |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 305 | TBB = SecondLastInst->getOperand(0).getMBB(); |
| 306 | Cond.push_back(SecondLastInst->getOperand(0)); |
| 307 | FBB = LastInst->getOperand(0).getMBB(); |
| 308 | return false; |
| 309 | } |
| 310 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 311 | // Otherwise, can't handle this. |
| 312 | return true; |
| 313 | } |
| 314 | |
| 315 | |
| 316 | unsigned HexagonInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const { |
Colin LeMahieu | db0b13c | 2014-12-10 21:24:10 +0000 | [diff] [blame] | 317 | int BOpc = Hexagon::J2_jump; |
| 318 | int BccOpc = Hexagon::J2_jumpt; |
| 319 | int BccOpcNot = Hexagon::J2_jumpf; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 320 | |
| 321 | MachineBasicBlock::iterator I = MBB.end(); |
| 322 | if (I == MBB.begin()) return 0; |
| 323 | --I; |
| 324 | if (I->getOpcode() != BOpc && I->getOpcode() != BccOpc && |
| 325 | I->getOpcode() != BccOpcNot) |
| 326 | return 0; |
| 327 | |
| 328 | // Remove the branch. |
| 329 | I->eraseFromParent(); |
| 330 | |
| 331 | I = MBB.end(); |
| 332 | |
| 333 | if (I == MBB.begin()) return 1; |
| 334 | --I; |
| 335 | if (I->getOpcode() != BccOpc && I->getOpcode() != BccOpcNot) |
| 336 | return 1; |
| 337 | |
| 338 | // Remove the branch. |
| 339 | I->eraseFromParent(); |
| 340 | return 2; |
| 341 | } |
| 342 | |
| 343 | |
Krzysztof Parzyszek | cfe285e | 2013-02-11 20:04:29 +0000 | [diff] [blame] | 344 | /// \brief For a comparison instruction, return the source registers in |
| 345 | /// \p SrcReg and \p SrcReg2 if having two register operands, and the value it |
| 346 | /// compares against in CmpValue. Return true if the comparison instruction |
| 347 | /// can be analyzed. |
| 348 | bool HexagonInstrInfo::analyzeCompare(const MachineInstr *MI, |
| 349 | unsigned &SrcReg, unsigned &SrcReg2, |
| 350 | int &Mask, int &Value) const { |
| 351 | unsigned Opc = MI->getOpcode(); |
| 352 | |
| 353 | // Set mask and the first source register. |
| 354 | switch (Opc) { |
Colin LeMahieu | 9bfe547 | 2014-12-08 21:56:47 +0000 | [diff] [blame] | 355 | case Hexagon::C2_cmpeqp: |
Colin LeMahieu | 6e0f9f8 | 2014-11-26 19:43:12 +0000 | [diff] [blame] | 356 | case Hexagon::C2_cmpeqi: |
Colin LeMahieu | 902157c | 2014-11-25 18:20:52 +0000 | [diff] [blame] | 357 | case Hexagon::C2_cmpeq: |
Colin LeMahieu | 9bfe547 | 2014-12-08 21:56:47 +0000 | [diff] [blame] | 358 | case Hexagon::C2_cmpgtp: |
| 359 | case Hexagon::C2_cmpgtup: |
Colin LeMahieu | 6e0f9f8 | 2014-11-26 19:43:12 +0000 | [diff] [blame] | 360 | case Hexagon::C2_cmpgtui: |
Colin LeMahieu | 902157c | 2014-11-25 18:20:52 +0000 | [diff] [blame] | 361 | case Hexagon::C2_cmpgtu: |
Colin LeMahieu | 6e0f9f8 | 2014-11-26 19:43:12 +0000 | [diff] [blame] | 362 | case Hexagon::C2_cmpgti: |
Colin LeMahieu | 902157c | 2014-11-25 18:20:52 +0000 | [diff] [blame] | 363 | case Hexagon::C2_cmpgt: |
Krzysztof Parzyszek | cfe285e | 2013-02-11 20:04:29 +0000 | [diff] [blame] | 364 | SrcReg = MI->getOperand(1).getReg(); |
| 365 | Mask = ~0; |
| 366 | break; |
Colin LeMahieu | fa94790 | 2015-01-14 16:49:12 +0000 | [diff] [blame] | 367 | case Hexagon::A4_cmpbeqi: |
Colin LeMahieu | ffacc6e | 2015-01-14 18:05:44 +0000 | [diff] [blame] | 368 | case Hexagon::A4_cmpbeq: |
| 369 | case Hexagon::A4_cmpbgtui: |
| 370 | case Hexagon::A4_cmpbgtu: |
| 371 | case Hexagon::A4_cmpbgt: |
Krzysztof Parzyszek | cfe285e | 2013-02-11 20:04:29 +0000 | [diff] [blame] | 372 | SrcReg = MI->getOperand(1).getReg(); |
| 373 | Mask = 0xFF; |
| 374 | break; |
Colin LeMahieu | c91fabc | 2015-01-14 18:26:14 +0000 | [diff] [blame] | 375 | case Hexagon::A4_cmpheqi: |
| 376 | case Hexagon::A4_cmpheq: |
| 377 | case Hexagon::A4_cmphgtui: |
| 378 | case Hexagon::A4_cmphgtu: |
| 379 | case Hexagon::A4_cmphgt: |
Krzysztof Parzyszek | cfe285e | 2013-02-11 20:04:29 +0000 | [diff] [blame] | 380 | SrcReg = MI->getOperand(1).getReg(); |
| 381 | Mask = 0xFFFF; |
| 382 | break; |
| 383 | } |
| 384 | |
| 385 | // Set the value/second source register. |
| 386 | switch (Opc) { |
Colin LeMahieu | 9bfe547 | 2014-12-08 21:56:47 +0000 | [diff] [blame] | 387 | case Hexagon::C2_cmpeqp: |
Colin LeMahieu | 902157c | 2014-11-25 18:20:52 +0000 | [diff] [blame] | 388 | case Hexagon::C2_cmpeq: |
Colin LeMahieu | 9bfe547 | 2014-12-08 21:56:47 +0000 | [diff] [blame] | 389 | case Hexagon::C2_cmpgtp: |
| 390 | case Hexagon::C2_cmpgtup: |
Colin LeMahieu | 902157c | 2014-11-25 18:20:52 +0000 | [diff] [blame] | 391 | case Hexagon::C2_cmpgtu: |
| 392 | case Hexagon::C2_cmpgt: |
Colin LeMahieu | ffacc6e | 2015-01-14 18:05:44 +0000 | [diff] [blame] | 393 | case Hexagon::A4_cmpbeq: |
| 394 | case Hexagon::A4_cmpbgtu: |
| 395 | case Hexagon::A4_cmpbgt: |
Colin LeMahieu | c91fabc | 2015-01-14 18:26:14 +0000 | [diff] [blame] | 396 | case Hexagon::A4_cmpheq: |
| 397 | case Hexagon::A4_cmphgtu: |
| 398 | case Hexagon::A4_cmphgt: |
Krzysztof Parzyszek | cfe285e | 2013-02-11 20:04:29 +0000 | [diff] [blame] | 399 | SrcReg2 = MI->getOperand(2).getReg(); |
| 400 | return true; |
| 401 | |
Colin LeMahieu | 6e0f9f8 | 2014-11-26 19:43:12 +0000 | [diff] [blame] | 402 | case Hexagon::C2_cmpeqi: |
| 403 | case Hexagon::C2_cmpgtui: |
| 404 | case Hexagon::C2_cmpgti: |
Colin LeMahieu | fa94790 | 2015-01-14 16:49:12 +0000 | [diff] [blame] | 405 | case Hexagon::A4_cmpbeqi: |
Colin LeMahieu | ffacc6e | 2015-01-14 18:05:44 +0000 | [diff] [blame] | 406 | case Hexagon::A4_cmpbgtui: |
Colin LeMahieu | c91fabc | 2015-01-14 18:26:14 +0000 | [diff] [blame] | 407 | case Hexagon::A4_cmpheqi: |
| 408 | case Hexagon::A4_cmphgtui: |
Krzysztof Parzyszek | cfe285e | 2013-02-11 20:04:29 +0000 | [diff] [blame] | 409 | SrcReg2 = 0; |
| 410 | Value = MI->getOperand(2).getImm(); |
| 411 | return true; |
| 412 | } |
| 413 | |
| 414 | return false; |
| 415 | } |
| 416 | |
| 417 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 418 | void HexagonInstrInfo::copyPhysReg(MachineBasicBlock &MBB, |
| 419 | MachineBasicBlock::iterator I, DebugLoc DL, |
| 420 | unsigned DestReg, unsigned SrcReg, |
| 421 | bool KillSrc) const { |
| 422 | if (Hexagon::IntRegsRegClass.contains(SrcReg, DestReg)) { |
Colin LeMahieu | 4af437f | 2014-12-09 20:23:30 +0000 | [diff] [blame] | 423 | BuildMI(MBB, I, DL, get(Hexagon::A2_tfr), DestReg).addReg(SrcReg); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 424 | return; |
| 425 | } |
| 426 | if (Hexagon::DoubleRegsRegClass.contains(SrcReg, DestReg)) { |
Colin LeMahieu | 4af437f | 2014-12-09 20:23:30 +0000 | [diff] [blame] | 427 | BuildMI(MBB, I, DL, get(Hexagon::A2_tfrp), DestReg).addReg(SrcReg); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 428 | return; |
| 429 | } |
| 430 | if (Hexagon::PredRegsRegClass.contains(SrcReg, DestReg)) { |
| 431 | // Map Pd = Ps to Pd = or(Ps, Ps). |
Colin LeMahieu | 5cf5632 | 2014-12-08 23:55:43 +0000 | [diff] [blame] | 432 | BuildMI(MBB, I, DL, get(Hexagon::C2_or), |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 433 | DestReg).addReg(SrcReg).addReg(SrcReg); |
| 434 | return; |
| 435 | } |
Sirish Pande | 8bb9745 | 2012-05-12 05:54:15 +0000 | [diff] [blame] | 436 | if (Hexagon::DoubleRegsRegClass.contains(DestReg) && |
| 437 | Hexagon::IntRegsRegClass.contains(SrcReg)) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 438 | // We can have an overlap between single and double reg: r1:0 = r0. |
| 439 | if(SrcReg == RI.getSubReg(DestReg, Hexagon::subreg_loreg)) { |
| 440 | // r1:0 = r0 |
Colin LeMahieu | 4af437f | 2014-12-09 20:23:30 +0000 | [diff] [blame] | 441 | BuildMI(MBB, I, DL, get(Hexagon::A2_tfrsi), (RI.getSubReg(DestReg, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 442 | Hexagon::subreg_hireg))).addImm(0); |
| 443 | } else { |
| 444 | // r1:0 = r1 or no overlap. |
Colin LeMahieu | 4af437f | 2014-12-09 20:23:30 +0000 | [diff] [blame] | 445 | BuildMI(MBB, I, DL, get(Hexagon::A2_tfr), (RI.getSubReg(DestReg, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 446 | Hexagon::subreg_loreg))).addReg(SrcReg); |
Colin LeMahieu | 4af437f | 2014-12-09 20:23:30 +0000 | [diff] [blame] | 447 | BuildMI(MBB, I, DL, get(Hexagon::A2_tfrsi), (RI.getSubReg(DestReg, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 448 | Hexagon::subreg_hireg))).addImm(0); |
| 449 | } |
| 450 | return; |
| 451 | } |
Colin LeMahieu | 402f772 | 2014-12-19 18:56:10 +0000 | [diff] [blame] | 452 | if (Hexagon::CtrRegsRegClass.contains(DestReg) && |
Sirish Pande | 8bb9745 | 2012-05-12 05:54:15 +0000 | [diff] [blame] | 453 | Hexagon::IntRegsRegClass.contains(SrcReg)) { |
Colin LeMahieu | 0f850bd | 2014-12-19 20:29:29 +0000 | [diff] [blame] | 454 | BuildMI(MBB, I, DL, get(Hexagon::A2_tfrrcr), DestReg).addReg(SrcReg); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 455 | return; |
Sirish Pande | 30804c2 | 2012-02-15 18:52:27 +0000 | [diff] [blame] | 456 | } |
Anshuman Dasgupta | e96f804 | 2013-02-13 22:56:34 +0000 | [diff] [blame] | 457 | if (Hexagon::PredRegsRegClass.contains(SrcReg) && |
| 458 | Hexagon::IntRegsRegClass.contains(DestReg)) { |
Colin LeMahieu | 30dcb23 | 2014-12-09 18:16:49 +0000 | [diff] [blame] | 459 | BuildMI(MBB, I, DL, get(Hexagon::C2_tfrpr), DestReg). |
Anshuman Dasgupta | e96f804 | 2013-02-13 22:56:34 +0000 | [diff] [blame] | 460 | addReg(SrcReg, getKillRegState(KillSrc)); |
| 461 | return; |
| 462 | } |
| 463 | if (Hexagon::IntRegsRegClass.contains(SrcReg) && |
| 464 | Hexagon::PredRegsRegClass.contains(DestReg)) { |
Colin LeMahieu | 30dcb23 | 2014-12-09 18:16:49 +0000 | [diff] [blame] | 465 | BuildMI(MBB, I, DL, get(Hexagon::C2_tfrrp), DestReg). |
Anshuman Dasgupta | e96f804 | 2013-02-13 22:56:34 +0000 | [diff] [blame] | 466 | addReg(SrcReg, getKillRegState(KillSrc)); |
| 467 | return; |
| 468 | } |
Sirish Pande | 30804c2 | 2012-02-15 18:52:27 +0000 | [diff] [blame] | 469 | |
| 470 | llvm_unreachable("Unimplemented"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | |
| 474 | void HexagonInstrInfo:: |
| 475 | storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 476 | unsigned SrcReg, bool isKill, int FI, |
| 477 | const TargetRegisterClass *RC, |
| 478 | const TargetRegisterInfo *TRI) const { |
| 479 | |
| 480 | DebugLoc DL = MBB.findDebugLoc(I); |
| 481 | MachineFunction &MF = *MBB.getParent(); |
| 482 | MachineFrameInfo &MFI = *MF.getFrameInfo(); |
| 483 | unsigned Align = MFI.getObjectAlignment(FI); |
| 484 | |
| 485 | MachineMemOperand *MMO = |
| 486 | MF.getMachineMemOperand( |
| 487 | MachinePointerInfo(PseudoSourceValue::getFixedStack(FI)), |
| 488 | MachineMemOperand::MOStore, |
| 489 | MFI.getObjectSize(FI), |
| 490 | Align); |
| 491 | |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 492 | if (Hexagon::IntRegsRegClass.hasSubClassEq(RC)) { |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 493 | BuildMI(MBB, I, DL, get(Hexagon::S2_storeri_io)) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 494 | .addFrameIndex(FI).addImm(0) |
| 495 | .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO); |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 496 | } else if (Hexagon::DoubleRegsRegClass.hasSubClassEq(RC)) { |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 497 | BuildMI(MBB, I, DL, get(Hexagon::S2_storerd_io)) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 498 | .addFrameIndex(FI).addImm(0) |
| 499 | .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO); |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 500 | } else if (Hexagon::PredRegsRegClass.hasSubClassEq(RC)) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 501 | BuildMI(MBB, I, DL, get(Hexagon::STriw_pred)) |
| 502 | .addFrameIndex(FI).addImm(0) |
| 503 | .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO); |
| 504 | } else { |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 505 | llvm_unreachable("Unimplemented"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | |
| 509 | |
| 510 | void HexagonInstrInfo::storeRegToAddr( |
| 511 | MachineFunction &MF, unsigned SrcReg, |
| 512 | bool isKill, |
| 513 | SmallVectorImpl<MachineOperand> &Addr, |
| 514 | const TargetRegisterClass *RC, |
| 515 | SmallVectorImpl<MachineInstr*> &NewMIs) const |
| 516 | { |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 517 | llvm_unreachable("Unimplemented"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | |
| 521 | void HexagonInstrInfo:: |
| 522 | loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 523 | unsigned DestReg, int FI, |
| 524 | const TargetRegisterClass *RC, |
| 525 | const TargetRegisterInfo *TRI) const { |
| 526 | DebugLoc DL = MBB.findDebugLoc(I); |
| 527 | MachineFunction &MF = *MBB.getParent(); |
| 528 | MachineFrameInfo &MFI = *MF.getFrameInfo(); |
| 529 | unsigned Align = MFI.getObjectAlignment(FI); |
| 530 | |
| 531 | MachineMemOperand *MMO = |
| 532 | MF.getMachineMemOperand( |
| 533 | MachinePointerInfo(PseudoSourceValue::getFixedStack(FI)), |
| 534 | MachineMemOperand::MOLoad, |
| 535 | MFI.getObjectSize(FI), |
| 536 | Align); |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 537 | if (RC == &Hexagon::IntRegsRegClass) { |
Colin LeMahieu | 026e88d | 2014-12-23 20:02:16 +0000 | [diff] [blame] | 538 | BuildMI(MBB, I, DL, get(Hexagon::L2_loadri_io), DestReg) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 539 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO); |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 540 | } else if (RC == &Hexagon::DoubleRegsRegClass) { |
Colin LeMahieu | 947cd70 | 2014-12-23 20:44:59 +0000 | [diff] [blame] | 541 | BuildMI(MBB, I, DL, get(Hexagon::L2_loadrd_io), DestReg) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 542 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO); |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 543 | } else if (RC == &Hexagon::PredRegsRegClass) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 544 | BuildMI(MBB, I, DL, get(Hexagon::LDriw_pred), DestReg) |
| 545 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO); |
| 546 | } else { |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 547 | llvm_unreachable("Can't store this register to stack slot"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | |
| 551 | |
| 552 | void HexagonInstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg, |
| 553 | SmallVectorImpl<MachineOperand> &Addr, |
| 554 | const TargetRegisterClass *RC, |
| 555 | SmallVectorImpl<MachineInstr*> &NewMIs) const { |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 556 | llvm_unreachable("Unimplemented"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 557 | } |
Colin LeMahieu | 7b1799c | 2015-03-09 22:05:21 +0000 | [diff] [blame] | 558 | bool |
| 559 | HexagonInstrInfo::expandPostRAPseudo(MachineBasicBlock::iterator MI) const { |
| 560 | unsigned Opc = MI->getOpcode(); |
| 561 | |
| 562 | switch (Opc) { |
| 563 | case Hexagon::TCRETURNi: |
| 564 | MI->setDesc(get(Hexagon::J2_jump)); |
| 565 | return true; |
| 566 | case Hexagon::TCRETURNr: |
| 567 | MI->setDesc(get(Hexagon::J2_jumpr)); |
| 568 | return true; |
| 569 | } |
| 570 | |
| 571 | return false; |
| 572 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 573 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 574 | MachineInstr *HexagonInstrInfo::foldMemoryOperandImpl(MachineFunction &MF, |
Benjamin Kramer | f1362f6 | 2015-02-28 12:04:00 +0000 | [diff] [blame] | 575 | MachineInstr *MI, |
| 576 | ArrayRef<unsigned> Ops, |
| 577 | int FI) const { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 578 | // Hexagon_TODO: Implement. |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 579 | return nullptr; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 580 | } |
| 581 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 582 | unsigned HexagonInstrInfo::createVR(MachineFunction* MF, MVT VT) const { |
| 583 | |
| 584 | MachineRegisterInfo &RegInfo = MF->getRegInfo(); |
| 585 | const TargetRegisterClass *TRC; |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 586 | if (VT == MVT::i1) { |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 587 | TRC = &Hexagon::PredRegsRegClass; |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 588 | } else if (VT == MVT::i32 || VT == MVT::f32) { |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 589 | TRC = &Hexagon::IntRegsRegClass; |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 590 | } else if (VT == MVT::i64 || VT == MVT::f64) { |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 591 | TRC = &Hexagon::DoubleRegsRegClass; |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 592 | } else { |
Benjamin Kramer | b668401 | 2011-12-27 11:41:05 +0000 | [diff] [blame] | 593 | llvm_unreachable("Cannot handle this register class"); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 594 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 595 | |
| 596 | unsigned NewReg = RegInfo.createVirtualRegister(TRC); |
| 597 | return NewReg; |
| 598 | } |
| 599 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 600 | bool HexagonInstrInfo::isExtendable(const MachineInstr *MI) const { |
Jyotsna Verma | f1214a8 | 2013-03-05 18:51:42 +0000 | [diff] [blame] | 601 | const MCInstrDesc &MID = MI->getDesc(); |
| 602 | const uint64_t F = MID.TSFlags; |
| 603 | if ((F >> HexagonII::ExtendablePos) & HexagonII::ExtendableMask) |
| 604 | return true; |
| 605 | |
| 606 | // TODO: This is largely obsolete now. Will need to be removed |
| 607 | // in consecutive patches. |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 608 | switch(MI->getOpcode()) { |
Jyotsna Verma | f1214a8 | 2013-03-05 18:51:42 +0000 | [diff] [blame] | 609 | // TFR_FI Remains a special case. |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 610 | case Hexagon::TFR_FI: |
| 611 | return true; |
Jyotsna Verma | f1214a8 | 2013-03-05 18:51:42 +0000 | [diff] [blame] | 612 | default: |
| 613 | return false; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 614 | } |
Jyotsna Verma | f1214a8 | 2013-03-05 18:51:42 +0000 | [diff] [blame] | 615 | return false; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 616 | } |
| 617 | |
Jyotsna Verma | f1214a8 | 2013-03-05 18:51:42 +0000 | [diff] [blame] | 618 | // This returns true in two cases: |
| 619 | // - The OP code itself indicates that this is an extended instruction. |
| 620 | // - One of MOs has been marked with HMOTF_ConstExtended flag. |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 621 | bool HexagonInstrInfo::isExtended(const MachineInstr *MI) const { |
Jyotsna Verma | f1214a8 | 2013-03-05 18:51:42 +0000 | [diff] [blame] | 622 | // First check if this is permanently extended op code. |
| 623 | const uint64_t F = MI->getDesc().TSFlags; |
| 624 | if ((F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask) |
| 625 | return true; |
| 626 | // Use MO operand flags to determine if one of MI's operands |
| 627 | // has HMOTF_ConstExtended flag set. |
| 628 | for (MachineInstr::const_mop_iterator I = MI->operands_begin(), |
| 629 | E = MI->operands_end(); I != E; ++I) { |
| 630 | if (I->getTargetFlags() && HexagonII::HMOTF_ConstExtended) |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 631 | return true; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 632 | } |
Jyotsna Verma | f1214a8 | 2013-03-05 18:51:42 +0000 | [diff] [blame] | 633 | return false; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 634 | } |
| 635 | |
Jyotsna Verma | 84c4710 | 2013-05-06 18:49:23 +0000 | [diff] [blame] | 636 | bool HexagonInstrInfo::isBranch (const MachineInstr *MI) const { |
| 637 | return MI->getDesc().isBranch(); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 638 | } |
| 639 | |
Jyotsna Verma | f1214a8 | 2013-03-05 18:51:42 +0000 | [diff] [blame] | 640 | bool HexagonInstrInfo::isNewValueInst(const MachineInstr *MI) const { |
| 641 | if (isNewValueJump(MI)) |
| 642 | return true; |
| 643 | |
| 644 | if (isNewValueStore(MI)) |
| 645 | return true; |
| 646 | |
| 647 | return false; |
| 648 | } |
| 649 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 650 | bool HexagonInstrInfo::isSaveCalleeSavedRegsCall(const MachineInstr *MI) const { |
| 651 | return MI->getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4; |
| 652 | } |
Andrew Trick | d06df96 | 2012-02-01 22:13:57 +0000 | [diff] [blame] | 653 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 654 | bool HexagonInstrInfo::isPredicable(MachineInstr *MI) const { |
| 655 | bool isPred = MI->getDesc().isPredicable(); |
| 656 | |
| 657 | if (!isPred) |
| 658 | return false; |
| 659 | |
| 660 | const int Opc = MI->getOpcode(); |
| 661 | |
| 662 | switch(Opc) { |
Colin LeMahieu | 4af437f | 2014-12-09 20:23:30 +0000 | [diff] [blame] | 663 | case Hexagon::A2_tfrsi: |
Colin LeMahieu | 2efa2d0 | 2015-03-09 21:48:13 +0000 | [diff] [blame] | 664 | return (isOperandExtended(MI, 1) && isConstExtended(MI)) || isInt<12>(MI->getOperand(1).getImm()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 665 | |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 666 | case Hexagon::S2_storerd_io: |
Brendon Cahoon | f6b687e | 2012-05-14 19:35:42 +0000 | [diff] [blame] | 667 | return isShiftedUInt<6,3>(MI->getOperand(1).getImm()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 668 | |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 669 | case Hexagon::S2_storeri_io: |
Colin LeMahieu | 9014890 | 2014-12-30 22:28:31 +0000 | [diff] [blame] | 670 | case Hexagon::S2_storerinew_io: |
Brendon Cahoon | f6b687e | 2012-05-14 19:35:42 +0000 | [diff] [blame] | 671 | return isShiftedUInt<6,2>(MI->getOperand(1).getImm()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 672 | |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 673 | case Hexagon::S2_storerh_io: |
Colin LeMahieu | 9014890 | 2014-12-30 22:28:31 +0000 | [diff] [blame] | 674 | case Hexagon::S2_storerhnew_io: |
Brendon Cahoon | f6b687e | 2012-05-14 19:35:42 +0000 | [diff] [blame] | 675 | return isShiftedUInt<6,1>(MI->getOperand(1).getImm()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 676 | |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 677 | case Hexagon::S2_storerb_io: |
Colin LeMahieu | 9014890 | 2014-12-30 22:28:31 +0000 | [diff] [blame] | 678 | case Hexagon::S2_storerbnew_io: |
Brendon Cahoon | f6b687e | 2012-05-14 19:35:42 +0000 | [diff] [blame] | 679 | return isUInt<6>(MI->getOperand(1).getImm()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 680 | |
Colin LeMahieu | 947cd70 | 2014-12-23 20:44:59 +0000 | [diff] [blame] | 681 | case Hexagon::L2_loadrd_io: |
Brendon Cahoon | f6b687e | 2012-05-14 19:35:42 +0000 | [diff] [blame] | 682 | return isShiftedUInt<6,3>(MI->getOperand(2).getImm()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 683 | |
Colin LeMahieu | 026e88d | 2014-12-23 20:02:16 +0000 | [diff] [blame] | 684 | case Hexagon::L2_loadri_io: |
Brendon Cahoon | f6b687e | 2012-05-14 19:35:42 +0000 | [diff] [blame] | 685 | return isShiftedUInt<6,2>(MI->getOperand(2).getImm()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 686 | |
Colin LeMahieu | 8e39cad | 2014-12-23 17:25:57 +0000 | [diff] [blame] | 687 | case Hexagon::L2_loadrh_io: |
Colin LeMahieu | a9386d2 | 2014-12-23 16:42:57 +0000 | [diff] [blame] | 688 | case Hexagon::L2_loadruh_io: |
Brendon Cahoon | f6b687e | 2012-05-14 19:35:42 +0000 | [diff] [blame] | 689 | return isShiftedUInt<6,1>(MI->getOperand(2).getImm()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 690 | |
Colin LeMahieu | 4b1eac4 | 2014-12-22 21:40:43 +0000 | [diff] [blame] | 691 | case Hexagon::L2_loadrb_io: |
Colin LeMahieu | af1e5de | 2014-12-22 21:20:03 +0000 | [diff] [blame] | 692 | case Hexagon::L2_loadrub_io: |
Brendon Cahoon | f6b687e | 2012-05-14 19:35:42 +0000 | [diff] [blame] | 693 | return isUInt<6>(MI->getOperand(2).getImm()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 694 | |
Colin LeMahieu | c83cbbf | 2014-12-26 19:31:46 +0000 | [diff] [blame] | 695 | case Hexagon::L2_loadrd_pi: |
Brendon Cahoon | f6b687e | 2012-05-14 19:35:42 +0000 | [diff] [blame] | 696 | return isShiftedInt<4,3>(MI->getOperand(3).getImm()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 697 | |
Colin LeMahieu | c83cbbf | 2014-12-26 19:31:46 +0000 | [diff] [blame] | 698 | case Hexagon::L2_loadri_pi: |
Brendon Cahoon | f6b687e | 2012-05-14 19:35:42 +0000 | [diff] [blame] | 699 | return isShiftedInt<4,2>(MI->getOperand(3).getImm()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 700 | |
Colin LeMahieu | c83cbbf | 2014-12-26 19:31:46 +0000 | [diff] [blame] | 701 | case Hexagon::L2_loadrh_pi: |
| 702 | case Hexagon::L2_loadruh_pi: |
Brendon Cahoon | f6b687e | 2012-05-14 19:35:42 +0000 | [diff] [blame] | 703 | return isShiftedInt<4,1>(MI->getOperand(3).getImm()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 704 | |
Colin LeMahieu | 96976a1 | 2014-12-26 18:57:13 +0000 | [diff] [blame] | 705 | case Hexagon::L2_loadrb_pi: |
Colin LeMahieu | fe9612e | 2014-12-26 19:12:11 +0000 | [diff] [blame] | 706 | case Hexagon::L2_loadrub_pi: |
Brendon Cahoon | f6b687e | 2012-05-14 19:35:42 +0000 | [diff] [blame] | 707 | return isInt<4>(MI->getOperand(3).getImm()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 708 | |
Colin LeMahieu | 2bad4a7 | 2014-12-30 21:01:38 +0000 | [diff] [blame] | 709 | case Hexagon::S4_storeirb_io: |
| 710 | case Hexagon::S4_storeirh_io: |
| 711 | case Hexagon::S4_storeiri_io: |
Brendon Cahoon | f6b687e | 2012-05-14 19:35:42 +0000 | [diff] [blame] | 712 | return (isUInt<6>(MI->getOperand(1).getImm()) && |
| 713 | isInt<6>(MI->getOperand(2).getImm())); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 714 | |
Colin LeMahieu | f297dbe | 2015-02-05 17:49:13 +0000 | [diff] [blame] | 715 | case Hexagon::A2_addi: |
Brendon Cahoon | f6b687e | 2012-05-14 19:35:42 +0000 | [diff] [blame] | 716 | return isInt<8>(MI->getOperand(2).getImm()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 717 | |
Colin LeMahieu | 3b3197e | 2014-11-24 17:44:19 +0000 | [diff] [blame] | 718 | case Hexagon::A2_aslh: |
Colin LeMahieu | 397a25e | 2014-11-24 18:04:42 +0000 | [diff] [blame] | 719 | case Hexagon::A2_asrh: |
Colin LeMahieu | 91ffec9 | 2014-11-21 21:35:52 +0000 | [diff] [blame] | 720 | case Hexagon::A2_sxtb: |
Colin LeMahieu | 310991c | 2014-11-21 21:54:59 +0000 | [diff] [blame] | 721 | case Hexagon::A2_sxth: |
Colin LeMahieu | bb7d6f5 | 2014-11-24 16:48:43 +0000 | [diff] [blame] | 722 | case Hexagon::A2_zxtb: |
Colin LeMahieu | 098256c | 2014-11-24 17:11:34 +0000 | [diff] [blame] | 723 | case Hexagon::A2_zxth: |
Colin LeMahieu | 4fd203d | 2015-02-09 21:56:37 +0000 | [diff] [blame] | 724 | return true; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | return true; |
| 728 | } |
| 729 | |
Sirish Pande | 8bb9745 | 2012-05-12 05:54:15 +0000 | [diff] [blame] | 730 | // This function performs the following inversiones: |
| 731 | // |
| 732 | // cPt ---> cNotPt |
| 733 | // cNotPt ---> cPt |
| 734 | // |
Sirish Pande | 30804c2 | 2012-02-15 18:52:27 +0000 | [diff] [blame] | 735 | unsigned HexagonInstrInfo::getInvertedPredicatedOpcode(const int Opc) const { |
Jyotsna Verma | 84c4710 | 2013-05-06 18:49:23 +0000 | [diff] [blame] | 736 | int InvPredOpcode; |
| 737 | InvPredOpcode = isPredicatedTrue(Opc) ? Hexagon::getFalsePredOpcode(Opc) |
| 738 | : Hexagon::getTruePredOpcode(Opc); |
| 739 | if (InvPredOpcode >= 0) // Valid instruction with the inverted predicate. |
| 740 | return InvPredOpcode; |
| 741 | |
Sirish Pande | 30804c2 | 2012-02-15 18:52:27 +0000 | [diff] [blame] | 742 | switch(Opc) { |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 743 | default: llvm_unreachable("Unexpected predicated instruction"); |
Colin LeMahieu | b580d7d | 2014-12-09 19:23:45 +0000 | [diff] [blame] | 744 | case Hexagon::C2_ccombinewt: |
| 745 | return Hexagon::C2_ccombinewf; |
| 746 | case Hexagon::C2_ccombinewf: |
| 747 | return Hexagon::C2_ccombinewt; |
Sirish Pande | 30804c2 | 2012-02-15 18:52:27 +0000 | [diff] [blame] | 748 | |
Jyotsna Verma | 978e972 | 2013-05-09 18:25:44 +0000 | [diff] [blame] | 749 | // Dealloc_return. |
Colin LeMahieu | 1445553 | 2015-01-06 16:15:15 +0000 | [diff] [blame] | 750 | case Hexagon::L4_return_t: |
| 751 | return Hexagon::L4_return_f; |
| 752 | case Hexagon::L4_return_f: |
| 753 | return Hexagon::L4_return_t; |
Sirish Pande | 30804c2 | 2012-02-15 18:52:27 +0000 | [diff] [blame] | 754 | } |
| 755 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 756 | |
Jyotsna Verma | 300f0b9 | 2013-05-10 20:27:34 +0000 | [diff] [blame] | 757 | // New Value Store instructions. |
| 758 | bool HexagonInstrInfo::isNewValueStore(const MachineInstr *MI) const { |
| 759 | const uint64_t F = MI->getDesc().TSFlags; |
| 760 | |
| 761 | return ((F >> HexagonII::NVStorePos) & HexagonII::NVStoreMask); |
| 762 | } |
| 763 | |
| 764 | bool HexagonInstrInfo::isNewValueStore(unsigned Opcode) const { |
| 765 | const uint64_t F = get(Opcode).TSFlags; |
| 766 | |
| 767 | return ((F >> HexagonII::NVStorePos) & HexagonII::NVStoreMask); |
| 768 | } |
Andrew Trick | d06df96 | 2012-02-01 22:13:57 +0000 | [diff] [blame] | 769 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 770 | int HexagonInstrInfo:: |
| 771 | getMatchingCondBranchOpcode(int Opc, bool invertPredicate) const { |
Pranav Bhandarkar | 34b6018 | 2012-11-01 19:13:23 +0000 | [diff] [blame] | 772 | enum Hexagon::PredSense inPredSense; |
| 773 | inPredSense = invertPredicate ? Hexagon::PredSense_false : |
| 774 | Hexagon::PredSense_true; |
| 775 | int CondOpcode = Hexagon::getPredOpcode(Opc, inPredSense); |
| 776 | if (CondOpcode >= 0) // Valid Conditional opcode/instruction |
| 777 | return CondOpcode; |
| 778 | |
| 779 | // This switch case will be removed once all the instructions have been |
| 780 | // modified to use relation maps. |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 781 | switch(Opc) { |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 782 | case Hexagon::TFRI_f: |
| 783 | return !invertPredicate ? Hexagon::TFRI_cPt_f : |
| 784 | Hexagon::TFRI_cNotPt_f; |
Colin LeMahieu | b580d7d | 2014-12-09 19:23:45 +0000 | [diff] [blame] | 785 | case Hexagon::A2_combinew: |
| 786 | return !invertPredicate ? Hexagon::C2_ccombinewt : |
| 787 | Hexagon::C2_ccombinewf; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 788 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 789 | // DEALLOC_RETURN. |
Colin LeMahieu | 1445553 | 2015-01-06 16:15:15 +0000 | [diff] [blame] | 790 | case Hexagon::L4_return: |
| 791 | return !invertPredicate ? Hexagon::L4_return_t: |
| 792 | Hexagon::L4_return_f; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 793 | } |
Benjamin Kramer | b668401 | 2011-12-27 11:41:05 +0000 | [diff] [blame] | 794 | llvm_unreachable("Unexpected predicable instruction"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | |
| 798 | bool HexagonInstrInfo:: |
| 799 | PredicateInstruction(MachineInstr *MI, |
| 800 | const SmallVectorImpl<MachineOperand> &Cond) const { |
| 801 | int Opc = MI->getOpcode(); |
| 802 | assert (isPredicable(MI) && "Expected predicable instruction"); |
| 803 | bool invertJump = (!Cond.empty() && Cond[0].isImm() && |
| 804 | (Cond[0].getImm() == 0)); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 805 | |
Jyotsna Verma | 39f7a2b | 2013-02-12 16:06:23 +0000 | [diff] [blame] | 806 | // This will change MI's opcode to its predicate version. |
| 807 | // However, its operand list is still the old one, i.e. the |
| 808 | // non-predicate one. |
| 809 | MI->setDesc(get(getMatchingCondBranchOpcode(Opc, invertJump))); |
| 810 | |
| 811 | int oper = -1; |
| 812 | unsigned int GAIdx = 0; |
| 813 | |
| 814 | // Indicates whether the current MI has a GlobalAddress operand |
| 815 | bool hasGAOpnd = false; |
| 816 | std::vector<MachineOperand> tmpOpnds; |
| 817 | |
| 818 | // Indicates whether we need to shift operands to right. |
| 819 | bool needShift = true; |
| 820 | |
| 821 | // The predicate is ALWAYS the FIRST input operand !!! |
| 822 | if (MI->getNumOperands() == 0) { |
| 823 | // The non-predicate version of MI does not take any operands, |
| 824 | // i.e. no outs and no ins. In this condition, the predicate |
| 825 | // operand will be directly placed at Operands[0]. No operand |
| 826 | // shift is needed. |
| 827 | // Example: BARRIER |
| 828 | needShift = false; |
| 829 | oper = -1; |
| 830 | } |
| 831 | else if ( MI->getOperand(MI->getNumOperands()-1).isReg() |
| 832 | && MI->getOperand(MI->getNumOperands()-1).isDef() |
| 833 | && !MI->getOperand(MI->getNumOperands()-1).isImplicit()) { |
| 834 | // The non-predicate version of MI does not have any input operands. |
| 835 | // In this condition, we extend the length of Operands[] by one and |
| 836 | // copy the original last operand to the newly allocated slot. |
| 837 | // At this moment, it is just a place holder. Later, we will put |
| 838 | // predicate operand directly into it. No operand shift is needed. |
| 839 | // Example: r0=BARRIER (this is a faked insn used here for illustration) |
| 840 | MI->addOperand(MI->getOperand(MI->getNumOperands()-1)); |
| 841 | needShift = false; |
| 842 | oper = MI->getNumOperands() - 2; |
| 843 | } |
| 844 | else { |
| 845 | // We need to right shift all input operands by one. Duplicate the |
| 846 | // last operand into the newly allocated slot. |
| 847 | MI->addOperand(MI->getOperand(MI->getNumOperands()-1)); |
| 848 | } |
| 849 | |
| 850 | if (needShift) |
| 851 | { |
| 852 | // Operands[ MI->getNumOperands() - 2 ] has been copied into |
| 853 | // Operands[ MI->getNumOperands() - 1 ], so we start from |
| 854 | // Operands[ MI->getNumOperands() - 3 ]. |
| 855 | // oper is a signed int. |
| 856 | // It is ok if "MI->getNumOperands()-3" is -3, -2, or -1. |
| 857 | for (oper = MI->getNumOperands() - 3; oper >= 0; --oper) |
| 858 | { |
| 859 | MachineOperand &MO = MI->getOperand(oper); |
| 860 | |
| 861 | // Opnd[0] Opnd[1] Opnd[2] Opnd[3] Opnd[4] Opnd[5] Opnd[6] Opnd[7] |
| 862 | // <Def0> <Def1> <Use0> <Use1> <ImpDef0> <ImpDef1> <ImpUse0> <ImpUse1> |
| 863 | // /\~ |
| 864 | // /||\~ |
| 865 | // || |
| 866 | // Predicate Operand here |
| 867 | if (MO.isReg() && !MO.isUse() && !MO.isImplicit()) { |
| 868 | break; |
| 869 | } |
| 870 | if (MO.isReg()) { |
| 871 | MI->getOperand(oper+1).ChangeToRegister(MO.getReg(), MO.isDef(), |
| 872 | MO.isImplicit(), MO.isKill(), |
| 873 | MO.isDead(), MO.isUndef(), |
| 874 | MO.isDebug()); |
| 875 | } |
| 876 | else if (MO.isImm()) { |
| 877 | MI->getOperand(oper+1).ChangeToImmediate(MO.getImm()); |
| 878 | } |
| 879 | else if (MO.isGlobal()) { |
| 880 | // MI can not have more than one GlobalAddress operand. |
| 881 | assert(hasGAOpnd == false && "MI can only have one GlobalAddress opnd"); |
| 882 | |
| 883 | // There is no member function called "ChangeToGlobalAddress" in the |
| 884 | // MachineOperand class (not like "ChangeToRegister" and |
| 885 | // "ChangeToImmediate"). So we have to remove them from Operands[] list |
| 886 | // first, and then add them back after we have inserted the predicate |
| 887 | // operand. tmpOpnds[] is to remember these operands before we remove |
| 888 | // them. |
| 889 | tmpOpnds.push_back(MO); |
| 890 | |
| 891 | // Operands[oper] is a GlobalAddress operand; |
| 892 | // Operands[oper+1] has been copied into Operands[oper+2]; |
| 893 | hasGAOpnd = true; |
| 894 | GAIdx = oper; |
| 895 | continue; |
| 896 | } |
| 897 | else { |
Craig Topper | d3c02f1 | 2015-01-05 10:15:49 +0000 | [diff] [blame] | 898 | llvm_unreachable("Unexpected operand type"); |
Jyotsna Verma | 39f7a2b | 2013-02-12 16:06:23 +0000 | [diff] [blame] | 899 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 900 | } |
| 901 | } |
| 902 | |
| 903 | int regPos = invertJump ? 1 : 0; |
| 904 | MachineOperand PredMO = Cond[regPos]; |
Jyotsna Verma | 39f7a2b | 2013-02-12 16:06:23 +0000 | [diff] [blame] | 905 | |
| 906 | // [oper] now points to the last explicit Def. Predicate operand must be |
| 907 | // located at [oper+1]. See diagram above. |
| 908 | // This assumes that the predicate is always the first operand, |
| 909 | // i.e. Operands[0+numResults], in the set of inputs |
| 910 | // It is better to have an assert here to check this. But I don't know how |
| 911 | // to write this assert because findFirstPredOperandIdx() would return -1 |
| 912 | if (oper < -1) oper = -1; |
Jyotsna Verma | cd66c0a | 2013-05-01 21:27:30 +0000 | [diff] [blame] | 913 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 914 | MI->getOperand(oper+1).ChangeToRegister(PredMO.getReg(), PredMO.isDef(), |
Jyotsna Verma | cd66c0a | 2013-05-01 21:27:30 +0000 | [diff] [blame] | 915 | PredMO.isImplicit(), false, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 916 | PredMO.isDead(), PredMO.isUndef(), |
| 917 | PredMO.isDebug()); |
| 918 | |
Jyotsna Verma | cd66c0a | 2013-05-01 21:27:30 +0000 | [diff] [blame] | 919 | MachineRegisterInfo &RegInfo = MI->getParent()->getParent()->getRegInfo(); |
| 920 | RegInfo.clearKillFlags(PredMO.getReg()); |
| 921 | |
Jyotsna Verma | 39f7a2b | 2013-02-12 16:06:23 +0000 | [diff] [blame] | 922 | if (hasGAOpnd) |
| 923 | { |
| 924 | unsigned int i; |
| 925 | |
| 926 | // Operands[GAIdx] is the original GlobalAddress operand, which is |
| 927 | // already copied into tmpOpnds[0]. |
| 928 | // Operands[GAIdx] now stores a copy of Operands[GAIdx-1] |
| 929 | // Operands[GAIdx+1] has already been copied into Operands[GAIdx+2], |
| 930 | // so we start from [GAIdx+2] |
| 931 | for (i = GAIdx + 2; i < MI->getNumOperands(); ++i) |
| 932 | tmpOpnds.push_back(MI->getOperand(i)); |
| 933 | |
| 934 | // Remove all operands in range [ (GAIdx+1) ... (MI->getNumOperands()-1) ] |
| 935 | // It is very important that we always remove from the end of Operands[] |
| 936 | // MI->getNumOperands() is at least 2 if program goes to here. |
| 937 | for (i = MI->getNumOperands() - 1; i > GAIdx; --i) |
| 938 | MI->RemoveOperand(i); |
| 939 | |
| 940 | for (i = 0; i < tmpOpnds.size(); ++i) |
| 941 | MI->addOperand(tmpOpnds[i]); |
| 942 | } |
| 943 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 944 | return true; |
| 945 | } |
| 946 | |
| 947 | |
| 948 | bool |
| 949 | HexagonInstrInfo:: |
| 950 | isProfitableToIfCvt(MachineBasicBlock &MBB, |
Kay Tiong Khoo | f294921 | 2012-06-13 15:53:04 +0000 | [diff] [blame] | 951 | unsigned NumCycles, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 952 | unsigned ExtraPredCycles, |
| 953 | const BranchProbability &Probability) const { |
| 954 | return true; |
| 955 | } |
| 956 | |
| 957 | |
| 958 | bool |
| 959 | HexagonInstrInfo:: |
| 960 | isProfitableToIfCvt(MachineBasicBlock &TMBB, |
| 961 | unsigned NumTCycles, |
| 962 | unsigned ExtraTCycles, |
| 963 | MachineBasicBlock &FMBB, |
| 964 | unsigned NumFCycles, |
| 965 | unsigned ExtraFCycles, |
| 966 | const BranchProbability &Probability) const { |
| 967 | return true; |
| 968 | } |
| 969 | |
Jyotsna Verma | 84c4710 | 2013-05-06 18:49:23 +0000 | [diff] [blame] | 970 | // Returns true if an instruction is predicated irrespective of the predicate |
| 971 | // sense. For example, all of the following will return true. |
| 972 | // if (p0) R1 = add(R2, R3) |
| 973 | // if (!p0) R1 = add(R2, R3) |
| 974 | // if (p0.new) R1 = add(R2, R3) |
| 975 | // if (!p0.new) R1 = add(R2, R3) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 976 | bool HexagonInstrInfo::isPredicated(const MachineInstr *MI) const { |
Brendon Cahoon | 6f35837 | 2012-02-08 18:25:47 +0000 | [diff] [blame] | 977 | const uint64_t F = MI->getDesc().TSFlags; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 978 | |
Brendon Cahoon | 6f35837 | 2012-02-08 18:25:47 +0000 | [diff] [blame] | 979 | return ((F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 980 | } |
| 981 | |
Jyotsna Verma | 84c4710 | 2013-05-06 18:49:23 +0000 | [diff] [blame] | 982 | bool HexagonInstrInfo::isPredicated(unsigned Opcode) const { |
| 983 | const uint64_t F = get(Opcode).TSFlags; |
| 984 | |
| 985 | return ((F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask); |
| 986 | } |
| 987 | |
| 988 | bool HexagonInstrInfo::isPredicatedTrue(const MachineInstr *MI) const { |
| 989 | const uint64_t F = MI->getDesc().TSFlags; |
| 990 | |
| 991 | assert(isPredicated(MI)); |
| 992 | return (!((F >> HexagonII::PredicatedFalsePos) & |
| 993 | HexagonII::PredicatedFalseMask)); |
| 994 | } |
| 995 | |
| 996 | bool HexagonInstrInfo::isPredicatedTrue(unsigned Opcode) const { |
| 997 | const uint64_t F = get(Opcode).TSFlags; |
| 998 | |
| 999 | // Make sure that the instruction is predicated. |
| 1000 | assert((F>> HexagonII::PredicatedPos) & HexagonII::PredicatedMask); |
| 1001 | return (!((F >> HexagonII::PredicatedFalsePos) & |
| 1002 | HexagonII::PredicatedFalseMask)); |
| 1003 | } |
| 1004 | |
Jyotsna Verma | a46059b | 2013-03-28 19:44:04 +0000 | [diff] [blame] | 1005 | bool HexagonInstrInfo::isPredicatedNew(const MachineInstr *MI) const { |
| 1006 | const uint64_t F = MI->getDesc().TSFlags; |
| 1007 | |
| 1008 | assert(isPredicated(MI)); |
| 1009 | return ((F >> HexagonII::PredicatedNewPos) & HexagonII::PredicatedNewMask); |
| 1010 | } |
| 1011 | |
Jyotsna Verma | 84c4710 | 2013-05-06 18:49:23 +0000 | [diff] [blame] | 1012 | bool HexagonInstrInfo::isPredicatedNew(unsigned Opcode) const { |
| 1013 | const uint64_t F = get(Opcode).TSFlags; |
| 1014 | |
| 1015 | assert(isPredicated(Opcode)); |
| 1016 | return ((F >> HexagonII::PredicatedNewPos) & HexagonII::PredicatedNewMask); |
| 1017 | } |
| 1018 | |
Jyotsna Verma | 438cec5 | 2013-05-10 20:58:11 +0000 | [diff] [blame] | 1019 | // Returns true, if a ST insn can be promoted to a new-value store. |
| 1020 | bool HexagonInstrInfo::mayBeNewStore(const MachineInstr *MI) const { |
Jyotsna Verma | 438cec5 | 2013-05-10 20:58:11 +0000 | [diff] [blame] | 1021 | const uint64_t F = MI->getDesc().TSFlags; |
| 1022 | |
| 1023 | return ((F >> HexagonII::mayNVStorePos) & |
Colin LeMahieu | 4fd203d | 2015-02-09 21:56:37 +0000 | [diff] [blame] | 1024 | HexagonII::mayNVStoreMask); |
Jyotsna Verma | 438cec5 | 2013-05-10 20:58:11 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1027 | bool |
| 1028 | HexagonInstrInfo::DefinesPredicate(MachineInstr *MI, |
| 1029 | std::vector<MachineOperand> &Pred) const { |
| 1030 | for (unsigned oper = 0; oper < MI->getNumOperands(); ++oper) { |
| 1031 | MachineOperand MO = MI->getOperand(oper); |
| 1032 | if (MO.isReg() && MO.isDef()) { |
| 1033 | const TargetRegisterClass* RC = RI.getMinimalPhysRegClass(MO.getReg()); |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1034 | if (RC == &Hexagon::PredRegsRegClass) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1035 | Pred.push_back(MO); |
| 1036 | return true; |
| 1037 | } |
| 1038 | } |
| 1039 | } |
| 1040 | return false; |
| 1041 | } |
| 1042 | |
| 1043 | |
| 1044 | bool |
| 1045 | HexagonInstrInfo:: |
| 1046 | SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1, |
| 1047 | const SmallVectorImpl<MachineOperand> &Pred2) const { |
| 1048 | // TODO: Fix this |
| 1049 | return false; |
| 1050 | } |
| 1051 | |
| 1052 | |
| 1053 | // |
| 1054 | // We indicate that we want to reverse the branch by |
| 1055 | // inserting a 0 at the beginning of the Cond vector. |
| 1056 | // |
| 1057 | bool HexagonInstrInfo:: |
| 1058 | ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const { |
| 1059 | if (!Cond.empty() && Cond[0].isImm() && Cond[0].getImm() == 0) { |
| 1060 | Cond.erase(Cond.begin()); |
| 1061 | } else { |
| 1062 | Cond.insert(Cond.begin(), MachineOperand::CreateImm(0)); |
| 1063 | } |
| 1064 | return false; |
| 1065 | } |
| 1066 | |
| 1067 | |
| 1068 | bool HexagonInstrInfo:: |
| 1069 | isProfitableToDupForIfCvt(MachineBasicBlock &MBB,unsigned NumInstrs, |
| 1070 | const BranchProbability &Probability) const { |
| 1071 | return (NumInstrs <= 4); |
| 1072 | } |
| 1073 | |
| 1074 | bool HexagonInstrInfo::isDeallocRet(const MachineInstr *MI) const { |
| 1075 | switch (MI->getOpcode()) { |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1076 | default: return false; |
Colin LeMahieu | 1445553 | 2015-01-06 16:15:15 +0000 | [diff] [blame] | 1077 | case Hexagon::L4_return: |
| 1078 | case Hexagon::L4_return_t: |
| 1079 | case Hexagon::L4_return_f: |
| 1080 | case Hexagon::L4_return_tnew_pnt: |
| 1081 | case Hexagon::L4_return_fnew_pnt: |
| 1082 | case Hexagon::L4_return_tnew_pt: |
| 1083 | case Hexagon::L4_return_fnew_pt: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1084 | return true; |
| 1085 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | |
| 1089 | bool HexagonInstrInfo:: |
| 1090 | isValidOffset(const int Opcode, const int Offset) const { |
| 1091 | // This function is to check whether the "Offset" is in the correct range of |
| 1092 | // the given "Opcode". If "Offset" is not in the correct range, "ADD_ri" is |
| 1093 | // inserted to calculate the final address. Due to this reason, the function |
| 1094 | // assumes that the "Offset" has correct alignment. |
Jyotsna Verma | ec61366 | 2013-03-14 19:08:03 +0000 | [diff] [blame] | 1095 | // We used to assert if the offset was not properly aligned, however, |
| 1096 | // there are cases where a misaligned pointer recast can cause this |
| 1097 | // problem, and we need to allow for it. The front end warns of such |
| 1098 | // misaligns with respect to load size. |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1099 | |
| 1100 | switch(Opcode) { |
| 1101 | |
Colin LeMahieu | 026e88d | 2014-12-23 20:02:16 +0000 | [diff] [blame] | 1102 | case Hexagon::L2_loadri_io: |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 1103 | case Hexagon::S2_storeri_io: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1104 | return (Offset >= Hexagon_MEMW_OFFSET_MIN) && |
| 1105 | (Offset <= Hexagon_MEMW_OFFSET_MAX); |
| 1106 | |
Colin LeMahieu | 947cd70 | 2014-12-23 20:44:59 +0000 | [diff] [blame] | 1107 | case Hexagon::L2_loadrd_io: |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 1108 | case Hexagon::S2_storerd_io: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1109 | return (Offset >= Hexagon_MEMD_OFFSET_MIN) && |
| 1110 | (Offset <= Hexagon_MEMD_OFFSET_MAX); |
| 1111 | |
Colin LeMahieu | 8e39cad | 2014-12-23 17:25:57 +0000 | [diff] [blame] | 1112 | case Hexagon::L2_loadrh_io: |
Colin LeMahieu | a9386d2 | 2014-12-23 16:42:57 +0000 | [diff] [blame] | 1113 | case Hexagon::L2_loadruh_io: |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 1114 | case Hexagon::S2_storerh_io: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1115 | return (Offset >= Hexagon_MEMH_OFFSET_MIN) && |
| 1116 | (Offset <= Hexagon_MEMH_OFFSET_MAX); |
| 1117 | |
Colin LeMahieu | 4b1eac4 | 2014-12-22 21:40:43 +0000 | [diff] [blame] | 1118 | case Hexagon::L2_loadrb_io: |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 1119 | case Hexagon::S2_storerb_io: |
Colin LeMahieu | af1e5de | 2014-12-22 21:20:03 +0000 | [diff] [blame] | 1120 | case Hexagon::L2_loadrub_io: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1121 | return (Offset >= Hexagon_MEMB_OFFSET_MIN) && |
| 1122 | (Offset <= Hexagon_MEMB_OFFSET_MAX); |
| 1123 | |
Colin LeMahieu | f297dbe | 2015-02-05 17:49:13 +0000 | [diff] [blame] | 1124 | case Hexagon::A2_addi: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1125 | case Hexagon::TFR_FI: |
| 1126 | return (Offset >= Hexagon_ADDI_OFFSET_MIN) && |
| 1127 | (Offset <= Hexagon_ADDI_OFFSET_MAX); |
| 1128 | |
Colin LeMahieu | dacf057 | 2015-01-05 21:36:38 +0000 | [diff] [blame] | 1129 | case Hexagon::L4_iadd_memopw_io: |
| 1130 | case Hexagon::L4_isub_memopw_io: |
| 1131 | case Hexagon::L4_add_memopw_io: |
| 1132 | case Hexagon::L4_sub_memopw_io: |
| 1133 | case Hexagon::L4_and_memopw_io: |
| 1134 | case Hexagon::L4_or_memopw_io: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1135 | return (0 <= Offset && Offset <= 255); |
| 1136 | |
Colin LeMahieu | dacf057 | 2015-01-05 21:36:38 +0000 | [diff] [blame] | 1137 | case Hexagon::L4_iadd_memoph_io: |
| 1138 | case Hexagon::L4_isub_memoph_io: |
| 1139 | case Hexagon::L4_add_memoph_io: |
| 1140 | case Hexagon::L4_sub_memoph_io: |
| 1141 | case Hexagon::L4_and_memoph_io: |
| 1142 | case Hexagon::L4_or_memoph_io: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1143 | return (0 <= Offset && Offset <= 127); |
| 1144 | |
Colin LeMahieu | dacf057 | 2015-01-05 21:36:38 +0000 | [diff] [blame] | 1145 | case Hexagon::L4_iadd_memopb_io: |
| 1146 | case Hexagon::L4_isub_memopb_io: |
| 1147 | case Hexagon::L4_add_memopb_io: |
| 1148 | case Hexagon::L4_sub_memopb_io: |
| 1149 | case Hexagon::L4_and_memopb_io: |
| 1150 | case Hexagon::L4_or_memopb_io: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1151 | return (0 <= Offset && Offset <= 63); |
| 1152 | |
| 1153 | // LDri_pred and STriw_pred are pseudo operations, so it has to take offset of |
| 1154 | // any size. Later pass knows how to handle it. |
| 1155 | case Hexagon::STriw_pred: |
| 1156 | case Hexagon::LDriw_pred: |
| 1157 | return true; |
| 1158 | |
Colin LeMahieu | 5ccbb12 | 2014-12-19 00:06:53 +0000 | [diff] [blame] | 1159 | case Hexagon::J2_loop0i: |
Krzysztof Parzyszek | 9a278f1 | 2013-02-11 21:37:55 +0000 | [diff] [blame] | 1160 | return isUInt<10>(Offset); |
| 1161 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1162 | // INLINEASM is very special. |
| 1163 | case Hexagon::INLINEASM: |
| 1164 | return true; |
| 1165 | } |
| 1166 | |
Benjamin Kramer | b668401 | 2011-12-27 11:41:05 +0000 | [diff] [blame] | 1167 | llvm_unreachable("No offset range is defined for this opcode. " |
| 1168 | "Please define it in the above switch statement!"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | |
| 1172 | // |
| 1173 | // Check if the Offset is a valid auto-inc imm by Load/Store Type. |
| 1174 | // |
| 1175 | bool HexagonInstrInfo:: |
| 1176 | isValidAutoIncImm(const EVT VT, const int Offset) const { |
| 1177 | |
| 1178 | if (VT == MVT::i64) { |
| 1179 | return (Offset >= Hexagon_MEMD_AUTOINC_MIN && |
| 1180 | Offset <= Hexagon_MEMD_AUTOINC_MAX && |
| 1181 | (Offset & 0x7) == 0); |
| 1182 | } |
| 1183 | if (VT == MVT::i32) { |
| 1184 | return (Offset >= Hexagon_MEMW_AUTOINC_MIN && |
| 1185 | Offset <= Hexagon_MEMW_AUTOINC_MAX && |
| 1186 | (Offset & 0x3) == 0); |
| 1187 | } |
| 1188 | if (VT == MVT::i16) { |
| 1189 | return (Offset >= Hexagon_MEMH_AUTOINC_MIN && |
| 1190 | Offset <= Hexagon_MEMH_AUTOINC_MAX && |
| 1191 | (Offset & 0x1) == 0); |
| 1192 | } |
| 1193 | if (VT == MVT::i8) { |
| 1194 | return (Offset >= Hexagon_MEMB_AUTOINC_MIN && |
| 1195 | Offset <= Hexagon_MEMB_AUTOINC_MAX); |
| 1196 | } |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 1197 | llvm_unreachable("Not an auto-inc opc!"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | |
| 1201 | bool HexagonInstrInfo:: |
| 1202 | isMemOp(const MachineInstr *MI) const { |
Jyotsna Verma | 300f0b9 | 2013-05-10 20:27:34 +0000 | [diff] [blame] | 1203 | // return MI->getDesc().mayLoad() && MI->getDesc().mayStore(); |
| 1204 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1205 | switch (MI->getOpcode()) |
| 1206 | { |
Colin LeMahieu | dacf057 | 2015-01-05 21:36:38 +0000 | [diff] [blame] | 1207 | default: return false; |
| 1208 | case Hexagon::L4_iadd_memopw_io: |
| 1209 | case Hexagon::L4_isub_memopw_io: |
| 1210 | case Hexagon::L4_add_memopw_io: |
| 1211 | case Hexagon::L4_sub_memopw_io: |
| 1212 | case Hexagon::L4_and_memopw_io: |
| 1213 | case Hexagon::L4_or_memopw_io: |
| 1214 | case Hexagon::L4_iadd_memoph_io: |
| 1215 | case Hexagon::L4_isub_memoph_io: |
| 1216 | case Hexagon::L4_add_memoph_io: |
| 1217 | case Hexagon::L4_sub_memoph_io: |
| 1218 | case Hexagon::L4_and_memoph_io: |
| 1219 | case Hexagon::L4_or_memoph_io: |
| 1220 | case Hexagon::L4_iadd_memopb_io: |
| 1221 | case Hexagon::L4_isub_memopb_io: |
| 1222 | case Hexagon::L4_add_memopb_io: |
| 1223 | case Hexagon::L4_sub_memopb_io: |
| 1224 | case Hexagon::L4_and_memopb_io: |
| 1225 | case Hexagon::L4_or_memopb_io: |
| 1226 | case Hexagon::L4_ior_memopb_io: |
| 1227 | case Hexagon::L4_ior_memoph_io: |
| 1228 | case Hexagon::L4_ior_memopw_io: |
| 1229 | case Hexagon::L4_iand_memopb_io: |
| 1230 | case Hexagon::L4_iand_memoph_io: |
| 1231 | case Hexagon::L4_iand_memopw_io: |
Jyotsna Verma | fdc660b | 2013-03-22 18:41:34 +0000 | [diff] [blame] | 1232 | return true; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1233 | } |
Jyotsna Verma | fdc660b | 2013-03-22 18:41:34 +0000 | [diff] [blame] | 1234 | return false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | |
| 1238 | bool HexagonInstrInfo:: |
| 1239 | isSpillPredRegOp(const MachineInstr *MI) const { |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1240 | switch (MI->getOpcode()) { |
| 1241 | default: return false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1242 | case Hexagon::STriw_pred : |
| 1243 | case Hexagon::LDriw_pred : |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1244 | return true; |
Sirish Pande | 2c7bf00 | 2012-04-23 17:49:28 +0000 | [diff] [blame] | 1245 | } |
Sirish Pande | 4bd20c5 | 2012-05-12 05:10:30 +0000 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | bool HexagonInstrInfo::isNewValueJumpCandidate(const MachineInstr *MI) const { |
| 1249 | switch (MI->getOpcode()) { |
Sirish Pande | 8bb9745 | 2012-05-12 05:54:15 +0000 | [diff] [blame] | 1250 | default: return false; |
Colin LeMahieu | 902157c | 2014-11-25 18:20:52 +0000 | [diff] [blame] | 1251 | case Hexagon::C2_cmpeq: |
Colin LeMahieu | 6e0f9f8 | 2014-11-26 19:43:12 +0000 | [diff] [blame] | 1252 | case Hexagon::C2_cmpeqi: |
Colin LeMahieu | 902157c | 2014-11-25 18:20:52 +0000 | [diff] [blame] | 1253 | case Hexagon::C2_cmpgt: |
Colin LeMahieu | 6e0f9f8 | 2014-11-26 19:43:12 +0000 | [diff] [blame] | 1254 | case Hexagon::C2_cmpgti: |
Colin LeMahieu | 902157c | 2014-11-25 18:20:52 +0000 | [diff] [blame] | 1255 | case Hexagon::C2_cmpgtu: |
Colin LeMahieu | 6e0f9f8 | 2014-11-26 19:43:12 +0000 | [diff] [blame] | 1256 | case Hexagon::C2_cmpgtui: |
Sirish Pande | 4bd20c5 | 2012-05-12 05:10:30 +0000 | [diff] [blame] | 1257 | return true; |
Sirish Pande | 4bd20c5 | 2012-05-12 05:10:30 +0000 | [diff] [blame] | 1258 | } |
Sirish Pande | 2c7bf00 | 2012-04-23 17:49:28 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1261 | bool HexagonInstrInfo:: |
| 1262 | isConditionalTransfer (const MachineInstr *MI) const { |
| 1263 | switch (MI->getOpcode()) { |
| 1264 | default: return false; |
Colin LeMahieu | 4af437f | 2014-12-09 20:23:30 +0000 | [diff] [blame] | 1265 | case Hexagon::A2_tfrt: |
| 1266 | case Hexagon::A2_tfrf: |
| 1267 | case Hexagon::C2_cmoveit: |
| 1268 | case Hexagon::C2_cmoveif: |
| 1269 | case Hexagon::A2_tfrtnew: |
| 1270 | case Hexagon::A2_tfrfnew: |
| 1271 | case Hexagon::C2_cmovenewit: |
| 1272 | case Hexagon::C2_cmovenewif: |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1273 | return true; |
| 1274 | } |
| 1275 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1276 | |
| 1277 | bool HexagonInstrInfo::isConditionalALU32 (const MachineInstr* MI) const { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1278 | switch (MI->getOpcode()) |
| 1279 | { |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1280 | default: return false; |
Colin LeMahieu | efa74e0 | 2014-11-18 20:28:11 +0000 | [diff] [blame] | 1281 | case Hexagon::A2_paddf: |
| 1282 | case Hexagon::A2_paddfnew: |
| 1283 | case Hexagon::A2_paddt: |
| 1284 | case Hexagon::A2_paddtnew: |
Colin LeMahieu | 44fd1c8 | 2014-11-18 22:45:47 +0000 | [diff] [blame] | 1285 | case Hexagon::A2_pandf: |
| 1286 | case Hexagon::A2_pandfnew: |
| 1287 | case Hexagon::A2_pandt: |
| 1288 | case Hexagon::A2_pandtnew: |
Colin LeMahieu | 3b3197e | 2014-11-24 17:44:19 +0000 | [diff] [blame] | 1289 | case Hexagon::A4_paslhf: |
| 1290 | case Hexagon::A4_paslhfnew: |
| 1291 | case Hexagon::A4_paslht: |
| 1292 | case Hexagon::A4_paslhtnew: |
Colin LeMahieu | 397a25e | 2014-11-24 18:04:42 +0000 | [diff] [blame] | 1293 | case Hexagon::A4_pasrhf: |
| 1294 | case Hexagon::A4_pasrhfnew: |
| 1295 | case Hexagon::A4_pasrht: |
| 1296 | case Hexagon::A4_pasrhtnew: |
Colin LeMahieu | 2186654 | 2014-11-19 22:58:04 +0000 | [diff] [blame] | 1297 | case Hexagon::A2_porf: |
| 1298 | case Hexagon::A2_porfnew: |
| 1299 | case Hexagon::A2_port: |
| 1300 | case Hexagon::A2_portnew: |
Colin LeMahieu | e88447d | 2014-11-21 21:19:18 +0000 | [diff] [blame] | 1301 | case Hexagon::A2_psubf: |
| 1302 | case Hexagon::A2_psubfnew: |
| 1303 | case Hexagon::A2_psubt: |
| 1304 | case Hexagon::A2_psubtnew: |
Colin LeMahieu | ac00643 | 2014-11-19 23:22:23 +0000 | [diff] [blame] | 1305 | case Hexagon::A2_pxorf: |
| 1306 | case Hexagon::A2_pxorfnew: |
| 1307 | case Hexagon::A2_pxort: |
| 1308 | case Hexagon::A2_pxortnew: |
Colin LeMahieu | 310991c | 2014-11-21 21:54:59 +0000 | [diff] [blame] | 1309 | case Hexagon::A4_psxthf: |
| 1310 | case Hexagon::A4_psxthfnew: |
| 1311 | case Hexagon::A4_psxtht: |
| 1312 | case Hexagon::A4_psxthtnew: |
Colin LeMahieu | 91ffec9 | 2014-11-21 21:35:52 +0000 | [diff] [blame] | 1313 | case Hexagon::A4_psxtbf: |
| 1314 | case Hexagon::A4_psxtbfnew: |
| 1315 | case Hexagon::A4_psxtbt: |
| 1316 | case Hexagon::A4_psxtbtnew: |
Colin LeMahieu | bb7d6f5 | 2014-11-24 16:48:43 +0000 | [diff] [blame] | 1317 | case Hexagon::A4_pzxtbf: |
| 1318 | case Hexagon::A4_pzxtbfnew: |
| 1319 | case Hexagon::A4_pzxtbt: |
| 1320 | case Hexagon::A4_pzxtbtnew: |
Colin LeMahieu | 098256c | 2014-11-24 17:11:34 +0000 | [diff] [blame] | 1321 | case Hexagon::A4_pzxthf: |
| 1322 | case Hexagon::A4_pzxthfnew: |
| 1323 | case Hexagon::A4_pzxtht: |
| 1324 | case Hexagon::A4_pzxthtnew: |
Colin LeMahieu | f297dbe | 2015-02-05 17:49:13 +0000 | [diff] [blame] | 1325 | case Hexagon::A2_paddit: |
| 1326 | case Hexagon::A2_paddif: |
Colin LeMahieu | b580d7d | 2014-12-09 19:23:45 +0000 | [diff] [blame] | 1327 | case Hexagon::C2_ccombinewt: |
| 1328 | case Hexagon::C2_ccombinewf: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1329 | return true; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1330 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1331 | } |
| 1332 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1333 | bool HexagonInstrInfo:: |
| 1334 | isConditionalLoad (const MachineInstr* MI) const { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1335 | switch (MI->getOpcode()) |
| 1336 | { |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1337 | default: return false; |
Colin LeMahieu | 947cd70 | 2014-12-23 20:44:59 +0000 | [diff] [blame] | 1338 | case Hexagon::L2_ploadrdt_io : |
| 1339 | case Hexagon::L2_ploadrdf_io: |
Colin LeMahieu | 026e88d | 2014-12-23 20:02:16 +0000 | [diff] [blame] | 1340 | case Hexagon::L2_ploadrit_io: |
| 1341 | case Hexagon::L2_ploadrif_io: |
Colin LeMahieu | 8e39cad | 2014-12-23 17:25:57 +0000 | [diff] [blame] | 1342 | case Hexagon::L2_ploadrht_io: |
| 1343 | case Hexagon::L2_ploadrhf_io: |
Colin LeMahieu | 4b1eac4 | 2014-12-22 21:40:43 +0000 | [diff] [blame] | 1344 | case Hexagon::L2_ploadrbt_io: |
| 1345 | case Hexagon::L2_ploadrbf_io: |
Colin LeMahieu | a9386d2 | 2014-12-23 16:42:57 +0000 | [diff] [blame] | 1346 | case Hexagon::L2_ploadruht_io: |
| 1347 | case Hexagon::L2_ploadruhf_io: |
Colin LeMahieu | af1e5de | 2014-12-22 21:20:03 +0000 | [diff] [blame] | 1348 | case Hexagon::L2_ploadrubt_io: |
| 1349 | case Hexagon::L2_ploadrubf_io: |
Colin LeMahieu | 9161d47 | 2014-12-30 18:58:47 +0000 | [diff] [blame] | 1350 | case Hexagon::L2_ploadrdt_pi: |
| 1351 | case Hexagon::L2_ploadrdf_pi: |
| 1352 | case Hexagon::L2_ploadrit_pi: |
| 1353 | case Hexagon::L2_ploadrif_pi: |
| 1354 | case Hexagon::L2_ploadrht_pi: |
| 1355 | case Hexagon::L2_ploadrhf_pi: |
| 1356 | case Hexagon::L2_ploadrbt_pi: |
| 1357 | case Hexagon::L2_ploadrbf_pi: |
| 1358 | case Hexagon::L2_ploadruht_pi: |
| 1359 | case Hexagon::L2_ploadruhf_pi: |
| 1360 | case Hexagon::L2_ploadrubt_pi: |
| 1361 | case Hexagon::L2_ploadrubf_pi: |
Colin LeMahieu | 9161d47 | 2014-12-30 18:58:47 +0000 | [diff] [blame] | 1362 | case Hexagon::L4_ploadrdt_rr: |
| 1363 | case Hexagon::L4_ploadrdf_rr: |
| 1364 | case Hexagon::L4_ploadrbt_rr: |
| 1365 | case Hexagon::L4_ploadrbf_rr: |
| 1366 | case Hexagon::L4_ploadrubt_rr: |
| 1367 | case Hexagon::L4_ploadrubf_rr: |
| 1368 | case Hexagon::L4_ploadrht_rr: |
| 1369 | case Hexagon::L4_ploadrhf_rr: |
| 1370 | case Hexagon::L4_ploadruht_rr: |
| 1371 | case Hexagon::L4_ploadruhf_rr: |
| 1372 | case Hexagon::L4_ploadrit_rr: |
| 1373 | case Hexagon::L4_ploadrif_rr: |
Colin LeMahieu | 4fd203d | 2015-02-09 21:56:37 +0000 | [diff] [blame] | 1374 | return true; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1375 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1376 | } |
Andrew Trick | d06df96 | 2012-02-01 22:13:57 +0000 | [diff] [blame] | 1377 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1378 | // Returns true if an instruction is a conditional store. |
| 1379 | // |
| 1380 | // Note: It doesn't include conditional new-value stores as they can't be |
| 1381 | // converted to .new predicate. |
| 1382 | // |
| 1383 | // p.new NV store [ if(p0.new)memw(R0+#0)=R2.new ] |
| 1384 | // ^ ^ |
| 1385 | // / \ (not OK. it will cause new-value store to be |
| 1386 | // / X conditional on p0.new while R2 producer is |
| 1387 | // / \ on p0) |
| 1388 | // / \. |
| 1389 | // p.new store p.old NV store |
| 1390 | // [if(p0.new)memw(R0+#0)=R2] [if(p0)memw(R0+#0)=R2.new] |
| 1391 | // ^ ^ |
| 1392 | // \ / |
| 1393 | // \ / |
| 1394 | // \ / |
| 1395 | // p.old store |
| 1396 | // [if (p0)memw(R0+#0)=R2] |
| 1397 | // |
| 1398 | // The above diagram shows the steps involoved in the conversion of a predicated |
| 1399 | // store instruction to its .new predicated new-value form. |
| 1400 | // |
| 1401 | // The following set of instructions further explains the scenario where |
| 1402 | // conditional new-value store becomes invalid when promoted to .new predicate |
| 1403 | // form. |
| 1404 | // |
| 1405 | // { 1) if (p0) r0 = add(r1, r2) |
| 1406 | // 2) p0 = cmp.eq(r3, #0) } |
| 1407 | // |
| 1408 | // 3) if (p0) memb(r1+#0) = r0 --> this instruction can't be grouped with |
| 1409 | // the first two instructions because in instr 1, r0 is conditional on old value |
| 1410 | // of p0 but its use in instr 3 is conditional on p0 modified by instr 2 which |
| 1411 | // is not valid for new-value stores. |
| 1412 | bool HexagonInstrInfo:: |
| 1413 | isConditionalStore (const MachineInstr* MI) const { |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1414 | switch (MI->getOpcode()) |
| 1415 | { |
| 1416 | default: return false; |
Colin LeMahieu | 2bad4a7 | 2014-12-30 21:01:38 +0000 | [diff] [blame] | 1417 | case Hexagon::S4_storeirbt_io: |
| 1418 | case Hexagon::S4_storeirbf_io: |
Colin LeMahieu | 94a498b | 2014-12-30 20:42:23 +0000 | [diff] [blame] | 1419 | case Hexagon::S4_pstorerbt_rr: |
| 1420 | case Hexagon::S4_pstorerbf_rr: |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 1421 | case Hexagon::S2_pstorerbt_io: |
| 1422 | case Hexagon::S2_pstorerbf_io: |
Colin LeMahieu | 3d34afb | 2014-12-29 19:42:14 +0000 | [diff] [blame] | 1423 | case Hexagon::S2_pstorerbt_pi: |
| 1424 | case Hexagon::S2_pstorerbf_pi: |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 1425 | case Hexagon::S2_pstorerdt_io: |
| 1426 | case Hexagon::S2_pstorerdf_io: |
Colin LeMahieu | 94a498b | 2014-12-30 20:42:23 +0000 | [diff] [blame] | 1427 | case Hexagon::S4_pstorerdt_rr: |
| 1428 | case Hexagon::S4_pstorerdf_rr: |
Colin LeMahieu | 9a3cd3f | 2014-12-29 20:00:43 +0000 | [diff] [blame] | 1429 | case Hexagon::S2_pstorerdt_pi: |
| 1430 | case Hexagon::S2_pstorerdf_pi: |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 1431 | case Hexagon::S2_pstorerht_io: |
| 1432 | case Hexagon::S2_pstorerhf_io: |
Colin LeMahieu | 2bad4a7 | 2014-12-30 21:01:38 +0000 | [diff] [blame] | 1433 | case Hexagon::S4_storeirht_io: |
| 1434 | case Hexagon::S4_storeirhf_io: |
Colin LeMahieu | 94a498b | 2014-12-30 20:42:23 +0000 | [diff] [blame] | 1435 | case Hexagon::S4_pstorerht_rr: |
| 1436 | case Hexagon::S4_pstorerhf_rr: |
Colin LeMahieu | 9a3cd3f | 2014-12-29 20:00:43 +0000 | [diff] [blame] | 1437 | case Hexagon::S2_pstorerht_pi: |
| 1438 | case Hexagon::S2_pstorerhf_pi: |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 1439 | case Hexagon::S2_pstorerit_io: |
| 1440 | case Hexagon::S2_pstorerif_io: |
Colin LeMahieu | 2bad4a7 | 2014-12-30 21:01:38 +0000 | [diff] [blame] | 1441 | case Hexagon::S4_storeirit_io: |
| 1442 | case Hexagon::S4_storeirif_io: |
Colin LeMahieu | 94a498b | 2014-12-30 20:42:23 +0000 | [diff] [blame] | 1443 | case Hexagon::S4_pstorerit_rr: |
| 1444 | case Hexagon::S4_pstorerif_rr: |
Colin LeMahieu | 9a3cd3f | 2014-12-29 20:00:43 +0000 | [diff] [blame] | 1445 | case Hexagon::S2_pstorerit_pi: |
| 1446 | case Hexagon::S2_pstorerif_pi: |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1447 | |
| 1448 | // V4 global address store before promoting to dot new. |
Colin LeMahieu | 1445553 | 2015-01-06 16:15:15 +0000 | [diff] [blame] | 1449 | case Hexagon::S4_pstorerdt_abs: |
| 1450 | case Hexagon::S4_pstorerdf_abs: |
| 1451 | case Hexagon::S4_pstorerbt_abs: |
| 1452 | case Hexagon::S4_pstorerbf_abs: |
| 1453 | case Hexagon::S4_pstorerht_abs: |
| 1454 | case Hexagon::S4_pstorerhf_abs: |
| 1455 | case Hexagon::S4_pstorerit_abs: |
| 1456 | case Hexagon::S4_pstorerif_abs: |
Colin LeMahieu | 4fd203d | 2015-02-09 21:56:37 +0000 | [diff] [blame] | 1457 | return true; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1458 | |
| 1459 | // Predicated new value stores (i.e. if (p0) memw(..)=r0.new) are excluded |
| 1460 | // from the "Conditional Store" list. Because a predicated new value store |
| 1461 | // would NOT be promoted to a double dot new store. See diagram below: |
| 1462 | // This function returns yes for those stores that are predicated but not |
| 1463 | // yet promoted to predicate dot new instructions. |
| 1464 | // |
| 1465 | // +---------------------+ |
| 1466 | // /-----| if (p0) memw(..)=r0 |---------\~ |
| 1467 | // || +---------------------+ || |
| 1468 | // promote || /\ /\ || promote |
| 1469 | // || /||\ /||\ || |
| 1470 | // \||/ demote || \||/ |
| 1471 | // \/ || || \/ |
| 1472 | // +-------------------------+ || +-------------------------+ |
| 1473 | // | if (p0.new) memw(..)=r0 | || | if (p0) memw(..)=r0.new | |
| 1474 | // +-------------------------+ || +-------------------------+ |
| 1475 | // || || || |
| 1476 | // || demote \||/ |
| 1477 | // promote || \/ NOT possible |
| 1478 | // || || /\~ |
| 1479 | // \||/ || /||\~ |
| 1480 | // \/ || || |
| 1481 | // +-----------------------------+ |
| 1482 | // | if (p0.new) memw(..)=r0.new | |
| 1483 | // +-----------------------------+ |
| 1484 | // Double Dot New Store |
| 1485 | // |
| 1486 | } |
| 1487 | } |
| 1488 | |
Jyotsna Verma | 84c4710 | 2013-05-06 18:49:23 +0000 | [diff] [blame] | 1489 | |
| 1490 | bool HexagonInstrInfo::isNewValueJump(const MachineInstr *MI) const { |
| 1491 | if (isNewValue(MI) && isBranch(MI)) |
| 1492 | return true; |
| 1493 | return false; |
| 1494 | } |
| 1495 | |
Jyotsna Verma | 00681dc | 2013-05-09 19:16:07 +0000 | [diff] [blame] | 1496 | bool HexagonInstrInfo::isPostIncrement (const MachineInstr* MI) const { |
| 1497 | return (getAddrMode(MI) == HexagonII::PostInc); |
| 1498 | } |
| 1499 | |
Jyotsna Verma | 84c4710 | 2013-05-06 18:49:23 +0000 | [diff] [blame] | 1500 | bool HexagonInstrInfo::isNewValue(const MachineInstr* MI) const { |
| 1501 | const uint64_t F = MI->getDesc().TSFlags; |
| 1502 | return ((F >> HexagonII::NewValuePos) & HexagonII::NewValueMask); |
| 1503 | } |
| 1504 | |
Jyotsna Verma | a46059b | 2013-03-28 19:44:04 +0000 | [diff] [blame] | 1505 | // Returns true, if any one of the operands is a dot new |
| 1506 | // insn, whether it is predicated dot new or register dot new. |
| 1507 | bool HexagonInstrInfo::isDotNewInst (const MachineInstr* MI) const { |
| 1508 | return (isNewValueInst(MI) || |
| 1509 | (isPredicated(MI) && isPredicatedNew(MI))); |
| 1510 | } |
| 1511 | |
Jyotsna Verma | 438cec5 | 2013-05-10 20:58:11 +0000 | [diff] [blame] | 1512 | // Returns the most basic instruction for the .new predicated instructions and |
| 1513 | // new-value stores. |
| 1514 | // For example, all of the following instructions will be converted back to the |
| 1515 | // same instruction: |
| 1516 | // 1) if (p0.new) memw(R0+#0) = R1.new ---> |
| 1517 | // 2) if (p0) memw(R0+#0)= R1.new -------> if (p0) memw(R0+#0) = R1 |
| 1518 | // 3) if (p0.new) memw(R0+#0) = R1 ---> |
| 1519 | // |
| 1520 | |
| 1521 | int HexagonInstrInfo::GetDotOldOp(const int opc) const { |
| 1522 | int NewOp = opc; |
| 1523 | if (isPredicated(NewOp) && isPredicatedNew(NewOp)) { // Get predicate old form |
| 1524 | NewOp = Hexagon::getPredOldOpcode(NewOp); |
Craig Topper | 35b2f75 | 2014-06-19 06:10:58 +0000 | [diff] [blame] | 1525 | assert(NewOp >= 0 && |
| 1526 | "Couldn't change predicate new instruction to its old form."); |
Jyotsna Verma | 438cec5 | 2013-05-10 20:58:11 +0000 | [diff] [blame] | 1527 | } |
| 1528 | |
Alp Toker | f907b89 | 2013-12-05 05:44:44 +0000 | [diff] [blame] | 1529 | if (isNewValueStore(NewOp)) { // Convert into non-new-value format |
Jyotsna Verma | 438cec5 | 2013-05-10 20:58:11 +0000 | [diff] [blame] | 1530 | NewOp = Hexagon::getNonNVStore(NewOp); |
Craig Topper | 35b2f75 | 2014-06-19 06:10:58 +0000 | [diff] [blame] | 1531 | assert(NewOp >= 0 && "Couldn't change new-value store to its old form."); |
Jyotsna Verma | 438cec5 | 2013-05-10 20:58:11 +0000 | [diff] [blame] | 1532 | } |
| 1533 | return NewOp; |
| 1534 | } |
| 1535 | |
Jyotsna Verma | 300f0b9 | 2013-05-10 20:27:34 +0000 | [diff] [blame] | 1536 | // Return the new value instruction for a given store. |
| 1537 | int HexagonInstrInfo::GetDotNewOp(const MachineInstr* MI) const { |
| 1538 | int NVOpcode = Hexagon::getNewValueOpcode(MI->getOpcode()); |
| 1539 | if (NVOpcode >= 0) // Valid new-value store instruction. |
| 1540 | return NVOpcode; |
| 1541 | |
| 1542 | switch (MI->getOpcode()) { |
| 1543 | default: llvm_unreachable("Unknown .new type"); |
| 1544 | // store new value byte |
Colin LeMahieu | c043446 | 2015-02-04 17:52:06 +0000 | [diff] [blame] | 1545 | case Hexagon::S4_storerb_ur: |
| 1546 | return Hexagon::S4_storerbnew_ur; |
Jyotsna Verma | 300f0b9 | 2013-05-10 20:27:34 +0000 | [diff] [blame] | 1547 | |
Colin LeMahieu | c043446 | 2015-02-04 17:52:06 +0000 | [diff] [blame] | 1548 | case Hexagon::S4_storerh_ur: |
| 1549 | return Hexagon::S4_storerhnew_ur; |
Jyotsna Verma | 300f0b9 | 2013-05-10 20:27:34 +0000 | [diff] [blame] | 1550 | |
Colin LeMahieu | c043446 | 2015-02-04 17:52:06 +0000 | [diff] [blame] | 1551 | case Hexagon::S4_storeri_ur: |
| 1552 | return Hexagon::S4_storerinew_ur; |
Jyotsna Verma | 300f0b9 | 2013-05-10 20:27:34 +0000 | [diff] [blame] | 1553 | |
| 1554 | } |
| 1555 | return 0; |
| 1556 | } |
| 1557 | |
Jyotsna Verma | 00681dc | 2013-05-09 19:16:07 +0000 | [diff] [blame] | 1558 | // Return .new predicate version for an instruction. |
| 1559 | int HexagonInstrInfo::GetDotNewPredOp(MachineInstr *MI, |
| 1560 | const MachineBranchProbabilityInfo |
| 1561 | *MBPI) const { |
| 1562 | |
| 1563 | int NewOpcode = Hexagon::getPredNewOpcode(MI->getOpcode()); |
| 1564 | if (NewOpcode >= 0) // Valid predicate new instruction |
| 1565 | return NewOpcode; |
| 1566 | |
| 1567 | switch (MI->getOpcode()) { |
| 1568 | default: llvm_unreachable("Unknown .new type"); |
| 1569 | // Condtional Jumps |
Colin LeMahieu | db0b13c | 2014-12-10 21:24:10 +0000 | [diff] [blame] | 1570 | case Hexagon::J2_jumpt: |
| 1571 | case Hexagon::J2_jumpf: |
Jyotsna Verma | 00681dc | 2013-05-09 19:16:07 +0000 | [diff] [blame] | 1572 | return getDotNewPredJumpOp(MI, MBPI); |
| 1573 | |
Colin LeMahieu | db0b13c | 2014-12-10 21:24:10 +0000 | [diff] [blame] | 1574 | case Hexagon::J2_jumprt: |
| 1575 | return Hexagon::J2_jumptnewpt; |
Jyotsna Verma | 00681dc | 2013-05-09 19:16:07 +0000 | [diff] [blame] | 1576 | |
Colin LeMahieu | db0b13c | 2014-12-10 21:24:10 +0000 | [diff] [blame] | 1577 | case Hexagon::J2_jumprf: |
| 1578 | return Hexagon::J2_jumprfnewpt; |
Jyotsna Verma | 00681dc | 2013-05-09 19:16:07 +0000 | [diff] [blame] | 1579 | |
Colin LeMahieu | db0b13c | 2014-12-10 21:24:10 +0000 | [diff] [blame] | 1580 | case Hexagon::JMPrett: |
| 1581 | return Hexagon::J2_jumprtnewpt; |
Jyotsna Verma | 00681dc | 2013-05-09 19:16:07 +0000 | [diff] [blame] | 1582 | |
Colin LeMahieu | db0b13c | 2014-12-10 21:24:10 +0000 | [diff] [blame] | 1583 | case Hexagon::JMPretf: |
| 1584 | return Hexagon::J2_jumprfnewpt; |
Jyotsna Verma | 00681dc | 2013-05-09 19:16:07 +0000 | [diff] [blame] | 1585 | |
| 1586 | |
| 1587 | // Conditional combine |
Colin LeMahieu | b580d7d | 2014-12-09 19:23:45 +0000 | [diff] [blame] | 1588 | case Hexagon::C2_ccombinewt: |
| 1589 | return Hexagon::C2_ccombinewnewt; |
| 1590 | case Hexagon::C2_ccombinewf: |
| 1591 | return Hexagon::C2_ccombinewnewf; |
Jyotsna Verma | 00681dc | 2013-05-09 19:16:07 +0000 | [diff] [blame] | 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 1596 | unsigned HexagonInstrInfo::getAddrMode(const MachineInstr* MI) const { |
| 1597 | const uint64_t F = MI->getDesc().TSFlags; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1598 | |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 1599 | return((F >> HexagonII::AddrModePos) & HexagonII::AddrModeMask); |
| 1600 | } |
| 1601 | |
| 1602 | /// immediateExtend - Changes the instruction in place to one using an immediate |
| 1603 | /// extender. |
| 1604 | void HexagonInstrInfo::immediateExtend(MachineInstr *MI) const { |
| 1605 | assert((isExtendable(MI)||isConstExtended(MI)) && |
| 1606 | "Instruction must be extendable"); |
| 1607 | // Find which operand is extendable. |
| 1608 | short ExtOpNum = getCExtOpNum(MI); |
| 1609 | MachineOperand &MO = MI->getOperand(ExtOpNum); |
| 1610 | // This needs to be something we understand. |
| 1611 | assert((MO.isMBB() || MO.isImm()) && |
| 1612 | "Branch with unknown extendable field type"); |
| 1613 | // Mark given operand as extended. |
| 1614 | MO.addTargetFlag(HexagonII::HMOTF_ConstExtended); |
| 1615 | } |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1616 | |
Eric Christopher | 143f02c | 2014-10-09 01:59:35 +0000 | [diff] [blame] | 1617 | DFAPacketizer *HexagonInstrInfo::CreateTargetScheduleState( |
| 1618 | const TargetSubtargetInfo &STI) const { |
| 1619 | const InstrItineraryData *II = STI.getInstrItineraryData(); |
| 1620 | return static_cast<const HexagonSubtarget &>(STI).createDFAPacketizer(II); |
Andrew Trick | d06df96 | 2012-02-01 22:13:57 +0000 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | bool HexagonInstrInfo::isSchedulingBoundary(const MachineInstr *MI, |
| 1624 | const MachineBasicBlock *MBB, |
| 1625 | const MachineFunction &MF) const { |
| 1626 | // Debug info is never a scheduling boundary. It's necessary to be explicit |
| 1627 | // due to the special treatment of IT instructions below, otherwise a |
| 1628 | // dbg_value followed by an IT will result in the IT instruction being |
| 1629 | // considered a scheduling hazard, which is wrong. It should be the actual |
| 1630 | // instruction preceding the dbg_value instruction(s), just like it is |
| 1631 | // when debug info is not present. |
| 1632 | if (MI->isDebugValue()) |
| 1633 | return false; |
| 1634 | |
| 1635 | // Terminators and labels can't be scheduled around. |
Rafael Espindola | b1f25f1 | 2014-03-07 06:08:31 +0000 | [diff] [blame] | 1636 | if (MI->getDesc().isTerminator() || MI->isPosition() || MI->isInlineAsm()) |
Andrew Trick | d06df96 | 2012-02-01 22:13:57 +0000 | [diff] [blame] | 1637 | return true; |
| 1638 | |
| 1639 | return false; |
| 1640 | } |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 1641 | |
| 1642 | bool HexagonInstrInfo::isConstExtended(MachineInstr *MI) const { |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 1643 | const uint64_t F = MI->getDesc().TSFlags; |
| 1644 | unsigned isExtended = (F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask; |
| 1645 | if (isExtended) // Instruction must be extended. |
| 1646 | return true; |
| 1647 | |
| 1648 | unsigned isExtendable = (F >> HexagonII::ExtendablePos) |
| 1649 | & HexagonII::ExtendableMask; |
| 1650 | if (!isExtendable) |
| 1651 | return false; |
| 1652 | |
| 1653 | short ExtOpNum = getCExtOpNum(MI); |
| 1654 | const MachineOperand &MO = MI->getOperand(ExtOpNum); |
| 1655 | // Use MO operand flags to determine if MO |
| 1656 | // has the HMOTF_ConstExtended flag set. |
| 1657 | if (MO.getTargetFlags() && HexagonII::HMOTF_ConstExtended) |
| 1658 | return true; |
| 1659 | // If this is a Machine BB address we are talking about, and it is |
| 1660 | // not marked as extended, say so. |
| 1661 | if (MO.isMBB()) |
| 1662 | return false; |
| 1663 | |
| 1664 | // We could be using an instruction with an extendable immediate and shoehorn |
| 1665 | // a global address into it. If it is a global address it will be constant |
| 1666 | // extended. We do this for COMBINE. |
| 1667 | // We currently only handle isGlobal() because it is the only kind of |
| 1668 | // object we are going to end up with here for now. |
| 1669 | // In the future we probably should add isSymbol(), etc. |
Colin LeMahieu | 2efa2d0 | 2015-03-09 21:48:13 +0000 | [diff] [blame] | 1670 | if (MO.isGlobal() || MO.isSymbol() || MO.isBlockAddress()) |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 1671 | return true; |
| 1672 | |
| 1673 | // If the extendable operand is not 'Immediate' type, the instruction should |
| 1674 | // have 'isExtended' flag set. |
| 1675 | assert(MO.isImm() && "Extendable operand must be Immediate type"); |
| 1676 | |
| 1677 | int MinValue = getMinValue(MI); |
| 1678 | int MaxValue = getMaxValue(MI); |
| 1679 | int ImmValue = MO.getImm(); |
| 1680 | |
| 1681 | return (ImmValue < MinValue || ImmValue > MaxValue); |
| 1682 | } |
| 1683 | |
Jyotsna Verma | 1d29750 | 2013-05-02 15:39:30 +0000 | [diff] [blame] | 1684 | // Returns the opcode to use when converting MI, which is a conditional jump, |
| 1685 | // into a conditional instruction which uses the .new value of the predicate. |
| 1686 | // We also use branch probabilities to add a hint to the jump. |
| 1687 | int |
| 1688 | HexagonInstrInfo::getDotNewPredJumpOp(MachineInstr *MI, |
| 1689 | const |
| 1690 | MachineBranchProbabilityInfo *MBPI) const { |
| 1691 | |
| 1692 | // We assume that block can have at most two successors. |
| 1693 | bool taken = false; |
| 1694 | MachineBasicBlock *Src = MI->getParent(); |
| 1695 | MachineOperand *BrTarget = &MI->getOperand(1); |
| 1696 | MachineBasicBlock *Dst = BrTarget->getMBB(); |
| 1697 | |
| 1698 | const BranchProbability Prediction = MBPI->getEdgeProbability(Src, Dst); |
| 1699 | if (Prediction >= BranchProbability(1,2)) |
| 1700 | taken = true; |
| 1701 | |
| 1702 | switch (MI->getOpcode()) { |
Colin LeMahieu | db0b13c | 2014-12-10 21:24:10 +0000 | [diff] [blame] | 1703 | case Hexagon::J2_jumpt: |
| 1704 | return taken ? Hexagon::J2_jumptnewpt : Hexagon::J2_jumptnew; |
| 1705 | case Hexagon::J2_jumpf: |
| 1706 | return taken ? Hexagon::J2_jumpfnewpt : Hexagon::J2_jumpfnew; |
Jyotsna Verma | 1d29750 | 2013-05-02 15:39:30 +0000 | [diff] [blame] | 1707 | |
| 1708 | default: |
| 1709 | llvm_unreachable("Unexpected jump instruction."); |
| 1710 | } |
| 1711 | } |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 1712 | // Returns true if a particular operand is extendable for an instruction. |
| 1713 | bool HexagonInstrInfo::isOperandExtended(const MachineInstr *MI, |
| 1714 | unsigned short OperandNum) const { |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 1715 | const uint64_t F = MI->getDesc().TSFlags; |
| 1716 | |
| 1717 | return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask) |
| 1718 | == OperandNum; |
| 1719 | } |
| 1720 | |
| 1721 | // Returns Operand Index for the constant extended instruction. |
| 1722 | unsigned short HexagonInstrInfo::getCExtOpNum(const MachineInstr *MI) const { |
| 1723 | const uint64_t F = MI->getDesc().TSFlags; |
| 1724 | return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask); |
| 1725 | } |
| 1726 | |
| 1727 | // Returns the min value that doesn't need to be extended. |
| 1728 | int HexagonInstrInfo::getMinValue(const MachineInstr *MI) const { |
| 1729 | const uint64_t F = MI->getDesc().TSFlags; |
| 1730 | unsigned isSigned = (F >> HexagonII::ExtentSignedPos) |
| 1731 | & HexagonII::ExtentSignedMask; |
| 1732 | unsigned bits = (F >> HexagonII::ExtentBitsPos) |
| 1733 | & HexagonII::ExtentBitsMask; |
| 1734 | |
| 1735 | if (isSigned) // if value is signed |
Alexey Samsonov | 2651ae6 | 2014-08-20 21:22:03 +0000 | [diff] [blame] | 1736 | return -1U << (bits - 1); |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 1737 | else |
| 1738 | return 0; |
| 1739 | } |
| 1740 | |
| 1741 | // Returns the max value that doesn't need to be extended. |
| 1742 | int HexagonInstrInfo::getMaxValue(const MachineInstr *MI) const { |
| 1743 | const uint64_t F = MI->getDesc().TSFlags; |
| 1744 | unsigned isSigned = (F >> HexagonII::ExtentSignedPos) |
| 1745 | & HexagonII::ExtentSignedMask; |
| 1746 | unsigned bits = (F >> HexagonII::ExtentBitsPos) |
| 1747 | & HexagonII::ExtentBitsMask; |
| 1748 | |
| 1749 | if (isSigned) // if value is signed |
Alexey Samsonov | 2651ae6 | 2014-08-20 21:22:03 +0000 | [diff] [blame] | 1750 | return ~(-1U << (bits - 1)); |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 1751 | else |
Alexey Samsonov | 2651ae6 | 2014-08-20 21:22:03 +0000 | [diff] [blame] | 1752 | return ~(-1U << bits); |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | // Returns true if an instruction can be converted into a non-extended |
| 1756 | // equivalent instruction. |
| 1757 | bool HexagonInstrInfo::NonExtEquivalentExists (const MachineInstr *MI) const { |
| 1758 | |
| 1759 | short NonExtOpcode; |
| 1760 | // Check if the instruction has a register form that uses register in place |
| 1761 | // of the extended operand, if so return that as the non-extended form. |
| 1762 | if (Hexagon::getRegForm(MI->getOpcode()) >= 0) |
| 1763 | return true; |
| 1764 | |
| 1765 | if (MI->getDesc().mayLoad() || MI->getDesc().mayStore()) { |
Alp Toker | cb40291 | 2014-01-24 17:20:08 +0000 | [diff] [blame] | 1766 | // Check addressing mode and retrieve non-ext equivalent instruction. |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 1767 | |
| 1768 | switch (getAddrMode(MI)) { |
| 1769 | case HexagonII::Absolute : |
| 1770 | // Load/store with absolute addressing mode can be converted into |
| 1771 | // base+offset mode. |
| 1772 | NonExtOpcode = Hexagon::getBasedWithImmOffset(MI->getOpcode()); |
| 1773 | break; |
| 1774 | case HexagonII::BaseImmOffset : |
| 1775 | // Load/store with base+offset addressing mode can be converted into |
| 1776 | // base+register offset addressing mode. However left shift operand should |
| 1777 | // be set to 0. |
| 1778 | NonExtOpcode = Hexagon::getBaseWithRegOffset(MI->getOpcode()); |
| 1779 | break; |
| 1780 | default: |
| 1781 | return false; |
| 1782 | } |
| 1783 | if (NonExtOpcode < 0) |
| 1784 | return false; |
| 1785 | return true; |
| 1786 | } |
| 1787 | return false; |
| 1788 | } |
| 1789 | |
| 1790 | // Returns opcode of the non-extended equivalent instruction. |
| 1791 | short HexagonInstrInfo::getNonExtOpcode (const MachineInstr *MI) const { |
| 1792 | |
| 1793 | // Check if the instruction has a register form that uses register in place |
| 1794 | // of the extended operand, if so return that as the non-extended form. |
| 1795 | short NonExtOpcode = Hexagon::getRegForm(MI->getOpcode()); |
| 1796 | if (NonExtOpcode >= 0) |
| 1797 | return NonExtOpcode; |
| 1798 | |
| 1799 | if (MI->getDesc().mayLoad() || MI->getDesc().mayStore()) { |
Alp Toker | cb40291 | 2014-01-24 17:20:08 +0000 | [diff] [blame] | 1800 | // Check addressing mode and retrieve non-ext equivalent instruction. |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 1801 | switch (getAddrMode(MI)) { |
| 1802 | case HexagonII::Absolute : |
| 1803 | return Hexagon::getBasedWithImmOffset(MI->getOpcode()); |
| 1804 | case HexagonII::BaseImmOffset : |
| 1805 | return Hexagon::getBaseWithRegOffset(MI->getOpcode()); |
| 1806 | default: |
| 1807 | return -1; |
| 1808 | } |
| 1809 | } |
| 1810 | return -1; |
| 1811 | } |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 1812 | |
| 1813 | bool HexagonInstrInfo::PredOpcodeHasJMP_c(Opcode_t Opcode) const { |
Colin LeMahieu | db0b13c | 2014-12-10 21:24:10 +0000 | [diff] [blame] | 1814 | return (Opcode == Hexagon::J2_jumpt) || |
| 1815 | (Opcode == Hexagon::J2_jumpf) || |
| 1816 | (Opcode == Hexagon::J2_jumptnewpt) || |
| 1817 | (Opcode == Hexagon::J2_jumpfnewpt) || |
| 1818 | (Opcode == Hexagon::J2_jumpt) || |
| 1819 | (Opcode == Hexagon::J2_jumpf); |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | bool HexagonInstrInfo::PredOpcodeHasNot(Opcode_t Opcode) const { |
Colin LeMahieu | db0b13c | 2014-12-10 21:24:10 +0000 | [diff] [blame] | 1823 | return (Opcode == Hexagon::J2_jumpf) || |
| 1824 | (Opcode == Hexagon::J2_jumpfnewpt) || |
| 1825 | (Opcode == Hexagon::J2_jumpfnew); |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 1826 | } |