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