blob: ee49a080435ef52c820bb6f21bca2548d1260d73 [file] [log] [blame]
Jia Liub22310f2012-02-18 12:03:15 +00001//===-- HexagonInstrInfo.cpp - Hexagon Instruction Information ------------===//
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002//
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 Zelenkob2ca1b32017-01-04 02:02:05 +000014#include "Hexagon.h"
Krzysztof Parzyszeke95e9552016-07-29 13:59:09 +000015#include "HexagonHazardRecognizer.h"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000016#include "HexagonInstrInfo.h"
Craig Topperb25fda92012-03-17 18:46:09 +000017#include "HexagonRegisterInfo.h"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000018#include "HexagonSubtarget.h"
Eugene Zelenkob2ca1b32017-01-04 02:02:05 +000019#include "llvm/ADT/SmallPtrSet.h"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000020#include "llvm/ADT/SmallVector.h"
Eugene Zelenkob2ca1b32017-01-04 02:02:05 +000021#include "llvm/ADT/StringRef.h"
Benjamin Kramerae87d7b2012-02-06 10:19:29 +000022#include "llvm/CodeGen/DFAPacketizer.h"
Ron Lieberman88159e52016-09-02 22:56:24 +000023#include "llvm/CodeGen/LivePhysRegs.h"
Eugene Zelenkob2ca1b32017-01-04 02:02:05 +000024#include "llvm/CodeGen/MachineBasicBlock.h"
25#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000026#include "llvm/CodeGen/MachineFrameInfo.h"
Eugene Zelenkob2ca1b32017-01-04 02:02:05 +000027#include "llvm/CodeGen/MachineFunction.h"
28#include "llvm/CodeGen/MachineInstr.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000029#include "llvm/CodeGen/MachineInstrBuilder.h"
Eugene Zelenkob2ca1b32017-01-04 02:02:05 +000030#include "llvm/CodeGen/MachineInstrBundle.h"
31#include "llvm/CodeGen/MachineLoopInfo.h"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000032#include "llvm/CodeGen/MachineMemOperand.h"
Eugene Zelenkob2ca1b32017-01-04 02:02:05 +000033#include "llvm/CodeGen/MachineOperand.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000034#include "llvm/CodeGen/MachineRegisterInfo.h"
Krzysztof Parzyszeke95e9552016-07-29 13:59:09 +000035#include "llvm/CodeGen/ScheduleDAG.h"
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +000036#include "llvm/MC/MCAsmInfo.h"
Eugene Zelenkob2ca1b32017-01-04 02:02:05 +000037#include "llvm/MC/MCInstrDesc.h"
38#include "llvm/MC/MCInstrItineraries.h"
39#include "llvm/MC/MCRegisterInfo.h"
40#include "llvm/Support/BranchProbability.h"
Krzysztof Parzyszekfeb65a32016-02-12 20:54:15 +000041#include "llvm/Support/CommandLine.h"
Jyotsna Verma5ed51812013-05-01 21:37:34 +000042#include "llvm/Support/Debug.h"
Eugene Zelenkob2ca1b32017-01-04 02:02:05 +000043#include "llvm/Support/ErrorHandling.h"
Benjamin Kramerae87d7b2012-02-06 10:19:29 +000044#include "llvm/Support/MathExtras.h"
Reid Kleckner1c76f1552013-05-03 00:54:56 +000045#include "llvm/Support/raw_ostream.h"
Eugene Zelenkob2ca1b32017-01-04 02:02:05 +000046#include "llvm/Target/TargetInstrInfo.h"
47#include "llvm/Target/TargetSubtargetInfo.h"
48#include <cassert>
Krzysztof Parzyszekaa935752015-11-24 15:11:13 +000049#include <cctype>
Eugene Zelenkob2ca1b32017-01-04 02:02:05 +000050#include <cstdint>
51#include <cstring>
52#include <iterator>
Tony Linthicum1213a7a2011-12-12 21:14:40 +000053
Tony Linthicum1213a7a2011-12-12 21:14:40 +000054using namespace llvm;
55
Chandler Carruthe96dd892014-04-21 22:55:11 +000056#define DEBUG_TYPE "hexagon-instrinfo"
57
Chandler Carruthd174b722014-04-22 02:03:14 +000058#define GET_INSTRINFO_CTOR_DTOR
59#define GET_INSTRMAP_INFO
60#include "HexagonGenInstrInfo.inc"
61#include "HexagonGenDFAPacketizer.inc"
62
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000063cl::opt<bool> ScheduleInlineAsm("hexagon-sched-inline-asm", cl::Hidden,
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +000064 cl::init(false), cl::desc("Do not consider inline-asm a scheduling/"
65 "packetization boundary."));
66
67static cl::opt<bool> EnableBranchPrediction("hexagon-enable-branch-prediction",
68 cl::Hidden, cl::init(true), cl::desc("Enable branch prediction"));
69
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000070static 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +000074static cl::opt<bool> EnableTimingClassLatency(
75 "enable-timing-class-latency", cl::Hidden, cl::init(false),
76 cl::desc("Enable timing class latency"));
77
78static cl::opt<bool> EnableALUForwarding(
79 "enable-alu-forwarding", cl::Hidden, cl::init(true),
80 cl::desc("Enable vec alu forwarding"));
81
82static cl::opt<bool> EnableACCForwarding(
83 "enable-acc-forwarding", cl::Hidden, cl::init(true),
84 cl::desc("Enable vec acc forwarding"));
85
86static cl::opt<bool> BranchRelaxAsmLarge("branch-relax-asm-large",
87 cl::init(true), cl::Hidden, cl::ZeroOrMore, cl::desc("branch relax asm"));
88
Krzysztof Parzyszeke95e9552016-07-29 13:59:09 +000089static 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 Linthicum1213a7a2011-12-12 21:14:40 +000093///
94/// Constants for Hexagon instructions.
95///
Krzysztof Parzyszek6bd42682016-05-05 21:58:02 +000096const int Hexagon_MEMV_OFFSET_MAX_128B = 896; // #s4: -8*128...7*128
97const int Hexagon_MEMV_OFFSET_MIN_128B = -1024; // #s4
98const int Hexagon_MEMV_OFFSET_MAX = 448; // #s4: -8*64...7*64
99const int Hexagon_MEMV_OFFSET_MIN = -512; // #s4
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000100const int Hexagon_MEMW_OFFSET_MAX = 4095;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000101const int Hexagon_MEMW_OFFSET_MIN = -4096;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000102const int Hexagon_MEMD_OFFSET_MAX = 8191;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000103const int Hexagon_MEMD_OFFSET_MIN = -8192;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000104const int Hexagon_MEMH_OFFSET_MAX = 2047;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000105const int Hexagon_MEMH_OFFSET_MIN = -2048;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000106const int Hexagon_MEMB_OFFSET_MAX = 1023;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000107const int Hexagon_MEMB_OFFSET_MIN = -1024;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000108const int Hexagon_ADDI_OFFSET_MAX = 32767;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000109const int Hexagon_ADDI_OFFSET_MIN = -32768;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000110const int Hexagon_MEMD_AUTOINC_MAX = 56;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000111const int Hexagon_MEMD_AUTOINC_MIN = -64;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000112const int Hexagon_MEMW_AUTOINC_MAX = 28;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000113const int Hexagon_MEMW_AUTOINC_MIN = -32;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000114const int Hexagon_MEMH_AUTOINC_MAX = 14;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000115const int Hexagon_MEMH_AUTOINC_MIN = -16;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000116const int Hexagon_MEMB_AUTOINC_MAX = 7;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000117const int Hexagon_MEMB_AUTOINC_MIN = -8;
Krzysztof Parzyszek6bd42682016-05-05 21:58:02 +0000118const int Hexagon_MEMV_AUTOINC_MAX = 192; // #s3
119const int Hexagon_MEMV_AUTOINC_MIN = -256; // #s3
120const int Hexagon_MEMV_AUTOINC_MAX_128B = 384; // #s3
121const int Hexagon_MEMV_AUTOINC_MIN_128B = -512; // #s3
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000122
Juergen Ributzkad12ccbd2013-11-19 00:57:56 +0000123// Pin the vtable to this file.
124void HexagonInstrInfo::anchor() {}
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000125
126HexagonInstrInfo::HexagonInstrInfo(HexagonSubtarget &ST)
Eric Christopherc4d31402015-03-10 23:45:55 +0000127 : HexagonGenInstrInfo(Hexagon::ADJCALLSTACKDOWN, Hexagon::ADJCALLSTACKUP),
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000128 RI() {}
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000129
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000130static bool isIntRegForSubInst(unsigned Reg) {
131 return (Reg >= Hexagon::R0 && Reg <= Hexagon::R7) ||
132 (Reg >= Hexagon::R16 && Reg <= Hexagon::R23);
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000133}
134
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000135static bool isDblRegForSubInst(unsigned Reg, const HexagonRegisterInfo &HRI) {
Krzysztof Parzyszeka5409972016-11-09 16:19:08 +0000136 return isIntRegForSubInst(HRI.getSubReg(Reg, Hexagon::isub_lo)) &&
137 isIntRegForSubInst(HRI.getSubReg(Reg, Hexagon::isub_hi));
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000138}
139
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000140/// Calculate number of instructions excluding the debug instructions.
141static 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +0000151/// 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 Parzyszekd67ab622017-02-02 19:36:37 +0000155static MachineInstr *findLoopInstr(MachineBasicBlock *BB, unsigned EndLoopOp,
156 MachineBasicBlock *TargetBB,
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000157 SmallPtrSet<MachineBasicBlock *, 8> &Visited) {
Krzysztof Parzyszekd67ab622017-02-02 19:36:37 +0000158 unsigned LOOPi;
159 unsigned LOOPr;
Brendon Cahoondf43e682015-05-08 16:16:29 +0000160 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 Linthicum1213a7a2011-12-12 21:14:40 +0000167
Brendon Cahoondf43e682015-05-08 16:16:29 +0000168 // The loop set-up instruction will be in a predecessor block
Krzysztof Parzyszekd67ab622017-02-02 19:36:37 +0000169 for (MachineBasicBlock *PB : BB->predecessors()) {
Brendon Cahoondf43e682015-05-08 16:16:29 +0000170 // If this has been visited, already skip it.
Krzysztof Parzyszekd67ab622017-02-02 19:36:37 +0000171 if (!Visited.insert(PB).second)
Brendon Cahoondf43e682015-05-08 16:16:29 +0000172 continue;
Krzysztof Parzyszekd67ab622017-02-02 19:36:37 +0000173 if (PB == BB)
Brendon Cahoondf43e682015-05-08 16:16:29 +0000174 continue;
Krzysztof Parzyszekd67ab622017-02-02 19:36:37 +0000175 for (auto I = PB->instr_rbegin(), E = PB->instr_rend(); I != E; ++I) {
176 unsigned Opc = I->getOpcode();
Brendon Cahoondf43e682015-05-08 16:16:29 +0000177 if (Opc == LOOPi || Opc == LOOPr)
178 return &*I;
Krzysztof Parzyszekd67ab622017-02-02 19:36:37 +0000179 // We've reached a different loop, which means the loop01 has been
180 // removed.
181 if (Opc == EndLoopOp && I->getOperand(0).getMBB() != TargetBB)
Eugene Zelenkob2ca1b32017-01-04 02:02:05 +0000182 return nullptr;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000183 }
Brendon Cahoondf43e682015-05-08 16:16:29 +0000184 // Check the predecessors for the LOOP instruction.
Krzysztof Parzyszekd67ab622017-02-02 19:36:37 +0000185 if (MachineInstr *Loop = findLoopInstr(PB, EndLoopOp, TargetBB, Visited))
186 return Loop;
Brendon Cahoondf43e682015-05-08 16:16:29 +0000187 }
Eugene Zelenkob2ca1b32017-01-04 02:02:05 +0000188 return nullptr;
Brendon Cahoondf43e682015-05-08 16:16:29 +0000189}
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000190
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000191/// Gather register def/uses from MI.
192/// This treats possible (predicated) defs as actually happening ones
193/// (conservatively).
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000194static inline void parseOperands(const MachineInstr &MI,
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000195 SmallVector<unsigned, 4> &Defs, SmallVector<unsigned, 8> &Uses) {
196 Defs.clear();
197 Uses.clear();
Brendon Cahoondf43e682015-05-08 16:16:29 +0000198
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000199 for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
200 const MachineOperand &MO = MI.getOperand(i);
Brendon Cahoondf43e682015-05-08 16:16:29 +0000201
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000202 if (!MO.isReg())
203 continue;
Brendon Cahoondf43e682015-05-08 16:16:29 +0000204
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000205 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +0000217// Position dependent, so check twice for swap.
218static 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +0000243/// 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 Smith9cfc75c2016-06-30 00:01:54 +0000248unsigned HexagonInstrInfo::isLoadFromStackSlot(const MachineInstr &MI,
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000249 int &FrameIndex) const {
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000250 switch (MI.getOpcode()) {
251 default:
252 break;
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000253 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 Parzyszek17aa4132016-08-16 15:43:54 +0000261 case Hexagon::PS_vloadrq_ai:
Krzysztof Parzyszekf2859632016-08-12 21:05:05 +0000262 case Hexagon::PS_vloadrw_ai:
Krzysztof Parzyszek17aa4132016-08-16 15:43:54 +0000263 case Hexagon::PS_vloadrq_ai_128B:
Krzysztof Parzyszekf2859632016-08-12 21:05:05 +0000264 case Hexagon::PS_vloadrw_ai_128B: {
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000265 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 Parzyszekfeb65a32016-02-12 20:54:15 +0000274
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000275 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 Cahoondf43e682015-05-08 16:16:29 +0000288 }
Krzysztof Parzyszekfeb65a32016-02-12 20:54:15 +0000289
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000290 return 0;
291}
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000292
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000293/// 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 Smith9cfc75c2016-06-30 00:01:54 +0000298unsigned HexagonInstrInfo::isStoreToStackSlot(const MachineInstr &MI,
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000299 int &FrameIndex) const {
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000300 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 Parzyszek17aa4132016-08-16 15:43:54 +0000313 case Hexagon::PS_vstorerq_ai:
Krzysztof Parzyszekf2859632016-08-12 21:05:05 +0000314 case Hexagon::PS_vstorerw_ai:
Krzysztof Parzyszek17aa4132016-08-16 15:43:54 +0000315 case Hexagon::PS_vstorerq_ai_128B:
Krzysztof Parzyszekf2859632016-08-12 21:05:05 +0000316 case Hexagon::PS_vstorerw_ai_128B: {
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000317 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 Parzyszekfeb65a32016-02-12 20:54:15 +0000326
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000327 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +0000344 }
Krzysztof Parzyszekfeb65a32016-02-12 20:54:15 +0000345
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000346 return 0;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000347}
348
Brendon Cahoondf43e682015-05-08 16:16:29 +0000349/// 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 Cahoondf43e682015-05-08 16:16:29 +0000364///
Jacques Pienaar71c30a12016-07-15 14:41:04 +0000365bool HexagonInstrInfo::analyzeBranch(MachineBasicBlock &MBB,
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000366 MachineBasicBlock *&TBB,
Brendon Cahoondf43e682015-05-08 16:16:29 +0000367 MachineBasicBlock *&FBB,
368 SmallVectorImpl<MachineOperand> &Cond,
369 bool AllowModify) const {
Craig Topper062a2ba2014-04-25 05:30:21 +0000370 TBB = nullptr;
371 FBB = nullptr;
Brendon Cahoondf43e682015-05-08 16:16:29 +0000372 Cond.clear();
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000373
374 // If the block has no terminators, it just falls into the block after it.
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000375 MachineBasicBlock::instr_iterator I = MBB.instr_end();
376 if (I == MBB.instr_begin())
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000377 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 Cahoondf43e682015-05-08 16:16:29 +0000394 // Don't analyze EH branches.
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000395 return true;
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000396 } while (I != MBB.instr_begin());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000397
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000398 I = MBB.instr_end();
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000399 --I;
400
401 while (I->isDebugValue()) {
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000402 if (I == MBB.instr_begin())
403 return false;
404 --I;
405 }
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000406
Colin LeMahieu7b1799c2015-03-09 22:05:21 +0000407 bool JumpToBlock = I->getOpcode() == Hexagon::J2_jump &&
408 I->getOperand(0).isMBB();
Brendon Cahoondf43e682015-05-08 16:16:29 +0000409 // Delete the J2_jump if it's equivalent to a fall-through.
Colin LeMahieu7b1799c2015-03-09 22:05:21 +0000410 if (AllowModify && JumpToBlock &&
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000411 MBB.isLayoutSuccessor(I->getOperand(0).getMBB())) {
Eugene Zelenkob2ca1b32017-01-04 02:02:05 +0000412 DEBUG(dbgs() << "\nErasing the jump to successor block\n";);
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000413 I->eraseFromParent();
414 I = MBB.instr_end();
415 if (I == MBB.instr_begin())
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000416 return false;
417 --I;
418 }
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000419 if (!isUnpredicatedTerminator(*I))
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000420 return false;
421
422 // Get the last instruction in the block.
Duncan P. N. Exon Smitha72c6e22015-10-20 00:46:39 +0000423 MachineInstr *LastInst = &*I;
Craig Topper062a2ba2014-04-25 05:30:21 +0000424 MachineInstr *SecondLastInst = nullptr;
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000425 // Find one more terminator if present.
Eugene Zelenkob2ca1b32017-01-04 02:02:05 +0000426 while (true) {
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000427 if (&*I != LastInst && !I->isBundle() && isUnpredicatedTerminator(*I)) {
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000428 if (!SecondLastInst)
Duncan P. N. Exon Smitha72c6e22015-10-20 00:46:39 +0000429 SecondLastInst = &*I;
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000430 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 Smitha72c6e22015-10-20 00:46:39 +0000437 }
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000438
439 int LastOpcode = LastInst->getOpcode();
Colin LeMahieu7b1799c2015-03-09 22:05:21 +0000440 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 Verma5ed51812013-05-01 21:37:34 +0000448
449 bool LastOpcodeHasJMP_c = PredOpcodeHasJMP_c(LastOpcode);
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000450 bool LastOpcodeHasNVJump = isNewValueJump(*LastInst);
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000451
Krzysztof Parzyszekb28ae102016-01-14 15:05:27 +0000452 if (LastOpcodeHasJMP_c && !LastInst->getOperand(1).isMBB())
453 return true;
454
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000455 // If there is only one terminator instruction, process it.
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000456 if (LastInst && !SecondLastInst) {
Colin LeMahieudb0b13c2014-12-10 21:24:10 +0000457 if (LastOpcode == Hexagon::J2_jump) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000458 TBB = LastInst->getOperand(0).getMBB();
459 return false;
460 }
Brendon Cahoondf43e682015-05-08 16:16:29 +0000461 if (isEndLoopN(LastOpcode)) {
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000462 TBB = LastInst->getOperand(0).getMBB();
Brendon Cahoondf43e682015-05-08 16:16:29 +0000463 Cond.push_back(MachineOperand::CreateImm(LastInst->getOpcode()));
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000464 Cond.push_back(LastInst->getOperand(0));
465 return false;
466 }
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000467 if (LastOpcodeHasJMP_c) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000468 TBB = LastInst->getOperand(1).getMBB();
Brendon Cahoondf43e682015-05-08 16:16:29 +0000469 Cond.push_back(MachineOperand::CreateImm(LastInst->getOpcode()));
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000470 Cond.push_back(LastInst->getOperand(0));
471 return false;
472 }
Brendon Cahoondf43e682015-05-08 16:16:29 +0000473 // 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 Linthicum1213a7a2011-12-12 21:14:40 +0000483 // Otherwise, don't know what this is.
484 return true;
485 }
486
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000487 bool SecLastOpcodeHasJMP_c = PredOpcodeHasJMP_c(SecLastOpcode);
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000488 bool SecLastOpcodeHasNVJump = isNewValueJump(*SecondLastInst);
Colin LeMahieudb0b13c2014-12-10 21:24:10 +0000489 if (SecLastOpcodeHasJMP_c && (LastOpcode == Hexagon::J2_jump)) {
Krzysztof Parzyszekb28ae102016-01-14 15:05:27 +0000490 if (!SecondLastInst->getOperand(1).isMBB())
491 return true;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000492 TBB = SecondLastInst->getOperand(1).getMBB();
Brendon Cahoondf43e682015-05-08 16:16:29 +0000493 Cond.push_back(MachineOperand::CreateImm(SecondLastInst->getOpcode()));
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000494 Cond.push_back(SecondLastInst->getOperand(0));
495 FBB = LastInst->getOperand(0).getMBB();
496 return false;
497 }
498
Brendon Cahoondf43e682015-05-08 16:16:29 +0000499 // 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 Linthicum1213a7a2011-12-12 21:14:40 +0000511 // If the block ends with two Hexagon:JMPs, handle it. The second one is not
512 // executed, so remove it.
Colin LeMahieudb0b13c2014-12-10 21:24:10 +0000513 if (SecLastOpcode == Hexagon::J2_jump && LastOpcode == Hexagon::J2_jump) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000514 TBB = SecondLastInst->getOperand(0).getMBB();
Duncan P. N. Exon Smithc5b668d2016-02-22 20:49:58 +0000515 I = LastInst->getIterator();
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000516 if (AllowModify)
517 I->eraseFromParent();
518 return false;
519 }
520
Brendon Cahoondf43e682015-05-08 16:16:29 +0000521 // If the block ends with an ENDLOOP, and J2_jump, handle it.
522 if (isEndLoopN(SecLastOpcode) && LastOpcode == Hexagon::J2_jump) {
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000523 TBB = SecondLastInst->getOperand(0).getMBB();
Brendon Cahoondf43e682015-05-08 16:16:29 +0000524 Cond.push_back(MachineOperand::CreateImm(SecondLastInst->getOpcode()));
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000525 Cond.push_back(SecondLastInst->getOperand(0));
526 FBB = LastInst->getOperand(0).getMBB();
527 return false;
528 }
Brendon Cahoondf43e682015-05-08 16:16:29 +0000529 DEBUG(dbgs() << "\nCant analyze BB#" << MBB.getNumber()
530 << " with two jumps";);
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000531 // Otherwise, can't handle this.
532 return true;
533}
534
Matt Arsenault1b9fc8e2016-09-14 20:43:16 +0000535unsigned HexagonInstrInfo::removeBranch(MachineBasicBlock &MBB,
Matt Arsenaulta2b036e2016-09-14 17:23:48 +0000536 int *BytesRemoved) const {
537 assert(!BytesRemoved && "code size not handled");
538
Brendon Cahoondf43e682015-05-08 16:16:29 +0000539 DEBUG(dbgs() << "\nRemoving branches out of BB#" << MBB.getNumber());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000540 MachineBasicBlock::iterator I = MBB.end();
Brendon Cahoondf43e682015-05-08 16:16:29 +0000541 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 Parzyszek78cc36f2015-03-18 15:56:43 +0000554 }
Brendon Cahoondf43e682015-05-08 16:16:29 +0000555 return Count;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000556}
557
Matt Arsenaulte8e0f5c2016-09-14 17:24:15 +0000558unsigned HexagonInstrInfo::insertBranch(MachineBasicBlock &MBB,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000559 MachineBasicBlock *TBB,
560 MachineBasicBlock *FBB,
561 ArrayRef<MachineOperand> Cond,
Matt Arsenaulta2b036e2016-09-14 17:23:48 +0000562 const DebugLoc &DL,
563 int *BytesAdded) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000564 unsigned BOpc = Hexagon::J2_jump;
565 unsigned BccOpc = Hexagon::J2_jumpt;
566 assert(validateBranchCond(Cond) && "Invalid branching condition");
Matt Arsenaulte8e0f5c2016-09-14 17:24:15 +0000567 assert(TBB && "insertBranch must not be told to insert a fallthrough");
Matt Arsenaulta2b036e2016-09-14 17:23:48 +0000568 assert(!BytesAdded && "code size not handled");
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000569
Matt Arsenault1b9fc8e2016-09-14 20:43:16 +0000570 // Check if reverseBranchCondition has asked to reverse this branch
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000571 // 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 Smith25b132e2016-07-08 18:26:20 +0000584 auto Term = MBB.getFirstTerminator();
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000585 if (Term != MBB.end() && isPredicated(*Term) &&
Duncan P. N. Exon Smithe04fe1a2016-08-17 00:34:00 +0000586 !analyzeBranch(MBB, NewTBB, NewFBB, Cond, false) &&
587 MachineFunction::iterator(NewTBB) == ++MBB.getIterator()) {
Matt Arsenault1b9fc8e2016-09-14 20:43:16 +0000588 reverseBranchCondition(Cond);
589 removeBranch(MBB);
Matt Arsenaulte8e0f5c2016-09-14 17:24:15 +0000590 return insertBranch(MBB, TBB, nullptr, Cond, DL);
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000591 }
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 Parzyszekd67ab622017-02-02 19:36:37 +0000599 MachineInstr *Loop = findLoopInstr(TBB, EndLoopOp, Cond[1].getMBB(),
600 VisitedBBs);
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000601 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 Parzyszekcfe285e2013-02-11 20:04:29 +0000628 }
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000629 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 Parzyszekd67ab622017-02-02 19:36:37 +0000640 MachineInstr *Loop = findLoopInstr(TBB, EndLoopOp, Cond[1].getMBB(),
641 VisitedBBs);
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000642 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 Parzyszekcfe285e2013-02-11 20:04:29 +0000650 }
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000651 BuildMI(&MBB, DL, get(BOpc)).addMBB(FBB);
Krzysztof Parzyszekcfe285e2013-02-11 20:04:29 +0000652
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000653 return 2;
654}
655
Brendon Cahoon254f8892016-07-29 16:44:44 +0000656/// 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.
661bool 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.
679unsigned HexagonInstrInfo::reduceLoopCount(MachineBasicBlock &MBB,
Krzysztof Parzyszek8fb181c2016-08-01 17:55:48 +0000680 MachineInstr *IndVar, MachineInstr &Cmp,
Brendon Cahoon254f8892016-07-29 16:44:44 +0000681 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 Parzyszek8fb181c2016-08-01 17:55:48 +0000686 assert((!IndVar) && isEndLoopN(Cmp.getOpcode())
Brendon Cahoon254f8892016-07-29 16:44:44 +0000687 && "Expecting a hardware loop");
688 MachineFunction *MF = MBB.getParent();
Krzysztof Parzyszek8fb181c2016-08-01 17:55:48 +0000689 DebugLoc DL = Cmp.getDebugLoc();
Brendon Cahoon254f8892016-07-29 16:44:44 +0000690 SmallPtrSet<MachineBasicBlock *, 8> VisitedBBs;
Krzysztof Parzyszekd67ab622017-02-02 19:36:37 +0000691 MachineInstr *Loop = findLoopInstr(&MBB, Cmp.getOpcode(),
692 Cmp.getOperand(0).getMBB(), VisitedBBs);
Brendon Cahoon254f8892016-07-29 16:44:44 +0000693 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +0000736
737bool HexagonInstrInfo::isProfitableToIfCvt(MachineBasicBlock &MBB,
738 unsigned NumCycles, unsigned ExtraPredCycles,
739 BranchProbability Probability) const {
740 return nonDbgBBSize(&MBB) <= 3;
741}
742
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000743bool 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +0000750bool HexagonInstrInfo::isProfitableToDupForIfCvt(MachineBasicBlock &MBB,
751 unsigned NumInstrs, BranchProbability Probability) const {
752 return NumInstrs <= 4;
Krzysztof Parzyszekcfe285e2013-02-11 20:04:29 +0000753}
754
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000755void HexagonInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000756 MachineBasicBlock::iterator I,
757 const DebugLoc &DL, unsigned DestReg,
758 unsigned SrcReg, bool KillSrc) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000759 auto &HRI = getRegisterInfo();
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000760 unsigned KillFlag = getKillRegState(KillSrc);
761
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000762 if (Hexagon::IntRegsRegClass.contains(SrcReg, DestReg)) {
Krzysztof Parzyszek3d6fc832016-06-02 14:33:08 +0000763 BuildMI(MBB, I, DL, get(Hexagon::A2_tfr), DestReg)
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000764 .addReg(SrcReg, KillFlag);
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000765 return;
766 }
767 if (Hexagon::DoubleRegsRegClass.contains(SrcReg, DestReg)) {
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000768 BuildMI(MBB, I, DL, get(Hexagon::A2_tfrp), DestReg)
769 .addReg(SrcReg, KillFlag);
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000770 return;
771 }
772 if (Hexagon::PredRegsRegClass.contains(SrcReg, DestReg)) {
773 // Map Pd = Ps to Pd = or(Ps, Ps).
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000774 BuildMI(MBB, I, DL, get(Hexagon::C2_or), DestReg)
775 .addReg(SrcReg).addReg(SrcReg, KillFlag);
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000776 return;
777 }
Colin LeMahieu402f7722014-12-19 18:56:10 +0000778 if (Hexagon::CtrRegsRegClass.contains(DestReg) &&
Sirish Pande8bb97452012-05-12 05:54:15 +0000779 Hexagon::IntRegsRegClass.contains(SrcReg)) {
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000780 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 Linthicum1213a7a2011-12-12 21:14:40 +0000794 return;
Sirish Pande30804c22012-02-15 18:52:27 +0000795 }
Anshuman Dasguptae96f8042013-02-13 22:56:34 +0000796 if (Hexagon::PredRegsRegClass.contains(SrcReg) &&
797 Hexagon::IntRegsRegClass.contains(DestReg)) {
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000798 BuildMI(MBB, I, DL, get(Hexagon::C2_tfrpr), DestReg)
799 .addReg(SrcReg, KillFlag);
Anshuman Dasguptae96f8042013-02-13 22:56:34 +0000800 return;
801 }
802 if (Hexagon::IntRegsRegClass.contains(SrcReg) &&
803 Hexagon::PredRegsRegClass.contains(DestReg)) {
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000804 BuildMI(MBB, I, DL, get(Hexagon::C2_tfrrp), DestReg)
805 .addReg(SrcReg, KillFlag);
Anshuman Dasguptae96f8042013-02-13 22:56:34 +0000806 return;
807 }
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000808 if (Hexagon::PredRegsRegClass.contains(SrcReg) &&
809 Hexagon::IntRegsRegClass.contains(DestReg)) {
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000810 BuildMI(MBB, I, DL, get(Hexagon::C2_tfrpr), DestReg)
811 .addReg(SrcReg, KillFlag);
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000812 return;
813 }
814 if (Hexagon::VectorRegsRegClass.contains(SrcReg, DestReg)) {
815 BuildMI(MBB, I, DL, get(Hexagon::V6_vassign), DestReg).
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000816 addReg(SrcReg, KillFlag);
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000817 return;
818 }
819 if (Hexagon::VecDblRegsRegClass.contains(SrcReg, DestReg)) {
Krzysztof Parzyszeka5409972016-11-09 16:19:08 +0000820 unsigned LoSrc = HRI.getSubReg(SrcReg, Hexagon::vsub_lo);
821 unsigned HiSrc = HRI.getSubReg(SrcReg, Hexagon::vsub_hi);
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000822 BuildMI(MBB, I, DL, get(Hexagon::V6_vcombine), DestReg)
Krzysztof Parzyszeka5409972016-11-09 16:19:08 +0000823 .addReg(HiSrc, KillFlag)
824 .addReg(LoSrc, KillFlag);
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000825 return;
826 }
827 if (Hexagon::VecPredRegsRegClass.contains(SrcReg, DestReg)) {
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000828 BuildMI(MBB, I, DL, get(Hexagon::V6_pred_and), DestReg)
829 .addReg(SrcReg)
830 .addReg(SrcReg, KillFlag);
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000831 return;
832 }
833 if (Hexagon::VecPredRegsRegClass.contains(SrcReg) &&
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000834 Hexagon::VectorRegsRegClass.contains(DestReg)) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000835 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 Parzyszeka5409972016-11-09 16:19:08 +0000844 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +0000852 return;
853 }
Sirish Pande30804c22012-02-15 18:52:27 +0000854
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000855#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 Pande30804c22012-02-15 18:52:27 +0000861 llvm_unreachable("Unimplemented");
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000862}
863
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000864void HexagonInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
865 MachineBasicBlock::iterator I, unsigned SrcReg, bool isKill, int FI,
866 const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000867 DebugLoc DL = MBB.findDebugLoc(I);
868 MachineFunction &MF = *MBB.getParent();
Matthias Braun941a7052016-07-28 18:40:00 +0000869 MachineFrameInfo &MFI = MF.getFrameInfo();
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000870 unsigned Align = MFI.getObjectAlignment(FI);
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000871 unsigned KillFlag = getKillRegState(isKill);
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000872
Alex Lorenze40c8a22015-08-11 23:09:45 +0000873 MachineMemOperand *MMO = MF.getMachineMemOperand(
874 MachinePointerInfo::getFixedStack(MF, FI), MachineMemOperand::MOStore,
875 MFI.getObjectSize(FI), Align);
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000876
Craig Topperc7242e02012-04-20 07:30:17 +0000877 if (Hexagon::IntRegsRegClass.hasSubClassEq(RC)) {
Colin LeMahieubda31b42014-12-29 20:44:51 +0000878 BuildMI(MBB, I, DL, get(Hexagon::S2_storeri_io))
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000879 .addFrameIndex(FI).addImm(0)
880 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
Craig Topperc7242e02012-04-20 07:30:17 +0000881 } else if (Hexagon::DoubleRegsRegClass.hasSubClassEq(RC)) {
Colin LeMahieubda31b42014-12-29 20:44:51 +0000882 BuildMI(MBB, I, DL, get(Hexagon::S2_storerd_io))
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000883 .addFrameIndex(FI).addImm(0)
884 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
Craig Topperc7242e02012-04-20 07:30:17 +0000885 } else if (Hexagon::PredRegsRegClass.hasSubClassEq(RC)) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000886 BuildMI(MBB, I, DL, get(Hexagon::STriw_pred))
Krzysztof Parzyszek7b413c62016-01-22 19:15:58 +0000887 .addFrameIndex(FI).addImm(0)
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000888 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
Krzysztof Parzyszek7b413c62016-01-22 19:15:58 +0000889 } else if (Hexagon::ModRegsRegClass.hasSubClassEq(RC)) {
890 BuildMI(MBB, I, DL, get(Hexagon::STriw_mod))
891 .addFrameIndex(FI).addImm(0)
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000892 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
893 } else if (Hexagon::VecPredRegs128BRegClass.hasSubClassEq(RC)) {
Krzysztof Parzyszek17aa4132016-08-16 15:43:54 +0000894 BuildMI(MBB, I, DL, get(Hexagon::PS_vstorerq_ai_128B))
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000895 .addFrameIndex(FI).addImm(0)
896 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
897 } else if (Hexagon::VecPredRegsRegClass.hasSubClassEq(RC)) {
Krzysztof Parzyszek17aa4132016-08-16 15:43:54 +0000898 BuildMI(MBB, I, DL, get(Hexagon::PS_vstorerq_ai))
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000899 .addFrameIndex(FI).addImm(0)
900 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
901 } else if (Hexagon::VectorRegs128BRegClass.hasSubClassEq(RC)) {
Krzysztof Parzyszekf2859632016-08-12 21:05:05 +0000902 unsigned Opc = Align < 128 ? Hexagon::V6_vS32Ub_ai_128B
903 : Hexagon::V6_vS32b_ai_128B;
904 BuildMI(MBB, I, DL, get(Opc))
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000905 .addFrameIndex(FI).addImm(0)
906 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
907 } else if (Hexagon::VectorRegsRegClass.hasSubClassEq(RC)) {
Krzysztof Parzyszekf2859632016-08-12 21:05:05 +0000908 unsigned Opc = Align < 64 ? Hexagon::V6_vS32Ub_ai
909 : Hexagon::V6_vS32b_ai;
910 BuildMI(MBB, I, DL, get(Opc))
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000911 .addFrameIndex(FI).addImm(0)
912 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
913 } else if (Hexagon::VecDblRegsRegClass.hasSubClassEq(RC)) {
Krzysztof Parzyszekf2859632016-08-12 21:05:05 +0000914 unsigned Opc = Align < 64 ? Hexagon::PS_vstorerwu_ai
915 : Hexagon::PS_vstorerw_ai;
916 BuildMI(MBB, I, DL, get(Opc))
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000917 .addFrameIndex(FI).addImm(0)
918 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
919 } else if (Hexagon::VecDblRegs128BRegClass.hasSubClassEq(RC)) {
Krzysztof Parzyszekf2859632016-08-12 21:05:05 +0000920 unsigned Opc = Align < 128 ? Hexagon::PS_vstorerwu_ai_128B
921 : Hexagon::PS_vstorerw_ai_128B;
922 BuildMI(MBB, I, DL, get(Opc))
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000923 .addFrameIndex(FI).addImm(0)
924 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000925 } else {
Craig Toppere55c5562012-02-07 02:50:20 +0000926 llvm_unreachable("Unimplemented");
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000927 }
928}
929
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +0000930void HexagonInstrInfo::loadRegFromStackSlot(
931 MachineBasicBlock &MBB, MachineBasicBlock::iterator I, unsigned DestReg,
932 int FI, const TargetRegisterClass *RC,
933 const TargetRegisterInfo *TRI) const {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000934 DebugLoc DL = MBB.findDebugLoc(I);
935 MachineFunction &MF = *MBB.getParent();
Matthias Braun941a7052016-07-28 18:40:00 +0000936 MachineFrameInfo &MFI = MF.getFrameInfo();
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000937 unsigned Align = MFI.getObjectAlignment(FI);
938
Alex Lorenze40c8a22015-08-11 23:09:45 +0000939 MachineMemOperand *MMO = MF.getMachineMemOperand(
940 MachinePointerInfo::getFixedStack(MF, FI), MachineMemOperand::MOLoad,
941 MFI.getObjectSize(FI), Align);
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000942
Krzysztof Parzyszek7b413c62016-01-22 19:15:58 +0000943 if (Hexagon::IntRegsRegClass.hasSubClassEq(RC)) {
Colin LeMahieu026e88d2014-12-23 20:02:16 +0000944 BuildMI(MBB, I, DL, get(Hexagon::L2_loadri_io), DestReg)
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000945 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
Krzysztof Parzyszek7b413c62016-01-22 19:15:58 +0000946 } else if (Hexagon::DoubleRegsRegClass.hasSubClassEq(RC)) {
Colin LeMahieu947cd702014-12-23 20:44:59 +0000947 BuildMI(MBB, I, DL, get(Hexagon::L2_loadrd_io), DestReg)
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000948 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
Krzysztof Parzyszek7b413c62016-01-22 19:15:58 +0000949 } else if (Hexagon::PredRegsRegClass.hasSubClassEq(RC)) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000950 BuildMI(MBB, I, DL, get(Hexagon::LDriw_pred), DestReg)
Krzysztof Parzyszek7b413c62016-01-22 19:15:58 +0000951 .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 Parzyszek79a886b2016-02-12 21:56:41 +0000955 } else if (Hexagon::VecPredRegs128BRegClass.hasSubClassEq(RC)) {
Krzysztof Parzyszek17aa4132016-08-16 15:43:54 +0000956 BuildMI(MBB, I, DL, get(Hexagon::PS_vloadrq_ai_128B), DestReg)
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000957 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
958 } else if (Hexagon::VecPredRegsRegClass.hasSubClassEq(RC)) {
Krzysztof Parzyszek17aa4132016-08-16 15:43:54 +0000959 BuildMI(MBB, I, DL, get(Hexagon::PS_vloadrq_ai), DestReg)
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000960 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
961 } else if (Hexagon::VecDblRegs128BRegClass.hasSubClassEq(RC)) {
Krzysztof Parzyszekf2859632016-08-12 21:05:05 +0000962 unsigned Opc = Align < 128 ? Hexagon::PS_vloadrwu_ai_128B
963 : Hexagon::PS_vloadrw_ai_128B;
964 BuildMI(MBB, I, DL, get(Opc), DestReg)
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000965 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
966 } else if (Hexagon::VectorRegs128BRegClass.hasSubClassEq(RC)) {
Krzysztof Parzyszekf2859632016-08-12 21:05:05 +0000967 unsigned Opc = Align < 128 ? Hexagon::V6_vL32Ub_ai_128B
968 : Hexagon::V6_vL32b_ai_128B;
969 BuildMI(MBB, I, DL, get(Opc), DestReg)
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000970 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
971 } else if (Hexagon::VectorRegsRegClass.hasSubClassEq(RC)) {
Krzysztof Parzyszekf2859632016-08-12 21:05:05 +0000972 unsigned Opc = Align < 64 ? Hexagon::V6_vL32Ub_ai
973 : Hexagon::V6_vL32b_ai;
974 BuildMI(MBB, I, DL, get(Opc), DestReg)
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000975 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
976 } else if (Hexagon::VecDblRegsRegClass.hasSubClassEq(RC)) {
Krzysztof Parzyszekf2859632016-08-12 21:05:05 +0000977 unsigned Opc = Align < 64 ? Hexagon::PS_vloadrwu_ai
978 : Hexagon::PS_vloadrw_ai;
979 BuildMI(MBB, I, DL, get(Opc), DestReg)
Krzysztof Parzyszek79a886b2016-02-12 21:56:41 +0000980 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000981 } else {
Craig Toppere55c5562012-02-07 02:50:20 +0000982 llvm_unreachable("Can't store this register to stack slot");
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000983 }
984}
985
Ron Lieberman88159e52016-09-02 22:56:24 +0000986static void getLiveRegsAt(LivePhysRegs &Regs, const MachineInstr &MI) {
987 const MachineBasicBlock &B = *MI.getParent();
988 Regs.addLiveOuts(B);
Duncan P. N. Exon Smith18720962016-09-11 18:51:28 +0000989 auto E = ++MachineBasicBlock::const_iterator(MI.getIterator()).getReverse();
Ron Lieberman88159e52016-09-02 22:56:24 +0000990 for (auto I = B.rbegin(); I != E; ++I)
991 Regs.stepBackward(*I);
992}
993
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +0000994/// 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 Smith9cfc75c2016-06-30 00:01:54 +00001000bool HexagonInstrInfo::expandPostRAPseudo(MachineInstr &MI) const {
Krzysztof Parzyszekfb338242015-10-06 15:49:14 +00001001 const HexagonRegisterInfo &HRI = getRegisterInfo();
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001002 MachineRegisterInfo &MRI = MI.getParent()->getParent()->getRegInfo();
1003 MachineBasicBlock &MBB = *MI.getParent();
1004 DebugLoc DL = MI.getDebugLoc();
1005 unsigned Opc = MI.getOpcode();
Krzysztof Parzyszek195dc8d2015-11-26 04:33:11 +00001006 const unsigned VecOffset = 1;
Colin LeMahieu7b1799c2015-03-09 22:05:21 +00001007
1008 switch (Opc) {
Krzysztof Parzyszek3d6fc832016-06-02 14:33:08 +00001009 case TargetOpcode::COPY: {
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001010 MachineOperand &MD = MI.getOperand(0);
1011 MachineOperand &MS = MI.getOperand(1);
1012 MachineBasicBlock::iterator MBBI = MI.getIterator();
Krzysztof Parzyszek3d6fc832016-06-02 14:33:08 +00001013 if (MD.getReg() != MS.getReg() && !MS.isUndef()) {
1014 copyPhysReg(MBB, MI, DL, MD.getReg(), MS.getReg(), MS.isKill());
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001015 std::prev(MBBI)->copyImplicitOps(*MBB.getParent(), MI);
Krzysztof Parzyszek3d6fc832016-06-02 14:33:08 +00001016 }
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001017 MBB.erase(MBBI);
Krzysztof Parzyszek3d6fc832016-06-02 14:33:08 +00001018 return true;
1019 }
Krzysztof Parzyszek1d01a792016-08-16 18:08:40 +00001020 case Hexagon::PS_aligna:
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001021 BuildMI(MBB, MI, DL, get(Hexagon::A2_andir), MI.getOperand(0).getReg())
Krzysztof Parzyszekfb338242015-10-06 15:49:14 +00001022 .addReg(HRI.getFrameRegister())
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001023 .addImm(-MI.getOperand(1).getImm());
Krzysztof Parzyszek4fa2a9f2015-04-22 16:43:53 +00001024 MBB.erase(MI);
1025 return true;
Krzysztof Parzyszekeabc0d02016-08-16 17:14:44 +00001026 case Hexagon::V6_vassignp_128B:
1027 case Hexagon::V6_vassignp: {
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001028 unsigned SrcReg = MI.getOperand(1).getReg();
1029 unsigned DstReg = MI.getOperand(0).getReg();
Krzysztof Parzyszekeabc0d02016-08-16 17:14:44 +00001030 unsigned Kill = getKillRegState(MI.getOperand(1).isKill());
1031 BuildMI(MBB, MI, DL, get(Hexagon::V6_vcombine), DstReg)
Krzysztof Parzyszeka5409972016-11-09 16:19:08 +00001032 .addReg(HRI.getSubReg(SrcReg, Hexagon::vsub_hi), Kill)
1033 .addReg(HRI.getSubReg(SrcReg, Hexagon::vsub_lo), Kill);
Krzysztof Parzyszek4eb6d4d2015-11-26 16:54:33 +00001034 MBB.erase(MI);
1035 return true;
1036 }
Krzysztof Parzyszekeabc0d02016-08-16 17:14:44 +00001037 case Hexagon::V6_lo_128B:
1038 case Hexagon::V6_lo: {
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001039 unsigned SrcReg = MI.getOperand(1).getReg();
1040 unsigned DstReg = MI.getOperand(0).getReg();
Krzysztof Parzyszeka5409972016-11-09 16:19:08 +00001041 unsigned SrcSubLo = HRI.getSubReg(SrcReg, Hexagon::vsub_lo);
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001042 copyPhysReg(MBB, MI, DL, DstReg, SrcSubLo, MI.getOperand(1).isKill());
Krzysztof Parzyszek4eb6d4d2015-11-26 16:54:33 +00001043 MBB.erase(MI);
1044 MRI.clearKillFlags(SrcSubLo);
1045 return true;
1046 }
Krzysztof Parzyszekeabc0d02016-08-16 17:14:44 +00001047 case Hexagon::V6_hi_128B:
1048 case Hexagon::V6_hi: {
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001049 unsigned SrcReg = MI.getOperand(1).getReg();
1050 unsigned DstReg = MI.getOperand(0).getReg();
Krzysztof Parzyszeka5409972016-11-09 16:19:08 +00001051 unsigned SrcSubHi = HRI.getSubReg(SrcReg, Hexagon::vsub_hi);
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001052 copyPhysReg(MBB, MI, DL, DstReg, SrcSubHi, MI.getOperand(1).isKill());
Krzysztof Parzyszek4eb6d4d2015-11-26 16:54:33 +00001053 MBB.erase(MI);
1054 MRI.clearKillFlags(SrcSubHi);
1055 return true;
1056 }
Krzysztof Parzyszekf2859632016-08-12 21:05:05 +00001057 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 Smith9cfc75c2016-06-30 00:01:54 +00001065 unsigned SrcReg = MI.getOperand(2).getReg();
Krzysztof Parzyszeka5409972016-11-09 16:19:08 +00001066 unsigned SrcSubHi = HRI.getSubReg(SrcReg, Hexagon::vsub_hi);
1067 unsigned SrcSubLo = HRI.getSubReg(SrcReg, Hexagon::vsub_lo);
Krzysztof Parzyszekf2859632016-08-12 21:05:05 +00001068 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 Parzyszek195dc8d2015-11-26 04:33:11 +00001076 unsigned Offset = Is128B ? VecOffset << 7 : VecOffset << 6;
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001077 MachineInstr *MI1New =
Krzysztof Parzyszekf2859632016-08-12 21:05:05 +00001078 BuildMI(MBB, MI, DL, get(NewOpc))
Diana Picus116bbab2017-01-13 09:58:52 +00001079 .add(MI.getOperand(0))
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001080 .addImm(MI.getOperand(1).getImm())
1081 .addReg(SrcSubLo)
1082 .setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
Krzysztof Parzyszek195dc8d2015-11-26 04:33:11 +00001083 MI1New->getOperand(0).setIsKill(false);
Krzysztof Parzyszekf2859632016-08-12 21:05:05 +00001084 BuildMI(MBB, MI, DL, get(NewOpc))
Diana Picus116bbab2017-01-13 09:58:52 +00001085 .add(MI.getOperand(0))
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001086 // 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 Parzyszek195dc8d2015-11-26 04:33:11 +00001090 MBB.erase(MI);
1091 return true;
1092 }
Krzysztof Parzyszekf2859632016-08-12 21:05:05 +00001093 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 Smith9cfc75c2016-06-30 00:01:54 +00001109 unsigned DstReg = MI.getOperand(0).getReg();
Krzysztof Parzyszek195dc8d2015-11-26 04:33:11 +00001110 unsigned Offset = Is128B ? VecOffset << 7 : VecOffset << 6;
Diana Picus116bbab2017-01-13 09:58:52 +00001111 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 Parzyszek195dc8d2015-11-26 04:33:11 +00001115 MI1New->getOperand(1).setIsKill(false);
Diana Picus116bbab2017-01-13 09:58:52 +00001116 BuildMI(MBB, MI, DL, get(NewOpc), HRI.getSubReg(DstReg, Hexagon::vsub_hi))
1117 .add(MI.getOperand(1))
Krzysztof Parzyszek195dc8d2015-11-26 04:33:11 +00001118 // The Vectors are indexed in multiples of vector size.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001119 .addImm(MI.getOperand(2).getImm() + Offset)
1120 .setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
Krzysztof Parzyszek195dc8d2015-11-26 04:33:11 +00001121 MBB.erase(MI);
1122 return true;
1123 }
Krzysztof Parzyszek1d01a792016-08-16 18:08:40 +00001124 case Hexagon::PS_true: {
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001125 unsigned Reg = MI.getOperand(0).getReg();
Krzysztof Parzyszek36ccfa52015-03-18 19:07:53 +00001126 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 Parzyszek1d01a792016-08-16 18:08:40 +00001132 case Hexagon::PS_false: {
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001133 unsigned Reg = MI.getOperand(0).getReg();
Krzysztof Parzyszek36ccfa52015-03-18 19:07:53 +00001134 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 Parzyszek1d01a792016-08-16 18:08:40 +00001140 case Hexagon::PS_vmulw: {
Krzysztof Parzyszek42113342015-03-19 16:33:08 +00001141 // Expand a 64-bit vector multiply into 2 32-bit scalar multiplies.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001142 unsigned DstReg = MI.getOperand(0).getReg();
1143 unsigned Src1Reg = MI.getOperand(1).getReg();
1144 unsigned Src2Reg = MI.getOperand(2).getReg();
Krzysztof Parzyszeka5409972016-11-09 16:19:08 +00001145 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 Smith9cfc75c2016-06-30 00:01:54 +00001149 BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::M2_mpyi),
Krzysztof Parzyszeka5409972016-11-09 16:19:08 +00001150 HRI.getSubReg(DstReg, Hexagon::isub_hi))
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001151 .addReg(Src1SubHi)
Krzysztof Parzyszek42113342015-03-19 16:33:08 +00001152 .addReg(Src2SubHi);
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001153 BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::M2_mpyi),
Krzysztof Parzyszeka5409972016-11-09 16:19:08 +00001154 HRI.getSubReg(DstReg, Hexagon::isub_lo))
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001155 .addReg(Src1SubLo)
Krzysztof Parzyszek42113342015-03-19 16:33:08 +00001156 .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 Parzyszek1d01a792016-08-16 18:08:40 +00001164 case Hexagon::PS_vmulw_acc: {
Krzysztof Parzyszek42113342015-03-19 16:33:08 +00001165 // Expand 64-bit vector multiply with addition into 2 scalar multiplies.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001166 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 Parzyszeka5409972016-11-09 16:19:08 +00001170 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 Smith9cfc75c2016-06-30 00:01:54 +00001176 BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::M2_maci),
Krzysztof Parzyszeka5409972016-11-09 16:19:08 +00001177 HRI.getSubReg(DstReg, Hexagon::isub_hi))
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001178 .addReg(Src1SubHi)
1179 .addReg(Src2SubHi)
1180 .addReg(Src3SubHi);
1181 BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::M2_maci),
Krzysztof Parzyszeka5409972016-11-09 16:19:08 +00001182 HRI.getSubReg(DstReg, Hexagon::isub_lo))
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001183 .addReg(Src1SubLo)
1184 .addReg(Src2SubLo)
1185 .addReg(Src3SubLo);
Krzysztof Parzyszek42113342015-03-19 16:33:08 +00001186 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 Parzyszek258af192016-08-11 19:12:18 +00001195 case Hexagon::PS_pselect: {
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001196 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 Parzyszekfb338242015-10-06 15:49:14 +00001200 unsigned Rd = Op0.getReg();
1201 unsigned Pu = Op1.getReg();
1202 unsigned Rs = Op2.getReg();
1203 unsigned Rt = Op3.getReg();
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001204 DebugLoc DL = MI.getDebugLoc();
Krzysztof Parzyszekfb338242015-10-06 15:49:14 +00001205 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 Parzyszek258af192016-08-11 19:12:18 +00001219 case Hexagon::PS_vselect:
1220 case Hexagon::PS_vselect_128B: {
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001221 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 Lieberman88159e52016-09-02 22:56:24 +00001225 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 Picus116bbab2017-01-13 09:58:52 +00001230 .add(Op0)
1231 .add(Op1)
1232 .add(Op2);
Ron Lieberman88159e52016-09-02 22:56:24 +00001233 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 Picus116bbab2017-01-13 09:58:52 +00001239 .add(Op0)
1240 .add(Op1)
1241 .add(Op3);
Ron Lieberman88159e52016-09-02 22:56:24 +00001242 if (IsDestLive)
1243 T.addReg(Op0.getReg(), RegState::Implicit);
1244 }
Krzysztof Parzyszek4afed552016-05-12 19:16:02 +00001245 MBB.erase(MI);
1246 return true;
1247 }
Krzysztof Parzyszek258af192016-08-11 19:12:18 +00001248 case Hexagon::PS_wselect:
1249 case Hexagon::PS_wselect_128B: {
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001250 MachineOperand &Op0 = MI.getOperand(0);
1251 MachineOperand &Op1 = MI.getOperand(1);
1252 MachineOperand &Op2 = MI.getOperand(2);
1253 MachineOperand &Op3 = MI.getOperand(3);
Ron Lieberman88159e52016-09-02 22:56:24 +00001254 LivePhysRegs LiveAtMI(&HRI);
1255 getLiveRegsAt(LiveAtMI, MI);
1256 bool IsDestLive = !LiveAtMI.available(MRI, Op0.getReg());
1257
1258 if (Op0.getReg() != Op2.getReg()) {
Krzysztof Parzyszeka5409972016-11-09 16:19:08 +00001259 unsigned SrcLo = HRI.getSubReg(Op2.getReg(), Hexagon::vsub_lo);
1260 unsigned SrcHi = HRI.getSubReg(Op2.getReg(), Hexagon::vsub_hi);
Ron Lieberman88159e52016-09-02 22:56:24 +00001261 auto T = BuildMI(MBB, MI, DL, get(Hexagon::V6_vccombine))
Diana Picus116bbab2017-01-13 09:58:52 +00001262 .add(Op0)
1263 .add(Op1)
1264 .addReg(SrcHi)
1265 .addReg(SrcLo);
Ron Lieberman88159e52016-09-02 22:56:24 +00001266 if (IsDestLive)
1267 T.addReg(Op0.getReg(), RegState::Implicit);
1268 IsDestLive = true;
1269 }
1270 if (Op0.getReg() != Op3.getReg()) {
Krzysztof Parzyszeka5409972016-11-09 16:19:08 +00001271 unsigned SrcLo = HRI.getSubReg(Op3.getReg(), Hexagon::vsub_lo);
1272 unsigned SrcHi = HRI.getSubReg(Op3.getReg(), Hexagon::vsub_hi);
Ron Lieberman88159e52016-09-02 22:56:24 +00001273 auto T = BuildMI(MBB, MI, DL, get(Hexagon::V6_vnccombine))
Diana Picus116bbab2017-01-13 09:58:52 +00001274 .add(Op0)
1275 .add(Op1)
1276 .addReg(SrcHi)
1277 .addReg(SrcLo);
Ron Lieberman88159e52016-09-02 22:56:24 +00001278 if (IsDestLive)
1279 T.addReg(Op0.getReg(), RegState::Implicit);
1280 }
Krzysztof Parzyszek4afed552016-05-12 19:16:02 +00001281 MBB.erase(MI);
1282 return true;
1283 }
Krzysztof Parzyszekbe976d42016-08-12 11:12:02 +00001284 case Hexagon::PS_tailcall_i:
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001285 MI.setDesc(get(Hexagon::J2_jump));
Colin LeMahieu7b1799c2015-03-09 22:05:21 +00001286 return true;
Krzysztof Parzyszekbe976d42016-08-12 11:12:02 +00001287 case Hexagon::PS_tailcall_r:
Krzysztof Parzyszek6421b932016-08-19 14:04:45 +00001288 case Hexagon::PS_jmpret:
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001289 MI.setDesc(get(Hexagon::J2_jumpr));
Colin LeMahieu7b1799c2015-03-09 22:05:21 +00001290 return true;
Krzysztof Parzyszek6421b932016-08-19 14:04:45 +00001291 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 LeMahieu7b1799c2015-03-09 22:05:21 +00001309 }
1310
1311 return false;
1312}
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001313
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001314// We indicate that we want to reverse the branch by
1315// inserting the reversed branching opcode.
Matt Arsenault1b9fc8e2016-09-14 20:43:16 +00001316bool HexagonInstrInfo::reverseBranchCondition(
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001317 SmallVectorImpl<MachineOperand> &Cond) const {
1318 if (Cond.empty())
Jyotsna Vermaf1214a82013-03-05 18:51:42 +00001319 return true;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001320 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 Vermaf1214a82013-03-05 18:51:42 +00001325 return true;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001326 unsigned NewOpcode = getInvertedPredicatedOpcode(opcode);
1327 Cond[0].setImm(NewOpcode);
Jyotsna Vermaf1214a82013-03-05 18:51:42 +00001328 return false;
1329}
1330
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001331void HexagonInstrInfo::insertNoop(MachineBasicBlock &MBB,
1332 MachineBasicBlock::iterator MI) const {
1333 DebugLoc DL;
1334 BuildMI(MBB, MI, DL, get(Hexagon::A2_nop));
1335}
1336
Krzysztof Parzyszek8fb181c2016-08-01 17:55:48 +00001337bool HexagonInstrInfo::isPostIncrement(const MachineInstr &MI) const {
1338 return getAddrMode(MI) == HexagonII::PostInc;
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001339}
1340
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001341// 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 Smith6307eb52016-02-23 02:46:52 +00001349bool HexagonInstrInfo::isPredicated(const MachineInstr &MI) const {
1350 const uint64_t F = MI.getDesc().TSFlags;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001351 return (F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask;
Brendon Cahoondf43e682015-05-08 16:16:29 +00001352}
1353
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001354bool HexagonInstrInfo::PredicateInstruction(
1355 MachineInstr &MI, ArrayRef<MachineOperand> Cond) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001356 if (Cond.empty() || isNewValueJump(Cond[0].getImm()) ||
1357 isEndLoopN(Cond[0].getImm())) {
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001358 DEBUG(dbgs() << "\nCannot predicate:"; MI.dump(););
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001359 return false;
1360 }
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001361 int Opc = MI.getOpcode();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001362 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 Smith6307eb52016-02-23 02:46:52 +00001370 MachineBasicBlock &B = *MI.getParent();
1371 DebugLoc DL = MI.getDebugLoc();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001372 unsigned PredOpc = getCondOpcode(Opc, invertJump);
1373 MachineInstrBuilder T = BuildMI(B, MI, DL, get(PredOpc));
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001374 unsigned NOp = 0, NumOps = MI.getNumOperands();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001375 while (NOp < NumOps) {
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001376 MachineOperand &Op = MI.getOperand(NOp);
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001377 if (!Op.isReg() || !Op.isDef() || Op.isImplicit())
1378 break;
Diana Picus116bbab2017-01-13 09:58:52 +00001379 T.add(Op);
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001380 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 Picus116bbab2017-01-13 09:58:52 +00001389 T.add(MI.getOperand(NOp++));
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001390
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001391 MI.setDesc(get(PredOpc));
1392 while (unsigned n = MI.getNumOperands())
1393 MI.RemoveOperand(n-1);
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001394 for (unsigned i = 0, n = T->getNumOperands(); i < n; ++i)
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001395 MI.addOperand(T->getOperand(i));
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001396
Duncan P. N. Exon Smithc5b668d2016-02-22 20:49:58 +00001397 MachineBasicBlock::instr_iterator TI = T->getIterator();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001398 B.erase(TI);
1399
1400 MachineRegisterInfo &MRI = B.getParent()->getRegInfo();
1401 MRI.clearKillFlags(PredReg);
1402 return true;
Brendon Cahoondf43e682015-05-08 16:16:29 +00001403}
1404
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001405bool HexagonInstrInfo::SubsumesPredicate(ArrayRef<MachineOperand> Pred1,
1406 ArrayRef<MachineOperand> Pred2) const {
1407 // TODO: Fix this
1408 return false;
1409}
1410
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001411bool HexagonInstrInfo::DefinesPredicate(
1412 MachineInstr &MI, std::vector<MachineOperand> &Pred) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001413 auto &HRI = getRegisterInfo();
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00001414 for (unsigned oper = 0; oper < MI.getNumOperands(); ++oper) {
1415 MachineOperand MO = MI.getOperand(oper);
Krzysztof Parzyszek1aaf41a2017-02-17 22:14:51 +00001416 if (MO.isReg()) {
1417 if (!MO.isDef())
1418 continue;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001419 const TargetRegisterClass* RC = HRI.getMinimalPhysRegClass(MO.getReg());
1420 if (RC == &Hexagon::PredRegsRegClass) {
1421 Pred.push_back(MO);
1422 return true;
1423 }
Krzysztof Parzyszek1aaf41a2017-02-17 22:14:51 +00001424 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +00001432 }
1433 }
1434 return false;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00001435}
Andrew Trickd06df962012-02-01 22:13:57 +00001436
Krzysztof Parzyszekcc318712017-03-03 18:30:54 +00001437bool HexagonInstrInfo::isPredicable(const MachineInstr &MI) const {
Krzysztof Parzyszek0a04ac22016-05-16 16:56:10 +00001438 return MI.getDesc().isPredicable();
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001439}
1440
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001441bool HexagonInstrInfo::isSchedulingBoundary(const MachineInstr &MI,
1442 const MachineBasicBlock *MBB,
1443 const MachineFunction &MF) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001444 // 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 Smith9cfc75c2016-06-30 00:01:54 +00001450 if (MI.isDebugValue())
Brendon Cahoondf43e682015-05-08 16:16:29 +00001451 return false;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001452
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001453 // Throwing call is a boundary.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001454 if (MI.isCall()) {
Krzysztof Parzyszekab9127c2016-08-12 11:01:10 +00001455 // Don't mess around with no return calls.
1456 if (doesNotReturn(MI))
1457 return true;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001458 // 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 Linthicum1213a7a2011-12-12 21:14:40 +00001462 return true;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001463 }
1464
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001465 // Terminators and labels can't be scheduled around.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001466 if (MI.getDesc().isTerminator() || MI.isPosition())
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001467 return true;
1468
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001469 if (MI.isInlineAsm() && !ScheduleInlineAsm)
1470 return true;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001471
1472 return false;
1473}
1474
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001475/// 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.
1485unsigned 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 Linthicum1213a7a2011-12-12 21:14:40 +00001498 }
Mehdi Amini36d33fc2016-10-01 06:46:33 +00001499 if (atInsnStart && strncmp(Str, MAI.getCommentString().data(),
1500 MAI.getCommentString().size()) == 0)
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001501 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +00001510ScheduleHazardRecognizer*
1511HexagonInstrInfo::CreateTargetPostRAHazardRecognizer(
1512 const InstrItineraryData *II, const ScheduleDAG *DAG) const {
Krzysztof Parzyszeke95e9552016-07-29 13:59:09 +00001513 if (UseDFAHazardRec) {
1514 auto &HST = DAG->MF.getSubtarget<HexagonSubtarget>();
1515 return new HexagonHazardRecognizer(II, this, HST);
1516 }
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001517 return TargetInstrInfo::CreateTargetPostRAHazardRecognizer(II, DAG);
1518}
1519
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001520/// \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 Smith9cfc75c2016-06-30 00:01:54 +00001524bool HexagonInstrInfo::analyzeCompare(const MachineInstr &MI, unsigned &SrcReg,
1525 unsigned &SrcReg2, int &Mask,
1526 int &Value) const {
1527 unsigned Opc = MI.getOpcode();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001528
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 Smith9cfc75c2016-06-30 00:01:54 +00001546 SrcReg = MI.getOperand(1).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001547 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 Smith9cfc75c2016-06-30 00:01:54 +00001555 SrcReg = MI.getOperand(1).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001556 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 Smith9cfc75c2016-06-30 00:01:54 +00001564 SrcReg = MI.getOperand(1).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001565 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 Smith9cfc75c2016-06-30 00:01:54 +00001586 SrcReg2 = MI.getOperand(2).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001587 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 Smith9cfc75c2016-06-30 00:01:54 +00001602 Value = MI.getOperand(2).getImm();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001603 return true;
1604 }
1605
1606 return false;
1607}
1608
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001609unsigned HexagonInstrInfo::getInstrLatency(const InstrItineraryData *ItinData,
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001610 const MachineInstr &MI,
1611 unsigned *PredCost) const {
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001612 return getInstrTimingClassLatency(ItinData, MI);
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001613}
1614
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001615DFAPacketizer *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 Parzyszekb9a1c3a2015-11-24 14:55:26 +00001621// 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 Smith9cfc75c2016-06-30 00:01:54 +00001625bool HexagonInstrInfo::areMemAccessesTriviallyDisjoint(
1626 MachineInstr &MIa, MachineInstr &MIb, AliasAnalysis *AA) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001627 int OffsetA = 0, OffsetB = 0;
1628 unsigned SizeA = 0, SizeB = 0;
1629
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00001630 if (MIa.hasUnmodeledSideEffects() || MIb.hasUnmodeledSideEffects() ||
1631 MIa.hasOrderedMemoryRef() || MIb.hasOrderedMemoryRef())
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001632 return false;
1633
1634 // Instructions that are pure loads, not loads and stores like memops are not
1635 // dependent.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001636 if (MIa.mayLoad() && !isMemOp(MIa) && MIb.mayLoad() && !isMemOp(MIb))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001637 return true;
1638
1639 // Get base, offset, and access size in MIa.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001640 unsigned BaseRegA = getBaseAndOffset(MIa, OffsetA, SizeA);
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001641 if (!BaseRegA || !SizeA)
1642 return false;
1643
1644 // Get base, offset, and access size in MIb.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001645 unsigned BaseRegB = getBaseAndOffset(MIb, OffsetB, SizeB);
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001646 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 Cahoon254f8892016-07-29 16:44:44 +00001665/// If the instruction is an increment of a constant value, return the amount.
Krzysztof Parzyszek8fb181c2016-08-01 17:55:48 +00001666bool HexagonInstrInfo::getIncrementValue(const MachineInstr &MI,
Brendon Cahoon254f8892016-07-29 16:44:44 +00001667 int &Value) const {
1668 if (isPostIncrement(MI)) {
1669 unsigned AccessSize;
Krzysztof Parzyszek8fb181c2016-08-01 17:55:48 +00001670 return getBaseAndOffset(MI, Value, AccessSize);
Brendon Cahoon254f8892016-07-29 16:44:44 +00001671 }
Krzysztof Parzyszek8fb181c2016-08-01 17:55:48 +00001672 if (MI.getOpcode() == Hexagon::A2_addi) {
1673 Value = MI.getOperand(2).getImm();
Brendon Cahoon254f8892016-07-29 16:44:44 +00001674 return true;
1675 }
1676
1677 return false;
1678}
1679
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001680unsigned HexagonInstrInfo::createVR(MachineFunction *MF, MVT VT) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001681 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 Parzyszekf0b34a52016-07-29 21:49:42 +00001697bool HexagonInstrInfo::isAbsoluteSet(const MachineInstr &MI) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001698 return (getAddrMode(MI) == HexagonII::AbsoluteSet);
1699}
1700
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001701bool HexagonInstrInfo::isAccumulator(const MachineInstr &MI) const {
1702 const uint64_t F = MI.getDesc().TSFlags;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001703 return((F >> HexagonII::AccumulatorPos) & HexagonII::AccumulatorMask);
1704}
1705
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001706bool HexagonInstrInfo::isComplex(const MachineInstr &MI) const {
1707 const MachineFunction *MF = MI.getParent()->getParent();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001708 const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo();
1709 const HexagonInstrInfo *QII = (const HexagonInstrInfo *) TII;
1710
1711 if (!(isTC1(MI))
1712 && !(QII->isTC2Early(MI))
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001713 && !(MI.getDesc().mayLoad())
1714 && !(MI.getDesc().mayStore())
1715 && (MI.getDesc().getOpcode() != Hexagon::S2_allocframe)
1716 && (MI.getDesc().getOpcode() != Hexagon::L2_deallocframe)
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001717 && !(QII->isMemOp(MI))
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001718 && !(MI.isBranch())
1719 && !(MI.isReturn())
1720 && !MI.isCall())
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001721 return true;
1722
1723 return false;
1724}
1725
Sanjay Patele4b9f502015-12-07 19:21:39 +00001726// Return true if the instruction is a compund branch instruction.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001727bool HexagonInstrInfo::isCompoundBranchInstr(const MachineInstr &MI) const {
Krzysztof Parzyszekf65b8f12017-02-02 15:03:30 +00001728 return getType(MI) == HexagonII::TypeCJ && MI.isBranch();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001729}
1730
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001731bool HexagonInstrInfo::isCondInst(const MachineInstr &MI) const {
1732 return (MI.isBranch() && isPredicated(MI)) ||
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001733 isConditionalTransfer(MI) ||
1734 isConditionalALU32(MI) ||
1735 isConditionalLoad(MI) ||
1736 // Predicated stores which don't have a .new on any operands.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001737 (MI.mayStore() && isPredicated(MI) && !isNewValueStore(MI) &&
1738 !isPredicatedNew(MI));
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001739}
1740
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001741bool HexagonInstrInfo::isConditionalALU32(const MachineInstr &MI) const {
1742 switch (MI.getOpcode()) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001743 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 Linthicum1213a7a2011-12-12 21:14:40 +00001794 }
1795 return false;
1796}
1797
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001798// FIXME - Function name and it's functionality don't match.
1799// It should be renamed to hasPredNewOpcode()
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001800bool HexagonInstrInfo::isConditionalLoad(const MachineInstr &MI) const {
1801 if (!MI.getDesc().mayLoad() || !isPredicated(MI))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001802 return false;
1803
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001804 int PNewOpcode = Hexagon::getPredNewOpcode(MI.getOpcode());
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001805 // Instruction with valid predicated-new opcode can be promoted to .new.
1806 return PNewOpcode >= 0;
1807}
1808
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001809// 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 Parzyszekf0b34a52016-07-29 21:49:42 +00001813bool HexagonInstrInfo::isConditionalStore(const MachineInstr &MI) const {
1814 switch (MI.getOpcode()) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001815 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 Parzyszekf0b34a52016-07-29 21:49:42 +00001866bool HexagonInstrInfo::isConditionalTransfer(const MachineInstr &MI) const {
1867 switch (MI.getOpcode()) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001868 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 Linthicum1213a7a2011-12-12 21:14:40 +00001883 return false;
1884}
1885
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001886// TODO: In order to have isExtendable for fpimm/f32Ext, we need to handle
1887// isFPImm and later getFPImm as well.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001888bool HexagonInstrInfo::isConstExtended(const MachineInstr &MI) const {
1889 const uint64_t F = MI.getDesc().TSFlags;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001890 unsigned isExtended = (F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask;
1891 if (isExtended) // Instruction must be extended.
Krzysztof Parzyszekc6f19332015-03-19 15:18:57 +00001892 return true;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001893
1894 unsigned isExtendable =
1895 (F >> HexagonII::ExtendablePos) & HexagonII::ExtendableMask;
1896 if (!isExtendable)
1897 return false;
1898
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001899 if (MI.isCall())
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001900 return false;
1901
1902 short ExtOpNum = getCExtOpNum(MI);
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001903 const MachineOperand &MO = MI.getOperand(ExtOpNum);
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001904 // Use MO operand flags to determine if MO
1905 // has the HMOTF_ConstExtended flag set.
1906 if (MO.getTargetFlags() && HexagonII::HMOTF_ConstExtended)
Brendon Cahoondf43e682015-05-08 16:16:29 +00001907 return true;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001908 // 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 Parzyszeka3386502016-08-10 16:46:36 +00001920 MO.isJTI() || MO.isCPI() || MO.isFPImm())
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001921 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 Linthicum1213a7a2011-12-12 21:14:40 +00001932}
1933
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001934bool HexagonInstrInfo::isDeallocRet(const MachineInstr &MI) const {
1935 switch (MI.getOpcode()) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001936 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 Linthicum1213a7a2011-12-12 21:14:40 +00001943 return true;
1944 }
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001945 return false;
1946}
1947
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001948// Return true when ConsMI uses a register defined by ProdMI.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001949bool HexagonInstrInfo::isDependent(const MachineInstr &ProdMI,
1950 const MachineInstr &ConsMI) const {
1951 if (!ProdMI.getDesc().getNumDefs())
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001952 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +00001984// Returns true if the instruction is alread a .cur.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00001985bool HexagonInstrInfo::isDotCurInst(const MachineInstr &MI) const {
1986 switch (MI.getOpcode()) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00001987 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +00001996// 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 Parzyszekf0b34a52016-07-29 21:49:42 +00001998bool HexagonInstrInfo::isDotNewInst(const MachineInstr &MI) const {
1999 if (isNewValueInst(MI) || (isPredicated(MI) && isPredicatedNew(MI)))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002000 return true;
2001
2002 return false;
2003}
2004
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002005/// Symmetrical. See if these two instructions are fit for duplex pair.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002006bool HexagonInstrInfo::isDuplexPair(const MachineInstr &MIa,
2007 const MachineInstr &MIb) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002008 HexagonII::SubInstructionGroup MIaG = getDuplexCandidateGroup(MIa);
2009 HexagonII::SubInstructionGroup MIbG = getDuplexCandidateGroup(MIb);
2010 return (isDuplexPairMatch(MIaG, MIbG) || isDuplexPairMatch(MIbG, MIaG));
2011}
2012
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002013bool HexagonInstrInfo::isEarlySourceInstr(const MachineInstr &MI) const {
2014 if (MI.mayLoad() || MI.mayStore() || MI.isCompare())
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002015 return true;
2016
2017 // Multiply
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002018 unsigned SchedClass = MI.getDesc().getSchedClass();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002019 if (SchedClass == Hexagon::Sched::M_tc_3or4x_SLOT23)
2020 return true;
2021 return false;
2022}
2023
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002024bool HexagonInstrInfo::isEndLoopN(unsigned Opcode) const {
2025 return (Opcode == Hexagon::ENDLOOP0 ||
2026 Opcode == Hexagon::ENDLOOP1);
2027}
2028
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002029bool 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 Parzyszekf0b34a52016-07-29 21:49:42 +00002043bool HexagonInstrInfo::isExtendable(const MachineInstr &MI) const {
2044 const MCInstrDesc &MID = MI.getDesc();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002045 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 Parzyszekf0b34a52016-07-29 21:49:42 +00002051 switch (MI.getOpcode()) {
Krzysztof Parzyszek1d01a792016-08-16 18:08:40 +00002052 // PS_fi and PS_fia remain special cases.
2053 case Hexagon::PS_fi:
2054 case Hexagon::PS_fia:
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002055 return true;
2056 default:
2057 return false;
2058 }
2059 return false;
2060}
2061
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002062// 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 Parzyszekf0b34a52016-07-29 21:49:42 +00002065bool HexagonInstrInfo::isExtended(const MachineInstr &MI) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002066 // First check if this is permanently extended op code.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002067 const uint64_t F = MI.getDesc().TSFlags;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002068 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 Parzyszekf0b34a52016-07-29 21:49:42 +00002072 for (MachineInstr::const_mop_iterator I = MI.operands_begin(),
2073 E = MI.operands_end(); I != E; ++I) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002074 if (I->getTargetFlags() && HexagonII::HMOTF_ConstExtended)
2075 return true;
2076 }
2077 return false;
2078}
2079
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002080bool HexagonInstrInfo::isFloat(const MachineInstr &MI) const {
2081 unsigned Opcode = MI.getOpcode();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002082 const uint64_t F = get(Opcode).TSFlags;
2083 return (F >> HexagonII::FPPos) & HexagonII::FPMask;
2084}
2085
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +00002086// No V60 HVX VMEM with A_INDIRECT.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002087bool HexagonInstrInfo::isHVXMemWithAIndirect(const MachineInstr &I,
2088 const MachineInstr &J) const {
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +00002089 if (!isV60VectorInstruction(I))
2090 return false;
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002091 if (!I.mayLoad() && !I.mayStore())
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +00002092 return false;
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002093 return J.isIndirectBranch() || isIndirectCall(J) || isIndirectL4Return(J);
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +00002094}
2095
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002096bool HexagonInstrInfo::isIndirectCall(const MachineInstr &MI) const {
2097 switch (MI.getOpcode()) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002098 case Hexagon::J2_callr :
2099 case Hexagon::J2_callrf :
2100 case Hexagon::J2_callrt :
Krzysztof Parzyszek5a7bef92016-08-19 17:20:57 +00002101 case Hexagon::PS_call_nr :
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002102 return true;
2103 }
2104 return false;
2105}
2106
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002107bool HexagonInstrInfo::isIndirectL4Return(const MachineInstr &MI) const {
2108 switch (MI.getOpcode()) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002109 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 Parzyszekf0b34a52016-07-29 21:49:42 +00002121bool HexagonInstrInfo::isJumpR(const MachineInstr &MI) const {
2122 switch (MI.getOpcode()) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002123 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 Pilgrim6ba672e2016-11-17 19:21:20 +00002135// Return true if a given MI can accommodate given offset.
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002136// 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 Parzyszekf0b34a52016-07-29 21:49:42 +00002139bool HexagonInstrInfo::isJumpWithinBranchRange(const MachineInstr &MI,
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002140 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 Parzyszekf0b34a52016-07-29 21:49:42 +00002146 switch (MI.getOpcode()) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002147 // 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 Parzyszekbe976d42016-08-12 11:12:02 +00002152 case Hexagon::PS_call_nr:
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002153 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 Parzyszekf0b34a52016-07-29 21:49:42 +00002179bool HexagonInstrInfo::isLateInstrFeedsEarlyInstr(const MachineInstr &LRMI,
2180 const MachineInstr &ESMI) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002181 bool isLate = isLateResultInstr(LRMI);
2182 bool isEarly = isEarlySourceInstr(ESMI);
2183
2184 DEBUG(dbgs() << "V60" << (isLate ? "-LR " : " -- "));
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002185 DEBUG(LRMI.dump());
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002186 DEBUG(dbgs() << "V60" << (isEarly ? "-ES " : " -- "));
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002187 DEBUG(ESMI.dump());
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002188
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 Parzyszekf0b34a52016-07-29 21:49:42 +00002197bool HexagonInstrInfo::isLateResultInstr(const MachineInstr &MI) const {
2198 switch (MI.getOpcode()) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002199 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 Parzyszekf0b34a52016-07-29 21:49:42 +00002212 unsigned SchedClass = MI.getDesc().getSchedClass();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002213
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 Parzyszekf0b34a52016-07-29 21:49:42 +00002233bool HexagonInstrInfo::isLateSourceInstr(const MachineInstr &MI) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002234 // 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 Parzyszekf0b34a52016-07-29 21:49:42 +00002236 return MI.getDesc().getSchedClass() == Hexagon::Sched::CVI_VX_LATE;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002237}
2238
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002239bool HexagonInstrInfo::isLoopN(const MachineInstr &MI) const {
2240 unsigned Opcode = MI.getOpcode();
Krzysztof Parzyszek5e6f2bd2015-12-14 21:32:25 +00002241 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +00002249}
2250
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002251bool HexagonInstrInfo::isMemOp(const MachineInstr &MI) const {
2252 switch (MI.getOpcode()) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002253 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 Parzyszekf0b34a52016-07-29 21:49:42 +00002283bool HexagonInstrInfo::isNewValue(const MachineInstr &MI) const {
2284 const uint64_t F = MI.getDesc().TSFlags;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002285 return (F >> HexagonII::NewValuePos) & HexagonII::NewValueMask;
2286}
2287
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002288bool HexagonInstrInfo::isNewValue(unsigned Opcode) const {
2289 const uint64_t F = get(Opcode).TSFlags;
2290 return (F >> HexagonII::NewValuePos) & HexagonII::NewValueMask;
2291}
2292
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002293bool HexagonInstrInfo::isNewValueInst(const MachineInstr &MI) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002294 return isNewValueJump(MI) || isNewValueStore(MI);
2295}
2296
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002297bool HexagonInstrInfo::isNewValueJump(const MachineInstr &MI) const {
2298 return isNewValue(MI) && MI.isBranch();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002299}
2300
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002301bool HexagonInstrInfo::isNewValueJump(unsigned Opcode) const {
2302 return isNewValue(Opcode) && get(Opcode).isBranch() && isPredicated(Opcode);
2303}
2304
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002305bool HexagonInstrInfo::isNewValueStore(const MachineInstr &MI) const {
2306 const uint64_t F = MI.getDesc().TSFlags;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002307 return (F >> HexagonII::NVStorePos) & HexagonII::NVStoreMask;
2308}
2309
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002310bool HexagonInstrInfo::isNewValueStore(unsigned Opcode) const {
2311 const uint64_t F = get(Opcode).TSFlags;
2312 return (F >> HexagonII::NVStorePos) & HexagonII::NVStoreMask;
2313}
2314
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002315// Returns true if a particular operand is extendable for an instruction.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002316bool HexagonInstrInfo::isOperandExtended(const MachineInstr &MI,
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002317 unsigned OperandNum) const {
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002318 const uint64_t F = MI.getDesc().TSFlags;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002319 return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask)
2320 == OperandNum;
2321}
2322
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +00002323bool HexagonInstrInfo::isPredicatedNew(const MachineInstr &MI) const {
2324 const uint64_t F = MI.getDesc().TSFlags;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002325 assert(isPredicated(MI));
2326 return (F >> HexagonII::PredicatedNewPos) & HexagonII::PredicatedNewMask;
2327}
2328
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002329bool 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 Smith6307eb52016-02-23 02:46:52 +00002335bool HexagonInstrInfo::isPredicatedTrue(const MachineInstr &MI) const {
2336 const uint64_t F = MI.getDesc().TSFlags;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002337 return !((F >> HexagonII::PredicatedFalsePos) &
2338 HexagonII::PredicatedFalseMask);
2339}
2340
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002341bool 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +00002349bool HexagonInstrInfo::isPredicated(unsigned Opcode) const {
2350 const uint64_t F = get(Opcode).TSFlags;
2351 return (F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask;
2352}
2353
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002354bool HexagonInstrInfo::isPredicateLate(unsigned Opcode) const {
2355 const uint64_t F = get(Opcode).TSFlags;
2356 return ~(F >> HexagonII::PredicateLatePos) & HexagonII::PredicateLateMask;
2357}
2358
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002359bool 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 Parzyszekf0b34a52016-07-29 21:49:42 +00002366bool 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +00002371}
2372
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00002373bool 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 Parzyszekfd02aad2016-02-12 18:37:23 +00002448 }
2449}
2450
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002451bool HexagonInstrInfo::isSolo(const MachineInstr &MI) const {
2452 const uint64_t F = MI.getDesc().TSFlags;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002453 return (F >> HexagonII::SoloPos) & HexagonII::SoloMask;
2454}
2455
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002456bool HexagonInstrInfo::isSpillPredRegOp(const MachineInstr &MI) const {
2457 switch (MI.getOpcode()) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002458 case Hexagon::STriw_pred :
2459 case Hexagon::LDriw_pred :
2460 return true;
2461 default:
2462 return false;
2463 }
2464}
2465
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002466bool HexagonInstrInfo::isTailCall(const MachineInstr &MI) const {
2467 if (!MI.isBranch())
Krzysztof Parzyszekecea07c2016-07-14 19:30:55 +00002468 return false;
2469
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002470 for (auto &Op : MI.operands())
Krzysztof Parzyszekecea07c2016-07-14 19:30:55 +00002471 if (Op.isGlobal() || Op.isSymbol())
2472 return true;
2473 return false;
2474}
2475
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002476// Returns true when SU has a timing class TC1.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002477bool HexagonInstrInfo::isTC1(const MachineInstr &MI) const {
2478 unsigned SchedClass = MI.getDesc().getSchedClass();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002479 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 Parzyszekf0b34a52016-07-29 21:49:42 +00002495bool HexagonInstrInfo::isTC2(const MachineInstr &MI) const {
2496 unsigned SchedClass = MI.getDesc().getSchedClass();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002497 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 Parzyszekf0b34a52016-07-29 21:49:42 +00002511bool HexagonInstrInfo::isTC2Early(const MachineInstr &MI) const {
2512 unsigned SchedClass = MI.getDesc().getSchedClass();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002513 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 Parzyszekf0b34a52016-07-29 21:49:42 +00002531bool HexagonInstrInfo::isTC4x(const MachineInstr &MI) const {
2532 unsigned SchedClass = MI.getDesc().getSchedClass();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002533 return SchedClass == Hexagon::Sched::M_tc_3or4x_SLOT23;
2534}
2535
Krzysztof Parzyszek408e3002016-07-15 21:34:02 +00002536// Schedule this ASAP.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002537bool HexagonInstrInfo::isToBeScheduledASAP(const MachineInstr &MI1,
2538 const MachineInstr &MI2) const {
Krzysztof Parzyszek408e3002016-07-15 21:34:02 +00002539 if (mayBeCurLoad(MI1)) {
2540 // if (result of SU is used in Next) return true;
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002541 unsigned DstReg = MI1.getOperand(0).getReg();
2542 int N = MI2.getNumOperands();
Krzysztof Parzyszek408e3002016-07-15 21:34:02 +00002543 for (int I = 0; I < N; I++)
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002544 if (MI2.getOperand(I).isReg() && DstReg == MI2.getOperand(I).getReg())
Krzysztof Parzyszek408e3002016-07-15 21:34:02 +00002545 return true;
2546 }
2547 if (mayBeNewStore(MI2))
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002548 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 Parzyszek408e3002016-07-15 21:34:02 +00002551 return true;
2552 return false;
2553}
2554
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002555bool HexagonInstrInfo::isV60VectorInstruction(const MachineInstr &MI) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002556 const uint64_t V = getType(MI);
2557 return HexagonII::TypeCVI_FIRST <= V && V <= HexagonII::TypeCVI_LAST;
2558}
2559
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002560// Check if the Offset is a valid auto-inc imm by Load/Store Type.
2561//
2562bool 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 Linthicum1213a7a2011-12-12 21:14:40 +00002596}
2597
Krzysztof Parzyszek05902162015-04-22 17:51:26 +00002598bool HexagonInstrInfo::isValidOffset(unsigned Opcode, int Offset,
2599 bool Extend) const {
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002600 // This function is to check whether the "Offset" is in the correct range of
Krzysztof Parzyszek05902162015-04-22 17:51:26 +00002601 // the given "Opcode". If "Offset" is not in the correct range, "A2_addi" is
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002602 // inserted to calculate the final address. Due to this reason, the function
2603 // assumes that the "Offset" has correct alignment.
Jyotsna Vermaec613662013-03-14 19:08:03 +00002604 // 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 Linthicum1213a7a2011-12-12 21:14:40 +00002608
Krzysztof Parzyszek05902162015-04-22 17:51:26 +00002609 switch (Opcode) {
Krzysztof Parzyszek17aa4132016-08-16 15:43:54 +00002610 case Hexagon::PS_vstorerq_ai:
Krzysztof Parzyszekf2859632016-08-12 21:05:05 +00002611 case Hexagon::PS_vstorerw_ai:
Krzysztof Parzyszek17aa4132016-08-16 15:43:54 +00002612 case Hexagon::PS_vloadrq_ai:
Krzysztof Parzyszekf2859632016-08-12 21:05:05 +00002613 case Hexagon::PS_vloadrw_ai:
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002614 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 Parzyszek17aa4132016-08-16 15:43:54 +00002621 case Hexagon::PS_vstorerq_ai_128B:
Krzysztof Parzyszekf2859632016-08-12 21:05:05 +00002622 case Hexagon::PS_vstorerw_ai_128B:
Krzysztof Parzyszek17aa4132016-08-16 15:43:54 +00002623 case Hexagon::PS_vloadrq_ai_128B:
Krzysztof Parzyszekf2859632016-08-12 21:05:05 +00002624 case Hexagon::PS_vloadrw_ai_128B:
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002625 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 Parzyszek05902162015-04-22 17:51:26 +00002632 case Hexagon::J2_loop0i:
2633 case Hexagon::J2_loop1i:
2634 return isUInt<10>(Offset);
Krzysztof Parzyszekbba0bf72016-07-15 15:35:52 +00002635
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 Parzyszek05902162015-04-22 17:51:26 +00002650 }
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002651
Krzysztof Parzyszek05902162015-04-22 17:51:26 +00002652 if (Extend)
2653 return true;
2654
2655 switch (Opcode) {
Colin LeMahieu026e88d2014-12-23 20:02:16 +00002656 case Hexagon::L2_loadri_io:
Colin LeMahieubda31b42014-12-29 20:44:51 +00002657 case Hexagon::S2_storeri_io:
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002658 return (Offset >= Hexagon_MEMW_OFFSET_MIN) &&
2659 (Offset <= Hexagon_MEMW_OFFSET_MAX);
2660
Colin LeMahieu947cd702014-12-23 20:44:59 +00002661 case Hexagon::L2_loadrd_io:
Colin LeMahieubda31b42014-12-29 20:44:51 +00002662 case Hexagon::S2_storerd_io:
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002663 return (Offset >= Hexagon_MEMD_OFFSET_MIN) &&
2664 (Offset <= Hexagon_MEMD_OFFSET_MAX);
2665
Colin LeMahieu8e39cad2014-12-23 17:25:57 +00002666 case Hexagon::L2_loadrh_io:
Colin LeMahieua9386d22014-12-23 16:42:57 +00002667 case Hexagon::L2_loadruh_io:
Colin LeMahieubda31b42014-12-29 20:44:51 +00002668 case Hexagon::S2_storerh_io:
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002669 return (Offset >= Hexagon_MEMH_OFFSET_MIN) &&
2670 (Offset <= Hexagon_MEMH_OFFSET_MAX);
2671
Colin LeMahieu4b1eac42014-12-22 21:40:43 +00002672 case Hexagon::L2_loadrb_io:
Colin LeMahieuaf1e5de2014-12-22 21:20:03 +00002673 case Hexagon::L2_loadrub_io:
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002674 case Hexagon::S2_storerb_io:
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002675 return (Offset >= Hexagon_MEMB_OFFSET_MIN) &&
2676 (Offset <= Hexagon_MEMB_OFFSET_MAX);
2677
Colin LeMahieuf297dbe2015-02-05 17:49:13 +00002678 case Hexagon::A2_addi:
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002679 return (Offset >= Hexagon_ADDI_OFFSET_MIN) &&
2680 (Offset <= Hexagon_ADDI_OFFSET_MAX);
2681
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002682 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 Linthicum1213a7a2011-12-12 21:14:40 +00002688 return (0 <= Offset && Offset <= 255);
2689
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002690 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 Linthicum1213a7a2011-12-12 21:14:40 +00002696 return (0 <= Offset && Offset <= 127);
2697
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002698 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 Linthicum1213a7a2011-12-12 21:14:40 +00002704 return (0 <= Offset && Offset <= 63);
2705
Krzysztof Parzyszekfd02aad2016-02-12 18:37:23 +00002706 // LDriw_xxx and STriw_xxx are pseudo operations, so it has to take offset of
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002707 // any size. Later pass knows how to handle it.
2708 case Hexagon::STriw_pred:
2709 case Hexagon::LDriw_pred:
Krzysztof Parzyszek7b413c62016-01-22 19:15:58 +00002710 case Hexagon::STriw_mod:
2711 case Hexagon::LDriw_mod:
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002712 return true;
2713
Krzysztof Parzyszek1d01a792016-08-16 18:08:40 +00002714 case Hexagon::PS_fi:
2715 case Hexagon::PS_fia:
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002716 case Hexagon::INLINEASM:
2717 return true;
Krzysztof Parzyszekfb338242015-10-06 15:49:14 +00002718
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 Parzyszekfb338242015-10-06 15:49:14 +00002725 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 Parzyszekfb338242015-10-06 15:49:14 +00002733 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 Parzyszekfb338242015-10-06 15:49:14 +00002739 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 Linthicum1213a7a2011-12-12 21:14:40 +00002747
Benjamin Kramerb6684012011-12-27 11:41:05 +00002748 llvm_unreachable("No offset range is defined for this opcode. "
2749 "Please define it in the above switch statement!");
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002750}
2751
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002752bool HexagonInstrInfo::isVecAcc(const MachineInstr &MI) const {
2753 return isV60VectorInstruction(MI) && isAccumulator(MI);
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002754}
2755
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002756bool HexagonInstrInfo::isVecALU(const MachineInstr &MI) const {
2757 const uint64_t F = get(MI.getOpcode()).TSFlags;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002758 const uint64_t V = ((F >> HexagonII::TypePos) & HexagonII::TypeMask);
2759 return
2760 V == HexagonII::TypeCVI_VA ||
2761 V == HexagonII::TypeCVI_VA_DV;
2762}
Andrew Trickd06df962012-02-01 22:13:57 +00002763
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002764bool HexagonInstrInfo::isVecUsableNextPacket(const MachineInstr &ProdMI,
2765 const MachineInstr &ConsMI) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002766 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 Trickd06df962012-02-01 22:13:57 +00002773 return true;
2774
2775 return false;
2776}
Jyotsna Verma84256432013-03-01 17:37:13 +00002777
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +00002778bool 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 Parzyszekfd02aad2016-02-12 18:37:23 +00002853 }
2854}
2855
Krzysztof Parzyszek408e3002016-07-15 21:34:02 +00002856// Add latency to instruction.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002857bool HexagonInstrInfo::addLatencyToSchedule(const MachineInstr &MI1,
2858 const MachineInstr &MI2) const {
Krzysztof Parzyszek408e3002016-07-15 21:34:02 +00002859 if (isV60VectorInstruction(MI1) && isV60VectorInstruction(MI2))
2860 if (!isVecUsableNextPacket(MI1, MI2))
2861 return true;
2862 return false;
2863}
2864
Brendon Cahoon254f8892016-07-29 16:44:44 +00002865/// \brief Get the base register and byte offset of a load/store instr.
2866bool HexagonInstrInfo::getMemOpBaseRegImmOfs(MachineInstr &LdSt,
2867 unsigned &BaseReg, int64_t &Offset, const TargetRegisterInfo *TRI)
2868 const {
2869 unsigned AccessSize = 0;
2870 int OffsetVal = 0;
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002871 BaseReg = getBaseAndOffset(LdSt, OffsetVal, AccessSize);
Brendon Cahoon254f8892016-07-29 16:44:44 +00002872 Offset = OffsetVal;
2873 return BaseReg != 0;
2874}
2875
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +00002876/// \brief Can these instructions execute at the same time in a bundle.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002877bool HexagonInstrInfo::canExecuteInBundle(const MachineInstr &First,
2878 const MachineInstr &Second) const {
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +00002879 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 Parzyszekf0b34a52016-07-29 21:49:42 +00002885 Second.getOperand(Second.getNumOperands() - 1);
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +00002886 if (!Stored.isReg())
2887 return false;
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002888 for (unsigned i = 0, e = First.getNumOperands(); i < e; ++i) {
2889 const MachineOperand &Op = First.getOperand(i);
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +00002890 if (Op.isReg() && Op.isDef() && Op.getReg() == Stored.getReg())
2891 return true;
2892 }
2893 }
2894 return false;
2895}
2896
Krzysztof Parzyszek1b689da2016-08-11 21:14:25 +00002897bool HexagonInstrInfo::doesNotReturn(const MachineInstr &CallMI) const {
2898 unsigned Opc = CallMI.getOpcode();
Krzysztof Parzyszekbe976d42016-08-12 11:12:02 +00002899 return Opc == Hexagon::PS_call_nr || Opc == Hexagon::PS_callr_nr;
Krzysztof Parzyszek1b689da2016-08-11 21:14:25 +00002900}
2901
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002902bool HexagonInstrInfo::hasEHLabel(const MachineBasicBlock *B) const {
2903 for (auto &I : *B)
2904 if (I.isEHLabel())
2905 return true;
2906 return false;
Jyotsna Verma84256432013-03-01 17:37:13 +00002907}
2908
Jyotsna Verma84256432013-03-01 17:37:13 +00002909// Returns true if an instruction can be converted into a non-extended
2910// equivalent instruction.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002911bool HexagonInstrInfo::hasNonExtEquivalent(const MachineInstr &MI) const {
Jyotsna Verma84256432013-03-01 17:37:13 +00002912 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 Parzyszekf0b34a52016-07-29 21:49:42 +00002915 if (Hexagon::getRegForm(MI.getOpcode()) >= 0)
Jyotsna Verma84256432013-03-01 17:37:13 +00002916 return true;
2917
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002918 if (MI.getDesc().mayLoad() || MI.getDesc().mayStore()) {
Alp Tokercb402912014-01-24 17:20:08 +00002919 // Check addressing mode and retrieve non-ext equivalent instruction.
Jyotsna Verma84256432013-03-01 17:37:13 +00002920
2921 switch (getAddrMode(MI)) {
2922 case HexagonII::Absolute :
2923 // Load/store with absolute addressing mode can be converted into
2924 // base+offset mode.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002925 NonExtOpcode = Hexagon::getBaseWithImmOffset(MI.getOpcode());
Jyotsna Verma84256432013-03-01 17:37:13 +00002926 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 Parzyszekf0b34a52016-07-29 21:49:42 +00002931 NonExtOpcode = Hexagon::getBaseWithRegOffset(MI.getOpcode());
Jyotsna Verma84256432013-03-01 17:37:13 +00002932 break;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002933 case HexagonII::BaseLongOffset:
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002934 NonExtOpcode = Hexagon::getRegShlForm(MI.getOpcode());
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002935 break;
Jyotsna Verma84256432013-03-01 17:37:13 +00002936 default:
2937 return false;
2938 }
2939 if (NonExtOpcode < 0)
2940 return false;
2941 return true;
2942 }
2943 return false;
2944}
2945
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002946bool HexagonInstrInfo::hasPseudoInstrPair(const MachineInstr &MI) const {
2947 return Hexagon::getRealHWInstr(MI.getOpcode(),
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002948 Hexagon::InstrType_Pseudo) >= 0;
2949}
2950
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002951bool 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +00002962// Returns true, if a LD insn can be promoted to a cur load.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002963bool HexagonInstrInfo::mayBeCurLoad(const MachineInstr &MI) const {
2964 auto &HST = MI.getParent()->getParent()->getSubtarget<HexagonSubtarget>();
2965 const uint64_t F = MI.getDesc().TSFlags;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002966 return ((F >> HexagonII::mayCVLoadPos) & HexagonII::mayCVLoadMask) &&
2967 HST.hasV60TOps();
2968}
2969
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002970// Returns true, if a ST insn can be promoted to a new-value store.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002971bool HexagonInstrInfo::mayBeNewStore(const MachineInstr &MI) const {
2972 const uint64_t F = MI.getDesc().TSFlags;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002973 return (F >> HexagonII::mayNVStorePos) & HexagonII::mayNVStoreMask;
2974}
2975
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00002976bool HexagonInstrInfo::producesStall(const MachineInstr &ProdMI,
2977 const MachineInstr &ConsMI) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002978 // 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 Parzyszekf0b34a52016-07-29 21:49:42 +00002994bool HexagonInstrInfo::producesStall(const MachineInstr &MI,
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00002995 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 Parzyszekf0b34a52016-07-29 21:49:42 +00003003 if (!MII->isBundle()) {
3004 const MachineInstr &J = *MII;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003005 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 Parzyszekf0b34a52016-07-29 21:49:42 +00003013 const MachineInstr &J = *MII;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003014 if (producesStall(J, MI))
3015 return true;
3016 }
3017 return false;
3018}
3019
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003020bool HexagonInstrInfo::predCanBeUsedAsDotNew(const MachineInstr &MI,
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003021 unsigned PredReg) const {
Krzysztof Parzyszek1aaf41a2017-02-17 22:14:51 +00003022 for (const MachineOperand &MO : MI.operands()) {
3023 // Predicate register must be explicitly defined.
3024 if (MO.isRegMask() && MO.clobbersPhysReg(PredReg))
3025 return false;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003026 if (MO.isReg() && MO.isDef() && MO.isImplicit() && (MO.getReg() == PredReg))
Krzysztof Parzyszek1aaf41a2017-02-17 22:14:51 +00003027 return false;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003028 }
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 Parzyszekf0b34a52016-07-29 21:49:42 +00003033 return MI.getOpcode() != Hexagon::A4_tlbmatch;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003034}
3035
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003036bool 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +00003045bool 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 Parzyszekf0b34a52016-07-29 21:49:42 +00003051short HexagonInstrInfo::getAbsoluteForm(const MachineInstr &MI) const {
3052 return Hexagon::getAbsoluteForm(MI.getOpcode());
Krzysztof Parzyszekf5cbac92016-04-29 15:49:13 +00003053}
3054
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003055unsigned HexagonInstrInfo::getAddrMode(const MachineInstr &MI) const {
3056 const uint64_t F = MI.getDesc().TSFlags;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003057 return (F >> HexagonII::AddrModePos) & HexagonII::AddrModeMask;
3058}
3059
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003060// 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 Parzyszekf0b34a52016-07-29 21:49:42 +00003062unsigned HexagonInstrInfo::getBaseAndOffset(const MachineInstr &MI,
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003063 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 Parzyszek8fb181c2016-08-01 17:55:48 +00003067 !isMemOp(MI) && !isPostIncrement(MI))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003068 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 Parzyszek8fb181c2016-08-01 17:55:48 +00003082 if (!getBaseAndOffsetPosition(MI, basePos, offsetPos))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003083 return 0;
3084
3085 // Post increment updates its EA after the mem access,
3086 // so we need to treat its offset as zero.
Krzysztof Parzyszek8fb181c2016-08-01 17:55:48 +00003087 if (isPostIncrement(MI))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003088 Offset = 0;
3089 else {
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003090 Offset = MI.getOperand(offsetPos).getImm();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003091 }
3092
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003093 return MI.getOperand(basePos).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003094}
3095
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003096/// Return the position of the base and offset operands for this instruction.
Krzysztof Parzyszek8fb181c2016-08-01 17:55:48 +00003097bool HexagonInstrInfo::getBaseAndOffsetPosition(const MachineInstr &MI,
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003098 unsigned &BasePos, unsigned &OffsetPos) const {
3099 // Deal with memops first.
Krzysztof Parzyszek8fb181c2016-08-01 17:55:48 +00003100 if (isMemOp(MI)) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003101 BasePos = 0;
3102 OffsetPos = 1;
Krzysztof Parzyszek8fb181c2016-08-01 17:55:48 +00003103 } else if (MI.mayStore()) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003104 BasePos = 0;
3105 OffsetPos = 1;
Krzysztof Parzyszek8fb181c2016-08-01 17:55:48 +00003106 } else if (MI.mayLoad()) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003107 BasePos = 1;
3108 OffsetPos = 2;
3109 } else
3110 return false;
3111
Krzysztof Parzyszek8fb181c2016-08-01 17:55:48 +00003112 if (isPredicated(MI)) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003113 BasePos++;
3114 OffsetPos++;
3115 }
3116 if (isPostIncrement(MI)) {
3117 BasePos++;
3118 OffsetPos++;
3119 }
3120
Krzysztof Parzyszek8fb181c2016-08-01 17:55:48 +00003121 if (!MI.getOperand(BasePos).isReg() || !MI.getOperand(OffsetPos).isImm())
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003122 return false;
3123
3124 return true;
3125}
3126
Simon Pilgrim6ba672e2016-11-17 19:21:20 +00003127// Inserts branching instructions in reverse order of their occurrence.
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003128// e.g. jump_t t1 (i1)
3129// jump t2 (i2)
3130// Jumpers = {i2, i1}
3131SmallVector<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 Smith6307eb52016-02-23 02:46:52 +00003165 if (!isUnpredicatedTerminator(*I))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003166 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 Smith6307eb52016-02-23 02:46:52 +00003174 if (&*I != LastInst && !I->isBundle() && isUnpredicatedTerminator(*I)) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003175 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 Parzyszekf5cbac92016-04-29 15:49:13 +00003188short HexagonInstrInfo::getBaseWithLongOffset(short Opcode) const {
3189 if (Opcode < 0)
3190 return -1;
3191 return Hexagon::getBaseWithLongOffset(Opcode);
3192}
3193
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003194short HexagonInstrInfo::getBaseWithLongOffset(const MachineInstr &MI) const {
3195 return Hexagon::getBaseWithLongOffset(MI.getOpcode());
Krzysztof Parzyszekf5cbac92016-04-29 15:49:13 +00003196}
3197
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003198short HexagonInstrInfo::getBaseWithRegOffset(const MachineInstr &MI) const {
3199 return Hexagon::getBaseWithRegOffset(MI.getOpcode());
Krzysztof Parzyszekf5cbac92016-04-29 15:49:13 +00003200}
3201
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003202// Returns Operand Index for the constant extended instruction.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003203unsigned HexagonInstrInfo::getCExtOpNum(const MachineInstr &MI) const {
3204 const uint64_t F = MI.getDesc().TSFlags;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003205 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.
3210HexagonII::CompoundGroup HexagonInstrInfo::getCompoundCandidateGroup(
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003211 const MachineInstr &MI) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003212 unsigned DstReg, SrcReg, Src1Reg, Src2Reg;
3213
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003214 switch (MI.getOpcode()) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003215 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 Parzyszekf0b34a52016-07-29 21:49:42 +00003226 DstReg = MI.getOperand(0).getReg();
3227 Src1Reg = MI.getOperand(1).getReg();
3228 Src2Reg = MI.getOperand(2).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003229 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 Parzyszekf0b34a52016-07-29 21:49:42 +00003238 DstReg = MI.getOperand(0).getReg();
3239 SrcReg = MI.getOperand(1).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003240 if (Hexagon::PredRegsRegClass.contains(DstReg) &&
3241 (Hexagon::P0 == DstReg || Hexagon::P1 == DstReg) &&
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003242 isIntRegForSubInst(SrcReg) && MI.getOperand(2).isImm() &&
3243 ((isUInt<5>(MI.getOperand(2).getImm())) ||
3244 (MI.getOperand(2).getImm() == -1)))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003245 return HexagonII::HCG_A;
3246 break;
3247 case Hexagon::A2_tfr:
3248 // Rd = Rs
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003249 DstReg = MI.getOperand(0).getReg();
3250 SrcReg = MI.getOperand(1).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003251 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 Parzyszekf0b34a52016-07-29 21:49:42 +00003258 DstReg = MI.getOperand(0).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003259 if (isIntRegForSubInst(DstReg))
3260 return HexagonII::HCG_A;
3261 break;
3262 case Hexagon::S2_tstbit_i:
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003263 DstReg = MI.getOperand(0).getReg();
3264 Src1Reg = MI.getOperand(1).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003265 if (Hexagon::PredRegsRegClass.contains(DstReg) &&
3266 (Hexagon::P0 == DstReg || Hexagon::P1 == DstReg) &&
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003267 MI.getOperand(2).isImm() &&
3268 isIntRegForSubInst(Src1Reg) && (MI.getOperand(2).getImm() == 0))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003269 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 Parzyszekf0b34a52016-07-29 21:49:42 +00003279 Src1Reg = MI.getOperand(0).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003280 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 Parzyszek5a7bef92016-08-19 17:20:57 +00003290 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC:
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003291 return HexagonII::HCG_C;
3292 break;
3293 }
3294
3295 return HexagonII::HCG_None;
3296}
3297
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003298// Returns -1 when there is no opcode found.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003299unsigned HexagonInstrInfo::getCompoundOpcode(const MachineInstr &GA,
3300 const MachineInstr &GB) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003301 assert(getCompoundCandidateGroup(GA) == HexagonII::HCG_A);
3302 assert(getCompoundCandidateGroup(GB) == HexagonII::HCG_B);
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003303 if ((GA.getOpcode() != Hexagon::C2_cmpeqi) ||
3304 (GB.getOpcode() != Hexagon::J2_jumptnew))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003305 return -1;
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003306 unsigned DestReg = GA.getOperand(0).getReg();
3307 if (!GB.readsRegister(DestReg))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003308 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +00003316int 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +00003324 llvm_unreachable("Unexpected predicable instruction");
3325}
3326
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003327// Return the cur value instruction for a given store.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003328int HexagonInstrInfo::getDotCurOp(const MachineInstr &MI) const {
3329 switch (MI.getOpcode()) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003330 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +00003344// 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +00003423// Return the new value instruction for a given store.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003424int HexagonInstrInfo::getDotNewOp(const MachineInstr &MI) const {
3425 int NVOpcode = Hexagon::getNewValueOpcode(MI.getOpcode());
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003426 if (NVOpcode >= 0) // Valid new-value store instruction.
3427 return NVOpcode;
3428
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003429 switch (MI.getOpcode()) {
Krzysztof Parzyszeka72fad92017-02-10 15:33:13 +00003430 default:
3431 llvm::report_fatal_error(std::string("Unknown .new type: ") +
3432 std::to_string(MI.getOpcode()).c_str());
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003433 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 Parzyszekf0b34a52016-07-29 21:49:42 +00003470int HexagonInstrInfo::getDotNewPredJumpOp(const MachineInstr &MI,
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003471 const MachineBranchProbabilityInfo *MBPI) const {
3472 // We assume that block can have at most two successors.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003473 const MachineBasicBlock *Src = MI.getParent();
3474 const MachineOperand &BrTarget = MI.getOperand(1);
Krzysztof Parzyszeke720feb2017-03-02 21:49:49 +00003475 bool Taken = false;
3476 const BranchProbability OneHalf(1, 2);
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003477
Krzysztof Parzyszeke720feb2017-03-02 21:49:49 +00003478 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 Parzyszekb9a1c3a2015-11-24 14:55:26 +00003536
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003537 switch (MI.getOpcode()) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003538 case Hexagon::J2_jumpt:
Krzysztof Parzyszeke720feb2017-03-02 21:49:49 +00003539 return Taken ? Hexagon::J2_jumptnewpt : Hexagon::J2_jumptnew;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003540 case Hexagon::J2_jumpf:
Krzysztof Parzyszeke720feb2017-03-02 21:49:49 +00003541 return Taken ? Hexagon::J2_jumpfnewpt : Hexagon::J2_jumpfnew;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003542
3543 default:
3544 llvm_unreachable("Unexpected jump instruction.");
3545 }
3546}
3547
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003548// Return .new predicate version for an instruction.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003549int HexagonInstrInfo::getDotNewPredOp(const MachineInstr &MI,
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003550 const MachineBranchProbabilityInfo *MBPI) const {
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003551 switch (MI.getOpcode()) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003552 // Condtional Jumps
3553 case Hexagon::J2_jumpt:
3554 case Hexagon::J2_jumpf:
3555 return getDotNewPredJumpOp(MI, MBPI);
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003556 }
Krzysztof Parzyszeke720feb2017-03-02 21:49:49 +00003557
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 Parzyszekb9a1c3a2015-11-24 14:55:26 +00003564}
3565
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003566int HexagonInstrInfo::getDotOldOp(const int opc) const {
3567 int NewOp = opc;
3568 if (isPredicated(NewOp) && isPredicatedNew(NewOp)) { // Get predicate old form
3569 NewOp = Hexagon::getPredOldOpcode(NewOp);
3570 assert(NewOp >= 0 &&
3571 "Couldn't change predicate new instruction to its old form.");
3572 }
3573
3574 if (isNewValueStore(NewOp)) { // Convert into non-new-value format
3575 NewOp = Hexagon::getNonNVStore(NewOp);
3576 assert(NewOp >= 0 && "Couldn't change new-value store to its old form.");
3577 }
3578 return NewOp;
3579}
3580
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003581// See if instruction could potentially be a duplex candidate.
3582// If so, return its group. Zero otherwise.
3583HexagonII::SubInstructionGroup HexagonInstrInfo::getDuplexCandidateGroup(
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003584 const MachineInstr &MI) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003585 unsigned DstReg, SrcReg, Src1Reg, Src2Reg;
3586 auto &HRI = getRegisterInfo();
3587
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003588 switch (MI.getOpcode()) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003589 default:
3590 return HexagonII::HSIG_None;
3591 //
3592 // Group L1:
3593 //
3594 // Rd = memw(Rs+#u4:2)
3595 // Rd = memub(Rs+#u4:0)
3596 case Hexagon::L2_loadri_io:
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003597 DstReg = MI.getOperand(0).getReg();
3598 SrcReg = MI.getOperand(1).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003599 // Special case this one from Group L2.
3600 // Rd = memw(r29+#u5:2)
3601 if (isIntRegForSubInst(DstReg)) {
3602 if (Hexagon::IntRegsRegClass.contains(SrcReg) &&
3603 HRI.getStackRegister() == SrcReg &&
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003604 MI.getOperand(2).isImm() &&
3605 isShiftedUInt<5,2>(MI.getOperand(2).getImm()))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003606 return HexagonII::HSIG_L2;
3607 // Rd = memw(Rs+#u4:2)
3608 if (isIntRegForSubInst(SrcReg) &&
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003609 (MI.getOperand(2).isImm() &&
3610 isShiftedUInt<4,2>(MI.getOperand(2).getImm())))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003611 return HexagonII::HSIG_L1;
3612 }
3613 break;
3614 case Hexagon::L2_loadrub_io:
3615 // Rd = memub(Rs+#u4:0)
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003616 DstReg = MI.getOperand(0).getReg();
3617 SrcReg = MI.getOperand(1).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003618 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) &&
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003619 MI.getOperand(2).isImm() && isUInt<4>(MI.getOperand(2).getImm()))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003620 return HexagonII::HSIG_L1;
3621 break;
3622 //
3623 // Group L2:
3624 //
3625 // Rd = memh/memuh(Rs+#u3:1)
3626 // Rd = memb(Rs+#u3:0)
3627 // Rd = memw(r29+#u5:2) - Handled above.
3628 // Rdd = memd(r29+#u5:3)
3629 // deallocframe
3630 // [if ([!]p0[.new])] dealloc_return
3631 // [if ([!]p0[.new])] jumpr r31
3632 case Hexagon::L2_loadrh_io:
3633 case Hexagon::L2_loadruh_io:
3634 // Rd = memh/memuh(Rs+#u3:1)
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003635 DstReg = MI.getOperand(0).getReg();
3636 SrcReg = MI.getOperand(1).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003637 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) &&
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003638 MI.getOperand(2).isImm() &&
3639 isShiftedUInt<3,1>(MI.getOperand(2).getImm()))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003640 return HexagonII::HSIG_L2;
3641 break;
3642 case Hexagon::L2_loadrb_io:
3643 // Rd = memb(Rs+#u3:0)
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003644 DstReg = MI.getOperand(0).getReg();
3645 SrcReg = MI.getOperand(1).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003646 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) &&
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003647 MI.getOperand(2).isImm() &&
3648 isUInt<3>(MI.getOperand(2).getImm()))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003649 return HexagonII::HSIG_L2;
3650 break;
3651 case Hexagon::L2_loadrd_io:
3652 // Rdd = memd(r29+#u5:3)
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003653 DstReg = MI.getOperand(0).getReg();
3654 SrcReg = MI.getOperand(1).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003655 if (isDblRegForSubInst(DstReg, HRI) &&
3656 Hexagon::IntRegsRegClass.contains(SrcReg) &&
3657 HRI.getStackRegister() == SrcReg &&
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003658 MI.getOperand(2).isImm() &&
3659 isShiftedUInt<5,3>(MI.getOperand(2).getImm()))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003660 return HexagonII::HSIG_L2;
3661 break;
3662 // dealloc_return is not documented in Hexagon Manual, but marked
3663 // with A_SUBINSN attribute in iset_v4classic.py.
3664 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4:
Krzysztof Parzyszek5a7bef92016-08-19 17:20:57 +00003665 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC:
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003666 case Hexagon::L4_return:
3667 case Hexagon::L2_deallocframe:
3668 return HexagonII::HSIG_L2;
3669 case Hexagon::EH_RETURN_JMPR:
Krzysztof Parzyszekbe976d42016-08-12 11:12:02 +00003670 case Hexagon::PS_jmpret:
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003671 // jumpr r31
3672 // Actual form JMPR %PC<imp-def>, %R31<imp-use>, %R0<imp-use,internal>.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003673 DstReg = MI.getOperand(0).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003674 if (Hexagon::IntRegsRegClass.contains(DstReg) && (Hexagon::R31 == DstReg))
3675 return HexagonII::HSIG_L2;
3676 break;
Krzysztof Parzyszekbe976d42016-08-12 11:12:02 +00003677 case Hexagon::PS_jmprett:
3678 case Hexagon::PS_jmpretf:
3679 case Hexagon::PS_jmprettnewpt:
3680 case Hexagon::PS_jmpretfnewpt:
3681 case Hexagon::PS_jmprettnew:
3682 case Hexagon::PS_jmpretfnew:
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003683 DstReg = MI.getOperand(1).getReg();
3684 SrcReg = MI.getOperand(0).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003685 // [if ([!]p0[.new])] jumpr r31
3686 if ((Hexagon::PredRegsRegClass.contains(SrcReg) &&
3687 (Hexagon::P0 == SrcReg)) &&
3688 (Hexagon::IntRegsRegClass.contains(DstReg) && (Hexagon::R31 == DstReg)))
3689 return HexagonII::HSIG_L2;
Krzysztof Parzyszekfb4c4172016-08-19 19:29:15 +00003690 break;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003691 case Hexagon::L4_return_t :
3692 case Hexagon::L4_return_f :
3693 case Hexagon::L4_return_tnew_pnt :
3694 case Hexagon::L4_return_fnew_pnt :
3695 case Hexagon::L4_return_tnew_pt :
3696 case Hexagon::L4_return_fnew_pt :
3697 // [if ([!]p0[.new])] dealloc_return
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003698 SrcReg = MI.getOperand(0).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003699 if (Hexagon::PredRegsRegClass.contains(SrcReg) && (Hexagon::P0 == SrcReg))
3700 return HexagonII::HSIG_L2;
3701 break;
3702 //
3703 // Group S1:
3704 //
3705 // memw(Rs+#u4:2) = Rt
3706 // memb(Rs+#u4:0) = Rt
3707 case Hexagon::S2_storeri_io:
3708 // Special case this one from Group S2.
3709 // memw(r29+#u5:2) = Rt
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003710 Src1Reg = MI.getOperand(0).getReg();
3711 Src2Reg = MI.getOperand(2).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003712 if (Hexagon::IntRegsRegClass.contains(Src1Reg) &&
3713 isIntRegForSubInst(Src2Reg) &&
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003714 HRI.getStackRegister() == Src1Reg && MI.getOperand(1).isImm() &&
3715 isShiftedUInt<5,2>(MI.getOperand(1).getImm()))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003716 return HexagonII::HSIG_S2;
3717 // memw(Rs+#u4:2) = Rt
3718 if (isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg) &&
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003719 MI.getOperand(1).isImm() &&
3720 isShiftedUInt<4,2>(MI.getOperand(1).getImm()))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003721 return HexagonII::HSIG_S1;
3722 break;
3723 case Hexagon::S2_storerb_io:
3724 // memb(Rs+#u4:0) = Rt
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003725 Src1Reg = MI.getOperand(0).getReg();
3726 Src2Reg = MI.getOperand(2).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003727 if (isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg) &&
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003728 MI.getOperand(1).isImm() && isUInt<4>(MI.getOperand(1).getImm()))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003729 return HexagonII::HSIG_S1;
3730 break;
3731 //
3732 // Group S2:
3733 //
3734 // memh(Rs+#u3:1) = Rt
3735 // memw(r29+#u5:2) = Rt
3736 // memd(r29+#s6:3) = Rtt
3737 // memw(Rs+#u4:2) = #U1
3738 // memb(Rs+#u4) = #U1
3739 // allocframe(#u5:3)
3740 case Hexagon::S2_storerh_io:
3741 // memh(Rs+#u3:1) = Rt
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003742 Src1Reg = MI.getOperand(0).getReg();
3743 Src2Reg = MI.getOperand(2).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003744 if (isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg) &&
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003745 MI.getOperand(1).isImm() &&
3746 isShiftedUInt<3,1>(MI.getOperand(1).getImm()))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003747 return HexagonII::HSIG_S1;
3748 break;
3749 case Hexagon::S2_storerd_io:
3750 // memd(r29+#s6:3) = Rtt
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003751 Src1Reg = MI.getOperand(0).getReg();
3752 Src2Reg = MI.getOperand(2).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003753 if (isDblRegForSubInst(Src2Reg, HRI) &&
3754 Hexagon::IntRegsRegClass.contains(Src1Reg) &&
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003755 HRI.getStackRegister() == Src1Reg && MI.getOperand(1).isImm() &&
3756 isShiftedInt<6,3>(MI.getOperand(1).getImm()))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003757 return HexagonII::HSIG_S2;
3758 break;
3759 case Hexagon::S4_storeiri_io:
3760 // memw(Rs+#u4:2) = #U1
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003761 Src1Reg = MI.getOperand(0).getReg();
3762 if (isIntRegForSubInst(Src1Reg) && MI.getOperand(1).isImm() &&
3763 isShiftedUInt<4,2>(MI.getOperand(1).getImm()) &&
3764 MI.getOperand(2).isImm() && isUInt<1>(MI.getOperand(2).getImm()))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003765 return HexagonII::HSIG_S2;
3766 break;
3767 case Hexagon::S4_storeirb_io:
3768 // memb(Rs+#u4) = #U1
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003769 Src1Reg = MI.getOperand(0).getReg();
Krzysztof Parzyszekf2a4f8f2016-06-15 21:05:04 +00003770 if (isIntRegForSubInst(Src1Reg) &&
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003771 MI.getOperand(1).isImm() && isUInt<4>(MI.getOperand(1).getImm()) &&
3772 MI.getOperand(2).isImm() && isUInt<1>(MI.getOperand(2).getImm()))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003773 return HexagonII::HSIG_S2;
3774 break;
3775 case Hexagon::S2_allocframe:
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003776 if (MI.getOperand(0).isImm() &&
3777 isShiftedUInt<5,3>(MI.getOperand(0).getImm()))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003778 return HexagonII::HSIG_S1;
3779 break;
3780 //
3781 // Group A:
3782 //
3783 // Rx = add(Rx,#s7)
3784 // Rd = Rs
3785 // Rd = #u6
3786 // Rd = #-1
3787 // if ([!]P0[.new]) Rd = #0
3788 // Rd = add(r29,#u6:2)
3789 // Rx = add(Rx,Rs)
3790 // P0 = cmp.eq(Rs,#u2)
3791 // Rdd = combine(#0,Rs)
3792 // Rdd = combine(Rs,#0)
3793 // Rdd = combine(#u2,#U2)
3794 // Rd = add(Rs,#1)
3795 // Rd = add(Rs,#-1)
3796 // Rd = sxth/sxtb/zxtb/zxth(Rs)
3797 // Rd = and(Rs,#1)
3798 case Hexagon::A2_addi:
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003799 DstReg = MI.getOperand(0).getReg();
3800 SrcReg = MI.getOperand(1).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003801 if (isIntRegForSubInst(DstReg)) {
3802 // Rd = add(r29,#u6:2)
3803 if (Hexagon::IntRegsRegClass.contains(SrcReg) &&
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003804 HRI.getStackRegister() == SrcReg && MI.getOperand(2).isImm() &&
3805 isShiftedUInt<6,2>(MI.getOperand(2).getImm()))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003806 return HexagonII::HSIG_A;
3807 // Rx = add(Rx,#s7)
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003808 if ((DstReg == SrcReg) && MI.getOperand(2).isImm() &&
3809 isInt<7>(MI.getOperand(2).getImm()))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003810 return HexagonII::HSIG_A;
3811 // Rd = add(Rs,#1)
3812 // Rd = add(Rs,#-1)
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003813 if (isIntRegForSubInst(SrcReg) && MI.getOperand(2).isImm() &&
3814 ((MI.getOperand(2).getImm() == 1) ||
3815 (MI.getOperand(2).getImm() == -1)))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003816 return HexagonII::HSIG_A;
3817 }
3818 break;
3819 case Hexagon::A2_add:
3820 // Rx = add(Rx,Rs)
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003821 DstReg = MI.getOperand(0).getReg();
3822 Src1Reg = MI.getOperand(1).getReg();
3823 Src2Reg = MI.getOperand(2).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003824 if (isIntRegForSubInst(DstReg) && (DstReg == Src1Reg) &&
3825 isIntRegForSubInst(Src2Reg))
3826 return HexagonII::HSIG_A;
3827 break;
3828 case Hexagon::A2_andir:
3829 // Same as zxtb.
3830 // Rd16=and(Rs16,#255)
3831 // Rd16=and(Rs16,#1)
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003832 DstReg = MI.getOperand(0).getReg();
3833 SrcReg = MI.getOperand(1).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003834 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) &&
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003835 MI.getOperand(2).isImm() &&
3836 ((MI.getOperand(2).getImm() == 1) ||
3837 (MI.getOperand(2).getImm() == 255)))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003838 return HexagonII::HSIG_A;
3839 break;
3840 case Hexagon::A2_tfr:
3841 // Rd = Rs
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003842 DstReg = MI.getOperand(0).getReg();
3843 SrcReg = MI.getOperand(1).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003844 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg))
3845 return HexagonII::HSIG_A;
3846 break;
3847 case Hexagon::A2_tfrsi:
3848 // Rd = #u6
3849 // Do not test for #u6 size since the const is getting extended
3850 // regardless and compound could be formed.
3851 // Rd = #-1
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003852 DstReg = MI.getOperand(0).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003853 if (isIntRegForSubInst(DstReg))
3854 return HexagonII::HSIG_A;
3855 break;
3856 case Hexagon::C2_cmoveit:
3857 case Hexagon::C2_cmovenewit:
3858 case Hexagon::C2_cmoveif:
3859 case Hexagon::C2_cmovenewif:
3860 // if ([!]P0[.new]) Rd = #0
3861 // Actual form:
3862 // %R16<def> = C2_cmovenewit %P0<internal>, 0, %R16<imp-use,undef>;
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003863 DstReg = MI.getOperand(0).getReg();
3864 SrcReg = MI.getOperand(1).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003865 if (isIntRegForSubInst(DstReg) &&
3866 Hexagon::PredRegsRegClass.contains(SrcReg) && Hexagon::P0 == SrcReg &&
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003867 MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0)
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003868 return HexagonII::HSIG_A;
3869 break;
3870 case Hexagon::C2_cmpeqi:
3871 // P0 = cmp.eq(Rs,#u2)
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003872 DstReg = MI.getOperand(0).getReg();
3873 SrcReg = MI.getOperand(1).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003874 if (Hexagon::PredRegsRegClass.contains(DstReg) &&
3875 Hexagon::P0 == DstReg && isIntRegForSubInst(SrcReg) &&
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003876 MI.getOperand(2).isImm() && isUInt<2>(MI.getOperand(2).getImm()))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003877 return HexagonII::HSIG_A;
3878 break;
3879 case Hexagon::A2_combineii:
3880 case Hexagon::A4_combineii:
3881 // Rdd = combine(#u2,#U2)
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003882 DstReg = MI.getOperand(0).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003883 if (isDblRegForSubInst(DstReg, HRI) &&
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003884 ((MI.getOperand(1).isImm() && isUInt<2>(MI.getOperand(1).getImm())) ||
3885 (MI.getOperand(1).isGlobal() &&
3886 isUInt<2>(MI.getOperand(1).getOffset()))) &&
3887 ((MI.getOperand(2).isImm() && isUInt<2>(MI.getOperand(2).getImm())) ||
3888 (MI.getOperand(2).isGlobal() &&
3889 isUInt<2>(MI.getOperand(2).getOffset()))))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003890 return HexagonII::HSIG_A;
3891 break;
3892 case Hexagon::A4_combineri:
3893 // Rdd = combine(Rs,#0)
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003894 DstReg = MI.getOperand(0).getReg();
3895 SrcReg = MI.getOperand(1).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003896 if (isDblRegForSubInst(DstReg, HRI) && isIntRegForSubInst(SrcReg) &&
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003897 ((MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0) ||
3898 (MI.getOperand(2).isGlobal() && MI.getOperand(2).getOffset() == 0)))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003899 return HexagonII::HSIG_A;
3900 break;
3901 case Hexagon::A4_combineir:
3902 // Rdd = combine(#0,Rs)
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003903 DstReg = MI.getOperand(0).getReg();
3904 SrcReg = MI.getOperand(2).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003905 if (isDblRegForSubInst(DstReg, HRI) && isIntRegForSubInst(SrcReg) &&
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003906 ((MI.getOperand(1).isImm() && MI.getOperand(1).getImm() == 0) ||
3907 (MI.getOperand(1).isGlobal() && MI.getOperand(1).getOffset() == 0)))
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003908 return HexagonII::HSIG_A;
3909 break;
3910 case Hexagon::A2_sxtb:
3911 case Hexagon::A2_sxth:
3912 case Hexagon::A2_zxtb:
3913 case Hexagon::A2_zxth:
3914 // Rd = sxth/sxtb/zxtb/zxth(Rs)
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003915 DstReg = MI.getOperand(0).getReg();
3916 SrcReg = MI.getOperand(1).getReg();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003917 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg))
3918 return HexagonII::HSIG_A;
3919 break;
3920 }
3921
3922 return HexagonII::HSIG_None;
3923}
3924
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003925short HexagonInstrInfo::getEquivalentHWInstr(const MachineInstr &MI) const {
3926 return Hexagon::getRealHWInstr(MI.getOpcode(), Hexagon::InstrType_Real);
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003927}
3928
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003929// Return first non-debug instruction in the basic block.
3930MachineInstr *HexagonInstrInfo::getFirstNonDbgInst(MachineBasicBlock *BB)
3931 const {
3932 for (auto MII = BB->instr_begin(), End = BB->instr_end(); MII != End; MII++) {
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003933 MachineInstr &MI = *MII;
3934 if (MI.isDebugValue())
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003935 continue;
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003936 return &MI;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003937 }
3938 return nullptr;
3939}
3940
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003941unsigned HexagonInstrInfo::getInstrTimingClassLatency(
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003942 const InstrItineraryData *ItinData, const MachineInstr &MI) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003943 // Default to one cycle for no itinerary. However, an "empty" itinerary may
3944 // still have a MinLatency property, which getStageLatency checks.
3945 if (!ItinData)
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003946 return getInstrLatency(ItinData, MI);
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003947
3948 // Get the latency embedded in the itinerary. If we're not using timing class
3949 // latencies or if we using BSB scheduling, then restrict the maximum latency
3950 // to 1 (that is, either 0 or 1).
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003951 if (MI.isTransient())
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003952 return 0;
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003953 unsigned Latency = ItinData->getStageLatency(MI.getDesc().getSchedClass());
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003954 if (!EnableTimingClassLatency ||
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003955 MI.getParent()->getParent()->getSubtarget<HexagonSubtarget>().
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003956 useBSBScheduling())
3957 if (Latency > 1)
3958 Latency = 1;
3959 return Latency;
3960}
3961
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003962// inverts the predication logic.
3963// p -> NotP
3964// NotP -> P
3965bool HexagonInstrInfo::getInvertedPredSense(
3966 SmallVectorImpl<MachineOperand> &Cond) const {
3967 if (Cond.empty())
3968 return false;
3969 unsigned Opc = getInvertedPredicatedOpcode(Cond[0].getImm());
3970 Cond[0].setImm(Opc);
3971 return true;
3972}
3973
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003974unsigned HexagonInstrInfo::getInvertedPredicatedOpcode(const int Opc) const {
3975 int InvPredOpcode;
3976 InvPredOpcode = isPredicatedTrue(Opc) ? Hexagon::getFalsePredOpcode(Opc)
3977 : Hexagon::getTruePredOpcode(Opc);
3978 if (InvPredOpcode >= 0) // Valid instruction with the inverted predicate.
3979 return InvPredOpcode;
3980
3981 llvm_unreachable("Unexpected predicated instruction");
3982}
3983
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003984// Returns the max value that doesn't need to be extended.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003985int HexagonInstrInfo::getMaxValue(const MachineInstr &MI) const {
3986 const uint64_t F = MI.getDesc().TSFlags;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00003987 unsigned isSigned = (F >> HexagonII::ExtentSignedPos)
3988 & HexagonII::ExtentSignedMask;
3989 unsigned bits = (F >> HexagonII::ExtentBitsPos)
3990 & HexagonII::ExtentBitsMask;
3991
3992 if (isSigned) // if value is signed
3993 return ~(-1U << (bits - 1));
3994 else
3995 return ~(-1U << bits);
3996}
3997
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00003998unsigned HexagonInstrInfo::getMemAccessSize(const MachineInstr &MI) const {
3999 const uint64_t F = MI.getDesc().TSFlags;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004000 return (F >> HexagonII::MemAccessSizePos) & HexagonII::MemAccesSizeMask;
4001}
4002
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004003// Returns the min value that doesn't need to be extended.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004004int HexagonInstrInfo::getMinValue(const MachineInstr &MI) const {
4005 const uint64_t F = MI.getDesc().TSFlags;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004006 unsigned isSigned = (F >> HexagonII::ExtentSignedPos)
4007 & HexagonII::ExtentSignedMask;
4008 unsigned bits = (F >> HexagonII::ExtentBitsPos)
4009 & HexagonII::ExtentBitsMask;
4010
4011 if (isSigned) // if value is signed
4012 return -1U << (bits - 1);
4013 else
4014 return 0;
4015}
4016
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004017// Returns opcode of the non-extended equivalent instruction.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004018short HexagonInstrInfo::getNonExtOpcode(const MachineInstr &MI) const {
Jyotsna Verma84256432013-03-01 17:37:13 +00004019 // Check if the instruction has a register form that uses register in place
4020 // of the extended operand, if so return that as the non-extended form.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004021 short NonExtOpcode = Hexagon::getRegForm(MI.getOpcode());
Jyotsna Verma84256432013-03-01 17:37:13 +00004022 if (NonExtOpcode >= 0)
4023 return NonExtOpcode;
4024
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004025 if (MI.getDesc().mayLoad() || MI.getDesc().mayStore()) {
Alp Tokercb402912014-01-24 17:20:08 +00004026 // Check addressing mode and retrieve non-ext equivalent instruction.
Jyotsna Verma84256432013-03-01 17:37:13 +00004027 switch (getAddrMode(MI)) {
4028 case HexagonII::Absolute :
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004029 return Hexagon::getBaseWithImmOffset(MI.getOpcode());
Jyotsna Verma84256432013-03-01 17:37:13 +00004030 case HexagonII::BaseImmOffset :
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004031 return Hexagon::getBaseWithRegOffset(MI.getOpcode());
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004032 case HexagonII::BaseLongOffset:
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004033 return Hexagon::getRegShlForm(MI.getOpcode());
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004034
Jyotsna Verma84256432013-03-01 17:37:13 +00004035 default:
4036 return -1;
4037 }
4038 }
4039 return -1;
4040}
Jyotsna Verma5ed51812013-05-01 21:37:34 +00004041
Ahmed Bougachac88bf542015-06-11 19:30:37 +00004042bool HexagonInstrInfo::getPredReg(ArrayRef<MachineOperand> Cond,
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004043 unsigned &PredReg, unsigned &PredRegPos, unsigned &PredRegFlags) const {
Brendon Cahoondf43e682015-05-08 16:16:29 +00004044 if (Cond.empty())
4045 return false;
4046 assert(Cond.size() == 2);
4047 if (isNewValueJump(Cond[0].getImm()) || Cond[1].isMBB()) {
Krzysztof Parzyszekfb4c4172016-08-19 19:29:15 +00004048 DEBUG(dbgs() << "No predregs for new-value jumps/endloop");
4049 return false;
Brendon Cahoondf43e682015-05-08 16:16:29 +00004050 }
4051 PredReg = Cond[1].getReg();
4052 PredRegPos = 1;
4053 // See IfConversion.cpp why we add RegState::Implicit | RegState::Undef
4054 PredRegFlags = 0;
4055 if (Cond[1].isImplicit())
4056 PredRegFlags = RegState::Implicit;
4057 if (Cond[1].isUndef())
4058 PredRegFlags |= RegState::Undef;
4059 return true;
4060}
4061
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004062short HexagonInstrInfo::getPseudoInstrPair(const MachineInstr &MI) const {
4063 return Hexagon::getRealHWInstr(MI.getOpcode(), Hexagon::InstrType_Pseudo);
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004064}
4065
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004066short HexagonInstrInfo::getRegForm(const MachineInstr &MI) const {
4067 return Hexagon::getRegForm(MI.getOpcode());
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004068}
4069
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004070// Return the number of bytes required to encode the instruction.
4071// Hexagon instructions are fixed length, 4 bytes, unless they
4072// use a constant extender, which requires another 4 bytes.
4073// For debug instructions and prolog labels, return 0.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004074unsigned HexagonInstrInfo::getSize(const MachineInstr &MI) const {
4075 if (MI.isDebugValue() || MI.isPosition())
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004076 return 0;
4077
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004078 unsigned Size = MI.getDesc().getSize();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004079 if (!Size)
4080 // Assume the default insn size in case it cannot be determined
4081 // for whatever reason.
4082 Size = HEXAGON_INSTR_SIZE;
4083
4084 if (isConstExtended(MI) || isExtended(MI))
4085 Size += HEXAGON_INSTR_SIZE;
4086
4087 // Try and compute number of instructions in asm.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004088 if (BranchRelaxAsmLarge && MI.getOpcode() == Hexagon::INLINEASM) {
4089 const MachineBasicBlock &MBB = *MI.getParent();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004090 const MachineFunction *MF = MBB.getParent();
4091 const MCAsmInfo *MAI = MF->getTarget().getMCAsmInfo();
4092
4093 // Count the number of register definitions to find the asm string.
4094 unsigned NumDefs = 0;
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004095 for (; MI.getOperand(NumDefs).isReg() && MI.getOperand(NumDefs).isDef();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004096 ++NumDefs)
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004097 assert(NumDefs != MI.getNumOperands()-2 && "No asm string?");
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004098
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004099 assert(MI.getOperand(NumDefs).isSymbol() && "No asm string?");
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004100 // Disassemble the AsmStr and approximate number of instructions.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004101 const char *AsmStr = MI.getOperand(NumDefs).getSymbolName();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004102 Size = getInlineAsmLength(AsmStr, *MAI);
4103 }
4104
4105 return Size;
4106}
4107
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004108uint64_t HexagonInstrInfo::getType(const MachineInstr &MI) const {
4109 const uint64_t F = MI.getDesc().TSFlags;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004110 return (F >> HexagonII::TypePos) & HexagonII::TypeMask;
4111}
4112
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004113unsigned HexagonInstrInfo::getUnits(const MachineInstr &MI) const {
4114 const TargetSubtargetInfo &ST = MI.getParent()->getParent()->getSubtarget();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004115 const InstrItineraryData &II = *ST.getInstrItineraryData();
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004116 const InstrStage &IS = *II.beginStage(MI.getDesc().getSchedClass());
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004117
4118 return IS.getUnits();
4119}
4120
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004121unsigned HexagonInstrInfo::getValidSubTargets(const unsigned Opcode) const {
4122 const uint64_t F = get(Opcode).TSFlags;
4123 return (F >> HexagonII::validSubTargetPos) & HexagonII::validSubTargetMask;
4124}
4125
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004126// Calculate size of the basic block without debug instructions.
4127unsigned HexagonInstrInfo::nonDbgBBSize(const MachineBasicBlock *BB) const {
4128 return nonDbgMICount(BB->instr_begin(), BB->instr_end());
4129}
4130
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004131unsigned HexagonInstrInfo::nonDbgBundleSize(
4132 MachineBasicBlock::const_iterator BundleHead) const {
4133 assert(BundleHead->isBundle() && "Not a bundle header");
Duncan P. N. Exon Smithd84f6002016-02-22 21:30:15 +00004134 auto MII = BundleHead.getInstrIterator();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004135 // Skip the bundle header.
Matthias Braunc8440dd2016-10-25 02:55:17 +00004136 return nonDbgMICount(++MII, getBundleEnd(BundleHead.getInstrIterator()));
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004137}
4138
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004139/// immediateExtend - Changes the instruction in place to one using an immediate
4140/// extender.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004141void HexagonInstrInfo::immediateExtend(MachineInstr &MI) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004142 assert((isExtendable(MI)||isConstExtended(MI)) &&
4143 "Instruction must be extendable");
4144 // Find which operand is extendable.
4145 short ExtOpNum = getCExtOpNum(MI);
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004146 MachineOperand &MO = MI.getOperand(ExtOpNum);
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004147 // This needs to be something we understand.
4148 assert((MO.isMBB() || MO.isImm()) &&
4149 "Branch with unknown extendable field type");
4150 // Mark given operand as extended.
4151 MO.addTargetFlag(HexagonII::HMOTF_ConstExtended);
4152}
4153
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004154bool HexagonInstrInfo::invertAndChangeJumpTarget(
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004155 MachineInstr &MI, MachineBasicBlock *NewTarget) const {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004156 DEBUG(dbgs() << "\n[invertAndChangeJumpTarget] to BB#"
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004157 << NewTarget->getNumber(); MI.dump(););
4158 assert(MI.isBranch());
4159 unsigned NewOpcode = getInvertedPredicatedOpcode(MI.getOpcode());
4160 int TargetPos = MI.getNumOperands() - 1;
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004161 // In general branch target is the last operand,
4162 // but some implicit defs added at the end might change it.
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004163 while ((TargetPos > -1) && !MI.getOperand(TargetPos).isMBB())
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004164 --TargetPos;
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004165 assert((TargetPos >= 0) && MI.getOperand(TargetPos).isMBB());
4166 MI.getOperand(TargetPos).setMBB(NewTarget);
4167 if (EnableBranchPrediction && isPredicatedNew(MI)) {
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004168 NewOpcode = reversePrediction(NewOpcode);
4169 }
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004170 MI.setDesc(get(NewOpcode));
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004171 return true;
4172}
4173
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004174void HexagonInstrInfo::genAllInsnTimingClasses(MachineFunction &MF) const {
4175 /* +++ The code below is used to generate complete set of Hexagon Insn +++ */
4176 MachineFunction::iterator A = MF.begin();
4177 MachineBasicBlock &B = *A;
4178 MachineBasicBlock::iterator I = B.begin();
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004179 DebugLoc DL = I->getDebugLoc();
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004180 MachineInstr *NewMI;
4181
4182 for (unsigned insn = TargetOpcode::GENERIC_OP_END+1;
4183 insn < Hexagon::INSTRUCTION_LIST_END; ++insn) {
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004184 NewMI = BuildMI(B, I, DL, get(insn));
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004185 DEBUG(dbgs() << "\n" << getName(NewMI->getOpcode()) <<
4186 " Class: " << NewMI->getDesc().getSchedClass());
4187 NewMI->eraseFromParent();
4188 }
4189 /* --- The code above is used to generate complete set of Hexagon Insn --- */
4190}
4191
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004192// inverts the predication logic.
4193// p -> NotP
4194// NotP -> P
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004195bool HexagonInstrInfo::reversePredSense(MachineInstr &MI) const {
4196 DEBUG(dbgs() << "\nTrying to reverse pred. sense of:"; MI.dump());
4197 MI.setDesc(get(getInvertedPredicatedOpcode(MI.getOpcode())));
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004198 return true;
4199}
4200
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004201// Reverse the branch prediction.
4202unsigned HexagonInstrInfo::reversePrediction(unsigned Opcode) const {
4203 int PredRevOpcode = -1;
4204 if (isPredictedTaken(Opcode))
4205 PredRevOpcode = Hexagon::notTakenBranchPrediction(Opcode);
4206 else
4207 PredRevOpcode = Hexagon::takenBranchPrediction(Opcode);
4208 assert(PredRevOpcode > 0);
4209 return PredRevOpcode;
4210}
4211
Krzysztof Parzyszekb9a1c3a2015-11-24 14:55:26 +00004212// TODO: Add more rigorous validation.
4213bool HexagonInstrInfo::validateBranchCond(const ArrayRef<MachineOperand> &Cond)
4214 const {
4215 return Cond.empty() || (Cond[0].isImm() && (Cond.size() != 1));
4216}
4217
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +00004218short HexagonInstrInfo::xformRegToImmOffset(const MachineInstr &MI) const {
4219 return Hexagon::xformRegToImmOffset(MI.getOpcode());
Krzysztof Parzyszekf5cbac92016-04-29 15:49:13 +00004220}