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