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