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 | |
Krzysztof Parzyszek | e95e955 | 2016-07-29 13:59:09 +0000 | [diff] [blame] | 14 | #include "HexagonHazardRecognizer.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 15 | #include "HexagonInstrInfo.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" |
Ron Lieberman | 88159e5 | 2016-09-02 22:56:24 +0000 | [diff] [blame^] | 21 | #include "llvm/CodeGen/LivePhysRegs.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/MachineMemOperand.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/PseudoSourceValue.h" |
Krzysztof Parzyszek | e95e955 | 2016-07-29 13:59:09 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/ScheduleDAG.h" |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 28 | #include "llvm/MC/MCAsmInfo.h" |
Krzysztof Parzyszek | feb65a3 | 2016-02-12 20:54:15 +0000 | [diff] [blame] | 29 | #include "llvm/Support/CommandLine.h" |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 30 | #include "llvm/Support/Debug.h" |
Benjamin Kramer | ae87d7b | 2012-02-06 10:19:29 +0000 | [diff] [blame] | 31 | #include "llvm/Support/MathExtras.h" |
Reid Kleckner | 1c76f155 | 2013-05-03 00:54:56 +0000 | [diff] [blame] | 32 | #include "llvm/Support/raw_ostream.h" |
Krzysztof Parzyszek | aa93575 | 2015-11-24 15:11:13 +0000 | [diff] [blame] | 33 | #include <cctype> |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 34 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 35 | using namespace llvm; |
| 36 | |
Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 37 | #define DEBUG_TYPE "hexagon-instrinfo" |
| 38 | |
Chandler Carruth | d174b72 | 2014-04-22 02:03:14 +0000 | [diff] [blame] | 39 | #define GET_INSTRINFO_CTOR_DTOR |
| 40 | #define GET_INSTRMAP_INFO |
| 41 | #include "HexagonGenInstrInfo.inc" |
| 42 | #include "HexagonGenDFAPacketizer.inc" |
| 43 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 44 | cl::opt<bool> ScheduleInlineAsm("hexagon-sched-inline-asm", cl::Hidden, |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 45 | cl::init(false), cl::desc("Do not consider inline-asm a scheduling/" |
| 46 | "packetization boundary.")); |
| 47 | |
| 48 | static cl::opt<bool> EnableBranchPrediction("hexagon-enable-branch-prediction", |
| 49 | cl::Hidden, cl::init(true), cl::desc("Enable branch prediction")); |
| 50 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 51 | static cl::opt<bool> DisableNVSchedule("disable-hexagon-nv-schedule", |
| 52 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 53 | cl::desc("Disable schedule adjustment for new value stores.")); |
| 54 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 55 | static cl::opt<bool> EnableTimingClassLatency( |
| 56 | "enable-timing-class-latency", cl::Hidden, cl::init(false), |
| 57 | cl::desc("Enable timing class latency")); |
| 58 | |
| 59 | static cl::opt<bool> EnableALUForwarding( |
| 60 | "enable-alu-forwarding", cl::Hidden, cl::init(true), |
| 61 | cl::desc("Enable vec alu forwarding")); |
| 62 | |
| 63 | static cl::opt<bool> EnableACCForwarding( |
| 64 | "enable-acc-forwarding", cl::Hidden, cl::init(true), |
| 65 | cl::desc("Enable vec acc forwarding")); |
| 66 | |
| 67 | static cl::opt<bool> BranchRelaxAsmLarge("branch-relax-asm-large", |
| 68 | cl::init(true), cl::Hidden, cl::ZeroOrMore, cl::desc("branch relax asm")); |
| 69 | |
Krzysztof Parzyszek | e95e955 | 2016-07-29 13:59:09 +0000 | [diff] [blame] | 70 | static cl::opt<bool> UseDFAHazardRec("dfa-hazard-rec", |
| 71 | cl::init(true), cl::Hidden, cl::ZeroOrMore, |
| 72 | cl::desc("Use the DFA based hazard recognizer.")); |
| 73 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 74 | /// |
| 75 | /// Constants for Hexagon instructions. |
| 76 | /// |
Krzysztof Parzyszek | 6bd4268 | 2016-05-05 21:58:02 +0000 | [diff] [blame] | 77 | const int Hexagon_MEMV_OFFSET_MAX_128B = 896; // #s4: -8*128...7*128 |
| 78 | const int Hexagon_MEMV_OFFSET_MIN_128B = -1024; // #s4 |
| 79 | const int Hexagon_MEMV_OFFSET_MAX = 448; // #s4: -8*64...7*64 |
| 80 | const int Hexagon_MEMV_OFFSET_MIN = -512; // #s4 |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 81 | const int Hexagon_MEMW_OFFSET_MAX = 4095; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 82 | const int Hexagon_MEMW_OFFSET_MIN = -4096; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 83 | const int Hexagon_MEMD_OFFSET_MAX = 8191; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 84 | const int Hexagon_MEMD_OFFSET_MIN = -8192; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 85 | const int Hexagon_MEMH_OFFSET_MAX = 2047; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 86 | const int Hexagon_MEMH_OFFSET_MIN = -2048; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 87 | const int Hexagon_MEMB_OFFSET_MAX = 1023; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 88 | const int Hexagon_MEMB_OFFSET_MIN = -1024; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 89 | const int Hexagon_ADDI_OFFSET_MAX = 32767; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 90 | const int Hexagon_ADDI_OFFSET_MIN = -32768; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 91 | const int Hexagon_MEMD_AUTOINC_MAX = 56; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 92 | const int Hexagon_MEMD_AUTOINC_MIN = -64; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 93 | const int Hexagon_MEMW_AUTOINC_MAX = 28; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 94 | const int Hexagon_MEMW_AUTOINC_MIN = -32; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 95 | const int Hexagon_MEMH_AUTOINC_MAX = 14; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 96 | const int Hexagon_MEMH_AUTOINC_MIN = -16; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 97 | const int Hexagon_MEMB_AUTOINC_MAX = 7; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 98 | const int Hexagon_MEMB_AUTOINC_MIN = -8; |
Krzysztof Parzyszek | 6bd4268 | 2016-05-05 21:58:02 +0000 | [diff] [blame] | 99 | const int Hexagon_MEMV_AUTOINC_MAX = 192; // #s3 |
| 100 | const int Hexagon_MEMV_AUTOINC_MIN = -256; // #s3 |
| 101 | const int Hexagon_MEMV_AUTOINC_MAX_128B = 384; // #s3 |
| 102 | const int Hexagon_MEMV_AUTOINC_MIN_128B = -512; // #s3 |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 103 | |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 104 | // Pin the vtable to this file. |
| 105 | void HexagonInstrInfo::anchor() {} |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 106 | |
| 107 | HexagonInstrInfo::HexagonInstrInfo(HexagonSubtarget &ST) |
Eric Christopher | c4d3140 | 2015-03-10 23:45:55 +0000 | [diff] [blame] | 108 | : HexagonGenInstrInfo(Hexagon::ADJCALLSTACKDOWN, Hexagon::ADJCALLSTACKUP), |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 109 | RI() {} |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 110 | |
| 111 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 112 | static bool isIntRegForSubInst(unsigned Reg) { |
| 113 | return (Reg >= Hexagon::R0 && Reg <= Hexagon::R7) || |
| 114 | (Reg >= Hexagon::R16 && Reg <= Hexagon::R23); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 118 | static bool isDblRegForSubInst(unsigned Reg, const HexagonRegisterInfo &HRI) { |
| 119 | return isIntRegForSubInst(HRI.getSubReg(Reg, Hexagon::subreg_loreg)) && |
| 120 | isIntRegForSubInst(HRI.getSubReg(Reg, Hexagon::subreg_hireg)); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 123 | |
| 124 | /// Calculate number of instructions excluding the debug instructions. |
| 125 | static unsigned nonDbgMICount(MachineBasicBlock::const_instr_iterator MIB, |
| 126 | MachineBasicBlock::const_instr_iterator MIE) { |
| 127 | unsigned Count = 0; |
| 128 | for (; MIB != MIE; ++MIB) { |
| 129 | if (!MIB->isDebugValue()) |
| 130 | ++Count; |
| 131 | } |
| 132 | return Count; |
| 133 | } |
| 134 | |
| 135 | |
| 136 | /// Find the hardware loop instruction used to set-up the specified loop. |
| 137 | /// On Hexagon, we have two instructions used to set-up the hardware loop |
| 138 | /// (LOOP0, LOOP1) with corresponding endloop (ENDLOOP0, ENDLOOP1) instructions |
| 139 | /// to indicate the end of a loop. |
| 140 | static MachineInstr *findLoopInstr(MachineBasicBlock *BB, int EndLoopOp, |
| 141 | SmallPtrSet<MachineBasicBlock *, 8> &Visited) { |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 142 | int LOOPi; |
| 143 | int LOOPr; |
| 144 | if (EndLoopOp == Hexagon::ENDLOOP0) { |
| 145 | LOOPi = Hexagon::J2_loop0i; |
| 146 | LOOPr = Hexagon::J2_loop0r; |
| 147 | } else { // EndLoopOp == Hexagon::EndLOOP1 |
| 148 | LOOPi = Hexagon::J2_loop1i; |
| 149 | LOOPr = Hexagon::J2_loop1r; |
| 150 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 151 | |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 152 | // The loop set-up instruction will be in a predecessor block |
| 153 | for (MachineBasicBlock::pred_iterator PB = BB->pred_begin(), |
| 154 | PE = BB->pred_end(); PB != PE; ++PB) { |
| 155 | // If this has been visited, already skip it. |
| 156 | if (!Visited.insert(*PB).second) |
| 157 | continue; |
| 158 | if (*PB == BB) |
| 159 | continue; |
| 160 | for (MachineBasicBlock::reverse_instr_iterator I = (*PB)->instr_rbegin(), |
| 161 | E = (*PB)->instr_rend(); I != E; ++I) { |
| 162 | int Opc = I->getOpcode(); |
| 163 | if (Opc == LOOPi || Opc == LOOPr) |
| 164 | return &*I; |
| 165 | // We've reached a different loop, which means the loop0 has been removed. |
| 166 | if (Opc == EndLoopOp) |
| 167 | return 0; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 168 | } |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 169 | // Check the predecessors for the LOOP instruction. |
| 170 | MachineInstr *loop = findLoopInstr(*PB, EndLoopOp, Visited); |
| 171 | if (loop) |
| 172 | return loop; |
| 173 | } |
| 174 | return 0; |
| 175 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 176 | |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 177 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 178 | /// Gather register def/uses from MI. |
| 179 | /// This treats possible (predicated) defs as actually happening ones |
| 180 | /// (conservatively). |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 181 | static inline void parseOperands(const MachineInstr &MI, |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 182 | SmallVector<unsigned, 4> &Defs, SmallVector<unsigned, 8> &Uses) { |
| 183 | Defs.clear(); |
| 184 | Uses.clear(); |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 185 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 186 | for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) { |
| 187 | const MachineOperand &MO = MI.getOperand(i); |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 188 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 189 | if (!MO.isReg()) |
| 190 | continue; |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 191 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 192 | unsigned Reg = MO.getReg(); |
| 193 | if (!Reg) |
| 194 | continue; |
| 195 | |
| 196 | if (MO.isUse()) |
| 197 | Uses.push_back(MO.getReg()); |
| 198 | |
| 199 | if (MO.isDef()) |
| 200 | Defs.push_back(MO.getReg()); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | |
| 205 | // Position dependent, so check twice for swap. |
| 206 | static bool isDuplexPairMatch(unsigned Ga, unsigned Gb) { |
| 207 | switch (Ga) { |
| 208 | case HexagonII::HSIG_None: |
| 209 | default: |
| 210 | return false; |
| 211 | case HexagonII::HSIG_L1: |
| 212 | return (Gb == HexagonII::HSIG_L1 || Gb == HexagonII::HSIG_A); |
| 213 | case HexagonII::HSIG_L2: |
| 214 | return (Gb == HexagonII::HSIG_L1 || Gb == HexagonII::HSIG_L2 || |
| 215 | Gb == HexagonII::HSIG_A); |
| 216 | case HexagonII::HSIG_S1: |
| 217 | return (Gb == HexagonII::HSIG_L1 || Gb == HexagonII::HSIG_L2 || |
| 218 | Gb == HexagonII::HSIG_S1 || Gb == HexagonII::HSIG_A); |
| 219 | case HexagonII::HSIG_S2: |
| 220 | return (Gb == HexagonII::HSIG_L1 || Gb == HexagonII::HSIG_L2 || |
| 221 | Gb == HexagonII::HSIG_S1 || Gb == HexagonII::HSIG_S2 || |
| 222 | Gb == HexagonII::HSIG_A); |
| 223 | case HexagonII::HSIG_A: |
| 224 | return (Gb == HexagonII::HSIG_A); |
| 225 | case HexagonII::HSIG_Compound: |
| 226 | return (Gb == HexagonII::HSIG_Compound); |
| 227 | } |
| 228 | return false; |
| 229 | } |
| 230 | |
| 231 | |
| 232 | |
| 233 | /// isLoadFromStackSlot - If the specified machine instruction is a direct |
| 234 | /// load from a stack slot, return the virtual or physical register number of |
| 235 | /// the destination along with the FrameIndex of the loaded stack slot. If |
| 236 | /// not, return 0. This predicate must return 0 if the instruction has |
| 237 | /// any side effects other than loading from the stack slot. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 238 | unsigned HexagonInstrInfo::isLoadFromStackSlot(const MachineInstr &MI, |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 239 | int &FrameIndex) const { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 240 | switch (MI.getOpcode()) { |
| 241 | default: |
| 242 | break; |
| 243 | case Hexagon::L2_loadrb_io: |
| 244 | case Hexagon::L2_loadrub_io: |
| 245 | case Hexagon::L2_loadrh_io: |
| 246 | case Hexagon::L2_loadruh_io: |
| 247 | case Hexagon::L2_loadri_io: |
| 248 | case Hexagon::L2_loadrd_io: |
| 249 | case Hexagon::V6_vL32b_ai: |
| 250 | case Hexagon::V6_vL32b_ai_128B: |
| 251 | case Hexagon::V6_vL32Ub_ai: |
| 252 | case Hexagon::V6_vL32Ub_ai_128B: |
| 253 | case Hexagon::LDriw_pred: |
| 254 | case Hexagon::LDriw_mod: |
Krzysztof Parzyszek | 17aa413 | 2016-08-16 15:43:54 +0000 | [diff] [blame] | 255 | case Hexagon::PS_vloadrq_ai: |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 256 | case Hexagon::PS_vloadrw_ai: |
Krzysztof Parzyszek | 17aa413 | 2016-08-16 15:43:54 +0000 | [diff] [blame] | 257 | case Hexagon::PS_vloadrq_ai_128B: |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 258 | case Hexagon::PS_vloadrw_ai_128B: { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 259 | const MachineOperand OpFI = MI.getOperand(1); |
| 260 | if (!OpFI.isFI()) |
| 261 | return 0; |
| 262 | const MachineOperand OpOff = MI.getOperand(2); |
| 263 | if (!OpOff.isImm() || OpOff.getImm() != 0) |
| 264 | return 0; |
| 265 | FrameIndex = OpFI.getIndex(); |
| 266 | return MI.getOperand(0).getReg(); |
| 267 | } |
Krzysztof Parzyszek | feb65a3 | 2016-02-12 20:54:15 +0000 | [diff] [blame] | 268 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 269 | case Hexagon::L2_ploadrbt_io: |
| 270 | case Hexagon::L2_ploadrbf_io: |
| 271 | case Hexagon::L2_ploadrubt_io: |
| 272 | case Hexagon::L2_ploadrubf_io: |
| 273 | case Hexagon::L2_ploadrht_io: |
| 274 | case Hexagon::L2_ploadrhf_io: |
| 275 | case Hexagon::L2_ploadruht_io: |
| 276 | case Hexagon::L2_ploadruhf_io: |
| 277 | case Hexagon::L2_ploadrit_io: |
| 278 | case Hexagon::L2_ploadrif_io: |
| 279 | case Hexagon::L2_ploadrdt_io: |
| 280 | case Hexagon::L2_ploadrdf_io: { |
| 281 | const MachineOperand OpFI = MI.getOperand(2); |
| 282 | if (!OpFI.isFI()) |
| 283 | return 0; |
| 284 | const MachineOperand OpOff = MI.getOperand(3); |
| 285 | if (!OpOff.isImm() || OpOff.getImm() != 0) |
| 286 | return 0; |
| 287 | FrameIndex = OpFI.getIndex(); |
| 288 | return MI.getOperand(0).getReg(); |
| 289 | } |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 290 | } |
Krzysztof Parzyszek | feb65a3 | 2016-02-12 20:54:15 +0000 | [diff] [blame] | 291 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 292 | return 0; |
| 293 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 294 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 295 | |
| 296 | /// isStoreToStackSlot - If the specified machine instruction is a direct |
| 297 | /// store to a stack slot, return the virtual or physical register number of |
| 298 | /// the source reg along with the FrameIndex of the loaded stack slot. If |
| 299 | /// not, return 0. This predicate must return 0 if the instruction has |
| 300 | /// any side effects other than storing to the stack slot. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 301 | unsigned HexagonInstrInfo::isStoreToStackSlot(const MachineInstr &MI, |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 302 | int &FrameIndex) const { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 303 | switch (MI.getOpcode()) { |
| 304 | default: |
| 305 | break; |
| 306 | case Hexagon::S2_storerb_io: |
| 307 | case Hexagon::S2_storerh_io: |
| 308 | case Hexagon::S2_storeri_io: |
| 309 | case Hexagon::S2_storerd_io: |
| 310 | case Hexagon::V6_vS32b_ai: |
| 311 | case Hexagon::V6_vS32b_ai_128B: |
| 312 | case Hexagon::V6_vS32Ub_ai: |
| 313 | case Hexagon::V6_vS32Ub_ai_128B: |
| 314 | case Hexagon::STriw_pred: |
| 315 | case Hexagon::STriw_mod: |
Krzysztof Parzyszek | 17aa413 | 2016-08-16 15:43:54 +0000 | [diff] [blame] | 316 | case Hexagon::PS_vstorerq_ai: |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 317 | case Hexagon::PS_vstorerw_ai: |
Krzysztof Parzyszek | 17aa413 | 2016-08-16 15:43:54 +0000 | [diff] [blame] | 318 | case Hexagon::PS_vstorerq_ai_128B: |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 319 | case Hexagon::PS_vstorerw_ai_128B: { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 320 | const MachineOperand &OpFI = MI.getOperand(0); |
| 321 | if (!OpFI.isFI()) |
| 322 | return 0; |
| 323 | const MachineOperand &OpOff = MI.getOperand(1); |
| 324 | if (!OpOff.isImm() || OpOff.getImm() != 0) |
| 325 | return 0; |
| 326 | FrameIndex = OpFI.getIndex(); |
| 327 | return MI.getOperand(2).getReg(); |
| 328 | } |
Krzysztof Parzyszek | feb65a3 | 2016-02-12 20:54:15 +0000 | [diff] [blame] | 329 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 330 | case Hexagon::S2_pstorerbt_io: |
| 331 | case Hexagon::S2_pstorerbf_io: |
| 332 | case Hexagon::S2_pstorerht_io: |
| 333 | case Hexagon::S2_pstorerhf_io: |
| 334 | case Hexagon::S2_pstorerit_io: |
| 335 | case Hexagon::S2_pstorerif_io: |
| 336 | case Hexagon::S2_pstorerdt_io: |
| 337 | case Hexagon::S2_pstorerdf_io: { |
| 338 | const MachineOperand &OpFI = MI.getOperand(1); |
| 339 | if (!OpFI.isFI()) |
| 340 | return 0; |
| 341 | const MachineOperand &OpOff = MI.getOperand(2); |
| 342 | if (!OpOff.isImm() || OpOff.getImm() != 0) |
| 343 | return 0; |
| 344 | FrameIndex = OpFI.getIndex(); |
| 345 | return MI.getOperand(3).getReg(); |
| 346 | } |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 347 | } |
Krzysztof Parzyszek | feb65a3 | 2016-02-12 20:54:15 +0000 | [diff] [blame] | 348 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 349 | return 0; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 353 | /// This function can analyze one/two way branching only and should (mostly) be |
| 354 | /// called by target independent side. |
| 355 | /// First entry is always the opcode of the branching instruction, except when |
| 356 | /// the Cond vector is supposed to be empty, e.g., when AnalyzeBranch fails, a |
| 357 | /// BB with only unconditional jump. Subsequent entries depend upon the opcode, |
| 358 | /// e.g. Jump_c p will have |
| 359 | /// Cond[0] = Jump_c |
| 360 | /// Cond[1] = p |
| 361 | /// HW-loop ENDLOOP: |
| 362 | /// Cond[0] = ENDLOOP |
| 363 | /// Cond[1] = MBB |
| 364 | /// New value jump: |
| 365 | /// Cond[0] = Hexagon::CMPEQri_f_Jumpnv_t_V4 -- specific opcode |
| 366 | /// Cond[1] = R |
| 367 | /// Cond[2] = Imm |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 368 | /// |
Jacques Pienaar | 71c30a1 | 2016-07-15 14:41:04 +0000 | [diff] [blame] | 369 | bool HexagonInstrInfo::analyzeBranch(MachineBasicBlock &MBB, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 370 | MachineBasicBlock *&TBB, |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 371 | MachineBasicBlock *&FBB, |
| 372 | SmallVectorImpl<MachineOperand> &Cond, |
| 373 | bool AllowModify) const { |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 374 | TBB = nullptr; |
| 375 | FBB = nullptr; |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 376 | Cond.clear(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 377 | |
| 378 | // 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] | 379 | MachineBasicBlock::instr_iterator I = MBB.instr_end(); |
| 380 | if (I == MBB.instr_begin()) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 381 | return false; |
| 382 | |
| 383 | // A basic block may looks like this: |
| 384 | // |
| 385 | // [ insn |
| 386 | // EH_LABEL |
| 387 | // insn |
| 388 | // insn |
| 389 | // insn |
| 390 | // EH_LABEL |
| 391 | // insn ] |
| 392 | // |
| 393 | // It has two succs but does not have a terminator |
| 394 | // Don't know how to handle it. |
| 395 | do { |
| 396 | --I; |
| 397 | if (I->isEHLabel()) |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 398 | // Don't analyze EH branches. |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 399 | return true; |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 400 | } while (I != MBB.instr_begin()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 401 | |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 402 | I = MBB.instr_end(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 403 | --I; |
| 404 | |
| 405 | while (I->isDebugValue()) { |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 406 | if (I == MBB.instr_begin()) |
| 407 | return false; |
| 408 | --I; |
| 409 | } |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 410 | |
Colin LeMahieu | 7b1799c | 2015-03-09 22:05:21 +0000 | [diff] [blame] | 411 | bool JumpToBlock = I->getOpcode() == Hexagon::J2_jump && |
| 412 | I->getOperand(0).isMBB(); |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 413 | // Delete the J2_jump if it's equivalent to a fall-through. |
Colin LeMahieu | 7b1799c | 2015-03-09 22:05:21 +0000 | [diff] [blame] | 414 | if (AllowModify && JumpToBlock && |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 415 | MBB.isLayoutSuccessor(I->getOperand(0).getMBB())) { |
| 416 | DEBUG(dbgs()<< "\nErasing the jump to successor block\n";); |
| 417 | I->eraseFromParent(); |
| 418 | I = MBB.instr_end(); |
| 419 | if (I == MBB.instr_begin()) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 420 | return false; |
| 421 | --I; |
| 422 | } |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 423 | if (!isUnpredicatedTerminator(*I)) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 424 | return false; |
| 425 | |
| 426 | // Get the last instruction in the block. |
Duncan P. N. Exon Smith | a72c6e2 | 2015-10-20 00:46:39 +0000 | [diff] [blame] | 427 | MachineInstr *LastInst = &*I; |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 428 | MachineInstr *SecondLastInst = nullptr; |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 429 | // Find one more terminator if present. |
Duncan P. N. Exon Smith | a72c6e2 | 2015-10-20 00:46:39 +0000 | [diff] [blame] | 430 | for (;;) { |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 431 | if (&*I != LastInst && !I->isBundle() && isUnpredicatedTerminator(*I)) { |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 432 | if (!SecondLastInst) |
Duncan P. N. Exon Smith | a72c6e2 | 2015-10-20 00:46:39 +0000 | [diff] [blame] | 433 | SecondLastInst = &*I; |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 434 | else |
| 435 | // This is a third branch. |
| 436 | return true; |
| 437 | } |
| 438 | if (I == MBB.instr_begin()) |
| 439 | break; |
| 440 | --I; |
Duncan P. N. Exon Smith | a72c6e2 | 2015-10-20 00:46:39 +0000 | [diff] [blame] | 441 | } |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 442 | |
| 443 | int LastOpcode = LastInst->getOpcode(); |
Colin LeMahieu | 7b1799c | 2015-03-09 22:05:21 +0000 | [diff] [blame] | 444 | int SecLastOpcode = SecondLastInst ? SecondLastInst->getOpcode() : 0; |
| 445 | // If the branch target is not a basic block, it could be a tail call. |
| 446 | // (It is, if the target is a function.) |
| 447 | if (LastOpcode == Hexagon::J2_jump && !LastInst->getOperand(0).isMBB()) |
| 448 | return true; |
| 449 | if (SecLastOpcode == Hexagon::J2_jump && |
| 450 | !SecondLastInst->getOperand(0).isMBB()) |
| 451 | return true; |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 452 | |
| 453 | bool LastOpcodeHasJMP_c = PredOpcodeHasJMP_c(LastOpcode); |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 454 | bool LastOpcodeHasNVJump = isNewValueJump(*LastInst); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 455 | |
Krzysztof Parzyszek | b28ae10 | 2016-01-14 15:05:27 +0000 | [diff] [blame] | 456 | if (LastOpcodeHasJMP_c && !LastInst->getOperand(1).isMBB()) |
| 457 | return true; |
| 458 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 459 | // If there is only one terminator instruction, process it. |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 460 | if (LastInst && !SecondLastInst) { |
Colin LeMahieu | db0b13c | 2014-12-10 21:24:10 +0000 | [diff] [blame] | 461 | if (LastOpcode == Hexagon::J2_jump) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 462 | TBB = LastInst->getOperand(0).getMBB(); |
| 463 | return false; |
| 464 | } |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 465 | if (isEndLoopN(LastOpcode)) { |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 466 | TBB = LastInst->getOperand(0).getMBB(); |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 467 | Cond.push_back(MachineOperand::CreateImm(LastInst->getOpcode())); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 468 | Cond.push_back(LastInst->getOperand(0)); |
| 469 | return false; |
| 470 | } |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 471 | if (LastOpcodeHasJMP_c) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 472 | TBB = LastInst->getOperand(1).getMBB(); |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 473 | Cond.push_back(MachineOperand::CreateImm(LastInst->getOpcode())); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 474 | Cond.push_back(LastInst->getOperand(0)); |
| 475 | return false; |
| 476 | } |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 477 | // Only supporting rr/ri versions of new-value jumps. |
| 478 | if (LastOpcodeHasNVJump && (LastInst->getNumExplicitOperands() == 3)) { |
| 479 | TBB = LastInst->getOperand(2).getMBB(); |
| 480 | Cond.push_back(MachineOperand::CreateImm(LastInst->getOpcode())); |
| 481 | Cond.push_back(LastInst->getOperand(0)); |
| 482 | Cond.push_back(LastInst->getOperand(1)); |
| 483 | return false; |
| 484 | } |
| 485 | DEBUG(dbgs() << "\nCant analyze BB#" << MBB.getNumber() |
| 486 | << " with one jump\n";); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 487 | // Otherwise, don't know what this is. |
| 488 | return true; |
| 489 | } |
| 490 | |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 491 | bool SecLastOpcodeHasJMP_c = PredOpcodeHasJMP_c(SecLastOpcode); |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 492 | bool SecLastOpcodeHasNVJump = isNewValueJump(*SecondLastInst); |
Colin LeMahieu | db0b13c | 2014-12-10 21:24:10 +0000 | [diff] [blame] | 493 | if (SecLastOpcodeHasJMP_c && (LastOpcode == Hexagon::J2_jump)) { |
Krzysztof Parzyszek | b28ae10 | 2016-01-14 15:05:27 +0000 | [diff] [blame] | 494 | if (!SecondLastInst->getOperand(1).isMBB()) |
| 495 | return true; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 496 | TBB = SecondLastInst->getOperand(1).getMBB(); |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 497 | Cond.push_back(MachineOperand::CreateImm(SecondLastInst->getOpcode())); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 498 | Cond.push_back(SecondLastInst->getOperand(0)); |
| 499 | FBB = LastInst->getOperand(0).getMBB(); |
| 500 | return false; |
| 501 | } |
| 502 | |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 503 | // Only supporting rr/ri versions of new-value jumps. |
| 504 | if (SecLastOpcodeHasNVJump && |
| 505 | (SecondLastInst->getNumExplicitOperands() == 3) && |
| 506 | (LastOpcode == Hexagon::J2_jump)) { |
| 507 | TBB = SecondLastInst->getOperand(2).getMBB(); |
| 508 | Cond.push_back(MachineOperand::CreateImm(SecondLastInst->getOpcode())); |
| 509 | Cond.push_back(SecondLastInst->getOperand(0)); |
| 510 | Cond.push_back(SecondLastInst->getOperand(1)); |
| 511 | FBB = LastInst->getOperand(0).getMBB(); |
| 512 | return false; |
| 513 | } |
| 514 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 515 | // If the block ends with two Hexagon:JMPs, handle it. The second one is not |
| 516 | // executed, so remove it. |
Colin LeMahieu | db0b13c | 2014-12-10 21:24:10 +0000 | [diff] [blame] | 517 | if (SecLastOpcode == Hexagon::J2_jump && LastOpcode == Hexagon::J2_jump) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 518 | TBB = SecondLastInst->getOperand(0).getMBB(); |
Duncan P. N. Exon Smith | c5b668d | 2016-02-22 20:49:58 +0000 | [diff] [blame] | 519 | I = LastInst->getIterator(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 520 | if (AllowModify) |
| 521 | I->eraseFromParent(); |
| 522 | return false; |
| 523 | } |
| 524 | |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 525 | // If the block ends with an ENDLOOP, and J2_jump, handle it. |
| 526 | if (isEndLoopN(SecLastOpcode) && LastOpcode == Hexagon::J2_jump) { |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 527 | TBB = SecondLastInst->getOperand(0).getMBB(); |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 528 | Cond.push_back(MachineOperand::CreateImm(SecondLastInst->getOpcode())); |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 529 | Cond.push_back(SecondLastInst->getOperand(0)); |
| 530 | FBB = LastInst->getOperand(0).getMBB(); |
| 531 | return false; |
| 532 | } |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 533 | DEBUG(dbgs() << "\nCant analyze BB#" << MBB.getNumber() |
| 534 | << " with two jumps";); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 535 | // Otherwise, can't handle this. |
| 536 | return true; |
| 537 | } |
| 538 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 539 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 540 | unsigned HexagonInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const { |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 541 | DEBUG(dbgs() << "\nRemoving branches out of BB#" << MBB.getNumber()); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 542 | MachineBasicBlock::iterator I = MBB.end(); |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 543 | unsigned Count = 0; |
| 544 | while (I != MBB.begin()) { |
| 545 | --I; |
| 546 | if (I->isDebugValue()) |
| 547 | continue; |
| 548 | // Only removing branches from end of MBB. |
| 549 | if (!I->isBranch()) |
| 550 | return Count; |
| 551 | if (Count && (I->getOpcode() == Hexagon::J2_jump)) |
| 552 | llvm_unreachable("Malformed basic block: unconditional branch not last"); |
| 553 | MBB.erase(&MBB.back()); |
| 554 | I = MBB.end(); |
| 555 | ++Count; |
Krzysztof Parzyszek | 78cc36f | 2015-03-18 15:56:43 +0000 | [diff] [blame] | 556 | } |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 557 | return Count; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 558 | } |
| 559 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 560 | unsigned HexagonInstrInfo::InsertBranch(MachineBasicBlock &MBB, |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 561 | MachineBasicBlock *TBB, |
| 562 | MachineBasicBlock *FBB, |
| 563 | ArrayRef<MachineOperand> Cond, |
| 564 | const DebugLoc &DL) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 565 | unsigned BOpc = Hexagon::J2_jump; |
| 566 | unsigned BccOpc = Hexagon::J2_jumpt; |
| 567 | assert(validateBranchCond(Cond) && "Invalid branching condition"); |
| 568 | assert(TBB && "InsertBranch must not be told to insert a fallthrough"); |
| 569 | |
| 570 | // Check if ReverseBranchCondition has asked to reverse this branch |
| 571 | // If we want to reverse the branch an odd number of times, we want |
| 572 | // J2_jumpf. |
| 573 | if (!Cond.empty() && Cond[0].isImm()) |
| 574 | BccOpc = Cond[0].getImm(); |
| 575 | |
| 576 | if (!FBB) { |
| 577 | if (Cond.empty()) { |
| 578 | // Due to a bug in TailMerging/CFG Optimization, we need to add a |
| 579 | // special case handling of a predicated jump followed by an |
| 580 | // unconditional jump. If not, Tail Merging and CFG Optimization go |
| 581 | // into an infinite loop. |
| 582 | MachineBasicBlock *NewTBB, *NewFBB; |
| 583 | SmallVector<MachineOperand, 4> Cond; |
Duncan P. N. Exon Smith | 25b132e | 2016-07-08 18:26:20 +0000 | [diff] [blame] | 584 | auto Term = MBB.getFirstTerminator(); |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 585 | if (Term != MBB.end() && isPredicated(*Term) && |
Duncan P. N. Exon Smith | e04fe1a | 2016-08-17 00:34:00 +0000 | [diff] [blame] | 586 | !analyzeBranch(MBB, NewTBB, NewFBB, Cond, false) && |
| 587 | MachineFunction::iterator(NewTBB) == ++MBB.getIterator()) { |
| 588 | ReverseBranchCondition(Cond); |
| 589 | RemoveBranch(MBB); |
| 590 | return InsertBranch(MBB, TBB, nullptr, Cond, DL); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 591 | } |
| 592 | BuildMI(&MBB, DL, get(BOpc)).addMBB(TBB); |
| 593 | } else if (isEndLoopN(Cond[0].getImm())) { |
| 594 | int EndLoopOp = Cond[0].getImm(); |
| 595 | assert(Cond[1].isMBB()); |
| 596 | // Since we're adding an ENDLOOP, there better be a LOOP instruction. |
| 597 | // Check for it, and change the BB target if needed. |
| 598 | SmallPtrSet<MachineBasicBlock *, 8> VisitedBBs; |
| 599 | MachineInstr *Loop = findLoopInstr(TBB, EndLoopOp, VisitedBBs); |
| 600 | assert(Loop != 0 && "Inserting an ENDLOOP without a LOOP"); |
| 601 | Loop->getOperand(0).setMBB(TBB); |
| 602 | // Add the ENDLOOP after the finding the LOOP0. |
| 603 | BuildMI(&MBB, DL, get(EndLoopOp)).addMBB(TBB); |
| 604 | } else if (isNewValueJump(Cond[0].getImm())) { |
| 605 | assert((Cond.size() == 3) && "Only supporting rr/ri version of nvjump"); |
| 606 | // New value jump |
| 607 | // (ins IntRegs:$src1, IntRegs:$src2, brtarget:$offset) |
| 608 | // (ins IntRegs:$src1, u5Imm:$src2, brtarget:$offset) |
| 609 | unsigned Flags1 = getUndefRegState(Cond[1].isUndef()); |
| 610 | DEBUG(dbgs() << "\nInserting NVJump for BB#" << MBB.getNumber();); |
| 611 | if (Cond[2].isReg()) { |
| 612 | unsigned Flags2 = getUndefRegState(Cond[2].isUndef()); |
| 613 | BuildMI(&MBB, DL, get(BccOpc)).addReg(Cond[1].getReg(), Flags1). |
| 614 | addReg(Cond[2].getReg(), Flags2).addMBB(TBB); |
| 615 | } else if(Cond[2].isImm()) { |
| 616 | BuildMI(&MBB, DL, get(BccOpc)).addReg(Cond[1].getReg(), Flags1). |
| 617 | addImm(Cond[2].getImm()).addMBB(TBB); |
| 618 | } else |
| 619 | llvm_unreachable("Invalid condition for branching"); |
| 620 | } else { |
| 621 | assert((Cond.size() == 2) && "Malformed cond vector"); |
| 622 | const MachineOperand &RO = Cond[1]; |
| 623 | unsigned Flags = getUndefRegState(RO.isUndef()); |
| 624 | BuildMI(&MBB, DL, get(BccOpc)).addReg(RO.getReg(), Flags).addMBB(TBB); |
| 625 | } |
| 626 | return 1; |
Krzysztof Parzyszek | cfe285e | 2013-02-11 20:04:29 +0000 | [diff] [blame] | 627 | } |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 628 | assert((!Cond.empty()) && |
| 629 | "Cond. cannot be empty when multiple branchings are required"); |
| 630 | assert((!isNewValueJump(Cond[0].getImm())) && |
| 631 | "NV-jump cannot be inserted with another branch"); |
| 632 | // Special case for hardware loops. The condition is a basic block. |
| 633 | if (isEndLoopN(Cond[0].getImm())) { |
| 634 | int EndLoopOp = Cond[0].getImm(); |
| 635 | assert(Cond[1].isMBB()); |
| 636 | // Since we're adding an ENDLOOP, there better be a LOOP instruction. |
| 637 | // Check for it, and change the BB target if needed. |
| 638 | SmallPtrSet<MachineBasicBlock *, 8> VisitedBBs; |
| 639 | MachineInstr *Loop = findLoopInstr(TBB, EndLoopOp, VisitedBBs); |
| 640 | assert(Loop != 0 && "Inserting an ENDLOOP without a LOOP"); |
| 641 | Loop->getOperand(0).setMBB(TBB); |
| 642 | // Add the ENDLOOP after the finding the LOOP0. |
| 643 | BuildMI(&MBB, DL, get(EndLoopOp)).addMBB(TBB); |
| 644 | } else { |
| 645 | const MachineOperand &RO = Cond[1]; |
| 646 | unsigned Flags = getUndefRegState(RO.isUndef()); |
| 647 | BuildMI(&MBB, DL, get(BccOpc)).addReg(RO.getReg(), Flags).addMBB(TBB); |
Krzysztof Parzyszek | cfe285e | 2013-02-11 20:04:29 +0000 | [diff] [blame] | 648 | } |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 649 | BuildMI(&MBB, DL, get(BOpc)).addMBB(FBB); |
Krzysztof Parzyszek | cfe285e | 2013-02-11 20:04:29 +0000 | [diff] [blame] | 650 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 651 | return 2; |
| 652 | } |
| 653 | |
Brendon Cahoon | 254f889 | 2016-07-29 16:44:44 +0000 | [diff] [blame] | 654 | /// Analyze the loop code to find the loop induction variable and compare used |
| 655 | /// to compute the number of iterations. Currently, we analyze loop that are |
| 656 | /// controlled using hardware loops. In this case, the induction variable |
| 657 | /// instruction is null. For all other cases, this function returns true, which |
| 658 | /// means we're unable to analyze it. |
| 659 | bool HexagonInstrInfo::analyzeLoop(MachineLoop &L, |
| 660 | MachineInstr *&IndVarInst, |
| 661 | MachineInstr *&CmpInst) const { |
| 662 | |
| 663 | MachineBasicBlock *LoopEnd = L.getBottomBlock(); |
| 664 | MachineBasicBlock::iterator I = LoopEnd->getFirstTerminator(); |
| 665 | // We really "analyze" only hardware loops right now. |
| 666 | if (I != LoopEnd->end() && isEndLoopN(I->getOpcode())) { |
| 667 | IndVarInst = nullptr; |
| 668 | CmpInst = &*I; |
| 669 | return false; |
| 670 | } |
| 671 | return true; |
| 672 | } |
| 673 | |
| 674 | /// Generate code to reduce the loop iteration by one and check if the loop is |
| 675 | /// finished. Return the value/register of the new loop count. this function |
| 676 | /// assumes the nth iteration is peeled first. |
| 677 | unsigned HexagonInstrInfo::reduceLoopCount(MachineBasicBlock &MBB, |
Krzysztof Parzyszek | 8fb181c | 2016-08-01 17:55:48 +0000 | [diff] [blame] | 678 | MachineInstr *IndVar, MachineInstr &Cmp, |
Brendon Cahoon | 254f889 | 2016-07-29 16:44:44 +0000 | [diff] [blame] | 679 | SmallVectorImpl<MachineOperand> &Cond, |
| 680 | SmallVectorImpl<MachineInstr *> &PrevInsts, |
| 681 | unsigned Iter, unsigned MaxIter) const { |
| 682 | // We expect a hardware loop currently. This means that IndVar is set |
| 683 | // to null, and the compare is the ENDLOOP instruction. |
Krzysztof Parzyszek | 8fb181c | 2016-08-01 17:55:48 +0000 | [diff] [blame] | 684 | assert((!IndVar) && isEndLoopN(Cmp.getOpcode()) |
Brendon Cahoon | 254f889 | 2016-07-29 16:44:44 +0000 | [diff] [blame] | 685 | && "Expecting a hardware loop"); |
| 686 | MachineFunction *MF = MBB.getParent(); |
Krzysztof Parzyszek | 8fb181c | 2016-08-01 17:55:48 +0000 | [diff] [blame] | 687 | DebugLoc DL = Cmp.getDebugLoc(); |
Brendon Cahoon | 254f889 | 2016-07-29 16:44:44 +0000 | [diff] [blame] | 688 | SmallPtrSet<MachineBasicBlock *, 8> VisitedBBs; |
Krzysztof Parzyszek | 8fb181c | 2016-08-01 17:55:48 +0000 | [diff] [blame] | 689 | MachineInstr *Loop = findLoopInstr(&MBB, Cmp.getOpcode(), VisitedBBs); |
Brendon Cahoon | 254f889 | 2016-07-29 16:44:44 +0000 | [diff] [blame] | 690 | if (!Loop) |
| 691 | return 0; |
| 692 | // If the loop trip count is a compile-time value, then just change the |
| 693 | // value. |
| 694 | if (Loop->getOpcode() == Hexagon::J2_loop0i || |
| 695 | Loop->getOpcode() == Hexagon::J2_loop1i) { |
| 696 | int64_t Offset = Loop->getOperand(1).getImm(); |
| 697 | if (Offset <= 1) |
| 698 | Loop->eraseFromParent(); |
| 699 | else |
| 700 | Loop->getOperand(1).setImm(Offset - 1); |
| 701 | return Offset - 1; |
| 702 | } |
| 703 | // The loop trip count is a run-time value. We generate code to subtract |
| 704 | // one from the trip count, and update the loop instruction. |
| 705 | assert(Loop->getOpcode() == Hexagon::J2_loop0r && "Unexpected instruction"); |
| 706 | unsigned LoopCount = Loop->getOperand(1).getReg(); |
| 707 | // Check if we're done with the loop. |
| 708 | unsigned LoopEnd = createVR(MF, MVT::i1); |
| 709 | MachineInstr *NewCmp = BuildMI(&MBB, DL, get(Hexagon::C2_cmpgtui), LoopEnd). |
| 710 | addReg(LoopCount).addImm(1); |
| 711 | unsigned NewLoopCount = createVR(MF, MVT::i32); |
| 712 | MachineInstr *NewAdd = BuildMI(&MBB, DL, get(Hexagon::A2_addi), NewLoopCount). |
| 713 | addReg(LoopCount).addImm(-1); |
| 714 | // Update the previously generated instructions with the new loop counter. |
| 715 | for (SmallVectorImpl<MachineInstr *>::iterator I = PrevInsts.begin(), |
| 716 | E = PrevInsts.end(); I != E; ++I) |
| 717 | (*I)->substituteRegister(LoopCount, NewLoopCount, 0, getRegisterInfo()); |
| 718 | PrevInsts.clear(); |
| 719 | PrevInsts.push_back(NewCmp); |
| 720 | PrevInsts.push_back(NewAdd); |
| 721 | // Insert the new loop instruction if this is the last time the loop is |
| 722 | // decremented. |
| 723 | if (Iter == MaxIter) |
| 724 | BuildMI(&MBB, DL, get(Hexagon::J2_loop0r)). |
| 725 | addMBB(Loop->getOperand(0).getMBB()).addReg(NewLoopCount); |
| 726 | // Delete the old loop instruction. |
| 727 | if (Iter == 0) |
| 728 | Loop->eraseFromParent(); |
| 729 | Cond.push_back(MachineOperand::CreateImm(Hexagon::J2_jumpf)); |
| 730 | Cond.push_back(NewCmp->getOperand(0)); |
| 731 | return NewLoopCount; |
| 732 | } |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 733 | |
| 734 | bool HexagonInstrInfo::isProfitableToIfCvt(MachineBasicBlock &MBB, |
| 735 | unsigned NumCycles, unsigned ExtraPredCycles, |
| 736 | BranchProbability Probability) const { |
| 737 | return nonDbgBBSize(&MBB) <= 3; |
| 738 | } |
| 739 | |
| 740 | |
| 741 | bool HexagonInstrInfo::isProfitableToIfCvt(MachineBasicBlock &TMBB, |
| 742 | unsigned NumTCycles, unsigned ExtraTCycles, MachineBasicBlock &FMBB, |
| 743 | unsigned NumFCycles, unsigned ExtraFCycles, BranchProbability Probability) |
| 744 | const { |
| 745 | return nonDbgBBSize(&TMBB) <= 3 && nonDbgBBSize(&FMBB) <= 3; |
| 746 | } |
| 747 | |
| 748 | |
| 749 | bool HexagonInstrInfo::isProfitableToDupForIfCvt(MachineBasicBlock &MBB, |
| 750 | unsigned NumInstrs, BranchProbability Probability) const { |
| 751 | return NumInstrs <= 4; |
Krzysztof Parzyszek | cfe285e | 2013-02-11 20:04:29 +0000 | [diff] [blame] | 752 | } |
| 753 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 754 | void HexagonInstrInfo::copyPhysReg(MachineBasicBlock &MBB, |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 755 | MachineBasicBlock::iterator I, |
| 756 | const DebugLoc &DL, unsigned DestReg, |
| 757 | unsigned SrcReg, bool KillSrc) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 758 | auto &HRI = getRegisterInfo(); |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 759 | unsigned KillFlag = getKillRegState(KillSrc); |
| 760 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 761 | if (Hexagon::IntRegsRegClass.contains(SrcReg, DestReg)) { |
Krzysztof Parzyszek | 3d6fc83 | 2016-06-02 14:33:08 +0000 | [diff] [blame] | 762 | BuildMI(MBB, I, DL, get(Hexagon::A2_tfr), DestReg) |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 763 | .addReg(SrcReg, KillFlag); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 764 | return; |
| 765 | } |
| 766 | if (Hexagon::DoubleRegsRegClass.contains(SrcReg, DestReg)) { |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 767 | BuildMI(MBB, I, DL, get(Hexagon::A2_tfrp), DestReg) |
| 768 | .addReg(SrcReg, KillFlag); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 769 | return; |
| 770 | } |
| 771 | if (Hexagon::PredRegsRegClass.contains(SrcReg, DestReg)) { |
| 772 | // Map Pd = Ps to Pd = or(Ps, Ps). |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 773 | BuildMI(MBB, I, DL, get(Hexagon::C2_or), DestReg) |
| 774 | .addReg(SrcReg).addReg(SrcReg, KillFlag); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 775 | return; |
| 776 | } |
Colin LeMahieu | 402f772 | 2014-12-19 18:56:10 +0000 | [diff] [blame] | 777 | if (Hexagon::CtrRegsRegClass.contains(DestReg) && |
Sirish Pande | 8bb9745 | 2012-05-12 05:54:15 +0000 | [diff] [blame] | 778 | Hexagon::IntRegsRegClass.contains(SrcReg)) { |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 779 | BuildMI(MBB, I, DL, get(Hexagon::A2_tfrrcr), DestReg) |
| 780 | .addReg(SrcReg, KillFlag); |
| 781 | return; |
| 782 | } |
| 783 | if (Hexagon::IntRegsRegClass.contains(DestReg) && |
| 784 | Hexagon::CtrRegsRegClass.contains(SrcReg)) { |
| 785 | BuildMI(MBB, I, DL, get(Hexagon::A2_tfrcrr), DestReg) |
| 786 | .addReg(SrcReg, KillFlag); |
| 787 | return; |
| 788 | } |
| 789 | if (Hexagon::ModRegsRegClass.contains(DestReg) && |
| 790 | Hexagon::IntRegsRegClass.contains(SrcReg)) { |
| 791 | BuildMI(MBB, I, DL, get(Hexagon::A2_tfrrcr), DestReg) |
| 792 | .addReg(SrcReg, KillFlag); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 793 | return; |
Sirish Pande | 30804c2 | 2012-02-15 18:52:27 +0000 | [diff] [blame] | 794 | } |
Anshuman Dasgupta | e96f804 | 2013-02-13 22:56:34 +0000 | [diff] [blame] | 795 | if (Hexagon::PredRegsRegClass.contains(SrcReg) && |
| 796 | Hexagon::IntRegsRegClass.contains(DestReg)) { |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 797 | BuildMI(MBB, I, DL, get(Hexagon::C2_tfrpr), DestReg) |
| 798 | .addReg(SrcReg, KillFlag); |
Anshuman Dasgupta | e96f804 | 2013-02-13 22:56:34 +0000 | [diff] [blame] | 799 | return; |
| 800 | } |
| 801 | if (Hexagon::IntRegsRegClass.contains(SrcReg) && |
| 802 | Hexagon::PredRegsRegClass.contains(DestReg)) { |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 803 | BuildMI(MBB, I, DL, get(Hexagon::C2_tfrrp), DestReg) |
| 804 | .addReg(SrcReg, KillFlag); |
Anshuman Dasgupta | e96f804 | 2013-02-13 22:56:34 +0000 | [diff] [blame] | 805 | return; |
| 806 | } |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 807 | if (Hexagon::PredRegsRegClass.contains(SrcReg) && |
| 808 | Hexagon::IntRegsRegClass.contains(DestReg)) { |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 809 | BuildMI(MBB, I, DL, get(Hexagon::C2_tfrpr), DestReg) |
| 810 | .addReg(SrcReg, KillFlag); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 811 | return; |
| 812 | } |
| 813 | if (Hexagon::VectorRegsRegClass.contains(SrcReg, DestReg)) { |
| 814 | BuildMI(MBB, I, DL, get(Hexagon::V6_vassign), DestReg). |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 815 | addReg(SrcReg, KillFlag); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 816 | return; |
| 817 | } |
| 818 | if (Hexagon::VecDblRegsRegClass.contains(SrcReg, DestReg)) { |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 819 | BuildMI(MBB, I, DL, get(Hexagon::V6_vcombine), DestReg) |
| 820 | .addReg(HRI.getSubReg(SrcReg, Hexagon::subreg_hireg), KillFlag) |
| 821 | .addReg(HRI.getSubReg(SrcReg, Hexagon::subreg_loreg), KillFlag); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 822 | return; |
| 823 | } |
| 824 | if (Hexagon::VecPredRegsRegClass.contains(SrcReg, DestReg)) { |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 825 | BuildMI(MBB, I, DL, get(Hexagon::V6_pred_and), DestReg) |
| 826 | .addReg(SrcReg) |
| 827 | .addReg(SrcReg, KillFlag); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 828 | return; |
| 829 | } |
| 830 | if (Hexagon::VecPredRegsRegClass.contains(SrcReg) && |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 831 | Hexagon::VectorRegsRegClass.contains(DestReg)) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 832 | llvm_unreachable("Unimplemented pred to vec"); |
| 833 | return; |
| 834 | } |
| 835 | if (Hexagon::VecPredRegsRegClass.contains(DestReg) && |
| 836 | Hexagon::VectorRegsRegClass.contains(SrcReg)) { |
| 837 | llvm_unreachable("Unimplemented vec to pred"); |
| 838 | return; |
| 839 | } |
| 840 | if (Hexagon::VecPredRegs128BRegClass.contains(SrcReg, DestReg)) { |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 841 | unsigned DstHi = HRI.getSubReg(DestReg, Hexagon::subreg_hireg); |
| 842 | BuildMI(MBB, I, DL, get(Hexagon::V6_pred_and), DstHi) |
| 843 | .addReg(HRI.getSubReg(SrcReg, Hexagon::subreg_hireg), KillFlag); |
| 844 | unsigned DstLo = HRI.getSubReg(DestReg, Hexagon::subreg_loreg); |
| 845 | BuildMI(MBB, I, DL, get(Hexagon::V6_pred_and), DstLo) |
| 846 | .addReg(HRI.getSubReg(SrcReg, Hexagon::subreg_loreg), KillFlag); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 847 | return; |
| 848 | } |
Sirish Pande | 30804c2 | 2012-02-15 18:52:27 +0000 | [diff] [blame] | 849 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 850 | #ifndef NDEBUG |
| 851 | // Show the invalid registers to ease debugging. |
| 852 | dbgs() << "Invalid registers for copy in BB#" << MBB.getNumber() |
| 853 | << ": " << PrintReg(DestReg, &HRI) |
| 854 | << " = " << PrintReg(SrcReg, &HRI) << '\n'; |
| 855 | #endif |
Sirish Pande | 30804c2 | 2012-02-15 18:52:27 +0000 | [diff] [blame] | 856 | llvm_unreachable("Unimplemented"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 860 | void HexagonInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB, |
| 861 | MachineBasicBlock::iterator I, unsigned SrcReg, bool isKill, int FI, |
| 862 | const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 863 | DebugLoc DL = MBB.findDebugLoc(I); |
| 864 | MachineFunction &MF = *MBB.getParent(); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 865 | MachineFrameInfo &MFI = MF.getFrameInfo(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 866 | unsigned Align = MFI.getObjectAlignment(FI); |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 867 | unsigned KillFlag = getKillRegState(isKill); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 868 | |
Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 869 | MachineMemOperand *MMO = MF.getMachineMemOperand( |
| 870 | MachinePointerInfo::getFixedStack(MF, FI), MachineMemOperand::MOStore, |
| 871 | MFI.getObjectSize(FI), Align); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 872 | |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 873 | if (Hexagon::IntRegsRegClass.hasSubClassEq(RC)) { |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 874 | BuildMI(MBB, I, DL, get(Hexagon::S2_storeri_io)) |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 875 | .addFrameIndex(FI).addImm(0) |
| 876 | .addReg(SrcReg, KillFlag).addMemOperand(MMO); |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 877 | } else if (Hexagon::DoubleRegsRegClass.hasSubClassEq(RC)) { |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 878 | BuildMI(MBB, I, DL, get(Hexagon::S2_storerd_io)) |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 879 | .addFrameIndex(FI).addImm(0) |
| 880 | .addReg(SrcReg, KillFlag).addMemOperand(MMO); |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 881 | } else if (Hexagon::PredRegsRegClass.hasSubClassEq(RC)) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 882 | BuildMI(MBB, I, DL, get(Hexagon::STriw_pred)) |
Krzysztof Parzyszek | 7b413c6 | 2016-01-22 19:15:58 +0000 | [diff] [blame] | 883 | .addFrameIndex(FI).addImm(0) |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 884 | .addReg(SrcReg, KillFlag).addMemOperand(MMO); |
Krzysztof Parzyszek | 7b413c6 | 2016-01-22 19:15:58 +0000 | [diff] [blame] | 885 | } else if (Hexagon::ModRegsRegClass.hasSubClassEq(RC)) { |
| 886 | BuildMI(MBB, I, DL, get(Hexagon::STriw_mod)) |
| 887 | .addFrameIndex(FI).addImm(0) |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 888 | .addReg(SrcReg, KillFlag).addMemOperand(MMO); |
| 889 | } else if (Hexagon::VecPredRegs128BRegClass.hasSubClassEq(RC)) { |
Krzysztof Parzyszek | 17aa413 | 2016-08-16 15:43:54 +0000 | [diff] [blame] | 890 | BuildMI(MBB, I, DL, get(Hexagon::PS_vstorerq_ai_128B)) |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 891 | .addFrameIndex(FI).addImm(0) |
| 892 | .addReg(SrcReg, KillFlag).addMemOperand(MMO); |
| 893 | } else if (Hexagon::VecPredRegsRegClass.hasSubClassEq(RC)) { |
Krzysztof Parzyszek | 17aa413 | 2016-08-16 15:43:54 +0000 | [diff] [blame] | 894 | BuildMI(MBB, I, DL, get(Hexagon::PS_vstorerq_ai)) |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 895 | .addFrameIndex(FI).addImm(0) |
| 896 | .addReg(SrcReg, KillFlag).addMemOperand(MMO); |
| 897 | } else if (Hexagon::VectorRegs128BRegClass.hasSubClassEq(RC)) { |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 898 | unsigned Opc = Align < 128 ? Hexagon::V6_vS32Ub_ai_128B |
| 899 | : Hexagon::V6_vS32b_ai_128B; |
| 900 | BuildMI(MBB, I, DL, get(Opc)) |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 901 | .addFrameIndex(FI).addImm(0) |
| 902 | .addReg(SrcReg, KillFlag).addMemOperand(MMO); |
| 903 | } else if (Hexagon::VectorRegsRegClass.hasSubClassEq(RC)) { |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 904 | unsigned Opc = Align < 64 ? Hexagon::V6_vS32Ub_ai |
| 905 | : Hexagon::V6_vS32b_ai; |
| 906 | BuildMI(MBB, I, DL, get(Opc)) |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 907 | .addFrameIndex(FI).addImm(0) |
| 908 | .addReg(SrcReg, KillFlag).addMemOperand(MMO); |
| 909 | } else if (Hexagon::VecDblRegsRegClass.hasSubClassEq(RC)) { |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 910 | unsigned Opc = Align < 64 ? Hexagon::PS_vstorerwu_ai |
| 911 | : Hexagon::PS_vstorerw_ai; |
| 912 | BuildMI(MBB, I, DL, get(Opc)) |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 913 | .addFrameIndex(FI).addImm(0) |
| 914 | .addReg(SrcReg, KillFlag).addMemOperand(MMO); |
| 915 | } else if (Hexagon::VecDblRegs128BRegClass.hasSubClassEq(RC)) { |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 916 | unsigned Opc = Align < 128 ? Hexagon::PS_vstorerwu_ai_128B |
| 917 | : Hexagon::PS_vstorerw_ai_128B; |
| 918 | BuildMI(MBB, I, DL, get(Opc)) |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 919 | .addFrameIndex(FI).addImm(0) |
| 920 | .addReg(SrcReg, KillFlag).addMemOperand(MMO); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 921 | } else { |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 922 | llvm_unreachable("Unimplemented"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 923 | } |
| 924 | } |
| 925 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 926 | void HexagonInstrInfo::loadRegFromStackSlot( |
| 927 | MachineBasicBlock &MBB, MachineBasicBlock::iterator I, unsigned DestReg, |
| 928 | int FI, const TargetRegisterClass *RC, |
| 929 | const TargetRegisterInfo *TRI) const { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 930 | DebugLoc DL = MBB.findDebugLoc(I); |
| 931 | MachineFunction &MF = *MBB.getParent(); |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 932 | MachineFrameInfo &MFI = MF.getFrameInfo(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 933 | unsigned Align = MFI.getObjectAlignment(FI); |
| 934 | |
Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 935 | MachineMemOperand *MMO = MF.getMachineMemOperand( |
| 936 | MachinePointerInfo::getFixedStack(MF, FI), MachineMemOperand::MOLoad, |
| 937 | MFI.getObjectSize(FI), Align); |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 938 | |
Krzysztof Parzyszek | 7b413c6 | 2016-01-22 19:15:58 +0000 | [diff] [blame] | 939 | if (Hexagon::IntRegsRegClass.hasSubClassEq(RC)) { |
Colin LeMahieu | 026e88d | 2014-12-23 20:02:16 +0000 | [diff] [blame] | 940 | BuildMI(MBB, I, DL, get(Hexagon::L2_loadri_io), DestReg) |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 941 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO); |
Krzysztof Parzyszek | 7b413c6 | 2016-01-22 19:15:58 +0000 | [diff] [blame] | 942 | } else if (Hexagon::DoubleRegsRegClass.hasSubClassEq(RC)) { |
Colin LeMahieu | 947cd70 | 2014-12-23 20:44:59 +0000 | [diff] [blame] | 943 | BuildMI(MBB, I, DL, get(Hexagon::L2_loadrd_io), DestReg) |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 944 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO); |
Krzysztof Parzyszek | 7b413c6 | 2016-01-22 19:15:58 +0000 | [diff] [blame] | 945 | } else if (Hexagon::PredRegsRegClass.hasSubClassEq(RC)) { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 946 | BuildMI(MBB, I, DL, get(Hexagon::LDriw_pred), DestReg) |
Krzysztof Parzyszek | 7b413c6 | 2016-01-22 19:15:58 +0000 | [diff] [blame] | 947 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO); |
| 948 | } else if (Hexagon::ModRegsRegClass.hasSubClassEq(RC)) { |
| 949 | BuildMI(MBB, I, DL, get(Hexagon::LDriw_mod), DestReg) |
| 950 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO); |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 951 | } else if (Hexagon::VecPredRegs128BRegClass.hasSubClassEq(RC)) { |
Krzysztof Parzyszek | 17aa413 | 2016-08-16 15:43:54 +0000 | [diff] [blame] | 952 | BuildMI(MBB, I, DL, get(Hexagon::PS_vloadrq_ai_128B), DestReg) |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 953 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO); |
| 954 | } else if (Hexagon::VecPredRegsRegClass.hasSubClassEq(RC)) { |
Krzysztof Parzyszek | 17aa413 | 2016-08-16 15:43:54 +0000 | [diff] [blame] | 955 | BuildMI(MBB, I, DL, get(Hexagon::PS_vloadrq_ai), DestReg) |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 956 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO); |
| 957 | } else if (Hexagon::VecDblRegs128BRegClass.hasSubClassEq(RC)) { |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 958 | unsigned Opc = Align < 128 ? Hexagon::PS_vloadrwu_ai_128B |
| 959 | : Hexagon::PS_vloadrw_ai_128B; |
| 960 | BuildMI(MBB, I, DL, get(Opc), DestReg) |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 961 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO); |
| 962 | } else if (Hexagon::VectorRegs128BRegClass.hasSubClassEq(RC)) { |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 963 | unsigned Opc = Align < 128 ? Hexagon::V6_vL32Ub_ai_128B |
| 964 | : Hexagon::V6_vL32b_ai_128B; |
| 965 | BuildMI(MBB, I, DL, get(Opc), DestReg) |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 966 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO); |
| 967 | } else if (Hexagon::VectorRegsRegClass.hasSubClassEq(RC)) { |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 968 | unsigned Opc = Align < 64 ? Hexagon::V6_vL32Ub_ai |
| 969 | : Hexagon::V6_vL32b_ai; |
| 970 | BuildMI(MBB, I, DL, get(Opc), DestReg) |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 971 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO); |
| 972 | } else if (Hexagon::VecDblRegsRegClass.hasSubClassEq(RC)) { |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 973 | unsigned Opc = Align < 64 ? Hexagon::PS_vloadrwu_ai |
| 974 | : Hexagon::PS_vloadrw_ai; |
| 975 | BuildMI(MBB, I, DL, get(Opc), DestReg) |
Krzysztof Parzyszek | 79a886b | 2016-02-12 21:56:41 +0000 | [diff] [blame] | 976 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 977 | } else { |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 978 | llvm_unreachable("Can't store this register to stack slot"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 979 | } |
| 980 | } |
| 981 | |
| 982 | |
Ron Lieberman | 88159e5 | 2016-09-02 22:56:24 +0000 | [diff] [blame^] | 983 | static void getLiveRegsAt(LivePhysRegs &Regs, const MachineInstr &MI) { |
| 984 | const MachineBasicBlock &B = *MI.getParent(); |
| 985 | Regs.addLiveOuts(B); |
| 986 | auto E = MachineBasicBlock::const_reverse_iterator(MI.getIterator()); |
| 987 | for (auto I = B.rbegin(); I != E; ++I) |
| 988 | Regs.stepBackward(*I); |
| 989 | } |
| 990 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 991 | /// expandPostRAPseudo - This function is called for all pseudo instructions |
| 992 | /// that remain after register allocation. Many pseudo instructions are |
| 993 | /// created to help register allocation. This is the place to convert them |
| 994 | /// into real instructions. The target can edit MI in place, or it can insert |
| 995 | /// new instructions and erase MI. The function should return true if |
| 996 | /// anything was changed. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 997 | bool HexagonInstrInfo::expandPostRAPseudo(MachineInstr &MI) const { |
Krzysztof Parzyszek | fb33824 | 2015-10-06 15:49:14 +0000 | [diff] [blame] | 998 | const HexagonRegisterInfo &HRI = getRegisterInfo(); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 999 | MachineRegisterInfo &MRI = MI.getParent()->getParent()->getRegInfo(); |
| 1000 | MachineBasicBlock &MBB = *MI.getParent(); |
| 1001 | DebugLoc DL = MI.getDebugLoc(); |
| 1002 | unsigned Opc = MI.getOpcode(); |
Krzysztof Parzyszek | 195dc8d | 2015-11-26 04:33:11 +0000 | [diff] [blame] | 1003 | const unsigned VecOffset = 1; |
Colin LeMahieu | 7b1799c | 2015-03-09 22:05:21 +0000 | [diff] [blame] | 1004 | |
| 1005 | switch (Opc) { |
Krzysztof Parzyszek | 3d6fc83 | 2016-06-02 14:33:08 +0000 | [diff] [blame] | 1006 | case TargetOpcode::COPY: { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1007 | MachineOperand &MD = MI.getOperand(0); |
| 1008 | MachineOperand &MS = MI.getOperand(1); |
| 1009 | MachineBasicBlock::iterator MBBI = MI.getIterator(); |
Krzysztof Parzyszek | 3d6fc83 | 2016-06-02 14:33:08 +0000 | [diff] [blame] | 1010 | if (MD.getReg() != MS.getReg() && !MS.isUndef()) { |
| 1011 | copyPhysReg(MBB, MI, DL, MD.getReg(), MS.getReg(), MS.isKill()); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1012 | std::prev(MBBI)->copyImplicitOps(*MBB.getParent(), MI); |
Krzysztof Parzyszek | 3d6fc83 | 2016-06-02 14:33:08 +0000 | [diff] [blame] | 1013 | } |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1014 | MBB.erase(MBBI); |
Krzysztof Parzyszek | 3d6fc83 | 2016-06-02 14:33:08 +0000 | [diff] [blame] | 1015 | return true; |
| 1016 | } |
Krzysztof Parzyszek | 1d01a79 | 2016-08-16 18:08:40 +0000 | [diff] [blame] | 1017 | case Hexagon::PS_aligna: |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1018 | BuildMI(MBB, MI, DL, get(Hexagon::A2_andir), MI.getOperand(0).getReg()) |
Krzysztof Parzyszek | fb33824 | 2015-10-06 15:49:14 +0000 | [diff] [blame] | 1019 | .addReg(HRI.getFrameRegister()) |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1020 | .addImm(-MI.getOperand(1).getImm()); |
Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 1021 | MBB.erase(MI); |
| 1022 | return true; |
Krzysztof Parzyszek | eabc0d0 | 2016-08-16 17:14:44 +0000 | [diff] [blame] | 1023 | case Hexagon::V6_vassignp_128B: |
| 1024 | case Hexagon::V6_vassignp: { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1025 | unsigned SrcReg = MI.getOperand(1).getReg(); |
| 1026 | unsigned DstReg = MI.getOperand(0).getReg(); |
Krzysztof Parzyszek | eabc0d0 | 2016-08-16 17:14:44 +0000 | [diff] [blame] | 1027 | unsigned Kill = getKillRegState(MI.getOperand(1).isKill()); |
| 1028 | BuildMI(MBB, MI, DL, get(Hexagon::V6_vcombine), DstReg) |
| 1029 | .addReg(HRI.getSubReg(SrcReg, Hexagon::subreg_hireg), Kill) |
| 1030 | .addReg(HRI.getSubReg(SrcReg, Hexagon::subreg_loreg), Kill); |
Krzysztof Parzyszek | 4eb6d4d | 2015-11-26 16:54:33 +0000 | [diff] [blame] | 1031 | MBB.erase(MI); |
| 1032 | return true; |
| 1033 | } |
Krzysztof Parzyszek | eabc0d0 | 2016-08-16 17:14:44 +0000 | [diff] [blame] | 1034 | case Hexagon::V6_lo_128B: |
| 1035 | case Hexagon::V6_lo: { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1036 | unsigned SrcReg = MI.getOperand(1).getReg(); |
| 1037 | unsigned DstReg = MI.getOperand(0).getReg(); |
Krzysztof Parzyszek | 4eb6d4d | 2015-11-26 16:54:33 +0000 | [diff] [blame] | 1038 | unsigned SrcSubLo = HRI.getSubReg(SrcReg, Hexagon::subreg_loreg); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1039 | copyPhysReg(MBB, MI, DL, DstReg, SrcSubLo, MI.getOperand(1).isKill()); |
Krzysztof Parzyszek | 4eb6d4d | 2015-11-26 16:54:33 +0000 | [diff] [blame] | 1040 | MBB.erase(MI); |
| 1041 | MRI.clearKillFlags(SrcSubLo); |
| 1042 | return true; |
| 1043 | } |
Krzysztof Parzyszek | eabc0d0 | 2016-08-16 17:14:44 +0000 | [diff] [blame] | 1044 | case Hexagon::V6_hi_128B: |
| 1045 | case Hexagon::V6_hi: { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1046 | unsigned SrcReg = MI.getOperand(1).getReg(); |
| 1047 | unsigned DstReg = MI.getOperand(0).getReg(); |
Krzysztof Parzyszek | 4eb6d4d | 2015-11-26 16:54:33 +0000 | [diff] [blame] | 1048 | unsigned SrcSubHi = HRI.getSubReg(SrcReg, Hexagon::subreg_hireg); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1049 | copyPhysReg(MBB, MI, DL, DstReg, SrcSubHi, MI.getOperand(1).isKill()); |
Krzysztof Parzyszek | 4eb6d4d | 2015-11-26 16:54:33 +0000 | [diff] [blame] | 1050 | MBB.erase(MI); |
| 1051 | MRI.clearKillFlags(SrcSubHi); |
| 1052 | return true; |
| 1053 | } |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 1054 | case Hexagon::PS_vstorerw_ai: |
| 1055 | case Hexagon::PS_vstorerwu_ai: |
| 1056 | case Hexagon::PS_vstorerw_ai_128B: |
| 1057 | case Hexagon::PS_vstorerwu_ai_128B: { |
| 1058 | bool Is128B = (Opc == Hexagon::PS_vstorerw_ai_128B || |
| 1059 | Opc == Hexagon::PS_vstorerwu_ai_128B); |
| 1060 | bool Aligned = (Opc == Hexagon::PS_vstorerw_ai || |
| 1061 | Opc == Hexagon::PS_vstorerw_ai_128B); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1062 | unsigned SrcReg = MI.getOperand(2).getReg(); |
Krzysztof Parzyszek | 195dc8d | 2015-11-26 04:33:11 +0000 | [diff] [blame] | 1063 | unsigned SrcSubHi = HRI.getSubReg(SrcReg, Hexagon::subreg_hireg); |
| 1064 | unsigned SrcSubLo = HRI.getSubReg(SrcReg, Hexagon::subreg_loreg); |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 1065 | unsigned NewOpc; |
| 1066 | if (Aligned) |
| 1067 | NewOpc = Is128B ? Hexagon::V6_vS32b_ai_128B |
| 1068 | : Hexagon::V6_vS32b_ai; |
| 1069 | else |
| 1070 | NewOpc = Is128B ? Hexagon::V6_vS32Ub_ai_128B |
| 1071 | : Hexagon::V6_vS32Ub_ai; |
| 1072 | |
Krzysztof Parzyszek | 195dc8d | 2015-11-26 04:33:11 +0000 | [diff] [blame] | 1073 | unsigned Offset = Is128B ? VecOffset << 7 : VecOffset << 6; |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1074 | MachineInstr *MI1New = |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 1075 | BuildMI(MBB, MI, DL, get(NewOpc)) |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1076 | .addOperand(MI.getOperand(0)) |
| 1077 | .addImm(MI.getOperand(1).getImm()) |
| 1078 | .addReg(SrcSubLo) |
| 1079 | .setMemRefs(MI.memoperands_begin(), MI.memoperands_end()); |
Krzysztof Parzyszek | 195dc8d | 2015-11-26 04:33:11 +0000 | [diff] [blame] | 1080 | MI1New->getOperand(0).setIsKill(false); |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 1081 | BuildMI(MBB, MI, DL, get(NewOpc)) |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1082 | .addOperand(MI.getOperand(0)) |
| 1083 | // The Vectors are indexed in multiples of vector size. |
| 1084 | .addImm(MI.getOperand(1).getImm() + Offset) |
| 1085 | .addReg(SrcSubHi) |
| 1086 | .setMemRefs(MI.memoperands_begin(), MI.memoperands_end()); |
Krzysztof Parzyszek | 195dc8d | 2015-11-26 04:33:11 +0000 | [diff] [blame] | 1087 | MBB.erase(MI); |
| 1088 | return true; |
| 1089 | } |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 1090 | case Hexagon::PS_vloadrw_ai: |
| 1091 | case Hexagon::PS_vloadrwu_ai: |
| 1092 | case Hexagon::PS_vloadrw_ai_128B: |
| 1093 | case Hexagon::PS_vloadrwu_ai_128B: { |
| 1094 | bool Is128B = (Opc == Hexagon::PS_vloadrw_ai_128B || |
| 1095 | Opc == Hexagon::PS_vloadrwu_ai_128B); |
| 1096 | bool Aligned = (Opc == Hexagon::PS_vloadrw_ai || |
| 1097 | Opc == Hexagon::PS_vloadrw_ai_128B); |
| 1098 | unsigned NewOpc; |
| 1099 | if (Aligned) |
| 1100 | NewOpc = Is128B ? Hexagon::V6_vL32b_ai_128B |
| 1101 | : Hexagon::V6_vL32b_ai; |
| 1102 | else |
| 1103 | NewOpc = Is128B ? Hexagon::V6_vL32Ub_ai_128B |
| 1104 | : Hexagon::V6_vL32Ub_ai; |
| 1105 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1106 | unsigned DstReg = MI.getOperand(0).getReg(); |
Krzysztof Parzyszek | 195dc8d | 2015-11-26 04:33:11 +0000 | [diff] [blame] | 1107 | unsigned Offset = Is128B ? VecOffset << 7 : VecOffset << 6; |
| 1108 | MachineInstr *MI1New = |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 1109 | BuildMI(MBB, MI, DL, get(NewOpc), |
Krzysztof Parzyszek | 195dc8d | 2015-11-26 04:33:11 +0000 | [diff] [blame] | 1110 | HRI.getSubReg(DstReg, Hexagon::subreg_loreg)) |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1111 | .addOperand(MI.getOperand(1)) |
| 1112 | .addImm(MI.getOperand(2).getImm()); |
Krzysztof Parzyszek | 195dc8d | 2015-11-26 04:33:11 +0000 | [diff] [blame] | 1113 | MI1New->getOperand(1).setIsKill(false); |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 1114 | BuildMI(MBB, MI, DL, get(NewOpc), |
Krzysztof Parzyszek | 195dc8d | 2015-11-26 04:33:11 +0000 | [diff] [blame] | 1115 | HRI.getSubReg(DstReg, Hexagon::subreg_hireg)) |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1116 | .addOperand(MI.getOperand(1)) |
Krzysztof Parzyszek | 195dc8d | 2015-11-26 04:33:11 +0000 | [diff] [blame] | 1117 | // The Vectors are indexed in multiples of vector size. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1118 | .addImm(MI.getOperand(2).getImm() + Offset) |
| 1119 | .setMemRefs(MI.memoperands_begin(), MI.memoperands_end()); |
Krzysztof Parzyszek | 195dc8d | 2015-11-26 04:33:11 +0000 | [diff] [blame] | 1120 | MBB.erase(MI); |
| 1121 | return true; |
| 1122 | } |
Krzysztof Parzyszek | 1d01a79 | 2016-08-16 18:08:40 +0000 | [diff] [blame] | 1123 | case Hexagon::PS_true: { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1124 | unsigned Reg = MI.getOperand(0).getReg(); |
Krzysztof Parzyszek | 36ccfa5 | 2015-03-18 19:07:53 +0000 | [diff] [blame] | 1125 | BuildMI(MBB, MI, DL, get(Hexagon::C2_orn), Reg) |
| 1126 | .addReg(Reg, RegState::Undef) |
| 1127 | .addReg(Reg, RegState::Undef); |
| 1128 | MBB.erase(MI); |
| 1129 | return true; |
| 1130 | } |
Krzysztof Parzyszek | 1d01a79 | 2016-08-16 18:08:40 +0000 | [diff] [blame] | 1131 | case Hexagon::PS_false: { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1132 | unsigned Reg = MI.getOperand(0).getReg(); |
Krzysztof Parzyszek | 36ccfa5 | 2015-03-18 19:07:53 +0000 | [diff] [blame] | 1133 | BuildMI(MBB, MI, DL, get(Hexagon::C2_andn), Reg) |
| 1134 | .addReg(Reg, RegState::Undef) |
| 1135 | .addReg(Reg, RegState::Undef); |
| 1136 | MBB.erase(MI); |
| 1137 | return true; |
| 1138 | } |
Krzysztof Parzyszek | 1d01a79 | 2016-08-16 18:08:40 +0000 | [diff] [blame] | 1139 | case Hexagon::PS_vmulw: { |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1140 | // Expand a 64-bit vector multiply into 2 32-bit scalar multiplies. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1141 | unsigned DstReg = MI.getOperand(0).getReg(); |
| 1142 | unsigned Src1Reg = MI.getOperand(1).getReg(); |
| 1143 | unsigned Src2Reg = MI.getOperand(2).getReg(); |
Krzysztof Parzyszek | fb33824 | 2015-10-06 15:49:14 +0000 | [diff] [blame] | 1144 | unsigned Src1SubHi = HRI.getSubReg(Src1Reg, Hexagon::subreg_hireg); |
| 1145 | unsigned Src1SubLo = HRI.getSubReg(Src1Reg, Hexagon::subreg_loreg); |
| 1146 | unsigned Src2SubHi = HRI.getSubReg(Src2Reg, Hexagon::subreg_hireg); |
| 1147 | unsigned Src2SubLo = HRI.getSubReg(Src2Reg, Hexagon::subreg_loreg); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1148 | BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::M2_mpyi), |
| 1149 | HRI.getSubReg(DstReg, Hexagon::subreg_hireg)) |
| 1150 | .addReg(Src1SubHi) |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1151 | .addReg(Src2SubHi); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1152 | BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::M2_mpyi), |
| 1153 | HRI.getSubReg(DstReg, Hexagon::subreg_loreg)) |
| 1154 | .addReg(Src1SubLo) |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1155 | .addReg(Src2SubLo); |
| 1156 | MBB.erase(MI); |
| 1157 | MRI.clearKillFlags(Src1SubHi); |
| 1158 | MRI.clearKillFlags(Src1SubLo); |
| 1159 | MRI.clearKillFlags(Src2SubHi); |
| 1160 | MRI.clearKillFlags(Src2SubLo); |
| 1161 | return true; |
| 1162 | } |
Krzysztof Parzyszek | 1d01a79 | 2016-08-16 18:08:40 +0000 | [diff] [blame] | 1163 | case Hexagon::PS_vmulw_acc: { |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1164 | // Expand 64-bit vector multiply with addition into 2 scalar multiplies. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1165 | unsigned DstReg = MI.getOperand(0).getReg(); |
| 1166 | unsigned Src1Reg = MI.getOperand(1).getReg(); |
| 1167 | unsigned Src2Reg = MI.getOperand(2).getReg(); |
| 1168 | unsigned Src3Reg = MI.getOperand(3).getReg(); |
Krzysztof Parzyszek | fb33824 | 2015-10-06 15:49:14 +0000 | [diff] [blame] | 1169 | unsigned Src1SubHi = HRI.getSubReg(Src1Reg, Hexagon::subreg_hireg); |
| 1170 | unsigned Src1SubLo = HRI.getSubReg(Src1Reg, Hexagon::subreg_loreg); |
| 1171 | unsigned Src2SubHi = HRI.getSubReg(Src2Reg, Hexagon::subreg_hireg); |
| 1172 | unsigned Src2SubLo = HRI.getSubReg(Src2Reg, Hexagon::subreg_loreg); |
| 1173 | unsigned Src3SubHi = HRI.getSubReg(Src3Reg, Hexagon::subreg_hireg); |
| 1174 | unsigned Src3SubLo = HRI.getSubReg(Src3Reg, Hexagon::subreg_loreg); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1175 | BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::M2_maci), |
| 1176 | HRI.getSubReg(DstReg, Hexagon::subreg_hireg)) |
| 1177 | .addReg(Src1SubHi) |
| 1178 | .addReg(Src2SubHi) |
| 1179 | .addReg(Src3SubHi); |
| 1180 | BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::M2_maci), |
| 1181 | HRI.getSubReg(DstReg, Hexagon::subreg_loreg)) |
| 1182 | .addReg(Src1SubLo) |
| 1183 | .addReg(Src2SubLo) |
| 1184 | .addReg(Src3SubLo); |
Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1185 | MBB.erase(MI); |
| 1186 | MRI.clearKillFlags(Src1SubHi); |
| 1187 | MRI.clearKillFlags(Src1SubLo); |
| 1188 | MRI.clearKillFlags(Src2SubHi); |
| 1189 | MRI.clearKillFlags(Src2SubLo); |
| 1190 | MRI.clearKillFlags(Src3SubHi); |
| 1191 | MRI.clearKillFlags(Src3SubLo); |
| 1192 | return true; |
| 1193 | } |
Krzysztof Parzyszek | 237b961 | 2016-01-14 15:37:16 +0000 | [diff] [blame] | 1194 | case Hexagon::Insert4: { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1195 | unsigned DstReg = MI.getOperand(0).getReg(); |
| 1196 | unsigned Src1Reg = MI.getOperand(1).getReg(); |
| 1197 | unsigned Src2Reg = MI.getOperand(2).getReg(); |
| 1198 | unsigned Src3Reg = MI.getOperand(3).getReg(); |
| 1199 | unsigned Src4Reg = MI.getOperand(4).getReg(); |
| 1200 | unsigned Src1RegIsKill = getKillRegState(MI.getOperand(1).isKill()); |
| 1201 | unsigned Src2RegIsKill = getKillRegState(MI.getOperand(2).isKill()); |
| 1202 | unsigned Src3RegIsKill = getKillRegState(MI.getOperand(3).isKill()); |
| 1203 | unsigned Src4RegIsKill = getKillRegState(MI.getOperand(4).isKill()); |
Krzysztof Parzyszek | 237b961 | 2016-01-14 15:37:16 +0000 | [diff] [blame] | 1204 | unsigned DstSubHi = HRI.getSubReg(DstReg, Hexagon::subreg_hireg); |
| 1205 | unsigned DstSubLo = HRI.getSubReg(DstReg, Hexagon::subreg_loreg); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1206 | BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::S2_insert), |
| 1207 | HRI.getSubReg(DstReg, Hexagon::subreg_loreg)) |
| 1208 | .addReg(DstSubLo) |
| 1209 | .addReg(Src1Reg, Src1RegIsKill) |
| 1210 | .addImm(16) |
| 1211 | .addImm(0); |
| 1212 | BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::S2_insert), |
| 1213 | HRI.getSubReg(DstReg, Hexagon::subreg_loreg)) |
| 1214 | .addReg(DstSubLo) |
| 1215 | .addReg(Src2Reg, Src2RegIsKill) |
| 1216 | .addImm(16) |
| 1217 | .addImm(16); |
| 1218 | BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::S2_insert), |
| 1219 | HRI.getSubReg(DstReg, Hexagon::subreg_hireg)) |
| 1220 | .addReg(DstSubHi) |
| 1221 | .addReg(Src3Reg, Src3RegIsKill) |
| 1222 | .addImm(16) |
| 1223 | .addImm(0); |
| 1224 | BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::S2_insert), |
| 1225 | HRI.getSubReg(DstReg, Hexagon::subreg_hireg)) |
| 1226 | .addReg(DstSubHi) |
| 1227 | .addReg(Src4Reg, Src4RegIsKill) |
| 1228 | .addImm(16) |
| 1229 | .addImm(16); |
Krzysztof Parzyszek | 237b961 | 2016-01-14 15:37:16 +0000 | [diff] [blame] | 1230 | MBB.erase(MI); |
| 1231 | MRI.clearKillFlags(DstReg); |
| 1232 | MRI.clearKillFlags(DstSubHi); |
| 1233 | MRI.clearKillFlags(DstSubLo); |
| 1234 | return true; |
| 1235 | } |
Krzysztof Parzyszek | 258af19 | 2016-08-11 19:12:18 +0000 | [diff] [blame] | 1236 | case Hexagon::PS_pselect: { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1237 | const MachineOperand &Op0 = MI.getOperand(0); |
| 1238 | const MachineOperand &Op1 = MI.getOperand(1); |
| 1239 | const MachineOperand &Op2 = MI.getOperand(2); |
| 1240 | const MachineOperand &Op3 = MI.getOperand(3); |
Krzysztof Parzyszek | fb33824 | 2015-10-06 15:49:14 +0000 | [diff] [blame] | 1241 | unsigned Rd = Op0.getReg(); |
| 1242 | unsigned Pu = Op1.getReg(); |
| 1243 | unsigned Rs = Op2.getReg(); |
| 1244 | unsigned Rt = Op3.getReg(); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1245 | DebugLoc DL = MI.getDebugLoc(); |
Krzysztof Parzyszek | fb33824 | 2015-10-06 15:49:14 +0000 | [diff] [blame] | 1246 | unsigned K1 = getKillRegState(Op1.isKill()); |
| 1247 | unsigned K2 = getKillRegState(Op2.isKill()); |
| 1248 | unsigned K3 = getKillRegState(Op3.isKill()); |
| 1249 | if (Rd != Rs) |
| 1250 | BuildMI(MBB, MI, DL, get(Hexagon::A2_tfrpt), Rd) |
| 1251 | .addReg(Pu, (Rd == Rt) ? K1 : 0) |
| 1252 | .addReg(Rs, K2); |
| 1253 | if (Rd != Rt) |
| 1254 | BuildMI(MBB, MI, DL, get(Hexagon::A2_tfrpf), Rd) |
| 1255 | .addReg(Pu, K1) |
| 1256 | .addReg(Rt, K3); |
| 1257 | MBB.erase(MI); |
| 1258 | return true; |
| 1259 | } |
Krzysztof Parzyszek | 258af19 | 2016-08-11 19:12:18 +0000 | [diff] [blame] | 1260 | case Hexagon::PS_vselect: |
| 1261 | case Hexagon::PS_vselect_128B: { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1262 | const MachineOperand &Op0 = MI.getOperand(0); |
| 1263 | const MachineOperand &Op1 = MI.getOperand(1); |
| 1264 | const MachineOperand &Op2 = MI.getOperand(2); |
| 1265 | const MachineOperand &Op3 = MI.getOperand(3); |
Ron Lieberman | 88159e5 | 2016-09-02 22:56:24 +0000 | [diff] [blame^] | 1266 | LivePhysRegs LiveAtMI(&HRI); |
| 1267 | getLiveRegsAt(LiveAtMI, MI); |
| 1268 | bool IsDestLive = !LiveAtMI.available(MRI, Op0.getReg()); |
| 1269 | if (Op0.getReg() != Op2.getReg()) { |
| 1270 | auto T = BuildMI(MBB, MI, DL, get(Hexagon::V6_vcmov)) |
| 1271 | .addOperand(Op0) |
| 1272 | .addOperand(Op1) |
| 1273 | .addOperand(Op2); |
| 1274 | if (IsDestLive) |
| 1275 | T.addReg(Op0.getReg(), RegState::Implicit); |
| 1276 | IsDestLive = true; |
| 1277 | } |
| 1278 | if (Op0.getReg() != Op3.getReg()) { |
| 1279 | auto T = BuildMI(MBB, MI, DL, get(Hexagon::V6_vncmov)) |
| 1280 | .addOperand(Op0) |
| 1281 | .addOperand(Op1) |
| 1282 | .addOperand(Op3); |
| 1283 | if (IsDestLive) |
| 1284 | T.addReg(Op0.getReg(), RegState::Implicit); |
| 1285 | } |
Krzysztof Parzyszek | 4afed55 | 2016-05-12 19:16:02 +0000 | [diff] [blame] | 1286 | MBB.erase(MI); |
| 1287 | return true; |
| 1288 | } |
Krzysztof Parzyszek | 258af19 | 2016-08-11 19:12:18 +0000 | [diff] [blame] | 1289 | case Hexagon::PS_wselect: |
| 1290 | case Hexagon::PS_wselect_128B: { |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1291 | MachineOperand &Op0 = MI.getOperand(0); |
| 1292 | MachineOperand &Op1 = MI.getOperand(1); |
| 1293 | MachineOperand &Op2 = MI.getOperand(2); |
| 1294 | MachineOperand &Op3 = MI.getOperand(3); |
Ron Lieberman | 88159e5 | 2016-09-02 22:56:24 +0000 | [diff] [blame^] | 1295 | LivePhysRegs LiveAtMI(&HRI); |
| 1296 | getLiveRegsAt(LiveAtMI, MI); |
| 1297 | bool IsDestLive = !LiveAtMI.available(MRI, Op0.getReg()); |
| 1298 | |
| 1299 | if (Op0.getReg() != Op2.getReg()) { |
| 1300 | unsigned SrcLo = HRI.getSubReg(Op2.getReg(), Hexagon::subreg_loreg); |
| 1301 | unsigned SrcHi = HRI.getSubReg(Op2.getReg(), Hexagon::subreg_hireg); |
| 1302 | auto T = BuildMI(MBB, MI, DL, get(Hexagon::V6_vccombine)) |
| 1303 | .addOperand(Op0) |
| 1304 | .addOperand(Op1) |
| 1305 | .addReg(SrcHi) |
| 1306 | .addReg(SrcLo); |
| 1307 | if (IsDestLive) |
| 1308 | T.addReg(Op0.getReg(), RegState::Implicit); |
| 1309 | IsDestLive = true; |
| 1310 | } |
| 1311 | if (Op0.getReg() != Op3.getReg()) { |
| 1312 | unsigned SrcLo = HRI.getSubReg(Op3.getReg(), Hexagon::subreg_loreg); |
| 1313 | unsigned SrcHi = HRI.getSubReg(Op3.getReg(), Hexagon::subreg_hireg); |
| 1314 | auto T = BuildMI(MBB, MI, DL, get(Hexagon::V6_vnccombine)) |
| 1315 | .addOperand(Op0) |
| 1316 | .addOperand(Op1) |
| 1317 | .addReg(SrcHi) |
| 1318 | .addReg(SrcLo); |
| 1319 | if (IsDestLive) |
| 1320 | T.addReg(Op0.getReg(), RegState::Implicit); |
| 1321 | } |
Krzysztof Parzyszek | 4afed55 | 2016-05-12 19:16:02 +0000 | [diff] [blame] | 1322 | MBB.erase(MI); |
| 1323 | return true; |
| 1324 | } |
Krzysztof Parzyszek | be976d4 | 2016-08-12 11:12:02 +0000 | [diff] [blame] | 1325 | case Hexagon::PS_tailcall_i: |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1326 | MI.setDesc(get(Hexagon::J2_jump)); |
Colin LeMahieu | 7b1799c | 2015-03-09 22:05:21 +0000 | [diff] [blame] | 1327 | return true; |
Krzysztof Parzyszek | be976d4 | 2016-08-12 11:12:02 +0000 | [diff] [blame] | 1328 | case Hexagon::PS_tailcall_r: |
Krzysztof Parzyszek | 6421b93 | 2016-08-19 14:04:45 +0000 | [diff] [blame] | 1329 | case Hexagon::PS_jmpret: |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1330 | MI.setDesc(get(Hexagon::J2_jumpr)); |
Colin LeMahieu | 7b1799c | 2015-03-09 22:05:21 +0000 | [diff] [blame] | 1331 | return true; |
Krzysztof Parzyszek | 6421b93 | 2016-08-19 14:04:45 +0000 | [diff] [blame] | 1332 | case Hexagon::PS_jmprett: |
| 1333 | MI.setDesc(get(Hexagon::J2_jumprt)); |
| 1334 | return true; |
| 1335 | case Hexagon::PS_jmpretf: |
| 1336 | MI.setDesc(get(Hexagon::J2_jumprf)); |
| 1337 | return true; |
| 1338 | case Hexagon::PS_jmprettnewpt: |
| 1339 | MI.setDesc(get(Hexagon::J2_jumprtnewpt)); |
| 1340 | return true; |
| 1341 | case Hexagon::PS_jmpretfnewpt: |
| 1342 | MI.setDesc(get(Hexagon::J2_jumprfnewpt)); |
| 1343 | return true; |
| 1344 | case Hexagon::PS_jmprettnew: |
| 1345 | MI.setDesc(get(Hexagon::J2_jumprtnew)); |
| 1346 | return true; |
| 1347 | case Hexagon::PS_jmpretfnew: |
| 1348 | MI.setDesc(get(Hexagon::J2_jumprfnew)); |
| 1349 | return true; |
Colin LeMahieu | 7b1799c | 2015-03-09 22:05:21 +0000 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | return false; |
| 1353 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1354 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1355 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1356 | // We indicate that we want to reverse the branch by |
| 1357 | // inserting the reversed branching opcode. |
| 1358 | bool HexagonInstrInfo::ReverseBranchCondition( |
| 1359 | SmallVectorImpl<MachineOperand> &Cond) const { |
| 1360 | if (Cond.empty()) |
Jyotsna Verma | f1214a8 | 2013-03-05 18:51:42 +0000 | [diff] [blame] | 1361 | return true; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1362 | assert(Cond[0].isImm() && "First entry in the cond vector not imm-val"); |
| 1363 | unsigned opcode = Cond[0].getImm(); |
| 1364 | //unsigned temp; |
| 1365 | assert(get(opcode).isBranch() && "Should be a branching condition."); |
| 1366 | if (isEndLoopN(opcode)) |
Jyotsna Verma | f1214a8 | 2013-03-05 18:51:42 +0000 | [diff] [blame] | 1367 | return true; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1368 | unsigned NewOpcode = getInvertedPredicatedOpcode(opcode); |
| 1369 | Cond[0].setImm(NewOpcode); |
Jyotsna Verma | f1214a8 | 2013-03-05 18:51:42 +0000 | [diff] [blame] | 1370 | return false; |
| 1371 | } |
| 1372 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1373 | |
| 1374 | void HexagonInstrInfo::insertNoop(MachineBasicBlock &MBB, |
| 1375 | MachineBasicBlock::iterator MI) const { |
| 1376 | DebugLoc DL; |
| 1377 | BuildMI(MBB, MI, DL, get(Hexagon::A2_nop)); |
| 1378 | } |
| 1379 | |
| 1380 | |
Krzysztof Parzyszek | 8fb181c | 2016-08-01 17:55:48 +0000 | [diff] [blame] | 1381 | bool HexagonInstrInfo::isPostIncrement(const MachineInstr &MI) const { |
| 1382 | return getAddrMode(MI) == HexagonII::PostInc; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1386 | // Returns true if an instruction is predicated irrespective of the predicate |
| 1387 | // sense. For example, all of the following will return true. |
| 1388 | // if (p0) R1 = add(R2, R3) |
| 1389 | // if (!p0) R1 = add(R2, R3) |
| 1390 | // if (p0.new) R1 = add(R2, R3) |
| 1391 | // if (!p0.new) R1 = add(R2, R3) |
| 1392 | // Note: New-value stores are not included here as in the current |
| 1393 | // implementation, we don't need to check their predicate sense. |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1394 | bool HexagonInstrInfo::isPredicated(const MachineInstr &MI) const { |
| 1395 | const uint64_t F = MI.getDesc().TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1396 | return (F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask; |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 1397 | } |
| 1398 | |
Krzysztof Parzyszek | 0a04ac2 | 2016-05-16 16:56:10 +0000 | [diff] [blame] | 1399 | |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1400 | bool HexagonInstrInfo::PredicateInstruction( |
| 1401 | MachineInstr &MI, ArrayRef<MachineOperand> Cond) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1402 | if (Cond.empty() || isNewValueJump(Cond[0].getImm()) || |
| 1403 | isEndLoopN(Cond[0].getImm())) { |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1404 | DEBUG(dbgs() << "\nCannot predicate:"; MI.dump();); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1405 | return false; |
| 1406 | } |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1407 | int Opc = MI.getOpcode(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1408 | assert (isPredicable(MI) && "Expected predicable instruction"); |
| 1409 | bool invertJump = predOpcodeHasNot(Cond); |
| 1410 | |
| 1411 | // We have to predicate MI "in place", i.e. after this function returns, |
| 1412 | // MI will need to be transformed into a predicated form. To avoid com- |
| 1413 | // plicated manipulations with the operands (handling tied operands, |
| 1414 | // etc.), build a new temporary instruction, then overwrite MI with it. |
| 1415 | |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1416 | MachineBasicBlock &B = *MI.getParent(); |
| 1417 | DebugLoc DL = MI.getDebugLoc(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1418 | unsigned PredOpc = getCondOpcode(Opc, invertJump); |
| 1419 | MachineInstrBuilder T = BuildMI(B, MI, DL, get(PredOpc)); |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1420 | unsigned NOp = 0, NumOps = MI.getNumOperands(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1421 | while (NOp < NumOps) { |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1422 | MachineOperand &Op = MI.getOperand(NOp); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1423 | if (!Op.isReg() || !Op.isDef() || Op.isImplicit()) |
| 1424 | break; |
| 1425 | T.addOperand(Op); |
| 1426 | NOp++; |
| 1427 | } |
| 1428 | |
| 1429 | unsigned PredReg, PredRegPos, PredRegFlags; |
| 1430 | bool GotPredReg = getPredReg(Cond, PredReg, PredRegPos, PredRegFlags); |
| 1431 | (void)GotPredReg; |
| 1432 | assert(GotPredReg); |
| 1433 | T.addReg(PredReg, PredRegFlags); |
| 1434 | while (NOp < NumOps) |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1435 | T.addOperand(MI.getOperand(NOp++)); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1436 | |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1437 | MI.setDesc(get(PredOpc)); |
| 1438 | while (unsigned n = MI.getNumOperands()) |
| 1439 | MI.RemoveOperand(n-1); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1440 | for (unsigned i = 0, n = T->getNumOperands(); i < n; ++i) |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1441 | MI.addOperand(T->getOperand(i)); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1442 | |
Duncan P. N. Exon Smith | c5b668d | 2016-02-22 20:49:58 +0000 | [diff] [blame] | 1443 | MachineBasicBlock::instr_iterator TI = T->getIterator(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1444 | B.erase(TI); |
| 1445 | |
| 1446 | MachineRegisterInfo &MRI = B.getParent()->getRegInfo(); |
| 1447 | MRI.clearKillFlags(PredReg); |
| 1448 | return true; |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 1449 | } |
| 1450 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1451 | |
| 1452 | bool HexagonInstrInfo::SubsumesPredicate(ArrayRef<MachineOperand> Pred1, |
| 1453 | ArrayRef<MachineOperand> Pred2) const { |
| 1454 | // TODO: Fix this |
| 1455 | return false; |
| 1456 | } |
| 1457 | |
Krzysztof Parzyszek | 0a04ac2 | 2016-05-16 16:56:10 +0000 | [diff] [blame] | 1458 | |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1459 | bool HexagonInstrInfo::DefinesPredicate( |
| 1460 | MachineInstr &MI, std::vector<MachineOperand> &Pred) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1461 | auto &HRI = getRegisterInfo(); |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1462 | for (unsigned oper = 0; oper < MI.getNumOperands(); ++oper) { |
| 1463 | MachineOperand MO = MI.getOperand(oper); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1464 | if (MO.isReg() && MO.isDef()) { |
| 1465 | const TargetRegisterClass* RC = HRI.getMinimalPhysRegClass(MO.getReg()); |
| 1466 | if (RC == &Hexagon::PredRegsRegClass) { |
| 1467 | Pred.push_back(MO); |
| 1468 | return true; |
| 1469 | } |
| 1470 | } |
| 1471 | } |
| 1472 | return false; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1473 | } |
Andrew Trick | d06df96 | 2012-02-01 22:13:57 +0000 | [diff] [blame] | 1474 | |
Krzysztof Parzyszek | 0a04ac2 | 2016-05-16 16:56:10 +0000 | [diff] [blame] | 1475 | |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1476 | bool HexagonInstrInfo::isPredicable(MachineInstr &MI) const { |
Krzysztof Parzyszek | 0a04ac2 | 2016-05-16 16:56:10 +0000 | [diff] [blame] | 1477 | return MI.getDesc().isPredicable(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1478 | } |
| 1479 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1480 | bool HexagonInstrInfo::isSchedulingBoundary(const MachineInstr &MI, |
| 1481 | const MachineBasicBlock *MBB, |
| 1482 | const MachineFunction &MF) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1483 | // Debug info is never a scheduling boundary. It's necessary to be explicit |
| 1484 | // due to the special treatment of IT instructions below, otherwise a |
| 1485 | // dbg_value followed by an IT will result in the IT instruction being |
| 1486 | // considered a scheduling hazard, which is wrong. It should be the actual |
| 1487 | // instruction preceding the dbg_value instruction(s), just like it is |
| 1488 | // when debug info is not present. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1489 | if (MI.isDebugValue()) |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 1490 | return false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1491 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1492 | // Throwing call is a boundary. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1493 | if (MI.isCall()) { |
Krzysztof Parzyszek | ab9127c | 2016-08-12 11:01:10 +0000 | [diff] [blame] | 1494 | // Don't mess around with no return calls. |
| 1495 | if (doesNotReturn(MI)) |
| 1496 | return true; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1497 | // If any of the block's successors is a landing pad, this could be a |
| 1498 | // throwing call. |
| 1499 | for (auto I : MBB->successors()) |
| 1500 | if (I->isEHPad()) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1501 | return true; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1502 | } |
| 1503 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1504 | // Terminators and labels can't be scheduled around. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1505 | if (MI.getDesc().isTerminator() || MI.isPosition()) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1506 | return true; |
| 1507 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1508 | if (MI.isInlineAsm() && !ScheduleInlineAsm) |
| 1509 | return true; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1510 | |
| 1511 | return false; |
| 1512 | } |
| 1513 | |
| 1514 | |
| 1515 | /// Measure the specified inline asm to determine an approximation of its |
| 1516 | /// length. |
| 1517 | /// Comments (which run till the next SeparatorString or newline) do not |
| 1518 | /// count as an instruction. |
| 1519 | /// Any other non-whitespace text is considered an instruction, with |
| 1520 | /// multiple instructions separated by SeparatorString or newlines. |
| 1521 | /// Variable-length instructions are not handled here; this function |
| 1522 | /// may be overloaded in the target code to do that. |
| 1523 | /// Hexagon counts the number of ##'s and adjust for that many |
| 1524 | /// constant exenders. |
| 1525 | unsigned HexagonInstrInfo::getInlineAsmLength(const char *Str, |
| 1526 | const MCAsmInfo &MAI) const { |
| 1527 | StringRef AStr(Str); |
| 1528 | // Count the number of instructions in the asm. |
| 1529 | bool atInsnStart = true; |
| 1530 | unsigned Length = 0; |
| 1531 | for (; *Str; ++Str) { |
| 1532 | if (*Str == '\n' || strncmp(Str, MAI.getSeparatorString(), |
| 1533 | strlen(MAI.getSeparatorString())) == 0) |
| 1534 | atInsnStart = true; |
| 1535 | if (atInsnStart && !std::isspace(static_cast<unsigned char>(*Str))) { |
| 1536 | Length += MAI.getMaxInstLength(); |
| 1537 | atInsnStart = false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1538 | } |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1539 | if (atInsnStart && strncmp(Str, MAI.getCommentString(), |
| 1540 | strlen(MAI.getCommentString())) == 0) |
| 1541 | atInsnStart = false; |
| 1542 | } |
| 1543 | |
| 1544 | // Add to size number of constant extenders seen * 4. |
| 1545 | StringRef Occ("##"); |
| 1546 | Length += AStr.count(Occ)*4; |
| 1547 | return Length; |
| 1548 | } |
| 1549 | |
| 1550 | |
| 1551 | ScheduleHazardRecognizer* |
| 1552 | HexagonInstrInfo::CreateTargetPostRAHazardRecognizer( |
| 1553 | const InstrItineraryData *II, const ScheduleDAG *DAG) const { |
Krzysztof Parzyszek | e95e955 | 2016-07-29 13:59:09 +0000 | [diff] [blame] | 1554 | if (UseDFAHazardRec) { |
| 1555 | auto &HST = DAG->MF.getSubtarget<HexagonSubtarget>(); |
| 1556 | return new HexagonHazardRecognizer(II, this, HST); |
| 1557 | } |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1558 | return TargetInstrInfo::CreateTargetPostRAHazardRecognizer(II, DAG); |
| 1559 | } |
| 1560 | |
| 1561 | |
| 1562 | /// \brief For a comparison instruction, return the source registers in |
| 1563 | /// \p SrcReg and \p SrcReg2 if having two register operands, and the value it |
| 1564 | /// compares against in CmpValue. Return true if the comparison instruction |
| 1565 | /// can be analyzed. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1566 | bool HexagonInstrInfo::analyzeCompare(const MachineInstr &MI, unsigned &SrcReg, |
| 1567 | unsigned &SrcReg2, int &Mask, |
| 1568 | int &Value) const { |
| 1569 | unsigned Opc = MI.getOpcode(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1570 | |
| 1571 | // Set mask and the first source register. |
| 1572 | switch (Opc) { |
| 1573 | case Hexagon::C2_cmpeq: |
| 1574 | case Hexagon::C2_cmpeqp: |
| 1575 | case Hexagon::C2_cmpgt: |
| 1576 | case Hexagon::C2_cmpgtp: |
| 1577 | case Hexagon::C2_cmpgtu: |
| 1578 | case Hexagon::C2_cmpgtup: |
| 1579 | case Hexagon::C4_cmpneq: |
| 1580 | case Hexagon::C4_cmplte: |
| 1581 | case Hexagon::C4_cmplteu: |
| 1582 | case Hexagon::C2_cmpeqi: |
| 1583 | case Hexagon::C2_cmpgti: |
| 1584 | case Hexagon::C2_cmpgtui: |
| 1585 | case Hexagon::C4_cmpneqi: |
| 1586 | case Hexagon::C4_cmplteui: |
| 1587 | case Hexagon::C4_cmpltei: |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1588 | SrcReg = MI.getOperand(1).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1589 | Mask = ~0; |
| 1590 | break; |
| 1591 | case Hexagon::A4_cmpbeq: |
| 1592 | case Hexagon::A4_cmpbgt: |
| 1593 | case Hexagon::A4_cmpbgtu: |
| 1594 | case Hexagon::A4_cmpbeqi: |
| 1595 | case Hexagon::A4_cmpbgti: |
| 1596 | case Hexagon::A4_cmpbgtui: |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1597 | SrcReg = MI.getOperand(1).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1598 | Mask = 0xFF; |
| 1599 | break; |
| 1600 | case Hexagon::A4_cmpheq: |
| 1601 | case Hexagon::A4_cmphgt: |
| 1602 | case Hexagon::A4_cmphgtu: |
| 1603 | case Hexagon::A4_cmpheqi: |
| 1604 | case Hexagon::A4_cmphgti: |
| 1605 | case Hexagon::A4_cmphgtui: |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1606 | SrcReg = MI.getOperand(1).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1607 | Mask = 0xFFFF; |
| 1608 | break; |
| 1609 | } |
| 1610 | |
| 1611 | // Set the value/second source register. |
| 1612 | switch (Opc) { |
| 1613 | case Hexagon::C2_cmpeq: |
| 1614 | case Hexagon::C2_cmpeqp: |
| 1615 | case Hexagon::C2_cmpgt: |
| 1616 | case Hexagon::C2_cmpgtp: |
| 1617 | case Hexagon::C2_cmpgtu: |
| 1618 | case Hexagon::C2_cmpgtup: |
| 1619 | case Hexagon::A4_cmpbeq: |
| 1620 | case Hexagon::A4_cmpbgt: |
| 1621 | case Hexagon::A4_cmpbgtu: |
| 1622 | case Hexagon::A4_cmpheq: |
| 1623 | case Hexagon::A4_cmphgt: |
| 1624 | case Hexagon::A4_cmphgtu: |
| 1625 | case Hexagon::C4_cmpneq: |
| 1626 | case Hexagon::C4_cmplte: |
| 1627 | case Hexagon::C4_cmplteu: |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1628 | SrcReg2 = MI.getOperand(2).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1629 | return true; |
| 1630 | |
| 1631 | case Hexagon::C2_cmpeqi: |
| 1632 | case Hexagon::C2_cmpgtui: |
| 1633 | case Hexagon::C2_cmpgti: |
| 1634 | case Hexagon::C4_cmpneqi: |
| 1635 | case Hexagon::C4_cmplteui: |
| 1636 | case Hexagon::C4_cmpltei: |
| 1637 | case Hexagon::A4_cmpbeqi: |
| 1638 | case Hexagon::A4_cmpbgti: |
| 1639 | case Hexagon::A4_cmpbgtui: |
| 1640 | case Hexagon::A4_cmpheqi: |
| 1641 | case Hexagon::A4_cmphgti: |
| 1642 | case Hexagon::A4_cmphgtui: |
| 1643 | SrcReg2 = 0; |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1644 | Value = MI.getOperand(2).getImm(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1645 | return true; |
| 1646 | } |
| 1647 | |
| 1648 | return false; |
| 1649 | } |
| 1650 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1651 | unsigned HexagonInstrInfo::getInstrLatency(const InstrItineraryData *ItinData, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1652 | const MachineInstr &MI, |
| 1653 | unsigned *PredCost) const { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1654 | return getInstrTimingClassLatency(ItinData, MI); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | |
| 1658 | DFAPacketizer *HexagonInstrInfo::CreateTargetScheduleState( |
| 1659 | const TargetSubtargetInfo &STI) const { |
| 1660 | const InstrItineraryData *II = STI.getInstrItineraryData(); |
| 1661 | return static_cast<const HexagonSubtarget&>(STI).createDFAPacketizer(II); |
| 1662 | } |
| 1663 | |
| 1664 | |
| 1665 | // Inspired by this pair: |
| 1666 | // %R13<def> = L2_loadri_io %R29, 136; mem:LD4[FixedStack0] |
| 1667 | // S2_storeri_io %R29, 132, %R1<kill>; flags: mem:ST4[FixedStack1] |
| 1668 | // Currently AA considers the addresses in these instructions to be aliasing. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1669 | bool HexagonInstrInfo::areMemAccessesTriviallyDisjoint( |
| 1670 | MachineInstr &MIa, MachineInstr &MIb, AliasAnalysis *AA) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1671 | int OffsetA = 0, OffsetB = 0; |
| 1672 | unsigned SizeA = 0, SizeB = 0; |
| 1673 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1674 | if (MIa.hasUnmodeledSideEffects() || MIb.hasUnmodeledSideEffects() || |
| 1675 | MIa.hasOrderedMemoryRef() || MIb.hasOrderedMemoryRef()) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1676 | return false; |
| 1677 | |
| 1678 | // Instructions that are pure loads, not loads and stores like memops are not |
| 1679 | // dependent. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1680 | if (MIa.mayLoad() && !isMemOp(MIa) && MIb.mayLoad() && !isMemOp(MIb)) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1681 | return true; |
| 1682 | |
| 1683 | // Get base, offset, and access size in MIa. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1684 | unsigned BaseRegA = getBaseAndOffset(MIa, OffsetA, SizeA); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1685 | if (!BaseRegA || !SizeA) |
| 1686 | return false; |
| 1687 | |
| 1688 | // Get base, offset, and access size in MIb. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1689 | unsigned BaseRegB = getBaseAndOffset(MIb, OffsetB, SizeB); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1690 | if (!BaseRegB || !SizeB) |
| 1691 | return false; |
| 1692 | |
| 1693 | if (BaseRegA != BaseRegB) |
| 1694 | return false; |
| 1695 | |
| 1696 | // This is a mem access with the same base register and known offsets from it. |
| 1697 | // Reason about it. |
| 1698 | if (OffsetA > OffsetB) { |
| 1699 | uint64_t offDiff = (uint64_t)((int64_t)OffsetA - (int64_t)OffsetB); |
| 1700 | return (SizeB <= offDiff); |
| 1701 | } else if (OffsetA < OffsetB) { |
| 1702 | uint64_t offDiff = (uint64_t)((int64_t)OffsetB - (int64_t)OffsetA); |
| 1703 | return (SizeA <= offDiff); |
| 1704 | } |
| 1705 | |
| 1706 | return false; |
| 1707 | } |
| 1708 | |
| 1709 | |
Brendon Cahoon | 254f889 | 2016-07-29 16:44:44 +0000 | [diff] [blame] | 1710 | /// If the instruction is an increment of a constant value, return the amount. |
Krzysztof Parzyszek | 8fb181c | 2016-08-01 17:55:48 +0000 | [diff] [blame] | 1711 | bool HexagonInstrInfo::getIncrementValue(const MachineInstr &MI, |
Brendon Cahoon | 254f889 | 2016-07-29 16:44:44 +0000 | [diff] [blame] | 1712 | int &Value) const { |
| 1713 | if (isPostIncrement(MI)) { |
| 1714 | unsigned AccessSize; |
Krzysztof Parzyszek | 8fb181c | 2016-08-01 17:55:48 +0000 | [diff] [blame] | 1715 | return getBaseAndOffset(MI, Value, AccessSize); |
Brendon Cahoon | 254f889 | 2016-07-29 16:44:44 +0000 | [diff] [blame] | 1716 | } |
Krzysztof Parzyszek | 8fb181c | 2016-08-01 17:55:48 +0000 | [diff] [blame] | 1717 | if (MI.getOpcode() == Hexagon::A2_addi) { |
| 1718 | Value = MI.getOperand(2).getImm(); |
Brendon Cahoon | 254f889 | 2016-07-29 16:44:44 +0000 | [diff] [blame] | 1719 | return true; |
| 1720 | } |
| 1721 | |
| 1722 | return false; |
| 1723 | } |
| 1724 | |
| 1725 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1726 | unsigned HexagonInstrInfo::createVR(MachineFunction *MF, MVT VT) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1727 | MachineRegisterInfo &MRI = MF->getRegInfo(); |
| 1728 | const TargetRegisterClass *TRC; |
| 1729 | if (VT == MVT::i1) { |
| 1730 | TRC = &Hexagon::PredRegsRegClass; |
| 1731 | } else if (VT == MVT::i32 || VT == MVT::f32) { |
| 1732 | TRC = &Hexagon::IntRegsRegClass; |
| 1733 | } else if (VT == MVT::i64 || VT == MVT::f64) { |
| 1734 | TRC = &Hexagon::DoubleRegsRegClass; |
| 1735 | } else { |
| 1736 | llvm_unreachable("Cannot handle this register class"); |
| 1737 | } |
| 1738 | |
| 1739 | unsigned NewReg = MRI.createVirtualRegister(TRC); |
| 1740 | return NewReg; |
| 1741 | } |
| 1742 | |
| 1743 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1744 | bool HexagonInstrInfo::isAbsoluteSet(const MachineInstr &MI) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1745 | return (getAddrMode(MI) == HexagonII::AbsoluteSet); |
| 1746 | } |
| 1747 | |
| 1748 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1749 | bool HexagonInstrInfo::isAccumulator(const MachineInstr &MI) const { |
| 1750 | const uint64_t F = MI.getDesc().TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1751 | return((F >> HexagonII::AccumulatorPos) & HexagonII::AccumulatorMask); |
| 1752 | } |
| 1753 | |
| 1754 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1755 | bool HexagonInstrInfo::isComplex(const MachineInstr &MI) const { |
| 1756 | const MachineFunction *MF = MI.getParent()->getParent(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1757 | const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo(); |
| 1758 | const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII; |
| 1759 | |
| 1760 | if (!(isTC1(MI)) |
| 1761 | && !(QII->isTC2Early(MI)) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1762 | && !(MI.getDesc().mayLoad()) |
| 1763 | && !(MI.getDesc().mayStore()) |
| 1764 | && (MI.getDesc().getOpcode() != Hexagon::S2_allocframe) |
| 1765 | && (MI.getDesc().getOpcode() != Hexagon::L2_deallocframe) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1766 | && !(QII->isMemOp(MI)) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1767 | && !(MI.isBranch()) |
| 1768 | && !(MI.isReturn()) |
| 1769 | && !MI.isCall()) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1770 | return true; |
| 1771 | |
| 1772 | return false; |
| 1773 | } |
| 1774 | |
| 1775 | |
Sanjay Patel | e4b9f50 | 2015-12-07 19:21:39 +0000 | [diff] [blame] | 1776 | // Return true if the instruction is a compund branch instruction. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1777 | bool HexagonInstrInfo::isCompoundBranchInstr(const MachineInstr &MI) const { |
| 1778 | return (getType(MI) == HexagonII::TypeCOMPOUND && MI.isBranch()); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1782 | bool HexagonInstrInfo::isCondInst(const MachineInstr &MI) const { |
| 1783 | return (MI.isBranch() && isPredicated(MI)) || |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1784 | isConditionalTransfer(MI) || |
| 1785 | isConditionalALU32(MI) || |
| 1786 | isConditionalLoad(MI) || |
| 1787 | // Predicated stores which don't have a .new on any operands. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1788 | (MI.mayStore() && isPredicated(MI) && !isNewValueStore(MI) && |
| 1789 | !isPredicatedNew(MI)); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1793 | bool HexagonInstrInfo::isConditionalALU32(const MachineInstr &MI) const { |
| 1794 | switch (MI.getOpcode()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1795 | case Hexagon::A2_paddf: |
| 1796 | case Hexagon::A2_paddfnew: |
| 1797 | case Hexagon::A2_paddif: |
| 1798 | case Hexagon::A2_paddifnew: |
| 1799 | case Hexagon::A2_paddit: |
| 1800 | case Hexagon::A2_padditnew: |
| 1801 | case Hexagon::A2_paddt: |
| 1802 | case Hexagon::A2_paddtnew: |
| 1803 | case Hexagon::A2_pandf: |
| 1804 | case Hexagon::A2_pandfnew: |
| 1805 | case Hexagon::A2_pandt: |
| 1806 | case Hexagon::A2_pandtnew: |
| 1807 | case Hexagon::A2_porf: |
| 1808 | case Hexagon::A2_porfnew: |
| 1809 | case Hexagon::A2_port: |
| 1810 | case Hexagon::A2_portnew: |
| 1811 | case Hexagon::A2_psubf: |
| 1812 | case Hexagon::A2_psubfnew: |
| 1813 | case Hexagon::A2_psubt: |
| 1814 | case Hexagon::A2_psubtnew: |
| 1815 | case Hexagon::A2_pxorf: |
| 1816 | case Hexagon::A2_pxorfnew: |
| 1817 | case Hexagon::A2_pxort: |
| 1818 | case Hexagon::A2_pxortnew: |
| 1819 | case Hexagon::A4_paslhf: |
| 1820 | case Hexagon::A4_paslhfnew: |
| 1821 | case Hexagon::A4_paslht: |
| 1822 | case Hexagon::A4_paslhtnew: |
| 1823 | case Hexagon::A4_pasrhf: |
| 1824 | case Hexagon::A4_pasrhfnew: |
| 1825 | case Hexagon::A4_pasrht: |
| 1826 | case Hexagon::A4_pasrhtnew: |
| 1827 | case Hexagon::A4_psxtbf: |
| 1828 | case Hexagon::A4_psxtbfnew: |
| 1829 | case Hexagon::A4_psxtbt: |
| 1830 | case Hexagon::A4_psxtbtnew: |
| 1831 | case Hexagon::A4_psxthf: |
| 1832 | case Hexagon::A4_psxthfnew: |
| 1833 | case Hexagon::A4_psxtht: |
| 1834 | case Hexagon::A4_psxthtnew: |
| 1835 | case Hexagon::A4_pzxtbf: |
| 1836 | case Hexagon::A4_pzxtbfnew: |
| 1837 | case Hexagon::A4_pzxtbt: |
| 1838 | case Hexagon::A4_pzxtbtnew: |
| 1839 | case Hexagon::A4_pzxthf: |
| 1840 | case Hexagon::A4_pzxthfnew: |
| 1841 | case Hexagon::A4_pzxtht: |
| 1842 | case Hexagon::A4_pzxthtnew: |
| 1843 | case Hexagon::C2_ccombinewf: |
| 1844 | case Hexagon::C2_ccombinewt: |
| 1845 | return true; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1846 | } |
| 1847 | return false; |
| 1848 | } |
| 1849 | |
| 1850 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1851 | // FIXME - Function name and it's functionality don't match. |
| 1852 | // It should be renamed to hasPredNewOpcode() |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1853 | bool HexagonInstrInfo::isConditionalLoad(const MachineInstr &MI) const { |
| 1854 | if (!MI.getDesc().mayLoad() || !isPredicated(MI)) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1855 | return false; |
| 1856 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1857 | int PNewOpcode = Hexagon::getPredNewOpcode(MI.getOpcode()); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1858 | // Instruction with valid predicated-new opcode can be promoted to .new. |
| 1859 | return PNewOpcode >= 0; |
| 1860 | } |
| 1861 | |
| 1862 | |
| 1863 | // Returns true if an instruction is a conditional store. |
| 1864 | // |
| 1865 | // Note: It doesn't include conditional new-value stores as they can't be |
| 1866 | // converted to .new predicate. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1867 | bool HexagonInstrInfo::isConditionalStore(const MachineInstr &MI) const { |
| 1868 | switch (MI.getOpcode()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1869 | default: return false; |
| 1870 | case Hexagon::S4_storeirbt_io: |
| 1871 | case Hexagon::S4_storeirbf_io: |
| 1872 | case Hexagon::S4_pstorerbt_rr: |
| 1873 | case Hexagon::S4_pstorerbf_rr: |
| 1874 | case Hexagon::S2_pstorerbt_io: |
| 1875 | case Hexagon::S2_pstorerbf_io: |
| 1876 | case Hexagon::S2_pstorerbt_pi: |
| 1877 | case Hexagon::S2_pstorerbf_pi: |
| 1878 | case Hexagon::S2_pstorerdt_io: |
| 1879 | case Hexagon::S2_pstorerdf_io: |
| 1880 | case Hexagon::S4_pstorerdt_rr: |
| 1881 | case Hexagon::S4_pstorerdf_rr: |
| 1882 | case Hexagon::S2_pstorerdt_pi: |
| 1883 | case Hexagon::S2_pstorerdf_pi: |
| 1884 | case Hexagon::S2_pstorerht_io: |
| 1885 | case Hexagon::S2_pstorerhf_io: |
| 1886 | case Hexagon::S4_storeirht_io: |
| 1887 | case Hexagon::S4_storeirhf_io: |
| 1888 | case Hexagon::S4_pstorerht_rr: |
| 1889 | case Hexagon::S4_pstorerhf_rr: |
| 1890 | case Hexagon::S2_pstorerht_pi: |
| 1891 | case Hexagon::S2_pstorerhf_pi: |
| 1892 | case Hexagon::S2_pstorerit_io: |
| 1893 | case Hexagon::S2_pstorerif_io: |
| 1894 | case Hexagon::S4_storeirit_io: |
| 1895 | case Hexagon::S4_storeirif_io: |
| 1896 | case Hexagon::S4_pstorerit_rr: |
| 1897 | case Hexagon::S4_pstorerif_rr: |
| 1898 | case Hexagon::S2_pstorerit_pi: |
| 1899 | case Hexagon::S2_pstorerif_pi: |
| 1900 | |
| 1901 | // V4 global address store before promoting to dot new. |
| 1902 | case Hexagon::S4_pstorerdt_abs: |
| 1903 | case Hexagon::S4_pstorerdf_abs: |
| 1904 | case Hexagon::S4_pstorerbt_abs: |
| 1905 | case Hexagon::S4_pstorerbf_abs: |
| 1906 | case Hexagon::S4_pstorerht_abs: |
| 1907 | case Hexagon::S4_pstorerhf_abs: |
| 1908 | case Hexagon::S4_pstorerit_abs: |
| 1909 | case Hexagon::S4_pstorerif_abs: |
| 1910 | return true; |
| 1911 | |
| 1912 | // Predicated new value stores (i.e. if (p0) memw(..)=r0.new) are excluded |
| 1913 | // from the "Conditional Store" list. Because a predicated new value store |
| 1914 | // would NOT be promoted to a double dot new store. |
| 1915 | // This function returns yes for those stores that are predicated but not |
| 1916 | // yet promoted to predicate dot new instructions. |
| 1917 | } |
| 1918 | } |
| 1919 | |
| 1920 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1921 | bool HexagonInstrInfo::isConditionalTransfer(const MachineInstr &MI) const { |
| 1922 | switch (MI.getOpcode()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1923 | case Hexagon::A2_tfrt: |
| 1924 | case Hexagon::A2_tfrf: |
| 1925 | case Hexagon::C2_cmoveit: |
| 1926 | case Hexagon::C2_cmoveif: |
| 1927 | case Hexagon::A2_tfrtnew: |
| 1928 | case Hexagon::A2_tfrfnew: |
| 1929 | case Hexagon::C2_cmovenewit: |
| 1930 | case Hexagon::C2_cmovenewif: |
| 1931 | case Hexagon::A2_tfrpt: |
| 1932 | case Hexagon::A2_tfrpf: |
| 1933 | return true; |
| 1934 | |
| 1935 | default: |
| 1936 | return false; |
| 1937 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1938 | return false; |
| 1939 | } |
| 1940 | |
| 1941 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1942 | // TODO: In order to have isExtendable for fpimm/f32Ext, we need to handle |
| 1943 | // isFPImm and later getFPImm as well. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1944 | bool HexagonInstrInfo::isConstExtended(const MachineInstr &MI) const { |
| 1945 | const uint64_t F = MI.getDesc().TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1946 | unsigned isExtended = (F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask; |
| 1947 | if (isExtended) // Instruction must be extended. |
Krzysztof Parzyszek | c6f1933 | 2015-03-19 15:18:57 +0000 | [diff] [blame] | 1948 | return true; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1949 | |
| 1950 | unsigned isExtendable = |
| 1951 | (F >> HexagonII::ExtendablePos) & HexagonII::ExtendableMask; |
| 1952 | if (!isExtendable) |
| 1953 | return false; |
| 1954 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1955 | if (MI.isCall()) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1956 | return false; |
| 1957 | |
| 1958 | short ExtOpNum = getCExtOpNum(MI); |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1959 | const MachineOperand &MO = MI.getOperand(ExtOpNum); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1960 | // Use MO operand flags to determine if MO |
| 1961 | // has the HMOTF_ConstExtended flag set. |
| 1962 | if (MO.getTargetFlags() && HexagonII::HMOTF_ConstExtended) |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 1963 | return true; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1964 | // If this is a Machine BB address we are talking about, and it is |
| 1965 | // not marked as extended, say so. |
| 1966 | if (MO.isMBB()) |
| 1967 | return false; |
| 1968 | |
| 1969 | // We could be using an instruction with an extendable immediate and shoehorn |
| 1970 | // a global address into it. If it is a global address it will be constant |
| 1971 | // extended. We do this for COMBINE. |
| 1972 | // We currently only handle isGlobal() because it is the only kind of |
| 1973 | // object we are going to end up with here for now. |
| 1974 | // In the future we probably should add isSymbol(), etc. |
| 1975 | if (MO.isGlobal() || MO.isSymbol() || MO.isBlockAddress() || |
Krzysztof Parzyszek | a338650 | 2016-08-10 16:46:36 +0000 | [diff] [blame] | 1976 | MO.isJTI() || MO.isCPI() || MO.isFPImm()) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1977 | return true; |
| 1978 | |
| 1979 | // If the extendable operand is not 'Immediate' type, the instruction should |
| 1980 | // have 'isExtended' flag set. |
| 1981 | assert(MO.isImm() && "Extendable operand must be Immediate type"); |
| 1982 | |
| 1983 | int MinValue = getMinValue(MI); |
| 1984 | int MaxValue = getMaxValue(MI); |
| 1985 | int ImmValue = MO.getImm(); |
| 1986 | |
| 1987 | return (ImmValue < MinValue || ImmValue > MaxValue); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1991 | bool HexagonInstrInfo::isDeallocRet(const MachineInstr &MI) const { |
| 1992 | switch (MI.getOpcode()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1993 | case Hexagon::L4_return : |
| 1994 | case Hexagon::L4_return_t : |
| 1995 | case Hexagon::L4_return_f : |
| 1996 | case Hexagon::L4_return_tnew_pnt : |
| 1997 | case Hexagon::L4_return_fnew_pnt : |
| 1998 | case Hexagon::L4_return_tnew_pt : |
| 1999 | case Hexagon::L4_return_fnew_pt : |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2000 | return true; |
| 2001 | } |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2002 | return false; |
| 2003 | } |
| 2004 | |
| 2005 | |
| 2006 | // Return true when ConsMI uses a register defined by ProdMI. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2007 | bool HexagonInstrInfo::isDependent(const MachineInstr &ProdMI, |
| 2008 | const MachineInstr &ConsMI) const { |
| 2009 | if (!ProdMI.getDesc().getNumDefs()) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2010 | return false; |
| 2011 | |
| 2012 | auto &HRI = getRegisterInfo(); |
| 2013 | |
| 2014 | SmallVector<unsigned, 4> DefsA; |
| 2015 | SmallVector<unsigned, 4> DefsB; |
| 2016 | SmallVector<unsigned, 8> UsesA; |
| 2017 | SmallVector<unsigned, 8> UsesB; |
| 2018 | |
| 2019 | parseOperands(ProdMI, DefsA, UsesA); |
| 2020 | parseOperands(ConsMI, DefsB, UsesB); |
| 2021 | |
| 2022 | for (auto &RegA : DefsA) |
| 2023 | for (auto &RegB : UsesB) { |
| 2024 | // True data dependency. |
| 2025 | if (RegA == RegB) |
| 2026 | return true; |
| 2027 | |
| 2028 | if (Hexagon::DoubleRegsRegClass.contains(RegA)) |
| 2029 | for (MCSubRegIterator SubRegs(RegA, &HRI); SubRegs.isValid(); ++SubRegs) |
| 2030 | if (RegB == *SubRegs) |
| 2031 | return true; |
| 2032 | |
| 2033 | if (Hexagon::DoubleRegsRegClass.contains(RegB)) |
| 2034 | for (MCSubRegIterator SubRegs(RegB, &HRI); SubRegs.isValid(); ++SubRegs) |
| 2035 | if (RegA == *SubRegs) |
| 2036 | return true; |
| 2037 | } |
| 2038 | |
| 2039 | return false; |
| 2040 | } |
| 2041 | |
| 2042 | |
| 2043 | // Returns true if the instruction is alread a .cur. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2044 | bool HexagonInstrInfo::isDotCurInst(const MachineInstr &MI) const { |
| 2045 | switch (MI.getOpcode()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2046 | case Hexagon::V6_vL32b_cur_pi: |
| 2047 | case Hexagon::V6_vL32b_cur_ai: |
| 2048 | case Hexagon::V6_vL32b_cur_pi_128B: |
| 2049 | case Hexagon::V6_vL32b_cur_ai_128B: |
| 2050 | return true; |
| 2051 | } |
| 2052 | return false; |
| 2053 | } |
| 2054 | |
| 2055 | |
| 2056 | // Returns true, if any one of the operands is a dot new |
| 2057 | // insn, whether it is predicated dot new or register dot new. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2058 | bool HexagonInstrInfo::isDotNewInst(const MachineInstr &MI) const { |
| 2059 | if (isNewValueInst(MI) || (isPredicated(MI) && isPredicatedNew(MI))) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2060 | return true; |
| 2061 | |
| 2062 | return false; |
| 2063 | } |
| 2064 | |
| 2065 | |
| 2066 | /// Symmetrical. See if these two instructions are fit for duplex pair. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2067 | bool HexagonInstrInfo::isDuplexPair(const MachineInstr &MIa, |
| 2068 | const MachineInstr &MIb) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2069 | HexagonII::SubInstructionGroup MIaG = getDuplexCandidateGroup(MIa); |
| 2070 | HexagonII::SubInstructionGroup MIbG = getDuplexCandidateGroup(MIb); |
| 2071 | return (isDuplexPairMatch(MIaG, MIbG) || isDuplexPairMatch(MIbG, MIaG)); |
| 2072 | } |
| 2073 | |
| 2074 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2075 | bool HexagonInstrInfo::isEarlySourceInstr(const MachineInstr &MI) const { |
| 2076 | if (MI.mayLoad() || MI.mayStore() || MI.isCompare()) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2077 | return true; |
| 2078 | |
| 2079 | // Multiply |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2080 | unsigned SchedClass = MI.getDesc().getSchedClass(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2081 | if (SchedClass == Hexagon::Sched::M_tc_3or4x_SLOT23) |
| 2082 | return true; |
| 2083 | return false; |
| 2084 | } |
| 2085 | |
| 2086 | |
| 2087 | bool HexagonInstrInfo::isEndLoopN(unsigned Opcode) const { |
| 2088 | return (Opcode == Hexagon::ENDLOOP0 || |
| 2089 | Opcode == Hexagon::ENDLOOP1); |
| 2090 | } |
| 2091 | |
| 2092 | |
| 2093 | bool HexagonInstrInfo::isExpr(unsigned OpType) const { |
| 2094 | switch(OpType) { |
| 2095 | case MachineOperand::MO_MachineBasicBlock: |
| 2096 | case MachineOperand::MO_GlobalAddress: |
| 2097 | case MachineOperand::MO_ExternalSymbol: |
| 2098 | case MachineOperand::MO_JumpTableIndex: |
| 2099 | case MachineOperand::MO_ConstantPoolIndex: |
| 2100 | case MachineOperand::MO_BlockAddress: |
| 2101 | return true; |
| 2102 | default: |
| 2103 | return false; |
| 2104 | } |
| 2105 | } |
| 2106 | |
| 2107 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2108 | bool HexagonInstrInfo::isExtendable(const MachineInstr &MI) const { |
| 2109 | const MCInstrDesc &MID = MI.getDesc(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2110 | const uint64_t F = MID.TSFlags; |
| 2111 | if ((F >> HexagonII::ExtendablePos) & HexagonII::ExtendableMask) |
| 2112 | return true; |
| 2113 | |
| 2114 | // TODO: This is largely obsolete now. Will need to be removed |
| 2115 | // in consecutive patches. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2116 | switch (MI.getOpcode()) { |
Krzysztof Parzyszek | 1d01a79 | 2016-08-16 18:08:40 +0000 | [diff] [blame] | 2117 | // PS_fi and PS_fia remain special cases. |
| 2118 | case Hexagon::PS_fi: |
| 2119 | case Hexagon::PS_fia: |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2120 | return true; |
| 2121 | default: |
| 2122 | return false; |
| 2123 | } |
| 2124 | return false; |
| 2125 | } |
| 2126 | |
| 2127 | |
| 2128 | // This returns true in two cases: |
| 2129 | // - The OP code itself indicates that this is an extended instruction. |
| 2130 | // - One of MOs has been marked with HMOTF_ConstExtended flag. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2131 | bool HexagonInstrInfo::isExtended(const MachineInstr &MI) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2132 | // First check if this is permanently extended op code. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2133 | const uint64_t F = MI.getDesc().TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2134 | if ((F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask) |
| 2135 | return true; |
| 2136 | // Use MO operand flags to determine if one of MI's operands |
| 2137 | // has HMOTF_ConstExtended flag set. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2138 | for (MachineInstr::const_mop_iterator I = MI.operands_begin(), |
| 2139 | E = MI.operands_end(); I != E; ++I) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2140 | if (I->getTargetFlags() && HexagonII::HMOTF_ConstExtended) |
| 2141 | return true; |
| 2142 | } |
| 2143 | return false; |
| 2144 | } |
| 2145 | |
| 2146 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2147 | bool HexagonInstrInfo::isFloat(const MachineInstr &MI) const { |
| 2148 | unsigned Opcode = MI.getOpcode(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2149 | const uint64_t F = get(Opcode).TSFlags; |
| 2150 | return (F >> HexagonII::FPPos) & HexagonII::FPMask; |
| 2151 | } |
| 2152 | |
| 2153 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 2154 | // No V60 HVX VMEM with A_INDIRECT. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2155 | bool HexagonInstrInfo::isHVXMemWithAIndirect(const MachineInstr &I, |
| 2156 | const MachineInstr &J) const { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 2157 | if (!isV60VectorInstruction(I)) |
| 2158 | return false; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2159 | if (!I.mayLoad() && !I.mayStore()) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 2160 | return false; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2161 | return J.isIndirectBranch() || isIndirectCall(J) || isIndirectL4Return(J); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2165 | bool HexagonInstrInfo::isIndirectCall(const MachineInstr &MI) const { |
| 2166 | switch (MI.getOpcode()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2167 | case Hexagon::J2_callr : |
| 2168 | case Hexagon::J2_callrf : |
| 2169 | case Hexagon::J2_callrt : |
Krzysztof Parzyszek | 5a7bef9 | 2016-08-19 17:20:57 +0000 | [diff] [blame] | 2170 | case Hexagon::PS_call_nr : |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2171 | return true; |
| 2172 | } |
| 2173 | return false; |
| 2174 | } |
| 2175 | |
| 2176 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2177 | bool HexagonInstrInfo::isIndirectL4Return(const MachineInstr &MI) const { |
| 2178 | switch (MI.getOpcode()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2179 | case Hexagon::L4_return : |
| 2180 | case Hexagon::L4_return_t : |
| 2181 | case Hexagon::L4_return_f : |
| 2182 | case Hexagon::L4_return_fnew_pnt : |
| 2183 | case Hexagon::L4_return_fnew_pt : |
| 2184 | case Hexagon::L4_return_tnew_pnt : |
| 2185 | case Hexagon::L4_return_tnew_pt : |
| 2186 | return true; |
| 2187 | } |
| 2188 | return false; |
| 2189 | } |
| 2190 | |
| 2191 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2192 | bool HexagonInstrInfo::isJumpR(const MachineInstr &MI) const { |
| 2193 | switch (MI.getOpcode()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2194 | case Hexagon::J2_jumpr : |
| 2195 | case Hexagon::J2_jumprt : |
| 2196 | case Hexagon::J2_jumprf : |
| 2197 | case Hexagon::J2_jumprtnewpt : |
| 2198 | case Hexagon::J2_jumprfnewpt : |
| 2199 | case Hexagon::J2_jumprtnew : |
| 2200 | case Hexagon::J2_jumprfnew : |
| 2201 | return true; |
| 2202 | } |
| 2203 | return false; |
| 2204 | } |
| 2205 | |
| 2206 | |
| 2207 | // Return true if a given MI can accomodate given offset. |
| 2208 | // Use abs estimate as oppose to the exact number. |
| 2209 | // TODO: This will need to be changed to use MC level |
| 2210 | // definition of instruction extendable field size. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2211 | bool HexagonInstrInfo::isJumpWithinBranchRange(const MachineInstr &MI, |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2212 | unsigned offset) const { |
| 2213 | // This selection of jump instructions matches to that what |
| 2214 | // AnalyzeBranch can parse, plus NVJ. |
| 2215 | if (isNewValueJump(MI)) // r9:2 |
| 2216 | return isInt<11>(offset); |
| 2217 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2218 | switch (MI.getOpcode()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2219 | // Still missing Jump to address condition on register value. |
| 2220 | default: |
| 2221 | return false; |
| 2222 | case Hexagon::J2_jump: // bits<24> dst; // r22:2 |
| 2223 | case Hexagon::J2_call: |
Krzysztof Parzyszek | be976d4 | 2016-08-12 11:12:02 +0000 | [diff] [blame] | 2224 | case Hexagon::PS_call_nr: |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2225 | return isInt<24>(offset); |
| 2226 | case Hexagon::J2_jumpt: //bits<17> dst; // r15:2 |
| 2227 | case Hexagon::J2_jumpf: |
| 2228 | case Hexagon::J2_jumptnew: |
| 2229 | case Hexagon::J2_jumptnewpt: |
| 2230 | case Hexagon::J2_jumpfnew: |
| 2231 | case Hexagon::J2_jumpfnewpt: |
| 2232 | case Hexagon::J2_callt: |
| 2233 | case Hexagon::J2_callf: |
| 2234 | return isInt<17>(offset); |
| 2235 | case Hexagon::J2_loop0i: |
| 2236 | case Hexagon::J2_loop0iext: |
| 2237 | case Hexagon::J2_loop0r: |
| 2238 | case Hexagon::J2_loop0rext: |
| 2239 | case Hexagon::J2_loop1i: |
| 2240 | case Hexagon::J2_loop1iext: |
| 2241 | case Hexagon::J2_loop1r: |
| 2242 | case Hexagon::J2_loop1rext: |
| 2243 | return isInt<9>(offset); |
| 2244 | // TODO: Add all the compound branches here. Can we do this in Relation model? |
| 2245 | case Hexagon::J4_cmpeqi_tp0_jump_nt: |
| 2246 | case Hexagon::J4_cmpeqi_tp1_jump_nt: |
| 2247 | return isInt<11>(offset); |
| 2248 | } |
| 2249 | } |
| 2250 | |
| 2251 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2252 | bool HexagonInstrInfo::isLateInstrFeedsEarlyInstr(const MachineInstr &LRMI, |
| 2253 | const MachineInstr &ESMI) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2254 | bool isLate = isLateResultInstr(LRMI); |
| 2255 | bool isEarly = isEarlySourceInstr(ESMI); |
| 2256 | |
| 2257 | DEBUG(dbgs() << "V60" << (isLate ? "-LR " : " -- ")); |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2258 | DEBUG(LRMI.dump()); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2259 | DEBUG(dbgs() << "V60" << (isEarly ? "-ES " : " -- ")); |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2260 | DEBUG(ESMI.dump()); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2261 | |
| 2262 | if (isLate && isEarly) { |
| 2263 | DEBUG(dbgs() << "++Is Late Result feeding Early Source\n"); |
| 2264 | return true; |
| 2265 | } |
| 2266 | |
| 2267 | return false; |
| 2268 | } |
| 2269 | |
| 2270 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2271 | bool HexagonInstrInfo::isLateResultInstr(const MachineInstr &MI) const { |
| 2272 | switch (MI.getOpcode()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2273 | case TargetOpcode::EXTRACT_SUBREG: |
| 2274 | case TargetOpcode::INSERT_SUBREG: |
| 2275 | case TargetOpcode::SUBREG_TO_REG: |
| 2276 | case TargetOpcode::REG_SEQUENCE: |
| 2277 | case TargetOpcode::IMPLICIT_DEF: |
| 2278 | case TargetOpcode::COPY: |
| 2279 | case TargetOpcode::INLINEASM: |
| 2280 | case TargetOpcode::PHI: |
| 2281 | return false; |
| 2282 | default: |
| 2283 | break; |
| 2284 | } |
| 2285 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2286 | unsigned SchedClass = MI.getDesc().getSchedClass(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2287 | |
| 2288 | switch (SchedClass) { |
| 2289 | case Hexagon::Sched::ALU32_2op_tc_1_SLOT0123: |
| 2290 | case Hexagon::Sched::ALU32_3op_tc_1_SLOT0123: |
| 2291 | case Hexagon::Sched::ALU32_ADDI_tc_1_SLOT0123: |
| 2292 | case Hexagon::Sched::ALU64_tc_1_SLOT23: |
| 2293 | case Hexagon::Sched::EXTENDER_tc_1_SLOT0123: |
| 2294 | case Hexagon::Sched::S_2op_tc_1_SLOT23: |
| 2295 | case Hexagon::Sched::S_3op_tc_1_SLOT23: |
| 2296 | case Hexagon::Sched::V2LDST_tc_ld_SLOT01: |
| 2297 | case Hexagon::Sched::V2LDST_tc_st_SLOT0: |
| 2298 | case Hexagon::Sched::V2LDST_tc_st_SLOT01: |
| 2299 | case Hexagon::Sched::V4LDST_tc_ld_SLOT01: |
| 2300 | case Hexagon::Sched::V4LDST_tc_st_SLOT0: |
| 2301 | case Hexagon::Sched::V4LDST_tc_st_SLOT01: |
| 2302 | return false; |
| 2303 | } |
| 2304 | return true; |
| 2305 | } |
| 2306 | |
| 2307 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2308 | bool HexagonInstrInfo::isLateSourceInstr(const MachineInstr &MI) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2309 | // Instructions with iclass A_CVI_VX and attribute A_CVI_LATE uses a multiply |
| 2310 | // resource, but all operands can be received late like an ALU instruction. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2311 | return MI.getDesc().getSchedClass() == Hexagon::Sched::CVI_VX_LATE; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2315 | bool HexagonInstrInfo::isLoopN(const MachineInstr &MI) const { |
| 2316 | unsigned Opcode = MI.getOpcode(); |
Krzysztof Parzyszek | 5e6f2bd | 2015-12-14 21:32:25 +0000 | [diff] [blame] | 2317 | return Opcode == Hexagon::J2_loop0i || |
| 2318 | Opcode == Hexagon::J2_loop0r || |
| 2319 | Opcode == Hexagon::J2_loop0iext || |
| 2320 | Opcode == Hexagon::J2_loop0rext || |
| 2321 | Opcode == Hexagon::J2_loop1i || |
| 2322 | Opcode == Hexagon::J2_loop1r || |
| 2323 | Opcode == Hexagon::J2_loop1iext || |
| 2324 | Opcode == Hexagon::J2_loop1rext; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2325 | } |
| 2326 | |
| 2327 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2328 | bool HexagonInstrInfo::isMemOp(const MachineInstr &MI) const { |
| 2329 | switch (MI.getOpcode()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2330 | default: return false; |
| 2331 | case Hexagon::L4_iadd_memopw_io : |
| 2332 | case Hexagon::L4_isub_memopw_io : |
| 2333 | case Hexagon::L4_add_memopw_io : |
| 2334 | case Hexagon::L4_sub_memopw_io : |
| 2335 | case Hexagon::L4_and_memopw_io : |
| 2336 | case Hexagon::L4_or_memopw_io : |
| 2337 | case Hexagon::L4_iadd_memoph_io : |
| 2338 | case Hexagon::L4_isub_memoph_io : |
| 2339 | case Hexagon::L4_add_memoph_io : |
| 2340 | case Hexagon::L4_sub_memoph_io : |
| 2341 | case Hexagon::L4_and_memoph_io : |
| 2342 | case Hexagon::L4_or_memoph_io : |
| 2343 | case Hexagon::L4_iadd_memopb_io : |
| 2344 | case Hexagon::L4_isub_memopb_io : |
| 2345 | case Hexagon::L4_add_memopb_io : |
| 2346 | case Hexagon::L4_sub_memopb_io : |
| 2347 | case Hexagon::L4_and_memopb_io : |
| 2348 | case Hexagon::L4_or_memopb_io : |
| 2349 | case Hexagon::L4_ior_memopb_io: |
| 2350 | case Hexagon::L4_ior_memoph_io: |
| 2351 | case Hexagon::L4_ior_memopw_io: |
| 2352 | case Hexagon::L4_iand_memopb_io: |
| 2353 | case Hexagon::L4_iand_memoph_io: |
| 2354 | case Hexagon::L4_iand_memopw_io: |
| 2355 | return true; |
| 2356 | } |
| 2357 | return false; |
| 2358 | } |
| 2359 | |
| 2360 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2361 | bool HexagonInstrInfo::isNewValue(const MachineInstr &MI) const { |
| 2362 | const uint64_t F = MI.getDesc().TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2363 | return (F >> HexagonII::NewValuePos) & HexagonII::NewValueMask; |
| 2364 | } |
| 2365 | |
| 2366 | |
| 2367 | bool HexagonInstrInfo::isNewValue(unsigned Opcode) const { |
| 2368 | const uint64_t F = get(Opcode).TSFlags; |
| 2369 | return (F >> HexagonII::NewValuePos) & HexagonII::NewValueMask; |
| 2370 | } |
| 2371 | |
| 2372 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2373 | bool HexagonInstrInfo::isNewValueInst(const MachineInstr &MI) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2374 | return isNewValueJump(MI) || isNewValueStore(MI); |
| 2375 | } |
| 2376 | |
| 2377 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2378 | bool HexagonInstrInfo::isNewValueJump(const MachineInstr &MI) const { |
| 2379 | return isNewValue(MI) && MI.isBranch(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2380 | } |
| 2381 | |
| 2382 | |
| 2383 | bool HexagonInstrInfo::isNewValueJump(unsigned Opcode) const { |
| 2384 | return isNewValue(Opcode) && get(Opcode).isBranch() && isPredicated(Opcode); |
| 2385 | } |
| 2386 | |
| 2387 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2388 | bool HexagonInstrInfo::isNewValueStore(const MachineInstr &MI) const { |
| 2389 | const uint64_t F = MI.getDesc().TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2390 | return (F >> HexagonII::NVStorePos) & HexagonII::NVStoreMask; |
| 2391 | } |
| 2392 | |
| 2393 | |
| 2394 | bool HexagonInstrInfo::isNewValueStore(unsigned Opcode) const { |
| 2395 | const uint64_t F = get(Opcode).TSFlags; |
| 2396 | return (F >> HexagonII::NVStorePos) & HexagonII::NVStoreMask; |
| 2397 | } |
| 2398 | |
| 2399 | |
| 2400 | // Returns true if a particular operand is extendable for an instruction. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2401 | bool HexagonInstrInfo::isOperandExtended(const MachineInstr &MI, |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2402 | unsigned OperandNum) const { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2403 | const uint64_t F = MI.getDesc().TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2404 | return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask) |
| 2405 | == OperandNum; |
| 2406 | } |
| 2407 | |
| 2408 | |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 2409 | bool HexagonInstrInfo::isPredicatedNew(const MachineInstr &MI) const { |
| 2410 | const uint64_t F = MI.getDesc().TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2411 | assert(isPredicated(MI)); |
| 2412 | return (F >> HexagonII::PredicatedNewPos) & HexagonII::PredicatedNewMask; |
| 2413 | } |
| 2414 | |
| 2415 | |
| 2416 | bool HexagonInstrInfo::isPredicatedNew(unsigned Opcode) const { |
| 2417 | const uint64_t F = get(Opcode).TSFlags; |
| 2418 | assert(isPredicated(Opcode)); |
| 2419 | return (F >> HexagonII::PredicatedNewPos) & HexagonII::PredicatedNewMask; |
| 2420 | } |
| 2421 | |
| 2422 | |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 2423 | bool HexagonInstrInfo::isPredicatedTrue(const MachineInstr &MI) const { |
| 2424 | const uint64_t F = MI.getDesc().TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2425 | return !((F >> HexagonII::PredicatedFalsePos) & |
| 2426 | HexagonII::PredicatedFalseMask); |
| 2427 | } |
| 2428 | |
| 2429 | |
| 2430 | bool HexagonInstrInfo::isPredicatedTrue(unsigned Opcode) const { |
| 2431 | const uint64_t F = get(Opcode).TSFlags; |
| 2432 | // Make sure that the instruction is predicated. |
| 2433 | assert((F>> HexagonII::PredicatedPos) & HexagonII::PredicatedMask); |
| 2434 | return !((F >> HexagonII::PredicatedFalsePos) & |
| 2435 | HexagonII::PredicatedFalseMask); |
| 2436 | } |
| 2437 | |
| 2438 | |
| 2439 | bool HexagonInstrInfo::isPredicated(unsigned Opcode) const { |
| 2440 | const uint64_t F = get(Opcode).TSFlags; |
| 2441 | return (F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask; |
| 2442 | } |
| 2443 | |
| 2444 | |
| 2445 | bool HexagonInstrInfo::isPredicateLate(unsigned Opcode) const { |
| 2446 | const uint64_t F = get(Opcode).TSFlags; |
| 2447 | return ~(F >> HexagonII::PredicateLatePos) & HexagonII::PredicateLateMask; |
| 2448 | } |
| 2449 | |
| 2450 | |
| 2451 | bool HexagonInstrInfo::isPredictedTaken(unsigned Opcode) const { |
| 2452 | const uint64_t F = get(Opcode).TSFlags; |
| 2453 | assert(get(Opcode).isBranch() && |
| 2454 | (isPredicatedNew(Opcode) || isNewValue(Opcode))); |
| 2455 | return (F >> HexagonII::TakenPos) & HexagonII::TakenMask; |
| 2456 | } |
| 2457 | |
| 2458 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2459 | bool HexagonInstrInfo::isSaveCalleeSavedRegsCall(const MachineInstr &MI) const { |
| 2460 | return MI.getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4 || |
| 2461 | MI.getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4_EXT || |
| 2462 | MI.getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4_PIC || |
| 2463 | MI.getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4_EXT_PIC; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2464 | } |
| 2465 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 2466 | bool HexagonInstrInfo::isSignExtendingLoad(const MachineInstr &MI) const { |
| 2467 | switch (MI.getOpcode()) { |
| 2468 | // Byte |
| 2469 | case Hexagon::L2_loadrb_io: |
| 2470 | case Hexagon::L4_loadrb_ur: |
| 2471 | case Hexagon::L4_loadrb_ap: |
| 2472 | case Hexagon::L2_loadrb_pr: |
| 2473 | case Hexagon::L2_loadrb_pbr: |
| 2474 | case Hexagon::L2_loadrb_pi: |
| 2475 | case Hexagon::L2_loadrb_pci: |
| 2476 | case Hexagon::L2_loadrb_pcr: |
| 2477 | case Hexagon::L2_loadbsw2_io: |
| 2478 | case Hexagon::L4_loadbsw2_ur: |
| 2479 | case Hexagon::L4_loadbsw2_ap: |
| 2480 | case Hexagon::L2_loadbsw2_pr: |
| 2481 | case Hexagon::L2_loadbsw2_pbr: |
| 2482 | case Hexagon::L2_loadbsw2_pi: |
| 2483 | case Hexagon::L2_loadbsw2_pci: |
| 2484 | case Hexagon::L2_loadbsw2_pcr: |
| 2485 | case Hexagon::L2_loadbsw4_io: |
| 2486 | case Hexagon::L4_loadbsw4_ur: |
| 2487 | case Hexagon::L4_loadbsw4_ap: |
| 2488 | case Hexagon::L2_loadbsw4_pr: |
| 2489 | case Hexagon::L2_loadbsw4_pbr: |
| 2490 | case Hexagon::L2_loadbsw4_pi: |
| 2491 | case Hexagon::L2_loadbsw4_pci: |
| 2492 | case Hexagon::L2_loadbsw4_pcr: |
| 2493 | case Hexagon::L4_loadrb_rr: |
| 2494 | case Hexagon::L2_ploadrbt_io: |
| 2495 | case Hexagon::L2_ploadrbt_pi: |
| 2496 | case Hexagon::L2_ploadrbf_io: |
| 2497 | case Hexagon::L2_ploadrbf_pi: |
| 2498 | case Hexagon::L2_ploadrbtnew_io: |
| 2499 | case Hexagon::L2_ploadrbfnew_io: |
| 2500 | case Hexagon::L4_ploadrbt_rr: |
| 2501 | case Hexagon::L4_ploadrbf_rr: |
| 2502 | case Hexagon::L4_ploadrbtnew_rr: |
| 2503 | case Hexagon::L4_ploadrbfnew_rr: |
| 2504 | case Hexagon::L2_ploadrbtnew_pi: |
| 2505 | case Hexagon::L2_ploadrbfnew_pi: |
| 2506 | case Hexagon::L4_ploadrbt_abs: |
| 2507 | case Hexagon::L4_ploadrbf_abs: |
| 2508 | case Hexagon::L4_ploadrbtnew_abs: |
| 2509 | case Hexagon::L4_ploadrbfnew_abs: |
| 2510 | case Hexagon::L2_loadrbgp: |
| 2511 | // Half |
| 2512 | case Hexagon::L2_loadrh_io: |
| 2513 | case Hexagon::L4_loadrh_ur: |
| 2514 | case Hexagon::L4_loadrh_ap: |
| 2515 | case Hexagon::L2_loadrh_pr: |
| 2516 | case Hexagon::L2_loadrh_pbr: |
| 2517 | case Hexagon::L2_loadrh_pi: |
| 2518 | case Hexagon::L2_loadrh_pci: |
| 2519 | case Hexagon::L2_loadrh_pcr: |
| 2520 | case Hexagon::L4_loadrh_rr: |
| 2521 | case Hexagon::L2_ploadrht_io: |
| 2522 | case Hexagon::L2_ploadrht_pi: |
| 2523 | case Hexagon::L2_ploadrhf_io: |
| 2524 | case Hexagon::L2_ploadrhf_pi: |
| 2525 | case Hexagon::L2_ploadrhtnew_io: |
| 2526 | case Hexagon::L2_ploadrhfnew_io: |
| 2527 | case Hexagon::L4_ploadrht_rr: |
| 2528 | case Hexagon::L4_ploadrhf_rr: |
| 2529 | case Hexagon::L4_ploadrhtnew_rr: |
| 2530 | case Hexagon::L4_ploadrhfnew_rr: |
| 2531 | case Hexagon::L2_ploadrhtnew_pi: |
| 2532 | case Hexagon::L2_ploadrhfnew_pi: |
| 2533 | case Hexagon::L4_ploadrht_abs: |
| 2534 | case Hexagon::L4_ploadrhf_abs: |
| 2535 | case Hexagon::L4_ploadrhtnew_abs: |
| 2536 | case Hexagon::L4_ploadrhfnew_abs: |
| 2537 | case Hexagon::L2_loadrhgp: |
| 2538 | return true; |
| 2539 | default: |
| 2540 | return false; |
Krzysztof Parzyszek | fd02aad | 2016-02-12 18:37:23 +0000 | [diff] [blame] | 2541 | } |
| 2542 | } |
| 2543 | |
| 2544 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2545 | bool HexagonInstrInfo::isSolo(const MachineInstr &MI) const { |
| 2546 | const uint64_t F = MI.getDesc().TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2547 | return (F >> HexagonII::SoloPos) & HexagonII::SoloMask; |
| 2548 | } |
| 2549 | |
| 2550 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2551 | bool HexagonInstrInfo::isSpillPredRegOp(const MachineInstr &MI) const { |
| 2552 | switch (MI.getOpcode()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2553 | case Hexagon::STriw_pred : |
| 2554 | case Hexagon::LDriw_pred : |
| 2555 | return true; |
| 2556 | default: |
| 2557 | return false; |
| 2558 | } |
| 2559 | } |
| 2560 | |
| 2561 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2562 | bool HexagonInstrInfo::isTailCall(const MachineInstr &MI) const { |
| 2563 | if (!MI.isBranch()) |
Krzysztof Parzyszek | ecea07c | 2016-07-14 19:30:55 +0000 | [diff] [blame] | 2564 | return false; |
| 2565 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2566 | for (auto &Op : MI.operands()) |
Krzysztof Parzyszek | ecea07c | 2016-07-14 19:30:55 +0000 | [diff] [blame] | 2567 | if (Op.isGlobal() || Op.isSymbol()) |
| 2568 | return true; |
| 2569 | return false; |
| 2570 | } |
| 2571 | |
| 2572 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2573 | // Returns true when SU has a timing class TC1. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2574 | bool HexagonInstrInfo::isTC1(const MachineInstr &MI) const { |
| 2575 | unsigned SchedClass = MI.getDesc().getSchedClass(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2576 | switch (SchedClass) { |
| 2577 | case Hexagon::Sched::ALU32_2op_tc_1_SLOT0123: |
| 2578 | case Hexagon::Sched::ALU32_3op_tc_1_SLOT0123: |
| 2579 | case Hexagon::Sched::ALU32_ADDI_tc_1_SLOT0123: |
| 2580 | case Hexagon::Sched::ALU64_tc_1_SLOT23: |
| 2581 | case Hexagon::Sched::EXTENDER_tc_1_SLOT0123: |
| 2582 | //case Hexagon::Sched::M_tc_1_SLOT23: |
| 2583 | case Hexagon::Sched::S_2op_tc_1_SLOT23: |
| 2584 | case Hexagon::Sched::S_3op_tc_1_SLOT23: |
| 2585 | return true; |
| 2586 | |
| 2587 | default: |
| 2588 | return false; |
| 2589 | } |
| 2590 | } |
| 2591 | |
| 2592 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2593 | bool HexagonInstrInfo::isTC2(const MachineInstr &MI) const { |
| 2594 | unsigned SchedClass = MI.getDesc().getSchedClass(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2595 | switch (SchedClass) { |
| 2596 | case Hexagon::Sched::ALU32_3op_tc_2_SLOT0123: |
| 2597 | case Hexagon::Sched::ALU64_tc_2_SLOT23: |
| 2598 | case Hexagon::Sched::CR_tc_2_SLOT3: |
| 2599 | case Hexagon::Sched::M_tc_2_SLOT23: |
| 2600 | case Hexagon::Sched::S_2op_tc_2_SLOT23: |
| 2601 | case Hexagon::Sched::S_3op_tc_2_SLOT23: |
| 2602 | return true; |
| 2603 | |
| 2604 | default: |
| 2605 | return false; |
| 2606 | } |
| 2607 | } |
| 2608 | |
| 2609 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2610 | bool HexagonInstrInfo::isTC2Early(const MachineInstr &MI) const { |
| 2611 | unsigned SchedClass = MI.getDesc().getSchedClass(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2612 | switch (SchedClass) { |
| 2613 | case Hexagon::Sched::ALU32_2op_tc_2early_SLOT0123: |
| 2614 | case Hexagon::Sched::ALU32_3op_tc_2early_SLOT0123: |
| 2615 | case Hexagon::Sched::ALU64_tc_2early_SLOT23: |
| 2616 | case Hexagon::Sched::CR_tc_2early_SLOT23: |
| 2617 | case Hexagon::Sched::CR_tc_2early_SLOT3: |
| 2618 | case Hexagon::Sched::J_tc_2early_SLOT0123: |
| 2619 | case Hexagon::Sched::J_tc_2early_SLOT2: |
| 2620 | case Hexagon::Sched::J_tc_2early_SLOT23: |
| 2621 | case Hexagon::Sched::S_2op_tc_2early_SLOT23: |
| 2622 | case Hexagon::Sched::S_3op_tc_2early_SLOT23: |
| 2623 | return true; |
| 2624 | |
| 2625 | default: |
| 2626 | return false; |
| 2627 | } |
| 2628 | } |
| 2629 | |
| 2630 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2631 | bool HexagonInstrInfo::isTC4x(const MachineInstr &MI) const { |
| 2632 | unsigned SchedClass = MI.getDesc().getSchedClass(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2633 | return SchedClass == Hexagon::Sched::M_tc_3or4x_SLOT23; |
| 2634 | } |
| 2635 | |
| 2636 | |
Krzysztof Parzyszek | 408e300 | 2016-07-15 21:34:02 +0000 | [diff] [blame] | 2637 | // Schedule this ASAP. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2638 | bool HexagonInstrInfo::isToBeScheduledASAP(const MachineInstr &MI1, |
| 2639 | const MachineInstr &MI2) const { |
Krzysztof Parzyszek | 408e300 | 2016-07-15 21:34:02 +0000 | [diff] [blame] | 2640 | if (mayBeCurLoad(MI1)) { |
| 2641 | // if (result of SU is used in Next) return true; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2642 | unsigned DstReg = MI1.getOperand(0).getReg(); |
| 2643 | int N = MI2.getNumOperands(); |
Krzysztof Parzyszek | 408e300 | 2016-07-15 21:34:02 +0000 | [diff] [blame] | 2644 | for (int I = 0; I < N; I++) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2645 | if (MI2.getOperand(I).isReg() && DstReg == MI2.getOperand(I).getReg()) |
Krzysztof Parzyszek | 408e300 | 2016-07-15 21:34:02 +0000 | [diff] [blame] | 2646 | return true; |
| 2647 | } |
| 2648 | if (mayBeNewStore(MI2)) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2649 | if (MI2.getOpcode() == Hexagon::V6_vS32b_pi) |
| 2650 | if (MI1.getOperand(0).isReg() && MI2.getOperand(3).isReg() && |
| 2651 | MI1.getOperand(0).getReg() == MI2.getOperand(3).getReg()) |
Krzysztof Parzyszek | 408e300 | 2016-07-15 21:34:02 +0000 | [diff] [blame] | 2652 | return true; |
| 2653 | return false; |
| 2654 | } |
| 2655 | |
| 2656 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2657 | bool HexagonInstrInfo::isV60VectorInstruction(const MachineInstr &MI) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2658 | const uint64_t V = getType(MI); |
| 2659 | return HexagonII::TypeCVI_FIRST <= V && V <= HexagonII::TypeCVI_LAST; |
| 2660 | } |
| 2661 | |
| 2662 | |
| 2663 | // Check if the Offset is a valid auto-inc imm by Load/Store Type. |
| 2664 | // |
| 2665 | bool HexagonInstrInfo::isValidAutoIncImm(const EVT VT, const int Offset) const { |
| 2666 | if (VT == MVT::v16i32 || VT == MVT::v8i64 || |
| 2667 | VT == MVT::v32i16 || VT == MVT::v64i8) { |
| 2668 | return (Offset >= Hexagon_MEMV_AUTOINC_MIN && |
| 2669 | Offset <= Hexagon_MEMV_AUTOINC_MAX && |
| 2670 | (Offset & 0x3f) == 0); |
| 2671 | } |
| 2672 | // 128B |
| 2673 | if (VT == MVT::v32i32 || VT == MVT::v16i64 || |
| 2674 | VT == MVT::v64i16 || VT == MVT::v128i8) { |
| 2675 | return (Offset >= Hexagon_MEMV_AUTOINC_MIN_128B && |
| 2676 | Offset <= Hexagon_MEMV_AUTOINC_MAX_128B && |
| 2677 | (Offset & 0x7f) == 0); |
| 2678 | } |
| 2679 | if (VT == MVT::i64) { |
| 2680 | return (Offset >= Hexagon_MEMD_AUTOINC_MIN && |
| 2681 | Offset <= Hexagon_MEMD_AUTOINC_MAX && |
| 2682 | (Offset & 0x7) == 0); |
| 2683 | } |
| 2684 | if (VT == MVT::i32) { |
| 2685 | return (Offset >= Hexagon_MEMW_AUTOINC_MIN && |
| 2686 | Offset <= Hexagon_MEMW_AUTOINC_MAX && |
| 2687 | (Offset & 0x3) == 0); |
| 2688 | } |
| 2689 | if (VT == MVT::i16) { |
| 2690 | return (Offset >= Hexagon_MEMH_AUTOINC_MIN && |
| 2691 | Offset <= Hexagon_MEMH_AUTOINC_MAX && |
| 2692 | (Offset & 0x1) == 0); |
| 2693 | } |
| 2694 | if (VT == MVT::i8) { |
| 2695 | return (Offset >= Hexagon_MEMB_AUTOINC_MIN && |
| 2696 | Offset <= Hexagon_MEMB_AUTOINC_MAX); |
| 2697 | } |
| 2698 | llvm_unreachable("Not an auto-inc opc!"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2699 | } |
| 2700 | |
| 2701 | |
Krzysztof Parzyszek | 0590216 | 2015-04-22 17:51:26 +0000 | [diff] [blame] | 2702 | bool HexagonInstrInfo::isValidOffset(unsigned Opcode, int Offset, |
| 2703 | bool Extend) const { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2704 | // 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] | 2705 | // 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] | 2706 | // inserted to calculate the final address. Due to this reason, the function |
| 2707 | // assumes that the "Offset" has correct alignment. |
Jyotsna Verma | ec61366 | 2013-03-14 19:08:03 +0000 | [diff] [blame] | 2708 | // We used to assert if the offset was not properly aligned, however, |
| 2709 | // there are cases where a misaligned pointer recast can cause this |
| 2710 | // problem, and we need to allow for it. The front end warns of such |
| 2711 | // misaligns with respect to load size. |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2712 | |
Krzysztof Parzyszek | 0590216 | 2015-04-22 17:51:26 +0000 | [diff] [blame] | 2713 | switch (Opcode) { |
Krzysztof Parzyszek | 17aa413 | 2016-08-16 15:43:54 +0000 | [diff] [blame] | 2714 | case Hexagon::PS_vstorerq_ai: |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 2715 | case Hexagon::PS_vstorerw_ai: |
Krzysztof Parzyszek | 17aa413 | 2016-08-16 15:43:54 +0000 | [diff] [blame] | 2716 | case Hexagon::PS_vloadrq_ai: |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 2717 | case Hexagon::PS_vloadrw_ai: |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2718 | case Hexagon::V6_vL32b_ai: |
| 2719 | case Hexagon::V6_vS32b_ai: |
| 2720 | case Hexagon::V6_vL32Ub_ai: |
| 2721 | case Hexagon::V6_vS32Ub_ai: |
| 2722 | return (Offset >= Hexagon_MEMV_OFFSET_MIN) && |
| 2723 | (Offset <= Hexagon_MEMV_OFFSET_MAX); |
| 2724 | |
Krzysztof Parzyszek | 17aa413 | 2016-08-16 15:43:54 +0000 | [diff] [blame] | 2725 | case Hexagon::PS_vstorerq_ai_128B: |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 2726 | case Hexagon::PS_vstorerw_ai_128B: |
Krzysztof Parzyszek | 17aa413 | 2016-08-16 15:43:54 +0000 | [diff] [blame] | 2727 | case Hexagon::PS_vloadrq_ai_128B: |
Krzysztof Parzyszek | f285963 | 2016-08-12 21:05:05 +0000 | [diff] [blame] | 2728 | case Hexagon::PS_vloadrw_ai_128B: |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2729 | case Hexagon::V6_vL32b_ai_128B: |
| 2730 | case Hexagon::V6_vS32b_ai_128B: |
| 2731 | case Hexagon::V6_vL32Ub_ai_128B: |
| 2732 | case Hexagon::V6_vS32Ub_ai_128B: |
| 2733 | return (Offset >= Hexagon_MEMV_OFFSET_MIN_128B) && |
| 2734 | (Offset <= Hexagon_MEMV_OFFSET_MAX_128B); |
| 2735 | |
Krzysztof Parzyszek | 0590216 | 2015-04-22 17:51:26 +0000 | [diff] [blame] | 2736 | case Hexagon::J2_loop0i: |
| 2737 | case Hexagon::J2_loop1i: |
| 2738 | return isUInt<10>(Offset); |
Krzysztof Parzyszek | bba0bf7 | 2016-07-15 15:35:52 +0000 | [diff] [blame] | 2739 | |
| 2740 | case Hexagon::S4_storeirb_io: |
| 2741 | case Hexagon::S4_storeirbt_io: |
| 2742 | case Hexagon::S4_storeirbf_io: |
| 2743 | return isUInt<6>(Offset); |
| 2744 | |
| 2745 | case Hexagon::S4_storeirh_io: |
| 2746 | case Hexagon::S4_storeirht_io: |
| 2747 | case Hexagon::S4_storeirhf_io: |
| 2748 | return isShiftedUInt<6,1>(Offset); |
| 2749 | |
| 2750 | case Hexagon::S4_storeiri_io: |
| 2751 | case Hexagon::S4_storeirit_io: |
| 2752 | case Hexagon::S4_storeirif_io: |
| 2753 | return isShiftedUInt<6,2>(Offset); |
Krzysztof Parzyszek | 0590216 | 2015-04-22 17:51:26 +0000 | [diff] [blame] | 2754 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2755 | |
Krzysztof Parzyszek | 0590216 | 2015-04-22 17:51:26 +0000 | [diff] [blame] | 2756 | if (Extend) |
| 2757 | return true; |
| 2758 | |
| 2759 | switch (Opcode) { |
Colin LeMahieu | 026e88d | 2014-12-23 20:02:16 +0000 | [diff] [blame] | 2760 | case Hexagon::L2_loadri_io: |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 2761 | case Hexagon::S2_storeri_io: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2762 | return (Offset >= Hexagon_MEMW_OFFSET_MIN) && |
| 2763 | (Offset <= Hexagon_MEMW_OFFSET_MAX); |
| 2764 | |
Colin LeMahieu | 947cd70 | 2014-12-23 20:44:59 +0000 | [diff] [blame] | 2765 | case Hexagon::L2_loadrd_io: |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 2766 | case Hexagon::S2_storerd_io: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2767 | return (Offset >= Hexagon_MEMD_OFFSET_MIN) && |
| 2768 | (Offset <= Hexagon_MEMD_OFFSET_MAX); |
| 2769 | |
Colin LeMahieu | 8e39cad | 2014-12-23 17:25:57 +0000 | [diff] [blame] | 2770 | case Hexagon::L2_loadrh_io: |
Colin LeMahieu | a9386d2 | 2014-12-23 16:42:57 +0000 | [diff] [blame] | 2771 | case Hexagon::L2_loadruh_io: |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 2772 | case Hexagon::S2_storerh_io: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2773 | return (Offset >= Hexagon_MEMH_OFFSET_MIN) && |
| 2774 | (Offset <= Hexagon_MEMH_OFFSET_MAX); |
| 2775 | |
Colin LeMahieu | 4b1eac4 | 2014-12-22 21:40:43 +0000 | [diff] [blame] | 2776 | case Hexagon::L2_loadrb_io: |
Colin LeMahieu | af1e5de | 2014-12-22 21:20:03 +0000 | [diff] [blame] | 2777 | case Hexagon::L2_loadrub_io: |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2778 | case Hexagon::S2_storerb_io: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2779 | return (Offset >= Hexagon_MEMB_OFFSET_MIN) && |
| 2780 | (Offset <= Hexagon_MEMB_OFFSET_MAX); |
| 2781 | |
Colin LeMahieu | f297dbe | 2015-02-05 17:49:13 +0000 | [diff] [blame] | 2782 | case Hexagon::A2_addi: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2783 | return (Offset >= Hexagon_ADDI_OFFSET_MIN) && |
| 2784 | (Offset <= Hexagon_ADDI_OFFSET_MAX); |
| 2785 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2786 | case Hexagon::L4_iadd_memopw_io : |
| 2787 | case Hexagon::L4_isub_memopw_io : |
| 2788 | case Hexagon::L4_add_memopw_io : |
| 2789 | case Hexagon::L4_sub_memopw_io : |
| 2790 | case Hexagon::L4_and_memopw_io : |
| 2791 | case Hexagon::L4_or_memopw_io : |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2792 | return (0 <= Offset && Offset <= 255); |
| 2793 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2794 | case Hexagon::L4_iadd_memoph_io : |
| 2795 | case Hexagon::L4_isub_memoph_io : |
| 2796 | case Hexagon::L4_add_memoph_io : |
| 2797 | case Hexagon::L4_sub_memoph_io : |
| 2798 | case Hexagon::L4_and_memoph_io : |
| 2799 | case Hexagon::L4_or_memoph_io : |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2800 | return (0 <= Offset && Offset <= 127); |
| 2801 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2802 | case Hexagon::L4_iadd_memopb_io : |
| 2803 | case Hexagon::L4_isub_memopb_io : |
| 2804 | case Hexagon::L4_add_memopb_io : |
| 2805 | case Hexagon::L4_sub_memopb_io : |
| 2806 | case Hexagon::L4_and_memopb_io : |
| 2807 | case Hexagon::L4_or_memopb_io : |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2808 | return (0 <= Offset && Offset <= 63); |
| 2809 | |
Krzysztof Parzyszek | fd02aad | 2016-02-12 18:37:23 +0000 | [diff] [blame] | 2810 | // LDriw_xxx and STriw_xxx are pseudo operations, so it has to take offset of |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2811 | // any size. Later pass knows how to handle it. |
| 2812 | case Hexagon::STriw_pred: |
| 2813 | case Hexagon::LDriw_pred: |
Krzysztof Parzyszek | 7b413c6 | 2016-01-22 19:15:58 +0000 | [diff] [blame] | 2814 | case Hexagon::STriw_mod: |
| 2815 | case Hexagon::LDriw_mod: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2816 | return true; |
| 2817 | |
Krzysztof Parzyszek | 1d01a79 | 2016-08-16 18:08:40 +0000 | [diff] [blame] | 2818 | case Hexagon::PS_fi: |
| 2819 | case Hexagon::PS_fia: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2820 | case Hexagon::INLINEASM: |
| 2821 | return true; |
Krzysztof Parzyszek | fb33824 | 2015-10-06 15:49:14 +0000 | [diff] [blame] | 2822 | |
| 2823 | case Hexagon::L2_ploadrbt_io: |
| 2824 | case Hexagon::L2_ploadrbf_io: |
| 2825 | case Hexagon::L2_ploadrubt_io: |
| 2826 | case Hexagon::L2_ploadrubf_io: |
| 2827 | case Hexagon::S2_pstorerbt_io: |
| 2828 | case Hexagon::S2_pstorerbf_io: |
Krzysztof Parzyszek | fb33824 | 2015-10-06 15:49:14 +0000 | [diff] [blame] | 2829 | return isUInt<6>(Offset); |
| 2830 | |
| 2831 | case Hexagon::L2_ploadrht_io: |
| 2832 | case Hexagon::L2_ploadrhf_io: |
| 2833 | case Hexagon::L2_ploadruht_io: |
| 2834 | case Hexagon::L2_ploadruhf_io: |
| 2835 | case Hexagon::S2_pstorerht_io: |
| 2836 | case Hexagon::S2_pstorerhf_io: |
Krzysztof Parzyszek | fb33824 | 2015-10-06 15:49:14 +0000 | [diff] [blame] | 2837 | return isShiftedUInt<6,1>(Offset); |
| 2838 | |
| 2839 | case Hexagon::L2_ploadrit_io: |
| 2840 | case Hexagon::L2_ploadrif_io: |
| 2841 | case Hexagon::S2_pstorerit_io: |
| 2842 | case Hexagon::S2_pstorerif_io: |
Krzysztof Parzyszek | fb33824 | 2015-10-06 15:49:14 +0000 | [diff] [blame] | 2843 | return isShiftedUInt<6,2>(Offset); |
| 2844 | |
| 2845 | case Hexagon::L2_ploadrdt_io: |
| 2846 | case Hexagon::L2_ploadrdf_io: |
| 2847 | case Hexagon::S2_pstorerdt_io: |
| 2848 | case Hexagon::S2_pstorerdf_io: |
| 2849 | return isShiftedUInt<6,3>(Offset); |
| 2850 | } // switch |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2851 | |
Benjamin Kramer | b668401 | 2011-12-27 11:41:05 +0000 | [diff] [blame] | 2852 | llvm_unreachable("No offset range is defined for this opcode. " |
| 2853 | "Please define it in the above switch statement!"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2854 | } |
| 2855 | |
| 2856 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2857 | bool HexagonInstrInfo::isVecAcc(const MachineInstr &MI) const { |
| 2858 | return isV60VectorInstruction(MI) && isAccumulator(MI); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2859 | } |
| 2860 | |
| 2861 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2862 | bool HexagonInstrInfo::isVecALU(const MachineInstr &MI) const { |
| 2863 | const uint64_t F = get(MI.getOpcode()).TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2864 | const uint64_t V = ((F >> HexagonII::TypePos) & HexagonII::TypeMask); |
| 2865 | return |
| 2866 | V == HexagonII::TypeCVI_VA || |
| 2867 | V == HexagonII::TypeCVI_VA_DV; |
| 2868 | } |
Andrew Trick | d06df96 | 2012-02-01 22:13:57 +0000 | [diff] [blame] | 2869 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2870 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2871 | bool HexagonInstrInfo::isVecUsableNextPacket(const MachineInstr &ProdMI, |
| 2872 | const MachineInstr &ConsMI) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2873 | if (EnableACCForwarding && isVecAcc(ProdMI) && isVecAcc(ConsMI)) |
| 2874 | return true; |
| 2875 | |
| 2876 | if (EnableALUForwarding && (isVecALU(ConsMI) || isLateSourceInstr(ConsMI))) |
| 2877 | return true; |
| 2878 | |
| 2879 | if (mayBeNewStore(ConsMI)) |
Andrew Trick | d06df96 | 2012-02-01 22:13:57 +0000 | [diff] [blame] | 2880 | return true; |
| 2881 | |
| 2882 | return false; |
| 2883 | } |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 2884 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 2885 | bool HexagonInstrInfo::isZeroExtendingLoad(const MachineInstr &MI) const { |
| 2886 | switch (MI.getOpcode()) { |
| 2887 | // Byte |
| 2888 | case Hexagon::L2_loadrub_io: |
| 2889 | case Hexagon::L4_loadrub_ur: |
| 2890 | case Hexagon::L4_loadrub_ap: |
| 2891 | case Hexagon::L2_loadrub_pr: |
| 2892 | case Hexagon::L2_loadrub_pbr: |
| 2893 | case Hexagon::L2_loadrub_pi: |
| 2894 | case Hexagon::L2_loadrub_pci: |
| 2895 | case Hexagon::L2_loadrub_pcr: |
| 2896 | case Hexagon::L2_loadbzw2_io: |
| 2897 | case Hexagon::L4_loadbzw2_ur: |
| 2898 | case Hexagon::L4_loadbzw2_ap: |
| 2899 | case Hexagon::L2_loadbzw2_pr: |
| 2900 | case Hexagon::L2_loadbzw2_pbr: |
| 2901 | case Hexagon::L2_loadbzw2_pi: |
| 2902 | case Hexagon::L2_loadbzw2_pci: |
| 2903 | case Hexagon::L2_loadbzw2_pcr: |
| 2904 | case Hexagon::L2_loadbzw4_io: |
| 2905 | case Hexagon::L4_loadbzw4_ur: |
| 2906 | case Hexagon::L4_loadbzw4_ap: |
| 2907 | case Hexagon::L2_loadbzw4_pr: |
| 2908 | case Hexagon::L2_loadbzw4_pbr: |
| 2909 | case Hexagon::L2_loadbzw4_pi: |
| 2910 | case Hexagon::L2_loadbzw4_pci: |
| 2911 | case Hexagon::L2_loadbzw4_pcr: |
| 2912 | case Hexagon::L4_loadrub_rr: |
| 2913 | case Hexagon::L2_ploadrubt_io: |
| 2914 | case Hexagon::L2_ploadrubt_pi: |
| 2915 | case Hexagon::L2_ploadrubf_io: |
| 2916 | case Hexagon::L2_ploadrubf_pi: |
| 2917 | case Hexagon::L2_ploadrubtnew_io: |
| 2918 | case Hexagon::L2_ploadrubfnew_io: |
| 2919 | case Hexagon::L4_ploadrubt_rr: |
| 2920 | case Hexagon::L4_ploadrubf_rr: |
| 2921 | case Hexagon::L4_ploadrubtnew_rr: |
| 2922 | case Hexagon::L4_ploadrubfnew_rr: |
| 2923 | case Hexagon::L2_ploadrubtnew_pi: |
| 2924 | case Hexagon::L2_ploadrubfnew_pi: |
| 2925 | case Hexagon::L4_ploadrubt_abs: |
| 2926 | case Hexagon::L4_ploadrubf_abs: |
| 2927 | case Hexagon::L4_ploadrubtnew_abs: |
| 2928 | case Hexagon::L4_ploadrubfnew_abs: |
| 2929 | case Hexagon::L2_loadrubgp: |
| 2930 | // Half |
| 2931 | case Hexagon::L2_loadruh_io: |
| 2932 | case Hexagon::L4_loadruh_ur: |
| 2933 | case Hexagon::L4_loadruh_ap: |
| 2934 | case Hexagon::L2_loadruh_pr: |
| 2935 | case Hexagon::L2_loadruh_pbr: |
| 2936 | case Hexagon::L2_loadruh_pi: |
| 2937 | case Hexagon::L2_loadruh_pci: |
| 2938 | case Hexagon::L2_loadruh_pcr: |
| 2939 | case Hexagon::L4_loadruh_rr: |
| 2940 | case Hexagon::L2_ploadruht_io: |
| 2941 | case Hexagon::L2_ploadruht_pi: |
| 2942 | case Hexagon::L2_ploadruhf_io: |
| 2943 | case Hexagon::L2_ploadruhf_pi: |
| 2944 | case Hexagon::L2_ploadruhtnew_io: |
| 2945 | case Hexagon::L2_ploadruhfnew_io: |
| 2946 | case Hexagon::L4_ploadruht_rr: |
| 2947 | case Hexagon::L4_ploadruhf_rr: |
| 2948 | case Hexagon::L4_ploadruhtnew_rr: |
| 2949 | case Hexagon::L4_ploadruhfnew_rr: |
| 2950 | case Hexagon::L2_ploadruhtnew_pi: |
| 2951 | case Hexagon::L2_ploadruhfnew_pi: |
| 2952 | case Hexagon::L4_ploadruht_abs: |
| 2953 | case Hexagon::L4_ploadruhf_abs: |
| 2954 | case Hexagon::L4_ploadruhtnew_abs: |
| 2955 | case Hexagon::L4_ploadruhfnew_abs: |
| 2956 | case Hexagon::L2_loadruhgp: |
| 2957 | return true; |
| 2958 | default: |
| 2959 | return false; |
Krzysztof Parzyszek | fd02aad | 2016-02-12 18:37:23 +0000 | [diff] [blame] | 2960 | } |
| 2961 | } |
| 2962 | |
| 2963 | |
Krzysztof Parzyszek | 408e300 | 2016-07-15 21:34:02 +0000 | [diff] [blame] | 2964 | // Add latency to instruction. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2965 | bool HexagonInstrInfo::addLatencyToSchedule(const MachineInstr &MI1, |
| 2966 | const MachineInstr &MI2) const { |
Krzysztof Parzyszek | 408e300 | 2016-07-15 21:34:02 +0000 | [diff] [blame] | 2967 | if (isV60VectorInstruction(MI1) && isV60VectorInstruction(MI2)) |
| 2968 | if (!isVecUsableNextPacket(MI1, MI2)) |
| 2969 | return true; |
| 2970 | return false; |
| 2971 | } |
| 2972 | |
| 2973 | |
Brendon Cahoon | 254f889 | 2016-07-29 16:44:44 +0000 | [diff] [blame] | 2974 | /// \brief Get the base register and byte offset of a load/store instr. |
| 2975 | bool HexagonInstrInfo::getMemOpBaseRegImmOfs(MachineInstr &LdSt, |
| 2976 | unsigned &BaseReg, int64_t &Offset, const TargetRegisterInfo *TRI) |
| 2977 | const { |
| 2978 | unsigned AccessSize = 0; |
| 2979 | int OffsetVal = 0; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2980 | BaseReg = getBaseAndOffset(LdSt, OffsetVal, AccessSize); |
Brendon Cahoon | 254f889 | 2016-07-29 16:44:44 +0000 | [diff] [blame] | 2981 | Offset = OffsetVal; |
| 2982 | return BaseReg != 0; |
| 2983 | } |
| 2984 | |
| 2985 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 2986 | /// \brief Can these instructions execute at the same time in a bundle. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2987 | bool HexagonInstrInfo::canExecuteInBundle(const MachineInstr &First, |
| 2988 | const MachineInstr &Second) const { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 2989 | if (DisableNVSchedule) |
| 2990 | return false; |
| 2991 | if (mayBeNewStore(Second)) { |
| 2992 | // Make sure the definition of the first instruction is the value being |
| 2993 | // stored. |
| 2994 | const MachineOperand &Stored = |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2995 | Second.getOperand(Second.getNumOperands() - 1); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 2996 | if (!Stored.isReg()) |
| 2997 | return false; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 2998 | for (unsigned i = 0, e = First.getNumOperands(); i < e; ++i) { |
| 2999 | const MachineOperand &Op = First.getOperand(i); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 3000 | if (Op.isReg() && Op.isDef() && Op.getReg() == Stored.getReg()) |
| 3001 | return true; |
| 3002 | } |
| 3003 | } |
| 3004 | return false; |
| 3005 | } |
| 3006 | |
| 3007 | |
Krzysztof Parzyszek | 1b689da | 2016-08-11 21:14:25 +0000 | [diff] [blame] | 3008 | bool HexagonInstrInfo::doesNotReturn(const MachineInstr &CallMI) const { |
| 3009 | unsigned Opc = CallMI.getOpcode(); |
Krzysztof Parzyszek | be976d4 | 2016-08-12 11:12:02 +0000 | [diff] [blame] | 3010 | return Opc == Hexagon::PS_call_nr || Opc == Hexagon::PS_callr_nr; |
Krzysztof Parzyszek | 1b689da | 2016-08-11 21:14:25 +0000 | [diff] [blame] | 3011 | } |
| 3012 | |
| 3013 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3014 | bool HexagonInstrInfo::hasEHLabel(const MachineBasicBlock *B) const { |
| 3015 | for (auto &I : *B) |
| 3016 | if (I.isEHLabel()) |
| 3017 | return true; |
| 3018 | return false; |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 3019 | } |
| 3020 | |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 3021 | |
| 3022 | // Returns true if an instruction can be converted into a non-extended |
| 3023 | // equivalent instruction. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3024 | bool HexagonInstrInfo::hasNonExtEquivalent(const MachineInstr &MI) const { |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 3025 | short NonExtOpcode; |
| 3026 | // Check if the instruction has a register form that uses register in place |
| 3027 | // of the extended operand, if so return that as the non-extended form. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3028 | if (Hexagon::getRegForm(MI.getOpcode()) >= 0) |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 3029 | return true; |
| 3030 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3031 | if (MI.getDesc().mayLoad() || MI.getDesc().mayStore()) { |
Alp Toker | cb40291 | 2014-01-24 17:20:08 +0000 | [diff] [blame] | 3032 | // Check addressing mode and retrieve non-ext equivalent instruction. |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 3033 | |
| 3034 | switch (getAddrMode(MI)) { |
| 3035 | case HexagonII::Absolute : |
| 3036 | // Load/store with absolute addressing mode can be converted into |
| 3037 | // base+offset mode. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3038 | NonExtOpcode = Hexagon::getBaseWithImmOffset(MI.getOpcode()); |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 3039 | break; |
| 3040 | case HexagonII::BaseImmOffset : |
| 3041 | // Load/store with base+offset addressing mode can be converted into |
| 3042 | // base+register offset addressing mode. However left shift operand should |
| 3043 | // be set to 0. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3044 | NonExtOpcode = Hexagon::getBaseWithRegOffset(MI.getOpcode()); |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 3045 | break; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3046 | case HexagonII::BaseLongOffset: |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3047 | NonExtOpcode = Hexagon::getRegShlForm(MI.getOpcode()); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3048 | break; |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 3049 | default: |
| 3050 | return false; |
| 3051 | } |
| 3052 | if (NonExtOpcode < 0) |
| 3053 | return false; |
| 3054 | return true; |
| 3055 | } |
| 3056 | return false; |
| 3057 | } |
| 3058 | |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 3059 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3060 | bool HexagonInstrInfo::hasPseudoInstrPair(const MachineInstr &MI) const { |
| 3061 | return Hexagon::getRealHWInstr(MI.getOpcode(), |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3062 | Hexagon::InstrType_Pseudo) >= 0; |
| 3063 | } |
| 3064 | |
| 3065 | |
| 3066 | bool HexagonInstrInfo::hasUncondBranch(const MachineBasicBlock *B) |
| 3067 | const { |
| 3068 | MachineBasicBlock::const_iterator I = B->getFirstTerminator(), E = B->end(); |
| 3069 | while (I != E) { |
| 3070 | if (I->isBarrier()) |
| 3071 | return true; |
| 3072 | ++I; |
| 3073 | } |
| 3074 | return false; |
| 3075 | } |
| 3076 | |
| 3077 | |
| 3078 | // Returns true, if a LD insn can be promoted to a cur load. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3079 | bool HexagonInstrInfo::mayBeCurLoad(const MachineInstr &MI) const { |
| 3080 | auto &HST = MI.getParent()->getParent()->getSubtarget<HexagonSubtarget>(); |
| 3081 | const uint64_t F = MI.getDesc().TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3082 | return ((F >> HexagonII::mayCVLoadPos) & HexagonII::mayCVLoadMask) && |
| 3083 | HST.hasV60TOps(); |
| 3084 | } |
| 3085 | |
| 3086 | |
| 3087 | // Returns true, if a ST insn can be promoted to a new-value store. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3088 | bool HexagonInstrInfo::mayBeNewStore(const MachineInstr &MI) const { |
| 3089 | const uint64_t F = MI.getDesc().TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3090 | return (F >> HexagonII::mayNVStorePos) & HexagonII::mayNVStoreMask; |
| 3091 | } |
| 3092 | |
| 3093 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3094 | bool HexagonInstrInfo::producesStall(const MachineInstr &ProdMI, |
| 3095 | const MachineInstr &ConsMI) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3096 | // There is no stall when ProdMI is not a V60 vector. |
| 3097 | if (!isV60VectorInstruction(ProdMI)) |
| 3098 | return false; |
| 3099 | |
| 3100 | // There is no stall when ProdMI and ConsMI are not dependent. |
| 3101 | if (!isDependent(ProdMI, ConsMI)) |
| 3102 | return false; |
| 3103 | |
| 3104 | // When Forward Scheduling is enabled, there is no stall if ProdMI and ConsMI |
| 3105 | // are scheduled in consecutive packets. |
| 3106 | if (isVecUsableNextPacket(ProdMI, ConsMI)) |
| 3107 | return false; |
| 3108 | |
| 3109 | return true; |
| 3110 | } |
| 3111 | |
| 3112 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3113 | bool HexagonInstrInfo::producesStall(const MachineInstr &MI, |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3114 | MachineBasicBlock::const_instr_iterator BII) const { |
| 3115 | // There is no stall when I is not a V60 vector. |
| 3116 | if (!isV60VectorInstruction(MI)) |
| 3117 | return false; |
| 3118 | |
| 3119 | MachineBasicBlock::const_instr_iterator MII = BII; |
| 3120 | MachineBasicBlock::const_instr_iterator MIE = MII->getParent()->instr_end(); |
| 3121 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3122 | if (!MII->isBundle()) { |
| 3123 | const MachineInstr &J = *MII; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3124 | if (!isV60VectorInstruction(J)) |
| 3125 | return false; |
| 3126 | else if (isVecUsableNextPacket(J, MI)) |
| 3127 | return false; |
| 3128 | return true; |
| 3129 | } |
| 3130 | |
| 3131 | for (++MII; MII != MIE && MII->isInsideBundle(); ++MII) { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3132 | const MachineInstr &J = *MII; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3133 | if (producesStall(J, MI)) |
| 3134 | return true; |
| 3135 | } |
| 3136 | return false; |
| 3137 | } |
| 3138 | |
| 3139 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3140 | bool HexagonInstrInfo::predCanBeUsedAsDotNew(const MachineInstr &MI, |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3141 | unsigned PredReg) const { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3142 | for (unsigned opNum = 0; opNum < MI.getNumOperands(); opNum++) { |
| 3143 | const MachineOperand &MO = MI.getOperand(opNum); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3144 | if (MO.isReg() && MO.isDef() && MO.isImplicit() && (MO.getReg() == PredReg)) |
| 3145 | return false; // Predicate register must be explicitly defined. |
| 3146 | } |
| 3147 | |
| 3148 | // Hexagon Programmer's Reference says that decbin, memw_locked, and |
| 3149 | // memd_locked cannot be used as .new as well, |
| 3150 | // but we don't seem to have these instructions defined. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3151 | return MI.getOpcode() != Hexagon::A4_tlbmatch; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3152 | } |
| 3153 | |
| 3154 | |
| 3155 | bool HexagonInstrInfo::PredOpcodeHasJMP_c(unsigned Opcode) const { |
| 3156 | return (Opcode == Hexagon::J2_jumpt) || |
| 3157 | (Opcode == Hexagon::J2_jumpf) || |
| 3158 | (Opcode == Hexagon::J2_jumptnew) || |
| 3159 | (Opcode == Hexagon::J2_jumpfnew) || |
| 3160 | (Opcode == Hexagon::J2_jumptnewpt) || |
| 3161 | (Opcode == Hexagon::J2_jumpfnewpt); |
| 3162 | } |
| 3163 | |
| 3164 | |
| 3165 | bool HexagonInstrInfo::predOpcodeHasNot(ArrayRef<MachineOperand> Cond) const { |
| 3166 | if (Cond.empty() || !isPredicated(Cond[0].getImm())) |
| 3167 | return false; |
| 3168 | return !isPredicatedTrue(Cond[0].getImm()); |
| 3169 | } |
| 3170 | |
| 3171 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3172 | short HexagonInstrInfo::getAbsoluteForm(const MachineInstr &MI) const { |
| 3173 | return Hexagon::getAbsoluteForm(MI.getOpcode()); |
Krzysztof Parzyszek | f5cbac9 | 2016-04-29 15:49:13 +0000 | [diff] [blame] | 3174 | } |
| 3175 | |
| 3176 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3177 | unsigned HexagonInstrInfo::getAddrMode(const MachineInstr &MI) const { |
| 3178 | const uint64_t F = MI.getDesc().TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3179 | return (F >> HexagonII::AddrModePos) & HexagonII::AddrModeMask; |
| 3180 | } |
| 3181 | |
| 3182 | |
| 3183 | // Returns the base register in a memory access (load/store). The offset is |
| 3184 | // returned in Offset and the access size is returned in AccessSize. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3185 | unsigned HexagonInstrInfo::getBaseAndOffset(const MachineInstr &MI, |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3186 | int &Offset, unsigned &AccessSize) const { |
| 3187 | // Return if it is not a base+offset type instruction or a MemOp. |
| 3188 | if (getAddrMode(MI) != HexagonII::BaseImmOffset && |
| 3189 | getAddrMode(MI) != HexagonII::BaseLongOffset && |
Krzysztof Parzyszek | 8fb181c | 2016-08-01 17:55:48 +0000 | [diff] [blame] | 3190 | !isMemOp(MI) && !isPostIncrement(MI)) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3191 | return 0; |
| 3192 | |
| 3193 | // Since it is a memory access instruction, getMemAccessSize() should never |
| 3194 | // return 0. |
| 3195 | assert (getMemAccessSize(MI) && |
| 3196 | "BaseImmOffset or BaseLongOffset or MemOp without accessSize"); |
| 3197 | |
| 3198 | // Return Values of getMemAccessSize() are |
| 3199 | // 0 - Checked in the assert above. |
| 3200 | // 1, 2, 3, 4 & 7, 8 - The statement below is correct for all these. |
| 3201 | // MemAccessSize is represented as 1+log2(N) where N is size in bits. |
| 3202 | AccessSize = (1U << (getMemAccessSize(MI) - 1)); |
| 3203 | |
| 3204 | unsigned basePos = 0, offsetPos = 0; |
Krzysztof Parzyszek | 8fb181c | 2016-08-01 17:55:48 +0000 | [diff] [blame] | 3205 | if (!getBaseAndOffsetPosition(MI, basePos, offsetPos)) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3206 | return 0; |
| 3207 | |
| 3208 | // Post increment updates its EA after the mem access, |
| 3209 | // so we need to treat its offset as zero. |
Krzysztof Parzyszek | 8fb181c | 2016-08-01 17:55:48 +0000 | [diff] [blame] | 3210 | if (isPostIncrement(MI)) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3211 | Offset = 0; |
| 3212 | else { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3213 | Offset = MI.getOperand(offsetPos).getImm(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3214 | } |
| 3215 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3216 | return MI.getOperand(basePos).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3217 | } |
| 3218 | |
| 3219 | |
| 3220 | /// Return the position of the base and offset operands for this instruction. |
Krzysztof Parzyszek | 8fb181c | 2016-08-01 17:55:48 +0000 | [diff] [blame] | 3221 | bool HexagonInstrInfo::getBaseAndOffsetPosition(const MachineInstr &MI, |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3222 | unsigned &BasePos, unsigned &OffsetPos) const { |
| 3223 | // Deal with memops first. |
Krzysztof Parzyszek | 8fb181c | 2016-08-01 17:55:48 +0000 | [diff] [blame] | 3224 | if (isMemOp(MI)) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3225 | BasePos = 0; |
| 3226 | OffsetPos = 1; |
Krzysztof Parzyszek | 8fb181c | 2016-08-01 17:55:48 +0000 | [diff] [blame] | 3227 | } else if (MI.mayStore()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3228 | BasePos = 0; |
| 3229 | OffsetPos = 1; |
Krzysztof Parzyszek | 8fb181c | 2016-08-01 17:55:48 +0000 | [diff] [blame] | 3230 | } else if (MI.mayLoad()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3231 | BasePos = 1; |
| 3232 | OffsetPos = 2; |
| 3233 | } else |
| 3234 | return false; |
| 3235 | |
Krzysztof Parzyszek | 8fb181c | 2016-08-01 17:55:48 +0000 | [diff] [blame] | 3236 | if (isPredicated(MI)) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3237 | BasePos++; |
| 3238 | OffsetPos++; |
| 3239 | } |
| 3240 | if (isPostIncrement(MI)) { |
| 3241 | BasePos++; |
| 3242 | OffsetPos++; |
| 3243 | } |
| 3244 | |
Krzysztof Parzyszek | 8fb181c | 2016-08-01 17:55:48 +0000 | [diff] [blame] | 3245 | if (!MI.getOperand(BasePos).isReg() || !MI.getOperand(OffsetPos).isImm()) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3246 | return false; |
| 3247 | |
| 3248 | return true; |
| 3249 | } |
| 3250 | |
| 3251 | |
| 3252 | // Inserts branching instructions in reverse order of their occurence. |
| 3253 | // e.g. jump_t t1 (i1) |
| 3254 | // jump t2 (i2) |
| 3255 | // Jumpers = {i2, i1} |
| 3256 | SmallVector<MachineInstr*, 2> HexagonInstrInfo::getBranchingInstrs( |
| 3257 | MachineBasicBlock& MBB) const { |
| 3258 | SmallVector<MachineInstr*, 2> Jumpers; |
| 3259 | // If the block has no terminators, it just falls into the block after it. |
| 3260 | MachineBasicBlock::instr_iterator I = MBB.instr_end(); |
| 3261 | if (I == MBB.instr_begin()) |
| 3262 | return Jumpers; |
| 3263 | |
| 3264 | // A basic block may looks like this: |
| 3265 | // |
| 3266 | // [ insn |
| 3267 | // EH_LABEL |
| 3268 | // insn |
| 3269 | // insn |
| 3270 | // insn |
| 3271 | // EH_LABEL |
| 3272 | // insn ] |
| 3273 | // |
| 3274 | // It has two succs but does not have a terminator |
| 3275 | // Don't know how to handle it. |
| 3276 | do { |
| 3277 | --I; |
| 3278 | if (I->isEHLabel()) |
| 3279 | return Jumpers; |
| 3280 | } while (I != MBB.instr_begin()); |
| 3281 | |
| 3282 | I = MBB.instr_end(); |
| 3283 | --I; |
| 3284 | |
| 3285 | while (I->isDebugValue()) { |
| 3286 | if (I == MBB.instr_begin()) |
| 3287 | return Jumpers; |
| 3288 | --I; |
| 3289 | } |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 3290 | if (!isUnpredicatedTerminator(*I)) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3291 | return Jumpers; |
| 3292 | |
| 3293 | // Get the last instruction in the block. |
| 3294 | MachineInstr *LastInst = &*I; |
| 3295 | Jumpers.push_back(LastInst); |
| 3296 | MachineInstr *SecondLastInst = nullptr; |
| 3297 | // Find one more terminator if present. |
| 3298 | do { |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 3299 | if (&*I != LastInst && !I->isBundle() && isUnpredicatedTerminator(*I)) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3300 | if (!SecondLastInst) { |
| 3301 | SecondLastInst = &*I; |
| 3302 | Jumpers.push_back(SecondLastInst); |
| 3303 | } else // This is a third branch. |
| 3304 | return Jumpers; |
| 3305 | } |
| 3306 | if (I == MBB.instr_begin()) |
| 3307 | break; |
| 3308 | --I; |
| 3309 | } while (true); |
| 3310 | return Jumpers; |
| 3311 | } |
| 3312 | |
| 3313 | |
Krzysztof Parzyszek | f5cbac9 | 2016-04-29 15:49:13 +0000 | [diff] [blame] | 3314 | short HexagonInstrInfo::getBaseWithLongOffset(short Opcode) const { |
| 3315 | if (Opcode < 0) |
| 3316 | return -1; |
| 3317 | return Hexagon::getBaseWithLongOffset(Opcode); |
| 3318 | } |
| 3319 | |
| 3320 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3321 | short HexagonInstrInfo::getBaseWithLongOffset(const MachineInstr &MI) const { |
| 3322 | return Hexagon::getBaseWithLongOffset(MI.getOpcode()); |
Krzysztof Parzyszek | f5cbac9 | 2016-04-29 15:49:13 +0000 | [diff] [blame] | 3323 | } |
| 3324 | |
| 3325 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3326 | short HexagonInstrInfo::getBaseWithRegOffset(const MachineInstr &MI) const { |
| 3327 | return Hexagon::getBaseWithRegOffset(MI.getOpcode()); |
Krzysztof Parzyszek | f5cbac9 | 2016-04-29 15:49:13 +0000 | [diff] [blame] | 3328 | } |
| 3329 | |
| 3330 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3331 | // Returns Operand Index for the constant extended instruction. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3332 | unsigned HexagonInstrInfo::getCExtOpNum(const MachineInstr &MI) const { |
| 3333 | const uint64_t F = MI.getDesc().TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3334 | return (F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask; |
| 3335 | } |
| 3336 | |
| 3337 | // See if instruction could potentially be a duplex candidate. |
| 3338 | // If so, return its group. Zero otherwise. |
| 3339 | HexagonII::CompoundGroup HexagonInstrInfo::getCompoundCandidateGroup( |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3340 | const MachineInstr &MI) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3341 | unsigned DstReg, SrcReg, Src1Reg, Src2Reg; |
| 3342 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3343 | switch (MI.getOpcode()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3344 | default: |
| 3345 | return HexagonII::HCG_None; |
| 3346 | // |
| 3347 | // Compound pairs. |
| 3348 | // "p0=cmp.eq(Rs16,Rt16); if (p0.new) jump:nt #r9:2" |
| 3349 | // "Rd16=#U6 ; jump #r9:2" |
| 3350 | // "Rd16=Rs16 ; jump #r9:2" |
| 3351 | // |
| 3352 | case Hexagon::C2_cmpeq: |
| 3353 | case Hexagon::C2_cmpgt: |
| 3354 | case Hexagon::C2_cmpgtu: |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3355 | DstReg = MI.getOperand(0).getReg(); |
| 3356 | Src1Reg = MI.getOperand(1).getReg(); |
| 3357 | Src2Reg = MI.getOperand(2).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3358 | if (Hexagon::PredRegsRegClass.contains(DstReg) && |
| 3359 | (Hexagon::P0 == DstReg || Hexagon::P1 == DstReg) && |
| 3360 | isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg)) |
| 3361 | return HexagonII::HCG_A; |
| 3362 | break; |
| 3363 | case Hexagon::C2_cmpeqi: |
| 3364 | case Hexagon::C2_cmpgti: |
| 3365 | case Hexagon::C2_cmpgtui: |
| 3366 | // P0 = cmp.eq(Rs,#u2) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3367 | DstReg = MI.getOperand(0).getReg(); |
| 3368 | SrcReg = MI.getOperand(1).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3369 | if (Hexagon::PredRegsRegClass.contains(DstReg) && |
| 3370 | (Hexagon::P0 == DstReg || Hexagon::P1 == DstReg) && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3371 | isIntRegForSubInst(SrcReg) && MI.getOperand(2).isImm() && |
| 3372 | ((isUInt<5>(MI.getOperand(2).getImm())) || |
| 3373 | (MI.getOperand(2).getImm() == -1))) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3374 | return HexagonII::HCG_A; |
| 3375 | break; |
| 3376 | case Hexagon::A2_tfr: |
| 3377 | // Rd = Rs |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3378 | DstReg = MI.getOperand(0).getReg(); |
| 3379 | SrcReg = MI.getOperand(1).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3380 | if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg)) |
| 3381 | return HexagonII::HCG_A; |
| 3382 | break; |
| 3383 | case Hexagon::A2_tfrsi: |
| 3384 | // Rd = #u6 |
| 3385 | // Do not test for #u6 size since the const is getting extended |
| 3386 | // regardless and compound could be formed. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3387 | DstReg = MI.getOperand(0).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3388 | if (isIntRegForSubInst(DstReg)) |
| 3389 | return HexagonII::HCG_A; |
| 3390 | break; |
| 3391 | case Hexagon::S2_tstbit_i: |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3392 | DstReg = MI.getOperand(0).getReg(); |
| 3393 | Src1Reg = MI.getOperand(1).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3394 | if (Hexagon::PredRegsRegClass.contains(DstReg) && |
| 3395 | (Hexagon::P0 == DstReg || Hexagon::P1 == DstReg) && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3396 | MI.getOperand(2).isImm() && |
| 3397 | isIntRegForSubInst(Src1Reg) && (MI.getOperand(2).getImm() == 0)) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3398 | return HexagonII::HCG_A; |
| 3399 | break; |
| 3400 | // The fact that .new form is used pretty much guarantees |
| 3401 | // that predicate register will match. Nevertheless, |
| 3402 | // there could be some false positives without additional |
| 3403 | // checking. |
| 3404 | case Hexagon::J2_jumptnew: |
| 3405 | case Hexagon::J2_jumpfnew: |
| 3406 | case Hexagon::J2_jumptnewpt: |
| 3407 | case Hexagon::J2_jumpfnewpt: |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3408 | Src1Reg = MI.getOperand(0).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3409 | if (Hexagon::PredRegsRegClass.contains(Src1Reg) && |
| 3410 | (Hexagon::P0 == Src1Reg || Hexagon::P1 == Src1Reg)) |
| 3411 | return HexagonII::HCG_B; |
| 3412 | break; |
| 3413 | // Transfer and jump: |
| 3414 | // Rd=#U6 ; jump #r9:2 |
| 3415 | // Rd=Rs ; jump #r9:2 |
| 3416 | // Do not test for jump range here. |
| 3417 | case Hexagon::J2_jump: |
| 3418 | case Hexagon::RESTORE_DEALLOC_RET_JMP_V4: |
Krzysztof Parzyszek | 5a7bef9 | 2016-08-19 17:20:57 +0000 | [diff] [blame] | 3419 | case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC: |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3420 | return HexagonII::HCG_C; |
| 3421 | break; |
| 3422 | } |
| 3423 | |
| 3424 | return HexagonII::HCG_None; |
| 3425 | } |
| 3426 | |
| 3427 | |
| 3428 | // Returns -1 when there is no opcode found. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3429 | unsigned HexagonInstrInfo::getCompoundOpcode(const MachineInstr &GA, |
| 3430 | const MachineInstr &GB) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3431 | assert(getCompoundCandidateGroup(GA) == HexagonII::HCG_A); |
| 3432 | assert(getCompoundCandidateGroup(GB) == HexagonII::HCG_B); |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3433 | if ((GA.getOpcode() != Hexagon::C2_cmpeqi) || |
| 3434 | (GB.getOpcode() != Hexagon::J2_jumptnew)) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3435 | return -1; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3436 | unsigned DestReg = GA.getOperand(0).getReg(); |
| 3437 | if (!GB.readsRegister(DestReg)) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3438 | return -1; |
| 3439 | if (DestReg == Hexagon::P0) |
| 3440 | return Hexagon::J4_cmpeqi_tp0_jump_nt; |
| 3441 | if (DestReg == Hexagon::P1) |
| 3442 | return Hexagon::J4_cmpeqi_tp1_jump_nt; |
| 3443 | return -1; |
| 3444 | } |
| 3445 | |
| 3446 | |
| 3447 | int HexagonInstrInfo::getCondOpcode(int Opc, bool invertPredicate) const { |
| 3448 | enum Hexagon::PredSense inPredSense; |
| 3449 | inPredSense = invertPredicate ? Hexagon::PredSense_false : |
| 3450 | Hexagon::PredSense_true; |
| 3451 | int CondOpcode = Hexagon::getPredOpcode(Opc, inPredSense); |
| 3452 | if (CondOpcode >= 0) // Valid Conditional opcode/instruction |
| 3453 | return CondOpcode; |
| 3454 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3455 | llvm_unreachable("Unexpected predicable instruction"); |
| 3456 | } |
| 3457 | |
| 3458 | |
| 3459 | // Return the cur value instruction for a given store. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3460 | int HexagonInstrInfo::getDotCurOp(const MachineInstr &MI) const { |
| 3461 | switch (MI.getOpcode()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3462 | default: llvm_unreachable("Unknown .cur type"); |
| 3463 | case Hexagon::V6_vL32b_pi: |
| 3464 | return Hexagon::V6_vL32b_cur_pi; |
| 3465 | case Hexagon::V6_vL32b_ai: |
| 3466 | return Hexagon::V6_vL32b_cur_ai; |
| 3467 | //128B |
| 3468 | case Hexagon::V6_vL32b_pi_128B: |
| 3469 | return Hexagon::V6_vL32b_cur_pi_128B; |
| 3470 | case Hexagon::V6_vL32b_ai_128B: |
| 3471 | return Hexagon::V6_vL32b_cur_ai_128B; |
| 3472 | } |
| 3473 | return 0; |
| 3474 | } |
| 3475 | |
| 3476 | |
| 3477 | |
| 3478 | // The diagram below shows the steps involved in the conversion of a predicated |
| 3479 | // store instruction to its .new predicated new-value form. |
| 3480 | // |
| 3481 | // p.new NV store [ if(p0.new)memw(R0+#0)=R2.new ] |
| 3482 | // ^ ^ |
| 3483 | // / \ (not OK. it will cause new-value store to be |
| 3484 | // / X conditional on p0.new while R2 producer is |
| 3485 | // / \ on p0) |
| 3486 | // / \. |
| 3487 | // p.new store p.old NV store |
| 3488 | // [if(p0.new)memw(R0+#0)=R2] [if(p0)memw(R0+#0)=R2.new] |
| 3489 | // ^ ^ |
| 3490 | // \ / |
| 3491 | // \ / |
| 3492 | // \ / |
| 3493 | // p.old store |
| 3494 | // [if (p0)memw(R0+#0)=R2] |
| 3495 | // |
| 3496 | // |
| 3497 | // The following set of instructions further explains the scenario where |
| 3498 | // conditional new-value store becomes invalid when promoted to .new predicate |
| 3499 | // form. |
| 3500 | // |
| 3501 | // { 1) if (p0) r0 = add(r1, r2) |
| 3502 | // 2) p0 = cmp.eq(r3, #0) } |
| 3503 | // |
| 3504 | // 3) if (p0) memb(r1+#0) = r0 --> this instruction can't be grouped with |
| 3505 | // the first two instructions because in instr 1, r0 is conditional on old value |
| 3506 | // of p0 but its use in instr 3 is conditional on p0 modified by instr 2 which |
| 3507 | // is not valid for new-value stores. |
| 3508 | // Predicated new value stores (i.e. if (p0) memw(..)=r0.new) are excluded |
| 3509 | // from the "Conditional Store" list. Because a predicated new value store |
| 3510 | // would NOT be promoted to a double dot new store. See diagram below: |
| 3511 | // This function returns yes for those stores that are predicated but not |
| 3512 | // yet promoted to predicate dot new instructions. |
| 3513 | // |
| 3514 | // +---------------------+ |
| 3515 | // /-----| if (p0) memw(..)=r0 |---------\~ |
| 3516 | // || +---------------------+ || |
| 3517 | // promote || /\ /\ || promote |
| 3518 | // || /||\ /||\ || |
| 3519 | // \||/ demote || \||/ |
| 3520 | // \/ || || \/ |
| 3521 | // +-------------------------+ || +-------------------------+ |
| 3522 | // | if (p0.new) memw(..)=r0 | || | if (p0) memw(..)=r0.new | |
| 3523 | // +-------------------------+ || +-------------------------+ |
| 3524 | // || || || |
| 3525 | // || demote \||/ |
| 3526 | // promote || \/ NOT possible |
| 3527 | // || || /\~ |
| 3528 | // \||/ || /||\~ |
| 3529 | // \/ || || |
| 3530 | // +-----------------------------+ |
| 3531 | // | if (p0.new) memw(..)=r0.new | |
| 3532 | // +-----------------------------+ |
| 3533 | // Double Dot New Store |
| 3534 | // |
| 3535 | // Returns the most basic instruction for the .new predicated instructions and |
| 3536 | // new-value stores. |
| 3537 | // For example, all of the following instructions will be converted back to the |
| 3538 | // same instruction: |
| 3539 | // 1) if (p0.new) memw(R0+#0) = R1.new ---> |
| 3540 | // 2) if (p0) memw(R0+#0)= R1.new -------> if (p0) memw(R0+#0) = R1 |
| 3541 | // 3) if (p0.new) memw(R0+#0) = R1 ---> |
| 3542 | // |
| 3543 | // To understand the translation of instruction 1 to its original form, consider |
| 3544 | // a packet with 3 instructions. |
| 3545 | // { p0 = cmp.eq(R0,R1) |
| 3546 | // if (p0.new) R2 = add(R3, R4) |
| 3547 | // R5 = add (R3, R1) |
| 3548 | // } |
| 3549 | // if (p0) memw(R5+#0) = R2 <--- trying to include it in the previous packet |
| 3550 | // |
| 3551 | // This instruction can be part of the previous packet only if both p0 and R2 |
| 3552 | // are promoted to .new values. This promotion happens in steps, first |
| 3553 | // predicate register is promoted to .new and in the next iteration R2 is |
| 3554 | // promoted. Therefore, in case of dependence check failure (due to R5) during |
| 3555 | // next iteration, it should be converted back to its most basic form. |
| 3556 | |
| 3557 | |
| 3558 | // Return the new value instruction for a given store. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3559 | int HexagonInstrInfo::getDotNewOp(const MachineInstr &MI) const { |
| 3560 | int NVOpcode = Hexagon::getNewValueOpcode(MI.getOpcode()); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3561 | if (NVOpcode >= 0) // Valid new-value store instruction. |
| 3562 | return NVOpcode; |
| 3563 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3564 | switch (MI.getOpcode()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3565 | default: llvm_unreachable("Unknown .new type"); |
| 3566 | case Hexagon::S4_storerb_ur: |
| 3567 | return Hexagon::S4_storerbnew_ur; |
| 3568 | |
| 3569 | case Hexagon::S2_storerb_pci: |
| 3570 | return Hexagon::S2_storerb_pci; |
| 3571 | |
| 3572 | case Hexagon::S2_storeri_pci: |
| 3573 | return Hexagon::S2_storeri_pci; |
| 3574 | |
| 3575 | case Hexagon::S2_storerh_pci: |
| 3576 | return Hexagon::S2_storerh_pci; |
| 3577 | |
| 3578 | case Hexagon::S2_storerd_pci: |
| 3579 | return Hexagon::S2_storerd_pci; |
| 3580 | |
| 3581 | case Hexagon::S2_storerf_pci: |
| 3582 | return Hexagon::S2_storerf_pci; |
| 3583 | |
| 3584 | case Hexagon::V6_vS32b_ai: |
| 3585 | return Hexagon::V6_vS32b_new_ai; |
| 3586 | |
| 3587 | case Hexagon::V6_vS32b_pi: |
| 3588 | return Hexagon::V6_vS32b_new_pi; |
| 3589 | |
| 3590 | // 128B |
| 3591 | case Hexagon::V6_vS32b_ai_128B: |
| 3592 | return Hexagon::V6_vS32b_new_ai_128B; |
| 3593 | |
| 3594 | case Hexagon::V6_vS32b_pi_128B: |
| 3595 | return Hexagon::V6_vS32b_new_pi_128B; |
| 3596 | } |
| 3597 | return 0; |
| 3598 | } |
| 3599 | |
Krzysztof Parzyszek | 0a04ac2 | 2016-05-16 16:56:10 +0000 | [diff] [blame] | 3600 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3601 | // Returns the opcode to use when converting MI, which is a conditional jump, |
| 3602 | // into a conditional instruction which uses the .new value of the predicate. |
| 3603 | // We also use branch probabilities to add a hint to the jump. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3604 | int HexagonInstrInfo::getDotNewPredJumpOp(const MachineInstr &MI, |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3605 | const MachineBranchProbabilityInfo *MBPI) const { |
| 3606 | // We assume that block can have at most two successors. |
| 3607 | bool taken = false; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3608 | const MachineBasicBlock *Src = MI.getParent(); |
| 3609 | const MachineOperand &BrTarget = MI.getOperand(1); |
| 3610 | const MachineBasicBlock *Dst = BrTarget.getMBB(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3611 | |
| 3612 | const BranchProbability Prediction = MBPI->getEdgeProbability(Src, Dst); |
| 3613 | if (Prediction >= BranchProbability(1,2)) |
| 3614 | taken = true; |
| 3615 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3616 | switch (MI.getOpcode()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3617 | case Hexagon::J2_jumpt: |
| 3618 | return taken ? Hexagon::J2_jumptnewpt : Hexagon::J2_jumptnew; |
| 3619 | case Hexagon::J2_jumpf: |
| 3620 | return taken ? Hexagon::J2_jumpfnewpt : Hexagon::J2_jumpfnew; |
| 3621 | |
| 3622 | default: |
| 3623 | llvm_unreachable("Unexpected jump instruction."); |
| 3624 | } |
| 3625 | } |
| 3626 | |
| 3627 | |
| 3628 | // Return .new predicate version for an instruction. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3629 | int HexagonInstrInfo::getDotNewPredOp(const MachineInstr &MI, |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3630 | const MachineBranchProbabilityInfo *MBPI) const { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3631 | int NewOpcode = Hexagon::getPredNewOpcode(MI.getOpcode()); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3632 | if (NewOpcode >= 0) // Valid predicate new instruction |
| 3633 | return NewOpcode; |
| 3634 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3635 | switch (MI.getOpcode()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3636 | // Condtional Jumps |
| 3637 | case Hexagon::J2_jumpt: |
| 3638 | case Hexagon::J2_jumpf: |
| 3639 | return getDotNewPredJumpOp(MI, MBPI); |
| 3640 | |
| 3641 | default: |
| 3642 | assert(0 && "Unknown .new type"); |
| 3643 | } |
| 3644 | return 0; |
| 3645 | } |
| 3646 | |
| 3647 | |
| 3648 | int HexagonInstrInfo::getDotOldOp(const int opc) const { |
| 3649 | int NewOp = opc; |
| 3650 | if (isPredicated(NewOp) && isPredicatedNew(NewOp)) { // Get predicate old form |
| 3651 | NewOp = Hexagon::getPredOldOpcode(NewOp); |
| 3652 | assert(NewOp >= 0 && |
| 3653 | "Couldn't change predicate new instruction to its old form."); |
| 3654 | } |
| 3655 | |
| 3656 | if (isNewValueStore(NewOp)) { // Convert into non-new-value format |
| 3657 | NewOp = Hexagon::getNonNVStore(NewOp); |
| 3658 | assert(NewOp >= 0 && "Couldn't change new-value store to its old form."); |
| 3659 | } |
| 3660 | return NewOp; |
| 3661 | } |
| 3662 | |
| 3663 | |
| 3664 | // See if instruction could potentially be a duplex candidate. |
| 3665 | // If so, return its group. Zero otherwise. |
| 3666 | HexagonII::SubInstructionGroup HexagonInstrInfo::getDuplexCandidateGroup( |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3667 | const MachineInstr &MI) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3668 | unsigned DstReg, SrcReg, Src1Reg, Src2Reg; |
| 3669 | auto &HRI = getRegisterInfo(); |
| 3670 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3671 | switch (MI.getOpcode()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3672 | default: |
| 3673 | return HexagonII::HSIG_None; |
| 3674 | // |
| 3675 | // Group L1: |
| 3676 | // |
| 3677 | // Rd = memw(Rs+#u4:2) |
| 3678 | // Rd = memub(Rs+#u4:0) |
| 3679 | case Hexagon::L2_loadri_io: |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3680 | DstReg = MI.getOperand(0).getReg(); |
| 3681 | SrcReg = MI.getOperand(1).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3682 | // Special case this one from Group L2. |
| 3683 | // Rd = memw(r29+#u5:2) |
| 3684 | if (isIntRegForSubInst(DstReg)) { |
| 3685 | if (Hexagon::IntRegsRegClass.contains(SrcReg) && |
| 3686 | HRI.getStackRegister() == SrcReg && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3687 | MI.getOperand(2).isImm() && |
| 3688 | isShiftedUInt<5,2>(MI.getOperand(2).getImm())) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3689 | return HexagonII::HSIG_L2; |
| 3690 | // Rd = memw(Rs+#u4:2) |
| 3691 | if (isIntRegForSubInst(SrcReg) && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3692 | (MI.getOperand(2).isImm() && |
| 3693 | isShiftedUInt<4,2>(MI.getOperand(2).getImm()))) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3694 | return HexagonII::HSIG_L1; |
| 3695 | } |
| 3696 | break; |
| 3697 | case Hexagon::L2_loadrub_io: |
| 3698 | // Rd = memub(Rs+#u4:0) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3699 | DstReg = MI.getOperand(0).getReg(); |
| 3700 | SrcReg = MI.getOperand(1).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3701 | if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3702 | MI.getOperand(2).isImm() && isUInt<4>(MI.getOperand(2).getImm())) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3703 | return HexagonII::HSIG_L1; |
| 3704 | break; |
| 3705 | // |
| 3706 | // Group L2: |
| 3707 | // |
| 3708 | // Rd = memh/memuh(Rs+#u3:1) |
| 3709 | // Rd = memb(Rs+#u3:0) |
| 3710 | // Rd = memw(r29+#u5:2) - Handled above. |
| 3711 | // Rdd = memd(r29+#u5:3) |
| 3712 | // deallocframe |
| 3713 | // [if ([!]p0[.new])] dealloc_return |
| 3714 | // [if ([!]p0[.new])] jumpr r31 |
| 3715 | case Hexagon::L2_loadrh_io: |
| 3716 | case Hexagon::L2_loadruh_io: |
| 3717 | // Rd = memh/memuh(Rs+#u3:1) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3718 | DstReg = MI.getOperand(0).getReg(); |
| 3719 | SrcReg = MI.getOperand(1).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3720 | if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3721 | MI.getOperand(2).isImm() && |
| 3722 | isShiftedUInt<3,1>(MI.getOperand(2).getImm())) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3723 | return HexagonII::HSIG_L2; |
| 3724 | break; |
| 3725 | case Hexagon::L2_loadrb_io: |
| 3726 | // Rd = memb(Rs+#u3:0) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3727 | DstReg = MI.getOperand(0).getReg(); |
| 3728 | SrcReg = MI.getOperand(1).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3729 | if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3730 | MI.getOperand(2).isImm() && |
| 3731 | isUInt<3>(MI.getOperand(2).getImm())) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3732 | return HexagonII::HSIG_L2; |
| 3733 | break; |
| 3734 | case Hexagon::L2_loadrd_io: |
| 3735 | // Rdd = memd(r29+#u5:3) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3736 | DstReg = MI.getOperand(0).getReg(); |
| 3737 | SrcReg = MI.getOperand(1).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3738 | if (isDblRegForSubInst(DstReg, HRI) && |
| 3739 | Hexagon::IntRegsRegClass.contains(SrcReg) && |
| 3740 | HRI.getStackRegister() == SrcReg && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3741 | MI.getOperand(2).isImm() && |
| 3742 | isShiftedUInt<5,3>(MI.getOperand(2).getImm())) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3743 | return HexagonII::HSIG_L2; |
| 3744 | break; |
| 3745 | // dealloc_return is not documented in Hexagon Manual, but marked |
| 3746 | // with A_SUBINSN attribute in iset_v4classic.py. |
| 3747 | case Hexagon::RESTORE_DEALLOC_RET_JMP_V4: |
Krzysztof Parzyszek | 5a7bef9 | 2016-08-19 17:20:57 +0000 | [diff] [blame] | 3748 | case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC: |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3749 | case Hexagon::L4_return: |
| 3750 | case Hexagon::L2_deallocframe: |
| 3751 | return HexagonII::HSIG_L2; |
| 3752 | case Hexagon::EH_RETURN_JMPR: |
Krzysztof Parzyszek | be976d4 | 2016-08-12 11:12:02 +0000 | [diff] [blame] | 3753 | case Hexagon::PS_jmpret: |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3754 | // jumpr r31 |
| 3755 | // Actual form JMPR %PC<imp-def>, %R31<imp-use>, %R0<imp-use,internal>. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3756 | DstReg = MI.getOperand(0).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3757 | if (Hexagon::IntRegsRegClass.contains(DstReg) && (Hexagon::R31 == DstReg)) |
| 3758 | return HexagonII::HSIG_L2; |
| 3759 | break; |
Krzysztof Parzyszek | be976d4 | 2016-08-12 11:12:02 +0000 | [diff] [blame] | 3760 | case Hexagon::PS_jmprett: |
| 3761 | case Hexagon::PS_jmpretf: |
| 3762 | case Hexagon::PS_jmprettnewpt: |
| 3763 | case Hexagon::PS_jmpretfnewpt: |
| 3764 | case Hexagon::PS_jmprettnew: |
| 3765 | case Hexagon::PS_jmpretfnew: |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3766 | DstReg = MI.getOperand(1).getReg(); |
| 3767 | SrcReg = MI.getOperand(0).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3768 | // [if ([!]p0[.new])] jumpr r31 |
| 3769 | if ((Hexagon::PredRegsRegClass.contains(SrcReg) && |
| 3770 | (Hexagon::P0 == SrcReg)) && |
| 3771 | (Hexagon::IntRegsRegClass.contains(DstReg) && (Hexagon::R31 == DstReg))) |
| 3772 | return HexagonII::HSIG_L2; |
Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 3773 | break; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3774 | case Hexagon::L4_return_t : |
| 3775 | case Hexagon::L4_return_f : |
| 3776 | case Hexagon::L4_return_tnew_pnt : |
| 3777 | case Hexagon::L4_return_fnew_pnt : |
| 3778 | case Hexagon::L4_return_tnew_pt : |
| 3779 | case Hexagon::L4_return_fnew_pt : |
| 3780 | // [if ([!]p0[.new])] dealloc_return |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3781 | SrcReg = MI.getOperand(0).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3782 | if (Hexagon::PredRegsRegClass.contains(SrcReg) && (Hexagon::P0 == SrcReg)) |
| 3783 | return HexagonII::HSIG_L2; |
| 3784 | break; |
| 3785 | // |
| 3786 | // Group S1: |
| 3787 | // |
| 3788 | // memw(Rs+#u4:2) = Rt |
| 3789 | // memb(Rs+#u4:0) = Rt |
| 3790 | case Hexagon::S2_storeri_io: |
| 3791 | // Special case this one from Group S2. |
| 3792 | // memw(r29+#u5:2) = Rt |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3793 | Src1Reg = MI.getOperand(0).getReg(); |
| 3794 | Src2Reg = MI.getOperand(2).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3795 | if (Hexagon::IntRegsRegClass.contains(Src1Reg) && |
| 3796 | isIntRegForSubInst(Src2Reg) && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3797 | HRI.getStackRegister() == Src1Reg && MI.getOperand(1).isImm() && |
| 3798 | isShiftedUInt<5,2>(MI.getOperand(1).getImm())) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3799 | return HexagonII::HSIG_S2; |
| 3800 | // memw(Rs+#u4:2) = Rt |
| 3801 | if (isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg) && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3802 | MI.getOperand(1).isImm() && |
| 3803 | isShiftedUInt<4,2>(MI.getOperand(1).getImm())) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3804 | return HexagonII::HSIG_S1; |
| 3805 | break; |
| 3806 | case Hexagon::S2_storerb_io: |
| 3807 | // memb(Rs+#u4:0) = Rt |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3808 | Src1Reg = MI.getOperand(0).getReg(); |
| 3809 | Src2Reg = MI.getOperand(2).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3810 | if (isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg) && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3811 | MI.getOperand(1).isImm() && isUInt<4>(MI.getOperand(1).getImm())) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3812 | return HexagonII::HSIG_S1; |
| 3813 | break; |
| 3814 | // |
| 3815 | // Group S2: |
| 3816 | // |
| 3817 | // memh(Rs+#u3:1) = Rt |
| 3818 | // memw(r29+#u5:2) = Rt |
| 3819 | // memd(r29+#s6:3) = Rtt |
| 3820 | // memw(Rs+#u4:2) = #U1 |
| 3821 | // memb(Rs+#u4) = #U1 |
| 3822 | // allocframe(#u5:3) |
| 3823 | case Hexagon::S2_storerh_io: |
| 3824 | // memh(Rs+#u3:1) = Rt |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3825 | Src1Reg = MI.getOperand(0).getReg(); |
| 3826 | Src2Reg = MI.getOperand(2).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3827 | if (isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg) && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3828 | MI.getOperand(1).isImm() && |
| 3829 | isShiftedUInt<3,1>(MI.getOperand(1).getImm())) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3830 | return HexagonII::HSIG_S1; |
| 3831 | break; |
| 3832 | case Hexagon::S2_storerd_io: |
| 3833 | // memd(r29+#s6:3) = Rtt |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3834 | Src1Reg = MI.getOperand(0).getReg(); |
| 3835 | Src2Reg = MI.getOperand(2).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3836 | if (isDblRegForSubInst(Src2Reg, HRI) && |
| 3837 | Hexagon::IntRegsRegClass.contains(Src1Reg) && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3838 | HRI.getStackRegister() == Src1Reg && MI.getOperand(1).isImm() && |
| 3839 | isShiftedInt<6,3>(MI.getOperand(1).getImm())) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3840 | return HexagonII::HSIG_S2; |
| 3841 | break; |
| 3842 | case Hexagon::S4_storeiri_io: |
| 3843 | // memw(Rs+#u4:2) = #U1 |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3844 | Src1Reg = MI.getOperand(0).getReg(); |
| 3845 | if (isIntRegForSubInst(Src1Reg) && MI.getOperand(1).isImm() && |
| 3846 | isShiftedUInt<4,2>(MI.getOperand(1).getImm()) && |
| 3847 | MI.getOperand(2).isImm() && isUInt<1>(MI.getOperand(2).getImm())) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3848 | return HexagonII::HSIG_S2; |
| 3849 | break; |
| 3850 | case Hexagon::S4_storeirb_io: |
| 3851 | // memb(Rs+#u4) = #U1 |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3852 | Src1Reg = MI.getOperand(0).getReg(); |
Krzysztof Parzyszek | f2a4f8f | 2016-06-15 21:05:04 +0000 | [diff] [blame] | 3853 | if (isIntRegForSubInst(Src1Reg) && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3854 | MI.getOperand(1).isImm() && isUInt<4>(MI.getOperand(1).getImm()) && |
| 3855 | MI.getOperand(2).isImm() && isUInt<1>(MI.getOperand(2).getImm())) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3856 | return HexagonII::HSIG_S2; |
| 3857 | break; |
| 3858 | case Hexagon::S2_allocframe: |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3859 | if (MI.getOperand(0).isImm() && |
| 3860 | isShiftedUInt<5,3>(MI.getOperand(0).getImm())) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3861 | return HexagonII::HSIG_S1; |
| 3862 | break; |
| 3863 | // |
| 3864 | // Group A: |
| 3865 | // |
| 3866 | // Rx = add(Rx,#s7) |
| 3867 | // Rd = Rs |
| 3868 | // Rd = #u6 |
| 3869 | // Rd = #-1 |
| 3870 | // if ([!]P0[.new]) Rd = #0 |
| 3871 | // Rd = add(r29,#u6:2) |
| 3872 | // Rx = add(Rx,Rs) |
| 3873 | // P0 = cmp.eq(Rs,#u2) |
| 3874 | // Rdd = combine(#0,Rs) |
| 3875 | // Rdd = combine(Rs,#0) |
| 3876 | // Rdd = combine(#u2,#U2) |
| 3877 | // Rd = add(Rs,#1) |
| 3878 | // Rd = add(Rs,#-1) |
| 3879 | // Rd = sxth/sxtb/zxtb/zxth(Rs) |
| 3880 | // Rd = and(Rs,#1) |
| 3881 | case Hexagon::A2_addi: |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3882 | DstReg = MI.getOperand(0).getReg(); |
| 3883 | SrcReg = MI.getOperand(1).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3884 | if (isIntRegForSubInst(DstReg)) { |
| 3885 | // Rd = add(r29,#u6:2) |
| 3886 | if (Hexagon::IntRegsRegClass.contains(SrcReg) && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3887 | HRI.getStackRegister() == SrcReg && MI.getOperand(2).isImm() && |
| 3888 | isShiftedUInt<6,2>(MI.getOperand(2).getImm())) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3889 | return HexagonII::HSIG_A; |
| 3890 | // Rx = add(Rx,#s7) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3891 | if ((DstReg == SrcReg) && MI.getOperand(2).isImm() && |
| 3892 | isInt<7>(MI.getOperand(2).getImm())) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3893 | return HexagonII::HSIG_A; |
| 3894 | // Rd = add(Rs,#1) |
| 3895 | // Rd = add(Rs,#-1) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3896 | if (isIntRegForSubInst(SrcReg) && MI.getOperand(2).isImm() && |
| 3897 | ((MI.getOperand(2).getImm() == 1) || |
| 3898 | (MI.getOperand(2).getImm() == -1))) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3899 | return HexagonII::HSIG_A; |
| 3900 | } |
| 3901 | break; |
| 3902 | case Hexagon::A2_add: |
| 3903 | // Rx = add(Rx,Rs) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3904 | DstReg = MI.getOperand(0).getReg(); |
| 3905 | Src1Reg = MI.getOperand(1).getReg(); |
| 3906 | Src2Reg = MI.getOperand(2).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3907 | if (isIntRegForSubInst(DstReg) && (DstReg == Src1Reg) && |
| 3908 | isIntRegForSubInst(Src2Reg)) |
| 3909 | return HexagonII::HSIG_A; |
| 3910 | break; |
| 3911 | case Hexagon::A2_andir: |
| 3912 | // Same as zxtb. |
| 3913 | // Rd16=and(Rs16,#255) |
| 3914 | // Rd16=and(Rs16,#1) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3915 | DstReg = MI.getOperand(0).getReg(); |
| 3916 | SrcReg = MI.getOperand(1).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3917 | if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3918 | MI.getOperand(2).isImm() && |
| 3919 | ((MI.getOperand(2).getImm() == 1) || |
| 3920 | (MI.getOperand(2).getImm() == 255))) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3921 | return HexagonII::HSIG_A; |
| 3922 | break; |
| 3923 | case Hexagon::A2_tfr: |
| 3924 | // Rd = Rs |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3925 | DstReg = MI.getOperand(0).getReg(); |
| 3926 | SrcReg = MI.getOperand(1).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3927 | if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg)) |
| 3928 | return HexagonII::HSIG_A; |
| 3929 | break; |
| 3930 | case Hexagon::A2_tfrsi: |
| 3931 | // Rd = #u6 |
| 3932 | // Do not test for #u6 size since the const is getting extended |
| 3933 | // regardless and compound could be formed. |
| 3934 | // Rd = #-1 |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3935 | DstReg = MI.getOperand(0).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3936 | if (isIntRegForSubInst(DstReg)) |
| 3937 | return HexagonII::HSIG_A; |
| 3938 | break; |
| 3939 | case Hexagon::C2_cmoveit: |
| 3940 | case Hexagon::C2_cmovenewit: |
| 3941 | case Hexagon::C2_cmoveif: |
| 3942 | case Hexagon::C2_cmovenewif: |
| 3943 | // if ([!]P0[.new]) Rd = #0 |
| 3944 | // Actual form: |
| 3945 | // %R16<def> = C2_cmovenewit %P0<internal>, 0, %R16<imp-use,undef>; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3946 | DstReg = MI.getOperand(0).getReg(); |
| 3947 | SrcReg = MI.getOperand(1).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3948 | if (isIntRegForSubInst(DstReg) && |
| 3949 | Hexagon::PredRegsRegClass.contains(SrcReg) && Hexagon::P0 == SrcReg && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3950 | MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3951 | return HexagonII::HSIG_A; |
| 3952 | break; |
| 3953 | case Hexagon::C2_cmpeqi: |
| 3954 | // P0 = cmp.eq(Rs,#u2) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3955 | DstReg = MI.getOperand(0).getReg(); |
| 3956 | SrcReg = MI.getOperand(1).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3957 | if (Hexagon::PredRegsRegClass.contains(DstReg) && |
| 3958 | Hexagon::P0 == DstReg && isIntRegForSubInst(SrcReg) && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3959 | MI.getOperand(2).isImm() && isUInt<2>(MI.getOperand(2).getImm())) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3960 | return HexagonII::HSIG_A; |
| 3961 | break; |
| 3962 | case Hexagon::A2_combineii: |
| 3963 | case Hexagon::A4_combineii: |
| 3964 | // Rdd = combine(#u2,#U2) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3965 | DstReg = MI.getOperand(0).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3966 | if (isDblRegForSubInst(DstReg, HRI) && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3967 | ((MI.getOperand(1).isImm() && isUInt<2>(MI.getOperand(1).getImm())) || |
| 3968 | (MI.getOperand(1).isGlobal() && |
| 3969 | isUInt<2>(MI.getOperand(1).getOffset()))) && |
| 3970 | ((MI.getOperand(2).isImm() && isUInt<2>(MI.getOperand(2).getImm())) || |
| 3971 | (MI.getOperand(2).isGlobal() && |
| 3972 | isUInt<2>(MI.getOperand(2).getOffset())))) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3973 | return HexagonII::HSIG_A; |
| 3974 | break; |
| 3975 | case Hexagon::A4_combineri: |
| 3976 | // Rdd = combine(Rs,#0) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3977 | DstReg = MI.getOperand(0).getReg(); |
| 3978 | SrcReg = MI.getOperand(1).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3979 | if (isDblRegForSubInst(DstReg, HRI) && isIntRegForSubInst(SrcReg) && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3980 | ((MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0) || |
| 3981 | (MI.getOperand(2).isGlobal() && MI.getOperand(2).getOffset() == 0))) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3982 | return HexagonII::HSIG_A; |
| 3983 | break; |
| 3984 | case Hexagon::A4_combineir: |
| 3985 | // Rdd = combine(#0,Rs) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3986 | DstReg = MI.getOperand(0).getReg(); |
| 3987 | SrcReg = MI.getOperand(2).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3988 | if (isDblRegForSubInst(DstReg, HRI) && isIntRegForSubInst(SrcReg) && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3989 | ((MI.getOperand(1).isImm() && MI.getOperand(1).getImm() == 0) || |
| 3990 | (MI.getOperand(1).isGlobal() && MI.getOperand(1).getOffset() == 0))) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3991 | return HexagonII::HSIG_A; |
| 3992 | break; |
| 3993 | case Hexagon::A2_sxtb: |
| 3994 | case Hexagon::A2_sxth: |
| 3995 | case Hexagon::A2_zxtb: |
| 3996 | case Hexagon::A2_zxth: |
| 3997 | // Rd = sxth/sxtb/zxtb/zxth(Rs) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 3998 | DstReg = MI.getOperand(0).getReg(); |
| 3999 | SrcReg = MI.getOperand(1).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4000 | if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg)) |
| 4001 | return HexagonII::HSIG_A; |
| 4002 | break; |
| 4003 | } |
| 4004 | |
| 4005 | return HexagonII::HSIG_None; |
| 4006 | } |
| 4007 | |
| 4008 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4009 | short HexagonInstrInfo::getEquivalentHWInstr(const MachineInstr &MI) const { |
| 4010 | return Hexagon::getRealHWInstr(MI.getOpcode(), Hexagon::InstrType_Real); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4011 | } |
| 4012 | |
| 4013 | |
| 4014 | // Return first non-debug instruction in the basic block. |
| 4015 | MachineInstr *HexagonInstrInfo::getFirstNonDbgInst(MachineBasicBlock *BB) |
| 4016 | const { |
| 4017 | for (auto MII = BB->instr_begin(), End = BB->instr_end(); MII != End; MII++) { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4018 | MachineInstr &MI = *MII; |
| 4019 | if (MI.isDebugValue()) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4020 | continue; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4021 | return &MI; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4022 | } |
| 4023 | return nullptr; |
| 4024 | } |
| 4025 | |
| 4026 | |
| 4027 | unsigned HexagonInstrInfo::getInstrTimingClassLatency( |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4028 | const InstrItineraryData *ItinData, const MachineInstr &MI) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4029 | // Default to one cycle for no itinerary. However, an "empty" itinerary may |
| 4030 | // still have a MinLatency property, which getStageLatency checks. |
| 4031 | if (!ItinData) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4032 | return getInstrLatency(ItinData, MI); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4033 | |
| 4034 | // Get the latency embedded in the itinerary. If we're not using timing class |
| 4035 | // latencies or if we using BSB scheduling, then restrict the maximum latency |
| 4036 | // to 1 (that is, either 0 or 1). |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4037 | if (MI.isTransient()) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4038 | return 0; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4039 | unsigned Latency = ItinData->getStageLatency(MI.getDesc().getSchedClass()); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4040 | if (!EnableTimingClassLatency || |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4041 | MI.getParent()->getParent()->getSubtarget<HexagonSubtarget>(). |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4042 | useBSBScheduling()) |
| 4043 | if (Latency > 1) |
| 4044 | Latency = 1; |
| 4045 | return Latency; |
| 4046 | } |
| 4047 | |
| 4048 | |
| 4049 | // inverts the predication logic. |
| 4050 | // p -> NotP |
| 4051 | // NotP -> P |
| 4052 | bool HexagonInstrInfo::getInvertedPredSense( |
| 4053 | SmallVectorImpl<MachineOperand> &Cond) const { |
| 4054 | if (Cond.empty()) |
| 4055 | return false; |
| 4056 | unsigned Opc = getInvertedPredicatedOpcode(Cond[0].getImm()); |
| 4057 | Cond[0].setImm(Opc); |
| 4058 | return true; |
| 4059 | } |
| 4060 | |
| 4061 | |
| 4062 | unsigned HexagonInstrInfo::getInvertedPredicatedOpcode(const int Opc) const { |
| 4063 | int InvPredOpcode; |
| 4064 | InvPredOpcode = isPredicatedTrue(Opc) ? Hexagon::getFalsePredOpcode(Opc) |
| 4065 | : Hexagon::getTruePredOpcode(Opc); |
| 4066 | if (InvPredOpcode >= 0) // Valid instruction with the inverted predicate. |
| 4067 | return InvPredOpcode; |
| 4068 | |
| 4069 | llvm_unreachable("Unexpected predicated instruction"); |
| 4070 | } |
| 4071 | |
| 4072 | |
| 4073 | // Returns the max value that doesn't need to be extended. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4074 | int HexagonInstrInfo::getMaxValue(const MachineInstr &MI) const { |
| 4075 | const uint64_t F = MI.getDesc().TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4076 | unsigned isSigned = (F >> HexagonII::ExtentSignedPos) |
| 4077 | & HexagonII::ExtentSignedMask; |
| 4078 | unsigned bits = (F >> HexagonII::ExtentBitsPos) |
| 4079 | & HexagonII::ExtentBitsMask; |
| 4080 | |
| 4081 | if (isSigned) // if value is signed |
| 4082 | return ~(-1U << (bits - 1)); |
| 4083 | else |
| 4084 | return ~(-1U << bits); |
| 4085 | } |
| 4086 | |
| 4087 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4088 | unsigned HexagonInstrInfo::getMemAccessSize(const MachineInstr &MI) const { |
| 4089 | const uint64_t F = MI.getDesc().TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4090 | return (F >> HexagonII::MemAccessSizePos) & HexagonII::MemAccesSizeMask; |
| 4091 | } |
| 4092 | |
| 4093 | |
| 4094 | // Returns the min value that doesn't need to be extended. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4095 | int HexagonInstrInfo::getMinValue(const MachineInstr &MI) const { |
| 4096 | const uint64_t F = MI.getDesc().TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4097 | unsigned isSigned = (F >> HexagonII::ExtentSignedPos) |
| 4098 | & HexagonII::ExtentSignedMask; |
| 4099 | unsigned bits = (F >> HexagonII::ExtentBitsPos) |
| 4100 | & HexagonII::ExtentBitsMask; |
| 4101 | |
| 4102 | if (isSigned) // if value is signed |
| 4103 | return -1U << (bits - 1); |
| 4104 | else |
| 4105 | return 0; |
| 4106 | } |
| 4107 | |
| 4108 | |
| 4109 | // Returns opcode of the non-extended equivalent instruction. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4110 | short HexagonInstrInfo::getNonExtOpcode(const MachineInstr &MI) const { |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 4111 | // Check if the instruction has a register form that uses register in place |
| 4112 | // of the extended operand, if so return that as the non-extended form. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4113 | short NonExtOpcode = Hexagon::getRegForm(MI.getOpcode()); |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 4114 | if (NonExtOpcode >= 0) |
| 4115 | return NonExtOpcode; |
| 4116 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4117 | if (MI.getDesc().mayLoad() || MI.getDesc().mayStore()) { |
Alp Toker | cb40291 | 2014-01-24 17:20:08 +0000 | [diff] [blame] | 4118 | // Check addressing mode and retrieve non-ext equivalent instruction. |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 4119 | switch (getAddrMode(MI)) { |
| 4120 | case HexagonII::Absolute : |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4121 | return Hexagon::getBaseWithImmOffset(MI.getOpcode()); |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 4122 | case HexagonII::BaseImmOffset : |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4123 | return Hexagon::getBaseWithRegOffset(MI.getOpcode()); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4124 | case HexagonII::BaseLongOffset: |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4125 | return Hexagon::getRegShlForm(MI.getOpcode()); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4126 | |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 4127 | default: |
| 4128 | return -1; |
| 4129 | } |
| 4130 | } |
| 4131 | return -1; |
| 4132 | } |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 4133 | |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 4134 | |
Ahmed Bougacha | c88bf54 | 2015-06-11 19:30:37 +0000 | [diff] [blame] | 4135 | bool HexagonInstrInfo::getPredReg(ArrayRef<MachineOperand> Cond, |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4136 | unsigned &PredReg, unsigned &PredRegPos, unsigned &PredRegFlags) const { |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 4137 | if (Cond.empty()) |
| 4138 | return false; |
| 4139 | assert(Cond.size() == 2); |
| 4140 | if (isNewValueJump(Cond[0].getImm()) || Cond[1].isMBB()) { |
Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 4141 | DEBUG(dbgs() << "No predregs for new-value jumps/endloop"); |
| 4142 | return false; |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 4143 | } |
| 4144 | PredReg = Cond[1].getReg(); |
| 4145 | PredRegPos = 1; |
| 4146 | // See IfConversion.cpp why we add RegState::Implicit | RegState::Undef |
| 4147 | PredRegFlags = 0; |
| 4148 | if (Cond[1].isImplicit()) |
| 4149 | PredRegFlags = RegState::Implicit; |
| 4150 | if (Cond[1].isUndef()) |
| 4151 | PredRegFlags |= RegState::Undef; |
| 4152 | return true; |
| 4153 | } |
| 4154 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4155 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4156 | short HexagonInstrInfo::getPseudoInstrPair(const MachineInstr &MI) const { |
| 4157 | return Hexagon::getRealHWInstr(MI.getOpcode(), Hexagon::InstrType_Pseudo); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4158 | } |
| 4159 | |
| 4160 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4161 | short HexagonInstrInfo::getRegForm(const MachineInstr &MI) const { |
| 4162 | return Hexagon::getRegForm(MI.getOpcode()); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4163 | } |
| 4164 | |
| 4165 | |
| 4166 | // Return the number of bytes required to encode the instruction. |
| 4167 | // Hexagon instructions are fixed length, 4 bytes, unless they |
| 4168 | // use a constant extender, which requires another 4 bytes. |
| 4169 | // For debug instructions and prolog labels, return 0. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4170 | unsigned HexagonInstrInfo::getSize(const MachineInstr &MI) const { |
| 4171 | if (MI.isDebugValue() || MI.isPosition()) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4172 | return 0; |
| 4173 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4174 | unsigned Size = MI.getDesc().getSize(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4175 | if (!Size) |
| 4176 | // Assume the default insn size in case it cannot be determined |
| 4177 | // for whatever reason. |
| 4178 | Size = HEXAGON_INSTR_SIZE; |
| 4179 | |
| 4180 | if (isConstExtended(MI) || isExtended(MI)) |
| 4181 | Size += HEXAGON_INSTR_SIZE; |
| 4182 | |
| 4183 | // Try and compute number of instructions in asm. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4184 | if (BranchRelaxAsmLarge && MI.getOpcode() == Hexagon::INLINEASM) { |
| 4185 | const MachineBasicBlock &MBB = *MI.getParent(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4186 | const MachineFunction *MF = MBB.getParent(); |
| 4187 | const MCAsmInfo *MAI = MF->getTarget().getMCAsmInfo(); |
| 4188 | |
| 4189 | // Count the number of register definitions to find the asm string. |
| 4190 | unsigned NumDefs = 0; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4191 | for (; MI.getOperand(NumDefs).isReg() && MI.getOperand(NumDefs).isDef(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4192 | ++NumDefs) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4193 | assert(NumDefs != MI.getNumOperands()-2 && "No asm string?"); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4194 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4195 | assert(MI.getOperand(NumDefs).isSymbol() && "No asm string?"); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4196 | // Disassemble the AsmStr and approximate number of instructions. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4197 | const char *AsmStr = MI.getOperand(NumDefs).getSymbolName(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4198 | Size = getInlineAsmLength(AsmStr, *MAI); |
| 4199 | } |
| 4200 | |
| 4201 | return Size; |
| 4202 | } |
| 4203 | |
| 4204 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4205 | uint64_t HexagonInstrInfo::getType(const MachineInstr &MI) const { |
| 4206 | const uint64_t F = MI.getDesc().TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4207 | return (F >> HexagonII::TypePos) & HexagonII::TypeMask; |
| 4208 | } |
| 4209 | |
| 4210 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4211 | unsigned HexagonInstrInfo::getUnits(const MachineInstr &MI) const { |
| 4212 | const TargetSubtargetInfo &ST = MI.getParent()->getParent()->getSubtarget(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4213 | const InstrItineraryData &II = *ST.getInstrItineraryData(); |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4214 | const InstrStage &IS = *II.beginStage(MI.getDesc().getSchedClass()); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4215 | |
| 4216 | return IS.getUnits(); |
| 4217 | } |
| 4218 | |
| 4219 | |
| 4220 | unsigned HexagonInstrInfo::getValidSubTargets(const unsigned Opcode) const { |
| 4221 | const uint64_t F = get(Opcode).TSFlags; |
| 4222 | return (F >> HexagonII::validSubTargetPos) & HexagonII::validSubTargetMask; |
| 4223 | } |
| 4224 | |
| 4225 | |
| 4226 | // Calculate size of the basic block without debug instructions. |
| 4227 | unsigned HexagonInstrInfo::nonDbgBBSize(const MachineBasicBlock *BB) const { |
| 4228 | return nonDbgMICount(BB->instr_begin(), BB->instr_end()); |
| 4229 | } |
| 4230 | |
| 4231 | |
| 4232 | unsigned HexagonInstrInfo::nonDbgBundleSize( |
| 4233 | MachineBasicBlock::const_iterator BundleHead) const { |
| 4234 | assert(BundleHead->isBundle() && "Not a bundle header"); |
Duncan P. N. Exon Smith | d84f600 | 2016-02-22 21:30:15 +0000 | [diff] [blame] | 4235 | auto MII = BundleHead.getInstrIterator(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4236 | // Skip the bundle header. |
Duncan P. N. Exon Smith | f9ab416 | 2016-02-27 17:05:33 +0000 | [diff] [blame] | 4237 | return nonDbgMICount(++MII, getBundleEnd(*BundleHead)); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4238 | } |
| 4239 | |
| 4240 | |
| 4241 | /// immediateExtend - Changes the instruction in place to one using an immediate |
| 4242 | /// extender. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4243 | void HexagonInstrInfo::immediateExtend(MachineInstr &MI) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4244 | assert((isExtendable(MI)||isConstExtended(MI)) && |
| 4245 | "Instruction must be extendable"); |
| 4246 | // Find which operand is extendable. |
| 4247 | short ExtOpNum = getCExtOpNum(MI); |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4248 | MachineOperand &MO = MI.getOperand(ExtOpNum); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4249 | // This needs to be something we understand. |
| 4250 | assert((MO.isMBB() || MO.isImm()) && |
| 4251 | "Branch with unknown extendable field type"); |
| 4252 | // Mark given operand as extended. |
| 4253 | MO.addTargetFlag(HexagonII::HMOTF_ConstExtended); |
| 4254 | } |
| 4255 | |
| 4256 | |
| 4257 | bool HexagonInstrInfo::invertAndChangeJumpTarget( |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4258 | MachineInstr &MI, MachineBasicBlock *NewTarget) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4259 | DEBUG(dbgs() << "\n[invertAndChangeJumpTarget] to BB#" |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4260 | << NewTarget->getNumber(); MI.dump();); |
| 4261 | assert(MI.isBranch()); |
| 4262 | unsigned NewOpcode = getInvertedPredicatedOpcode(MI.getOpcode()); |
| 4263 | int TargetPos = MI.getNumOperands() - 1; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4264 | // In general branch target is the last operand, |
| 4265 | // but some implicit defs added at the end might change it. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4266 | while ((TargetPos > -1) && !MI.getOperand(TargetPos).isMBB()) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4267 | --TargetPos; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4268 | assert((TargetPos >= 0) && MI.getOperand(TargetPos).isMBB()); |
| 4269 | MI.getOperand(TargetPos).setMBB(NewTarget); |
| 4270 | if (EnableBranchPrediction && isPredicatedNew(MI)) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4271 | NewOpcode = reversePrediction(NewOpcode); |
| 4272 | } |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4273 | MI.setDesc(get(NewOpcode)); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4274 | return true; |
| 4275 | } |
| 4276 | |
| 4277 | |
| 4278 | void HexagonInstrInfo::genAllInsnTimingClasses(MachineFunction &MF) const { |
| 4279 | /* +++ The code below is used to generate complete set of Hexagon Insn +++ */ |
| 4280 | MachineFunction::iterator A = MF.begin(); |
| 4281 | MachineBasicBlock &B = *A; |
| 4282 | MachineBasicBlock::iterator I = B.begin(); |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4283 | DebugLoc DL = I->getDebugLoc(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4284 | MachineInstr *NewMI; |
| 4285 | |
| 4286 | for (unsigned insn = TargetOpcode::GENERIC_OP_END+1; |
| 4287 | insn < Hexagon::INSTRUCTION_LIST_END; ++insn) { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4288 | NewMI = BuildMI(B, I, DL, get(insn)); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4289 | DEBUG(dbgs() << "\n" << getName(NewMI->getOpcode()) << |
| 4290 | " Class: " << NewMI->getDesc().getSchedClass()); |
| 4291 | NewMI->eraseFromParent(); |
| 4292 | } |
| 4293 | /* --- The code above is used to generate complete set of Hexagon Insn --- */ |
| 4294 | } |
| 4295 | |
| 4296 | |
| 4297 | // inverts the predication logic. |
| 4298 | // p -> NotP |
| 4299 | // NotP -> P |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4300 | bool HexagonInstrInfo::reversePredSense(MachineInstr &MI) const { |
| 4301 | DEBUG(dbgs() << "\nTrying to reverse pred. sense of:"; MI.dump()); |
| 4302 | MI.setDesc(get(getInvertedPredicatedOpcode(MI.getOpcode()))); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4303 | return true; |
| 4304 | } |
| 4305 | |
| 4306 | |
| 4307 | // Reverse the branch prediction. |
| 4308 | unsigned HexagonInstrInfo::reversePrediction(unsigned Opcode) const { |
| 4309 | int PredRevOpcode = -1; |
| 4310 | if (isPredictedTaken(Opcode)) |
| 4311 | PredRevOpcode = Hexagon::notTakenBranchPrediction(Opcode); |
| 4312 | else |
| 4313 | PredRevOpcode = Hexagon::takenBranchPrediction(Opcode); |
| 4314 | assert(PredRevOpcode > 0); |
| 4315 | return PredRevOpcode; |
| 4316 | } |
| 4317 | |
| 4318 | |
| 4319 | // TODO: Add more rigorous validation. |
| 4320 | bool HexagonInstrInfo::validateBranchCond(const ArrayRef<MachineOperand> &Cond) |
| 4321 | const { |
| 4322 | return Cond.empty() || (Cond[0].isImm() && (Cond.size() != 1)); |
| 4323 | } |
| 4324 | |
Krzysztof Parzyszek | f5cbac9 | 2016-04-29 15:49:13 +0000 | [diff] [blame] | 4325 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 4326 | short HexagonInstrInfo::xformRegToImmOffset(const MachineInstr &MI) const { |
| 4327 | return Hexagon::xformRegToImmOffset(MI.getOpcode()); |
Krzysztof Parzyszek | f5cbac9 | 2016-04-29 15:49:13 +0000 | [diff] [blame] | 4328 | } |