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