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). |
| 180 | static inline void parseOperands(const MachineInstr *MI, |
| 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 | b9a1c3a | 2015-11-24 14:55:26 +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); |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +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); |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +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, |
| 687 | MachineInstr *IndVar, MachineInstr *Cmp, |
| 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. |
| 693 | assert((!IndVar) && isEndLoopN(Cmp->getOpcode()) |
| 694 | && "Expecting a hardware loop"); |
| 695 | MachineFunction *MF = MBB.getParent(); |
| 696 | DebugLoc DL = Cmp->getDebugLoc(); |
| 697 | SmallPtrSet<MachineBasicBlock *, 8> VisitedBBs; |
| 698 | MachineInstr *Loop = findLoopInstr(&MBB, Cmp->getOpcode(), VisitedBBs); |
| 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; |
Krzysztof Parzyszek | 70a134d | 2015-11-25 21:40:03 +0000 | [diff] [blame] | 1304 | case Hexagon::TFRI_f: |
| 1305 | case Hexagon::TFRI_cPt_f: |
| 1306 | case Hexagon::TFRI_cNotPt_f: { |
| 1307 | unsigned Opx = (Opc == Hexagon::TFRI_f) ? 1 : 2; |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1308 | APFloat FVal = MI.getOperand(Opx).getFPImm()->getValueAPF(); |
Krzysztof Parzyszek | 70a134d | 2015-11-25 21:40:03 +0000 | [diff] [blame] | 1309 | APInt IVal = FVal.bitcastToAPInt(); |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1310 | MI.RemoveOperand(Opx); |
Krzysztof Parzyszek | 70a134d | 2015-11-25 21:40:03 +0000 | [diff] [blame] | 1311 | unsigned NewOpc = (Opc == Hexagon::TFRI_f) ? Hexagon::A2_tfrsi : |
| 1312 | (Opc == Hexagon::TFRI_cPt_f) ? Hexagon::C2_cmoveit : |
| 1313 | Hexagon::C2_cmoveif; |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1314 | MI.setDesc(get(NewOpc)); |
| 1315 | MI.addOperand(MachineOperand::CreateImm(IVal.getZExtValue())); |
Krzysztof Parzyszek | 70a134d | 2015-11-25 21:40:03 +0000 | [diff] [blame] | 1316 | return true; |
| 1317 | } |
Colin LeMahieu | 7b1799c | 2015-03-09 22:05:21 +0000 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | return false; |
| 1321 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1322 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1323 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1324 | // We indicate that we want to reverse the branch by |
| 1325 | // inserting the reversed branching opcode. |
| 1326 | bool HexagonInstrInfo::ReverseBranchCondition( |
| 1327 | SmallVectorImpl<MachineOperand> &Cond) const { |
| 1328 | if (Cond.empty()) |
Jyotsna Verma | f1214a8 | 2013-03-05 18:51:42 +0000 | [diff] [blame] | 1329 | return true; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1330 | assert(Cond[0].isImm() && "First entry in the cond vector not imm-val"); |
| 1331 | unsigned opcode = Cond[0].getImm(); |
| 1332 | //unsigned temp; |
| 1333 | assert(get(opcode).isBranch() && "Should be a branching condition."); |
| 1334 | if (isEndLoopN(opcode)) |
Jyotsna Verma | f1214a8 | 2013-03-05 18:51:42 +0000 | [diff] [blame] | 1335 | return true; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1336 | unsigned NewOpcode = getInvertedPredicatedOpcode(opcode); |
| 1337 | Cond[0].setImm(NewOpcode); |
Jyotsna Verma | f1214a8 | 2013-03-05 18:51:42 +0000 | [diff] [blame] | 1338 | return false; |
| 1339 | } |
| 1340 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1341 | |
| 1342 | void HexagonInstrInfo::insertNoop(MachineBasicBlock &MBB, |
| 1343 | MachineBasicBlock::iterator MI) const { |
| 1344 | DebugLoc DL; |
| 1345 | BuildMI(MBB, MI, DL, get(Hexagon::A2_nop)); |
| 1346 | } |
| 1347 | |
| 1348 | |
| 1349 | // Returns true if an instruction is predicated irrespective of the predicate |
| 1350 | // sense. For example, all of the following will return true. |
| 1351 | // if (p0) R1 = add(R2, R3) |
| 1352 | // if (!p0) R1 = add(R2, R3) |
| 1353 | // if (p0.new) R1 = add(R2, R3) |
| 1354 | // if (!p0.new) R1 = add(R2, R3) |
| 1355 | // Note: New-value stores are not included here as in the current |
| 1356 | // 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] | 1357 | bool HexagonInstrInfo::isPredicated(const MachineInstr &MI) const { |
| 1358 | const uint64_t F = MI.getDesc().TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1359 | return (F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask; |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
Krzysztof Parzyszek | 0a04ac2 | 2016-05-16 16:56:10 +0000 | [diff] [blame] | 1362 | |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1363 | bool HexagonInstrInfo::PredicateInstruction( |
| 1364 | MachineInstr &MI, ArrayRef<MachineOperand> Cond) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1365 | if (Cond.empty() || isNewValueJump(Cond[0].getImm()) || |
| 1366 | isEndLoopN(Cond[0].getImm())) { |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1367 | DEBUG(dbgs() << "\nCannot predicate:"; MI.dump();); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1368 | return false; |
| 1369 | } |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1370 | int Opc = MI.getOpcode(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1371 | assert (isPredicable(MI) && "Expected predicable instruction"); |
| 1372 | bool invertJump = predOpcodeHasNot(Cond); |
| 1373 | |
| 1374 | // We have to predicate MI "in place", i.e. after this function returns, |
| 1375 | // MI will need to be transformed into a predicated form. To avoid com- |
| 1376 | // plicated manipulations with the operands (handling tied operands, |
| 1377 | // etc.), build a new temporary instruction, then overwrite MI with it. |
| 1378 | |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1379 | MachineBasicBlock &B = *MI.getParent(); |
| 1380 | DebugLoc DL = MI.getDebugLoc(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1381 | unsigned PredOpc = getCondOpcode(Opc, invertJump); |
| 1382 | MachineInstrBuilder T = BuildMI(B, MI, DL, get(PredOpc)); |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1383 | unsigned NOp = 0, NumOps = MI.getNumOperands(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1384 | while (NOp < NumOps) { |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1385 | MachineOperand &Op = MI.getOperand(NOp); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1386 | if (!Op.isReg() || !Op.isDef() || Op.isImplicit()) |
| 1387 | break; |
| 1388 | T.addOperand(Op); |
| 1389 | NOp++; |
| 1390 | } |
| 1391 | |
| 1392 | unsigned PredReg, PredRegPos, PredRegFlags; |
| 1393 | bool GotPredReg = getPredReg(Cond, PredReg, PredRegPos, PredRegFlags); |
| 1394 | (void)GotPredReg; |
| 1395 | assert(GotPredReg); |
| 1396 | T.addReg(PredReg, PredRegFlags); |
| 1397 | while (NOp < NumOps) |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1398 | T.addOperand(MI.getOperand(NOp++)); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1399 | |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1400 | MI.setDesc(get(PredOpc)); |
| 1401 | while (unsigned n = MI.getNumOperands()) |
| 1402 | MI.RemoveOperand(n-1); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1403 | 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] | 1404 | MI.addOperand(T->getOperand(i)); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1405 | |
Duncan P. N. Exon Smith | c5b668d | 2016-02-22 20:49:58 +0000 | [diff] [blame] | 1406 | MachineBasicBlock::instr_iterator TI = T->getIterator(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1407 | B.erase(TI); |
| 1408 | |
| 1409 | MachineRegisterInfo &MRI = B.getParent()->getRegInfo(); |
| 1410 | MRI.clearKillFlags(PredReg); |
| 1411 | return true; |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 1412 | } |
| 1413 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1414 | |
| 1415 | bool HexagonInstrInfo::SubsumesPredicate(ArrayRef<MachineOperand> Pred1, |
| 1416 | ArrayRef<MachineOperand> Pred2) const { |
| 1417 | // TODO: Fix this |
| 1418 | return false; |
| 1419 | } |
| 1420 | |
Krzysztof Parzyszek | 0a04ac2 | 2016-05-16 16:56:10 +0000 | [diff] [blame] | 1421 | |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1422 | bool HexagonInstrInfo::DefinesPredicate( |
| 1423 | MachineInstr &MI, std::vector<MachineOperand> &Pred) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1424 | auto &HRI = getRegisterInfo(); |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1425 | for (unsigned oper = 0; oper < MI.getNumOperands(); ++oper) { |
| 1426 | MachineOperand MO = MI.getOperand(oper); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1427 | if (MO.isReg() && MO.isDef()) { |
| 1428 | const TargetRegisterClass* RC = HRI.getMinimalPhysRegClass(MO.getReg()); |
| 1429 | if (RC == &Hexagon::PredRegsRegClass) { |
| 1430 | Pred.push_back(MO); |
| 1431 | return true; |
| 1432 | } |
| 1433 | } |
| 1434 | } |
| 1435 | return false; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1436 | } |
Andrew Trick | d06df96 | 2012-02-01 22:13:57 +0000 | [diff] [blame] | 1437 | |
Krzysztof Parzyszek | 0a04ac2 | 2016-05-16 16:56:10 +0000 | [diff] [blame] | 1438 | |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1439 | bool HexagonInstrInfo::isPredicable(MachineInstr &MI) const { |
Krzysztof Parzyszek | 0a04ac2 | 2016-05-16 16:56:10 +0000 | [diff] [blame] | 1440 | return MI.getDesc().isPredicable(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1441 | } |
| 1442 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1443 | bool HexagonInstrInfo::isSchedulingBoundary(const MachineInstr &MI, |
| 1444 | const MachineBasicBlock *MBB, |
| 1445 | const MachineFunction &MF) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1446 | // Debug info is never a scheduling boundary. It's necessary to be explicit |
| 1447 | // due to the special treatment of IT instructions below, otherwise a |
| 1448 | // dbg_value followed by an IT will result in the IT instruction being |
| 1449 | // considered a scheduling hazard, which is wrong. It should be the actual |
| 1450 | // instruction preceding the dbg_value instruction(s), just like it is |
| 1451 | // when debug info is not present. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1452 | if (MI.isDebugValue()) |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 1453 | return false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1454 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1455 | // Throwing call is a boundary. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1456 | if (MI.isCall()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1457 | // If any of the block's successors is a landing pad, this could be a |
| 1458 | // throwing call. |
| 1459 | for (auto I : MBB->successors()) |
| 1460 | if (I->isEHPad()) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1461 | return true; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | // Don't mess around with no return calls. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1465 | if (MI.getOpcode() == Hexagon::CALLv3nr) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1466 | return true; |
| 1467 | |
| 1468 | // Terminators and labels can't be scheduled around. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1469 | if (MI.getDesc().isTerminator() || MI.isPosition()) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1470 | return true; |
| 1471 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1472 | if (MI.isInlineAsm() && !ScheduleInlineAsm) |
| 1473 | return true; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1474 | |
| 1475 | return false; |
| 1476 | } |
| 1477 | |
| 1478 | |
| 1479 | /// Measure the specified inline asm to determine an approximation of its |
| 1480 | /// length. |
| 1481 | /// Comments (which run till the next SeparatorString or newline) do not |
| 1482 | /// count as an instruction. |
| 1483 | /// Any other non-whitespace text is considered an instruction, with |
| 1484 | /// multiple instructions separated by SeparatorString or newlines. |
| 1485 | /// Variable-length instructions are not handled here; this function |
| 1486 | /// may be overloaded in the target code to do that. |
| 1487 | /// Hexagon counts the number of ##'s and adjust for that many |
| 1488 | /// constant exenders. |
| 1489 | unsigned HexagonInstrInfo::getInlineAsmLength(const char *Str, |
| 1490 | const MCAsmInfo &MAI) const { |
| 1491 | StringRef AStr(Str); |
| 1492 | // Count the number of instructions in the asm. |
| 1493 | bool atInsnStart = true; |
| 1494 | unsigned Length = 0; |
| 1495 | for (; *Str; ++Str) { |
| 1496 | if (*Str == '\n' || strncmp(Str, MAI.getSeparatorString(), |
| 1497 | strlen(MAI.getSeparatorString())) == 0) |
| 1498 | atInsnStart = true; |
| 1499 | if (atInsnStart && !std::isspace(static_cast<unsigned char>(*Str))) { |
| 1500 | Length += MAI.getMaxInstLength(); |
| 1501 | atInsnStart = false; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1502 | } |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1503 | if (atInsnStart && strncmp(Str, MAI.getCommentString(), |
| 1504 | strlen(MAI.getCommentString())) == 0) |
| 1505 | atInsnStart = false; |
| 1506 | } |
| 1507 | |
| 1508 | // Add to size number of constant extenders seen * 4. |
| 1509 | StringRef Occ("##"); |
| 1510 | Length += AStr.count(Occ)*4; |
| 1511 | return Length; |
| 1512 | } |
| 1513 | |
| 1514 | |
| 1515 | ScheduleHazardRecognizer* |
| 1516 | HexagonInstrInfo::CreateTargetPostRAHazardRecognizer( |
| 1517 | const InstrItineraryData *II, const ScheduleDAG *DAG) const { |
Krzysztof Parzyszek | e95e955 | 2016-07-29 13:59:09 +0000 | [diff] [blame] | 1518 | if (UseDFAHazardRec) { |
| 1519 | auto &HST = DAG->MF.getSubtarget<HexagonSubtarget>(); |
| 1520 | return new HexagonHazardRecognizer(II, this, HST); |
| 1521 | } |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1522 | return TargetInstrInfo::CreateTargetPostRAHazardRecognizer(II, DAG); |
| 1523 | } |
| 1524 | |
| 1525 | |
| 1526 | /// \brief For a comparison instruction, return the source registers in |
| 1527 | /// \p SrcReg and \p SrcReg2 if having two register operands, and the value it |
| 1528 | /// compares against in CmpValue. Return true if the comparison instruction |
| 1529 | /// can be analyzed. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1530 | bool HexagonInstrInfo::analyzeCompare(const MachineInstr &MI, unsigned &SrcReg, |
| 1531 | unsigned &SrcReg2, int &Mask, |
| 1532 | int &Value) const { |
| 1533 | unsigned Opc = MI.getOpcode(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1534 | |
| 1535 | // Set mask and the first source register. |
| 1536 | switch (Opc) { |
| 1537 | case Hexagon::C2_cmpeq: |
| 1538 | case Hexagon::C2_cmpeqp: |
| 1539 | case Hexagon::C2_cmpgt: |
| 1540 | case Hexagon::C2_cmpgtp: |
| 1541 | case Hexagon::C2_cmpgtu: |
| 1542 | case Hexagon::C2_cmpgtup: |
| 1543 | case Hexagon::C4_cmpneq: |
| 1544 | case Hexagon::C4_cmplte: |
| 1545 | case Hexagon::C4_cmplteu: |
| 1546 | case Hexagon::C2_cmpeqi: |
| 1547 | case Hexagon::C2_cmpgti: |
| 1548 | case Hexagon::C2_cmpgtui: |
| 1549 | case Hexagon::C4_cmpneqi: |
| 1550 | case Hexagon::C4_cmplteui: |
| 1551 | case Hexagon::C4_cmpltei: |
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 = ~0; |
| 1554 | break; |
| 1555 | case Hexagon::A4_cmpbeq: |
| 1556 | case Hexagon::A4_cmpbgt: |
| 1557 | case Hexagon::A4_cmpbgtu: |
| 1558 | case Hexagon::A4_cmpbeqi: |
| 1559 | case Hexagon::A4_cmpbgti: |
| 1560 | case Hexagon::A4_cmpbgtui: |
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 = 0xFF; |
| 1563 | break; |
| 1564 | case Hexagon::A4_cmpheq: |
| 1565 | case Hexagon::A4_cmphgt: |
| 1566 | case Hexagon::A4_cmphgtu: |
| 1567 | case Hexagon::A4_cmpheqi: |
| 1568 | case Hexagon::A4_cmphgti: |
| 1569 | case Hexagon::A4_cmphgtui: |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1570 | SrcReg = MI.getOperand(1).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1571 | Mask = 0xFFFF; |
| 1572 | break; |
| 1573 | } |
| 1574 | |
| 1575 | // Set the value/second source register. |
| 1576 | switch (Opc) { |
| 1577 | case Hexagon::C2_cmpeq: |
| 1578 | case Hexagon::C2_cmpeqp: |
| 1579 | case Hexagon::C2_cmpgt: |
| 1580 | case Hexagon::C2_cmpgtp: |
| 1581 | case Hexagon::C2_cmpgtu: |
| 1582 | case Hexagon::C2_cmpgtup: |
| 1583 | case Hexagon::A4_cmpbeq: |
| 1584 | case Hexagon::A4_cmpbgt: |
| 1585 | case Hexagon::A4_cmpbgtu: |
| 1586 | case Hexagon::A4_cmpheq: |
| 1587 | case Hexagon::A4_cmphgt: |
| 1588 | case Hexagon::A4_cmphgtu: |
| 1589 | case Hexagon::C4_cmpneq: |
| 1590 | case Hexagon::C4_cmplte: |
| 1591 | case Hexagon::C4_cmplteu: |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1592 | SrcReg2 = MI.getOperand(2).getReg(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1593 | return true; |
| 1594 | |
| 1595 | case Hexagon::C2_cmpeqi: |
| 1596 | case Hexagon::C2_cmpgtui: |
| 1597 | case Hexagon::C2_cmpgti: |
| 1598 | case Hexagon::C4_cmpneqi: |
| 1599 | case Hexagon::C4_cmplteui: |
| 1600 | case Hexagon::C4_cmpltei: |
| 1601 | case Hexagon::A4_cmpbeqi: |
| 1602 | case Hexagon::A4_cmpbgti: |
| 1603 | case Hexagon::A4_cmpbgtui: |
| 1604 | case Hexagon::A4_cmpheqi: |
| 1605 | case Hexagon::A4_cmphgti: |
| 1606 | case Hexagon::A4_cmphgtui: |
| 1607 | SrcReg2 = 0; |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1608 | Value = MI.getOperand(2).getImm(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1609 | return true; |
| 1610 | } |
| 1611 | |
| 1612 | return false; |
| 1613 | } |
| 1614 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1615 | unsigned HexagonInstrInfo::getInstrLatency(const InstrItineraryData *ItinData, |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1616 | const MachineInstr &MI, |
| 1617 | unsigned *PredCost) const { |
| 1618 | return getInstrTimingClassLatency(ItinData, &MI); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | |
| 1622 | DFAPacketizer *HexagonInstrInfo::CreateTargetScheduleState( |
| 1623 | const TargetSubtargetInfo &STI) const { |
| 1624 | const InstrItineraryData *II = STI.getInstrItineraryData(); |
| 1625 | return static_cast<const HexagonSubtarget&>(STI).createDFAPacketizer(II); |
| 1626 | } |
| 1627 | |
| 1628 | |
| 1629 | // Inspired by this pair: |
| 1630 | // %R13<def> = L2_loadri_io %R29, 136; mem:LD4[FixedStack0] |
| 1631 | // S2_storeri_io %R29, 132, %R1<kill>; flags: mem:ST4[FixedStack1] |
| 1632 | // 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] | 1633 | bool HexagonInstrInfo::areMemAccessesTriviallyDisjoint( |
| 1634 | MachineInstr &MIa, MachineInstr &MIb, AliasAnalysis *AA) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1635 | int OffsetA = 0, OffsetB = 0; |
| 1636 | unsigned SizeA = 0, SizeB = 0; |
| 1637 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1638 | if (MIa.hasUnmodeledSideEffects() || MIb.hasUnmodeledSideEffects() || |
| 1639 | MIa.hasOrderedMemoryRef() || MIb.hasOrderedMemoryRef()) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1640 | return false; |
| 1641 | |
| 1642 | // Instructions that are pure loads, not loads and stores like memops are not |
| 1643 | // dependent. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1644 | if (MIa.mayLoad() && !isMemOp(&MIa) && MIb.mayLoad() && !isMemOp(&MIb)) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1645 | return true; |
| 1646 | |
| 1647 | // Get base, offset, and access size in MIa. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1648 | unsigned BaseRegA = getBaseAndOffset(&MIa, OffsetA, SizeA); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1649 | if (!BaseRegA || !SizeA) |
| 1650 | return false; |
| 1651 | |
| 1652 | // Get base, offset, and access size in MIb. |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 1653 | unsigned BaseRegB = getBaseAndOffset(&MIb, OffsetB, SizeB); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1654 | if (!BaseRegB || !SizeB) |
| 1655 | return false; |
| 1656 | |
| 1657 | if (BaseRegA != BaseRegB) |
| 1658 | return false; |
| 1659 | |
| 1660 | // This is a mem access with the same base register and known offsets from it. |
| 1661 | // Reason about it. |
| 1662 | if (OffsetA > OffsetB) { |
| 1663 | uint64_t offDiff = (uint64_t)((int64_t)OffsetA - (int64_t)OffsetB); |
| 1664 | return (SizeB <= offDiff); |
| 1665 | } else if (OffsetA < OffsetB) { |
| 1666 | uint64_t offDiff = (uint64_t)((int64_t)OffsetB - (int64_t)OffsetA); |
| 1667 | return (SizeA <= offDiff); |
| 1668 | } |
| 1669 | |
| 1670 | return false; |
| 1671 | } |
| 1672 | |
| 1673 | |
Brendon Cahoon | 254f889 | 2016-07-29 16:44:44 +0000 | [diff] [blame^] | 1674 | /// If the instruction is an increment of a constant value, return the amount. |
| 1675 | bool HexagonInstrInfo::getIncrementValue(const MachineInstr *MI, |
| 1676 | int &Value) const { |
| 1677 | if (isPostIncrement(MI)) { |
| 1678 | unsigned AccessSize; |
| 1679 | return getBaseAndOffset(MI, Value, AccessSize); |
| 1680 | } |
| 1681 | if (MI->getOpcode() == Hexagon::A2_addi) { |
| 1682 | Value = MI->getOperand(2).getImm(); |
| 1683 | return true; |
| 1684 | } |
| 1685 | |
| 1686 | return false; |
| 1687 | } |
| 1688 | |
| 1689 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1690 | unsigned HexagonInstrInfo::createVR(MachineFunction* MF, MVT VT) const { |
| 1691 | MachineRegisterInfo &MRI = MF->getRegInfo(); |
| 1692 | const TargetRegisterClass *TRC; |
| 1693 | if (VT == MVT::i1) { |
| 1694 | TRC = &Hexagon::PredRegsRegClass; |
| 1695 | } else if (VT == MVT::i32 || VT == MVT::f32) { |
| 1696 | TRC = &Hexagon::IntRegsRegClass; |
| 1697 | } else if (VT == MVT::i64 || VT == MVT::f64) { |
| 1698 | TRC = &Hexagon::DoubleRegsRegClass; |
| 1699 | } else { |
| 1700 | llvm_unreachable("Cannot handle this register class"); |
| 1701 | } |
| 1702 | |
| 1703 | unsigned NewReg = MRI.createVirtualRegister(TRC); |
| 1704 | return NewReg; |
| 1705 | } |
| 1706 | |
| 1707 | |
| 1708 | bool HexagonInstrInfo::isAbsoluteSet(const MachineInstr* MI) const { |
| 1709 | return (getAddrMode(MI) == HexagonII::AbsoluteSet); |
| 1710 | } |
| 1711 | |
| 1712 | |
| 1713 | bool HexagonInstrInfo::isAccumulator(const MachineInstr *MI) const { |
| 1714 | const uint64_t F = MI->getDesc().TSFlags; |
| 1715 | return((F >> HexagonII::AccumulatorPos) & HexagonII::AccumulatorMask); |
| 1716 | } |
| 1717 | |
| 1718 | |
| 1719 | bool HexagonInstrInfo::isComplex(const MachineInstr *MI) const { |
| 1720 | const MachineFunction *MF = MI->getParent()->getParent(); |
| 1721 | const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo(); |
| 1722 | const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII; |
| 1723 | |
| 1724 | if (!(isTC1(MI)) |
| 1725 | && !(QII->isTC2Early(MI)) |
| 1726 | && !(MI->getDesc().mayLoad()) |
| 1727 | && !(MI->getDesc().mayStore()) |
| 1728 | && (MI->getDesc().getOpcode() != Hexagon::S2_allocframe) |
| 1729 | && (MI->getDesc().getOpcode() != Hexagon::L2_deallocframe) |
| 1730 | && !(QII->isMemOp(MI)) |
| 1731 | && !(MI->isBranch()) |
| 1732 | && !(MI->isReturn()) |
| 1733 | && !MI->isCall()) |
| 1734 | return true; |
| 1735 | |
| 1736 | return false; |
| 1737 | } |
| 1738 | |
| 1739 | |
Sanjay Patel | e4b9f50 | 2015-12-07 19:21:39 +0000 | [diff] [blame] | 1740 | // Return true if the instruction is a compund branch instruction. |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1741 | bool HexagonInstrInfo::isCompoundBranchInstr(const MachineInstr *MI) const { |
| 1742 | return (getType(MI) == HexagonII::TypeCOMPOUND && MI->isBranch()); |
| 1743 | } |
| 1744 | |
| 1745 | |
| 1746 | bool HexagonInstrInfo::isCondInst(const MachineInstr *MI) const { |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1747 | return (MI->isBranch() && isPredicated(*MI)) || |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1748 | isConditionalTransfer(MI) || |
| 1749 | isConditionalALU32(MI) || |
| 1750 | isConditionalLoad(MI) || |
| 1751 | // Predicated stores which don't have a .new on any operands. |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1752 | (MI->mayStore() && isPredicated(*MI) && !isNewValueStore(MI) && |
| 1753 | !isPredicatedNew(*MI)); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | |
| 1757 | bool HexagonInstrInfo::isConditionalALU32(const MachineInstr* MI) const { |
| 1758 | switch (MI->getOpcode()) { |
| 1759 | case Hexagon::A2_paddf: |
| 1760 | case Hexagon::A2_paddfnew: |
| 1761 | case Hexagon::A2_paddif: |
| 1762 | case Hexagon::A2_paddifnew: |
| 1763 | case Hexagon::A2_paddit: |
| 1764 | case Hexagon::A2_padditnew: |
| 1765 | case Hexagon::A2_paddt: |
| 1766 | case Hexagon::A2_paddtnew: |
| 1767 | case Hexagon::A2_pandf: |
| 1768 | case Hexagon::A2_pandfnew: |
| 1769 | case Hexagon::A2_pandt: |
| 1770 | case Hexagon::A2_pandtnew: |
| 1771 | case Hexagon::A2_porf: |
| 1772 | case Hexagon::A2_porfnew: |
| 1773 | case Hexagon::A2_port: |
| 1774 | case Hexagon::A2_portnew: |
| 1775 | case Hexagon::A2_psubf: |
| 1776 | case Hexagon::A2_psubfnew: |
| 1777 | case Hexagon::A2_psubt: |
| 1778 | case Hexagon::A2_psubtnew: |
| 1779 | case Hexagon::A2_pxorf: |
| 1780 | case Hexagon::A2_pxorfnew: |
| 1781 | case Hexagon::A2_pxort: |
| 1782 | case Hexagon::A2_pxortnew: |
| 1783 | case Hexagon::A4_paslhf: |
| 1784 | case Hexagon::A4_paslhfnew: |
| 1785 | case Hexagon::A4_paslht: |
| 1786 | case Hexagon::A4_paslhtnew: |
| 1787 | case Hexagon::A4_pasrhf: |
| 1788 | case Hexagon::A4_pasrhfnew: |
| 1789 | case Hexagon::A4_pasrht: |
| 1790 | case Hexagon::A4_pasrhtnew: |
| 1791 | case Hexagon::A4_psxtbf: |
| 1792 | case Hexagon::A4_psxtbfnew: |
| 1793 | case Hexagon::A4_psxtbt: |
| 1794 | case Hexagon::A4_psxtbtnew: |
| 1795 | case Hexagon::A4_psxthf: |
| 1796 | case Hexagon::A4_psxthfnew: |
| 1797 | case Hexagon::A4_psxtht: |
| 1798 | case Hexagon::A4_psxthtnew: |
| 1799 | case Hexagon::A4_pzxtbf: |
| 1800 | case Hexagon::A4_pzxtbfnew: |
| 1801 | case Hexagon::A4_pzxtbt: |
| 1802 | case Hexagon::A4_pzxtbtnew: |
| 1803 | case Hexagon::A4_pzxthf: |
| 1804 | case Hexagon::A4_pzxthfnew: |
| 1805 | case Hexagon::A4_pzxtht: |
| 1806 | case Hexagon::A4_pzxthtnew: |
| 1807 | case Hexagon::C2_ccombinewf: |
| 1808 | case Hexagon::C2_ccombinewt: |
| 1809 | return true; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1810 | } |
| 1811 | return false; |
| 1812 | } |
| 1813 | |
| 1814 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1815 | // FIXME - Function name and it's functionality don't match. |
| 1816 | // It should be renamed to hasPredNewOpcode() |
| 1817 | bool HexagonInstrInfo::isConditionalLoad(const MachineInstr* MI) const { |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 1818 | if (!MI->getDesc().mayLoad() || !isPredicated(*MI)) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1819 | return false; |
| 1820 | |
| 1821 | int PNewOpcode = Hexagon::getPredNewOpcode(MI->getOpcode()); |
| 1822 | // Instruction with valid predicated-new opcode can be promoted to .new. |
| 1823 | return PNewOpcode >= 0; |
| 1824 | } |
| 1825 | |
| 1826 | |
| 1827 | // Returns true if an instruction is a conditional store. |
| 1828 | // |
| 1829 | // Note: It doesn't include conditional new-value stores as they can't be |
| 1830 | // converted to .new predicate. |
| 1831 | bool HexagonInstrInfo::isConditionalStore(const MachineInstr* MI) const { |
| 1832 | switch (MI->getOpcode()) { |
| 1833 | default: return false; |
| 1834 | case Hexagon::S4_storeirbt_io: |
| 1835 | case Hexagon::S4_storeirbf_io: |
| 1836 | case Hexagon::S4_pstorerbt_rr: |
| 1837 | case Hexagon::S4_pstorerbf_rr: |
| 1838 | case Hexagon::S2_pstorerbt_io: |
| 1839 | case Hexagon::S2_pstorerbf_io: |
| 1840 | case Hexagon::S2_pstorerbt_pi: |
| 1841 | case Hexagon::S2_pstorerbf_pi: |
| 1842 | case Hexagon::S2_pstorerdt_io: |
| 1843 | case Hexagon::S2_pstorerdf_io: |
| 1844 | case Hexagon::S4_pstorerdt_rr: |
| 1845 | case Hexagon::S4_pstorerdf_rr: |
| 1846 | case Hexagon::S2_pstorerdt_pi: |
| 1847 | case Hexagon::S2_pstorerdf_pi: |
| 1848 | case Hexagon::S2_pstorerht_io: |
| 1849 | case Hexagon::S2_pstorerhf_io: |
| 1850 | case Hexagon::S4_storeirht_io: |
| 1851 | case Hexagon::S4_storeirhf_io: |
| 1852 | case Hexagon::S4_pstorerht_rr: |
| 1853 | case Hexagon::S4_pstorerhf_rr: |
| 1854 | case Hexagon::S2_pstorerht_pi: |
| 1855 | case Hexagon::S2_pstorerhf_pi: |
| 1856 | case Hexagon::S2_pstorerit_io: |
| 1857 | case Hexagon::S2_pstorerif_io: |
| 1858 | case Hexagon::S4_storeirit_io: |
| 1859 | case Hexagon::S4_storeirif_io: |
| 1860 | case Hexagon::S4_pstorerit_rr: |
| 1861 | case Hexagon::S4_pstorerif_rr: |
| 1862 | case Hexagon::S2_pstorerit_pi: |
| 1863 | case Hexagon::S2_pstorerif_pi: |
| 1864 | |
| 1865 | // V4 global address store before promoting to dot new. |
| 1866 | case Hexagon::S4_pstorerdt_abs: |
| 1867 | case Hexagon::S4_pstorerdf_abs: |
| 1868 | case Hexagon::S4_pstorerbt_abs: |
| 1869 | case Hexagon::S4_pstorerbf_abs: |
| 1870 | case Hexagon::S4_pstorerht_abs: |
| 1871 | case Hexagon::S4_pstorerhf_abs: |
| 1872 | case Hexagon::S4_pstorerit_abs: |
| 1873 | case Hexagon::S4_pstorerif_abs: |
| 1874 | return true; |
| 1875 | |
| 1876 | // Predicated new value stores (i.e. if (p0) memw(..)=r0.new) are excluded |
| 1877 | // from the "Conditional Store" list. Because a predicated new value store |
| 1878 | // would NOT be promoted to a double dot new store. |
| 1879 | // This function returns yes for those stores that are predicated but not |
| 1880 | // yet promoted to predicate dot new instructions. |
| 1881 | } |
| 1882 | } |
| 1883 | |
| 1884 | |
| 1885 | bool HexagonInstrInfo::isConditionalTransfer(const MachineInstr *MI) const { |
| 1886 | switch (MI->getOpcode()) { |
| 1887 | case Hexagon::A2_tfrt: |
| 1888 | case Hexagon::A2_tfrf: |
| 1889 | case Hexagon::C2_cmoveit: |
| 1890 | case Hexagon::C2_cmoveif: |
| 1891 | case Hexagon::A2_tfrtnew: |
| 1892 | case Hexagon::A2_tfrfnew: |
| 1893 | case Hexagon::C2_cmovenewit: |
| 1894 | case Hexagon::C2_cmovenewif: |
| 1895 | case Hexagon::A2_tfrpt: |
| 1896 | case Hexagon::A2_tfrpf: |
| 1897 | return true; |
| 1898 | |
| 1899 | default: |
| 1900 | return false; |
| 1901 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1902 | return false; |
| 1903 | } |
| 1904 | |
| 1905 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1906 | // TODO: In order to have isExtendable for fpimm/f32Ext, we need to handle |
| 1907 | // isFPImm and later getFPImm as well. |
| 1908 | bool HexagonInstrInfo::isConstExtended(const MachineInstr *MI) const { |
| 1909 | const uint64_t F = MI->getDesc().TSFlags; |
| 1910 | unsigned isExtended = (F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask; |
| 1911 | if (isExtended) // Instruction must be extended. |
Krzysztof Parzyszek | c6f1933 | 2015-03-19 15:18:57 +0000 | [diff] [blame] | 1912 | return true; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1913 | |
| 1914 | unsigned isExtendable = |
| 1915 | (F >> HexagonII::ExtendablePos) & HexagonII::ExtendableMask; |
| 1916 | if (!isExtendable) |
| 1917 | return false; |
| 1918 | |
| 1919 | if (MI->isCall()) |
| 1920 | return false; |
| 1921 | |
| 1922 | short ExtOpNum = getCExtOpNum(MI); |
| 1923 | const MachineOperand &MO = MI->getOperand(ExtOpNum); |
| 1924 | // Use MO operand flags to determine if MO |
| 1925 | // has the HMOTF_ConstExtended flag set. |
| 1926 | if (MO.getTargetFlags() && HexagonII::HMOTF_ConstExtended) |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 1927 | return true; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1928 | // If this is a Machine BB address we are talking about, and it is |
| 1929 | // not marked as extended, say so. |
| 1930 | if (MO.isMBB()) |
| 1931 | return false; |
| 1932 | |
| 1933 | // We could be using an instruction with an extendable immediate and shoehorn |
| 1934 | // a global address into it. If it is a global address it will be constant |
| 1935 | // extended. We do this for COMBINE. |
| 1936 | // We currently only handle isGlobal() because it is the only kind of |
| 1937 | // object we are going to end up with here for now. |
| 1938 | // In the future we probably should add isSymbol(), etc. |
| 1939 | if (MO.isGlobal() || MO.isSymbol() || MO.isBlockAddress() || |
| 1940 | MO.isJTI() || MO.isCPI()) |
| 1941 | return true; |
| 1942 | |
| 1943 | // If the extendable operand is not 'Immediate' type, the instruction should |
| 1944 | // have 'isExtended' flag set. |
| 1945 | assert(MO.isImm() && "Extendable operand must be Immediate type"); |
| 1946 | |
| 1947 | int MinValue = getMinValue(MI); |
| 1948 | int MaxValue = getMaxValue(MI); |
| 1949 | int ImmValue = MO.getImm(); |
| 1950 | |
| 1951 | return (ImmValue < MinValue || ImmValue > MaxValue); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1955 | bool HexagonInstrInfo::isDeallocRet(const MachineInstr *MI) const { |
| 1956 | switch (MI->getOpcode()) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1957 | case Hexagon::L4_return : |
| 1958 | case Hexagon::L4_return_t : |
| 1959 | case Hexagon::L4_return_f : |
| 1960 | case Hexagon::L4_return_tnew_pnt : |
| 1961 | case Hexagon::L4_return_fnew_pnt : |
| 1962 | case Hexagon::L4_return_tnew_pt : |
| 1963 | case Hexagon::L4_return_fnew_pt : |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1964 | return true; |
| 1965 | } |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 1966 | return false; |
| 1967 | } |
| 1968 | |
| 1969 | |
| 1970 | // Return true when ConsMI uses a register defined by ProdMI. |
| 1971 | bool HexagonInstrInfo::isDependent(const MachineInstr *ProdMI, |
| 1972 | const MachineInstr *ConsMI) const { |
| 1973 | const MCInstrDesc &ProdMCID = ProdMI->getDesc(); |
| 1974 | if (!ProdMCID.getNumDefs()) |
| 1975 | return false; |
| 1976 | |
| 1977 | auto &HRI = getRegisterInfo(); |
| 1978 | |
| 1979 | SmallVector<unsigned, 4> DefsA; |
| 1980 | SmallVector<unsigned, 4> DefsB; |
| 1981 | SmallVector<unsigned, 8> UsesA; |
| 1982 | SmallVector<unsigned, 8> UsesB; |
| 1983 | |
| 1984 | parseOperands(ProdMI, DefsA, UsesA); |
| 1985 | parseOperands(ConsMI, DefsB, UsesB); |
| 1986 | |
| 1987 | for (auto &RegA : DefsA) |
| 1988 | for (auto &RegB : UsesB) { |
| 1989 | // True data dependency. |
| 1990 | if (RegA == RegB) |
| 1991 | return true; |
| 1992 | |
| 1993 | if (Hexagon::DoubleRegsRegClass.contains(RegA)) |
| 1994 | for (MCSubRegIterator SubRegs(RegA, &HRI); SubRegs.isValid(); ++SubRegs) |
| 1995 | if (RegB == *SubRegs) |
| 1996 | return true; |
| 1997 | |
| 1998 | if (Hexagon::DoubleRegsRegClass.contains(RegB)) |
| 1999 | for (MCSubRegIterator SubRegs(RegB, &HRI); SubRegs.isValid(); ++SubRegs) |
| 2000 | if (RegA == *SubRegs) |
| 2001 | return true; |
| 2002 | } |
| 2003 | |
| 2004 | return false; |
| 2005 | } |
| 2006 | |
| 2007 | |
| 2008 | // Returns true if the instruction is alread a .cur. |
| 2009 | bool HexagonInstrInfo::isDotCurInst(const MachineInstr* MI) const { |
| 2010 | switch (MI->getOpcode()) { |
| 2011 | case Hexagon::V6_vL32b_cur_pi: |
| 2012 | case Hexagon::V6_vL32b_cur_ai: |
| 2013 | case Hexagon::V6_vL32b_cur_pi_128B: |
| 2014 | case Hexagon::V6_vL32b_cur_ai_128B: |
| 2015 | return true; |
| 2016 | } |
| 2017 | return false; |
| 2018 | } |
| 2019 | |
| 2020 | |
| 2021 | // Returns true, if any one of the operands is a dot new |
| 2022 | // insn, whether it is predicated dot new or register dot new. |
| 2023 | bool HexagonInstrInfo::isDotNewInst(const MachineInstr* MI) const { |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 2024 | if (isNewValueInst(MI) || (isPredicated(*MI) && isPredicatedNew(*MI))) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2025 | return true; |
| 2026 | |
| 2027 | return false; |
| 2028 | } |
| 2029 | |
| 2030 | |
| 2031 | /// Symmetrical. See if these two instructions are fit for duplex pair. |
| 2032 | bool HexagonInstrInfo::isDuplexPair(const MachineInstr *MIa, |
| 2033 | const MachineInstr *MIb) const { |
| 2034 | HexagonII::SubInstructionGroup MIaG = getDuplexCandidateGroup(MIa); |
| 2035 | HexagonII::SubInstructionGroup MIbG = getDuplexCandidateGroup(MIb); |
| 2036 | return (isDuplexPairMatch(MIaG, MIbG) || isDuplexPairMatch(MIbG, MIaG)); |
| 2037 | } |
| 2038 | |
| 2039 | |
Krzysztof Parzyszek | 5e6f2bd | 2015-12-14 21:32:25 +0000 | [diff] [blame] | 2040 | bool HexagonInstrInfo::isEarlySourceInstr(const MachineInstr *MI) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2041 | if (!MI) |
| 2042 | return false; |
| 2043 | |
| 2044 | if (MI->mayLoad() || MI->mayStore() || MI->isCompare()) |
| 2045 | return true; |
| 2046 | |
| 2047 | // Multiply |
| 2048 | unsigned SchedClass = MI->getDesc().getSchedClass(); |
| 2049 | if (SchedClass == Hexagon::Sched::M_tc_3or4x_SLOT23) |
| 2050 | return true; |
| 2051 | return false; |
| 2052 | } |
| 2053 | |
| 2054 | |
| 2055 | bool HexagonInstrInfo::isEndLoopN(unsigned Opcode) const { |
| 2056 | return (Opcode == Hexagon::ENDLOOP0 || |
| 2057 | Opcode == Hexagon::ENDLOOP1); |
| 2058 | } |
| 2059 | |
| 2060 | |
| 2061 | bool HexagonInstrInfo::isExpr(unsigned OpType) const { |
| 2062 | switch(OpType) { |
| 2063 | case MachineOperand::MO_MachineBasicBlock: |
| 2064 | case MachineOperand::MO_GlobalAddress: |
| 2065 | case MachineOperand::MO_ExternalSymbol: |
| 2066 | case MachineOperand::MO_JumpTableIndex: |
| 2067 | case MachineOperand::MO_ConstantPoolIndex: |
| 2068 | case MachineOperand::MO_BlockAddress: |
| 2069 | return true; |
| 2070 | default: |
| 2071 | return false; |
| 2072 | } |
| 2073 | } |
| 2074 | |
| 2075 | |
| 2076 | bool HexagonInstrInfo::isExtendable(const MachineInstr *MI) const { |
| 2077 | const MCInstrDesc &MID = MI->getDesc(); |
| 2078 | const uint64_t F = MID.TSFlags; |
| 2079 | if ((F >> HexagonII::ExtendablePos) & HexagonII::ExtendableMask) |
| 2080 | return true; |
| 2081 | |
| 2082 | // TODO: This is largely obsolete now. Will need to be removed |
| 2083 | // in consecutive patches. |
| 2084 | switch(MI->getOpcode()) { |
| 2085 | // TFR_FI Remains a special case. |
| 2086 | case Hexagon::TFR_FI: |
| 2087 | return true; |
| 2088 | default: |
| 2089 | return false; |
| 2090 | } |
| 2091 | return false; |
| 2092 | } |
| 2093 | |
| 2094 | |
| 2095 | // This returns true in two cases: |
| 2096 | // - The OP code itself indicates that this is an extended instruction. |
| 2097 | // - One of MOs has been marked with HMOTF_ConstExtended flag. |
| 2098 | bool HexagonInstrInfo::isExtended(const MachineInstr *MI) const { |
| 2099 | // First check if this is permanently extended op code. |
| 2100 | const uint64_t F = MI->getDesc().TSFlags; |
| 2101 | if ((F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask) |
| 2102 | return true; |
| 2103 | // Use MO operand flags to determine if one of MI's operands |
| 2104 | // has HMOTF_ConstExtended flag set. |
| 2105 | for (MachineInstr::const_mop_iterator I = MI->operands_begin(), |
| 2106 | E = MI->operands_end(); I != E; ++I) { |
| 2107 | if (I->getTargetFlags() && HexagonII::HMOTF_ConstExtended) |
| 2108 | return true; |
| 2109 | } |
| 2110 | return false; |
| 2111 | } |
| 2112 | |
| 2113 | |
Krzysztof Parzyszek | 5e6f2bd | 2015-12-14 21:32:25 +0000 | [diff] [blame] | 2114 | bool HexagonInstrInfo::isFloat(const MachineInstr *MI) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2115 | unsigned Opcode = MI->getOpcode(); |
| 2116 | const uint64_t F = get(Opcode).TSFlags; |
| 2117 | return (F >> HexagonII::FPPos) & HexagonII::FPMask; |
| 2118 | } |
| 2119 | |
| 2120 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 2121 | // No V60 HVX VMEM with A_INDIRECT. |
| 2122 | bool HexagonInstrInfo::isHVXMemWithAIndirect(const MachineInstr *I, |
| 2123 | const MachineInstr *J) const { |
| 2124 | if (!isV60VectorInstruction(I)) |
| 2125 | return false; |
| 2126 | if (!I->mayLoad() && !I->mayStore()) |
| 2127 | return false; |
| 2128 | return J->isIndirectBranch() || isIndirectCall(J) || isIndirectL4Return(J); |
| 2129 | } |
| 2130 | |
| 2131 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2132 | bool HexagonInstrInfo::isIndirectCall(const MachineInstr *MI) const { |
| 2133 | switch (MI->getOpcode()) { |
| 2134 | case Hexagon::J2_callr : |
| 2135 | case Hexagon::J2_callrf : |
| 2136 | case Hexagon::J2_callrt : |
| 2137 | return true; |
| 2138 | } |
| 2139 | return false; |
| 2140 | } |
| 2141 | |
| 2142 | |
| 2143 | bool HexagonInstrInfo::isIndirectL4Return(const MachineInstr *MI) const { |
| 2144 | switch (MI->getOpcode()) { |
| 2145 | case Hexagon::L4_return : |
| 2146 | case Hexagon::L4_return_t : |
| 2147 | case Hexagon::L4_return_f : |
| 2148 | case Hexagon::L4_return_fnew_pnt : |
| 2149 | case Hexagon::L4_return_fnew_pt : |
| 2150 | case Hexagon::L4_return_tnew_pnt : |
| 2151 | case Hexagon::L4_return_tnew_pt : |
| 2152 | return true; |
| 2153 | } |
| 2154 | return false; |
| 2155 | } |
| 2156 | |
| 2157 | |
| 2158 | bool HexagonInstrInfo::isJumpR(const MachineInstr *MI) const { |
| 2159 | switch (MI->getOpcode()) { |
| 2160 | case Hexagon::J2_jumpr : |
| 2161 | case Hexagon::J2_jumprt : |
| 2162 | case Hexagon::J2_jumprf : |
| 2163 | case Hexagon::J2_jumprtnewpt : |
| 2164 | case Hexagon::J2_jumprfnewpt : |
| 2165 | case Hexagon::J2_jumprtnew : |
| 2166 | case Hexagon::J2_jumprfnew : |
| 2167 | return true; |
| 2168 | } |
| 2169 | return false; |
| 2170 | } |
| 2171 | |
| 2172 | |
| 2173 | // Return true if a given MI can accomodate given offset. |
| 2174 | // Use abs estimate as oppose to the exact number. |
| 2175 | // TODO: This will need to be changed to use MC level |
| 2176 | // definition of instruction extendable field size. |
| 2177 | bool HexagonInstrInfo::isJumpWithinBranchRange(const MachineInstr *MI, |
| 2178 | unsigned offset) const { |
| 2179 | // This selection of jump instructions matches to that what |
| 2180 | // AnalyzeBranch can parse, plus NVJ. |
| 2181 | if (isNewValueJump(MI)) // r9:2 |
| 2182 | return isInt<11>(offset); |
| 2183 | |
| 2184 | switch (MI->getOpcode()) { |
| 2185 | // Still missing Jump to address condition on register value. |
| 2186 | default: |
| 2187 | return false; |
| 2188 | case Hexagon::J2_jump: // bits<24> dst; // r22:2 |
| 2189 | case Hexagon::J2_call: |
| 2190 | case Hexagon::CALLv3nr: |
| 2191 | return isInt<24>(offset); |
| 2192 | case Hexagon::J2_jumpt: //bits<17> dst; // r15:2 |
| 2193 | case Hexagon::J2_jumpf: |
| 2194 | case Hexagon::J2_jumptnew: |
| 2195 | case Hexagon::J2_jumptnewpt: |
| 2196 | case Hexagon::J2_jumpfnew: |
| 2197 | case Hexagon::J2_jumpfnewpt: |
| 2198 | case Hexagon::J2_callt: |
| 2199 | case Hexagon::J2_callf: |
| 2200 | return isInt<17>(offset); |
| 2201 | case Hexagon::J2_loop0i: |
| 2202 | case Hexagon::J2_loop0iext: |
| 2203 | case Hexagon::J2_loop0r: |
| 2204 | case Hexagon::J2_loop0rext: |
| 2205 | case Hexagon::J2_loop1i: |
| 2206 | case Hexagon::J2_loop1iext: |
| 2207 | case Hexagon::J2_loop1r: |
| 2208 | case Hexagon::J2_loop1rext: |
| 2209 | return isInt<9>(offset); |
| 2210 | // TODO: Add all the compound branches here. Can we do this in Relation model? |
| 2211 | case Hexagon::J4_cmpeqi_tp0_jump_nt: |
| 2212 | case Hexagon::J4_cmpeqi_tp1_jump_nt: |
| 2213 | return isInt<11>(offset); |
| 2214 | } |
| 2215 | } |
| 2216 | |
| 2217 | |
Krzysztof Parzyszek | 5e6f2bd | 2015-12-14 21:32:25 +0000 | [diff] [blame] | 2218 | bool HexagonInstrInfo::isLateInstrFeedsEarlyInstr(const MachineInstr *LRMI, |
| 2219 | const MachineInstr *ESMI) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2220 | if (!LRMI || !ESMI) |
| 2221 | return false; |
| 2222 | |
| 2223 | bool isLate = isLateResultInstr(LRMI); |
| 2224 | bool isEarly = isEarlySourceInstr(ESMI); |
| 2225 | |
| 2226 | DEBUG(dbgs() << "V60" << (isLate ? "-LR " : " -- ")); |
| 2227 | DEBUG(LRMI->dump()); |
| 2228 | DEBUG(dbgs() << "V60" << (isEarly ? "-ES " : " -- ")); |
| 2229 | DEBUG(ESMI->dump()); |
| 2230 | |
| 2231 | if (isLate && isEarly) { |
| 2232 | DEBUG(dbgs() << "++Is Late Result feeding Early Source\n"); |
| 2233 | return true; |
| 2234 | } |
| 2235 | |
| 2236 | return false; |
| 2237 | } |
| 2238 | |
| 2239 | |
Krzysztof Parzyszek | 5e6f2bd | 2015-12-14 21:32:25 +0000 | [diff] [blame] | 2240 | bool HexagonInstrInfo::isLateResultInstr(const MachineInstr *MI) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2241 | if (!MI) |
| 2242 | return false; |
| 2243 | |
| 2244 | switch (MI->getOpcode()) { |
| 2245 | case TargetOpcode::EXTRACT_SUBREG: |
| 2246 | case TargetOpcode::INSERT_SUBREG: |
| 2247 | case TargetOpcode::SUBREG_TO_REG: |
| 2248 | case TargetOpcode::REG_SEQUENCE: |
| 2249 | case TargetOpcode::IMPLICIT_DEF: |
| 2250 | case TargetOpcode::COPY: |
| 2251 | case TargetOpcode::INLINEASM: |
| 2252 | case TargetOpcode::PHI: |
| 2253 | return false; |
| 2254 | default: |
| 2255 | break; |
| 2256 | } |
| 2257 | |
| 2258 | unsigned SchedClass = MI->getDesc().getSchedClass(); |
| 2259 | |
| 2260 | switch (SchedClass) { |
| 2261 | case Hexagon::Sched::ALU32_2op_tc_1_SLOT0123: |
| 2262 | case Hexagon::Sched::ALU32_3op_tc_1_SLOT0123: |
| 2263 | case Hexagon::Sched::ALU32_ADDI_tc_1_SLOT0123: |
| 2264 | case Hexagon::Sched::ALU64_tc_1_SLOT23: |
| 2265 | case Hexagon::Sched::EXTENDER_tc_1_SLOT0123: |
| 2266 | case Hexagon::Sched::S_2op_tc_1_SLOT23: |
| 2267 | case Hexagon::Sched::S_3op_tc_1_SLOT23: |
| 2268 | case Hexagon::Sched::V2LDST_tc_ld_SLOT01: |
| 2269 | case Hexagon::Sched::V2LDST_tc_st_SLOT0: |
| 2270 | case Hexagon::Sched::V2LDST_tc_st_SLOT01: |
| 2271 | case Hexagon::Sched::V4LDST_tc_ld_SLOT01: |
| 2272 | case Hexagon::Sched::V4LDST_tc_st_SLOT0: |
| 2273 | case Hexagon::Sched::V4LDST_tc_st_SLOT01: |
| 2274 | return false; |
| 2275 | } |
| 2276 | return true; |
| 2277 | } |
| 2278 | |
| 2279 | |
| 2280 | bool HexagonInstrInfo::isLateSourceInstr(const MachineInstr *MI) const { |
| 2281 | if (!MI) |
| 2282 | return false; |
| 2283 | |
| 2284 | // Instructions with iclass A_CVI_VX and attribute A_CVI_LATE uses a multiply |
| 2285 | // resource, but all operands can be received late like an ALU instruction. |
| 2286 | return MI->getDesc().getSchedClass() == Hexagon::Sched::CVI_VX_LATE; |
| 2287 | } |
| 2288 | |
| 2289 | |
Krzysztof Parzyszek | 5e6f2bd | 2015-12-14 21:32:25 +0000 | [diff] [blame] | 2290 | bool HexagonInstrInfo::isLoopN(const MachineInstr *MI) const { |
| 2291 | unsigned Opcode = MI->getOpcode(); |
| 2292 | return Opcode == Hexagon::J2_loop0i || |
| 2293 | Opcode == Hexagon::J2_loop0r || |
| 2294 | Opcode == Hexagon::J2_loop0iext || |
| 2295 | Opcode == Hexagon::J2_loop0rext || |
| 2296 | Opcode == Hexagon::J2_loop1i || |
| 2297 | Opcode == Hexagon::J2_loop1r || |
| 2298 | Opcode == Hexagon::J2_loop1iext || |
| 2299 | Opcode == Hexagon::J2_loop1rext; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | |
| 2303 | bool HexagonInstrInfo::isMemOp(const MachineInstr *MI) const { |
| 2304 | switch (MI->getOpcode()) { |
| 2305 | default: return false; |
| 2306 | case Hexagon::L4_iadd_memopw_io : |
| 2307 | case Hexagon::L4_isub_memopw_io : |
| 2308 | case Hexagon::L4_add_memopw_io : |
| 2309 | case Hexagon::L4_sub_memopw_io : |
| 2310 | case Hexagon::L4_and_memopw_io : |
| 2311 | case Hexagon::L4_or_memopw_io : |
| 2312 | case Hexagon::L4_iadd_memoph_io : |
| 2313 | case Hexagon::L4_isub_memoph_io : |
| 2314 | case Hexagon::L4_add_memoph_io : |
| 2315 | case Hexagon::L4_sub_memoph_io : |
| 2316 | case Hexagon::L4_and_memoph_io : |
| 2317 | case Hexagon::L4_or_memoph_io : |
| 2318 | case Hexagon::L4_iadd_memopb_io : |
| 2319 | case Hexagon::L4_isub_memopb_io : |
| 2320 | case Hexagon::L4_add_memopb_io : |
| 2321 | case Hexagon::L4_sub_memopb_io : |
| 2322 | case Hexagon::L4_and_memopb_io : |
| 2323 | case Hexagon::L4_or_memopb_io : |
| 2324 | case Hexagon::L4_ior_memopb_io: |
| 2325 | case Hexagon::L4_ior_memoph_io: |
| 2326 | case Hexagon::L4_ior_memopw_io: |
| 2327 | case Hexagon::L4_iand_memopb_io: |
| 2328 | case Hexagon::L4_iand_memoph_io: |
| 2329 | case Hexagon::L4_iand_memopw_io: |
| 2330 | return true; |
| 2331 | } |
| 2332 | return false; |
| 2333 | } |
| 2334 | |
| 2335 | |
| 2336 | bool HexagonInstrInfo::isNewValue(const MachineInstr* MI) const { |
| 2337 | const uint64_t F = MI->getDesc().TSFlags; |
| 2338 | return (F >> HexagonII::NewValuePos) & HexagonII::NewValueMask; |
| 2339 | } |
| 2340 | |
| 2341 | |
| 2342 | bool HexagonInstrInfo::isNewValue(unsigned Opcode) const { |
| 2343 | const uint64_t F = get(Opcode).TSFlags; |
| 2344 | return (F >> HexagonII::NewValuePos) & HexagonII::NewValueMask; |
| 2345 | } |
| 2346 | |
| 2347 | |
| 2348 | bool HexagonInstrInfo::isNewValueInst(const MachineInstr *MI) const { |
| 2349 | return isNewValueJump(MI) || isNewValueStore(MI); |
| 2350 | } |
| 2351 | |
| 2352 | |
| 2353 | bool HexagonInstrInfo::isNewValueJump(const MachineInstr *MI) const { |
| 2354 | return isNewValue(MI) && MI->isBranch(); |
| 2355 | } |
| 2356 | |
| 2357 | |
| 2358 | bool HexagonInstrInfo::isNewValueJump(unsigned Opcode) const { |
| 2359 | return isNewValue(Opcode) && get(Opcode).isBranch() && isPredicated(Opcode); |
| 2360 | } |
| 2361 | |
| 2362 | |
| 2363 | bool HexagonInstrInfo::isNewValueStore(const MachineInstr *MI) const { |
| 2364 | const uint64_t F = MI->getDesc().TSFlags; |
| 2365 | return (F >> HexagonII::NVStorePos) & HexagonII::NVStoreMask; |
| 2366 | } |
| 2367 | |
| 2368 | |
| 2369 | bool HexagonInstrInfo::isNewValueStore(unsigned Opcode) const { |
| 2370 | const uint64_t F = get(Opcode).TSFlags; |
| 2371 | return (F >> HexagonII::NVStorePos) & HexagonII::NVStoreMask; |
| 2372 | } |
| 2373 | |
| 2374 | |
| 2375 | // Returns true if a particular operand is extendable for an instruction. |
| 2376 | bool HexagonInstrInfo::isOperandExtended(const MachineInstr *MI, |
| 2377 | unsigned OperandNum) const { |
| 2378 | const uint64_t F = MI->getDesc().TSFlags; |
| 2379 | return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask) |
| 2380 | == OperandNum; |
| 2381 | } |
| 2382 | |
| 2383 | |
| 2384 | bool HexagonInstrInfo::isPostIncrement(const MachineInstr* MI) const { |
| 2385 | return getAddrMode(MI) == HexagonII::PostInc; |
| 2386 | } |
| 2387 | |
| 2388 | |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 2389 | bool HexagonInstrInfo::isPredicatedNew(const MachineInstr &MI) const { |
| 2390 | const uint64_t F = MI.getDesc().TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2391 | assert(isPredicated(MI)); |
| 2392 | return (F >> HexagonII::PredicatedNewPos) & HexagonII::PredicatedNewMask; |
| 2393 | } |
| 2394 | |
| 2395 | |
| 2396 | bool HexagonInstrInfo::isPredicatedNew(unsigned Opcode) const { |
| 2397 | const uint64_t F = get(Opcode).TSFlags; |
| 2398 | assert(isPredicated(Opcode)); |
| 2399 | return (F >> HexagonII::PredicatedNewPos) & HexagonII::PredicatedNewMask; |
| 2400 | } |
| 2401 | |
| 2402 | |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 2403 | bool HexagonInstrInfo::isPredicatedTrue(const MachineInstr &MI) const { |
| 2404 | const uint64_t F = MI.getDesc().TSFlags; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2405 | return !((F >> HexagonII::PredicatedFalsePos) & |
| 2406 | HexagonII::PredicatedFalseMask); |
| 2407 | } |
| 2408 | |
| 2409 | |
| 2410 | bool HexagonInstrInfo::isPredicatedTrue(unsigned Opcode) const { |
| 2411 | const uint64_t F = get(Opcode).TSFlags; |
| 2412 | // Make sure that the instruction is predicated. |
| 2413 | assert((F>> HexagonII::PredicatedPos) & HexagonII::PredicatedMask); |
| 2414 | return !((F >> HexagonII::PredicatedFalsePos) & |
| 2415 | HexagonII::PredicatedFalseMask); |
| 2416 | } |
| 2417 | |
| 2418 | |
| 2419 | bool HexagonInstrInfo::isPredicated(unsigned Opcode) const { |
| 2420 | const uint64_t F = get(Opcode).TSFlags; |
| 2421 | return (F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask; |
| 2422 | } |
| 2423 | |
| 2424 | |
| 2425 | bool HexagonInstrInfo::isPredicateLate(unsigned Opcode) const { |
| 2426 | const uint64_t F = get(Opcode).TSFlags; |
| 2427 | return ~(F >> HexagonII::PredicateLatePos) & HexagonII::PredicateLateMask; |
| 2428 | } |
| 2429 | |
| 2430 | |
| 2431 | bool HexagonInstrInfo::isPredictedTaken(unsigned Opcode) const { |
| 2432 | const uint64_t F = get(Opcode).TSFlags; |
| 2433 | assert(get(Opcode).isBranch() && |
| 2434 | (isPredicatedNew(Opcode) || isNewValue(Opcode))); |
| 2435 | return (F >> HexagonII::TakenPos) & HexagonII::TakenMask; |
| 2436 | } |
| 2437 | |
| 2438 | |
| 2439 | bool HexagonInstrInfo::isSaveCalleeSavedRegsCall(const MachineInstr *MI) const { |
| 2440 | return MI->getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4 || |
Krzysztof Parzyszek | 181fdbd | 2016-03-24 19:18:48 +0000 | [diff] [blame] | 2441 | MI->getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4_EXT || |
| 2442 | MI->getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4_PIC || |
| 2443 | MI->getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4_EXT_PIC; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2444 | } |
| 2445 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 2446 | bool HexagonInstrInfo::isSignExtendingLoad(const MachineInstr &MI) const { |
| 2447 | switch (MI.getOpcode()) { |
| 2448 | // Byte |
| 2449 | case Hexagon::L2_loadrb_io: |
| 2450 | case Hexagon::L4_loadrb_ur: |
| 2451 | case Hexagon::L4_loadrb_ap: |
| 2452 | case Hexagon::L2_loadrb_pr: |
| 2453 | case Hexagon::L2_loadrb_pbr: |
| 2454 | case Hexagon::L2_loadrb_pi: |
| 2455 | case Hexagon::L2_loadrb_pci: |
| 2456 | case Hexagon::L2_loadrb_pcr: |
| 2457 | case Hexagon::L2_loadbsw2_io: |
| 2458 | case Hexagon::L4_loadbsw2_ur: |
| 2459 | case Hexagon::L4_loadbsw2_ap: |
| 2460 | case Hexagon::L2_loadbsw2_pr: |
| 2461 | case Hexagon::L2_loadbsw2_pbr: |
| 2462 | case Hexagon::L2_loadbsw2_pi: |
| 2463 | case Hexagon::L2_loadbsw2_pci: |
| 2464 | case Hexagon::L2_loadbsw2_pcr: |
| 2465 | case Hexagon::L2_loadbsw4_io: |
| 2466 | case Hexagon::L4_loadbsw4_ur: |
| 2467 | case Hexagon::L4_loadbsw4_ap: |
| 2468 | case Hexagon::L2_loadbsw4_pr: |
| 2469 | case Hexagon::L2_loadbsw4_pbr: |
| 2470 | case Hexagon::L2_loadbsw4_pi: |
| 2471 | case Hexagon::L2_loadbsw4_pci: |
| 2472 | case Hexagon::L2_loadbsw4_pcr: |
| 2473 | case Hexagon::L4_loadrb_rr: |
| 2474 | case Hexagon::L2_ploadrbt_io: |
| 2475 | case Hexagon::L2_ploadrbt_pi: |
| 2476 | case Hexagon::L2_ploadrbf_io: |
| 2477 | case Hexagon::L2_ploadrbf_pi: |
| 2478 | case Hexagon::L2_ploadrbtnew_io: |
| 2479 | case Hexagon::L2_ploadrbfnew_io: |
| 2480 | case Hexagon::L4_ploadrbt_rr: |
| 2481 | case Hexagon::L4_ploadrbf_rr: |
| 2482 | case Hexagon::L4_ploadrbtnew_rr: |
| 2483 | case Hexagon::L4_ploadrbfnew_rr: |
| 2484 | case Hexagon::L2_ploadrbtnew_pi: |
| 2485 | case Hexagon::L2_ploadrbfnew_pi: |
| 2486 | case Hexagon::L4_ploadrbt_abs: |
| 2487 | case Hexagon::L4_ploadrbf_abs: |
| 2488 | case Hexagon::L4_ploadrbtnew_abs: |
| 2489 | case Hexagon::L4_ploadrbfnew_abs: |
| 2490 | case Hexagon::L2_loadrbgp: |
| 2491 | // Half |
| 2492 | case Hexagon::L2_loadrh_io: |
| 2493 | case Hexagon::L4_loadrh_ur: |
| 2494 | case Hexagon::L4_loadrh_ap: |
| 2495 | case Hexagon::L2_loadrh_pr: |
| 2496 | case Hexagon::L2_loadrh_pbr: |
| 2497 | case Hexagon::L2_loadrh_pi: |
| 2498 | case Hexagon::L2_loadrh_pci: |
| 2499 | case Hexagon::L2_loadrh_pcr: |
| 2500 | case Hexagon::L4_loadrh_rr: |
| 2501 | case Hexagon::L2_ploadrht_io: |
| 2502 | case Hexagon::L2_ploadrht_pi: |
| 2503 | case Hexagon::L2_ploadrhf_io: |
| 2504 | case Hexagon::L2_ploadrhf_pi: |
| 2505 | case Hexagon::L2_ploadrhtnew_io: |
| 2506 | case Hexagon::L2_ploadrhfnew_io: |
| 2507 | case Hexagon::L4_ploadrht_rr: |
| 2508 | case Hexagon::L4_ploadrhf_rr: |
| 2509 | case Hexagon::L4_ploadrhtnew_rr: |
| 2510 | case Hexagon::L4_ploadrhfnew_rr: |
| 2511 | case Hexagon::L2_ploadrhtnew_pi: |
| 2512 | case Hexagon::L2_ploadrhfnew_pi: |
| 2513 | case Hexagon::L4_ploadrht_abs: |
| 2514 | case Hexagon::L4_ploadrhf_abs: |
| 2515 | case Hexagon::L4_ploadrhtnew_abs: |
| 2516 | case Hexagon::L4_ploadrhfnew_abs: |
| 2517 | case Hexagon::L2_loadrhgp: |
| 2518 | return true; |
| 2519 | default: |
| 2520 | return false; |
Krzysztof Parzyszek | fd02aad | 2016-02-12 18:37:23 +0000 | [diff] [blame] | 2521 | } |
| 2522 | } |
| 2523 | |
| 2524 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2525 | bool HexagonInstrInfo::isSolo(const MachineInstr* MI) const { |
| 2526 | const uint64_t F = MI->getDesc().TSFlags; |
| 2527 | return (F >> HexagonII::SoloPos) & HexagonII::SoloMask; |
| 2528 | } |
| 2529 | |
| 2530 | |
| 2531 | bool HexagonInstrInfo::isSpillPredRegOp(const MachineInstr *MI) const { |
| 2532 | switch (MI->getOpcode()) { |
| 2533 | case Hexagon::STriw_pred : |
| 2534 | case Hexagon::LDriw_pred : |
| 2535 | return true; |
| 2536 | default: |
| 2537 | return false; |
| 2538 | } |
| 2539 | } |
| 2540 | |
| 2541 | |
Krzysztof Parzyszek | ecea07c | 2016-07-14 19:30:55 +0000 | [diff] [blame] | 2542 | bool HexagonInstrInfo::isTailCall(const MachineInstr *MI) const { |
| 2543 | if (!MI->isBranch()) |
| 2544 | return false; |
| 2545 | |
| 2546 | for (auto &Op : MI->operands()) |
| 2547 | if (Op.isGlobal() || Op.isSymbol()) |
| 2548 | return true; |
| 2549 | return false; |
| 2550 | } |
| 2551 | |
| 2552 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2553 | // Returns true when SU has a timing class TC1. |
| 2554 | bool HexagonInstrInfo::isTC1(const MachineInstr *MI) const { |
| 2555 | unsigned SchedClass = MI->getDesc().getSchedClass(); |
| 2556 | switch (SchedClass) { |
| 2557 | case Hexagon::Sched::ALU32_2op_tc_1_SLOT0123: |
| 2558 | case Hexagon::Sched::ALU32_3op_tc_1_SLOT0123: |
| 2559 | case Hexagon::Sched::ALU32_ADDI_tc_1_SLOT0123: |
| 2560 | case Hexagon::Sched::ALU64_tc_1_SLOT23: |
| 2561 | case Hexagon::Sched::EXTENDER_tc_1_SLOT0123: |
| 2562 | //case Hexagon::Sched::M_tc_1_SLOT23: |
| 2563 | case Hexagon::Sched::S_2op_tc_1_SLOT23: |
| 2564 | case Hexagon::Sched::S_3op_tc_1_SLOT23: |
| 2565 | return true; |
| 2566 | |
| 2567 | default: |
| 2568 | return false; |
| 2569 | } |
| 2570 | } |
| 2571 | |
| 2572 | |
| 2573 | bool HexagonInstrInfo::isTC2(const MachineInstr *MI) const { |
| 2574 | unsigned SchedClass = MI->getDesc().getSchedClass(); |
| 2575 | switch (SchedClass) { |
| 2576 | case Hexagon::Sched::ALU32_3op_tc_2_SLOT0123: |
| 2577 | case Hexagon::Sched::ALU64_tc_2_SLOT23: |
| 2578 | case Hexagon::Sched::CR_tc_2_SLOT3: |
| 2579 | case Hexagon::Sched::M_tc_2_SLOT23: |
| 2580 | case Hexagon::Sched::S_2op_tc_2_SLOT23: |
| 2581 | case Hexagon::Sched::S_3op_tc_2_SLOT23: |
| 2582 | return true; |
| 2583 | |
| 2584 | default: |
| 2585 | return false; |
| 2586 | } |
| 2587 | } |
| 2588 | |
| 2589 | |
| 2590 | bool HexagonInstrInfo::isTC2Early(const MachineInstr *MI) const { |
| 2591 | unsigned SchedClass = MI->getDesc().getSchedClass(); |
| 2592 | switch (SchedClass) { |
| 2593 | case Hexagon::Sched::ALU32_2op_tc_2early_SLOT0123: |
| 2594 | case Hexagon::Sched::ALU32_3op_tc_2early_SLOT0123: |
| 2595 | case Hexagon::Sched::ALU64_tc_2early_SLOT23: |
| 2596 | case Hexagon::Sched::CR_tc_2early_SLOT23: |
| 2597 | case Hexagon::Sched::CR_tc_2early_SLOT3: |
| 2598 | case Hexagon::Sched::J_tc_2early_SLOT0123: |
| 2599 | case Hexagon::Sched::J_tc_2early_SLOT2: |
| 2600 | case Hexagon::Sched::J_tc_2early_SLOT23: |
| 2601 | case Hexagon::Sched::S_2op_tc_2early_SLOT23: |
| 2602 | case Hexagon::Sched::S_3op_tc_2early_SLOT23: |
| 2603 | return true; |
| 2604 | |
| 2605 | default: |
| 2606 | return false; |
| 2607 | } |
| 2608 | } |
| 2609 | |
| 2610 | |
| 2611 | bool HexagonInstrInfo::isTC4x(const MachineInstr *MI) const { |
| 2612 | if (!MI) |
| 2613 | return false; |
| 2614 | |
| 2615 | unsigned SchedClass = MI->getDesc().getSchedClass(); |
| 2616 | return SchedClass == Hexagon::Sched::M_tc_3or4x_SLOT23; |
| 2617 | } |
| 2618 | |
| 2619 | |
Krzysztof Parzyszek | 408e300 | 2016-07-15 21:34:02 +0000 | [diff] [blame] | 2620 | // Schedule this ASAP. |
| 2621 | bool HexagonInstrInfo::isToBeScheduledASAP(const MachineInstr *MI1, |
| 2622 | const MachineInstr *MI2) const { |
| 2623 | if (!MI1 || !MI2) |
| 2624 | return false; |
| 2625 | if (mayBeCurLoad(MI1)) { |
| 2626 | // if (result of SU is used in Next) return true; |
| 2627 | unsigned DstReg = MI1->getOperand(0).getReg(); |
| 2628 | int N = MI2->getNumOperands(); |
| 2629 | for (int I = 0; I < N; I++) |
| 2630 | if (MI2->getOperand(I).isReg() && DstReg == MI2->getOperand(I).getReg()) |
| 2631 | return true; |
| 2632 | } |
| 2633 | if (mayBeNewStore(MI2)) |
| 2634 | if (MI2->getOpcode() == Hexagon::V6_vS32b_pi) |
| 2635 | if (MI1->getOperand(0).isReg() && MI2->getOperand(3).isReg() && |
| 2636 | MI1->getOperand(0).getReg() == MI2->getOperand(3).getReg()) |
| 2637 | return true; |
| 2638 | return false; |
| 2639 | } |
| 2640 | |
| 2641 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2642 | bool HexagonInstrInfo::isV60VectorInstruction(const MachineInstr *MI) const { |
| 2643 | if (!MI) |
| 2644 | return false; |
| 2645 | |
| 2646 | const uint64_t V = getType(MI); |
| 2647 | return HexagonII::TypeCVI_FIRST <= V && V <= HexagonII::TypeCVI_LAST; |
| 2648 | } |
| 2649 | |
| 2650 | |
| 2651 | // Check if the Offset is a valid auto-inc imm by Load/Store Type. |
| 2652 | // |
| 2653 | bool HexagonInstrInfo::isValidAutoIncImm(const EVT VT, const int Offset) const { |
| 2654 | if (VT == MVT::v16i32 || VT == MVT::v8i64 || |
| 2655 | VT == MVT::v32i16 || VT == MVT::v64i8) { |
| 2656 | return (Offset >= Hexagon_MEMV_AUTOINC_MIN && |
| 2657 | Offset <= Hexagon_MEMV_AUTOINC_MAX && |
| 2658 | (Offset & 0x3f) == 0); |
| 2659 | } |
| 2660 | // 128B |
| 2661 | if (VT == MVT::v32i32 || VT == MVT::v16i64 || |
| 2662 | VT == MVT::v64i16 || VT == MVT::v128i8) { |
| 2663 | return (Offset >= Hexagon_MEMV_AUTOINC_MIN_128B && |
| 2664 | Offset <= Hexagon_MEMV_AUTOINC_MAX_128B && |
| 2665 | (Offset & 0x7f) == 0); |
| 2666 | } |
| 2667 | if (VT == MVT::i64) { |
| 2668 | return (Offset >= Hexagon_MEMD_AUTOINC_MIN && |
| 2669 | Offset <= Hexagon_MEMD_AUTOINC_MAX && |
| 2670 | (Offset & 0x7) == 0); |
| 2671 | } |
| 2672 | if (VT == MVT::i32) { |
| 2673 | return (Offset >= Hexagon_MEMW_AUTOINC_MIN && |
| 2674 | Offset <= Hexagon_MEMW_AUTOINC_MAX && |
| 2675 | (Offset & 0x3) == 0); |
| 2676 | } |
| 2677 | if (VT == MVT::i16) { |
| 2678 | return (Offset >= Hexagon_MEMH_AUTOINC_MIN && |
| 2679 | Offset <= Hexagon_MEMH_AUTOINC_MAX && |
| 2680 | (Offset & 0x1) == 0); |
| 2681 | } |
| 2682 | if (VT == MVT::i8) { |
| 2683 | return (Offset >= Hexagon_MEMB_AUTOINC_MIN && |
| 2684 | Offset <= Hexagon_MEMB_AUTOINC_MAX); |
| 2685 | } |
| 2686 | llvm_unreachable("Not an auto-inc opc!"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2687 | } |
| 2688 | |
| 2689 | |
Krzysztof Parzyszek | 0590216 | 2015-04-22 17:51:26 +0000 | [diff] [blame] | 2690 | bool HexagonInstrInfo::isValidOffset(unsigned Opcode, int Offset, |
| 2691 | bool Extend) const { |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2692 | // 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] | 2693 | // 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] | 2694 | // inserted to calculate the final address. Due to this reason, the function |
| 2695 | // assumes that the "Offset" has correct alignment. |
Jyotsna Verma | ec61366 | 2013-03-14 19:08:03 +0000 | [diff] [blame] | 2696 | // We used to assert if the offset was not properly aligned, however, |
| 2697 | // there are cases where a misaligned pointer recast can cause this |
| 2698 | // problem, and we need to allow for it. The front end warns of such |
| 2699 | // misaligns with respect to load size. |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2700 | |
Krzysztof Parzyszek | 0590216 | 2015-04-22 17:51:26 +0000 | [diff] [blame] | 2701 | switch (Opcode) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2702 | case Hexagon::STriq_pred_V6: |
| 2703 | case Hexagon::STriq_pred_vec_V6: |
| 2704 | case Hexagon::STriv_pseudo_V6: |
| 2705 | case Hexagon::STrivv_pseudo_V6: |
| 2706 | case Hexagon::LDriq_pred_V6: |
| 2707 | case Hexagon::LDriq_pred_vec_V6: |
| 2708 | case Hexagon::LDriv_pseudo_V6: |
| 2709 | case Hexagon::LDrivv_pseudo_V6: |
| 2710 | case Hexagon::LDrivv_indexed: |
| 2711 | case Hexagon::STrivv_indexed: |
| 2712 | case Hexagon::V6_vL32b_ai: |
| 2713 | case Hexagon::V6_vS32b_ai: |
| 2714 | case Hexagon::V6_vL32Ub_ai: |
| 2715 | case Hexagon::V6_vS32Ub_ai: |
| 2716 | return (Offset >= Hexagon_MEMV_OFFSET_MIN) && |
| 2717 | (Offset <= Hexagon_MEMV_OFFSET_MAX); |
| 2718 | |
| 2719 | case Hexagon::STriq_pred_V6_128B: |
| 2720 | case Hexagon::STriq_pred_vec_V6_128B: |
| 2721 | case Hexagon::STriv_pseudo_V6_128B: |
| 2722 | case Hexagon::STrivv_pseudo_V6_128B: |
| 2723 | case Hexagon::LDriq_pred_V6_128B: |
| 2724 | case Hexagon::LDriq_pred_vec_V6_128B: |
| 2725 | case Hexagon::LDriv_pseudo_V6_128B: |
| 2726 | case Hexagon::LDrivv_pseudo_V6_128B: |
| 2727 | case Hexagon::LDrivv_indexed_128B: |
| 2728 | case Hexagon::STrivv_indexed_128B: |
| 2729 | case Hexagon::V6_vL32b_ai_128B: |
| 2730 | case Hexagon::V6_vS32b_ai_128B: |
| 2731 | case Hexagon::V6_vL32Ub_ai_128B: |
| 2732 | case Hexagon::V6_vS32Ub_ai_128B: |
| 2733 | return (Offset >= Hexagon_MEMV_OFFSET_MIN_128B) && |
| 2734 | (Offset <= Hexagon_MEMV_OFFSET_MAX_128B); |
| 2735 | |
Krzysztof Parzyszek | 0590216 | 2015-04-22 17:51:26 +0000 | [diff] [blame] | 2736 | case Hexagon::J2_loop0i: |
| 2737 | case Hexagon::J2_loop1i: |
| 2738 | return isUInt<10>(Offset); |
Krzysztof Parzyszek | bba0bf7 | 2016-07-15 15:35:52 +0000 | [diff] [blame] | 2739 | |
| 2740 | case Hexagon::S4_storeirb_io: |
| 2741 | case Hexagon::S4_storeirbt_io: |
| 2742 | case Hexagon::S4_storeirbf_io: |
| 2743 | return isUInt<6>(Offset); |
| 2744 | |
| 2745 | case Hexagon::S4_storeirh_io: |
| 2746 | case Hexagon::S4_storeirht_io: |
| 2747 | case Hexagon::S4_storeirhf_io: |
| 2748 | return isShiftedUInt<6,1>(Offset); |
| 2749 | |
| 2750 | case Hexagon::S4_storeiri_io: |
| 2751 | case Hexagon::S4_storeirit_io: |
| 2752 | case Hexagon::S4_storeirif_io: |
| 2753 | return isShiftedUInt<6,2>(Offset); |
Krzysztof Parzyszek | 0590216 | 2015-04-22 17:51:26 +0000 | [diff] [blame] | 2754 | } |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2755 | |
Krzysztof Parzyszek | 0590216 | 2015-04-22 17:51:26 +0000 | [diff] [blame] | 2756 | if (Extend) |
| 2757 | return true; |
| 2758 | |
| 2759 | switch (Opcode) { |
Colin LeMahieu | 026e88d | 2014-12-23 20:02:16 +0000 | [diff] [blame] | 2760 | case Hexagon::L2_loadri_io: |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 2761 | case Hexagon::S2_storeri_io: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2762 | return (Offset >= Hexagon_MEMW_OFFSET_MIN) && |
| 2763 | (Offset <= Hexagon_MEMW_OFFSET_MAX); |
| 2764 | |
Colin LeMahieu | 947cd70 | 2014-12-23 20:44:59 +0000 | [diff] [blame] | 2765 | case Hexagon::L2_loadrd_io: |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 2766 | case Hexagon::S2_storerd_io: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2767 | return (Offset >= Hexagon_MEMD_OFFSET_MIN) && |
| 2768 | (Offset <= Hexagon_MEMD_OFFSET_MAX); |
| 2769 | |
Colin LeMahieu | 8e39cad | 2014-12-23 17:25:57 +0000 | [diff] [blame] | 2770 | case Hexagon::L2_loadrh_io: |
Colin LeMahieu | a9386d2 | 2014-12-23 16:42:57 +0000 | [diff] [blame] | 2771 | case Hexagon::L2_loadruh_io: |
Colin LeMahieu | bda31b4 | 2014-12-29 20:44:51 +0000 | [diff] [blame] | 2772 | case Hexagon::S2_storerh_io: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2773 | return (Offset >= Hexagon_MEMH_OFFSET_MIN) && |
| 2774 | (Offset <= Hexagon_MEMH_OFFSET_MAX); |
| 2775 | |
Colin LeMahieu | 4b1eac4 | 2014-12-22 21:40:43 +0000 | [diff] [blame] | 2776 | case Hexagon::L2_loadrb_io: |
Colin LeMahieu | af1e5de | 2014-12-22 21:20:03 +0000 | [diff] [blame] | 2777 | case Hexagon::L2_loadrub_io: |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2778 | case Hexagon::S2_storerb_io: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2779 | return (Offset >= Hexagon_MEMB_OFFSET_MIN) && |
| 2780 | (Offset <= Hexagon_MEMB_OFFSET_MAX); |
| 2781 | |
Colin LeMahieu | f297dbe | 2015-02-05 17:49:13 +0000 | [diff] [blame] | 2782 | case Hexagon::A2_addi: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2783 | return (Offset >= Hexagon_ADDI_OFFSET_MIN) && |
| 2784 | (Offset <= Hexagon_ADDI_OFFSET_MAX); |
| 2785 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2786 | case Hexagon::L4_iadd_memopw_io : |
| 2787 | case Hexagon::L4_isub_memopw_io : |
| 2788 | case Hexagon::L4_add_memopw_io : |
| 2789 | case Hexagon::L4_sub_memopw_io : |
| 2790 | case Hexagon::L4_and_memopw_io : |
| 2791 | case Hexagon::L4_or_memopw_io : |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2792 | return (0 <= Offset && Offset <= 255); |
| 2793 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2794 | case Hexagon::L4_iadd_memoph_io : |
| 2795 | case Hexagon::L4_isub_memoph_io : |
| 2796 | case Hexagon::L4_add_memoph_io : |
| 2797 | case Hexagon::L4_sub_memoph_io : |
| 2798 | case Hexagon::L4_and_memoph_io : |
| 2799 | case Hexagon::L4_or_memoph_io : |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2800 | return (0 <= Offset && Offset <= 127); |
| 2801 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2802 | case Hexagon::L4_iadd_memopb_io : |
| 2803 | case Hexagon::L4_isub_memopb_io : |
| 2804 | case Hexagon::L4_add_memopb_io : |
| 2805 | case Hexagon::L4_sub_memopb_io : |
| 2806 | case Hexagon::L4_and_memopb_io : |
| 2807 | case Hexagon::L4_or_memopb_io : |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2808 | return (0 <= Offset && Offset <= 63); |
| 2809 | |
Krzysztof Parzyszek | fd02aad | 2016-02-12 18:37:23 +0000 | [diff] [blame] | 2810 | // LDriw_xxx and STriw_xxx are pseudo operations, so it has to take offset of |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2811 | // any size. Later pass knows how to handle it. |
| 2812 | case Hexagon::STriw_pred: |
| 2813 | case Hexagon::LDriw_pred: |
Krzysztof Parzyszek | 7b413c6 | 2016-01-22 19:15:58 +0000 | [diff] [blame] | 2814 | case Hexagon::STriw_mod: |
| 2815 | case Hexagon::LDriw_mod: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2816 | return true; |
| 2817 | |
Krzysztof Parzyszek | 0590216 | 2015-04-22 17:51:26 +0000 | [diff] [blame] | 2818 | case Hexagon::TFR_FI: |
| 2819 | case Hexagon::TFR_FIA: |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2820 | case Hexagon::INLINEASM: |
| 2821 | return true; |
Krzysztof Parzyszek | fb33824 | 2015-10-06 15:49:14 +0000 | [diff] [blame] | 2822 | |
| 2823 | case Hexagon::L2_ploadrbt_io: |
| 2824 | case Hexagon::L2_ploadrbf_io: |
| 2825 | case Hexagon::L2_ploadrubt_io: |
| 2826 | case Hexagon::L2_ploadrubf_io: |
| 2827 | case Hexagon::S2_pstorerbt_io: |
| 2828 | case Hexagon::S2_pstorerbf_io: |
Krzysztof Parzyszek | fb33824 | 2015-10-06 15:49:14 +0000 | [diff] [blame] | 2829 | return isUInt<6>(Offset); |
| 2830 | |
| 2831 | case Hexagon::L2_ploadrht_io: |
| 2832 | case Hexagon::L2_ploadrhf_io: |
| 2833 | case Hexagon::L2_ploadruht_io: |
| 2834 | case Hexagon::L2_ploadruhf_io: |
| 2835 | case Hexagon::S2_pstorerht_io: |
| 2836 | case Hexagon::S2_pstorerhf_io: |
Krzysztof Parzyszek | fb33824 | 2015-10-06 15:49:14 +0000 | [diff] [blame] | 2837 | return isShiftedUInt<6,1>(Offset); |
| 2838 | |
| 2839 | case Hexagon::L2_ploadrit_io: |
| 2840 | case Hexagon::L2_ploadrif_io: |
| 2841 | case Hexagon::S2_pstorerit_io: |
| 2842 | case Hexagon::S2_pstorerif_io: |
Krzysztof Parzyszek | fb33824 | 2015-10-06 15:49:14 +0000 | [diff] [blame] | 2843 | return isShiftedUInt<6,2>(Offset); |
| 2844 | |
| 2845 | case Hexagon::L2_ploadrdt_io: |
| 2846 | case Hexagon::L2_ploadrdf_io: |
| 2847 | case Hexagon::S2_pstorerdt_io: |
| 2848 | case Hexagon::S2_pstorerdf_io: |
| 2849 | return isShiftedUInt<6,3>(Offset); |
| 2850 | } // switch |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2851 | |
Benjamin Kramer | b668401 | 2011-12-27 11:41:05 +0000 | [diff] [blame] | 2852 | llvm_unreachable("No offset range is defined for this opcode. " |
| 2853 | "Please define it in the above switch statement!"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2854 | } |
| 2855 | |
| 2856 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2857 | bool HexagonInstrInfo::isVecAcc(const MachineInstr *MI) const { |
| 2858 | return MI && isV60VectorInstruction(MI) && isAccumulator(MI); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2859 | } |
| 2860 | |
| 2861 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2862 | bool HexagonInstrInfo::isVecALU(const MachineInstr *MI) const { |
| 2863 | if (!MI) |
Andrew Trick | d06df96 | 2012-02-01 22:13:57 +0000 | [diff] [blame] | 2864 | return false; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2865 | const uint64_t F = get(MI->getOpcode()).TSFlags; |
| 2866 | const uint64_t V = ((F >> HexagonII::TypePos) & HexagonII::TypeMask); |
| 2867 | return |
| 2868 | V == HexagonII::TypeCVI_VA || |
| 2869 | V == HexagonII::TypeCVI_VA_DV; |
| 2870 | } |
Andrew Trick | d06df96 | 2012-02-01 22:13:57 +0000 | [diff] [blame] | 2871 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 2872 | |
| 2873 | bool HexagonInstrInfo::isVecUsableNextPacket(const MachineInstr *ProdMI, |
| 2874 | const MachineInstr *ConsMI) const { |
| 2875 | if (EnableACCForwarding && isVecAcc(ProdMI) && isVecAcc(ConsMI)) |
| 2876 | return true; |
| 2877 | |
| 2878 | if (EnableALUForwarding && (isVecALU(ConsMI) || isLateSourceInstr(ConsMI))) |
| 2879 | return true; |
| 2880 | |
| 2881 | if (mayBeNewStore(ConsMI)) |
Andrew Trick | d06df96 | 2012-02-01 22:13:57 +0000 | [diff] [blame] | 2882 | return true; |
| 2883 | |
| 2884 | return false; |
| 2885 | } |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 2886 | |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 2887 | bool HexagonInstrInfo::isZeroExtendingLoad(const MachineInstr &MI) const { |
| 2888 | switch (MI.getOpcode()) { |
| 2889 | // Byte |
| 2890 | case Hexagon::L2_loadrub_io: |
| 2891 | case Hexagon::L4_loadrub_ur: |
| 2892 | case Hexagon::L4_loadrub_ap: |
| 2893 | case Hexagon::L2_loadrub_pr: |
| 2894 | case Hexagon::L2_loadrub_pbr: |
| 2895 | case Hexagon::L2_loadrub_pi: |
| 2896 | case Hexagon::L2_loadrub_pci: |
| 2897 | case Hexagon::L2_loadrub_pcr: |
| 2898 | case Hexagon::L2_loadbzw2_io: |
| 2899 | case Hexagon::L4_loadbzw2_ur: |
| 2900 | case Hexagon::L4_loadbzw2_ap: |
| 2901 | case Hexagon::L2_loadbzw2_pr: |
| 2902 | case Hexagon::L2_loadbzw2_pbr: |
| 2903 | case Hexagon::L2_loadbzw2_pi: |
| 2904 | case Hexagon::L2_loadbzw2_pci: |
| 2905 | case Hexagon::L2_loadbzw2_pcr: |
| 2906 | case Hexagon::L2_loadbzw4_io: |
| 2907 | case Hexagon::L4_loadbzw4_ur: |
| 2908 | case Hexagon::L4_loadbzw4_ap: |
| 2909 | case Hexagon::L2_loadbzw4_pr: |
| 2910 | case Hexagon::L2_loadbzw4_pbr: |
| 2911 | case Hexagon::L2_loadbzw4_pi: |
| 2912 | case Hexagon::L2_loadbzw4_pci: |
| 2913 | case Hexagon::L2_loadbzw4_pcr: |
| 2914 | case Hexagon::L4_loadrub_rr: |
| 2915 | case Hexagon::L2_ploadrubt_io: |
| 2916 | case Hexagon::L2_ploadrubt_pi: |
| 2917 | case Hexagon::L2_ploadrubf_io: |
| 2918 | case Hexagon::L2_ploadrubf_pi: |
| 2919 | case Hexagon::L2_ploadrubtnew_io: |
| 2920 | case Hexagon::L2_ploadrubfnew_io: |
| 2921 | case Hexagon::L4_ploadrubt_rr: |
| 2922 | case Hexagon::L4_ploadrubf_rr: |
| 2923 | case Hexagon::L4_ploadrubtnew_rr: |
| 2924 | case Hexagon::L4_ploadrubfnew_rr: |
| 2925 | case Hexagon::L2_ploadrubtnew_pi: |
| 2926 | case Hexagon::L2_ploadrubfnew_pi: |
| 2927 | case Hexagon::L4_ploadrubt_abs: |
| 2928 | case Hexagon::L4_ploadrubf_abs: |
| 2929 | case Hexagon::L4_ploadrubtnew_abs: |
| 2930 | case Hexagon::L4_ploadrubfnew_abs: |
| 2931 | case Hexagon::L2_loadrubgp: |
| 2932 | // Half |
| 2933 | case Hexagon::L2_loadruh_io: |
| 2934 | case Hexagon::L4_loadruh_ur: |
| 2935 | case Hexagon::L4_loadruh_ap: |
| 2936 | case Hexagon::L2_loadruh_pr: |
| 2937 | case Hexagon::L2_loadruh_pbr: |
| 2938 | case Hexagon::L2_loadruh_pi: |
| 2939 | case Hexagon::L2_loadruh_pci: |
| 2940 | case Hexagon::L2_loadruh_pcr: |
| 2941 | case Hexagon::L4_loadruh_rr: |
| 2942 | case Hexagon::L2_ploadruht_io: |
| 2943 | case Hexagon::L2_ploadruht_pi: |
| 2944 | case Hexagon::L2_ploadruhf_io: |
| 2945 | case Hexagon::L2_ploadruhf_pi: |
| 2946 | case Hexagon::L2_ploadruhtnew_io: |
| 2947 | case Hexagon::L2_ploadruhfnew_io: |
| 2948 | case Hexagon::L4_ploadruht_rr: |
| 2949 | case Hexagon::L4_ploadruhf_rr: |
| 2950 | case Hexagon::L4_ploadruhtnew_rr: |
| 2951 | case Hexagon::L4_ploadruhfnew_rr: |
| 2952 | case Hexagon::L2_ploadruhtnew_pi: |
| 2953 | case Hexagon::L2_ploadruhfnew_pi: |
| 2954 | case Hexagon::L4_ploadruht_abs: |
| 2955 | case Hexagon::L4_ploadruhf_abs: |
| 2956 | case Hexagon::L4_ploadruhtnew_abs: |
| 2957 | case Hexagon::L4_ploadruhfnew_abs: |
| 2958 | case Hexagon::L2_loadruhgp: |
| 2959 | return true; |
| 2960 | default: |
| 2961 | return false; |
Krzysztof Parzyszek | fd02aad | 2016-02-12 18:37:23 +0000 | [diff] [blame] | 2962 | } |
| 2963 | } |
| 2964 | |
| 2965 | |
Krzysztof Parzyszek | 408e300 | 2016-07-15 21:34:02 +0000 | [diff] [blame] | 2966 | // Add latency to instruction. |
| 2967 | bool HexagonInstrInfo::addLatencyToSchedule(const MachineInstr *MI1, |
| 2968 | const MachineInstr *MI2) const { |
| 2969 | if (isV60VectorInstruction(MI1) && isV60VectorInstruction(MI2)) |
| 2970 | if (!isVecUsableNextPacket(MI1, MI2)) |
| 2971 | return true; |
| 2972 | return false; |
| 2973 | } |
| 2974 | |
| 2975 | |
Brendon Cahoon | 254f889 | 2016-07-29 16:44:44 +0000 | [diff] [blame^] | 2976 | /// \brief Get the base register and byte offset of a load/store instr. |
| 2977 | bool HexagonInstrInfo::getMemOpBaseRegImmOfs(MachineInstr &LdSt, |
| 2978 | unsigned &BaseReg, int64_t &Offset, const TargetRegisterInfo *TRI) |
| 2979 | const { |
| 2980 | unsigned AccessSize = 0; |
| 2981 | int OffsetVal = 0; |
| 2982 | BaseReg = getBaseAndOffset(&LdSt, OffsetVal, AccessSize); |
| 2983 | Offset = OffsetVal; |
| 2984 | return BaseReg != 0; |
| 2985 | } |
| 2986 | |
| 2987 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 2988 | /// \brief Can these instructions execute at the same time in a bundle. |
| 2989 | bool HexagonInstrInfo::canExecuteInBundle(const MachineInstr *First, |
| 2990 | const MachineInstr *Second) const { |
| 2991 | if (DisableNVSchedule) |
| 2992 | return false; |
| 2993 | if (mayBeNewStore(Second)) { |
| 2994 | // Make sure the definition of the first instruction is the value being |
| 2995 | // stored. |
| 2996 | const MachineOperand &Stored = |
| 2997 | Second->getOperand(Second->getNumOperands() - 1); |
| 2998 | if (!Stored.isReg()) |
| 2999 | return false; |
| 3000 | for (unsigned i = 0, e = First->getNumOperands(); i < e; ++i) { |
| 3001 | const MachineOperand &Op = First->getOperand(i); |
| 3002 | if (Op.isReg() && Op.isDef() && Op.getReg() == Stored.getReg()) |
| 3003 | return true; |
| 3004 | } |
| 3005 | } |
| 3006 | return false; |
| 3007 | } |
| 3008 | |
| 3009 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3010 | bool HexagonInstrInfo::hasEHLabel(const MachineBasicBlock *B) const { |
| 3011 | for (auto &I : *B) |
| 3012 | if (I.isEHLabel()) |
| 3013 | return true; |
| 3014 | return false; |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 3015 | } |
| 3016 | |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 3017 | |
| 3018 | // Returns true if an instruction can be converted into a non-extended |
| 3019 | // equivalent instruction. |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3020 | bool HexagonInstrInfo::hasNonExtEquivalent(const MachineInstr *MI) const { |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 3021 | short NonExtOpcode; |
| 3022 | // Check if the instruction has a register form that uses register in place |
| 3023 | // of the extended operand, if so return that as the non-extended form. |
| 3024 | if (Hexagon::getRegForm(MI->getOpcode()) >= 0) |
| 3025 | return true; |
| 3026 | |
| 3027 | if (MI->getDesc().mayLoad() || MI->getDesc().mayStore()) { |
Alp Toker | cb40291 | 2014-01-24 17:20:08 +0000 | [diff] [blame] | 3028 | // Check addressing mode and retrieve non-ext equivalent instruction. |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 3029 | |
| 3030 | switch (getAddrMode(MI)) { |
| 3031 | case HexagonII::Absolute : |
| 3032 | // Load/store with absolute addressing mode can be converted into |
| 3033 | // base+offset mode. |
Krzysztof Parzyszek | 0257905 | 2015-10-20 19:21:05 +0000 | [diff] [blame] | 3034 | NonExtOpcode = Hexagon::getBaseWithImmOffset(MI->getOpcode()); |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 3035 | break; |
| 3036 | case HexagonII::BaseImmOffset : |
| 3037 | // Load/store with base+offset addressing mode can be converted into |
| 3038 | // base+register offset addressing mode. However left shift operand should |
| 3039 | // be set to 0. |
| 3040 | NonExtOpcode = Hexagon::getBaseWithRegOffset(MI->getOpcode()); |
| 3041 | break; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3042 | case HexagonII::BaseLongOffset: |
| 3043 | NonExtOpcode = Hexagon::getRegShlForm(MI->getOpcode()); |
| 3044 | break; |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 3045 | default: |
| 3046 | return false; |
| 3047 | } |
| 3048 | if (NonExtOpcode < 0) |
| 3049 | return false; |
| 3050 | return true; |
| 3051 | } |
| 3052 | return false; |
| 3053 | } |
| 3054 | |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 3055 | |
Krzysztof Parzyszek | 5e6f2bd | 2015-12-14 21:32:25 +0000 | [diff] [blame] | 3056 | bool HexagonInstrInfo::hasPseudoInstrPair(const MachineInstr *MI) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3057 | return Hexagon::getRealHWInstr(MI->getOpcode(), |
| 3058 | Hexagon::InstrType_Pseudo) >= 0; |
| 3059 | } |
| 3060 | |
| 3061 | |
| 3062 | bool HexagonInstrInfo::hasUncondBranch(const MachineBasicBlock *B) |
| 3063 | const { |
| 3064 | MachineBasicBlock::const_iterator I = B->getFirstTerminator(), E = B->end(); |
| 3065 | while (I != E) { |
| 3066 | if (I->isBarrier()) |
| 3067 | return true; |
| 3068 | ++I; |
| 3069 | } |
| 3070 | return false; |
| 3071 | } |
| 3072 | |
| 3073 | |
| 3074 | // Returns true, if a LD insn can be promoted to a cur load. |
| 3075 | bool HexagonInstrInfo::mayBeCurLoad(const MachineInstr *MI) const { |
| 3076 | auto &HST = MI->getParent()->getParent()->getSubtarget<HexagonSubtarget>(); |
| 3077 | const uint64_t F = MI->getDesc().TSFlags; |
| 3078 | return ((F >> HexagonII::mayCVLoadPos) & HexagonII::mayCVLoadMask) && |
| 3079 | HST.hasV60TOps(); |
| 3080 | } |
| 3081 | |
| 3082 | |
| 3083 | // Returns true, if a ST insn can be promoted to a new-value store. |
| 3084 | bool HexagonInstrInfo::mayBeNewStore(const MachineInstr *MI) const { |
| 3085 | const uint64_t F = MI->getDesc().TSFlags; |
| 3086 | return (F >> HexagonII::mayNVStorePos) & HexagonII::mayNVStoreMask; |
| 3087 | } |
| 3088 | |
| 3089 | |
| 3090 | bool HexagonInstrInfo::producesStall(const MachineInstr *ProdMI, |
| 3091 | const MachineInstr *ConsMI) const { |
| 3092 | // There is no stall when ProdMI is not a V60 vector. |
| 3093 | if (!isV60VectorInstruction(ProdMI)) |
| 3094 | return false; |
| 3095 | |
| 3096 | // There is no stall when ProdMI and ConsMI are not dependent. |
| 3097 | if (!isDependent(ProdMI, ConsMI)) |
| 3098 | return false; |
| 3099 | |
| 3100 | // When Forward Scheduling is enabled, there is no stall if ProdMI and ConsMI |
| 3101 | // are scheduled in consecutive packets. |
| 3102 | if (isVecUsableNextPacket(ProdMI, ConsMI)) |
| 3103 | return false; |
| 3104 | |
| 3105 | return true; |
| 3106 | } |
| 3107 | |
| 3108 | |
| 3109 | bool HexagonInstrInfo::producesStall(const MachineInstr *MI, |
| 3110 | MachineBasicBlock::const_instr_iterator BII) const { |
| 3111 | // There is no stall when I is not a V60 vector. |
| 3112 | if (!isV60VectorInstruction(MI)) |
| 3113 | return false; |
| 3114 | |
| 3115 | MachineBasicBlock::const_instr_iterator MII = BII; |
| 3116 | MachineBasicBlock::const_instr_iterator MIE = MII->getParent()->instr_end(); |
| 3117 | |
| 3118 | if (!(*MII).isBundle()) { |
| 3119 | const MachineInstr *J = &*MII; |
| 3120 | if (!isV60VectorInstruction(J)) |
| 3121 | return false; |
| 3122 | else if (isVecUsableNextPacket(J, MI)) |
| 3123 | return false; |
| 3124 | return true; |
| 3125 | } |
| 3126 | |
| 3127 | for (++MII; MII != MIE && MII->isInsideBundle(); ++MII) { |
| 3128 | const MachineInstr *J = &*MII; |
| 3129 | if (producesStall(J, MI)) |
| 3130 | return true; |
| 3131 | } |
| 3132 | return false; |
| 3133 | } |
| 3134 | |
| 3135 | |
Krzysztof Parzyszek | 5e6f2bd | 2015-12-14 21:32:25 +0000 | [diff] [blame] | 3136 | bool HexagonInstrInfo::predCanBeUsedAsDotNew(const MachineInstr *MI, |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3137 | unsigned PredReg) const { |
| 3138 | for (unsigned opNum = 0; opNum < MI->getNumOperands(); opNum++) { |
Krzysztof Parzyszek | 5e6f2bd | 2015-12-14 21:32:25 +0000 | [diff] [blame] | 3139 | const MachineOperand &MO = MI->getOperand(opNum); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3140 | if (MO.isReg() && MO.isDef() && MO.isImplicit() && (MO.getReg() == PredReg)) |
| 3141 | return false; // Predicate register must be explicitly defined. |
| 3142 | } |
| 3143 | |
| 3144 | // Hexagon Programmer's Reference says that decbin, memw_locked, and |
| 3145 | // memd_locked cannot be used as .new as well, |
| 3146 | // but we don't seem to have these instructions defined. |
| 3147 | return MI->getOpcode() != Hexagon::A4_tlbmatch; |
| 3148 | } |
| 3149 | |
| 3150 | |
| 3151 | bool HexagonInstrInfo::PredOpcodeHasJMP_c(unsigned Opcode) const { |
| 3152 | return (Opcode == Hexagon::J2_jumpt) || |
| 3153 | (Opcode == Hexagon::J2_jumpf) || |
| 3154 | (Opcode == Hexagon::J2_jumptnew) || |
| 3155 | (Opcode == Hexagon::J2_jumpfnew) || |
| 3156 | (Opcode == Hexagon::J2_jumptnewpt) || |
| 3157 | (Opcode == Hexagon::J2_jumpfnewpt); |
| 3158 | } |
| 3159 | |
| 3160 | |
| 3161 | bool HexagonInstrInfo::predOpcodeHasNot(ArrayRef<MachineOperand> Cond) const { |
| 3162 | if (Cond.empty() || !isPredicated(Cond[0].getImm())) |
| 3163 | return false; |
| 3164 | return !isPredicatedTrue(Cond[0].getImm()); |
| 3165 | } |
| 3166 | |
| 3167 | |
Krzysztof Parzyszek | f5cbac9 | 2016-04-29 15:49:13 +0000 | [diff] [blame] | 3168 | short HexagonInstrInfo::getAbsoluteForm(const MachineInstr *MI) const { |
| 3169 | return Hexagon::getAbsoluteForm(MI->getOpcode()); |
| 3170 | } |
| 3171 | |
| 3172 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3173 | unsigned HexagonInstrInfo::getAddrMode(const MachineInstr* MI) const { |
| 3174 | const uint64_t F = MI->getDesc().TSFlags; |
| 3175 | return (F >> HexagonII::AddrModePos) & HexagonII::AddrModeMask; |
| 3176 | } |
| 3177 | |
| 3178 | |
| 3179 | // Returns the base register in a memory access (load/store). The offset is |
| 3180 | // returned in Offset and the access size is returned in AccessSize. |
| 3181 | unsigned HexagonInstrInfo::getBaseAndOffset(const MachineInstr *MI, |
| 3182 | int &Offset, unsigned &AccessSize) const { |
| 3183 | // Return if it is not a base+offset type instruction or a MemOp. |
| 3184 | if (getAddrMode(MI) != HexagonII::BaseImmOffset && |
| 3185 | getAddrMode(MI) != HexagonII::BaseLongOffset && |
| 3186 | !isMemOp(MI) && !isPostIncrement(MI)) |
| 3187 | return 0; |
| 3188 | |
| 3189 | // Since it is a memory access instruction, getMemAccessSize() should never |
| 3190 | // return 0. |
| 3191 | assert (getMemAccessSize(MI) && |
| 3192 | "BaseImmOffset or BaseLongOffset or MemOp without accessSize"); |
| 3193 | |
| 3194 | // Return Values of getMemAccessSize() are |
| 3195 | // 0 - Checked in the assert above. |
| 3196 | // 1, 2, 3, 4 & 7, 8 - The statement below is correct for all these. |
| 3197 | // MemAccessSize is represented as 1+log2(N) where N is size in bits. |
| 3198 | AccessSize = (1U << (getMemAccessSize(MI) - 1)); |
| 3199 | |
| 3200 | unsigned basePos = 0, offsetPos = 0; |
| 3201 | if (!getBaseAndOffsetPosition(MI, basePos, offsetPos)) |
| 3202 | return 0; |
| 3203 | |
| 3204 | // Post increment updates its EA after the mem access, |
| 3205 | // so we need to treat its offset as zero. |
| 3206 | if (isPostIncrement(MI)) |
| 3207 | Offset = 0; |
| 3208 | else { |
| 3209 | Offset = MI->getOperand(offsetPos).getImm(); |
| 3210 | } |
| 3211 | |
| 3212 | return MI->getOperand(basePos).getReg(); |
| 3213 | } |
| 3214 | |
| 3215 | |
| 3216 | /// Return the position of the base and offset operands for this instruction. |
| 3217 | bool HexagonInstrInfo::getBaseAndOffsetPosition(const MachineInstr *MI, |
| 3218 | unsigned &BasePos, unsigned &OffsetPos) const { |
| 3219 | // Deal with memops first. |
| 3220 | if (isMemOp(MI)) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3221 | BasePos = 0; |
| 3222 | OffsetPos = 1; |
| 3223 | } else if (MI->mayStore()) { |
| 3224 | BasePos = 0; |
| 3225 | OffsetPos = 1; |
| 3226 | } else if (MI->mayLoad()) { |
| 3227 | BasePos = 1; |
| 3228 | OffsetPos = 2; |
| 3229 | } else |
| 3230 | return false; |
| 3231 | |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 3232 | if (isPredicated(*MI)) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3233 | BasePos++; |
| 3234 | OffsetPos++; |
| 3235 | } |
| 3236 | if (isPostIncrement(MI)) { |
| 3237 | BasePos++; |
| 3238 | OffsetPos++; |
| 3239 | } |
| 3240 | |
| 3241 | if (!MI->getOperand(BasePos).isReg() || !MI->getOperand(OffsetPos).isImm()) |
| 3242 | return false; |
| 3243 | |
| 3244 | return true; |
| 3245 | } |
| 3246 | |
| 3247 | |
| 3248 | // Inserts branching instructions in reverse order of their occurence. |
| 3249 | // e.g. jump_t t1 (i1) |
| 3250 | // jump t2 (i2) |
| 3251 | // Jumpers = {i2, i1} |
| 3252 | SmallVector<MachineInstr*, 2> HexagonInstrInfo::getBranchingInstrs( |
| 3253 | MachineBasicBlock& MBB) const { |
| 3254 | SmallVector<MachineInstr*, 2> Jumpers; |
| 3255 | // If the block has no terminators, it just falls into the block after it. |
| 3256 | MachineBasicBlock::instr_iterator I = MBB.instr_end(); |
| 3257 | if (I == MBB.instr_begin()) |
| 3258 | return Jumpers; |
| 3259 | |
| 3260 | // A basic block may looks like this: |
| 3261 | // |
| 3262 | // [ insn |
| 3263 | // EH_LABEL |
| 3264 | // insn |
| 3265 | // insn |
| 3266 | // insn |
| 3267 | // EH_LABEL |
| 3268 | // insn ] |
| 3269 | // |
| 3270 | // It has two succs but does not have a terminator |
| 3271 | // Don't know how to handle it. |
| 3272 | do { |
| 3273 | --I; |
| 3274 | if (I->isEHLabel()) |
| 3275 | return Jumpers; |
| 3276 | } while (I != MBB.instr_begin()); |
| 3277 | |
| 3278 | I = MBB.instr_end(); |
| 3279 | --I; |
| 3280 | |
| 3281 | while (I->isDebugValue()) { |
| 3282 | if (I == MBB.instr_begin()) |
| 3283 | return Jumpers; |
| 3284 | --I; |
| 3285 | } |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 3286 | if (!isUnpredicatedTerminator(*I)) |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3287 | return Jumpers; |
| 3288 | |
| 3289 | // Get the last instruction in the block. |
| 3290 | MachineInstr *LastInst = &*I; |
| 3291 | Jumpers.push_back(LastInst); |
| 3292 | MachineInstr *SecondLastInst = nullptr; |
| 3293 | // Find one more terminator if present. |
| 3294 | do { |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 3295 | if (&*I != LastInst && !I->isBundle() && isUnpredicatedTerminator(*I)) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3296 | if (!SecondLastInst) { |
| 3297 | SecondLastInst = &*I; |
| 3298 | Jumpers.push_back(SecondLastInst); |
| 3299 | } else // This is a third branch. |
| 3300 | return Jumpers; |
| 3301 | } |
| 3302 | if (I == MBB.instr_begin()) |
| 3303 | break; |
| 3304 | --I; |
| 3305 | } while (true); |
| 3306 | return Jumpers; |
| 3307 | } |
| 3308 | |
| 3309 | |
Krzysztof Parzyszek | f5cbac9 | 2016-04-29 15:49:13 +0000 | [diff] [blame] | 3310 | short HexagonInstrInfo::getBaseWithLongOffset(short Opcode) const { |
| 3311 | if (Opcode < 0) |
| 3312 | return -1; |
| 3313 | return Hexagon::getBaseWithLongOffset(Opcode); |
| 3314 | } |
| 3315 | |
| 3316 | |
| 3317 | short HexagonInstrInfo::getBaseWithLongOffset(const MachineInstr *MI) const { |
| 3318 | return Hexagon::getBaseWithLongOffset(MI->getOpcode()); |
| 3319 | } |
| 3320 | |
| 3321 | |
| 3322 | short HexagonInstrInfo::getBaseWithRegOffset(const MachineInstr *MI) const { |
| 3323 | return Hexagon::getBaseWithRegOffset(MI->getOpcode()); |
| 3324 | } |
| 3325 | |
| 3326 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3327 | // Returns Operand Index for the constant extended instruction. |
| 3328 | unsigned HexagonInstrInfo::getCExtOpNum(const MachineInstr *MI) const { |
| 3329 | const uint64_t F = MI->getDesc().TSFlags; |
| 3330 | return (F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask; |
| 3331 | } |
| 3332 | |
| 3333 | // See if instruction could potentially be a duplex candidate. |
| 3334 | // If so, return its group. Zero otherwise. |
| 3335 | HexagonII::CompoundGroup HexagonInstrInfo::getCompoundCandidateGroup( |
| 3336 | const MachineInstr *MI) const { |
| 3337 | unsigned DstReg, SrcReg, Src1Reg, Src2Reg; |
| 3338 | |
| 3339 | switch (MI->getOpcode()) { |
| 3340 | default: |
| 3341 | return HexagonII::HCG_None; |
| 3342 | // |
| 3343 | // Compound pairs. |
| 3344 | // "p0=cmp.eq(Rs16,Rt16); if (p0.new) jump:nt #r9:2" |
| 3345 | // "Rd16=#U6 ; jump #r9:2" |
| 3346 | // "Rd16=Rs16 ; jump #r9:2" |
| 3347 | // |
| 3348 | case Hexagon::C2_cmpeq: |
| 3349 | case Hexagon::C2_cmpgt: |
| 3350 | case Hexagon::C2_cmpgtu: |
| 3351 | DstReg = MI->getOperand(0).getReg(); |
| 3352 | Src1Reg = MI->getOperand(1).getReg(); |
| 3353 | Src2Reg = MI->getOperand(2).getReg(); |
| 3354 | if (Hexagon::PredRegsRegClass.contains(DstReg) && |
| 3355 | (Hexagon::P0 == DstReg || Hexagon::P1 == DstReg) && |
| 3356 | isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg)) |
| 3357 | return HexagonII::HCG_A; |
| 3358 | break; |
| 3359 | case Hexagon::C2_cmpeqi: |
| 3360 | case Hexagon::C2_cmpgti: |
| 3361 | case Hexagon::C2_cmpgtui: |
| 3362 | // P0 = cmp.eq(Rs,#u2) |
| 3363 | DstReg = MI->getOperand(0).getReg(); |
| 3364 | SrcReg = MI->getOperand(1).getReg(); |
| 3365 | if (Hexagon::PredRegsRegClass.contains(DstReg) && |
| 3366 | (Hexagon::P0 == DstReg || Hexagon::P1 == DstReg) && |
| 3367 | isIntRegForSubInst(SrcReg) && MI->getOperand(2).isImm() && |
| 3368 | ((isUInt<5>(MI->getOperand(2).getImm())) || |
| 3369 | (MI->getOperand(2).getImm() == -1))) |
| 3370 | return HexagonII::HCG_A; |
| 3371 | break; |
| 3372 | case Hexagon::A2_tfr: |
| 3373 | // Rd = Rs |
| 3374 | DstReg = MI->getOperand(0).getReg(); |
| 3375 | SrcReg = MI->getOperand(1).getReg(); |
| 3376 | if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg)) |
| 3377 | return HexagonII::HCG_A; |
| 3378 | break; |
| 3379 | case Hexagon::A2_tfrsi: |
| 3380 | // Rd = #u6 |
| 3381 | // Do not test for #u6 size since the const is getting extended |
| 3382 | // regardless and compound could be formed. |
| 3383 | DstReg = MI->getOperand(0).getReg(); |
| 3384 | if (isIntRegForSubInst(DstReg)) |
| 3385 | return HexagonII::HCG_A; |
| 3386 | break; |
| 3387 | case Hexagon::S2_tstbit_i: |
| 3388 | DstReg = MI->getOperand(0).getReg(); |
| 3389 | Src1Reg = MI->getOperand(1).getReg(); |
| 3390 | if (Hexagon::PredRegsRegClass.contains(DstReg) && |
| 3391 | (Hexagon::P0 == DstReg || Hexagon::P1 == DstReg) && |
| 3392 | MI->getOperand(2).isImm() && |
| 3393 | isIntRegForSubInst(Src1Reg) && (MI->getOperand(2).getImm() == 0)) |
| 3394 | return HexagonII::HCG_A; |
| 3395 | break; |
| 3396 | // The fact that .new form is used pretty much guarantees |
| 3397 | // that predicate register will match. Nevertheless, |
| 3398 | // there could be some false positives without additional |
| 3399 | // checking. |
| 3400 | case Hexagon::J2_jumptnew: |
| 3401 | case Hexagon::J2_jumpfnew: |
| 3402 | case Hexagon::J2_jumptnewpt: |
| 3403 | case Hexagon::J2_jumpfnewpt: |
| 3404 | Src1Reg = MI->getOperand(0).getReg(); |
| 3405 | if (Hexagon::PredRegsRegClass.contains(Src1Reg) && |
| 3406 | (Hexagon::P0 == Src1Reg || Hexagon::P1 == Src1Reg)) |
| 3407 | return HexagonII::HCG_B; |
| 3408 | break; |
| 3409 | // Transfer and jump: |
| 3410 | // Rd=#U6 ; jump #r9:2 |
| 3411 | // Rd=Rs ; jump #r9:2 |
| 3412 | // Do not test for jump range here. |
| 3413 | case Hexagon::J2_jump: |
| 3414 | case Hexagon::RESTORE_DEALLOC_RET_JMP_V4: |
| 3415 | return HexagonII::HCG_C; |
| 3416 | break; |
| 3417 | } |
| 3418 | |
| 3419 | return HexagonII::HCG_None; |
| 3420 | } |
| 3421 | |
| 3422 | |
| 3423 | // Returns -1 when there is no opcode found. |
| 3424 | unsigned HexagonInstrInfo::getCompoundOpcode(const MachineInstr *GA, |
| 3425 | const MachineInstr *GB) const { |
| 3426 | assert(getCompoundCandidateGroup(GA) == HexagonII::HCG_A); |
| 3427 | assert(getCompoundCandidateGroup(GB) == HexagonII::HCG_B); |
| 3428 | if ((GA->getOpcode() != Hexagon::C2_cmpeqi) || |
| 3429 | (GB->getOpcode() != Hexagon::J2_jumptnew)) |
| 3430 | return -1; |
| 3431 | unsigned DestReg = GA->getOperand(0).getReg(); |
| 3432 | if (!GB->readsRegister(DestReg)) |
| 3433 | return -1; |
| 3434 | if (DestReg == Hexagon::P0) |
| 3435 | return Hexagon::J4_cmpeqi_tp0_jump_nt; |
| 3436 | if (DestReg == Hexagon::P1) |
| 3437 | return Hexagon::J4_cmpeqi_tp1_jump_nt; |
| 3438 | return -1; |
| 3439 | } |
| 3440 | |
| 3441 | |
| 3442 | int HexagonInstrInfo::getCondOpcode(int Opc, bool invertPredicate) const { |
| 3443 | enum Hexagon::PredSense inPredSense; |
| 3444 | inPredSense = invertPredicate ? Hexagon::PredSense_false : |
| 3445 | Hexagon::PredSense_true; |
| 3446 | int CondOpcode = Hexagon::getPredOpcode(Opc, inPredSense); |
| 3447 | if (CondOpcode >= 0) // Valid Conditional opcode/instruction |
| 3448 | return CondOpcode; |
| 3449 | |
| 3450 | // This switch case will be removed once all the instructions have been |
| 3451 | // modified to use relation maps. |
| 3452 | switch(Opc) { |
| 3453 | case Hexagon::TFRI_f: |
| 3454 | return !invertPredicate ? Hexagon::TFRI_cPt_f : |
| 3455 | Hexagon::TFRI_cNotPt_f; |
| 3456 | } |
| 3457 | |
| 3458 | llvm_unreachable("Unexpected predicable instruction"); |
| 3459 | } |
| 3460 | |
| 3461 | |
| 3462 | // Return the cur value instruction for a given store. |
| 3463 | int HexagonInstrInfo::getDotCurOp(const MachineInstr* MI) const { |
| 3464 | switch (MI->getOpcode()) { |
| 3465 | default: llvm_unreachable("Unknown .cur type"); |
| 3466 | case Hexagon::V6_vL32b_pi: |
| 3467 | return Hexagon::V6_vL32b_cur_pi; |
| 3468 | case Hexagon::V6_vL32b_ai: |
| 3469 | return Hexagon::V6_vL32b_cur_ai; |
| 3470 | //128B |
| 3471 | case Hexagon::V6_vL32b_pi_128B: |
| 3472 | return Hexagon::V6_vL32b_cur_pi_128B; |
| 3473 | case Hexagon::V6_vL32b_ai_128B: |
| 3474 | return Hexagon::V6_vL32b_cur_ai_128B; |
| 3475 | } |
| 3476 | return 0; |
| 3477 | } |
| 3478 | |
| 3479 | |
| 3480 | |
| 3481 | // The diagram below shows the steps involved in the conversion of a predicated |
| 3482 | // store instruction to its .new predicated new-value form. |
| 3483 | // |
| 3484 | // p.new NV store [ if(p0.new)memw(R0+#0)=R2.new ] |
| 3485 | // ^ ^ |
| 3486 | // / \ (not OK. it will cause new-value store to be |
| 3487 | // / X conditional on p0.new while R2 producer is |
| 3488 | // / \ on p0) |
| 3489 | // / \. |
| 3490 | // p.new store p.old NV store |
| 3491 | // [if(p0.new)memw(R0+#0)=R2] [if(p0)memw(R0+#0)=R2.new] |
| 3492 | // ^ ^ |
| 3493 | // \ / |
| 3494 | // \ / |
| 3495 | // \ / |
| 3496 | // p.old store |
| 3497 | // [if (p0)memw(R0+#0)=R2] |
| 3498 | // |
| 3499 | // |
| 3500 | // The following set of instructions further explains the scenario where |
| 3501 | // conditional new-value store becomes invalid when promoted to .new predicate |
| 3502 | // form. |
| 3503 | // |
| 3504 | // { 1) if (p0) r0 = add(r1, r2) |
| 3505 | // 2) p0 = cmp.eq(r3, #0) } |
| 3506 | // |
| 3507 | // 3) if (p0) memb(r1+#0) = r0 --> this instruction can't be grouped with |
| 3508 | // the first two instructions because in instr 1, r0 is conditional on old value |
| 3509 | // of p0 but its use in instr 3 is conditional on p0 modified by instr 2 which |
| 3510 | // is not valid for new-value stores. |
| 3511 | // Predicated new value stores (i.e. if (p0) memw(..)=r0.new) are excluded |
| 3512 | // from the "Conditional Store" list. Because a predicated new value store |
| 3513 | // would NOT be promoted to a double dot new store. See diagram below: |
| 3514 | // This function returns yes for those stores that are predicated but not |
| 3515 | // yet promoted to predicate dot new instructions. |
| 3516 | // |
| 3517 | // +---------------------+ |
| 3518 | // /-----| if (p0) memw(..)=r0 |---------\~ |
| 3519 | // || +---------------------+ || |
| 3520 | // promote || /\ /\ || promote |
| 3521 | // || /||\ /||\ || |
| 3522 | // \||/ demote || \||/ |
| 3523 | // \/ || || \/ |
| 3524 | // +-------------------------+ || +-------------------------+ |
| 3525 | // | if (p0.new) memw(..)=r0 | || | if (p0) memw(..)=r0.new | |
| 3526 | // +-------------------------+ || +-------------------------+ |
| 3527 | // || || || |
| 3528 | // || demote \||/ |
| 3529 | // promote || \/ NOT possible |
| 3530 | // || || /\~ |
| 3531 | // \||/ || /||\~ |
| 3532 | // \/ || || |
| 3533 | // +-----------------------------+ |
| 3534 | // | if (p0.new) memw(..)=r0.new | |
| 3535 | // +-----------------------------+ |
| 3536 | // Double Dot New Store |
| 3537 | // |
| 3538 | // Returns the most basic instruction for the .new predicated instructions and |
| 3539 | // new-value stores. |
| 3540 | // For example, all of the following instructions will be converted back to the |
| 3541 | // same instruction: |
| 3542 | // 1) if (p0.new) memw(R0+#0) = R1.new ---> |
| 3543 | // 2) if (p0) memw(R0+#0)= R1.new -------> if (p0) memw(R0+#0) = R1 |
| 3544 | // 3) if (p0.new) memw(R0+#0) = R1 ---> |
| 3545 | // |
| 3546 | // To understand the translation of instruction 1 to its original form, consider |
| 3547 | // a packet with 3 instructions. |
| 3548 | // { p0 = cmp.eq(R0,R1) |
| 3549 | // if (p0.new) R2 = add(R3, R4) |
| 3550 | // R5 = add (R3, R1) |
| 3551 | // } |
| 3552 | // if (p0) memw(R5+#0) = R2 <--- trying to include it in the previous packet |
| 3553 | // |
| 3554 | // This instruction can be part of the previous packet only if both p0 and R2 |
| 3555 | // are promoted to .new values. This promotion happens in steps, first |
| 3556 | // predicate register is promoted to .new and in the next iteration R2 is |
| 3557 | // promoted. Therefore, in case of dependence check failure (due to R5) during |
| 3558 | // next iteration, it should be converted back to its most basic form. |
| 3559 | |
| 3560 | |
| 3561 | // Return the new value instruction for a given store. |
| 3562 | int HexagonInstrInfo::getDotNewOp(const MachineInstr* MI) const { |
| 3563 | int NVOpcode = Hexagon::getNewValueOpcode(MI->getOpcode()); |
| 3564 | if (NVOpcode >= 0) // Valid new-value store instruction. |
| 3565 | return NVOpcode; |
| 3566 | |
| 3567 | switch (MI->getOpcode()) { |
| 3568 | default: llvm_unreachable("Unknown .new type"); |
| 3569 | case Hexagon::S4_storerb_ur: |
| 3570 | return Hexagon::S4_storerbnew_ur; |
| 3571 | |
| 3572 | case Hexagon::S2_storerb_pci: |
| 3573 | return Hexagon::S2_storerb_pci; |
| 3574 | |
| 3575 | case Hexagon::S2_storeri_pci: |
| 3576 | return Hexagon::S2_storeri_pci; |
| 3577 | |
| 3578 | case Hexagon::S2_storerh_pci: |
| 3579 | return Hexagon::S2_storerh_pci; |
| 3580 | |
| 3581 | case Hexagon::S2_storerd_pci: |
| 3582 | return Hexagon::S2_storerd_pci; |
| 3583 | |
| 3584 | case Hexagon::S2_storerf_pci: |
| 3585 | return Hexagon::S2_storerf_pci; |
| 3586 | |
| 3587 | case Hexagon::V6_vS32b_ai: |
| 3588 | return Hexagon::V6_vS32b_new_ai; |
| 3589 | |
| 3590 | case Hexagon::V6_vS32b_pi: |
| 3591 | return Hexagon::V6_vS32b_new_pi; |
| 3592 | |
| 3593 | // 128B |
| 3594 | case Hexagon::V6_vS32b_ai_128B: |
| 3595 | return Hexagon::V6_vS32b_new_ai_128B; |
| 3596 | |
| 3597 | case Hexagon::V6_vS32b_pi_128B: |
| 3598 | return Hexagon::V6_vS32b_new_pi_128B; |
| 3599 | } |
| 3600 | return 0; |
| 3601 | } |
| 3602 | |
Krzysztof Parzyszek | 0a04ac2 | 2016-05-16 16:56:10 +0000 | [diff] [blame] | 3603 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3604 | // Returns the opcode to use when converting MI, which is a conditional jump, |
| 3605 | // into a conditional instruction which uses the .new value of the predicate. |
| 3606 | // We also use branch probabilities to add a hint to the jump. |
Krzysztof Parzyszek | 5e6f2bd | 2015-12-14 21:32:25 +0000 | [diff] [blame] | 3607 | int HexagonInstrInfo::getDotNewPredJumpOp(const MachineInstr *MI, |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3608 | const MachineBranchProbabilityInfo *MBPI) const { |
| 3609 | // We assume that block can have at most two successors. |
| 3610 | bool taken = false; |
Krzysztof Parzyszek | 5e6f2bd | 2015-12-14 21:32:25 +0000 | [diff] [blame] | 3611 | const MachineBasicBlock *Src = MI->getParent(); |
| 3612 | const MachineOperand *BrTarget = &MI->getOperand(1); |
| 3613 | const MachineBasicBlock *Dst = BrTarget->getMBB(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3614 | |
| 3615 | const BranchProbability Prediction = MBPI->getEdgeProbability(Src, Dst); |
| 3616 | if (Prediction >= BranchProbability(1,2)) |
| 3617 | taken = true; |
| 3618 | |
| 3619 | switch (MI->getOpcode()) { |
| 3620 | case Hexagon::J2_jumpt: |
| 3621 | return taken ? Hexagon::J2_jumptnewpt : Hexagon::J2_jumptnew; |
| 3622 | case Hexagon::J2_jumpf: |
| 3623 | return taken ? Hexagon::J2_jumpfnewpt : Hexagon::J2_jumpfnew; |
| 3624 | |
| 3625 | default: |
| 3626 | llvm_unreachable("Unexpected jump instruction."); |
| 3627 | } |
| 3628 | } |
| 3629 | |
| 3630 | |
| 3631 | // Return .new predicate version for an instruction. |
Krzysztof Parzyszek | 5e6f2bd | 2015-12-14 21:32:25 +0000 | [diff] [blame] | 3632 | int HexagonInstrInfo::getDotNewPredOp(const MachineInstr *MI, |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3633 | const MachineBranchProbabilityInfo *MBPI) const { |
| 3634 | int NewOpcode = Hexagon::getPredNewOpcode(MI->getOpcode()); |
| 3635 | if (NewOpcode >= 0) // Valid predicate new instruction |
| 3636 | return NewOpcode; |
| 3637 | |
| 3638 | switch (MI->getOpcode()) { |
| 3639 | // Condtional Jumps |
| 3640 | case Hexagon::J2_jumpt: |
| 3641 | case Hexagon::J2_jumpf: |
| 3642 | return getDotNewPredJumpOp(MI, MBPI); |
| 3643 | |
| 3644 | default: |
| 3645 | assert(0 && "Unknown .new type"); |
| 3646 | } |
| 3647 | return 0; |
| 3648 | } |
| 3649 | |
| 3650 | |
| 3651 | int HexagonInstrInfo::getDotOldOp(const int opc) const { |
| 3652 | int NewOp = opc; |
| 3653 | if (isPredicated(NewOp) && isPredicatedNew(NewOp)) { // Get predicate old form |
| 3654 | NewOp = Hexagon::getPredOldOpcode(NewOp); |
| 3655 | assert(NewOp >= 0 && |
| 3656 | "Couldn't change predicate new instruction to its old form."); |
| 3657 | } |
| 3658 | |
| 3659 | if (isNewValueStore(NewOp)) { // Convert into non-new-value format |
| 3660 | NewOp = Hexagon::getNonNVStore(NewOp); |
| 3661 | assert(NewOp >= 0 && "Couldn't change new-value store to its old form."); |
| 3662 | } |
| 3663 | return NewOp; |
| 3664 | } |
| 3665 | |
| 3666 | |
| 3667 | // See if instruction could potentially be a duplex candidate. |
| 3668 | // If so, return its group. Zero otherwise. |
| 3669 | HexagonII::SubInstructionGroup HexagonInstrInfo::getDuplexCandidateGroup( |
| 3670 | const MachineInstr *MI) const { |
| 3671 | unsigned DstReg, SrcReg, Src1Reg, Src2Reg; |
| 3672 | auto &HRI = getRegisterInfo(); |
| 3673 | |
| 3674 | switch (MI->getOpcode()) { |
| 3675 | default: |
| 3676 | return HexagonII::HSIG_None; |
| 3677 | // |
| 3678 | // Group L1: |
| 3679 | // |
| 3680 | // Rd = memw(Rs+#u4:2) |
| 3681 | // Rd = memub(Rs+#u4:0) |
| 3682 | case Hexagon::L2_loadri_io: |
| 3683 | DstReg = MI->getOperand(0).getReg(); |
| 3684 | SrcReg = MI->getOperand(1).getReg(); |
| 3685 | // Special case this one from Group L2. |
| 3686 | // Rd = memw(r29+#u5:2) |
| 3687 | if (isIntRegForSubInst(DstReg)) { |
| 3688 | if (Hexagon::IntRegsRegClass.contains(SrcReg) && |
| 3689 | HRI.getStackRegister() == SrcReg && |
| 3690 | MI->getOperand(2).isImm() && |
| 3691 | isShiftedUInt<5,2>(MI->getOperand(2).getImm())) |
| 3692 | return HexagonII::HSIG_L2; |
| 3693 | // Rd = memw(Rs+#u4:2) |
| 3694 | if (isIntRegForSubInst(SrcReg) && |
| 3695 | (MI->getOperand(2).isImm() && |
| 3696 | isShiftedUInt<4,2>(MI->getOperand(2).getImm()))) |
| 3697 | return HexagonII::HSIG_L1; |
| 3698 | } |
| 3699 | break; |
| 3700 | case Hexagon::L2_loadrub_io: |
| 3701 | // Rd = memub(Rs+#u4:0) |
| 3702 | DstReg = MI->getOperand(0).getReg(); |
| 3703 | SrcReg = MI->getOperand(1).getReg(); |
| 3704 | if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) && |
| 3705 | MI->getOperand(2).isImm() && isUInt<4>(MI->getOperand(2).getImm())) |
| 3706 | return HexagonII::HSIG_L1; |
| 3707 | break; |
| 3708 | // |
| 3709 | // Group L2: |
| 3710 | // |
| 3711 | // Rd = memh/memuh(Rs+#u3:1) |
| 3712 | // Rd = memb(Rs+#u3:0) |
| 3713 | // Rd = memw(r29+#u5:2) - Handled above. |
| 3714 | // Rdd = memd(r29+#u5:3) |
| 3715 | // deallocframe |
| 3716 | // [if ([!]p0[.new])] dealloc_return |
| 3717 | // [if ([!]p0[.new])] jumpr r31 |
| 3718 | case Hexagon::L2_loadrh_io: |
| 3719 | case Hexagon::L2_loadruh_io: |
| 3720 | // Rd = memh/memuh(Rs+#u3:1) |
| 3721 | DstReg = MI->getOperand(0).getReg(); |
| 3722 | SrcReg = MI->getOperand(1).getReg(); |
| 3723 | if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) && |
| 3724 | MI->getOperand(2).isImm() && |
| 3725 | isShiftedUInt<3,1>(MI->getOperand(2).getImm())) |
| 3726 | return HexagonII::HSIG_L2; |
| 3727 | break; |
| 3728 | case Hexagon::L2_loadrb_io: |
| 3729 | // Rd = memb(Rs+#u3:0) |
| 3730 | DstReg = MI->getOperand(0).getReg(); |
| 3731 | SrcReg = MI->getOperand(1).getReg(); |
| 3732 | if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) && |
| 3733 | MI->getOperand(2).isImm() && |
| 3734 | isUInt<3>(MI->getOperand(2).getImm())) |
| 3735 | return HexagonII::HSIG_L2; |
| 3736 | break; |
| 3737 | case Hexagon::L2_loadrd_io: |
| 3738 | // Rdd = memd(r29+#u5:3) |
| 3739 | DstReg = MI->getOperand(0).getReg(); |
| 3740 | SrcReg = MI->getOperand(1).getReg(); |
| 3741 | if (isDblRegForSubInst(DstReg, HRI) && |
| 3742 | Hexagon::IntRegsRegClass.contains(SrcReg) && |
| 3743 | HRI.getStackRegister() == SrcReg && |
| 3744 | MI->getOperand(2).isImm() && |
| 3745 | isShiftedUInt<5,3>(MI->getOperand(2).getImm())) |
| 3746 | return HexagonII::HSIG_L2; |
| 3747 | break; |
| 3748 | // dealloc_return is not documented in Hexagon Manual, but marked |
| 3749 | // with A_SUBINSN attribute in iset_v4classic.py. |
| 3750 | case Hexagon::RESTORE_DEALLOC_RET_JMP_V4: |
| 3751 | case Hexagon::L4_return: |
| 3752 | case Hexagon::L2_deallocframe: |
| 3753 | return HexagonII::HSIG_L2; |
| 3754 | case Hexagon::EH_RETURN_JMPR: |
| 3755 | case Hexagon::JMPret : |
| 3756 | // jumpr r31 |
| 3757 | // Actual form JMPR %PC<imp-def>, %R31<imp-use>, %R0<imp-use,internal>. |
| 3758 | DstReg = MI->getOperand(0).getReg(); |
| 3759 | if (Hexagon::IntRegsRegClass.contains(DstReg) && (Hexagon::R31 == DstReg)) |
| 3760 | return HexagonII::HSIG_L2; |
| 3761 | break; |
| 3762 | case Hexagon::JMPrett: |
| 3763 | case Hexagon::JMPretf: |
| 3764 | case Hexagon::JMPrettnewpt: |
| 3765 | case Hexagon::JMPretfnewpt : |
| 3766 | case Hexagon::JMPrettnew : |
| 3767 | case Hexagon::JMPretfnew : |
| 3768 | DstReg = MI->getOperand(1).getReg(); |
| 3769 | SrcReg = MI->getOperand(0).getReg(); |
| 3770 | // [if ([!]p0[.new])] jumpr r31 |
| 3771 | if ((Hexagon::PredRegsRegClass.contains(SrcReg) && |
| 3772 | (Hexagon::P0 == SrcReg)) && |
| 3773 | (Hexagon::IntRegsRegClass.contains(DstReg) && (Hexagon::R31 == DstReg))) |
| 3774 | return HexagonII::HSIG_L2; |
| 3775 | break; |
| 3776 | case Hexagon::L4_return_t : |
| 3777 | case Hexagon::L4_return_f : |
| 3778 | case Hexagon::L4_return_tnew_pnt : |
| 3779 | case Hexagon::L4_return_fnew_pnt : |
| 3780 | case Hexagon::L4_return_tnew_pt : |
| 3781 | case Hexagon::L4_return_fnew_pt : |
| 3782 | // [if ([!]p0[.new])] dealloc_return |
| 3783 | SrcReg = MI->getOperand(0).getReg(); |
| 3784 | if (Hexagon::PredRegsRegClass.contains(SrcReg) && (Hexagon::P0 == SrcReg)) |
| 3785 | return HexagonII::HSIG_L2; |
| 3786 | break; |
| 3787 | // |
| 3788 | // Group S1: |
| 3789 | // |
| 3790 | // memw(Rs+#u4:2) = Rt |
| 3791 | // memb(Rs+#u4:0) = Rt |
| 3792 | case Hexagon::S2_storeri_io: |
| 3793 | // Special case this one from Group S2. |
| 3794 | // memw(r29+#u5:2) = Rt |
| 3795 | Src1Reg = MI->getOperand(0).getReg(); |
| 3796 | Src2Reg = MI->getOperand(2).getReg(); |
| 3797 | if (Hexagon::IntRegsRegClass.contains(Src1Reg) && |
| 3798 | isIntRegForSubInst(Src2Reg) && |
| 3799 | HRI.getStackRegister() == Src1Reg && MI->getOperand(1).isImm() && |
| 3800 | isShiftedUInt<5,2>(MI->getOperand(1).getImm())) |
| 3801 | return HexagonII::HSIG_S2; |
| 3802 | // memw(Rs+#u4:2) = Rt |
| 3803 | if (isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg) && |
| 3804 | MI->getOperand(1).isImm() && |
| 3805 | isShiftedUInt<4,2>(MI->getOperand(1).getImm())) |
| 3806 | return HexagonII::HSIG_S1; |
| 3807 | break; |
| 3808 | case Hexagon::S2_storerb_io: |
| 3809 | // memb(Rs+#u4:0) = Rt |
| 3810 | Src1Reg = MI->getOperand(0).getReg(); |
| 3811 | Src2Reg = MI->getOperand(2).getReg(); |
| 3812 | if (isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg) && |
| 3813 | MI->getOperand(1).isImm() && isUInt<4>(MI->getOperand(1).getImm())) |
| 3814 | return HexagonII::HSIG_S1; |
| 3815 | break; |
| 3816 | // |
| 3817 | // Group S2: |
| 3818 | // |
| 3819 | // memh(Rs+#u3:1) = Rt |
| 3820 | // memw(r29+#u5:2) = Rt |
| 3821 | // memd(r29+#s6:3) = Rtt |
| 3822 | // memw(Rs+#u4:2) = #U1 |
| 3823 | // memb(Rs+#u4) = #U1 |
| 3824 | // allocframe(#u5:3) |
| 3825 | case Hexagon::S2_storerh_io: |
| 3826 | // memh(Rs+#u3:1) = Rt |
| 3827 | Src1Reg = MI->getOperand(0).getReg(); |
| 3828 | Src2Reg = MI->getOperand(2).getReg(); |
| 3829 | if (isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg) && |
| 3830 | MI->getOperand(1).isImm() && |
| 3831 | isShiftedUInt<3,1>(MI->getOperand(1).getImm())) |
| 3832 | return HexagonII::HSIG_S1; |
| 3833 | break; |
| 3834 | case Hexagon::S2_storerd_io: |
| 3835 | // memd(r29+#s6:3) = Rtt |
| 3836 | Src1Reg = MI->getOperand(0).getReg(); |
| 3837 | Src2Reg = MI->getOperand(2).getReg(); |
| 3838 | if (isDblRegForSubInst(Src2Reg, HRI) && |
| 3839 | Hexagon::IntRegsRegClass.contains(Src1Reg) && |
| 3840 | HRI.getStackRegister() == Src1Reg && MI->getOperand(1).isImm() && |
| 3841 | isShiftedInt<6,3>(MI->getOperand(1).getImm())) |
| 3842 | return HexagonII::HSIG_S2; |
| 3843 | break; |
| 3844 | case Hexagon::S4_storeiri_io: |
| 3845 | // memw(Rs+#u4:2) = #U1 |
| 3846 | Src1Reg = MI->getOperand(0).getReg(); |
| 3847 | if (isIntRegForSubInst(Src1Reg) && MI->getOperand(1).isImm() && |
| 3848 | isShiftedUInt<4,2>(MI->getOperand(1).getImm()) && |
| 3849 | MI->getOperand(2).isImm() && isUInt<1>(MI->getOperand(2).getImm())) |
| 3850 | return HexagonII::HSIG_S2; |
| 3851 | break; |
| 3852 | case Hexagon::S4_storeirb_io: |
| 3853 | // memb(Rs+#u4) = #U1 |
| 3854 | Src1Reg = MI->getOperand(0).getReg(); |
Krzysztof Parzyszek | f2a4f8f | 2016-06-15 21:05:04 +0000 | [diff] [blame] | 3855 | if (isIntRegForSubInst(Src1Reg) && |
| 3856 | MI->getOperand(1).isImm() && isUInt<4>(MI->getOperand(1).getImm()) && |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 3857 | MI->getOperand(2).isImm() && isUInt<1>(MI->getOperand(2).getImm())) |
| 3858 | return HexagonII::HSIG_S2; |
| 3859 | break; |
| 3860 | case Hexagon::S2_allocframe: |
| 3861 | if (MI->getOperand(0).isImm() && |
| 3862 | isShiftedUInt<5,3>(MI->getOperand(0).getImm())) |
| 3863 | return HexagonII::HSIG_S1; |
| 3864 | break; |
| 3865 | // |
| 3866 | // Group A: |
| 3867 | // |
| 3868 | // Rx = add(Rx,#s7) |
| 3869 | // Rd = Rs |
| 3870 | // Rd = #u6 |
| 3871 | // Rd = #-1 |
| 3872 | // if ([!]P0[.new]) Rd = #0 |
| 3873 | // Rd = add(r29,#u6:2) |
| 3874 | // Rx = add(Rx,Rs) |
| 3875 | // P0 = cmp.eq(Rs,#u2) |
| 3876 | // Rdd = combine(#0,Rs) |
| 3877 | // Rdd = combine(Rs,#0) |
| 3878 | // Rdd = combine(#u2,#U2) |
| 3879 | // Rd = add(Rs,#1) |
| 3880 | // Rd = add(Rs,#-1) |
| 3881 | // Rd = sxth/sxtb/zxtb/zxth(Rs) |
| 3882 | // Rd = and(Rs,#1) |
| 3883 | case Hexagon::A2_addi: |
| 3884 | DstReg = MI->getOperand(0).getReg(); |
| 3885 | SrcReg = MI->getOperand(1).getReg(); |
| 3886 | if (isIntRegForSubInst(DstReg)) { |
| 3887 | // Rd = add(r29,#u6:2) |
| 3888 | if (Hexagon::IntRegsRegClass.contains(SrcReg) && |
| 3889 | HRI.getStackRegister() == SrcReg && MI->getOperand(2).isImm() && |
| 3890 | isShiftedUInt<6,2>(MI->getOperand(2).getImm())) |
| 3891 | return HexagonII::HSIG_A; |
| 3892 | // Rx = add(Rx,#s7) |
| 3893 | if ((DstReg == SrcReg) && MI->getOperand(2).isImm() && |
| 3894 | isInt<7>(MI->getOperand(2).getImm())) |
| 3895 | return HexagonII::HSIG_A; |
| 3896 | // Rd = add(Rs,#1) |
| 3897 | // Rd = add(Rs,#-1) |
| 3898 | if (isIntRegForSubInst(SrcReg) && MI->getOperand(2).isImm() && |
| 3899 | ((MI->getOperand(2).getImm() == 1) || |
| 3900 | (MI->getOperand(2).getImm() == -1))) |
| 3901 | return HexagonII::HSIG_A; |
| 3902 | } |
| 3903 | break; |
| 3904 | case Hexagon::A2_add: |
| 3905 | // Rx = add(Rx,Rs) |
| 3906 | DstReg = MI->getOperand(0).getReg(); |
| 3907 | Src1Reg = MI->getOperand(1).getReg(); |
| 3908 | Src2Reg = MI->getOperand(2).getReg(); |
| 3909 | if (isIntRegForSubInst(DstReg) && (DstReg == Src1Reg) && |
| 3910 | isIntRegForSubInst(Src2Reg)) |
| 3911 | return HexagonII::HSIG_A; |
| 3912 | break; |
| 3913 | case Hexagon::A2_andir: |
| 3914 | // Same as zxtb. |
| 3915 | // Rd16=and(Rs16,#255) |
| 3916 | // Rd16=and(Rs16,#1) |
| 3917 | DstReg = MI->getOperand(0).getReg(); |
| 3918 | SrcReg = MI->getOperand(1).getReg(); |
| 3919 | if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) && |
| 3920 | MI->getOperand(2).isImm() && |
| 3921 | ((MI->getOperand(2).getImm() == 1) || |
| 3922 | (MI->getOperand(2).getImm() == 255))) |
| 3923 | return HexagonII::HSIG_A; |
| 3924 | break; |
| 3925 | case Hexagon::A2_tfr: |
| 3926 | // Rd = Rs |
| 3927 | DstReg = MI->getOperand(0).getReg(); |
| 3928 | SrcReg = MI->getOperand(1).getReg(); |
| 3929 | if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg)) |
| 3930 | return HexagonII::HSIG_A; |
| 3931 | break; |
| 3932 | case Hexagon::A2_tfrsi: |
| 3933 | // Rd = #u6 |
| 3934 | // Do not test for #u6 size since the const is getting extended |
| 3935 | // regardless and compound could be formed. |
| 3936 | // Rd = #-1 |
| 3937 | DstReg = MI->getOperand(0).getReg(); |
| 3938 | if (isIntRegForSubInst(DstReg)) |
| 3939 | return HexagonII::HSIG_A; |
| 3940 | break; |
| 3941 | case Hexagon::C2_cmoveit: |
| 3942 | case Hexagon::C2_cmovenewit: |
| 3943 | case Hexagon::C2_cmoveif: |
| 3944 | case Hexagon::C2_cmovenewif: |
| 3945 | // if ([!]P0[.new]) Rd = #0 |
| 3946 | // Actual form: |
| 3947 | // %R16<def> = C2_cmovenewit %P0<internal>, 0, %R16<imp-use,undef>; |
| 3948 | DstReg = MI->getOperand(0).getReg(); |
| 3949 | SrcReg = MI->getOperand(1).getReg(); |
| 3950 | if (isIntRegForSubInst(DstReg) && |
| 3951 | Hexagon::PredRegsRegClass.contains(SrcReg) && Hexagon::P0 == SrcReg && |
| 3952 | MI->getOperand(2).isImm() && MI->getOperand(2).getImm() == 0) |
| 3953 | return HexagonII::HSIG_A; |
| 3954 | break; |
| 3955 | case Hexagon::C2_cmpeqi: |
| 3956 | // P0 = cmp.eq(Rs,#u2) |
| 3957 | DstReg = MI->getOperand(0).getReg(); |
| 3958 | SrcReg = MI->getOperand(1).getReg(); |
| 3959 | if (Hexagon::PredRegsRegClass.contains(DstReg) && |
| 3960 | Hexagon::P0 == DstReg && isIntRegForSubInst(SrcReg) && |
| 3961 | MI->getOperand(2).isImm() && isUInt<2>(MI->getOperand(2).getImm())) |
| 3962 | return HexagonII::HSIG_A; |
| 3963 | break; |
| 3964 | case Hexagon::A2_combineii: |
| 3965 | case Hexagon::A4_combineii: |
| 3966 | // Rdd = combine(#u2,#U2) |
| 3967 | DstReg = MI->getOperand(0).getReg(); |
| 3968 | if (isDblRegForSubInst(DstReg, HRI) && |
| 3969 | ((MI->getOperand(1).isImm() && isUInt<2>(MI->getOperand(1).getImm())) || |
| 3970 | (MI->getOperand(1).isGlobal() && |
| 3971 | isUInt<2>(MI->getOperand(1).getOffset()))) && |
| 3972 | ((MI->getOperand(2).isImm() && isUInt<2>(MI->getOperand(2).getImm())) || |
| 3973 | (MI->getOperand(2).isGlobal() && |
| 3974 | isUInt<2>(MI->getOperand(2).getOffset())))) |
| 3975 | return HexagonII::HSIG_A; |
| 3976 | break; |
| 3977 | case Hexagon::A4_combineri: |
| 3978 | // Rdd = combine(Rs,#0) |
| 3979 | DstReg = MI->getOperand(0).getReg(); |
| 3980 | SrcReg = MI->getOperand(1).getReg(); |
| 3981 | if (isDblRegForSubInst(DstReg, HRI) && isIntRegForSubInst(SrcReg) && |
| 3982 | ((MI->getOperand(2).isImm() && MI->getOperand(2).getImm() == 0) || |
| 3983 | (MI->getOperand(2).isGlobal() && MI->getOperand(2).getOffset() == 0))) |
| 3984 | return HexagonII::HSIG_A; |
| 3985 | break; |
| 3986 | case Hexagon::A4_combineir: |
| 3987 | // Rdd = combine(#0,Rs) |
| 3988 | DstReg = MI->getOperand(0).getReg(); |
| 3989 | SrcReg = MI->getOperand(2).getReg(); |
| 3990 | if (isDblRegForSubInst(DstReg, HRI) && isIntRegForSubInst(SrcReg) && |
| 3991 | ((MI->getOperand(1).isImm() && MI->getOperand(1).getImm() == 0) || |
| 3992 | (MI->getOperand(1).isGlobal() && MI->getOperand(1).getOffset() == 0))) |
| 3993 | return HexagonII::HSIG_A; |
| 3994 | break; |
| 3995 | case Hexagon::A2_sxtb: |
| 3996 | case Hexagon::A2_sxth: |
| 3997 | case Hexagon::A2_zxtb: |
| 3998 | case Hexagon::A2_zxth: |
| 3999 | // Rd = sxth/sxtb/zxtb/zxth(Rs) |
| 4000 | DstReg = MI->getOperand(0).getReg(); |
| 4001 | SrcReg = MI->getOperand(1).getReg(); |
| 4002 | if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg)) |
| 4003 | return HexagonII::HSIG_A; |
| 4004 | break; |
| 4005 | } |
| 4006 | |
| 4007 | return HexagonII::HSIG_None; |
| 4008 | } |
| 4009 | |
| 4010 | |
Krzysztof Parzyszek | 5e6f2bd | 2015-12-14 21:32:25 +0000 | [diff] [blame] | 4011 | short HexagonInstrInfo::getEquivalentHWInstr(const MachineInstr *MI) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4012 | return Hexagon::getRealHWInstr(MI->getOpcode(), Hexagon::InstrType_Real); |
| 4013 | } |
| 4014 | |
| 4015 | |
| 4016 | // Return first non-debug instruction in the basic block. |
| 4017 | MachineInstr *HexagonInstrInfo::getFirstNonDbgInst(MachineBasicBlock *BB) |
| 4018 | const { |
| 4019 | for (auto MII = BB->instr_begin(), End = BB->instr_end(); MII != End; MII++) { |
| 4020 | MachineInstr *MI = &*MII; |
| 4021 | if (MI->isDebugValue()) |
| 4022 | continue; |
| 4023 | return MI; |
| 4024 | } |
| 4025 | return nullptr; |
| 4026 | } |
| 4027 | |
| 4028 | |
| 4029 | unsigned HexagonInstrInfo::getInstrTimingClassLatency( |
| 4030 | const InstrItineraryData *ItinData, const MachineInstr *MI) const { |
| 4031 | // Default to one cycle for no itinerary. However, an "empty" itinerary may |
| 4032 | // still have a MinLatency property, which getStageLatency checks. |
| 4033 | if (!ItinData) |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 4034 | return getInstrLatency(ItinData, *MI); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4035 | |
| 4036 | // Get the latency embedded in the itinerary. If we're not using timing class |
| 4037 | // latencies or if we using BSB scheduling, then restrict the maximum latency |
| 4038 | // to 1 (that is, either 0 or 1). |
| 4039 | if (MI->isTransient()) |
| 4040 | return 0; |
| 4041 | unsigned Latency = ItinData->getStageLatency(MI->getDesc().getSchedClass()); |
| 4042 | if (!EnableTimingClassLatency || |
| 4043 | MI->getParent()->getParent()->getSubtarget<HexagonSubtarget>(). |
| 4044 | useBSBScheduling()) |
| 4045 | if (Latency > 1) |
| 4046 | Latency = 1; |
| 4047 | return Latency; |
| 4048 | } |
| 4049 | |
| 4050 | |
| 4051 | // inverts the predication logic. |
| 4052 | // p -> NotP |
| 4053 | // NotP -> P |
| 4054 | bool HexagonInstrInfo::getInvertedPredSense( |
| 4055 | SmallVectorImpl<MachineOperand> &Cond) const { |
| 4056 | if (Cond.empty()) |
| 4057 | return false; |
| 4058 | unsigned Opc = getInvertedPredicatedOpcode(Cond[0].getImm()); |
| 4059 | Cond[0].setImm(Opc); |
| 4060 | return true; |
| 4061 | } |
| 4062 | |
| 4063 | |
| 4064 | unsigned HexagonInstrInfo::getInvertedPredicatedOpcode(const int Opc) const { |
| 4065 | int InvPredOpcode; |
| 4066 | InvPredOpcode = isPredicatedTrue(Opc) ? Hexagon::getFalsePredOpcode(Opc) |
| 4067 | : Hexagon::getTruePredOpcode(Opc); |
| 4068 | if (InvPredOpcode >= 0) // Valid instruction with the inverted predicate. |
| 4069 | return InvPredOpcode; |
| 4070 | |
| 4071 | llvm_unreachable("Unexpected predicated instruction"); |
| 4072 | } |
| 4073 | |
| 4074 | |
| 4075 | // Returns the max value that doesn't need to be extended. |
| 4076 | int HexagonInstrInfo::getMaxValue(const MachineInstr *MI) const { |
| 4077 | const uint64_t F = MI->getDesc().TSFlags; |
| 4078 | unsigned isSigned = (F >> HexagonII::ExtentSignedPos) |
| 4079 | & HexagonII::ExtentSignedMask; |
| 4080 | unsigned bits = (F >> HexagonII::ExtentBitsPos) |
| 4081 | & HexagonII::ExtentBitsMask; |
| 4082 | |
| 4083 | if (isSigned) // if value is signed |
| 4084 | return ~(-1U << (bits - 1)); |
| 4085 | else |
| 4086 | return ~(-1U << bits); |
| 4087 | } |
| 4088 | |
| 4089 | |
| 4090 | unsigned HexagonInstrInfo::getMemAccessSize(const MachineInstr* MI) const { |
| 4091 | const uint64_t F = MI->getDesc().TSFlags; |
| 4092 | return (F >> HexagonII::MemAccessSizePos) & HexagonII::MemAccesSizeMask; |
| 4093 | } |
| 4094 | |
| 4095 | |
| 4096 | // Returns the min value that doesn't need to be extended. |
| 4097 | int HexagonInstrInfo::getMinValue(const MachineInstr *MI) const { |
| 4098 | const uint64_t F = MI->getDesc().TSFlags; |
| 4099 | unsigned isSigned = (F >> HexagonII::ExtentSignedPos) |
| 4100 | & HexagonII::ExtentSignedMask; |
| 4101 | unsigned bits = (F >> HexagonII::ExtentBitsPos) |
| 4102 | & HexagonII::ExtentBitsMask; |
| 4103 | |
| 4104 | if (isSigned) // if value is signed |
| 4105 | return -1U << (bits - 1); |
| 4106 | else |
| 4107 | return 0; |
| 4108 | } |
| 4109 | |
| 4110 | |
| 4111 | // Returns opcode of the non-extended equivalent instruction. |
| 4112 | short HexagonInstrInfo::getNonExtOpcode(const MachineInstr *MI) const { |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 4113 | // Check if the instruction has a register form that uses register in place |
| 4114 | // of the extended operand, if so return that as the non-extended form. |
| 4115 | short NonExtOpcode = Hexagon::getRegForm(MI->getOpcode()); |
| 4116 | if (NonExtOpcode >= 0) |
| 4117 | return NonExtOpcode; |
| 4118 | |
| 4119 | if (MI->getDesc().mayLoad() || MI->getDesc().mayStore()) { |
Alp Toker | cb40291 | 2014-01-24 17:20:08 +0000 | [diff] [blame] | 4120 | // Check addressing mode and retrieve non-ext equivalent instruction. |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 4121 | switch (getAddrMode(MI)) { |
| 4122 | case HexagonII::Absolute : |
Krzysztof Parzyszek | 0257905 | 2015-10-20 19:21:05 +0000 | [diff] [blame] | 4123 | return Hexagon::getBaseWithImmOffset(MI->getOpcode()); |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 4124 | case HexagonII::BaseImmOffset : |
| 4125 | return Hexagon::getBaseWithRegOffset(MI->getOpcode()); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4126 | case HexagonII::BaseLongOffset: |
| 4127 | return Hexagon::getRegShlForm(MI->getOpcode()); |
| 4128 | |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 4129 | default: |
| 4130 | return -1; |
| 4131 | } |
| 4132 | } |
| 4133 | return -1; |
| 4134 | } |
Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 4135 | |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 4136 | |
Ahmed Bougacha | c88bf54 | 2015-06-11 19:30:37 +0000 | [diff] [blame] | 4137 | bool HexagonInstrInfo::getPredReg(ArrayRef<MachineOperand> Cond, |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4138 | unsigned &PredReg, unsigned &PredRegPos, unsigned &PredRegFlags) const { |
Brendon Cahoon | df43e68 | 2015-05-08 16:16:29 +0000 | [diff] [blame] | 4139 | if (Cond.empty()) |
| 4140 | return false; |
| 4141 | assert(Cond.size() == 2); |
| 4142 | if (isNewValueJump(Cond[0].getImm()) || Cond[1].isMBB()) { |
| 4143 | DEBUG(dbgs() << "No predregs for new-value jumps/endloop"); |
| 4144 | return false; |
| 4145 | } |
| 4146 | PredReg = Cond[1].getReg(); |
| 4147 | PredRegPos = 1; |
| 4148 | // See IfConversion.cpp why we add RegState::Implicit | RegState::Undef |
| 4149 | PredRegFlags = 0; |
| 4150 | if (Cond[1].isImplicit()) |
| 4151 | PredRegFlags = RegState::Implicit; |
| 4152 | if (Cond[1].isUndef()) |
| 4153 | PredRegFlags |= RegState::Undef; |
| 4154 | return true; |
| 4155 | } |
| 4156 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4157 | |
Krzysztof Parzyszek | 5e6f2bd | 2015-12-14 21:32:25 +0000 | [diff] [blame] | 4158 | short HexagonInstrInfo::getPseudoInstrPair(const MachineInstr *MI) const { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4159 | return Hexagon::getRealHWInstr(MI->getOpcode(), Hexagon::InstrType_Pseudo); |
| 4160 | } |
| 4161 | |
| 4162 | |
| 4163 | short HexagonInstrInfo::getRegForm(const MachineInstr *MI) const { |
| 4164 | return Hexagon::getRegForm(MI->getOpcode()); |
| 4165 | } |
| 4166 | |
| 4167 | |
| 4168 | // Return the number of bytes required to encode the instruction. |
| 4169 | // Hexagon instructions are fixed length, 4 bytes, unless they |
| 4170 | // use a constant extender, which requires another 4 bytes. |
| 4171 | // For debug instructions and prolog labels, return 0. |
| 4172 | unsigned HexagonInstrInfo::getSize(const MachineInstr *MI) const { |
| 4173 | if (MI->isDebugValue() || MI->isPosition()) |
| 4174 | return 0; |
| 4175 | |
| 4176 | unsigned Size = MI->getDesc().getSize(); |
| 4177 | if (!Size) |
| 4178 | // Assume the default insn size in case it cannot be determined |
| 4179 | // for whatever reason. |
| 4180 | Size = HEXAGON_INSTR_SIZE; |
| 4181 | |
| 4182 | if (isConstExtended(MI) || isExtended(MI)) |
| 4183 | Size += HEXAGON_INSTR_SIZE; |
| 4184 | |
| 4185 | // Try and compute number of instructions in asm. |
| 4186 | if (BranchRelaxAsmLarge && MI->getOpcode() == Hexagon::INLINEASM) { |
| 4187 | const MachineBasicBlock &MBB = *MI->getParent(); |
| 4188 | const MachineFunction *MF = MBB.getParent(); |
| 4189 | const MCAsmInfo *MAI = MF->getTarget().getMCAsmInfo(); |
| 4190 | |
| 4191 | // Count the number of register definitions to find the asm string. |
| 4192 | unsigned NumDefs = 0; |
| 4193 | for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef(); |
| 4194 | ++NumDefs) |
| 4195 | assert(NumDefs != MI->getNumOperands()-2 && "No asm string?"); |
| 4196 | |
| 4197 | assert(MI->getOperand(NumDefs).isSymbol() && "No asm string?"); |
| 4198 | // Disassemble the AsmStr and approximate number of instructions. |
| 4199 | const char *AsmStr = MI->getOperand(NumDefs).getSymbolName(); |
| 4200 | Size = getInlineAsmLength(AsmStr, *MAI); |
| 4201 | } |
| 4202 | |
| 4203 | return Size; |
| 4204 | } |
| 4205 | |
| 4206 | |
| 4207 | uint64_t HexagonInstrInfo::getType(const MachineInstr* MI) const { |
| 4208 | const uint64_t F = MI->getDesc().TSFlags; |
| 4209 | return (F >> HexagonII::TypePos) & HexagonII::TypeMask; |
| 4210 | } |
| 4211 | |
| 4212 | |
| 4213 | unsigned HexagonInstrInfo::getUnits(const MachineInstr* MI) const { |
| 4214 | const TargetSubtargetInfo &ST = MI->getParent()->getParent()->getSubtarget(); |
| 4215 | const InstrItineraryData &II = *ST.getInstrItineraryData(); |
| 4216 | const InstrStage &IS = *II.beginStage(MI->getDesc().getSchedClass()); |
| 4217 | |
| 4218 | return IS.getUnits(); |
| 4219 | } |
| 4220 | |
| 4221 | |
| 4222 | unsigned HexagonInstrInfo::getValidSubTargets(const unsigned Opcode) const { |
| 4223 | const uint64_t F = get(Opcode).TSFlags; |
| 4224 | return (F >> HexagonII::validSubTargetPos) & HexagonII::validSubTargetMask; |
| 4225 | } |
| 4226 | |
| 4227 | |
| 4228 | // Calculate size of the basic block without debug instructions. |
| 4229 | unsigned HexagonInstrInfo::nonDbgBBSize(const MachineBasicBlock *BB) const { |
| 4230 | return nonDbgMICount(BB->instr_begin(), BB->instr_end()); |
| 4231 | } |
| 4232 | |
| 4233 | |
| 4234 | unsigned HexagonInstrInfo::nonDbgBundleSize( |
| 4235 | MachineBasicBlock::const_iterator BundleHead) const { |
| 4236 | assert(BundleHead->isBundle() && "Not a bundle header"); |
Duncan P. N. Exon Smith | d84f600 | 2016-02-22 21:30:15 +0000 | [diff] [blame] | 4237 | auto MII = BundleHead.getInstrIterator(); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4238 | // Skip the bundle header. |
Duncan P. N. Exon Smith | f9ab416 | 2016-02-27 17:05:33 +0000 | [diff] [blame] | 4239 | return nonDbgMICount(++MII, getBundleEnd(*BundleHead)); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4240 | } |
| 4241 | |
| 4242 | |
| 4243 | /// immediateExtend - Changes the instruction in place to one using an immediate |
| 4244 | /// extender. |
| 4245 | void HexagonInstrInfo::immediateExtend(MachineInstr *MI) const { |
| 4246 | assert((isExtendable(MI)||isConstExtended(MI)) && |
| 4247 | "Instruction must be extendable"); |
| 4248 | // Find which operand is extendable. |
| 4249 | short ExtOpNum = getCExtOpNum(MI); |
| 4250 | MachineOperand &MO = MI->getOperand(ExtOpNum); |
| 4251 | // This needs to be something we understand. |
| 4252 | assert((MO.isMBB() || MO.isImm()) && |
| 4253 | "Branch with unknown extendable field type"); |
| 4254 | // Mark given operand as extended. |
| 4255 | MO.addTargetFlag(HexagonII::HMOTF_ConstExtended); |
| 4256 | } |
| 4257 | |
| 4258 | |
| 4259 | bool HexagonInstrInfo::invertAndChangeJumpTarget( |
| 4260 | MachineInstr* MI, MachineBasicBlock* NewTarget) const { |
| 4261 | DEBUG(dbgs() << "\n[invertAndChangeJumpTarget] to BB#" |
| 4262 | << NewTarget->getNumber(); MI->dump();); |
| 4263 | assert(MI->isBranch()); |
| 4264 | unsigned NewOpcode = getInvertedPredicatedOpcode(MI->getOpcode()); |
| 4265 | int TargetPos = MI->getNumOperands() - 1; |
| 4266 | // In general branch target is the last operand, |
| 4267 | // but some implicit defs added at the end might change it. |
| 4268 | while ((TargetPos > -1) && !MI->getOperand(TargetPos).isMBB()) |
| 4269 | --TargetPos; |
| 4270 | assert((TargetPos >= 0) && MI->getOperand(TargetPos).isMBB()); |
| 4271 | MI->getOperand(TargetPos).setMBB(NewTarget); |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 4272 | if (EnableBranchPrediction && isPredicatedNew(*MI)) { |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 4273 | NewOpcode = reversePrediction(NewOpcode); |
| 4274 | } |
| 4275 | MI->setDesc(get(NewOpcode)); |
| 4276 | return true; |
| 4277 | } |
| 4278 | |
| 4279 | |
| 4280 | void HexagonInstrInfo::genAllInsnTimingClasses(MachineFunction &MF) const { |
| 4281 | /* +++ The code below is used to generate complete set of Hexagon Insn +++ */ |
| 4282 | MachineFunction::iterator A = MF.begin(); |
| 4283 | MachineBasicBlock &B = *A; |
| 4284 | MachineBasicBlock::iterator I = B.begin(); |
| 4285 | MachineInstr *MI = &*I; |
| 4286 | DebugLoc DL = MI->getDebugLoc(); |
| 4287 | MachineInstr *NewMI; |
| 4288 | |
| 4289 | for (unsigned insn = TargetOpcode::GENERIC_OP_END+1; |
| 4290 | insn < Hexagon::INSTRUCTION_LIST_END; ++insn) { |
| 4291 | NewMI = BuildMI(B, MI, DL, get(insn)); |
| 4292 | DEBUG(dbgs() << "\n" << getName(NewMI->getOpcode()) << |
| 4293 | " Class: " << NewMI->getDesc().getSchedClass()); |
| 4294 | NewMI->eraseFromParent(); |
| 4295 | } |
| 4296 | /* --- The code above is used to generate complete set of Hexagon Insn --- */ |
| 4297 | } |
| 4298 | |
| 4299 | |
| 4300 | // inverts the predication logic. |
| 4301 | // p -> NotP |
| 4302 | // NotP -> P |
| 4303 | bool HexagonInstrInfo::reversePredSense(MachineInstr* MI) const { |
| 4304 | DEBUG(dbgs() << "\nTrying to reverse pred. sense of:"; MI->dump()); |
| 4305 | MI->setDesc(get(getInvertedPredicatedOpcode(MI->getOpcode()))); |
| 4306 | return true; |
| 4307 | } |
| 4308 | |
| 4309 | |
| 4310 | // Reverse the branch prediction. |
| 4311 | unsigned HexagonInstrInfo::reversePrediction(unsigned Opcode) const { |
| 4312 | int PredRevOpcode = -1; |
| 4313 | if (isPredictedTaken(Opcode)) |
| 4314 | PredRevOpcode = Hexagon::notTakenBranchPrediction(Opcode); |
| 4315 | else |
| 4316 | PredRevOpcode = Hexagon::takenBranchPrediction(Opcode); |
| 4317 | assert(PredRevOpcode > 0); |
| 4318 | return PredRevOpcode; |
| 4319 | } |
| 4320 | |
| 4321 | |
| 4322 | // TODO: Add more rigorous validation. |
| 4323 | bool HexagonInstrInfo::validateBranchCond(const ArrayRef<MachineOperand> &Cond) |
| 4324 | const { |
| 4325 | return Cond.empty() || (Cond[0].isImm() && (Cond.size() != 1)); |
| 4326 | } |
| 4327 | |
Krzysztof Parzyszek | f5cbac9 | 2016-04-29 15:49:13 +0000 | [diff] [blame] | 4328 | |
| 4329 | short HexagonInstrInfo::xformRegToImmOffset(const MachineInstr *MI) const { |
| 4330 | return Hexagon::xformRegToImmOffset(MI->getOpcode()); |
| 4331 | } |