LLVM 20.0.0git
HexagonInstrInfo.cpp
Go to the documentation of this file.
1//===- HexagonInstrInfo.cpp - Hexagon Instruction Information -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the Hexagon implementation of the TargetInstrInfo class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "HexagonInstrInfo.h"
16#include "HexagonRegisterInfo.h"
17#include "HexagonSubtarget.h"
18#include "llvm/ADT/ArrayRef.h"
22#include "llvm/ADT/StringRef.h"
41#include "llvm/IR/DebugLoc.h"
43#include "llvm/MC/MCAsmInfo.h"
45#include "llvm/MC/MCInstrDesc.h"
49#include "llvm/Support/Debug.h"
54#include <cassert>
55#include <cctype>
56#include <cstdint>
57#include <cstring>
58#include <iterator>
59#include <optional>
60#include <string>
61#include <utility>
62
63using namespace llvm;
64
65#define DEBUG_TYPE "hexagon-instrinfo"
66
67#define GET_INSTRINFO_CTOR_DTOR
68#define GET_INSTRMAP_INFO
70#include "HexagonGenDFAPacketizer.inc"
71#include "HexagonGenInstrInfo.inc"
72
73cl::opt<bool> ScheduleInlineAsm("hexagon-sched-inline-asm", cl::Hidden,
74 cl::init(false), cl::desc("Do not consider inline-asm a scheduling/"
75 "packetization boundary."));
76
77static cl::opt<bool> EnableBranchPrediction("hexagon-enable-branch-prediction",
78 cl::Hidden, cl::init(true), cl::desc("Enable branch prediction"));
79
81 "disable-hexagon-nv-schedule", cl::Hidden,
82 cl::desc("Disable schedule adjustment for new value stores."));
83
85 "enable-timing-class-latency", cl::Hidden, cl::init(false),
86 cl::desc("Enable timing class latency"));
87
89 "enable-alu-forwarding", cl::Hidden, cl::init(true),
90 cl::desc("Enable vec alu forwarding"));
91
93 "enable-acc-forwarding", cl::Hidden, cl::init(true),
94 cl::desc("Enable vec acc forwarding"));
95
96static cl::opt<bool> BranchRelaxAsmLarge("branch-relax-asm-large",
97 cl::init(true), cl::Hidden,
98 cl::desc("branch relax asm"));
99
100static cl::opt<bool>
101 UseDFAHazardRec("dfa-hazard-rec", cl::init(true), cl::Hidden,
102 cl::desc("Use the DFA based hazard recognizer."));
103
104/// Constants for Hexagon instructions.
105const int Hexagon_MEMW_OFFSET_MAX = 4095;
106const int Hexagon_MEMW_OFFSET_MIN = -4096;
107const int Hexagon_MEMD_OFFSET_MAX = 8191;
108const int Hexagon_MEMD_OFFSET_MIN = -8192;
109const int Hexagon_MEMH_OFFSET_MAX = 2047;
110const int Hexagon_MEMH_OFFSET_MIN = -2048;
111const int Hexagon_MEMB_OFFSET_MAX = 1023;
112const int Hexagon_MEMB_OFFSET_MIN = -1024;
113const int Hexagon_ADDI_OFFSET_MAX = 32767;
114const int Hexagon_ADDI_OFFSET_MIN = -32768;
115
116// Pin the vtable to this file.
117void HexagonInstrInfo::anchor() {}
118
120 : HexagonGenInstrInfo(Hexagon::ADJCALLSTACKDOWN, Hexagon::ADJCALLSTACKUP),
121 Subtarget(ST) {}
122
123namespace llvm {
124namespace HexagonFUnits {
125 bool isSlot0Only(unsigned units);
126}
127}
128
129static bool isIntRegForSubInst(Register Reg) {
130 return (Reg >= Hexagon::R0 && Reg <= Hexagon::R7) ||
131 (Reg >= Hexagon::R16 && Reg <= Hexagon::R23);
132}
133
134static bool isDblRegForSubInst(Register Reg, const HexagonRegisterInfo &HRI) {
135 return isIntRegForSubInst(HRI.getSubReg(Reg, Hexagon::isub_lo)) &&
136 isIntRegForSubInst(HRI.getSubReg(Reg, Hexagon::isub_hi));
137}
138
139/// Calculate number of instructions excluding the debug instructions.
142 unsigned Count = 0;
143 for (; MIB != MIE; ++MIB) {
144 if (!MIB->isDebugInstr())
145 ++Count;
146 }
147 return Count;
148}
149
150// Check if the A2_tfrsi instruction is cheap or not. If the operand has
151// to be constant-extendend it is not cheap since it occupies two slots
152// in a packet.
154 // Enable the following steps only at Os/Oz
155 if (!(MI.getMF()->getFunction().hasOptSize()))
156 return MI.isAsCheapAsAMove();
157
158 if (MI.getOpcode() == Hexagon::A2_tfrsi) {
159 auto Op = MI.getOperand(1);
160 // If the instruction has a global address as operand, it is not cheap
161 // since the operand will be constant extended.
162 if (Op.isGlobal())
163 return false;
164 // If the instruction has an operand of size > 16bits, its will be
165 // const-extended and hence, it is not cheap.
166 if (Op.isImm()) {
167 int64_t Imm = Op.getImm();
168 if (!isInt<16>(Imm))
169 return false;
170 }
171 }
172 return MI.isAsCheapAsAMove();
173}
174
175// Do not sink floating point instructions that updates USR register.
176// Example:
177// feclearexcept
178// F2_conv_w2sf
179// fetestexcept
180// MachineSink sinks F2_conv_w2sf and we are not able to catch exceptions.
181// TODO: On some of these floating point instructions, USR is marked as Use.
182// In reality, these instructions also Def the USR. If USR is marked as Def,
183// some of the assumptions in assembler packetization are broken.
185 // Assumption: A floating point instruction that reads the USR will write
186 // the USR as well.
187 if (isFloat(MI) && MI.hasRegisterImplicitUseOperand(Hexagon::USR))
188 return false;
189 return true;
190}
191
192/// Find the hardware loop instruction used to set-up the specified loop.
193/// On Hexagon, we have two instructions used to set-up the hardware loop
194/// (LOOP0, LOOP1) with corresponding endloop (ENDLOOP0, ENDLOOP1) instructions
195/// to indicate the end of a loop.
197 unsigned EndLoopOp, MachineBasicBlock *TargetBB,
199 unsigned LOOPi;
200 unsigned LOOPr;
201 if (EndLoopOp == Hexagon::ENDLOOP0) {
202 LOOPi = Hexagon::J2_loop0i;
203 LOOPr = Hexagon::J2_loop0r;
204 } else { // EndLoopOp == Hexagon::EndLOOP1
205 LOOPi = Hexagon::J2_loop1i;
206 LOOPr = Hexagon::J2_loop1r;
207 }
208
209 // The loop set-up instruction will be in a predecessor block
210 for (MachineBasicBlock *PB : BB->predecessors()) {
211 // If this has been visited, already skip it.
212 if (!Visited.insert(PB).second)
213 continue;
214 if (PB == BB)
215 continue;
216 for (MachineInstr &I : llvm::reverse(PB->instrs())) {
217 unsigned Opc = I.getOpcode();
218 if (Opc == LOOPi || Opc == LOOPr)
219 return &I;
220 // We've reached a different loop, which means the loop01 has been
221 // removed.
222 if (Opc == EndLoopOp && I.getOperand(0).getMBB() != TargetBB)
223 return nullptr;
224 }
225 // Check the predecessors for the LOOP instruction.
226 if (MachineInstr *Loop = findLoopInstr(PB, EndLoopOp, TargetBB, Visited))
227 return Loop;
228 }
229 return nullptr;
230}
231
232/// Gather register def/uses from MI.
233/// This treats possible (predicated) defs as actually happening ones
234/// (conservatively).
235static inline void parseOperands(const MachineInstr &MI,
237 Defs.clear();
238 Uses.clear();
239
240 for (const MachineOperand &MO : MI.operands()) {
241 if (!MO.isReg())
242 continue;
243
244 Register Reg = MO.getReg();
245 if (!Reg)
246 continue;
247
248 if (MO.isUse())
249 Uses.push_back(MO.getReg());
250
251 if (MO.isDef())
252 Defs.push_back(MO.getReg());
253 }
254}
255
256// Position dependent, so check twice for swap.
257static bool isDuplexPairMatch(unsigned Ga, unsigned Gb) {
258 switch (Ga) {
260 default:
261 return false;
263 return (Gb == HexagonII::HSIG_L1 || Gb == HexagonII::HSIG_A);
265 return (Gb == HexagonII::HSIG_L1 || Gb == HexagonII::HSIG_L2 ||
266 Gb == HexagonII::HSIG_A);
268 return (Gb == HexagonII::HSIG_L1 || Gb == HexagonII::HSIG_L2 ||
271 return (Gb == HexagonII::HSIG_L1 || Gb == HexagonII::HSIG_L2 ||
272 Gb == HexagonII::HSIG_S1 || Gb == HexagonII::HSIG_S2 ||
273 Gb == HexagonII::HSIG_A);
275 return (Gb == HexagonII::HSIG_A);
277 return (Gb == HexagonII::HSIG_Compound);
278 }
279 return false;
280}
281
282/// isLoadFromStackSlot - If the specified machine instruction is a direct
283/// load from a stack slot, return the virtual or physical register number of
284/// the destination along with the FrameIndex of the loaded stack slot. If
285/// not, return 0. This predicate must return 0 if the instruction has
286/// any side effects other than loading from the stack slot.
288 int &FrameIndex) const {
289 switch (MI.getOpcode()) {
290 default:
291 break;
292 case Hexagon::L2_loadri_io:
293 case Hexagon::L2_loadrd_io:
294 case Hexagon::V6_vL32b_ai:
295 case Hexagon::V6_vL32b_nt_ai:
296 case Hexagon::V6_vL32Ub_ai:
297 case Hexagon::LDriw_pred:
298 case Hexagon::LDriw_ctr:
299 case Hexagon::PS_vloadrq_ai:
300 case Hexagon::PS_vloadrw_ai:
301 case Hexagon::PS_vloadrw_nt_ai: {
302 const MachineOperand OpFI = MI.getOperand(1);
303 if (!OpFI.isFI())
304 return 0;
305 const MachineOperand OpOff = MI.getOperand(2);
306 if (!OpOff.isImm() || OpOff.getImm() != 0)
307 return 0;
308 FrameIndex = OpFI.getIndex();
309 return MI.getOperand(0).getReg();
310 }
311
312 case Hexagon::L2_ploadrit_io:
313 case Hexagon::L2_ploadrif_io:
314 case Hexagon::L2_ploadrdt_io:
315 case Hexagon::L2_ploadrdf_io: {
316 const MachineOperand OpFI = MI.getOperand(2);
317 if (!OpFI.isFI())
318 return 0;
319 const MachineOperand OpOff = MI.getOperand(3);
320 if (!OpOff.isImm() || OpOff.getImm() != 0)
321 return 0;
322 FrameIndex = OpFI.getIndex();
323 return MI.getOperand(0).getReg();
324 }
325 }
326
327 return 0;
328}
329
330/// isStoreToStackSlot - If the specified machine instruction is a direct
331/// store to a stack slot, return the virtual or physical register number of
332/// the source reg along with the FrameIndex of the loaded stack slot. If
333/// not, return 0. This predicate must return 0 if the instruction has
334/// any side effects other than storing to the stack slot.
336 int &FrameIndex) const {
337 switch (MI.getOpcode()) {
338 default:
339 break;
340 case Hexagon::S2_storerb_io:
341 case Hexagon::S2_storerh_io:
342 case Hexagon::S2_storeri_io:
343 case Hexagon::S2_storerd_io:
344 case Hexagon::V6_vS32b_ai:
345 case Hexagon::V6_vS32Ub_ai:
346 case Hexagon::STriw_pred:
347 case Hexagon::STriw_ctr:
348 case Hexagon::PS_vstorerq_ai:
349 case Hexagon::PS_vstorerw_ai: {
350 const MachineOperand &OpFI = MI.getOperand(0);
351 if (!OpFI.isFI())
352 return 0;
353 const MachineOperand &OpOff = MI.getOperand(1);
354 if (!OpOff.isImm() || OpOff.getImm() != 0)
355 return 0;
356 FrameIndex = OpFI.getIndex();
357 return MI.getOperand(2).getReg();
358 }
359
360 case Hexagon::S2_pstorerbt_io:
361 case Hexagon::S2_pstorerbf_io:
362 case Hexagon::S2_pstorerht_io:
363 case Hexagon::S2_pstorerhf_io:
364 case Hexagon::S2_pstorerit_io:
365 case Hexagon::S2_pstorerif_io:
366 case Hexagon::S2_pstorerdt_io:
367 case Hexagon::S2_pstorerdf_io: {
368 const MachineOperand &OpFI = MI.getOperand(1);
369 if (!OpFI.isFI())
370 return 0;
371 const MachineOperand &OpOff = MI.getOperand(2);
372 if (!OpOff.isImm() || OpOff.getImm() != 0)
373 return 0;
374 FrameIndex = OpFI.getIndex();
375 return MI.getOperand(3).getReg();
376 }
377 }
378
379 return 0;
380}
381
382/// This function checks if the instruction or bundle of instructions
383/// has load from stack slot and returns frameindex and machine memory
384/// operand of that instruction if true.
386 const MachineInstr &MI,
388 if (MI.isBundle()) {
389 const MachineBasicBlock *MBB = MI.getParent();
391 for (++MII; MII != MBB->instr_end() && MII->isInsideBundle(); ++MII)
392 if (TargetInstrInfo::hasLoadFromStackSlot(*MII, Accesses))
393 return true;
394 return false;
395 }
396
398}
399
400/// This function checks if the instruction or bundle of instructions
401/// has store to stack slot and returns frameindex and machine memory
402/// operand of that instruction if true.
404 const MachineInstr &MI,
406 if (MI.isBundle()) {
407 const MachineBasicBlock *MBB = MI.getParent();
409 for (++MII; MII != MBB->instr_end() && MII->isInsideBundle(); ++MII)
410 if (TargetInstrInfo::hasStoreToStackSlot(*MII, Accesses))
411 return true;
412 return false;
413 }
414
416}
417
418/// This function can analyze one/two way branching only and should (mostly) be
419/// called by target independent side.
420/// First entry is always the opcode of the branching instruction, except when
421/// the Cond vector is supposed to be empty, e.g., when analyzeBranch fails, a
422/// BB with only unconditional jump. Subsequent entries depend upon the opcode,
423/// e.g. Jump_c p will have
424/// Cond[0] = Jump_c
425/// Cond[1] = p
426/// HW-loop ENDLOOP:
427/// Cond[0] = ENDLOOP
428/// Cond[1] = MBB
429/// New value jump:
430/// Cond[0] = Hexagon::CMPEQri_f_Jumpnv_t_V4 -- specific opcode
431/// Cond[1] = R
432/// Cond[2] = Imm
435 MachineBasicBlock *&FBB,
437 bool AllowModify) const {
438 TBB = nullptr;
439 FBB = nullptr;
440 Cond.clear();
441
442 // If the block has no terminators, it just falls into the block after it.
444 if (I == MBB.instr_begin())
445 return false;
446
447 // A basic block may looks like this:
448 //
449 // [ insn
450 // EH_LABEL
451 // insn
452 // insn
453 // insn
454 // EH_LABEL
455 // insn ]
456 //
457 // It has two succs but does not have a terminator
458 // Don't know how to handle it.
459 do {
460 --I;
461 if (I->isEHLabel())
462 // Don't analyze EH branches.
463 return true;
464 } while (I != MBB.instr_begin());
465
466 I = MBB.instr_end();
467 --I;
468
469 while (I->isDebugInstr()) {
470 if (I == MBB.instr_begin())
471 return false;
472 --I;
473 }
474
475 bool JumpToBlock = I->getOpcode() == Hexagon::J2_jump &&
476 I->getOperand(0).isMBB();
477 // Delete the J2_jump if it's equivalent to a fall-through.
478 if (AllowModify && JumpToBlock &&
479 MBB.isLayoutSuccessor(I->getOperand(0).getMBB())) {
480 LLVM_DEBUG(dbgs() << "\nErasing the jump to successor block\n";);
481 I->eraseFromParent();
482 I = MBB.instr_end();
483 if (I == MBB.instr_begin())
484 return false;
485 --I;
486 }
487 if (!isUnpredicatedTerminator(*I))
488 return false;
489
490 // Get the last instruction in the block.
491 MachineInstr *LastInst = &*I;
492 MachineInstr *SecondLastInst = nullptr;
493 // Find one more terminator if present.
494 while (true) {
495 if (&*I != LastInst && !I->isBundle() && isUnpredicatedTerminator(*I)) {
496 if (!SecondLastInst)
497 SecondLastInst = &*I;
498 else
499 // This is a third branch.
500 return true;
501 }
502 if (I == MBB.instr_begin())
503 break;
504 --I;
505 }
506
507 int LastOpcode = LastInst->getOpcode();
508 int SecLastOpcode = SecondLastInst ? SecondLastInst->getOpcode() : 0;
509 // If the branch target is not a basic block, it could be a tail call.
510 // (It is, if the target is a function.)
511 if (LastOpcode == Hexagon::J2_jump && !LastInst->getOperand(0).isMBB())
512 return true;
513 if (SecLastOpcode == Hexagon::J2_jump &&
514 !SecondLastInst->getOperand(0).isMBB())
515 return true;
516
517 bool LastOpcodeHasJMP_c = PredOpcodeHasJMP_c(LastOpcode);
518 bool LastOpcodeHasNVJump = isNewValueJump(*LastInst);
519
520 if (LastOpcodeHasJMP_c && !LastInst->getOperand(1).isMBB())
521 return true;
522
523 // If there is only one terminator instruction, process it.
524 if (LastInst && !SecondLastInst) {
525 if (LastOpcode == Hexagon::J2_jump) {
526 TBB = LastInst->getOperand(0).getMBB();
527 return false;
528 }
529 if (isEndLoopN(LastOpcode)) {
530 TBB = LastInst->getOperand(0).getMBB();
531 Cond.push_back(MachineOperand::CreateImm(LastInst->getOpcode()));
532 Cond.push_back(LastInst->getOperand(0));
533 return false;
534 }
535 if (LastOpcodeHasJMP_c) {
536 TBB = LastInst->getOperand(1).getMBB();
537 Cond.push_back(MachineOperand::CreateImm(LastInst->getOpcode()));
538 Cond.push_back(LastInst->getOperand(0));
539 return false;
540 }
541 // Only supporting rr/ri versions of new-value jumps.
542 if (LastOpcodeHasNVJump && (LastInst->getNumExplicitOperands() == 3)) {
543 TBB = LastInst->getOperand(2).getMBB();
544 Cond.push_back(MachineOperand::CreateImm(LastInst->getOpcode()));
545 Cond.push_back(LastInst->getOperand(0));
546 Cond.push_back(LastInst->getOperand(1));
547 return false;
548 }
549 LLVM_DEBUG(dbgs() << "\nCant analyze " << printMBBReference(MBB)
550 << " with one jump\n";);
551 // Otherwise, don't know what this is.
552 return true;
553 }
554
555 bool SecLastOpcodeHasJMP_c = PredOpcodeHasJMP_c(SecLastOpcode);
556 bool SecLastOpcodeHasNVJump = isNewValueJump(*SecondLastInst);
557 if (SecLastOpcodeHasJMP_c && (LastOpcode == Hexagon::J2_jump)) {
558 if (!SecondLastInst->getOperand(1).isMBB())
559 return true;
560 TBB = SecondLastInst->getOperand(1).getMBB();
561 Cond.push_back(MachineOperand::CreateImm(SecondLastInst->getOpcode()));
562 Cond.push_back(SecondLastInst->getOperand(0));
563 FBB = LastInst->getOperand(0).getMBB();
564 return false;
565 }
566
567 // Only supporting rr/ri versions of new-value jumps.
568 if (SecLastOpcodeHasNVJump &&
569 (SecondLastInst->getNumExplicitOperands() == 3) &&
570 (LastOpcode == Hexagon::J2_jump)) {
571 TBB = SecondLastInst->getOperand(2).getMBB();
572 Cond.push_back(MachineOperand::CreateImm(SecondLastInst->getOpcode()));
573 Cond.push_back(SecondLastInst->getOperand(0));
574 Cond.push_back(SecondLastInst->getOperand(1));
575 FBB = LastInst->getOperand(0).getMBB();
576 return false;
577 }
578
579 // If the block ends with two Hexagon:JMPs, handle it. The second one is not
580 // executed, so remove it.
581 if (SecLastOpcode == Hexagon::J2_jump && LastOpcode == Hexagon::J2_jump) {
582 TBB = SecondLastInst->getOperand(0).getMBB();
583 I = LastInst->getIterator();
584 if (AllowModify)
585 I->eraseFromParent();
586 return false;
587 }
588
589 // If the block ends with an ENDLOOP, and J2_jump, handle it.
590 if (isEndLoopN(SecLastOpcode) && LastOpcode == Hexagon::J2_jump) {
591 TBB = SecondLastInst->getOperand(0).getMBB();
592 Cond.push_back(MachineOperand::CreateImm(SecondLastInst->getOpcode()));
593 Cond.push_back(SecondLastInst->getOperand(0));
594 FBB = LastInst->getOperand(0).getMBB();
595 return false;
596 }
597 LLVM_DEBUG(dbgs() << "\nCant analyze " << printMBBReference(MBB)
598 << " with two jumps";);
599 // Otherwise, can't handle this.
600 return true;
601}
602
604 int *BytesRemoved) const {
605 assert(!BytesRemoved && "code size not handled");
606
607 LLVM_DEBUG(dbgs() << "\nRemoving branches out of " << printMBBReference(MBB));
609 unsigned Count = 0;
610 while (I != MBB.begin()) {
611 --I;
612 if (I->isDebugInstr())
613 continue;
614 // Only removing branches from end of MBB.
615 if (!I->isBranch())
616 return Count;
617 if (Count && (I->getOpcode() == Hexagon::J2_jump))
618 llvm_unreachable("Malformed basic block: unconditional branch not last");
619 MBB.erase(&MBB.back());
620 I = MBB.end();
621 ++Count;
622 }
623 return Count;
624}
625
630 const DebugLoc &DL,
631 int *BytesAdded) const {
632 unsigned BOpc = Hexagon::J2_jump;
633 unsigned BccOpc = Hexagon::J2_jumpt;
634 assert(validateBranchCond(Cond) && "Invalid branching condition");
635 assert(TBB && "insertBranch must not be told to insert a fallthrough");
636 assert(!BytesAdded && "code size not handled");
637
638 // Check if reverseBranchCondition has asked to reverse this branch
639 // If we want to reverse the branch an odd number of times, we want
640 // J2_jumpf.
641 if (!Cond.empty() && Cond[0].isImm())
642 BccOpc = Cond[0].getImm();
643
644 if (!FBB) {
645 if (Cond.empty()) {
646 // Due to a bug in TailMerging/CFG Optimization, we need to add a
647 // special case handling of a predicated jump followed by an
648 // unconditional jump. If not, Tail Merging and CFG Optimization go
649 // into an infinite loop.
650 MachineBasicBlock *NewTBB, *NewFBB;
652 auto Term = MBB.getFirstTerminator();
653 if (Term != MBB.end() && isPredicated(*Term) &&
654 !analyzeBranch(MBB, NewTBB, NewFBB, Cond, false) &&
658 return insertBranch(MBB, TBB, nullptr, Cond, DL);
659 }
660 BuildMI(&MBB, DL, get(BOpc)).addMBB(TBB);
661 } else if (isEndLoopN(Cond[0].getImm())) {
662 int EndLoopOp = Cond[0].getImm();
663 assert(Cond[1].isMBB());
664 // Since we're adding an ENDLOOP, there better be a LOOP instruction.
665 // Check for it, and change the BB target if needed.
667 MachineInstr *Loop = findLoopInstr(TBB, EndLoopOp, Cond[1].getMBB(),
668 VisitedBBs);
669 assert(Loop != nullptr && "Inserting an ENDLOOP without a LOOP");
670 Loop->getOperand(0).setMBB(TBB);
671 // Add the ENDLOOP after the finding the LOOP0.
672 BuildMI(&MBB, DL, get(EndLoopOp)).addMBB(TBB);
673 } else if (isNewValueJump(Cond[0].getImm())) {
674 assert((Cond.size() == 3) && "Only supporting rr/ri version of nvjump");
675 // New value jump
676 // (ins IntRegs:$src1, IntRegs:$src2, brtarget:$offset)
677 // (ins IntRegs:$src1, u5Imm:$src2, brtarget:$offset)
678 unsigned Flags1 = getUndefRegState(Cond[1].isUndef());
679 LLVM_DEBUG(dbgs() << "\nInserting NVJump for "
681 if (Cond[2].isReg()) {
682 unsigned Flags2 = getUndefRegState(Cond[2].isUndef());
683 BuildMI(&MBB, DL, get(BccOpc)).addReg(Cond[1].getReg(), Flags1).
684 addReg(Cond[2].getReg(), Flags2).addMBB(TBB);
685 } else if(Cond[2].isImm()) {
686 BuildMI(&MBB, DL, get(BccOpc)).addReg(Cond[1].getReg(), Flags1).
687 addImm(Cond[2].getImm()).addMBB(TBB);
688 } else
689 llvm_unreachable("Invalid condition for branching");
690 } else {
691 assert((Cond.size() == 2) && "Malformed cond vector");
692 const MachineOperand &RO = Cond[1];
693 unsigned Flags = getUndefRegState(RO.isUndef());
694 BuildMI(&MBB, DL, get(BccOpc)).addReg(RO.getReg(), Flags).addMBB(TBB);
695 }
696 return 1;
697 }
698 assert((!Cond.empty()) &&
699 "Cond. cannot be empty when multiple branchings are required");
700 assert((!isNewValueJump(Cond[0].getImm())) &&
701 "NV-jump cannot be inserted with another branch");
702 // Special case for hardware loops. The condition is a basic block.
703 if (isEndLoopN(Cond[0].getImm())) {
704 int EndLoopOp = Cond[0].getImm();
705 assert(Cond[1].isMBB());
706 // Since we're adding an ENDLOOP, there better be a LOOP instruction.
707 // Check for it, and change the BB target if needed.
709 MachineInstr *Loop = findLoopInstr(TBB, EndLoopOp, Cond[1].getMBB(),
710 VisitedBBs);
711 assert(Loop != nullptr && "Inserting an ENDLOOP without a LOOP");
712 Loop->getOperand(0).setMBB(TBB);
713 // Add the ENDLOOP after the finding the LOOP0.
714 BuildMI(&MBB, DL, get(EndLoopOp)).addMBB(TBB);
715 } else {
716 const MachineOperand &RO = Cond[1];
717 unsigned Flags = getUndefRegState(RO.isUndef());
718 BuildMI(&MBB, DL, get(BccOpc)).addReg(RO.getReg(), Flags).addMBB(TBB);
719 }
720 BuildMI(&MBB, DL, get(BOpc)).addMBB(FBB);
721
722 return 2;
723}
724
725namespace {
726class HexagonPipelinerLoopInfo : public TargetInstrInfo::PipelinerLoopInfo {
727 MachineInstr *Loop, *EndLoop;
728 MachineFunction *MF;
729 const HexagonInstrInfo *TII;
730 int64_t TripCount;
731 Register LoopCount;
732 DebugLoc DL;
733
734public:
735 HexagonPipelinerLoopInfo(MachineInstr *Loop, MachineInstr *EndLoop)
736 : Loop(Loop), EndLoop(EndLoop), MF(Loop->getParent()->getParent()),
737 TII(MF->getSubtarget<HexagonSubtarget>().getInstrInfo()),
738 DL(Loop->getDebugLoc()) {
739 // Inspect the Loop instruction up-front, as it may be deleted when we call
740 // createTripCountGreaterCondition.
741 TripCount = Loop->getOpcode() == Hexagon::J2_loop0r
742 ? -1
743 : Loop->getOperand(1).getImm();
744 if (TripCount == -1)
745 LoopCount = Loop->getOperand(1).getReg();
746 }
747
748 bool shouldIgnoreForPipelining(const MachineInstr *MI) const override {
749 // Only ignore the terminator.
750 return MI == EndLoop;
751 }
752
753 std::optional<bool> createTripCountGreaterCondition(
754 int TC, MachineBasicBlock &MBB,
756 if (TripCount == -1) {
757 // Check if we're done with the loop.
758 Register Done = TII->createVR(MF, MVT::i1);
759 MachineInstr *NewCmp = BuildMI(&MBB, DL,
760 TII->get(Hexagon::C2_cmpgtui), Done)
761 .addReg(LoopCount)
762 .addImm(TC);
763 Cond.push_back(MachineOperand::CreateImm(Hexagon::J2_jumpf));
764 Cond.push_back(NewCmp->getOperand(0));
765 return {};
766 }
767
768 return TripCount > TC;
769 }
770
771 void setPreheader(MachineBasicBlock *NewPreheader) override {
772 NewPreheader->splice(NewPreheader->getFirstTerminator(), Loop->getParent(),
773 Loop);
774 }
775
776 void adjustTripCount(int TripCountAdjust) override {
777 // If the loop trip count is a compile-time value, then just change the
778 // value.
779 if (Loop->getOpcode() == Hexagon::J2_loop0i ||
780 Loop->getOpcode() == Hexagon::J2_loop1i) {
781 int64_t TripCount = Loop->getOperand(1).getImm() + TripCountAdjust;
782 assert(TripCount > 0 && "Can't create an empty or negative loop!");
783 Loop->getOperand(1).setImm(TripCount);
784 return;
785 }
786
787 // The loop trip count is a run-time value. We generate code to subtract
788 // one from the trip count, and update the loop instruction.
789 Register LoopCount = Loop->getOperand(1).getReg();
790 Register NewLoopCount = TII->createVR(MF, MVT::i32);
791 BuildMI(*Loop->getParent(), Loop, Loop->getDebugLoc(),
792 TII->get(Hexagon::A2_addi), NewLoopCount)
793 .addReg(LoopCount)
794 .addImm(TripCountAdjust);
795 Loop->getOperand(1).setReg(NewLoopCount);
796 }
797
798 void disposed() override { Loop->eraseFromParent(); }
799};
800} // namespace
801
802std::unique_ptr<TargetInstrInfo::PipelinerLoopInfo>
804 // We really "analyze" only hardware loops right now.
806
807 if (I != LoopBB->end() && isEndLoopN(I->getOpcode())) {
809 MachineInstr *LoopInst = findLoopInstr(
810 LoopBB, I->getOpcode(), I->getOperand(0).getMBB(), VisitedBBs);
811 if (LoopInst)
812 return std::make_unique<HexagonPipelinerLoopInfo>(LoopInst, &*I);
813 }
814 return nullptr;
815}
816
818 unsigned NumCycles, unsigned ExtraPredCycles,
819 BranchProbability Probability) const {
820 return nonDbgBBSize(&MBB) <= 3;
821}
822
824 unsigned NumTCycles, unsigned ExtraTCycles, MachineBasicBlock &FMBB,
825 unsigned NumFCycles, unsigned ExtraFCycles, BranchProbability Probability)
826 const {
827 return nonDbgBBSize(&TMBB) <= 3 && nonDbgBBSize(&FMBB) <= 3;
828}
829
831 unsigned NumInstrs, BranchProbability Probability) const {
832 return NumInstrs <= 4;
833}
834
835static void getLiveInRegsAt(LivePhysRegs &Regs, const MachineInstr &MI) {
837 const MachineBasicBlock &B = *MI.getParent();
838 Regs.addLiveIns(B);
839 auto E = MachineBasicBlock::const_iterator(MI.getIterator());
840 for (auto I = B.begin(); I != E; ++I) {
841 Clobbers.clear();
842 Regs.stepForward(*I, Clobbers);
843 }
844}
845
846static void getLiveOutRegsAt(LivePhysRegs &Regs, const MachineInstr &MI) {
847 const MachineBasicBlock &B = *MI.getParent();
848 Regs.addLiveOuts(B);
849 auto E = ++MachineBasicBlock::const_iterator(MI.getIterator()).getReverse();
850 for (auto I = B.rbegin(); I != E; ++I)
851 Regs.stepBackward(*I);
852}
853
856 const DebugLoc &DL, MCRegister DestReg,
857 MCRegister SrcReg, bool KillSrc,
858 bool RenamableDest,
859 bool RenamableSrc) const {
860 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
861 unsigned KillFlag = getKillRegState(KillSrc);
862
863 if (Hexagon::IntRegsRegClass.contains(SrcReg, DestReg)) {
864 BuildMI(MBB, I, DL, get(Hexagon::A2_tfr), DestReg)
865 .addReg(SrcReg, KillFlag);
866 return;
867 }
868 if (Hexagon::DoubleRegsRegClass.contains(SrcReg, DestReg)) {
869 BuildMI(MBB, I, DL, get(Hexagon::A2_tfrp), DestReg)
870 .addReg(SrcReg, KillFlag);
871 return;
872 }
873 if (Hexagon::PredRegsRegClass.contains(SrcReg, DestReg)) {
874 // Map Pd = Ps to Pd = or(Ps, Ps).
875 BuildMI(MBB, I, DL, get(Hexagon::C2_or), DestReg)
876 .addReg(SrcReg).addReg(SrcReg, KillFlag);
877 return;
878 }
879 if (Hexagon::CtrRegsRegClass.contains(DestReg) &&
880 Hexagon::IntRegsRegClass.contains(SrcReg)) {
881 BuildMI(MBB, I, DL, get(Hexagon::A2_tfrrcr), DestReg)
882 .addReg(SrcReg, KillFlag);
883 return;
884 }
885 if (Hexagon::IntRegsRegClass.contains(DestReg) &&
886 Hexagon::CtrRegsRegClass.contains(SrcReg)) {
887 BuildMI(MBB, I, DL, get(Hexagon::A2_tfrcrr), DestReg)
888 .addReg(SrcReg, KillFlag);
889 return;
890 }
891 if (Hexagon::ModRegsRegClass.contains(DestReg) &&
892 Hexagon::IntRegsRegClass.contains(SrcReg)) {
893 BuildMI(MBB, I, DL, get(Hexagon::A2_tfrrcr), DestReg)
894 .addReg(SrcReg, KillFlag);
895 return;
896 }
897 if (Hexagon::PredRegsRegClass.contains(SrcReg) &&
898 Hexagon::IntRegsRegClass.contains(DestReg)) {
899 BuildMI(MBB, I, DL, get(Hexagon::C2_tfrpr), DestReg)
900 .addReg(SrcReg, KillFlag);
901 return;
902 }
903 if (Hexagon::IntRegsRegClass.contains(SrcReg) &&
904 Hexagon::PredRegsRegClass.contains(DestReg)) {
905 BuildMI(MBB, I, DL, get(Hexagon::C2_tfrrp), DestReg)
906 .addReg(SrcReg, KillFlag);
907 return;
908 }
909 if (Hexagon::PredRegsRegClass.contains(SrcReg) &&
910 Hexagon::IntRegsRegClass.contains(DestReg)) {
911 BuildMI(MBB, I, DL, get(Hexagon::C2_tfrpr), DestReg)
912 .addReg(SrcReg, KillFlag);
913 return;
914 }
915 if (Hexagon::HvxVRRegClass.contains(SrcReg, DestReg)) {
916 BuildMI(MBB, I, DL, get(Hexagon::V6_vassign), DestReg).
917 addReg(SrcReg, KillFlag);
918 return;
919 }
920 if (Hexagon::HvxWRRegClass.contains(SrcReg, DestReg)) {
921 LivePhysRegs LiveAtMI(HRI);
922 getLiveInRegsAt(LiveAtMI, *I);
923 Register SrcLo = HRI.getSubReg(SrcReg, Hexagon::vsub_lo);
924 Register SrcHi = HRI.getSubReg(SrcReg, Hexagon::vsub_hi);
925 unsigned UndefLo = getUndefRegState(!LiveAtMI.contains(SrcLo));
926 unsigned UndefHi = getUndefRegState(!LiveAtMI.contains(SrcHi));
927 BuildMI(MBB, I, DL, get(Hexagon::V6_vcombine), DestReg)
928 .addReg(SrcHi, KillFlag | UndefHi)
929 .addReg(SrcLo, KillFlag | UndefLo);
930 return;
931 }
932 if (Hexagon::HvxQRRegClass.contains(SrcReg, DestReg)) {
933 BuildMI(MBB, I, DL, get(Hexagon::V6_pred_and), DestReg)
934 .addReg(SrcReg)
935 .addReg(SrcReg, KillFlag);
936 return;
937 }
938 if (Hexagon::HvxQRRegClass.contains(SrcReg) &&
939 Hexagon::HvxVRRegClass.contains(DestReg)) {
940 llvm_unreachable("Unimplemented pred to vec");
941 return;
942 }
943 if (Hexagon::HvxQRRegClass.contains(DestReg) &&
944 Hexagon::HvxVRRegClass.contains(SrcReg)) {
945 llvm_unreachable("Unimplemented vec to pred");
946 return;
947 }
948
949#ifndef NDEBUG
950 // Show the invalid registers to ease debugging.
951 dbgs() << "Invalid registers for copy in " << printMBBReference(MBB) << ": "
952 << printReg(DestReg, &HRI) << " = " << printReg(SrcReg, &HRI) << '\n';
953#endif
954 llvm_unreachable("Unimplemented");
955}
956
959 Register SrcReg, bool isKill, int FI,
960 const TargetRegisterClass *RC,
961 const TargetRegisterInfo *TRI,
962 Register VReg,
963 MachineInstr::MIFlag Flags) const {
966 MachineFrameInfo &MFI = MF.getFrameInfo();
967 unsigned KillFlag = getKillRegState(isKill);
968
971 MFI.getObjectSize(FI), MFI.getObjectAlign(FI));
972
973 if (Hexagon::IntRegsRegClass.hasSubClassEq(RC)) {
974 BuildMI(MBB, I, DL, get(Hexagon::S2_storeri_io))
975 .addFrameIndex(FI).addImm(0)
976 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
977 } else if (Hexagon::DoubleRegsRegClass.hasSubClassEq(RC)) {
978 BuildMI(MBB, I, DL, get(Hexagon::S2_storerd_io))
979 .addFrameIndex(FI).addImm(0)
980 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
981 } else if (Hexagon::PredRegsRegClass.hasSubClassEq(RC)) {
982 BuildMI(MBB, I, DL, get(Hexagon::STriw_pred))
983 .addFrameIndex(FI).addImm(0)
984 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
985 } else if (Hexagon::ModRegsRegClass.hasSubClassEq(RC)) {
986 BuildMI(MBB, I, DL, get(Hexagon::STriw_ctr))
987 .addFrameIndex(FI).addImm(0)
988 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
989 } else if (Hexagon::HvxQRRegClass.hasSubClassEq(RC)) {
990 BuildMI(MBB, I, DL, get(Hexagon::PS_vstorerq_ai))
991 .addFrameIndex(FI).addImm(0)
992 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
993 } else if (Hexagon::HvxVRRegClass.hasSubClassEq(RC)) {
994 BuildMI(MBB, I, DL, get(Hexagon::PS_vstorerv_ai))
995 .addFrameIndex(FI).addImm(0)
996 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
997 } else if (Hexagon::HvxWRRegClass.hasSubClassEq(RC)) {
998 BuildMI(MBB, I, DL, get(Hexagon::PS_vstorerw_ai))
999 .addFrameIndex(FI).addImm(0)
1000 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
1001 } else {
1002 llvm_unreachable("Unimplemented");
1003 }
1004}
1005
1008 int FI, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI,
1009 Register VReg, MachineInstr::MIFlag Flags) const {
1011 MachineFunction &MF = *MBB.getParent();
1012 MachineFrameInfo &MFI = MF.getFrameInfo();
1013
1016 MFI.getObjectSize(FI), MFI.getObjectAlign(FI));
1017
1018 if (Hexagon::IntRegsRegClass.hasSubClassEq(RC)) {
1019 BuildMI(MBB, I, DL, get(Hexagon::L2_loadri_io), DestReg)
1020 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
1021 } else if (Hexagon::DoubleRegsRegClass.hasSubClassEq(RC)) {
1022 BuildMI(MBB, I, DL, get(Hexagon::L2_loadrd_io), DestReg)
1023 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
1024 } else if (Hexagon::PredRegsRegClass.hasSubClassEq(RC)) {
1025 BuildMI(MBB, I, DL, get(Hexagon::LDriw_pred), DestReg)
1026 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
1027 } else if (Hexagon::ModRegsRegClass.hasSubClassEq(RC)) {
1028 BuildMI(MBB, I, DL, get(Hexagon::LDriw_ctr), DestReg)
1029 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
1030 } else if (Hexagon::HvxQRRegClass.hasSubClassEq(RC)) {
1031 BuildMI(MBB, I, DL, get(Hexagon::PS_vloadrq_ai), DestReg)
1032 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
1033 } else if (Hexagon::HvxVRRegClass.hasSubClassEq(RC)) {
1034 BuildMI(MBB, I, DL, get(Hexagon::PS_vloadrv_ai), DestReg)
1035 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
1036 } else if (Hexagon::HvxWRRegClass.hasSubClassEq(RC)) {
1037 BuildMI(MBB, I, DL, get(Hexagon::PS_vloadrw_ai), DestReg)
1038 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
1039 } else {
1040 llvm_unreachable("Can't store this register to stack slot");
1041 }
1042}
1043
1044/// expandPostRAPseudo - This function is called for all pseudo instructions
1045/// that remain after register allocation. Many pseudo instructions are
1046/// created to help register allocation. This is the place to convert them
1047/// into real instructions. The target can edit MI in place, or it can insert
1048/// new instructions and erase MI. The function should return true if
1049/// anything was changed.
1051 MachineBasicBlock &MBB = *MI.getParent();
1052 MachineFunction &MF = *MBB.getParent();
1054 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
1055 LivePhysRegs LiveIn(HRI), LiveOut(HRI);
1056 DebugLoc DL = MI.getDebugLoc();
1057 unsigned Opc = MI.getOpcode();
1058
1059 auto RealCirc = [&](unsigned Opc, bool HasImm, unsigned MxOp) {
1060 Register Mx = MI.getOperand(MxOp).getReg();
1061 Register CSx = (Mx == Hexagon::M0 ? Hexagon::CS0 : Hexagon::CS1);
1062 BuildMI(MBB, MI, DL, get(Hexagon::A2_tfrrcr), CSx)
1063 .add(MI.getOperand((HasImm ? 5 : 4)));
1064 auto MIB = BuildMI(MBB, MI, DL, get(Opc)).add(MI.getOperand(0))
1065 .add(MI.getOperand(1)).add(MI.getOperand(2)).add(MI.getOperand(3));
1066 if (HasImm)
1067 MIB.add(MI.getOperand(4));
1068 MIB.addReg(CSx, RegState::Implicit);
1069 MBB.erase(MI);
1070 return true;
1071 };
1072
1073 auto UseAligned = [&](const MachineInstr &MI, Align NeedAlign) {
1074 if (MI.memoperands().empty())
1075 return false;
1076 return all_of(MI.memoperands(), [NeedAlign](const MachineMemOperand *MMO) {
1077 return MMO->getAlign() >= NeedAlign;
1078 });
1079 };
1080
1081 switch (Opc) {
1082 case Hexagon::PS_call_instrprof_custom: {
1083 auto Op0 = MI.getOperand(0);
1084 assert(Op0.isGlobal() &&
1085 "First operand must be a global containing handler name.");
1086 const GlobalValue *NameVar = Op0.getGlobal();
1087 const GlobalVariable *GV = dyn_cast<GlobalVariable>(NameVar);
1088 auto *Arr = cast<ConstantDataArray>(GV->getInitializer());
1089 StringRef NameStr = Arr->isCString() ? Arr->getAsCString() : Arr->getAsString();
1090
1091 MachineOperand &Op1 = MI.getOperand(1);
1092 // Set R0 with the imm value to be passed to the custom profiling handler.
1093 BuildMI(MBB, MI, DL, get(Hexagon::A2_tfrsi), Hexagon::R0)
1094 .addImm(Op1.getImm());
1095 // The call to the custom handler is being treated as a special one as the
1096 // callee is responsible for saving and restoring all the registers
1097 // (including caller saved registers) it needs to modify. This is
1098 // done to reduce the impact of instrumentation on the code being
1099 // instrumented/profiled.
1100 // NOTE: R14, R15 and R28 are reserved for PLT handling. These registers
1101 // are in the Def list of the Hexagon::PS_call_instrprof_custom and
1102 // therefore will be handled appropriately duing register allocation.
1103
1104 // TODO: It may be a good idea to add a separate pseudo instruction for
1105 // static relocation which doesn't need to reserve r14, r15 and r28.
1106
1107 auto MIB = BuildMI(MBB, MI, DL, get(Hexagon::J2_call))
1109 .addDef(Hexagon::R29, RegState::ImplicitDefine)
1110 .addDef(Hexagon::R30, RegState::ImplicitDefine)
1111 .addDef(Hexagon::R14, RegState::ImplicitDefine)
1112 .addDef(Hexagon::R15, RegState::ImplicitDefine)
1113 .addDef(Hexagon::R28, RegState::ImplicitDefine);
1114 const char *cstr = MF.createExternalSymbolName(NameStr);
1115 MIB.addExternalSymbol(cstr);
1116 MBB.erase(MI);
1117 return true;
1118 }
1119 case TargetOpcode::COPY: {
1120 MachineOperand &MD = MI.getOperand(0);
1121 MachineOperand &MS = MI.getOperand(1);
1122 MachineBasicBlock::iterator MBBI = MI.getIterator();
1123 if (MD.getReg() != MS.getReg() && !MS.isUndef()) {
1124 copyPhysReg(MBB, MI, DL, MD.getReg(), MS.getReg(), MS.isKill());
1125 std::prev(MBBI)->copyImplicitOps(*MBB.getParent(), MI);
1126 }
1127 MBB.erase(MBBI);
1128 return true;
1129 }
1130 case Hexagon::PS_aligna:
1131 BuildMI(MBB, MI, DL, get(Hexagon::A2_andir), MI.getOperand(0).getReg())
1132 .addReg(HRI.getFrameRegister())
1133 .addImm(-MI.getOperand(1).getImm());
1134 MBB.erase(MI);
1135 return true;
1136 case Hexagon::V6_vassignp: {
1137 Register SrcReg = MI.getOperand(1).getReg();
1138 Register DstReg = MI.getOperand(0).getReg();
1139 Register SrcLo = HRI.getSubReg(SrcReg, Hexagon::vsub_lo);
1140 Register SrcHi = HRI.getSubReg(SrcReg, Hexagon::vsub_hi);
1141 getLiveInRegsAt(LiveIn, MI);
1142 unsigned UndefLo = getUndefRegState(!LiveIn.contains(SrcLo));
1143 unsigned UndefHi = getUndefRegState(!LiveIn.contains(SrcHi));
1144 unsigned Kill = getKillRegState(MI.getOperand(1).isKill());
1145 BuildMI(MBB, MI, DL, get(Hexagon::V6_vcombine), DstReg)
1146 .addReg(SrcHi, UndefHi)
1147 .addReg(SrcLo, Kill | UndefLo);
1148 MBB.erase(MI);
1149 return true;
1150 }
1151 case Hexagon::V6_lo: {
1152 Register SrcReg = MI.getOperand(1).getReg();
1153 Register DstReg = MI.getOperand(0).getReg();
1154 Register SrcSubLo = HRI.getSubReg(SrcReg, Hexagon::vsub_lo);
1155 copyPhysReg(MBB, MI, DL, DstReg, SrcSubLo, MI.getOperand(1).isKill());
1156 MBB.erase(MI);
1157 MRI.clearKillFlags(SrcSubLo);
1158 return true;
1159 }
1160 case Hexagon::V6_hi: {
1161 Register SrcReg = MI.getOperand(1).getReg();
1162 Register DstReg = MI.getOperand(0).getReg();
1163 Register SrcSubHi = HRI.getSubReg(SrcReg, Hexagon::vsub_hi);
1164 copyPhysReg(MBB, MI, DL, DstReg, SrcSubHi, MI.getOperand(1).isKill());
1165 MBB.erase(MI);
1166 MRI.clearKillFlags(SrcSubHi);
1167 return true;
1168 }
1169 case Hexagon::PS_vloadrv_ai: {
1170 Register DstReg = MI.getOperand(0).getReg();
1171 const MachineOperand &BaseOp = MI.getOperand(1);
1172 assert(BaseOp.getSubReg() == 0);
1173 int Offset = MI.getOperand(2).getImm();
1174 Align NeedAlign = HRI.getSpillAlign(Hexagon::HvxVRRegClass);
1175 unsigned NewOpc = UseAligned(MI, NeedAlign) ? Hexagon::V6_vL32b_ai
1176 : Hexagon::V6_vL32Ub_ai;
1177 BuildMI(MBB, MI, DL, get(NewOpc), DstReg)
1178 .addReg(BaseOp.getReg(), getRegState(BaseOp))
1179 .addImm(Offset)
1180 .cloneMemRefs(MI);
1181 MBB.erase(MI);
1182 return true;
1183 }
1184 case Hexagon::PS_vloadrw_ai: {
1185 Register DstReg = MI.getOperand(0).getReg();
1186 const MachineOperand &BaseOp = MI.getOperand(1);
1187 assert(BaseOp.getSubReg() == 0);
1188 int Offset = MI.getOperand(2).getImm();
1189 unsigned VecOffset = HRI.getSpillSize(Hexagon::HvxVRRegClass);
1190 Align NeedAlign = HRI.getSpillAlign(Hexagon::HvxVRRegClass);
1191 unsigned NewOpc = UseAligned(MI, NeedAlign) ? Hexagon::V6_vL32b_ai
1192 : Hexagon::V6_vL32Ub_ai;
1193 BuildMI(MBB, MI, DL, get(NewOpc),
1194 HRI.getSubReg(DstReg, Hexagon::vsub_lo))
1195 .addReg(BaseOp.getReg(), getRegState(BaseOp) & ~RegState::Kill)
1196 .addImm(Offset)
1197 .cloneMemRefs(MI);
1198 BuildMI(MBB, MI, DL, get(NewOpc),
1199 HRI.getSubReg(DstReg, Hexagon::vsub_hi))
1200 .addReg(BaseOp.getReg(), getRegState(BaseOp))
1201 .addImm(Offset + VecOffset)
1202 .cloneMemRefs(MI);
1203 MBB.erase(MI);
1204 return true;
1205 }
1206 case Hexagon::PS_vstorerv_ai: {
1207 const MachineOperand &SrcOp = MI.getOperand(2);
1208 assert(SrcOp.getSubReg() == 0);
1209 const MachineOperand &BaseOp = MI.getOperand(0);
1210 assert(BaseOp.getSubReg() == 0);
1211 int Offset = MI.getOperand(1).getImm();
1212 Align NeedAlign = HRI.getSpillAlign(Hexagon::HvxVRRegClass);
1213 unsigned NewOpc = UseAligned(MI, NeedAlign) ? Hexagon::V6_vS32b_ai
1214 : Hexagon::V6_vS32Ub_ai;
1215 BuildMI(MBB, MI, DL, get(NewOpc))
1216 .addReg(BaseOp.getReg(), getRegState(BaseOp))
1217 .addImm(Offset)
1219 .cloneMemRefs(MI);
1220 MBB.erase(MI);
1221 return true;
1222 }
1223 case Hexagon::PS_vstorerw_ai: {
1224 Register SrcReg = MI.getOperand(2).getReg();
1225 const MachineOperand &BaseOp = MI.getOperand(0);
1226 assert(BaseOp.getSubReg() == 0);
1227 int Offset = MI.getOperand(1).getImm();
1228 unsigned VecOffset = HRI.getSpillSize(Hexagon::HvxVRRegClass);
1229 Align NeedAlign = HRI.getSpillAlign(Hexagon::HvxVRRegClass);
1230 unsigned NewOpc = UseAligned(MI, NeedAlign) ? Hexagon::V6_vS32b_ai
1231 : Hexagon::V6_vS32Ub_ai;
1232 BuildMI(MBB, MI, DL, get(NewOpc))
1233 .addReg(BaseOp.getReg(), getRegState(BaseOp) & ~RegState::Kill)
1234 .addImm(Offset)
1235 .addReg(HRI.getSubReg(SrcReg, Hexagon::vsub_lo))
1236 .cloneMemRefs(MI);
1237 BuildMI(MBB, MI, DL, get(NewOpc))
1238 .addReg(BaseOp.getReg(), getRegState(BaseOp))
1239 .addImm(Offset + VecOffset)
1240 .addReg(HRI.getSubReg(SrcReg, Hexagon::vsub_hi))
1241 .cloneMemRefs(MI);
1242 MBB.erase(MI);
1243 return true;
1244 }
1245 case Hexagon::PS_true: {
1246 Register Reg = MI.getOperand(0).getReg();
1247 BuildMI(MBB, MI, DL, get(Hexagon::C2_orn), Reg)
1248 .addReg(Reg, RegState::Undef)
1249 .addReg(Reg, RegState::Undef);
1250 MBB.erase(MI);
1251 return true;
1252 }
1253 case Hexagon::PS_false: {
1254 Register Reg = MI.getOperand(0).getReg();
1255 BuildMI(MBB, MI, DL, get(Hexagon::C2_andn), Reg)
1256 .addReg(Reg, RegState::Undef)
1257 .addReg(Reg, RegState::Undef);
1258 MBB.erase(MI);
1259 return true;
1260 }
1261 case Hexagon::PS_qtrue: {
1262 BuildMI(MBB, MI, DL, get(Hexagon::V6_veqw), MI.getOperand(0).getReg())
1263 .addReg(Hexagon::V0, RegState::Undef)
1264 .addReg(Hexagon::V0, RegState::Undef);
1265 MBB.erase(MI);
1266 return true;
1267 }
1268 case Hexagon::PS_qfalse: {
1269 BuildMI(MBB, MI, DL, get(Hexagon::V6_vgtw), MI.getOperand(0).getReg())
1270 .addReg(Hexagon::V0, RegState::Undef)
1271 .addReg(Hexagon::V0, RegState::Undef);
1272 MBB.erase(MI);
1273 return true;
1274 }
1275 case Hexagon::PS_vdd0: {
1276 Register Vd = MI.getOperand(0).getReg();
1277 BuildMI(MBB, MI, DL, get(Hexagon::V6_vsubw_dv), Vd)
1279 .addReg(Vd, RegState::Undef);
1280 MBB.erase(MI);
1281 return true;
1282 }
1283 case Hexagon::PS_vmulw: {
1284 // Expand a 64-bit vector multiply into 2 32-bit scalar multiplies.
1285 Register DstReg = MI.getOperand(0).getReg();
1286 Register Src1Reg = MI.getOperand(1).getReg();
1287 Register Src2Reg = MI.getOperand(2).getReg();
1288 Register Src1SubHi = HRI.getSubReg(Src1Reg, Hexagon::isub_hi);
1289 Register Src1SubLo = HRI.getSubReg(Src1Reg, Hexagon::isub_lo);
1290 Register Src2SubHi = HRI.getSubReg(Src2Reg, Hexagon::isub_hi);
1291 Register Src2SubLo = HRI.getSubReg(Src2Reg, Hexagon::isub_lo);
1292 BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::M2_mpyi),
1293 HRI.getSubReg(DstReg, Hexagon::isub_hi))
1294 .addReg(Src1SubHi)
1295 .addReg(Src2SubHi);
1296 BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::M2_mpyi),
1297 HRI.getSubReg(DstReg, Hexagon::isub_lo))
1298 .addReg(Src1SubLo)
1299 .addReg(Src2SubLo);
1300 MBB.erase(MI);
1301 MRI.clearKillFlags(Src1SubHi);
1302 MRI.clearKillFlags(Src1SubLo);
1303 MRI.clearKillFlags(Src2SubHi);
1304 MRI.clearKillFlags(Src2SubLo);
1305 return true;
1306 }
1307 case Hexagon::PS_vmulw_acc: {
1308 // Expand 64-bit vector multiply with addition into 2 scalar multiplies.
1309 Register DstReg = MI.getOperand(0).getReg();
1310 Register Src1Reg = MI.getOperand(1).getReg();
1311 Register Src2Reg = MI.getOperand(2).getReg();
1312 Register Src3Reg = MI.getOperand(3).getReg();
1313 Register Src1SubHi = HRI.getSubReg(Src1Reg, Hexagon::isub_hi);
1314 Register Src1SubLo = HRI.getSubReg(Src1Reg, Hexagon::isub_lo);
1315 Register Src2SubHi = HRI.getSubReg(Src2Reg, Hexagon::isub_hi);
1316 Register Src2SubLo = HRI.getSubReg(Src2Reg, Hexagon::isub_lo);
1317 Register Src3SubHi = HRI.getSubReg(Src3Reg, Hexagon::isub_hi);
1318 Register Src3SubLo = HRI.getSubReg(Src3Reg, Hexagon::isub_lo);
1319 BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::M2_maci),
1320 HRI.getSubReg(DstReg, Hexagon::isub_hi))
1321 .addReg(Src1SubHi)
1322 .addReg(Src2SubHi)
1323 .addReg(Src3SubHi);
1324 BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::M2_maci),
1325 HRI.getSubReg(DstReg, Hexagon::isub_lo))
1326 .addReg(Src1SubLo)
1327 .addReg(Src2SubLo)
1328 .addReg(Src3SubLo);
1329 MBB.erase(MI);
1330 MRI.clearKillFlags(Src1SubHi);
1331 MRI.clearKillFlags(Src1SubLo);
1332 MRI.clearKillFlags(Src2SubHi);
1333 MRI.clearKillFlags(Src2SubLo);
1334 MRI.clearKillFlags(Src3SubHi);
1335 MRI.clearKillFlags(Src3SubLo);
1336 return true;
1337 }
1338 case Hexagon::PS_pselect: {
1339 const MachineOperand &Op0 = MI.getOperand(0);
1340 const MachineOperand &Op1 = MI.getOperand(1);
1341 const MachineOperand &Op2 = MI.getOperand(2);
1342 const MachineOperand &Op3 = MI.getOperand(3);
1343 Register Rd = Op0.getReg();
1344 Register Pu = Op1.getReg();
1345 Register Rs = Op2.getReg();
1346 Register Rt = Op3.getReg();
1347 DebugLoc DL = MI.getDebugLoc();
1348 unsigned K1 = getKillRegState(Op1.isKill());
1349 unsigned K2 = getKillRegState(Op2.isKill());
1350 unsigned K3 = getKillRegState(Op3.isKill());
1351 if (Rd != Rs)
1352 BuildMI(MBB, MI, DL, get(Hexagon::A2_tfrpt), Rd)
1353 .addReg(Pu, (Rd == Rt) ? K1 : 0)
1354 .addReg(Rs, K2);
1355 if (Rd != Rt)
1356 BuildMI(MBB, MI, DL, get(Hexagon::A2_tfrpf), Rd)
1357 .addReg(Pu, K1)
1358 .addReg(Rt, K3);
1359 MBB.erase(MI);
1360 return true;
1361 }
1362 case Hexagon::PS_vselect: {
1363 const MachineOperand &Op0 = MI.getOperand(0);
1364 const MachineOperand &Op1 = MI.getOperand(1);
1365 const MachineOperand &Op2 = MI.getOperand(2);
1366 const MachineOperand &Op3 = MI.getOperand(3);
1367 getLiveOutRegsAt(LiveOut, MI);
1368 bool IsDestLive = !LiveOut.available(MRI, Op0.getReg());
1369 Register PReg = Op1.getReg();
1370 assert(Op1.getSubReg() == 0);
1371 unsigned PState = getRegState(Op1);
1372
1373 if (Op0.getReg() != Op2.getReg()) {
1374 unsigned S = Op0.getReg() != Op3.getReg() ? PState & ~RegState::Kill
1375 : PState;
1376 auto T = BuildMI(MBB, MI, DL, get(Hexagon::V6_vcmov))
1377 .add(Op0)
1378 .addReg(PReg, S)
1379 .add(Op2);
1380 if (IsDestLive)
1381 T.addReg(Op0.getReg(), RegState::Implicit);
1382 IsDestLive = true;
1383 }
1384 if (Op0.getReg() != Op3.getReg()) {
1385 auto T = BuildMI(MBB, MI, DL, get(Hexagon::V6_vncmov))
1386 .add(Op0)
1387 .addReg(PReg, PState)
1388 .add(Op3);
1389 if (IsDestLive)
1390 T.addReg(Op0.getReg(), RegState::Implicit);
1391 }
1392 MBB.erase(MI);
1393 return true;
1394 }
1395 case Hexagon::PS_wselect: {
1396 MachineOperand &Op0 = MI.getOperand(0);
1397 MachineOperand &Op1 = MI.getOperand(1);
1398 MachineOperand &Op2 = MI.getOperand(2);
1399 MachineOperand &Op3 = MI.getOperand(3);
1400 getLiveOutRegsAt(LiveOut, MI);
1401 bool IsDestLive = !LiveOut.available(MRI, Op0.getReg());
1402 Register PReg = Op1.getReg();
1403 assert(Op1.getSubReg() == 0);
1404 unsigned PState = getRegState(Op1);
1405
1406 if (Op0.getReg() != Op2.getReg()) {
1407 unsigned S = Op0.getReg() != Op3.getReg() ? PState & ~RegState::Kill
1408 : PState;
1409 Register SrcLo = HRI.getSubReg(Op2.getReg(), Hexagon::vsub_lo);
1410 Register SrcHi = HRI.getSubReg(Op2.getReg(), Hexagon::vsub_hi);
1411 auto T = BuildMI(MBB, MI, DL, get(Hexagon::V6_vccombine))
1412 .add(Op0)
1413 .addReg(PReg, S)
1414 .addReg(SrcHi)
1415 .addReg(SrcLo);
1416 if (IsDestLive)
1417 T.addReg(Op0.getReg(), RegState::Implicit);
1418 IsDestLive = true;
1419 }
1420 if (Op0.getReg() != Op3.getReg()) {
1421 Register SrcLo = HRI.getSubReg(Op3.getReg(), Hexagon::vsub_lo);
1422 Register SrcHi = HRI.getSubReg(Op3.getReg(), Hexagon::vsub_hi);
1423 auto T = BuildMI(MBB, MI, DL, get(Hexagon::V6_vnccombine))
1424 .add(Op0)
1425 .addReg(PReg, PState)
1426 .addReg(SrcHi)
1427 .addReg(SrcLo);
1428 if (IsDestLive)
1429 T.addReg(Op0.getReg(), RegState::Implicit);
1430 }
1431 MBB.erase(MI);
1432 return true;
1433 }
1434
1435 case Hexagon::PS_crash: {
1436 // Generate a misaligned load that is guaranteed to cause a crash.
1437 class CrashPseudoSourceValue : public PseudoSourceValue {
1438 public:
1439 CrashPseudoSourceValue(const TargetMachine &TM)
1440 : PseudoSourceValue(TargetCustom, TM) {}
1441
1442 bool isConstant(const MachineFrameInfo *) const override {
1443 return false;
1444 }
1445 bool isAliased(const MachineFrameInfo *) const override {
1446 return false;
1447 }
1448 bool mayAlias(const MachineFrameInfo *) const override {
1449 return false;
1450 }
1451 void printCustom(raw_ostream &OS) const override {
1452 OS << "MisalignedCrash";
1453 }
1454 };
1455
1456 static const CrashPseudoSourceValue CrashPSV(MF.getTarget());
1458 MachinePointerInfo(&CrashPSV),
1460 Align(1));
1461 BuildMI(MBB, MI, DL, get(Hexagon::PS_loadrdabs), Hexagon::D13)
1462 .addImm(0xBADC0FEE) // Misaligned load.
1463 .addMemOperand(MMO);
1464 MBB.erase(MI);
1465 return true;
1466 }
1467
1468 case Hexagon::PS_tailcall_i:
1469 MI.setDesc(get(Hexagon::J2_jump));
1470 return true;
1471 case Hexagon::PS_tailcall_r:
1472 case Hexagon::PS_jmpret:
1473 MI.setDesc(get(Hexagon::J2_jumpr));
1474 return true;
1475 case Hexagon::PS_jmprett:
1476 MI.setDesc(get(Hexagon::J2_jumprt));
1477 return true;
1478 case Hexagon::PS_jmpretf:
1479 MI.setDesc(get(Hexagon::J2_jumprf));
1480 return true;
1481 case Hexagon::PS_jmprettnewpt:
1482 MI.setDesc(get(Hexagon::J2_jumprtnewpt));
1483 return true;
1484 case Hexagon::PS_jmpretfnewpt:
1485 MI.setDesc(get(Hexagon::J2_jumprfnewpt));
1486 return true;
1487 case Hexagon::PS_jmprettnew:
1488 MI.setDesc(get(Hexagon::J2_jumprtnew));
1489 return true;
1490 case Hexagon::PS_jmpretfnew:
1491 MI.setDesc(get(Hexagon::J2_jumprfnew));
1492 return true;
1493
1494 case Hexagon::PS_loadrub_pci:
1495 return RealCirc(Hexagon::L2_loadrub_pci, /*HasImm*/true, /*MxOp*/4);
1496 case Hexagon::PS_loadrb_pci:
1497 return RealCirc(Hexagon::L2_loadrb_pci, /*HasImm*/true, /*MxOp*/4);
1498 case Hexagon::PS_loadruh_pci:
1499 return RealCirc(Hexagon::L2_loadruh_pci, /*HasImm*/true, /*MxOp*/4);
1500 case Hexagon::PS_loadrh_pci:
1501 return RealCirc(Hexagon::L2_loadrh_pci, /*HasImm*/true, /*MxOp*/4);
1502 case Hexagon::PS_loadri_pci:
1503 return RealCirc(Hexagon::L2_loadri_pci, /*HasImm*/true, /*MxOp*/4);
1504 case Hexagon::PS_loadrd_pci:
1505 return RealCirc(Hexagon::L2_loadrd_pci, /*HasImm*/true, /*MxOp*/4);
1506 case Hexagon::PS_loadrub_pcr:
1507 return RealCirc(Hexagon::L2_loadrub_pcr, /*HasImm*/false, /*MxOp*/3);
1508 case Hexagon::PS_loadrb_pcr:
1509 return RealCirc(Hexagon::L2_loadrb_pcr, /*HasImm*/false, /*MxOp*/3);
1510 case Hexagon::PS_loadruh_pcr:
1511 return RealCirc(Hexagon::L2_loadruh_pcr, /*HasImm*/false, /*MxOp*/3);
1512 case Hexagon::PS_loadrh_pcr:
1513 return RealCirc(Hexagon::L2_loadrh_pcr, /*HasImm*/false, /*MxOp*/3);
1514 case Hexagon::PS_loadri_pcr:
1515 return RealCirc(Hexagon::L2_loadri_pcr, /*HasImm*/false, /*MxOp*/3);
1516 case Hexagon::PS_loadrd_pcr:
1517 return RealCirc(Hexagon::L2_loadrd_pcr, /*HasImm*/false, /*MxOp*/3);
1518 case Hexagon::PS_storerb_pci:
1519 return RealCirc(Hexagon::S2_storerb_pci, /*HasImm*/true, /*MxOp*/3);
1520 case Hexagon::PS_storerh_pci:
1521 return RealCirc(Hexagon::S2_storerh_pci, /*HasImm*/true, /*MxOp*/3);
1522 case Hexagon::PS_storerf_pci:
1523 return RealCirc(Hexagon::S2_storerf_pci, /*HasImm*/true, /*MxOp*/3);
1524 case Hexagon::PS_storeri_pci:
1525 return RealCirc(Hexagon::S2_storeri_pci, /*HasImm*/true, /*MxOp*/3);
1526 case Hexagon::PS_storerd_pci:
1527 return RealCirc(Hexagon::S2_storerd_pci, /*HasImm*/true, /*MxOp*/3);
1528 case Hexagon::PS_storerb_pcr:
1529 return RealCirc(Hexagon::S2_storerb_pcr, /*HasImm*/false, /*MxOp*/2);
1530 case Hexagon::PS_storerh_pcr:
1531 return RealCirc(Hexagon::S2_storerh_pcr, /*HasImm*/false, /*MxOp*/2);
1532 case Hexagon::PS_storerf_pcr:
1533 return RealCirc(Hexagon::S2_storerf_pcr, /*HasImm*/false, /*MxOp*/2);
1534 case Hexagon::PS_storeri_pcr:
1535 return RealCirc(Hexagon::S2_storeri_pcr, /*HasImm*/false, /*MxOp*/2);
1536 case Hexagon::PS_storerd_pcr:
1537 return RealCirc(Hexagon::S2_storerd_pcr, /*HasImm*/false, /*MxOp*/2);
1538 }
1539
1540 return false;
1541}
1542
1545 MachineBasicBlock &MBB = *MI.getParent();
1546 const DebugLoc &DL = MI.getDebugLoc();
1547 unsigned Opc = MI.getOpcode();
1549
1550 switch (Opc) {
1551 case Hexagon::V6_vgathermh_pseudo:
1552 First = BuildMI(MBB, MI, DL, get(Hexagon::V6_vgathermh))
1553 .add(MI.getOperand(2))
1554 .add(MI.getOperand(3))
1555 .add(MI.getOperand(4));
1556 BuildMI(MBB, MI, DL, get(Hexagon::V6_vS32b_new_ai))
1557 .add(MI.getOperand(0))
1558 .addImm(MI.getOperand(1).getImm())
1559 .addReg(Hexagon::VTMP);
1560 MBB.erase(MI);
1561 return First.getInstrIterator();
1562
1563 case Hexagon::V6_vgathermw_pseudo:
1564 First = BuildMI(MBB, MI, DL, get(Hexagon::V6_vgathermw))
1565 .add(MI.getOperand(2))
1566 .add(MI.getOperand(3))
1567 .add(MI.getOperand(4));
1568 BuildMI(MBB, MI, DL, get(Hexagon::V6_vS32b_new_ai))
1569 .add(MI.getOperand(0))
1570 .addImm(MI.getOperand(1).getImm())
1571 .addReg(Hexagon::VTMP);
1572 MBB.erase(MI);
1573 return First.getInstrIterator();
1574
1575 case Hexagon::V6_vgathermhw_pseudo:
1576 First = BuildMI(MBB, MI, DL, get(Hexagon::V6_vgathermhw))
1577 .add(MI.getOperand(2))
1578 .add(MI.getOperand(3))
1579 .add(MI.getOperand(4));
1580 BuildMI(MBB, MI, DL, get(Hexagon::V6_vS32b_new_ai))
1581 .add(MI.getOperand(0))
1582 .addImm(MI.getOperand(1).getImm())
1583 .addReg(Hexagon::VTMP);
1584 MBB.erase(MI);
1585 return First.getInstrIterator();
1586
1587 case Hexagon::V6_vgathermhq_pseudo:
1588 First = BuildMI(MBB, MI, DL, get(Hexagon::V6_vgathermhq))
1589 .add(MI.getOperand(2))
1590 .add(MI.getOperand(3))
1591 .add(MI.getOperand(4))
1592 .add(MI.getOperand(5));
1593 BuildMI(MBB, MI, DL, get(Hexagon::V6_vS32b_new_ai))
1594 .add(MI.getOperand(0))
1595 .addImm(MI.getOperand(1).getImm())
1596 .addReg(Hexagon::VTMP);
1597 MBB.erase(MI);
1598 return First.getInstrIterator();
1599
1600 case Hexagon::V6_vgathermwq_pseudo:
1601 First = BuildMI(MBB, MI, DL, get(Hexagon::V6_vgathermwq))
1602 .add(MI.getOperand(2))
1603 .add(MI.getOperand(3))
1604 .add(MI.getOperand(4))
1605 .add(MI.getOperand(5));
1606 BuildMI(MBB, MI, DL, get(Hexagon::V6_vS32b_new_ai))
1607 .add(MI.getOperand(0))
1608 .addImm(MI.getOperand(1).getImm())
1609 .addReg(Hexagon::VTMP);
1610 MBB.erase(MI);
1611 return First.getInstrIterator();
1612
1613 case Hexagon::V6_vgathermhwq_pseudo:
1614 First = BuildMI(MBB, MI, DL, get(Hexagon::V6_vgathermhwq))
1615 .add(MI.getOperand(2))
1616 .add(MI.getOperand(3))
1617 .add(MI.getOperand(4))
1618 .add(MI.getOperand(5));
1619 BuildMI(MBB, MI, DL, get(Hexagon::V6_vS32b_new_ai))
1620 .add(MI.getOperand(0))
1621 .addImm(MI.getOperand(1).getImm())
1622 .addReg(Hexagon::VTMP);
1623 MBB.erase(MI);
1624 return First.getInstrIterator();
1625 }
1626
1627 return MI.getIterator();
1628}
1629
1630// We indicate that we want to reverse the branch by
1631// inserting the reversed branching opcode.
1634 if (Cond.empty())
1635 return true;
1636 assert(Cond[0].isImm() && "First entry in the cond vector not imm-val");
1637 unsigned opcode = Cond[0].getImm();
1638 //unsigned temp;
1639 assert(get(opcode).isBranch() && "Should be a branching condition.");
1640 if (isEndLoopN(opcode))
1641 return true;
1642 unsigned NewOpcode = getInvertedPredicatedOpcode(opcode);
1643 Cond[0].setImm(NewOpcode);
1644 return false;
1645}
1646
1649 DebugLoc DL;
1650 BuildMI(MBB, MI, DL, get(Hexagon::A2_nop));
1651}
1652
1655}
1656
1657// Returns true if an instruction is predicated irrespective of the predicate
1658// sense. For example, all of the following will return true.
1659// if (p0) R1 = add(R2, R3)
1660// if (!p0) R1 = add(R2, R3)
1661// if (p0.new) R1 = add(R2, R3)
1662// if (!p0.new) R1 = add(R2, R3)
1663// Note: New-value stores are not included here as in the current
1664// implementation, we don't need to check their predicate sense.
1666 const uint64_t F = MI.getDesc().TSFlags;
1668}
1669
1672 if (Cond.empty() || isNewValueJump(Cond[0].getImm()) ||
1673 isEndLoopN(Cond[0].getImm())) {
1674 LLVM_DEBUG(dbgs() << "\nCannot predicate:"; MI.dump(););
1675 return false;
1676 }
1677 int Opc = MI.getOpcode();
1678 assert (isPredicable(MI) && "Expected predicable instruction");
1679 bool invertJump = predOpcodeHasNot(Cond);
1680
1681 // We have to predicate MI "in place", i.e. after this function returns,
1682 // MI will need to be transformed into a predicated form. To avoid com-
1683 // plicated manipulations with the operands (handling tied operands,
1684 // etc.), build a new temporary instruction, then overwrite MI with it.
1685
1686 MachineBasicBlock &B = *MI.getParent();
1687 DebugLoc DL = MI.getDebugLoc();
1688 unsigned PredOpc = getCondOpcode(Opc, invertJump);
1689 MachineInstrBuilder T = BuildMI(B, MI, DL, get(PredOpc));
1690 unsigned NOp = 0, NumOps = MI.getNumOperands();
1691 while (NOp < NumOps) {
1692 MachineOperand &Op = MI.getOperand(NOp);
1693 if (!Op.isReg() || !Op.isDef() || Op.isImplicit())
1694 break;
1695 T.add(Op);
1696 NOp++;
1697 }
1698
1699 Register PredReg;
1700 unsigned PredRegPos, PredRegFlags;
1701 bool GotPredReg = getPredReg(Cond, PredReg, PredRegPos, PredRegFlags);
1702 (void)GotPredReg;
1703 assert(GotPredReg);
1704 T.addReg(PredReg, PredRegFlags);
1705 while (NOp < NumOps)
1706 T.add(MI.getOperand(NOp++));
1707
1708 MI.setDesc(get(PredOpc));
1709 while (unsigned n = MI.getNumOperands())
1710 MI.removeOperand(n-1);
1711 for (unsigned i = 0, n = T->getNumOperands(); i < n; ++i)
1712 MI.addOperand(T->getOperand(i));
1713
1714 MachineBasicBlock::instr_iterator TI = T->getIterator();
1715 B.erase(TI);
1716
1717 MachineRegisterInfo &MRI = B.getParent()->getRegInfo();
1718 MRI.clearKillFlags(PredReg);
1719 return true;
1720}
1721
1723 ArrayRef<MachineOperand> Pred2) const {
1724 // TODO: Fix this
1725 return false;
1726}
1727
1729 std::vector<MachineOperand> &Pred,
1730 bool SkipDead) const {
1731 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
1732
1733 for (const MachineOperand &MO : MI.operands()) {
1734 if (MO.isReg()) {
1735 if (!MO.isDef())
1736 continue;
1737 const TargetRegisterClass* RC = HRI.getMinimalPhysRegClass(MO.getReg());
1738 if (RC == &Hexagon::PredRegsRegClass) {
1739 Pred.push_back(MO);
1740 return true;
1741 }
1742 continue;
1743 } else if (MO.isRegMask()) {
1744 for (Register PR : Hexagon::PredRegsRegClass) {
1745 if (!MI.modifiesRegister(PR, &HRI))
1746 continue;
1747 Pred.push_back(MO);
1748 return true;
1749 }
1750 }
1751 }
1752 return false;
1753}
1754
1756 if (!MI.getDesc().isPredicable())
1757 return false;
1758
1759 if (MI.isCall() || isTailCall(MI)) {
1760 if (!Subtarget.usePredicatedCalls())
1761 return false;
1762 }
1763
1764 // HVX loads are not predicable on v60, but are on v62.
1765 if (!Subtarget.hasV62Ops()) {
1766 switch (MI.getOpcode()) {
1767 case Hexagon::V6_vL32b_ai:
1768 case Hexagon::V6_vL32b_pi:
1769 case Hexagon::V6_vL32b_ppu:
1770 case Hexagon::V6_vL32b_cur_ai:
1771 case Hexagon::V6_vL32b_cur_pi:
1772 case Hexagon::V6_vL32b_cur_ppu:
1773 case Hexagon::V6_vL32b_nt_ai:
1774 case Hexagon::V6_vL32b_nt_pi:
1775 case Hexagon::V6_vL32b_nt_ppu:
1776 case Hexagon::V6_vL32b_tmp_ai:
1777 case Hexagon::V6_vL32b_tmp_pi:
1778 case Hexagon::V6_vL32b_tmp_ppu:
1779 case Hexagon::V6_vL32b_nt_cur_ai:
1780 case Hexagon::V6_vL32b_nt_cur_pi:
1781 case Hexagon::V6_vL32b_nt_cur_ppu:
1782 case Hexagon::V6_vL32b_nt_tmp_ai:
1783 case Hexagon::V6_vL32b_nt_tmp_pi:
1784 case Hexagon::V6_vL32b_nt_tmp_ppu:
1785 return false;
1786 }
1787 }
1788 return true;
1789}
1790
1792 const MachineBasicBlock *MBB,
1793 const MachineFunction &MF) const {
1794 // Debug info is never a scheduling boundary. It's necessary to be explicit
1795 // due to the special treatment of IT instructions below, otherwise a
1796 // dbg_value followed by an IT will result in the IT instruction being
1797 // considered a scheduling hazard, which is wrong. It should be the actual
1798 // instruction preceding the dbg_value instruction(s), just like it is
1799 // when debug info is not present.
1800 if (MI.isDebugInstr())
1801 return false;
1802
1803 // Throwing call is a boundary.
1804 if (MI.isCall()) {
1805 // Don't mess around with no return calls.
1806 if (doesNotReturn(MI))
1807 return true;
1808 // If any of the block's successors is a landing pad, this could be a
1809 // throwing call.
1810 for (auto *I : MBB->successors())
1811 if (I->isEHPad())
1812 return true;
1813 }
1814
1815 // Terminators and labels can't be scheduled around.
1816 if (MI.getDesc().isTerminator() || MI.isPosition())
1817 return true;
1818
1819 // INLINEASM_BR can jump to another block
1820 if (MI.getOpcode() == TargetOpcode::INLINEASM_BR)
1821 return true;
1822
1823 if (MI.isInlineAsm() && !ScheduleInlineAsm)
1824 return true;
1825
1826 return false;
1827}
1828
1829/// Measure the specified inline asm to determine an approximation of its
1830/// length.
1831/// Comments (which run till the next SeparatorString or newline) do not
1832/// count as an instruction.
1833/// Any other non-whitespace text is considered an instruction, with
1834/// multiple instructions separated by SeparatorString or newlines.
1835/// Variable-length instructions are not handled here; this function
1836/// may be overloaded in the target code to do that.
1837/// Hexagon counts the number of ##'s and adjust for that many
1838/// constant exenders.
1840 const MCAsmInfo &MAI,
1841 const TargetSubtargetInfo *STI) const {
1842 StringRef AStr(Str);
1843 // Count the number of instructions in the asm.
1844 bool atInsnStart = true;
1845 unsigned Length = 0;
1846 const unsigned MaxInstLength = MAI.getMaxInstLength(STI);
1847 for (; *Str; ++Str) {
1848 if (*Str == '\n' || strncmp(Str, MAI.getSeparatorString(),
1849 strlen(MAI.getSeparatorString())) == 0)
1850 atInsnStart = true;
1851 if (atInsnStart && !isSpace(static_cast<unsigned char>(*Str))) {
1852 Length += MaxInstLength;
1853 atInsnStart = false;
1854 }
1855 if (atInsnStart && strncmp(Str, MAI.getCommentString().data(),
1856 MAI.getCommentString().size()) == 0)
1857 atInsnStart = false;
1858 }
1859
1860 // Add to size number of constant extenders seen * 4.
1861 StringRef Occ("##");
1862 Length += AStr.count(Occ)*4;
1863 return Length;
1864}
1865
1868 const InstrItineraryData *II, const ScheduleDAG *DAG) const {
1869 if (UseDFAHazardRec)
1870 return new HexagonHazardRecognizer(II, this, Subtarget);
1872}
1873
1874/// For a comparison instruction, return the source registers in
1875/// \p SrcReg and \p SrcReg2 if having two register operands, and the value it
1876/// compares against in CmpValue. Return true if the comparison instruction
1877/// can be analyzed.
1879 Register &SrcReg2, int64_t &Mask,
1880 int64_t &Value) const {
1881 unsigned Opc = MI.getOpcode();
1882
1883 // Set mask and the first source register.
1884 switch (Opc) {
1885 case Hexagon::C2_cmpeq:
1886 case Hexagon::C2_cmpeqp:
1887 case Hexagon::C2_cmpgt:
1888 case Hexagon::C2_cmpgtp:
1889 case Hexagon::C2_cmpgtu:
1890 case Hexagon::C2_cmpgtup:
1891 case Hexagon::C4_cmpneq:
1892 case Hexagon::C4_cmplte:
1893 case Hexagon::C4_cmplteu:
1894 case Hexagon::C2_cmpeqi:
1895 case Hexagon::C2_cmpgti:
1896 case Hexagon::C2_cmpgtui:
1897 case Hexagon::C4_cmpneqi:
1898 case Hexagon::C4_cmplteui:
1899 case Hexagon::C4_cmpltei:
1900 SrcReg = MI.getOperand(1).getReg();
1901 Mask = ~0;
1902 break;
1903 case Hexagon::A4_cmpbeq:
1904 case Hexagon::A4_cmpbgt:
1905 case Hexagon::A4_cmpbgtu:
1906 case Hexagon::A4_cmpbeqi:
1907 case Hexagon::A4_cmpbgti:
1908 case Hexagon::A4_cmpbgtui:
1909 SrcReg = MI.getOperand(1).getReg();
1910 Mask = 0xFF;
1911 break;
1912 case Hexagon::A4_cmpheq:
1913 case Hexagon::A4_cmphgt:
1914 case Hexagon::A4_cmphgtu:
1915 case Hexagon::A4_cmpheqi:
1916 case Hexagon::A4_cmphgti:
1917 case Hexagon::A4_cmphgtui:
1918 SrcReg = MI.getOperand(1).getReg();
1919 Mask = 0xFFFF;
1920 break;
1921 }
1922
1923 // Set the value/second source register.
1924 switch (Opc) {
1925 case Hexagon::C2_cmpeq:
1926 case Hexagon::C2_cmpeqp:
1927 case Hexagon::C2_cmpgt:
1928 case Hexagon::C2_cmpgtp:
1929 case Hexagon::C2_cmpgtu:
1930 case Hexagon::C2_cmpgtup:
1931 case Hexagon::A4_cmpbeq:
1932 case Hexagon::A4_cmpbgt:
1933 case Hexagon::A4_cmpbgtu:
1934 case Hexagon::A4_cmpheq:
1935 case Hexagon::A4_cmphgt:
1936 case Hexagon::A4_cmphgtu:
1937 case Hexagon::C4_cmpneq:
1938 case Hexagon::C4_cmplte:
1939 case Hexagon::C4_cmplteu:
1940 SrcReg2 = MI.getOperand(2).getReg();
1941 Value = 0;
1942 return true;
1943
1944 case Hexagon::C2_cmpeqi:
1945 case Hexagon::C2_cmpgtui:
1946 case Hexagon::C2_cmpgti:
1947 case Hexagon::C4_cmpneqi:
1948 case Hexagon::C4_cmplteui:
1949 case Hexagon::C4_cmpltei:
1950 case Hexagon::A4_cmpbeqi:
1951 case Hexagon::A4_cmpbgti:
1952 case Hexagon::A4_cmpbgtui:
1953 case Hexagon::A4_cmpheqi:
1954 case Hexagon::A4_cmphgti:
1955 case Hexagon::A4_cmphgtui: {
1956 SrcReg2 = 0;
1957 const MachineOperand &Op2 = MI.getOperand(2);
1958 if (!Op2.isImm())
1959 return false;
1960 Value = MI.getOperand(2).getImm();
1961 return true;
1962 }
1963 }
1964
1965 return false;
1966}
1967
1969 const MachineInstr &MI,
1970 unsigned *PredCost) const {
1971 return getInstrTimingClassLatency(ItinData, MI);
1972}
1973
1975 const TargetSubtargetInfo &STI) const {
1977 return static_cast<const HexagonSubtarget&>(STI).createDFAPacketizer(II);
1978}
1979
1980// Inspired by this pair:
1981// %r13 = L2_loadri_io %r29, 136; mem:LD4[FixedStack0]
1982// S2_storeri_io %r29, 132, killed %r1; flags: mem:ST4[FixedStack1]
1983// Currently AA considers the addresses in these instructions to be aliasing.
1985 const MachineInstr &MIa, const MachineInstr &MIb) const {
1988 return false;
1989
1990 // Instructions that are pure loads, not loads and stores like memops are not
1991 // dependent.
1992 if (MIa.mayLoad() && !isMemOp(MIa) && MIb.mayLoad() && !isMemOp(MIb))
1993 return true;
1994
1995 // Get the base register in MIa.
1996 unsigned BasePosA, OffsetPosA;
1997 if (!getBaseAndOffsetPosition(MIa, BasePosA, OffsetPosA))
1998 return false;
1999 const MachineOperand &BaseA = MIa.getOperand(BasePosA);
2000 Register BaseRegA = BaseA.getReg();
2001 unsigned BaseSubA = BaseA.getSubReg();
2002
2003 // Get the base register in MIb.
2004 unsigned BasePosB, OffsetPosB;
2005 if (!getBaseAndOffsetPosition(MIb, BasePosB, OffsetPosB))
2006 return false;
2007 const MachineOperand &BaseB = MIb.getOperand(BasePosB);
2008 Register BaseRegB = BaseB.getReg();
2009 unsigned BaseSubB = BaseB.getSubReg();
2010
2011 if (BaseRegA != BaseRegB || BaseSubA != BaseSubB)
2012 return false;
2013
2014 // Get the access sizes.
2015 unsigned SizeA = getMemAccessSize(MIa);
2016 unsigned SizeB = getMemAccessSize(MIb);
2017
2018 // Get the offsets. Handle immediates only for now.
2019 const MachineOperand &OffA = MIa.getOperand(OffsetPosA);
2020 const MachineOperand &OffB = MIb.getOperand(OffsetPosB);
2021 if (!MIa.getOperand(OffsetPosA).isImm() ||
2022 !MIb.getOperand(OffsetPosB).isImm())
2023 return false;
2024 int OffsetA = isPostIncrement(MIa) ? 0 : OffA.getImm();
2025 int OffsetB = isPostIncrement(MIb) ? 0 : OffB.getImm();
2026
2027 // This is a mem access with the same base register and known offsets from it.
2028 // Reason about it.
2029 if (OffsetA > OffsetB) {
2030 uint64_t OffDiff = (uint64_t)((int64_t)OffsetA - (int64_t)OffsetB);
2031 return SizeB <= OffDiff;
2032 }
2033 if (OffsetA < OffsetB) {
2034 uint64_t OffDiff = (uint64_t)((int64_t)OffsetB - (int64_t)OffsetA);
2035 return SizeA <= OffDiff;
2036 }
2037
2038 return false;
2039}
2040
2041/// If the instruction is an increment of a constant value, return the amount.
2043 int &Value) const {
2044 if (isPostIncrement(MI)) {
2045 unsigned BasePos = 0, OffsetPos = 0;
2046 if (!getBaseAndOffsetPosition(MI, BasePos, OffsetPos))
2047 return false;
2048 const MachineOperand &OffsetOp = MI.getOperand(OffsetPos);
2049 if (OffsetOp.isImm()) {
2050 Value = OffsetOp.getImm();
2051 return true;
2052 }
2053 } else if (MI.getOpcode() == Hexagon::A2_addi) {
2054 const MachineOperand &AddOp = MI.getOperand(2);
2055 if (AddOp.isImm()) {
2056 Value = AddOp.getImm();
2057 return true;
2058 }
2059 }
2060
2061 return false;
2062}
2063
2064std::pair<unsigned, unsigned>
2066 return std::make_pair(TF & ~HexagonII::MO_Bitmasks,
2068}
2069
2072 using namespace HexagonII;
2073
2074 static const std::pair<unsigned, const char*> Flags[] = {
2075 {MO_PCREL, "hexagon-pcrel"},
2076 {MO_GOT, "hexagon-got"},
2077 {MO_LO16, "hexagon-lo16"},
2078 {MO_HI16, "hexagon-hi16"},
2079 {MO_GPREL, "hexagon-gprel"},
2080 {MO_GDGOT, "hexagon-gdgot"},
2081 {MO_GDPLT, "hexagon-gdplt"},
2082 {MO_IE, "hexagon-ie"},
2083 {MO_IEGOT, "hexagon-iegot"},
2084 {MO_TPREL, "hexagon-tprel"}
2085 };
2086 return ArrayRef(Flags);
2087}
2088
2091 using namespace HexagonII;
2092
2093 static const std::pair<unsigned, const char*> Flags[] = {
2094 {HMOTF_ConstExtended, "hexagon-ext"}
2095 };
2096 return ArrayRef(Flags);
2097}
2098
2101 const TargetRegisterClass *TRC;
2102 if (VT == MVT::i1) {
2103 TRC = &Hexagon::PredRegsRegClass;
2104 } else if (VT == MVT::i32 || VT == MVT::f32) {
2105 TRC = &Hexagon::IntRegsRegClass;
2106 } else if (VT == MVT::i64 || VT == MVT::f64) {
2107 TRC = &Hexagon::DoubleRegsRegClass;
2108 } else {
2109 llvm_unreachable("Cannot handle this register class");
2110 }
2111
2112 Register NewReg = MRI.createVirtualRegister(TRC);
2113 return NewReg;
2114}
2115
2118}
2119
2121 const uint64_t F = MI.getDesc().TSFlags;
2123}
2124
2127}
2128
2130 return !isTC1(MI) && !isTC2Early(MI) && !MI.getDesc().mayLoad() &&
2131 !MI.getDesc().mayStore() &&
2132 MI.getDesc().getOpcode() != Hexagon::S2_allocframe &&
2133 MI.getDesc().getOpcode() != Hexagon::L2_deallocframe &&
2134 !isMemOp(MI) && !MI.isBranch() && !MI.isReturn() && !MI.isCall();
2135}
2136
2137// Return true if the instruction is a compound branch instruction.
2139 return getType(MI) == HexagonII::TypeCJ && MI.isBranch();
2140}
2141
2142// TODO: In order to have isExtendable for fpimm/f32Ext, we need to handle
2143// isFPImm and later getFPImm as well.
2145 const uint64_t F = MI.getDesc().TSFlags;
2147 if (isExtended) // Instruction must be extended.
2148 return true;
2149
2150 unsigned isExtendable =
2152 if (!isExtendable)
2153 return false;
2154
2155 if (MI.isCall())
2156 return false;
2157
2158 short ExtOpNum = getCExtOpNum(MI);
2159 const MachineOperand &MO = MI.getOperand(ExtOpNum);
2160 // Use MO operand flags to determine if MO
2161 // has the HMOTF_ConstExtended flag set.
2163 return true;
2164 // If this is a Machine BB address we are talking about, and it is
2165 // not marked as extended, say so.
2166 if (MO.isMBB())
2167 return false;
2168
2169 // We could be using an instruction with an extendable immediate and shoehorn
2170 // a global address into it. If it is a global address it will be constant
2171 // extended. We do this for COMBINE.
2172 if (MO.isGlobal() || MO.isSymbol() || MO.isBlockAddress() ||
2173 MO.isJTI() || MO.isCPI() || MO.isFPImm())
2174 return true;
2175
2176 // If the extendable operand is not 'Immediate' type, the instruction should
2177 // have 'isExtended' flag set.
2178 assert(MO.isImm() && "Extendable operand must be Immediate type");
2179
2180 int64_t Value = MO.getImm();
2182 int32_t SValue = Value;
2183 int32_t MinValue = getMinValue(MI);
2184 int32_t MaxValue = getMaxValue(MI);
2185 return SValue < MinValue || SValue > MaxValue;
2186 }
2187 uint32_t UValue = Value;
2188 uint32_t MinValue = getMinValue(MI);
2189 uint32_t MaxValue = getMaxValue(MI);
2190 return UValue < MinValue || UValue > MaxValue;
2191}
2192
2194 switch (MI.getOpcode()) {
2195 case Hexagon::L4_return:
2196 case Hexagon::L4_return_t:
2197 case Hexagon::L4_return_f:
2198 case Hexagon::L4_return_tnew_pnt:
2199 case Hexagon::L4_return_fnew_pnt:
2200 case Hexagon::L4_return_tnew_pt:
2201 case Hexagon::L4_return_fnew_pt:
2202 return true;
2203 }
2204 return false;
2205}
2206
2207// Return true when ConsMI uses a register defined by ProdMI.
2209 const MachineInstr &ConsMI) const {
2210 if (!ProdMI.getDesc().getNumDefs())
2211 return false;
2212 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
2213
2218
2219 parseOperands(ProdMI, DefsA, UsesA);
2220 parseOperands(ConsMI, DefsB, UsesB);
2221
2222 for (auto &RegA : DefsA)
2223 for (auto &RegB : UsesB) {
2224 // True data dependency.
2225 if (RegA == RegB)
2226 return true;
2227
2228 if (RegA.isPhysical() && llvm::is_contained(HRI.subregs(RegA), RegB))
2229 return true;
2230
2231 if (RegB.isPhysical() && llvm::is_contained(HRI.subregs(RegB), RegA))
2232 return true;
2233 }
2234
2235 return false;
2236}
2237
2238// Returns true if the instruction is alread a .cur.
2240 switch (MI.getOpcode()) {
2241 case Hexagon::V6_vL32b_cur_pi:
2242 case Hexagon::V6_vL32b_cur_ai:
2243 return true;
2244 }
2245 return false;
2246}
2247
2248// Returns true, if any one of the operands is a dot new
2249// insn, whether it is predicated dot new or register dot new.
2252 return true;
2253
2254 return false;
2255}
2256
2257/// Symmetrical. See if these two instructions are fit for duplex pair.
2259 const MachineInstr &MIb) const {
2262 return (isDuplexPairMatch(MIaG, MIbG) || isDuplexPairMatch(MIbG, MIaG));
2263}
2264
2265bool HexagonInstrInfo::isEndLoopN(unsigned Opcode) const {
2266 return (Opcode == Hexagon::ENDLOOP0 ||
2267 Opcode == Hexagon::ENDLOOP1);
2268}
2269
2270bool HexagonInstrInfo::isExpr(unsigned OpType) const {
2271 switch(OpType) {
2278 return true;
2279 default:
2280 return false;
2281 }
2282}
2283
2285 const MCInstrDesc &MID = MI.getDesc();
2286 const uint64_t F = MID.TSFlags;
2288 return true;
2289
2290 // TODO: This is largely obsolete now. Will need to be removed
2291 // in consecutive patches.
2292 switch (MI.getOpcode()) {
2293 // PS_fi and PS_fia remain special cases.
2294 case Hexagon::PS_fi:
2295 case Hexagon::PS_fia:
2296 return true;
2297 default:
2298 return false;
2299 }
2300 return false;
2301}
2302
2303// This returns true in two cases:
2304// - The OP code itself indicates that this is an extended instruction.
2305// - One of MOs has been marked with HMOTF_ConstExtended flag.
2307 // First check if this is permanently extended op code.
2308 const uint64_t F = MI.getDesc().TSFlags;
2310 return true;
2311 // Use MO operand flags to determine if one of MI's operands
2312 // has HMOTF_ConstExtended flag set.
2313 for (const MachineOperand &MO : MI.operands())
2314 if (MO.getTargetFlags() & HexagonII::HMOTF_ConstExtended)
2315 return true;
2316 return false;
2317}
2318
2320 unsigned Opcode = MI.getOpcode();
2321 const uint64_t F = get(Opcode).TSFlags;
2322 return (F >> HexagonII::FPPos) & HexagonII::FPMask;
2323}
2324
2325// No V60 HVX VMEM with A_INDIRECT.
2327 const MachineInstr &J) const {
2328 if (!isHVXVec(I))
2329 return false;
2330 if (!I.mayLoad() && !I.mayStore())
2331 return false;
2332 return J.isIndirectBranch() || isIndirectCall(J) || isIndirectL4Return(J);
2333}
2334
2336 switch (MI.getOpcode()) {
2337 case Hexagon::J2_callr:
2338 case Hexagon::J2_callrf:
2339 case Hexagon::J2_callrt:
2340 case Hexagon::PS_call_nr:
2341 return true;
2342 }
2343 return false;
2344}
2345
2347 switch (MI.getOpcode()) {
2348 case Hexagon::L4_return:
2349 case Hexagon::L4_return_t:
2350 case Hexagon::L4_return_f:
2351 case Hexagon::L4_return_fnew_pnt:
2352 case Hexagon::L4_return_fnew_pt:
2353 case Hexagon::L4_return_tnew_pnt:
2354 case Hexagon::L4_return_tnew_pt:
2355 return true;
2356 }
2357 return false;
2358}
2359
2361 switch (MI.getOpcode()) {
2362 case Hexagon::J2_jumpr:
2363 case Hexagon::J2_jumprt:
2364 case Hexagon::J2_jumprf:
2365 case Hexagon::J2_jumprtnewpt:
2366 case Hexagon::J2_jumprfnewpt:
2367 case Hexagon::J2_jumprtnew:
2368 case Hexagon::J2_jumprfnew:
2369 return true;
2370 }
2371 return false;
2372}
2373
2374// Return true if a given MI can accommodate given offset.
2375// Use abs estimate as oppose to the exact number.
2376// TODO: This will need to be changed to use MC level
2377// definition of instruction extendable field size.
2379 unsigned offset) const {
2380 // This selection of jump instructions matches to that what
2381 // analyzeBranch can parse, plus NVJ.
2382 if (isNewValueJump(MI)) // r9:2
2383 return isInt<11>(offset);
2384
2385 switch (MI.getOpcode()) {
2386 // Still missing Jump to address condition on register value.
2387 default:
2388 return false;
2389 case Hexagon::J2_jump: // bits<24> dst; // r22:2
2390 case Hexagon::J2_call:
2391 case Hexagon::PS_call_nr:
2392 return isInt<24>(offset);
2393 case Hexagon::J2_jumpt: //bits<17> dst; // r15:2
2394 case Hexagon::J2_jumpf:
2395 case Hexagon::J2_jumptnew:
2396 case Hexagon::J2_jumptnewpt:
2397 case Hexagon::J2_jumpfnew:
2398 case Hexagon::J2_jumpfnewpt:
2399 case Hexagon::J2_callt:
2400 case Hexagon::J2_callf:
2401 return isInt<17>(offset);
2402 case Hexagon::J2_loop0i:
2403 case Hexagon::J2_loop0iext:
2404 case Hexagon::J2_loop0r:
2405 case Hexagon::J2_loop0rext:
2406 case Hexagon::J2_loop1i:
2407 case Hexagon::J2_loop1iext:
2408 case Hexagon::J2_loop1r:
2409 case Hexagon::J2_loop1rext:
2410 return isInt<9>(offset);
2411 // TODO: Add all the compound branches here. Can we do this in Relation model?
2412 case Hexagon::J4_cmpeqi_tp0_jump_nt:
2413 case Hexagon::J4_cmpeqi_tp1_jump_nt:
2414 case Hexagon::J4_cmpeqn1_tp0_jump_nt:
2415 case Hexagon::J4_cmpeqn1_tp1_jump_nt:
2416 return isInt<11>(offset);
2417 }
2418}
2419
2421 // Instructions with iclass A_CVI_VX and attribute A_CVI_LATE uses a multiply
2422 // resource, but all operands can be received late like an ALU instruction.
2424}
2425
2427 unsigned Opcode = MI.getOpcode();
2428 return Opcode == Hexagon::J2_loop0i ||
2429 Opcode == Hexagon::J2_loop0r ||
2430 Opcode == Hexagon::J2_loop0iext ||
2431 Opcode == Hexagon::J2_loop0rext ||
2432 Opcode == Hexagon::J2_loop1i ||
2433 Opcode == Hexagon::J2_loop1r ||
2434 Opcode == Hexagon::J2_loop1iext ||
2435 Opcode == Hexagon::J2_loop1rext;
2436}
2437
2439 switch (MI.getOpcode()) {
2440 default: return false;
2441 case Hexagon::L4_iadd_memopw_io:
2442 case Hexagon::L4_isub_memopw_io:
2443 case Hexagon::L4_add_memopw_io:
2444 case Hexagon::L4_sub_memopw_io:
2445 case Hexagon::L4_and_memopw_io:
2446 case Hexagon::L4_or_memopw_io:
2447 case Hexagon::L4_iadd_memoph_io:
2448 case Hexagon::L4_isub_memoph_io:
2449 case Hexagon::L4_add_memoph_io:
2450 case Hexagon::L4_sub_memoph_io:
2451 case Hexagon::L4_and_memoph_io:
2452 case Hexagon::L4_or_memoph_io:
2453 case Hexagon::L4_iadd_memopb_io:
2454 case Hexagon::L4_isub_memopb_io:
2455 case Hexagon::L4_add_memopb_io:
2456 case Hexagon::L4_sub_memopb_io:
2457 case Hexagon::L4_and_memopb_io:
2458 case Hexagon::L4_or_memopb_io:
2459 case Hexagon::L4_ior_memopb_io:
2460 case Hexagon::L4_ior_memoph_io:
2461 case Hexagon::L4_ior_memopw_io:
2462 case Hexagon::L4_iand_memopb_io:
2463 case Hexagon::L4_iand_memoph_io:
2464 case Hexagon::L4_iand_memopw_io:
2465 return true;
2466 }
2467 return false;
2468}
2469
2471 const uint64_t F = MI.getDesc().TSFlags;
2473}
2474
2475bool HexagonInstrInfo::isNewValue(unsigned Opcode) const {
2476 const uint64_t F = get(Opcode).TSFlags;
2478}
2479
2481 return isNewValueJump(MI) || isNewValueStore(MI);
2482}
2483
2485 return isNewValue(MI) && MI.isBranch();
2486}
2487
2488bool HexagonInstrInfo::isNewValueJump(unsigned Opcode) const {
2489 return isNewValue(Opcode) && get(Opcode).isBranch() && isPredicated(Opcode);
2490}
2491
2493 const uint64_t F = MI.getDesc().TSFlags;
2495}
2496
2497bool HexagonInstrInfo::isNewValueStore(unsigned Opcode) const {
2498 const uint64_t F = get(Opcode).TSFlags;
2500}
2501
2502// Returns true if a particular operand is extendable for an instruction.
2504 unsigned OperandNum) const {
2505 const uint64_t F = MI.getDesc().TSFlags;
2507 == OperandNum;
2508}
2509
2511 const uint64_t F = MI.getDesc().TSFlags;
2514}
2515
2516bool HexagonInstrInfo::isPredicatedNew(unsigned Opcode) const {
2517 const uint64_t F = get(Opcode).TSFlags;
2518 assert(isPredicated(Opcode));
2520}
2521
2523 const uint64_t F = MI.getDesc().TSFlags;
2524 return !((F >> HexagonII::PredicatedFalsePos) &
2526}
2527
2528bool HexagonInstrInfo::isPredicatedTrue(unsigned Opcode) const {
2529 const uint64_t F = get(Opcode).TSFlags;
2530 // Make sure that the instruction is predicated.
2532 return !((F >> HexagonII::PredicatedFalsePos) &
2534}
2535
2536bool HexagonInstrInfo::isPredicated(unsigned Opcode) const {
2537 const uint64_t F = get(Opcode).TSFlags;
2539}
2540
2541bool HexagonInstrInfo::isPredicateLate(unsigned Opcode) const {
2542 const uint64_t F = get(Opcode).TSFlags;
2544}
2545
2546bool HexagonInstrInfo::isPredictedTaken(unsigned Opcode) const {
2547 const uint64_t F = get(Opcode).TSFlags;
2548 assert(get(Opcode).isBranch() &&
2549 (isPredicatedNew(Opcode) || isNewValue(Opcode)));
2551}
2552
2554 return MI.getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4 ||
2555 MI.getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4_EXT ||
2556 MI.getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4_PIC ||
2557 MI.getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4_EXT_PIC;
2558}
2559
2561 switch (MI.getOpcode()) {
2562 // Byte
2563 case Hexagon::L2_loadrb_io:
2564 case Hexagon::L4_loadrb_ur:
2565 case Hexagon::L4_loadrb_ap:
2566 case Hexagon::L2_loadrb_pr:
2567 case Hexagon::L2_loadrb_pbr:
2568 case Hexagon::L2_loadrb_pi:
2569 case Hexagon::L2_loadrb_pci:
2570 case Hexagon::L2_loadrb_pcr:
2571 case Hexagon::L2_loadbsw2_io:
2572 case Hexagon::L4_loadbsw2_ur:
2573 case Hexagon::L4_loadbsw2_ap:
2574 case Hexagon::L2_loadbsw2_pr:
2575 case Hexagon::L2_loadbsw2_pbr:
2576 case Hexagon::L2_loadbsw2_pi:
2577 case Hexagon::L2_loadbsw2_pci:
2578 case Hexagon::L2_loadbsw2_pcr:
2579 case Hexagon::L2_loadbsw4_io:
2580 case Hexagon::L4_loadbsw4_ur:
2581 case Hexagon::L4_loadbsw4_ap:
2582 case Hexagon::L2_loadbsw4_pr:
2583 case Hexagon::L2_loadbsw4_pbr:
2584 case Hexagon::L2_loadbsw4_pi:
2585 case Hexagon::L2_loadbsw4_pci:
2586 case Hexagon::L2_loadbsw4_pcr:
2587 case Hexagon::L4_loadrb_rr:
2588 case Hexagon::L2_ploadrbt_io:
2589 case Hexagon::L2_ploadrbt_pi:
2590 case Hexagon::L2_ploadrbf_io:
2591 case Hexagon::L2_ploadrbf_pi:
2592 case Hexagon::L2_ploadrbtnew_io:
2593 case Hexagon::L2_ploadrbfnew_io:
2594 case Hexagon::L4_ploadrbt_rr:
2595 case Hexagon::L4_ploadrbf_rr:
2596 case Hexagon::L4_ploadrbtnew_rr:
2597 case Hexagon::L4_ploadrbfnew_rr:
2598 case Hexagon::L2_ploadrbtnew_pi:
2599 case Hexagon::L2_ploadrbfnew_pi:
2600 case Hexagon::L4_ploadrbt_abs:
2601 case Hexagon::L4_ploadrbf_abs:
2602 case Hexagon::L4_ploadrbtnew_abs:
2603 case Hexagon::L4_ploadrbfnew_abs:
2604 case Hexagon::L2_loadrbgp:
2605 // Half
2606 case Hexagon::L2_loadrh_io:
2607 case Hexagon::L4_loadrh_ur:
2608 case Hexagon::L4_loadrh_ap:
2609 case Hexagon::L2_loadrh_pr:
2610 case Hexagon::L2_loadrh_pbr:
2611 case Hexagon::L2_loadrh_pi:
2612 case Hexagon::L2_loadrh_pci:
2613 case Hexagon::L2_loadrh_pcr:
2614 case Hexagon::L4_loadrh_rr:
2615 case Hexagon::L2_ploadrht_io:
2616 case Hexagon::L2_ploadrht_pi:
2617 case Hexagon::L2_ploadrhf_io:
2618 case Hexagon::L2_ploadrhf_pi:
2619 case Hexagon::L2_ploadrhtnew_io:
2620 case Hexagon::L2_ploadrhfnew_io:
2621 case Hexagon::L4_ploadrht_rr:
2622 case Hexagon::L4_ploadrhf_rr:
2623 case Hexagon::L4_ploadrhtnew_rr:
2624 case Hexagon::L4_ploadrhfnew_rr:
2625 case Hexagon::L2_ploadrhtnew_pi:
2626 case Hexagon::L2_ploadrhfnew_pi:
2627 case Hexagon::L4_ploadrht_abs:
2628 case Hexagon::L4_ploadrhf_abs:
2629 case Hexagon::L4_ploadrhtnew_abs:
2630 case Hexagon::L4_ploadrhfnew_abs:
2631 case Hexagon::L2_loadrhgp:
2632 return true;
2633 default:
2634 return false;
2635 }
2636}
2637
2639 const uint64_t F = MI.getDesc().TSFlags;
2641}
2642
2644 switch (MI.getOpcode()) {
2645 case Hexagon::STriw_pred:
2646 case Hexagon::LDriw_pred:
2647 return true;
2648 default:
2649 return false;
2650 }
2651}
2652
2654 if (!MI.isBranch())
2655 return false;
2656
2657 for (auto &Op : MI.operands())
2658 if (Op.isGlobal() || Op.isSymbol())
2659 return true;
2660 return false;
2661}
2662
2663// Returns true when SU has a timing class TC1.
2665 unsigned SchedClass = MI.getDesc().getSchedClass();
2666 return is_TC1(SchedClass);
2667}
2668
2670 unsigned SchedClass = MI.getDesc().getSchedClass();
2671 return is_TC2(SchedClass);
2672}
2673
2675 unsigned SchedClass = MI.getDesc().getSchedClass();
2676 return is_TC2early(SchedClass);
2677}
2678
2680 unsigned SchedClass = MI.getDesc().getSchedClass();
2681 return is_TC4x(SchedClass);
2682}
2683
2684// Schedule this ASAP.
2686 const MachineInstr &MI2) const {
2687 if (mayBeCurLoad(MI1)) {
2688 // if (result of SU is used in Next) return true;
2689 Register DstReg = MI1.getOperand(0).getReg();
2690 int N = MI2.getNumOperands();
2691 for (int I = 0; I < N; I++)
2692 if (MI2.getOperand(I).isReg() && DstReg == MI2.getOperand(I).getReg())
2693 return true;
2694 }
2695 if (mayBeNewStore(MI2))
2696 if (MI2.getOpcode() == Hexagon::V6_vS32b_pi)
2697 if (MI1.getOperand(0).isReg() && MI2.getOperand(3).isReg() &&
2698 MI1.getOperand(0).getReg() == MI2.getOperand(3).getReg())
2699 return true;
2700 return false;
2701}
2702
2704 const uint64_t V = getType(MI);
2706}
2707
2708// Check if the Offset is a valid auto-inc imm by Load/Store Type.
2710 int Size = VT.getSizeInBits() / 8;
2711 if (Offset % Size != 0)
2712 return false;
2713 int Count = Offset / Size;
2714
2715 switch (VT.getSimpleVT().SimpleTy) {
2716 // For scalars the auto-inc is s4
2717 case MVT::i8:
2718 case MVT::i16:
2719 case MVT::i32:
2720 case MVT::i64:
2721 case MVT::f32:
2722 case MVT::f64:
2723 case MVT::v2i16:
2724 case MVT::v2i32:
2725 case MVT::v4i8:
2726 case MVT::v4i16:
2727 case MVT::v8i8:
2728 return isInt<4>(Count);
2729 // For HVX vectors the auto-inc is s3
2730 case MVT::v64i8:
2731 case MVT::v32i16:
2732 case MVT::v16i32:
2733 case MVT::v8i64:
2734 case MVT::v128i8:
2735 case MVT::v64i16:
2736 case MVT::v32i32:
2737 case MVT::v16i64:
2738 return isInt<3>(Count);
2739 default:
2740 break;
2741 }
2742
2743 llvm_unreachable("Not an valid type!");
2744}
2745
2746bool HexagonInstrInfo::isValidOffset(unsigned Opcode, int Offset,
2747 const TargetRegisterInfo *TRI, bool Extend) const {
2748 // This function is to check whether the "Offset" is in the correct range of
2749 // the given "Opcode". If "Offset" is not in the correct range, "A2_addi" is
2750 // inserted to calculate the final address. Due to this reason, the function
2751 // assumes that the "Offset" has correct alignment.
2752 // We used to assert if the offset was not properly aligned, however,
2753 // there are cases where a misaligned pointer recast can cause this
2754 // problem, and we need to allow for it. The front end warns of such
2755 // misaligns with respect to load size.
2756 switch (Opcode) {
2757 case Hexagon::PS_vstorerq_ai:
2758 case Hexagon::PS_vstorerv_ai:
2759 case Hexagon::PS_vstorerw_ai:
2760 case Hexagon::PS_vstorerw_nt_ai:
2761 case Hexagon::PS_vloadrq_ai:
2762 case Hexagon::PS_vloadrv_ai:
2763 case Hexagon::PS_vloadrw_ai:
2764 case Hexagon::PS_vloadrw_nt_ai:
2765 case Hexagon::V6_vL32b_ai:
2766 case Hexagon::V6_vS32b_ai:
2767 case Hexagon::V6_vS32b_pred_ai:
2768 case Hexagon::V6_vS32b_npred_ai:
2769 case Hexagon::V6_vS32b_qpred_ai:
2770 case Hexagon::V6_vS32b_nqpred_ai:
2771 case Hexagon::V6_vS32b_new_ai:
2772 case Hexagon::V6_vS32b_new_pred_ai:
2773 case Hexagon::V6_vS32b_new_npred_ai:
2774 case Hexagon::V6_vS32b_nt_pred_ai:
2775 case Hexagon::V6_vS32b_nt_npred_ai:
2776 case Hexagon::V6_vS32b_nt_new_ai:
2777 case Hexagon::V6_vS32b_nt_new_pred_ai:
2778 case Hexagon::V6_vS32b_nt_new_npred_ai:
2779 case Hexagon::V6_vS32b_nt_qpred_ai:
2780 case Hexagon::V6_vS32b_nt_nqpred_ai:
2781 case Hexagon::V6_vL32b_nt_ai:
2782 case Hexagon::V6_vS32b_nt_ai:
2783 case Hexagon::V6_vL32Ub_ai:
2784 case Hexagon::V6_vS32Ub_ai:
2785 case Hexagon::V6_vL32b_cur_ai:
2786 case Hexagon::V6_vL32b_tmp_ai:
2787 case Hexagon::V6_vL32b_pred_ai:
2788 case Hexagon::V6_vL32b_npred_ai:
2789 case Hexagon::V6_vL32b_cur_pred_ai:
2790 case Hexagon::V6_vL32b_cur_npred_ai:
2791 case Hexagon::V6_vL32b_tmp_pred_ai:
2792 case Hexagon::V6_vL32b_tmp_npred_ai:
2793 case Hexagon::V6_vL32b_nt_cur_ai:
2794 case Hexagon::V6_vL32b_nt_tmp_ai:
2795 case Hexagon::V6_vL32b_nt_pred_ai:
2796 case Hexagon::V6_vL32b_nt_npred_ai:
2797 case Hexagon::V6_vL32b_nt_cur_pred_ai:
2798 case Hexagon::V6_vL32b_nt_cur_npred_ai:
2799 case Hexagon::V6_vL32b_nt_tmp_pred_ai:
2800 case Hexagon::V6_vL32b_nt_tmp_npred_ai:
2801 case Hexagon::V6_vgathermh_pseudo:
2802 case Hexagon::V6_vgathermw_pseudo:
2803 case Hexagon::V6_vgathermhw_pseudo:
2804 case Hexagon::V6_vgathermhq_pseudo:
2805 case Hexagon::V6_vgathermwq_pseudo:
2806 case Hexagon::V6_vgathermhwq_pseudo: {
2807 unsigned VectorSize = TRI->getSpillSize(Hexagon::HvxVRRegClass);
2808 assert(isPowerOf2_32(VectorSize));
2809 if (Offset & (VectorSize-1))
2810 return false;
2811 return isInt<4>(Offset >> Log2_32(VectorSize));
2812 }
2813
2814 case Hexagon::J2_loop0i:
2815 case Hexagon::J2_loop1i:
2816 return isUInt<10>(Offset);
2817
2818 case Hexagon::S4_storeirb_io:
2819 case Hexagon::S4_storeirbt_io:
2820 case Hexagon::S4_storeirbf_io:
2821 return isUInt<6>(Offset);
2822
2823 case Hexagon::S4_storeirh_io:
2824 case Hexagon::S4_storeirht_io:
2825 case Hexagon::S4_storeirhf_io:
2826 return isShiftedUInt<6,1>(Offset);
2827
2828 case Hexagon::S4_storeiri_io:
2829 case Hexagon::S4_storeirit_io:
2830 case Hexagon::S4_storeirif_io:
2831 return isShiftedUInt<6,2>(Offset);
2832 // Handle these two compare instructions that are not extendable.
2833 case Hexagon::A4_cmpbeqi:
2834 return isUInt<8>(Offset);
2835 case Hexagon::A4_cmpbgti:
2836 return isInt<8>(Offset);
2837 }
2838
2839 if (Extend)
2840 return true;
2841
2842 switch (Opcode) {
2843 case Hexagon::L2_loadri_io:
2844 case Hexagon::S2_storeri_io:
2845 return (Offset >= Hexagon_MEMW_OFFSET_MIN) &&
2847
2848 case Hexagon::L2_loadrd_io:
2849 case Hexagon::S2_storerd_io:
2850 return (Offset >= Hexagon_MEMD_OFFSET_MIN) &&
2852
2853 case Hexagon::L2_loadrh_io:
2854 case Hexagon::L2_loadruh_io:
2855 case Hexagon::S2_storerh_io:
2856 case Hexagon::S2_storerf_io:
2857 return (Offset >= Hexagon_MEMH_OFFSET_MIN) &&
2859
2860 case Hexagon::L2_loadrb_io:
2861 case Hexagon::L2_loadrub_io:
2862 case Hexagon::S2_storerb_io:
2863 return (Offset >= Hexagon_MEMB_OFFSET_MIN) &&
2865
2866 case Hexagon::A2_addi:
2867 return (Offset >= Hexagon_ADDI_OFFSET_MIN) &&
2869
2870 case Hexagon::L4_iadd_memopw_io:
2871 case Hexagon::L4_isub_memopw_io:
2872 case Hexagon::L4_add_memopw_io:
2873 case Hexagon::L4_sub_memopw_io:
2874 case Hexagon::L4_iand_memopw_io:
2875 case Hexagon::L4_ior_memopw_io:
2876 case Hexagon::L4_and_memopw_io:
2877 case Hexagon::L4_or_memopw_io:
2878 return (0 <= Offset && Offset <= 255);
2879
2880 case Hexagon::L4_iadd_memoph_io:
2881 case Hexagon::L4_isub_memoph_io:
2882 case Hexagon::L4_add_memoph_io:
2883 case Hexagon::L4_sub_memoph_io:
2884 case Hexagon::L4_iand_memoph_io:
2885 case Hexagon::L4_ior_memoph_io:
2886 case Hexagon::L4_and_memoph_io:
2887 case Hexagon::L4_or_memoph_io:
2888 return (0 <= Offset && Offset <= 127);
2889
2890 case Hexagon::L4_iadd_memopb_io:
2891 case Hexagon::L4_isub_memopb_io:
2892 case Hexagon::L4_add_memopb_io:
2893 case Hexagon::L4_sub_memopb_io:
2894 case Hexagon::L4_iand_memopb_io:
2895 case Hexagon::L4_ior_memopb_io:
2896 case Hexagon::L4_and_memopb_io:
2897 case Hexagon::L4_or_memopb_io:
2898 return (0 <= Offset && Offset <= 63);
2899
2900 // LDriw_xxx and STriw_xxx are pseudo operations, so it has to take offset of
2901 // any size. Later pass knows how to handle it.
2902 case Hexagon::STriw_pred:
2903 case Hexagon::LDriw_pred:
2904 case Hexagon::STriw_ctr:
2905 case Hexagon::LDriw_ctr:
2906 return true;
2907
2908 case Hexagon::PS_fi:
2909 case Hexagon::PS_fia:
2910 case Hexagon::INLINEASM:
2911 return true;
2912
2913 case Hexagon::L2_ploadrbt_io:
2914 case Hexagon::L2_ploadrbf_io:
2915 case Hexagon::L2_ploadrubt_io:
2916 case Hexagon::L2_ploadrubf_io:
2917 case Hexagon::S2_pstorerbt_io:
2918 case Hexagon::S2_pstorerbf_io:
2919 return isUInt<6>(Offset);
2920
2921 case Hexagon::L2_ploadrht_io:
2922 case Hexagon::L2_ploadrhf_io:
2923 case Hexagon::L2_ploadruht_io:
2924 case Hexagon::L2_ploadruhf_io:
2925 case Hexagon::S2_pstorerht_io:
2926 case Hexagon::S2_pstorerhf_io:
2927 return isShiftedUInt<6,1>(Offset);
2928
2929 case Hexagon::L2_ploadrit_io:
2930 case Hexagon::L2_ploadrif_io:
2931 case Hexagon::S2_pstorerit_io:
2932 case Hexagon::S2_pstorerif_io:
2933 return isShiftedUInt<6,2>(Offset);
2934
2935 case Hexagon::L2_ploadrdt_io:
2936 case Hexagon::L2_ploadrdf_io:
2937 case Hexagon::S2_pstorerdt_io:
2938 case Hexagon::S2_pstorerdf_io:
2939 return isShiftedUInt<6,3>(Offset);
2940
2941 case Hexagon::L2_loadbsw2_io:
2942 case Hexagon::L2_loadbzw2_io:
2943 return isShiftedInt<11,1>(Offset);
2944
2945 case Hexagon::L2_loadbsw4_io:
2946 case Hexagon::L2_loadbzw4_io:
2947 return isShiftedInt<11,2>(Offset);
2948 } // switch
2949
2950 dbgs() << "Failed Opcode is : " << Opcode << " (" << getName(Opcode)
2951 << ")\n";
2952 llvm_unreachable("No offset range is defined for this opcode. "
2953 "Please define it in the above switch statement!");
2954}
2955
2957 return isHVXVec(MI) && isAccumulator(MI);
2958}
2959
2961 const uint64_t F = get(MI.getOpcode()).TSFlags;
2963 return
2964 V == HexagonII::TypeCVI_VA ||
2966}
2967
2969 const MachineInstr &ConsMI) const {
2970 if (EnableACCForwarding && isVecAcc(ProdMI) && isVecAcc(ConsMI))
2971 return true;
2972
2973 if (EnableALUForwarding && (isVecALU(ConsMI) || isLateSourceInstr(ConsMI)))
2974 return true;
2975
2976 if (mayBeNewStore(ConsMI))
2977 return true;
2978
2979 return false;
2980}
2981
2983 switch (MI.getOpcode()) {
2984 // Byte
2985 case Hexagon::L2_loadrub_io:
2986 case Hexagon::L4_loadrub_ur:
2987 case Hexagon::L4_loadrub_ap:
2988 case Hexagon::L2_loadrub_pr:
2989 case Hexagon::L2_loadrub_pbr:
2990 case Hexagon::L2_loadrub_pi:
2991 case Hexagon::L2_loadrub_pci:
2992 case Hexagon::L2_loadrub_pcr:
2993 case Hexagon::L2_loadbzw2_io:
2994 case Hexagon::L4_loadbzw2_ur:
2995 case Hexagon::L4_loadbzw2_ap:
2996 case Hexagon::L2_loadbzw2_pr:
2997 case Hexagon::L2_loadbzw2_pbr:
2998 case Hexagon::L2_loadbzw2_pi:
2999 case Hexagon::L2_loadbzw2_pci:
3000 case Hexagon::L2_loadbzw2_pcr:
3001 case Hexagon::L2_loadbzw4_io:
3002 case Hexagon::L4_loadbzw4_ur:
3003 case Hexagon::L4_loadbzw4_ap:
3004 case Hexagon::L2_loadbzw4_pr:
3005 case Hexagon::L2_loadbzw4_pbr:
3006 case Hexagon::L2_loadbzw4_pi:
3007 case Hexagon::L2_loadbzw4_pci:
3008 case Hexagon::L2_loadbzw4_pcr:
3009 case Hexagon::L4_loadrub_rr:
3010 case Hexagon::L2_ploadrubt_io:
3011 case Hexagon::L2_ploadrubt_pi:
3012 case Hexagon::L2_ploadrubf_io:
3013 case Hexagon::L2_ploadrubf_pi:
3014 case Hexagon::L2_ploadrubtnew_io:
3015 case Hexagon::L2_ploadrubfnew_io:
3016 case Hexagon::L4_ploadrubt_rr:
3017 case Hexagon::L4_ploadrubf_rr:
3018 case Hexagon::L4_ploadrubtnew_rr:
3019 case Hexagon::L4_ploadrubfnew_rr:
3020 case Hexagon::L2_ploadrubtnew_pi:
3021 case Hexagon::L2_ploadrubfnew_pi:
3022 case Hexagon::L4_ploadrubt_abs:
3023 case Hexagon::L4_ploadrubf_abs:
3024 case Hexagon::L4_ploadrubtnew_abs:
3025 case Hexagon::L4_ploadrubfnew_abs:
3026 case Hexagon::L2_loadrubgp:
3027 // Half
3028 case Hexagon::L2_loadruh_io:
3029 case Hexagon::L4_loadruh_ur:
3030 case Hexagon::L4_loadruh_ap:
3031 case Hexagon::L2_loadruh_pr:
3032 case Hexagon::L2_loadruh_pbr:
3033 case Hexagon::L2_loadruh_pi:
3034 case Hexagon::L2_loadruh_pci:
3035 case Hexagon::L2_loadruh_pcr:
3036 case Hexagon::L4_loadruh_rr:
3037 case Hexagon::L2_ploadruht_io:
3038 case Hexagon::L2_ploadruht_pi:
3039 case Hexagon::L2_ploadruhf_io:
3040 case Hexagon::L2_ploadruhf_pi:
3041 case Hexagon::L2_ploadruhtnew_io:
3042 case Hexagon::L2_ploadruhfnew_io:
3043 case Hexagon::L4_ploadruht_rr:
3044 case Hexagon::L4_ploadruhf_rr:
3045 case Hexagon::L4_ploadruhtnew_rr:
3046 case Hexagon::L4_ploadruhfnew_rr:
3047 case Hexagon::L2_ploadruhtnew_pi:
3048 case Hexagon::L2_ploadruhfnew_pi:
3049 case Hexagon::L4_ploadruht_abs:
3050 case Hexagon::L4_ploadruhf_abs:
3051 case Hexagon::L4_ploadruhtnew_abs:
3052 case Hexagon::L4_ploadruhfnew_abs:
3053 case Hexagon::L2_loadruhgp:
3054 return true;
3055 default:
3056 return false;
3057 }
3058}
3059
3060// Add latency to instruction.
3062 const MachineInstr &MI2) const {
3063 if (isHVXVec(MI1) && isHVXVec(MI2))
3064 if (!isVecUsableNextPacket(MI1, MI2))
3065 return true;
3066 return false;
3067}
3068
3069/// Get the base register and byte offset of a load/store instr.
3072 int64_t &Offset, bool &OffsetIsScalable, LocationSize &Width,
3073 const TargetRegisterInfo *TRI) const {
3074 OffsetIsScalable = false;
3075 const MachineOperand *BaseOp = getBaseAndOffset(LdSt, Offset, Width);
3076 if (!BaseOp || !BaseOp->isReg())
3077 return false;
3078 BaseOps.push_back(BaseOp);
3079 return true;
3080}
3081
3082/// Can these instructions execute at the same time in a bundle.
3084 const MachineInstr &Second) const {
3085 if (Second.mayStore() && First.getOpcode() == Hexagon::S2_allocframe) {
3086 const MachineOperand &Op = Second.getOperand(0);
3087 if (Op.isReg() && Op.isUse() && Op.getReg() == Hexagon::R29)
3088 return true;
3089 }
3091 return false;
3092 if (mayBeNewStore(Second)) {
3093 // Make sure the definition of the first instruction is the value being
3094 // stored.
3095 const MachineOperand &Stored =
3096 Second.getOperand(Second.getNumOperands() - 1);
3097 if (!Stored.isReg())
3098 return false;
3099 for (unsigned i = 0, e = First.getNumOperands(); i < e; ++i) {
3100 const MachineOperand &Op = First.getOperand(i);
3101 if (Op.isReg() && Op.isDef() && Op.getReg() == Stored.getReg())
3102 return true;
3103 }
3104 }
3105 return false;
3106}
3107
3109 unsigned Opc = CallMI.getOpcode();
3110 return Opc == Hexagon::PS_call_nr || Opc == Hexagon::PS_callr_nr;
3111}
3112
3114 for (auto &I : *B)
3115 if (I.isEHLabel())
3116 return true;
3117 return false;
3118}
3119
3120// Returns true if an instruction can be converted into a non-extended
3121// equivalent instruction.
3123 short NonExtOpcode;
3124 // Check if the instruction has a register form that uses register in place
3125 // of the extended operand, if so return that as the non-extended form.
3126 if (Hexagon::getRegForm(MI.getOpcode()) >= 0)
3127 return true;
3128
3129 if (MI.getDesc().mayLoad() || MI.getDesc().mayStore()) {
3130 // Check addressing mode and retrieve non-ext equivalent instruction.
3131
3132 switch (getAddrMode(MI)) {
3134 // Load/store with absolute addressing mode can be converted into
3135 // base+offset mode.
3136 NonExtOpcode = Hexagon::changeAddrMode_abs_io(MI.getOpcode());
3137 break;
3139 // Load/store with base+offset addressing mode can be converted into
3140 // base+register offset addressing mode. However left shift operand should
3141 // be set to 0.
3142 NonExtOpcode = Hexagon::changeAddrMode_io_rr(MI.getOpcode());
3143 break;
3145 NonExtOpcode = Hexagon::changeAddrMode_ur_rr(MI.getOpcode());
3146 break;
3147 default:
3148 return false;
3149 }
3150 if (NonExtOpcode < 0)
3151 return false;
3152 return true;
3153 }
3154 return false;
3155}
3156
3158 return Hexagon::getRealHWInstr(MI.getOpcode(),
3159 Hexagon::InstrType_Pseudo) >= 0;
3160}
3161
3163 const {
3164 MachineBasicBlock::const_iterator I = B->getFirstTerminator(), E = B->end();
3165 while (I != E) {
3166 if (I->isBarrier())
3167 return true;
3168 ++I;
3169 }
3170 return false;
3171}
3172
3173// Returns true, if a LD insn can be promoted to a cur load.
3175 const uint64_t F = MI.getDesc().TSFlags;
3177 Subtarget.hasV60Ops();
3178}
3179
3180// Returns true, if a ST insn can be promoted to a new-value store.
3182 if (MI.mayStore() && !Subtarget.useNewValueStores())
3183 return false;
3184
3185 const uint64_t F = MI.getDesc().TSFlags;
3187}
3188
3190 const MachineInstr &ConsMI) const {
3191 // There is no stall when ProdMI is not a V60 vector.
3192 if (!isHVXVec(ProdMI))
3193 return false;
3194
3195 // There is no stall when ProdMI and ConsMI are not dependent.
3196 if (!isDependent(ProdMI, ConsMI))
3197 return false;
3198
3199 // When Forward Scheduling is enabled, there is no stall if ProdMI and ConsMI
3200 // are scheduled in consecutive packets.
3201 if (isVecUsableNextPacket(ProdMI, ConsMI))
3202 return false;
3203
3204 return true;
3205}
3206
3209 // There is no stall when I is not a V60 vector.
3210 if (!isHVXVec(MI))
3211 return false;
3212
3214 MachineBasicBlock::const_instr_iterator MIE = MII->getParent()->instr_end();
3215
3216 if (!MII->isBundle())
3217 return producesStall(*MII, MI);
3218
3219 for (++MII; MII != MIE && MII->isInsideBundle(); ++MII) {
3220 const MachineInstr &J = *MII;
3221 if (producesStall(J, MI))
3222 return true;
3223 }
3224 return false;
3225}
3226
3228 Register PredReg) const {
3229 for (const MachineOperand &MO : MI.operands()) {
3230 // Predicate register must be explicitly defined.
3231 if (MO.isRegMask() && MO.clobbersPhysReg(PredReg))
3232 return false;
3233 if (MO.isReg() && MO.isDef() && MO.isImplicit() && (MO.getReg() == PredReg))
3234 return false;
3235 }
3236
3237 // Instruction that produce late predicate cannot be used as sources of
3238 // dot-new.
3239 switch (MI.getOpcode()) {
3240 case Hexagon::A4_addp_c:
3241 case Hexagon::A4_subp_c:
3242 case Hexagon::A4_tlbmatch:
3243 case Hexagon::A5_ACS:
3244 case Hexagon::F2_sfinvsqrta:
3245 case Hexagon::F2_sfrecipa:
3246 case Hexagon::J2_endloop0:
3247 case Hexagon::J2_endloop01:
3248 case Hexagon::J2_ploop1si:
3249 case Hexagon::J2_ploop1sr:
3250 case Hexagon::J2_ploop2si:
3251 case Hexagon::J2_ploop2sr:
3252 case Hexagon::J2_ploop3si:
3253 case Hexagon::J2_ploop3sr:
3254 case Hexagon::S2_cabacdecbin:
3255 case Hexagon::S2_storew_locked:
3256 case Hexagon::S4_stored_locked:
3257 return false;
3258 }
3259 return true;
3260}
3261
3262bool HexagonInstrInfo::PredOpcodeHasJMP_c(unsigned Opcode) const {
3263 return Opcode == Hexagon::J2_jumpt ||
3264 Opcode == Hexagon::J2_jumptpt ||
3265 Opcode == Hexagon::J2_jumpf ||
3266 Opcode == Hexagon::J2_jumpfpt ||
3267 Opcode == Hexagon::J2_jumptnew ||
3268 Opcode == Hexagon::J2_jumpfnew ||
3269 Opcode == Hexagon::J2_jumptnewpt ||
3270 Opcode == Hexagon::J2_jumpfnewpt;
3271}
3272
3274 if (Cond.empty() || !isPredicated(Cond[0].getImm()))
3275 return false;
3276 return !isPredicatedTrue(Cond[0].getImm());
3277}
3278
3280 const uint64_t F = MI.getDesc().TSFlags;
3282}
3283
3284// Returns the base register in a memory access (load/store). The offset is
3285// returned in Offset and the access size is returned in AccessSize.
3286// If the base operand has a subregister or the offset field does not contain
3287// an immediate value, return nullptr.
3290 LocationSize &AccessSize) const {
3291 // Return if it is not a base+offset type instruction or a MemOp.
3295 return nullptr;
3296
3297 AccessSize = getMemAccessSize(MI);
3298
3299 unsigned BasePos = 0, OffsetPos = 0;
3300 if (!getBaseAndOffsetPosition(MI, BasePos, OffsetPos))
3301 return nullptr;
3302
3303 // Post increment updates its EA after the mem access,
3304 // so we need to treat its offset as zero.
3305 if (isPostIncrement(MI)) {
3306 Offset = 0;
3307 } else {
3308 const MachineOperand &OffsetOp = MI.getOperand(OffsetPos);
3309 if (!OffsetOp.isImm())
3310 return nullptr;
3311 Offset = OffsetOp.getImm();
3312 }
3313
3314 const MachineOperand &BaseOp = MI.getOperand(BasePos);
3315 if (BaseOp.getSubReg() != 0)
3316 return nullptr;
3317 return &const_cast<MachineOperand&>(BaseOp);
3318}
3319
3320/// Return the position of the base and offset operands for this instruction.
3322 unsigned &BasePos, unsigned &OffsetPos) const {
3324 return false;
3325
3326 // Deal with memops first.
3327 if (isMemOp(MI)) {
3328 BasePos = 0;
3329 OffsetPos = 1;
3330 } else if (MI.mayStore()) {
3331 BasePos = 0;
3332 OffsetPos = 1;
3333 } else if (MI.mayLoad()) {
3334 BasePos = 1;
3335 OffsetPos = 2;
3336 } else
3337 return false;
3338
3339 if (isPredicated(MI)) {
3340 BasePos++;
3341 OffsetPos++;
3342 }
3343 if (isPostIncrement(MI)) {
3344 BasePos++;
3345 OffsetPos++;
3346 }
3347
3348 if (!MI.getOperand(BasePos).isReg() || !MI.getOperand(OffsetPos).isImm())
3349 return false;
3350
3351 return true;
3352}
3353
3354// Inserts branching instructions in reverse order of their occurrence.
3355// e.g. jump_t t1 (i1)
3356// jump t2 (i2)
3357// Jumpers = {i2, i1}
3359 MachineBasicBlock& MBB) const {
3361 // If the block has no terminators, it just falls into the block after it.
3363 if (I == MBB.instr_begin())
3364 return Jumpers;
3365
3366 // A basic block may looks like this:
3367 //
3368 // [ insn
3369 // EH_LABEL
3370 // insn
3371 // insn
3372 // insn
3373 // EH_LABEL
3374 // insn ]
3375 //
3376 // It has two succs but does not have a terminator
3377 // Don't know how to handle it.
3378 do {
3379 --I;
3380 if (I->isEHLabel())
3381 return Jumpers;
3382 } while (I != MBB.instr_begin());
3383
3384 I = MBB.instr_end();
3385 --I;
3386
3387 while (I->isDebugInstr()) {
3388 if (I == MBB.instr_begin())
3389 return Jumpers;
3390 --I;
3391 }
3392 if (!isUnpredicatedTerminator(*I))
3393 return Jumpers;
3394
3395 // Get the last instruction in the block.
3396 MachineInstr *LastInst = &*I;
3397 Jumpers.push_back(LastInst);
3398 MachineInstr *SecondLastInst = nullptr;
3399 // Find one more terminator if present.
3400 do {
3401 if (&*I != LastInst && !I->isBundle() && isUnpredicatedTerminator(*I)) {
3402 if (!SecondLastInst) {
3403 SecondLastInst = &*I;
3404 Jumpers.push_back(SecondLastInst);
3405 } else // This is a third branch.
3406 return Jumpers;
3407 }
3408 if (I == MBB.instr_begin())
3409 break;
3410 --I;
3411 } while (true);
3412 return Jumpers;
3413}
3414
3415// Returns Operand Index for the constant extended instruction.
3417 const uint64_t F = MI.getDesc().TSFlags;
3419}
3420
3421// See if instruction could potentially be a duplex candidate.
3422// If so, return its group. Zero otherwise.
3424 const MachineInstr &MI) const {
3425 Register DstReg, SrcReg, Src1Reg, Src2Reg;
3426
3427 switch (MI.getOpcode()) {
3428 default:
3429 return HexagonII::HCG_None;
3430 //
3431 // Compound pairs.
3432 // "p0=cmp.eq(Rs16,Rt16); if (p0.new) jump:nt #r9:2"
3433 // "Rd16=#U6 ; jump #r9:2"
3434 // "Rd16=Rs16 ; jump #r9:2"
3435 //
3436 case Hexagon::C2_cmpeq:
3437 case Hexagon::C2_cmpgt:
3438 case Hexagon::C2_cmpgtu:
3439 DstReg = MI.getOperand(0).getReg();
3440 Src1Reg = MI.getOperand(1).getReg();
3441 Src2Reg = MI.getOperand(2).getReg();
3442 if (Hexagon::PredRegsRegClass.contains(DstReg) &&
3443 (Hexagon::P0 == DstReg || Hexagon::P1 == DstReg) &&
3444 isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg))
3445 return HexagonII::HCG_A;
3446 break;
3447 case Hexagon::C2_cmpeqi:
3448 case Hexagon::C2_cmpgti:
3449 case Hexagon::C2_cmpgtui:
3450 // P0 = cmp.eq(Rs,#u2)
3451 DstReg = MI.getOperand(0).getReg();
3452 SrcReg = MI.getOperand(1).getReg();
3453 if (Hexagon::PredRegsRegClass.contains(DstReg) &&
3454 (Hexagon::P0 == DstReg || Hexagon::P1 == DstReg) &&
3455 isIntRegForSubInst(SrcReg) && MI.getOperand(2).isImm() &&
3456 ((isUInt<5>(MI.getOperand(2).getImm())) ||
3457 (MI.getOperand(2).getImm() == -1)))
3458 return HexagonII::HCG_A;
3459 break;
3460 case Hexagon::A2_tfr:
3461 // Rd = Rs
3462 DstReg = MI.getOperand(0).getReg();
3463 SrcReg = MI.getOperand(1).getReg();
3464 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg))
3465 return HexagonII::HCG_A;
3466 break;
3467 case Hexagon::A2_tfrsi:
3468 // Rd = #u6
3469 // Do not test for #u6 size since the const is getting extended
3470 // regardless and compound could be formed.
3471 DstReg = MI.getOperand(0).getReg();
3472 if (isIntRegForSubInst(DstReg))
3473 return HexagonII::HCG_A;
3474 break;
3475 case Hexagon::S2_tstbit_i:
3476 DstReg = MI.getOperand(0).getReg();
3477 Src1Reg = MI.getOperand(1).getReg();
3478 if (Hexagon::PredRegsRegClass.contains(DstReg) &&
3479 (Hexagon::P0 == DstReg || Hexagon::P1 == DstReg) &&
3480 MI.getOperand(2).isImm() &&
3481 isIntRegForSubInst(Src1Reg) && (MI.getOperand(2).getImm() == 0))
3482 return HexagonII::HCG_A;
3483 break;
3484 // The fact that .new form is used pretty much guarantees
3485 // that predicate register will match. Nevertheless,
3486 // there could be some false positives without additional
3487 // checking.
3488 case Hexagon::J2_jumptnew:
3489 case Hexagon::J2_jumpfnew:
3490 case Hexagon::J2_jumptnewpt:
3491 case Hexagon::J2_jumpfnewpt:
3492 Src1Reg = MI.getOperand(0).getReg();
3493 if (Hexagon::PredRegsRegClass.contains(Src1Reg) &&
3494 (Hexagon::P0 == Src1Reg || Hexagon::P1 == Src1Reg))
3495 return HexagonII::HCG_B;
3496 break;
3497 // Transfer and jump:
3498 // Rd=#U6 ; jump #r9:2
3499 // Rd=Rs ; jump #r9:2
3500 // Do not test for jump range here.
3501 case Hexagon::J2_jump:
3502 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4:
3503 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC:
3504 return HexagonII::HCG_C;
3505 }
3506
3507 return HexagonII::HCG_None;
3508}
3509
3510// Returns -1 when there is no opcode found.
3512 const MachineInstr &GB) const {
3515 if ((GA.getOpcode() != Hexagon::C2_cmpeqi) ||
3516 (GB.getOpcode() != Hexagon::J2_jumptnew))
3517 return -1u;
3518 Register DestReg = GA.getOperand(0).getReg();
3519 if (!GB.readsRegister(DestReg, /*TRI=*/nullptr))
3520 return -1u;
3521 if (DestReg != Hexagon::P0 && DestReg != Hexagon::P1)
3522 return -1u;
3523 // The value compared against must be either u5 or -1.
3524 const MachineOperand &CmpOp = GA.getOperand(2);
3525 if (!CmpOp.isImm())
3526 return -1u;
3527 int V = CmpOp.getImm();
3528 if (V == -1)
3529 return DestReg == Hexagon::P0 ? Hexagon::J4_cmpeqn1_tp0_jump_nt
3530 : Hexagon::J4_cmpeqn1_tp1_jump_nt;
3531 if (!isUInt<5>(V))
3532 return -1u;
3533 return DestReg == Hexagon::P0 ? Hexagon::J4_cmpeqi_tp0_jump_nt
3534 : Hexagon::J4_cmpeqi_tp1_jump_nt;
3535}
3536
3537// Returns -1 if there is no opcode found.
3539 bool ForBigCore) const {
3540 // Static table to switch the opcodes across Tiny Core and Big Core.
3541 // dup_ opcodes are Big core opcodes.
3542 // NOTE: There are special instructions that need to handled later.
3543 // L4_return* instructions, they will only occupy SLOT0 (on big core too).
3544 // PS_jmpret - This pseudo translates to J2_jumpr which occupies only SLOT2.
3545 // The compiler need to base the root instruction to L6_return_map_to_raw
3546 // which can go any slot.
3547 static const std::map<unsigned, unsigned> DupMap = {
3548 {Hexagon::A2_add, Hexagon::dup_A2_add},
3549 {Hexagon::A2_addi, Hexagon::dup_A2_addi},
3550 {Hexagon::A2_andir, Hexagon::dup_A2_andir},
3551 {Hexagon::A2_combineii, Hexagon::dup_A2_combineii},
3552 {Hexagon::A2_sxtb, Hexagon::dup_A2_sxtb},
3553 {Hexagon::A2_sxth, Hexagon::dup_A2_sxth},
3554 {Hexagon::A2_tfr, Hexagon::dup_A2_tfr},
3555 {Hexagon::A2_tfrsi, Hexagon::dup_A2_tfrsi},
3556 {Hexagon::A2_zxtb, Hexagon::dup_A2_zxtb},
3557 {Hexagon::A2_zxth, Hexagon::dup_A2_zxth},
3558 {Hexagon::A4_combineii, Hexagon::dup_A4_combineii},
3559 {Hexagon::A4_combineir, Hexagon::dup_A4_combineir},
3560 {Hexagon::A4_combineri, Hexagon::dup_A4_combineri},
3561 {Hexagon::C2_cmoveif, Hexagon::dup_C2_cmoveif},
3562 {Hexagon::C2_cmoveit, Hexagon::dup_C2_cmoveit},
3563 {Hexagon::C2_cmovenewif, Hexagon::dup_C2_cmovenewif},
3564 {Hexagon::C2_cmovenewit, Hexagon::dup_C2_cmovenewit},
3565 {Hexagon::C2_cmpeqi, Hexagon::dup_C2_cmpeqi},
3566 {Hexagon::L2_deallocframe, Hexagon::dup_L2_deallocframe},
3567 {Hexagon::L2_loadrb_io, Hexagon::dup_L2_loadrb_io},
3568 {Hexagon::L2_loadrd_io, Hexagon::dup_L2_loadrd_io},
3569 {Hexagon::L2_loadrh_io, Hexagon::dup_L2_loadrh_io},
3570 {Hexagon::L2_loadri_io, Hexagon::dup_L2_loadri_io},
3571 {Hexagon::L2_loadrub_io, Hexagon::dup_L2_loadrub_io},
3572 {Hexagon::L2_loadruh_io, Hexagon::dup_L2_loadruh_io},
3573 {Hexagon::S2_allocframe, Hexagon::dup_S2_allocframe},
3574 {Hexagon::S2_storerb_io, Hexagon::dup_S2_storerb_io},
3575 {Hexagon::S2_storerd_io, Hexagon::dup_S2_storerd_io},
3576 {Hexagon::S2_storerh_io, Hexagon::dup_S2_storerh_io},
3577 {Hexagon::S2_storeri_io, Hexagon::dup_S2_storeri_io},
3578 {Hexagon::S4_storeirb_io, Hexagon::dup_S4_storeirb_io},
3579 {Hexagon::S4_storeiri_io, Hexagon::dup_S4_storeiri_io},
3580 };
3581 unsigned OpNum = MI.getOpcode();
3582 // Conversion to Big core.
3583 if (ForBigCore) {
3584 auto Iter = DupMap.find(OpNum);
3585 if (Iter != DupMap.end())
3586 return Iter->second;
3587 } else { // Conversion to Tiny core.
3588 for (const auto &Iter : DupMap)
3589 if (Iter.second == OpNum)
3590 return Iter.first;
3591 }
3592 return -1;
3593}
3594
3595int HexagonInstrInfo::getCondOpcode(int Opc, bool invertPredicate) const {
3596 enum Hexagon::PredSense inPredSense;
3597 inPredSense = invertPredicate ? Hexagon::PredSense_false :
3598 Hexagon::PredSense_true;
3599 int CondOpcode = Hexagon::getPredOpcode(Opc, inPredSense);
3600 if (CondOpcode >= 0) // Valid Conditional opcode/instruction
3601 return CondOpcode;
3602
3603 llvm_unreachable("Unexpected predicable instruction");
3604}
3605
3606// Return the cur value instruction for a given store.
3608 switch (MI.getOpcode()) {
3609 default: llvm_unreachable("Unknown .cur type");
3610 case Hexagon::V6_vL32b_pi:
3611 return Hexagon::V6_vL32b_cur_pi;
3612 case Hexagon::V6_vL32b_ai:
3613 return Hexagon::V6_vL32b_cur_ai;
3614 case Hexagon::V6_vL32b_nt_pi:
3615 return Hexagon::V6_vL32b_nt_cur_pi;
3616 case Hexagon::V6_vL32b_nt_ai:
3617 return Hexagon::V6_vL32b_nt_cur_ai;
3618 case Hexagon::V6_vL32b_ppu:
3619 return Hexagon::V6_vL32b_cur_ppu;
3620 case Hexagon::V6_vL32b_nt_ppu:
3621 return Hexagon::V6_vL32b_nt_cur_ppu;
3622 }
3623 return 0;
3624}
3625
3626// Return the regular version of the .cur instruction.
3628 switch (MI.getOpcode()) {
3629 default: llvm_unreachable("Unknown .cur type");
3630 case Hexagon::V6_vL32b_cur_pi:
3631 return Hexagon::V6_vL32b_pi;
3632 case Hexagon::V6_vL32b_cur_ai:
3633 return Hexagon::V6_vL32b_ai;
3634 case Hexagon::V6_vL32b_nt_cur_pi:
3635 return Hexagon::V6_vL32b_nt_pi;
3636 case Hexagon::V6_vL32b_nt_cur_ai:
3637 return Hexagon::V6_vL32b_nt_ai;
3638 case Hexagon::V6_vL32b_cur_ppu:
3639 return Hexagon::V6_vL32b_ppu;
3640 case Hexagon::V6_vL32b_nt_cur_ppu:
3641 return Hexagon::V6_vL32b_nt_ppu;
3642 }
3643 return 0;
3644}
3645
3646// The diagram below shows the steps involved in the conversion of a predicated
3647// store instruction to its .new predicated new-value form.
3648//
3649// Note: It doesn't include conditional new-value stores as they can't be
3650// converted to .new predicate.
3651//
3652// p.new NV store [ if(p0.new)memw(R0+#0)=R2.new ]
3653// ^ ^
3654// / \ (not OK. it will cause new-value store to be
3655// / X conditional on p0.new while R2 producer is
3656// / \ on p0)
3657// / \.
3658// p.new store p.old NV store
3659// [if(p0.new)memw(R0+#0)=R2] [if(p0)memw(R0+#0)=R2.new]
3660// ^ ^
3661// \ /
3662// \ /
3663// \ /
3664// p.old store
3665// [if (p0)memw(R0+#0)=R2]
3666//
3667// The following set of instructions further explains the scenario where
3668// conditional new-value store becomes invalid when promoted to .new predicate
3669// form.
3670//
3671// { 1) if (p0) r0 = add(r1, r2)
3672// 2) p0 = cmp.eq(r3, #0) }
3673//
3674// 3) if (p0) memb(r1+#0) = r0 --> this instruction can't be grouped with
3675// the first two instructions because in instr 1, r0 is conditional on old value
3676// of p0 but its use in instr 3 is conditional on p0 modified by instr 2 which
3677// is not valid for new-value stores.
3678// Predicated new value stores (i.e. if (p0) memw(..)=r0.new) are excluded
3679// from the "Conditional Store" list. Because a predicated new value store
3680// would NOT be promoted to a double dot new store. See diagram below:
3681// This function returns yes for those stores that are predicated but not
3682// yet promoted to predicate dot new instructions.
3683//
3684// +---------------------+
3685// /-----| if (p0) memw(..)=r0 |---------\~
3686// || +---------------------+ ||
3687// promote || /\ /\ || promote
3688// || /||\ /||\ ||
3689// \||/ demote || \||/
3690// \/ || || \/
3691// +-------------------------+ || +-------------------------+
3692// | if (p0.new) memw(..)=r0 | || | if (p0) memw(..)=r0.new |
3693// +-------------------------+ || +-------------------------+
3694// || || ||
3695// || demote \||/
3696// promote || \/ NOT possible
3697// || || /\~
3698// \||/ || /||\~
3699// \/ || ||
3700// +-----------------------------+
3701// | if (p0.new) memw(..)=r0.new |
3702// +-----------------------------+
3703// Double Dot New Store
3704//
3705// Returns the most basic instruction for the .new predicated instructions and
3706// new-value stores.
3707// For example, all of the following instructions will be converted back to the
3708// same instruction:
3709// 1) if (p0.new) memw(R0+#0) = R1.new --->
3710// 2) if (p0) memw(R0+#0)= R1.new -------> if (p0) memw(R0+#0) = R1
3711// 3) if (p0.new) memw(R0+#0) = R1 --->
3712//
3713// To understand the translation of instruction 1 to its original form, consider
3714// a packet with 3 instructions.
3715// { p0 = cmp.eq(R0,R1)
3716// if (p0.new) R2 = add(R3, R4)
3717// R5 = add (R3, R1)
3718// }
3719// if (p0) memw(R5+#0) = R2 <--- trying to include it in the previous packet
3720//
3721// This instruction can be part of the previous packet only if both p0 and R2
3722// are promoted to .new values. This promotion happens in steps, first
3723// predicate register is promoted to .new and in the next iteration R2 is
3724// promoted. Therefore, in case of dependence check failure (due to R5) during
3725// next iteration, it should be converted back to its most basic form.
3726
3727// Return the new value instruction for a given store.
3729 int NVOpcode = Hexagon::getNewValueOpcode(MI.getOpcode());
3730 if (NVOpcode >= 0) // Valid new-value store instruction.
3731 return NVOpcode;
3732
3733 switch (MI.getOpcode()) {
3734 default:
3735 report_fatal_error(Twine("Unknown .new type: ") +
3736 std::to_string(MI.getOpcode()));
3737 case Hexagon::S4_storerb_ur:
3738 return Hexagon::S4_storerbnew_ur;
3739
3740 case Hexagon::S2_storerb_pci:
3741 return Hexagon::S2_storerb_pci;
3742
3743 case Hexagon::S2_storeri_pci:
3744 return Hexagon::S2_storeri_pci;
3745
3746 case Hexagon::S2_storerh_pci:
3747 return Hexagon::S2_storerh_pci;
3748
3749 case Hexagon::S2_storerd_pci:
3750 return Hexagon::S2_storerd_pci;
3751
3752 case Hexagon::S2_storerf_pci:
3753 return Hexagon::S2_storerf_pci;
3754
3755 case Hexagon::V6_vS32b_ai:
3756 return Hexagon::V6_vS32b_new_ai;
3757
3758 case Hexagon::V6_vS32b_pi:
3759 return Hexagon::V6_vS32b_new_pi;
3760 }
3761 return 0;
3762}
3763
3764// Returns the opcode to use when converting MI, which is a conditional jump,
3765// into a conditional instruction which uses the .new value of the predicate.
3766// We also use branch probabilities to add a hint to the jump.
3767// If MBPI is null, all edges will be treated as equally likely for the
3768// purposes of establishing a predication hint.
3770 const MachineBranchProbabilityInfo *MBPI) const {
3771 // We assume that block can have at most two successors.
3772 const MachineBasicBlock *Src = MI.getParent();
3773 const MachineOperand &BrTarget = MI.getOperand(1);
3774 bool Taken = false;
3775 const BranchProbability OneHalf(1, 2);
3776
3777 auto getEdgeProbability = [MBPI] (const MachineBasicBlock *Src,
3778 const MachineBasicBlock *Dst) {
3779 if (MBPI)
3780 return MBPI->getEdgeProbability(Src, Dst);
3781 return BranchProbability(1, Src->succ_size());
3782 };
3783
3784 if (BrTarget.isMBB()) {
3785 const MachineBasicBlock *Dst = BrTarget.getMBB();
3786 Taken = getEdgeProbability(Src, Dst) >= OneHalf;
3787 } else {
3788 // The branch target is not a basic block (most likely a function).
3789 // Since BPI only gives probabilities for targets that are basic blocks,
3790 // try to identify another target of this branch (potentially a fall-
3791 // -through) and check the probability of that target.
3792 //
3793 // The only handled branch combinations are:
3794 // - one conditional branch,
3795 // - one conditional branch followed by one unconditional branch.
3796 // Otherwise, assume not-taken.
3797 assert(MI.isConditionalBranch());
3798 const MachineBasicBlock &B = *MI.getParent();
3799 bool SawCond = false, Bad = false;
3800 for (const MachineInstr &I : B) {
3801 if (!I.isBranch())
3802 continue;
3803 if (I.isConditionalBranch()) {
3804 SawCond = true;
3805 if (&I != &MI) {
3806 Bad = true;
3807 break;
3808 }
3809 }
3810 if (I.isUnconditionalBranch() && !SawCond) {
3811 Bad = true;
3812 break;
3813 }
3814 }
3815 if (!Bad) {
3817 MachineBasicBlock::const_instr_iterator NextIt = std::next(It);
3818 if (NextIt == B.instr_end()) {
3819 // If this branch is the last, look for the fall-through block.
3820 for (const MachineBasicBlock *SB : B.successors()) {
3821 if (!B.isLayoutSuccessor(SB))
3822 continue;
3823 Taken = getEdgeProbability(Src, SB) < OneHalf;
3824 break;
3825 }
3826 } else {
3827 assert(NextIt->isUnconditionalBranch());
3828 // Find the first MBB operand and assume it's the target.
3829 const MachineBasicBlock *BT = nullptr;
3830 for (const MachineOperand &Op : NextIt->operands()) {
3831 if (!Op.isMBB())
3832 continue;
3833 BT = Op.getMBB();
3834 break;
3835 }
3836 Taken = BT && getEdgeProbability(Src, BT) < OneHalf;
3837 }
3838 } // if (!Bad)
3839 }
3840
3841 // The Taken flag should be set to something reasonable by this point.
3842
3843 switch (MI.getOpcode()) {
3844 case Hexagon::J2_jumpt:
3845 return Taken ? Hexagon::J2_jumptnewpt : Hexagon::J2_jumptnew;
3846 case Hexagon::J2_jumpf:
3847 return Taken ? Hexagon::J2_jumpfnewpt : Hexagon::J2_jumpfnew;
3848
3849 default:
3850 llvm_unreachable("Unexpected jump instruction.");
3851 }
3852}
3853
3854// Return .new predicate version for an instruction.
3856 const MachineBranchProbabilityInfo *MBPI) const {
3857 switch (MI.getOpcode()) {
3858 // Condtional Jumps
3859 case Hexagon::J2_jumpt:
3860 case Hexagon::J2_jumpf:
3861 return getDotNewPredJumpOp(MI, MBPI);
3862 }
3863
3864 int NewOpcode = Hexagon::getPredNewOpcode(MI.getOpcode());
3865 if (NewOpcode >= 0)
3866 return NewOpcode;
3867 return 0;
3868}
3869
3871 int NewOp = MI.getOpcode();
3872 if (isPredicated(NewOp) && isPredicatedNew(NewOp)) { // Get predicate old form
3873 NewOp = Hexagon::getPredOldOpcode(NewOp);
3874 // All Hexagon architectures have prediction bits on dot-new branches,
3875 // but only Hexagon V60+ has prediction bits on dot-old ones. Make sure
3876 // to pick the right opcode when converting back to dot-old.
3877 if (!Subtarget.hasFeature(Hexagon::ArchV60)) {
3878 switch (NewOp) {
3879 case Hexagon::J2_jumptpt:
3880 NewOp = Hexagon::J2_jumpt;
3881 break;
3882 case Hexagon::J2_jumpfpt:
3883 NewOp = Hexagon::J2_jumpf;
3884 break;
3885 case Hexagon::J2_jumprtpt:
3886 NewOp = Hexagon::J2_jumprt;
3887 break;
3888 case Hexagon::J2_jumprfpt:
3889 NewOp = Hexagon::J2_jumprf;
3890 break;
3891 }
3892 }
3893 assert(NewOp >= 0 &&
3894 "Couldn't change predicate new instruction to its old form.");
3895 }
3896
3897 if (isNewValueStore(NewOp)) { // Convert into non-new-value format
3898 NewOp = Hexagon::getNonNVStore(NewOp);
3899 assert(NewOp >= 0 && "Couldn't change new-value store to its old form.");
3900 }
3901
3902 if (Subtarget.hasV60Ops())
3903 return NewOp;
3904
3905 // Subtargets prior to V60 didn't support 'taken' forms of predicated jumps.
3906 switch (NewOp) {
3907 case Hexagon::J2_jumpfpt:
3908 return Hexagon::J2_jumpf;
3909 case Hexagon::J2_jumptpt:
3910 return Hexagon::J2_jumpt;
3911 case Hexagon::J2_jumprfpt:
3912 return Hexagon::J2_jumprf;
3913 case Hexagon::J2_jumprtpt:
3914 return Hexagon::J2_jumprt;
3915 }
3916 return NewOp;
3917}
3918
3919// See if instruction could potentially be a duplex candidate.
3920// If so, return its group. Zero otherwise.
3922 const MachineInstr &MI) const {
3923 Register DstReg, SrcReg, Src1Reg, Src2Reg;
3924 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
3925
3926 switch (MI.getOpcode()) {
3927 default:
3928 return HexagonII::HSIG_None;
3929 //
3930 // Group L1:
3931 //
3932 // Rd = memw(Rs+#u4:2)
3933 // Rd = memub(Rs+#u4:0)
3934 case Hexagon::L2_loadri_io:
3935 case Hexagon::dup_L2_loadri_io:
3936 DstReg = MI.getOperand(0).getReg();
3937 SrcReg = MI.getOperand(1).getReg();
3938 // Special case this one from Group L2.
3939 // Rd = memw(r29+#u5:2)
3940 if (isIntRegForSubInst(DstReg)) {
3941 if (Hexagon::IntRegsRegClass.contains(SrcReg) &&
3942 HRI.getStackRegister() == SrcReg &&
3943 MI.getOperand(2).isImm() &&
3944 isShiftedUInt<5,2>(MI.getOperand(2).getImm()))
3945 return HexagonII::HSIG_L2;
3946 // Rd = memw(Rs+#u4:2)
3947 if (isIntRegForSubInst(SrcReg) &&
3948 (MI.getOperand(2).isImm() &&
3949 isShiftedUInt<4,2>(MI.getOperand(2).getImm())))
3950 return HexagonII::HSIG_L1;
3951 }
3952 break;
3953 case Hexagon::L2_loadrub_io:
3954 case Hexagon::dup_L2_loadrub_io:
3955 // Rd = memub(Rs+#u4:0)
3956 DstReg = MI.getOperand(0).getReg();
3957 SrcReg = MI.getOperand(1).getReg();
3958 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) &&
3959 MI.getOperand(2).isImm() && isUInt<4>(MI.getOperand(2).getImm()))
3960 return HexagonII::HSIG_L1;
3961 break;
3962 //
3963 // Group L2:
3964 //
3965 // Rd = memh/memuh(Rs+#u3:1)
3966 // Rd = memb(Rs+#u3:0)
3967 // Rd = memw(r29+#u5:2) - Handled above.
3968 // Rdd = memd(r29+#u5:3)
3969 // deallocframe
3970 // [if ([!]p0[.new])] dealloc_return
3971 // [if ([!]p0[.new])] jumpr r31
3972 case Hexagon::L2_loadrh_io:
3973 case Hexagon::L2_loadruh_io:
3974 case Hexagon::dup_L2_loadrh_io:
3975 case Hexagon::dup_L2_loadruh_io:
3976 // Rd = memh/memuh(Rs+#u3:1)
3977 DstReg = MI.getOperand(0).getReg();
3978 SrcReg = MI.getOperand(1).getReg();
3979 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) &&
3980 MI.getOperand(2).isImm() &&
3981 isShiftedUInt<3,1>(MI.getOperand(2).getImm()))
3982 return HexagonII::HSIG_L2;
3983 break;
3984 case Hexagon::L2_loadrb_io:
3985 case Hexagon::dup_L2_loadrb_io:
3986 // Rd = memb(Rs+#u3:0)
3987 DstReg = MI.getOperand(0).getReg();
3988 SrcReg = MI.getOperand(1).getReg();
3989 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) &&
3990 MI.getOperand(2).isImm() &&
3991 isUInt<3>(MI.getOperand(2).getImm()))
3992 return HexagonII::HSIG_L2;
3993 break;
3994 case Hexagon::L2_loadrd_io:
3995 case Hexagon::dup_L2_loadrd_io:
3996 // Rdd = memd(r29+#u5:3)
3997 DstReg = MI.getOperand(0).getReg();
3998 SrcReg = MI.getOperand(1).getReg();
3999 if (isDblRegForSubInst(DstReg, HRI) &&
4000 Hexagon::IntRegsRegClass.contains(SrcReg) &&
4001 HRI.getStackRegister() == SrcReg &&
4002 MI.getOperand(2).isImm() &&
4003 isShiftedUInt<5,3>(MI.getOperand(2).getImm()))
4004 return HexagonII::HSIG_L2;
4005 break;
4006 // dealloc_return is not documented in Hexagon Manual, but marked
4007 // with A_SUBINSN attribute in iset_v4classic.py.
4008 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4:
4009 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC:
4010 case Hexagon::L4_return:
4011 case Hexagon::L2_deallocframe:
4012 case Hexagon::dup_L2_deallocframe:
4013 return HexagonII::HSIG_L2;
4014 case Hexagon::EH_RETURN_JMPR:
4015 case Hexagon::PS_jmpret:
4016 case Hexagon::SL2_jumpr31:
4017 // jumpr r31
4018 // Actual form JMPR implicit-def %pc, implicit %r31, implicit internal %r0
4019 DstReg = MI.getOperand(0).getReg();
4020 if (Hexagon::IntRegsRegClass.contains(DstReg) && (Hexagon::R31 == DstReg))
4021 return HexagonII::HSIG_L2;
4022 break;
4023 case Hexagon::PS_jmprett:
4024 case Hexagon::PS_jmpretf:
4025 case Hexagon::PS_jmprettnewpt:
4026 case Hexagon::PS_jmpretfnewpt:
4027 case Hexagon::PS_jmprettnew:
4028 case Hexagon::PS_jmpretfnew:
4029 case Hexagon::SL2_jumpr31_t:
4030 case Hexagon::SL2_jumpr31_f:
4031 case Hexagon::SL2_jumpr31_tnew:
4032 case Hexagon::SL2_jumpr31_fnew:
4033 DstReg = MI.getOperand(1).getReg();
4034 SrcReg = MI.getOperand(0).getReg();
4035 // [if ([!]p0[.new])] jumpr r31
4036 if ((Hexagon::PredRegsRegClass.contains(SrcReg) &&
4037 (Hexagon::P0 == SrcReg)) &&
4038 (Hexagon::IntRegsRegClass.contains(DstReg) && (Hexagon::R31 == DstReg)))
4039 return HexagonII::HSIG_L2;
4040 break;
4041 case Hexagon::L4_return_t:
4042 case Hexagon::L4_return_f:
4043 case Hexagon::L4_return_tnew_pnt:
4044 case Hexagon::L4_return_fnew_pnt:
4045 case Hexagon::L4_return_tnew_pt:
4046 case Hexagon::L4_return_fnew_pt:
4047 // [if ([!]p0[.new])] dealloc_return
4048 SrcReg = MI.getOperand(0).getReg();
4049 if (Hexagon::PredRegsRegClass.contains(SrcReg) && (Hexagon::P0 == SrcReg))
4050 return HexagonII::HSIG_L2;
4051 break;
4052 //
4053 // Group S1:
4054 //
4055 // memw(Rs+#u4:2) = Rt
4056 // memb(Rs+#u4:0) = Rt
4057 case Hexagon::S2_storeri_io:
4058 case Hexagon::dup_S2_storeri_io:
4059 // Special case this one from Group S2.
4060 // memw(r29+#u5:2) = Rt
4061 Src1Reg = MI.getOperand(0).getReg();
4062 Src2Reg = MI.getOperand(2).getReg();
4063 if (Hexagon::IntRegsRegClass.contains(Src1Reg) &&
4064 isIntRegForSubInst(Src2Reg) &&
4065 HRI.getStackRegister() == Src1Reg && MI.getOperand(1).isImm() &&
4066 isShiftedUInt<5,2>(MI.getOperand(1).getImm()))
4067 return HexagonII::HSIG_S2;
4068 // memw(Rs+#u4:2) = Rt
4069 if (isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg) &&
4070 MI.getOperand(1).isImm() &&
4071 isShiftedUInt<4,2>(MI.getOperand(1).getImm()))
4072 return HexagonII::HSIG_S1;
4073 break;
4074 case Hexagon::S2_storerb_io:
4075 case Hexagon::dup_S2_storerb_io:
4076 // memb(Rs+#u4:0) = Rt
4077 Src1Reg = MI.getOperand(0).getReg();
4078 Src2Reg = MI.getOperand(2).getReg();
4079 if (isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg) &&
4080 MI.getOperand(1).isImm() && isUInt<4>(MI.getOperand(1).getImm()))
4081 return HexagonII::HSIG_S1;
4082 break;
4083 //
4084 // Group S2:
4085 //
4086 // memh(Rs+#u3:1) = Rt
4087 // memw(r29+#u5:2) = Rt
4088 // memd(r29+#s6:3) = Rtt
4089 // memw(Rs+#u4:2) = #U1
4090 // memb(Rs+#u4) = #U1
4091 // allocframe(#u5:3)
4092 case Hexagon::S2_storerh_io:
4093 case Hexagon::dup_S2_storerh_io:
4094 // memh(Rs+#u3:1) = Rt
4095 Src1Reg = MI.getOperand(0).getReg();
4096 Src2Reg = MI.getOperand(2).getReg();
4097 if (isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg) &&
4098 MI.getOperand(1).isImm() &&
4099 isShiftedUInt<3,1>(MI.getOperand(1).getImm()))
4100 return HexagonII::HSIG_S1;
4101 break;
4102 case Hexagon::S2_storerd_io:
4103 case Hexagon::dup_S2_storerd_io:
4104 // memd(r29+#s6:3) = Rtt
4105 Src1Reg = MI.getOperand(0).getReg();
4106 Src2Reg = MI.getOperand(2).getReg();
4107 if (isDblRegForSubInst(Src2Reg, HRI) &&
4108 Hexagon::IntRegsRegClass.contains(Src1Reg) &&
4109 HRI.getStackRegister() == Src1Reg && MI.getOperand(1).isImm() &&
4110 isShiftedInt<6,3>(MI.getOperand(1).getImm()))
4111 return HexagonII::HSIG_S2;
4112 break;
4113 case Hexagon::S4_storeiri_io:
4114 case Hexagon::dup_S4_storeiri_io:
4115 // memw(Rs+#u4:2) = #U1
4116 Src1Reg = MI.getOperand(0).getReg();
4117 if (isIntRegForSubInst(Src1Reg) && MI.getOperand(1).isImm() &&
4118 isShiftedUInt<4,2>(MI.getOperand(1).getImm()) &&
4119 MI.getOperand(2).isImm() && isUInt<1>(MI.getOperand(2).getImm()))
4120 return HexagonII::HSIG_S2;
4121 break;
4122 case Hexagon::S4_storeirb_io:
4123 case Hexagon::dup_S4_storeirb_io:
4124 // memb(Rs+#u4) = #U1
4125 Src1Reg = MI.getOperand(0).getReg();
4126 if (isIntRegForSubInst(Src1Reg) &&
4127 MI.getOperand(1).isImm() && isUInt<4>(MI.getOperand(1).getImm()) &&
4128 MI.getOperand(2).isImm() && isUInt<1>(MI.getOperand(2).getImm()))
4129 return HexagonII::HSIG_S2;
4130 break;
4131 case Hexagon::S2_allocframe:
4132 case Hexagon::dup_S2_allocframe:
4133 if (MI.getOperand(2).isImm() &&
4134 isShiftedUInt<5,3>(MI.getOperand(2).getImm()))
4135 return HexagonII::HSIG_S1;
4136 break;
4137 //
4138 // Group A:
4139 //
4140 // Rx = add(Rx,#s7)
4141 // Rd = Rs
4142 // Rd = #u6
4143 // Rd = #-1
4144 // if ([!]P0[.new]) Rd = #0
4145 // Rd = add(r29,#u6:2)
4146 // Rx = add(Rx,Rs)
4147 // P0 = cmp.eq(Rs,#u2)
4148 // Rdd = combine(#0,Rs)
4149 // Rdd = combine(Rs,#0)
4150 // Rdd = combine(#u2,#U2)
4151 // Rd = add(Rs,#1)
4152 // Rd = add(Rs,#-1)
4153 // Rd = sxth/sxtb/zxtb/zxth(Rs)
4154 // Rd = and(Rs,#1)
4155 case Hexagon::A2_addi:
4156 case Hexagon::dup_A2_addi:
4157 DstReg = MI.getOperand(0).getReg();
4158 SrcReg = MI.getOperand(1).getReg();
4159 if (isIntRegForSubInst(DstReg)) {
4160 // Rd = add(r29,#u6:2)
4161 if (Hexagon::IntRegsRegClass.contains(SrcReg) &&
4162 HRI.getStackRegister() == SrcReg && MI.getOperand(2).isImm() &&
4163 isShiftedUInt<6,2>(MI.getOperand(2).getImm()))
4164 return HexagonII::HSIG_A;
4165 // Rx = add(Rx,#s7)
4166 if ((DstReg == SrcReg) && MI.getOperand(2).isImm() &&
4167 isInt<7>(MI.getOperand(2).getImm()))
4168 return HexagonII::HSIG_A;
4169 // Rd = add(Rs,#1)
4170 // Rd = add(Rs,#-1)
4171 if (isIntRegForSubInst(SrcReg) && MI.getOperand(2).isImm() &&
4172 ((MI.getOperand(2).getImm() == 1) ||
4173 (MI.getOperand(2).getImm() == -1)))
4174 return HexagonII::HSIG_A;
4175 }
4176 break;
4177 case Hexagon::A2_add:
4178 case Hexagon::dup_A2_add:
4179 // Rx = add(Rx,Rs)
4180 DstReg = MI.getOperand(0).getReg();
4181 Src1Reg = MI.getOperand(1).getReg();
4182 Src2Reg = MI.getOperand(2).getReg();
4183 if (isIntRegForSubInst(DstReg) && (DstReg == Src1Reg) &&
4184 isIntRegForSubInst(Src2Reg))
4185 return HexagonII::HSIG_A;
4186 break;
4187 case Hexagon::A2_andir:
4188 case Hexagon::dup_A2_andir:
4189 // Same as zxtb.
4190 // Rd16=and(Rs16,#255)
4191 // Rd16=and(Rs16,#1)
4192 DstReg = MI.getOperand(0).getReg();
4193 SrcReg = MI.getOperand(1).getReg();
4194 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) &&
4195 MI.getOperand(2).isImm() &&
4196 ((MI.getOperand(2).getImm() == 1) ||
4197 (MI.getOperand(2).getImm() == 255)))
4198 return HexagonII::HSIG_A;
4199 break;
4200 case Hexagon::A2_tfr:
4201 case Hexagon::dup_A2_tfr:
4202 // Rd = Rs
4203 DstReg = MI.getOperand(0).getReg();
4204 SrcReg = MI.getOperand(1).getReg();
4205 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg))
4206 return HexagonII::HSIG_A;
4207 break;
4208 case Hexagon::A2_tfrsi:
4209 case Hexagon::dup_A2_tfrsi:
4210 // Rd = #u6
4211 // Do not test for #u6 size since the const is getting extended
4212 // regardless and compound could be formed.
4213 // Rd = #-1
4214 DstReg = MI.getOperand(0).getReg();
4215 if (isIntRegForSubInst(DstReg))
4216 return HexagonII::HSIG_A;
4217 break;
4218 case Hexagon::C2_cmoveit:
4219 case Hexagon::C2_cmovenewit:
4220 case Hexagon::C2_cmoveif:
4221 case Hexagon::C2_cmovenewif:
4222 case Hexagon::dup_C2_cmoveit:
4223 case Hexagon::dup_C2_cmovenewit:
4224 case Hexagon::dup_C2_cmoveif:
4225 case Hexagon::dup_C2_cmovenewif:
4226 // if ([!]P0[.new]) Rd = #0
4227 // Actual form:
4228 // %r16 = C2_cmovenewit internal %p0, 0, implicit undef %r16;
4229 DstReg = MI.getOperand(0).getReg();
4230 SrcReg = MI.getOperand(1).getReg();
4231 if (isIntRegForSubInst(DstReg) &&
4232 Hexagon::PredRegsRegClass.contains(SrcReg) && Hexagon::P0 == SrcReg &&
4233 MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0)
4234 return HexagonII::HSIG_A;
4235 break;
4236 case Hexagon::C2_cmpeqi:
4237 case Hexagon::dup_C2_cmpeqi:
4238 // P0 = cmp.eq(Rs,#u2)
4239 DstReg = MI.getOperand(0).getReg();
4240 SrcReg = MI.getOperand(1).getReg();
4241 if (Hexagon::PredRegsRegClass.contains(DstReg) &&
4242 Hexagon::P0 == DstReg && isIntRegForSubInst(SrcReg) &&
4243 MI.getOperand(2).isImm() && isUInt<2>(MI.getOperand(2).getImm()))
4244 return HexagonII::HSIG_A;
4245 break;
4246 case Hexagon::A2_combineii:
4247 case Hexagon::A4_combineii:
4248 case Hexagon::dup_A2_combineii:
4249 case Hexagon::dup_A4_combineii:
4250 // Rdd = combine(#u2,#U2)
4251 DstReg = MI.getOperand(0).getReg();
4252 if (isDblRegForSubInst(DstReg, HRI) &&
4253 ((MI.getOperand(1).isImm() && isUInt<2>(MI.getOperand(1).getImm())) ||
4254 (MI.getOperand(1).isGlobal() &&
4255 isUInt<2>(MI.getOperand(1).getOffset()))) &&
4256 ((MI.getOperand(2).isImm() && isUInt<2>(MI.getOperand(2).getImm())) ||
4257 (MI.getOperand(2).isGlobal() &&
4258 isUInt<2>(MI.getOperand(2).getOffset()))))
4259 return HexagonII::HSIG_A;
4260 break;
4261 case Hexagon::A4_combineri:
4262 case Hexagon::dup_A4_combineri:
4263 // Rdd = combine(Rs,#0)
4264 // Rdd = combine(Rs,#0)
4265 DstReg = MI.getOperand(0).getReg();
4266 SrcReg = MI.getOperand(1).getReg();
4267 if (isDblRegForSubInst(DstReg, HRI) && isIntRegForSubInst(SrcReg) &&
4268 ((MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0) ||
4269 (MI.getOperand(2).isGlobal() && MI.getOperand(2).getOffset() == 0)))
4270 return HexagonII::HSIG_A;
4271 break;
4272 case Hexagon::A4_combineir:
4273 case Hexagon::dup_A4_combineir:
4274 // Rdd = combine(#0,Rs)
4275 DstReg = MI.getOperand(0).getReg();
4276 SrcReg = MI.getOperand(2).getReg();
4277 if (isDblRegForSubInst(DstReg, HRI) && isIntRegForSubInst(SrcReg) &&
4278 ((MI.getOperand(1).isImm() && MI.getOperand(1).getImm() == 0) ||
4279 (MI.getOperand(1).isGlobal() && MI.getOperand(1).getOffset() == 0)))
4280 return HexagonII::HSIG_A;
4281 break;
4282 case Hexagon::A2_sxtb:
4283 case Hexagon::A2_sxth:
4284 case Hexagon::A2_zxtb:
4285 case Hexagon::A2_zxth:
4286 case Hexagon::dup_A2_sxtb:
4287 case Hexagon::dup_A2_sxth:
4288 case Hexagon::dup_A2_zxtb:
4289 case Hexagon::dup_A2_zxth:
4290 // Rd = sxth/sxtb/zxtb/zxth(Rs)
4291 DstReg = MI.getOperand(0).getReg();
4292 SrcReg = MI.getOperand(1).getReg();
4293 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg))
4294 return HexagonII::HSIG_A;
4295 break;
4296 }
4297
4298 return HexagonII::HSIG_None;
4299}
4300
4302 return Hexagon::getRealHWInstr(MI.getOpcode(), Hexagon::InstrType_Real);
4303}
4304
4306 const InstrItineraryData *ItinData, const MachineInstr &MI) const {
4307 // Default to one cycle for no itinerary. However, an "empty" itinerary may
4308 // still have a MinLatency property, which getStageLatency checks.
4309 if (!ItinData)
4310 return getInstrLatency(ItinData, MI);
4311
4312 if (MI.isTransient())
4313 return 0;
4314 return ItinData->getStageLatency(MI.getDesc().getSchedClass());
4315}
4316
4317/// getOperandLatency - Compute and return the use operand latency of a given
4318/// pair of def and use.
4319/// In most cases, the static scheduling itinerary was enough to determine the
4320/// operand latency. But it may not be possible for instructions with variable
4321/// number of defs / uses.
4322///
4323/// This is a raw interface to the itinerary that may be directly overriden by
4324/// a target. Use computeOperandLatency to get the best estimate of latency.
4326 const InstrItineraryData *ItinData, const MachineInstr &DefMI,
4327 unsigned DefIdx, const MachineInstr &UseMI, unsigned UseIdx) const {
4328 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
4329
4330 // Get DefIdx and UseIdx for super registers.
4331 const MachineOperand &DefMO = DefMI.getOperand(DefIdx);
4332
4333 if (DefMO.isReg() && DefMO.getReg().isPhysical()) {
4334 if (DefMO.isImplicit()) {
4335 for (MCPhysReg SR : HRI.superregs(DefMO.getReg())) {
4336 int Idx = DefMI.findRegisterDefOperandIdx(SR, &HRI, false, false);
4337 if (Idx != -1) {
4338 DefIdx = Idx;
4339 break;
4340 }
4341 }
4342 }
4343
4344 const MachineOperand &UseMO = UseMI.getOperand(UseIdx);
4345 if (UseMO.isImplicit()) {
4346 for (MCPhysReg SR : HRI.superregs(UseMO.getReg())) {
4347 int Idx = UseMI.findRegisterUseOperandIdx(SR, &HRI, false);
4348 if (Idx != -1) {
4349 UseIdx = Idx;
4350 break;
4351 }
4352 }
4353 }
4354 }
4355
4356 std::optional<unsigned> Latency = TargetInstrInfo::getOperandLatency(
4357 ItinData, DefMI, DefIdx, UseMI, UseIdx);
4358 if (Latency == 0)
4359 // We should never have 0 cycle latency between two instructions unless
4360 // they can be packetized together. However, this decision can't be made
4361 // here.
4362 Latency = 1;
4363 return Latency;
4364}
4365
4366// inverts the predication logic.
4367// p -> NotP
4368// NotP -> P
4371 if (Cond.empty())
4372 return false;
4373 unsigned Opc = getInvertedPredicatedOpcode(Cond[0].getImm());
4374 Cond[0].setImm(Opc);
4375 return true;
4376}
4377
4379 int InvPredOpcode;
4380 InvPredOpcode = isPredicatedTrue(Opc) ? Hexagon::getFalsePredOpcode(Opc)
4381 : Hexagon::getTruePredOpcode(Opc);
4382 if (InvPredOpcode >= 0) // Valid instruction with the inverted predicate.
4383 return InvPredOpcode;
4384
4385 llvm_unreachable("Unexpected predicated instruction");
4386}
4387
4388// Returns the max value that doesn't need to be extended.
4390 const uint64_t F = MI.getDesc().TSFlags;
4391 unsigned isSigned = (F >> HexagonII::ExtentSignedPos)
4393 unsigned bits = (F >> HexagonII::ExtentBitsPos)
4395
4396 if (isSigned) // if value is signed
4397 return ~(-1U << (bits - 1));
4398 else
4399 return ~(-1U << bits);
4400}
4401
4402
4404 switch (MI.getOpcode()) {
4405 case Hexagon::L2_loadrbgp:
4406 case Hexagon::L2_loadrdgp:
4407 case Hexagon::L2_loadrhgp:
4408 case Hexagon::L2_loadrigp:
4409 case Hexagon::L2_loadrubgp:
4410 case Hexagon::L2_loadruhgp:
4411 case Hexagon::S2_storerbgp:
4412 case Hexagon::S2_storerbnewgp:
4413 case Hexagon::S2_storerhgp:
4414 case Hexagon::S2_storerhnewgp:
4415 case Hexagon::S2_storerigp:
4416 case Hexagon::S2_storerinewgp:
4417 case Hexagon::S2_storerdgp:
4418 case Hexagon::S2_storerfgp:
4419 return true;
4420 }
4421 const uint64_t F = MI.getDesc().TSFlags;
4422 unsigned addrMode =
4424 // Disallow any base+offset instruction. The assembler does not yet reorder
4425 // based up any zero offset instruction.
4426 return (addrMode == HexagonII::BaseRegOffset ||
4427 addrMode == HexagonII::BaseImmOffset ||
4428 addrMode == HexagonII::BaseLongOffset);
4429}
4430
4432 // Workaround for the Global Scheduler. Sometimes, it creates
4433 // A4_ext as a Pseudo instruction and calls this function to see if
4434 // it can be added to an existing bundle. Since the instruction doesn't
4435 // belong to any BB yet, we can't use getUnits API.
4436 if (MI.getOpcode() == Hexagon::A4_ext)
4437 return false;
4438
4439 unsigned FuncUnits = getUnits(MI);
4440 return HexagonFUnits::isSlot0Only(FuncUnits);
4441}
4442
4444 const uint64_t F = MI.getDesc().TSFlags;
4447}
4448
4450 bool ToBigInstrs) const {
4451 int Opcode = -1;
4452 if (ToBigInstrs) { // To BigCore Instr.
4453 // Check if the instruction can form a Duplex.
4454 if (getDuplexCandidateGroup(*MII))
4455 // Get the opcode marked "dup_*" tag.
4456 Opcode = getDuplexOpcode(*MII, ToBigInstrs);
4457 } else // To TinyCore Instr.
4458 Opcode = getDuplexOpcode(*MII, ToBigInstrs);
4459
4460 // Change the opcode of the instruction.
4461 if (Opcode >= 0)
4462 MII->setDesc(get(Opcode));
4463}
4464
4465// This function is used to translate instructions to facilitate generating
4466// Duplexes on TinyCore.
4468 bool ToBigInstrs) const {
4469 for (auto &MB : MF)
4470 for (MachineBasicBlock::instr_iterator Instr = MB.instr_begin(),
4471 End = MB.instr_end();
4472 Instr != End; ++Instr)
4473 changeDuplexOpcode(Instr, ToBigInstrs);
4474}
4475
4476// This is a specialized form of above function.
4478 MachineBasicBlock::instr_iterator MII, bool ToBigInstrs) const {
4480 while ((MII != MBB->instr_end()) && MII->isInsideBundle()) {
4481 changeDuplexOpcode(MII, ToBigInstrs);
4482 ++MII;
4483 }
4484}
4485
4487 using namespace HexagonII;
4488
4489 const uint64_t F = MI.getDesc().TSFlags;
4490 unsigned S = (F >> MemAccessSizePos) & MemAccesSizeMask;
4491 unsigned Size = getMemAccessSizeInBytes(MemAccessSize(S));
4492 if (Size != 0)
4493 return Size;
4494 // Y2_dcfetchbo is special
4495 if (MI.getOpcode() == Hexagon::Y2_dcfetchbo)
4497
4498 // Handle vector access sizes.
4499 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
4500 switch (S) {
4502 return HRI.getSpillSize(Hexagon::HvxVRRegClass);
4503 default:
4504 llvm_unreachable("Unexpected instruction");
4505 }
4506}
4507
4508// Returns the min value that doesn't need to be extended.
4510 const uint64_t F = MI.getDesc().TSFlags;
4511 unsigned isSigned = (F >> HexagonII::ExtentSignedPos)
4513 unsigned bits = (F >> HexagonII::ExtentBitsPos)
4515
4516 if (isSigned) // if value is signed
4517 return -1U << (bits - 1);
4518 else
4519 return 0;
4520}
4521
4522// Returns opcode of the non-extended equivalent instruction.
4524 // Check if the instruction has a register form that uses register in place
4525 // of the extended operand, if so return that as the non-extended form.
4526 short NonExtOpcode = Hexagon::getRegForm(MI.getOpcode());
4527 if (NonExtOpcode >= 0)
4528 return NonExtOpcode;
4529
4530 if (MI.getDesc().mayLoad() || MI.getDesc().mayStore()) {
4531 // Check addressing mode and retrieve non-ext equivalent instruction.
4532 switch (getAddrMode(MI)) {
4534 return Hexagon::changeAddrMode_abs_io(MI.getOpcode());
4536 return Hexagon::changeAddrMode_io_rr(MI.getOpcode());
4538 return Hexagon::changeAddrMode_ur_rr(MI.getOpcode());
4539
4540 default:
4541 return -1;
4542 }
4543 }
4544 return -1;
4545}
4546
4548 Register &PredReg, unsigned &PredRegPos, unsigned &PredRegFlags) const {
4549 if (Cond.empty())
4550 return false;
4551 assert(Cond.size() == 2);
4552 if (isNewValueJump(Cond[0].getImm()) || Cond[1].isMBB()) {
4553 LLVM_DEBUG(dbgs() << "No predregs for new-value jumps/endloop");
4554 return false;
4555 }
4556 PredReg = Cond[1].getReg();
4557 PredRegPos = 1;
4558 // See IfConversion.cpp why we add RegState::Implicit | RegState::Undef
4559 PredRegFlags = 0;
4560 if (Cond[1].isImplicit())
4561 PredRegFlags = RegState::Implicit;
4562 if (Cond[1].isUndef())
4563 PredRegFlags |= RegState::Undef;
4564 return true;
4565}
4566
4568 return Hexagon::getRealHWInstr(MI.getOpcode(), Hexagon::InstrType_Pseudo);
4569}
4570
4572 return Hexagon::getRegForm(MI.getOpcode());
4573}
4574
4575// Return the number of bytes required to encode the instruction.
4576// Hexagon instructions are fixed length, 4 bytes, unless they
4577// use a constant extender, which requires another 4 bytes.
4578// For debug instructions and prolog labels, return 0.
4580 if (MI.isDebugInstr() || MI.isPosition())
4581 return 0;
4582
4583 unsigned Size = MI.getDesc().getSize();
4584 if (!Size)
4585 // Assume the default insn size in case it cannot be determined
4586 // for whatever reason.
4588
4591
4592 // Try and compute number of instructions in asm.
4593 if (BranchRelaxAsmLarge && MI.getOpcode() == Hexagon::INLINEASM) {
4594 const MachineBasicBlock &MBB = *MI.getParent();
4595 const MachineFunction *MF = MBB.getParent();
4596 const MCAsmInfo *MAI = MF->getTarget().getMCAsmInfo();
4597
4598 // Count the number of register definitions to find the asm string.
4599 unsigned NumDefs = 0;
4600 for (; MI.getOperand(NumDefs).isReg() && MI.getOperand(NumDefs).isDef();
4601 ++NumDefs)
4602 assert(NumDefs != MI.getNumOperands()-2 && "No asm string?");
4603
4604 assert(MI.getOperand(NumDefs).isSymbol() && "No asm string?");
4605 // Disassemble the AsmStr and approximate number of instructions.
4606 const char *AsmStr = MI.getOperand(NumDefs).getSymbolName();
4607 Size = getInlineAsmLength(AsmStr, *MAI);
4608 }
4609
4610 return Size;
4611}
4612
4614 const uint64_t F = MI.getDesc().TSFlags;
4616}
4617
4619 const InstrItineraryData &II = *Subtarget.getInstrItineraryData();
4620 const InstrStage &IS = *II.beginStage(MI.getDesc().getSchedClass());
4621
4622 return IS.getUnits();
4623}
4624
4625// Calculate size of the basic block without debug instructions.
4627 return nonDbgMICount(BB->instr_begin(), BB->instr_end());
4628}
4629
4631 MachineBasicBlock::const_iterator BundleHead) const {
4632 assert(BundleHead->isBundle() && "Not a bundle header");
4633 auto MII = BundleHead.getInstrIterator();
4634 // Skip the bundle header.
4635 return nonDbgMICount(++MII, getBundleEnd(BundleHead.getInstrIterator()));
4636}
4637
4638/// immediateExtend - Changes the instruction in place to one using an immediate
4639/// extender.
4642 "Instruction must be extendable");
4643 // Find which operand is extendable.
4644 short ExtOpNum = getCExtOpNum(MI);
4645 MachineOperand &MO = MI.getOperand(ExtOpNum);
4646 // This needs to be something we understand.
4647 assert((MO.isMBB() || MO.isImm()) &&
4648 "Branch with unknown extendable field type");
4649 // Mark given operand as extended.
4651}
4652
4654 MachineInstr &MI, MachineBasicBlock *NewTarget) const {
4655 LLVM_DEBUG(dbgs() << "\n[invertAndChangeJumpTarget] to "
4656 << printMBBReference(*NewTarget);
4657 MI.dump(););
4658 assert(MI.isBranch());
4659 unsigned NewOpcode = getInvertedPredicatedOpcode(MI.getOpcode());
4660 int TargetPos = MI.getNumOperands() - 1;
4661 // In general branch target is the last operand,
4662 // but some implicit defs added at the end might change it.
4663 while ((TargetPos > -1) && !MI.getOperand(TargetPos).isMBB())
4664 --TargetPos;
4665 assert((TargetPos >= 0) && MI.getOperand(TargetPos).isMBB());
4666 MI.getOperand(TargetPos).setMBB(NewTarget);
4668 NewOpcode = reversePrediction(NewOpcode);
4669 }
4670 MI.setDesc(get(NewOpcode));
4671 return true;
4672}
4673
4675 /* +++ The code below is used to generate complete set of Hexagon Insn +++ */
4677 MachineBasicBlock &B = *A;
4679 DebugLoc DL = I->getDebugLoc();
4680 MachineInstr *NewMI;
4681
4682 for (unsigned insn = TargetOpcode::GENERIC_OP_END+1;
4683 insn < Hexagon::INSTRUCTION_LIST_END; ++insn) {
4684 NewMI = BuildMI(B, I, DL, get(insn));
4685 LLVM_DEBUG(dbgs() << "\n"
4686 << getName(NewMI->getOpcode())
4687 << " Class: " << NewMI->getDesc().getSchedClass());
4688 NewMI->eraseFromParent();
4689 }
4690 /* --- The code above is used to generate complete set of Hexagon Insn --- */
4691}
4692
4693// inverts the predication logic.
4694// p -> NotP
4695// NotP -> P
4697 LLVM_DEBUG(dbgs() << "\nTrying to reverse pred. sense of:"; MI.dump());
4698 MI.setDesc(get(getInvertedPredicatedOpcode(MI.getOpcode())));
4699 return true;
4700}
4701
4702// Reverse the branch prediction.
4703unsigned HexagonInstrInfo::reversePrediction(unsigned Opcode) const {
4704 int PredRevOpcode = -1;
4705 if (isPredictedTaken(Opcode))
4706 PredRevOpcode = Hexagon::notTakenBranchPrediction(Opcode);
4707 else
4708 PredRevOpcode = Hexagon::takenBranchPrediction(Opcode);
4709 assert(PredRevOpcode > 0);
4710 return PredRevOpcode;
4711}
4712
4713// TODO: Add more rigorous validation.
4715 const {
4716 return Cond.empty() || (Cond[0].isImm() && (Cond.size() != 1));
4717}
4718
4721 assert(MIB->isBundle());
4722 MachineOperand &Operand = MIB->getOperand(0);
4723 if (Operand.isImm())
4724 Operand.setImm(Operand.getImm() | memShufDisabledMask);
4725 else
4726 MIB->addOperand(MachineOperand::CreateImm(memShufDisabledMask));
4727}
4728
4730 assert(MIB.isBundle());
4731 const MachineOperand &Operand = MIB.getOperand(0);
4732 return (Operand.isImm() && (Operand.getImm() & memShufDisabledMask) != 0);
4733}
4734
4735// Addressing mode relations.
4737 return Opc >= 0 ? Hexagon::changeAddrMode_abs_io(Opc) : Opc;
4738}
4739
4741 return Opc >= 0 ? Hexagon::changeAddrMode_io_abs(Opc) : Opc;
4742}
4743
4745 return Opc >= 0 ? Hexagon::changeAddrMode_io_pi(Opc) : Opc;
4746}
4747
4749 return Opc >= 0 ? Hexagon::changeAddrMode_io_rr(Opc) : Opc;
4750}
4751
4753 return Opc >= 0 ? Hexagon::changeAddrMode_pi_io(Opc) : Opc;
4754}
4755
4757 return Opc >= 0 ? Hexagon::changeAddrMode_rr_io(Opc) : Opc;
4758}
4759
4761 return Opc >= 0 ? Hexagon::changeAddrMode_rr_ur(Opc) : Opc;
4762}
4763
4765 return Opc >= 0 ? Hexagon::changeAddrMode_ur_rr(Opc) : Opc;
4766}
4767
4769 static const MCInst Nop = MCInstBuilder(Hexagon::A2_nop);
4770
4771 return MCInstBuilder(Hexagon::BUNDLE)
4772 .addImm(0)
4773 .addInst(&Nop);
4774}
unsigned const MachineRegisterInfo * MRI
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
static bool mayAlias(MachineInstr &MIa, SmallVectorImpl< MachineInstr * > &MemInsns, AliasAnalysis *AA)
static bool isConstant(const MachineInstr &MI)
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static const Function * getParent(const Value *V)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
#define LLVM_DEBUG(...)
Definition: Debug.h:106
uint64_t Size
bool End
Definition: ELF_riscv.cpp:480
static bool isSigned(unsigned int Opcode)
const HexagonInstrInfo * TII
static bool isUndef(ArrayRef< int > Mask)
static cl::opt< bool > DisableNVSchedule("disable-hexagon-nv-schedule", cl::Hidden, cl::desc("Disable schedule adjustment for new value stores."))
const int Hexagon_MEMH_OFFSET_MAX
const int Hexagon_MEMB_OFFSET_MAX
const int Hexagon_MEMH_OFFSET_MIN
const int Hexagon_MEMD_OFFSET_MAX
static cl::opt< bool > EnableTimingClassLatency("enable-timing-class-latency", cl::Hidden, cl::init(false), cl::desc("Enable timing class latency"))
const int Hexagon_MEMD_OFFSET_MIN
const int Hexagon_ADDI_OFFSET_MAX
static cl::opt< bool > EnableACCForwarding("enable-acc-forwarding", cl::Hidden, cl::init(true), cl::desc("Enable vec acc forwarding"))
static void getLiveInRegsAt(LivePhysRegs &Regs, const MachineInstr &MI)
const int Hexagon_MEMW_OFFSET_MAX
Constants for Hexagon instructions.
const int Hexagon_MEMW_OFFSET_MIN
cl::opt< bool > ScheduleInlineAsm("hexagon-sched-inline-asm", cl::Hidden, cl::init(false), cl::desc("Do not consider inline-asm a scheduling/" "packetization boundary."))
const int Hexagon_ADDI_OFFSET_MIN
static cl::opt< bool > BranchRelaxAsmLarge("branch-relax-asm-large", cl::init(true), cl::Hidden, cl::desc("branch relax asm"))
static void parseOperands(const MachineInstr &MI, SmallVectorImpl< Register > &Defs, SmallVectorImpl< Register > &Uses)
Gather register def/uses from MI.
static cl::opt< bool > EnableALUForwarding("enable-alu-forwarding", cl::Hidden, cl::init(true), cl::desc("Enable vec alu forwarding"))
const int Hexagon_MEMB_OFFSET_MIN
static unsigned nonDbgMICount(MachineBasicBlock::const_instr_iterator MIB, MachineBasicBlock::const_instr_iterator MIE)
Calculate number of instructions excluding the debug instructions.
static cl::opt< bool > EnableBranchPrediction("hexagon-enable-branch-prediction", cl::Hidden, cl::init(true), cl::desc("Enable branch prediction"))
static bool isDblRegForSubInst(Register Reg, const HexagonRegisterInfo &HRI)
static void getLiveOutRegsAt(LivePhysRegs &Regs, const MachineInstr &MI)
static cl::opt< bool > UseDFAHazardRec("dfa-hazard-rec", cl::init(true), cl::Hidden, cl::desc("Use the DFA based hazard recognizer."))
static bool isIntRegForSubInst(Register Reg)
static bool isDuplexPairMatch(unsigned Ga, unsigned Gb)
#define HEXAGON_INSTR_SIZE
IRTranslator LLVM IR MI
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first found DebugLoc that has a DILocation, given a range of instructions.
unsigned const TargetRegisterInfo * TRI
static unsigned getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static bool isReg(const MCInst &MI, unsigned OpNo)
uint64_t IntrinsicInst * II
PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &PIC)
static StringRef getName(Value *V)
static bool isBranch(unsigned Opcode)
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
Remove Loads Into Fake Uses
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isImm(const MachineOperand &MO, MachineRegisterInfo *MRI)
raw_pwrite_stream & OS
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition: Value.cpp:469
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file contains some functions that are useful when dealing with strings.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
This class represents an Operation in the Expression.
A debug info location.
Definition: DebugLoc.h:33
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
short getEquivalentHWInstr(const MachineInstr &MI) const
int getDuplexOpcode(const MachineInstr &MI, bool ForBigCore=true) const
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
Remove the branching code at the end of the specific MBB.
bool isPredicated(const MachineInstr &MI) const override
Returns true if the instruction is already predicated.
bool isHVXMemWithAIndirect(const MachineInstr &I, const MachineInstr &J) const
short changeAddrMode_abs_io(short Opc) const
bool isRestrictNoSlot1Store(const MachineInstr &MI) const
short getRegForm(const MachineInstr &MI) const
bool isVecALU(const MachineInstr &MI) const
bool isCompoundBranchInstr(const MachineInstr &MI) const
bool isDuplexPair(const MachineInstr &MIa, const MachineInstr &MIb) const
Symmetrical. See if these two instructions are fit for duplex pair.
bool isJumpR(const MachineInstr &MI) const
ScheduleHazardRecognizer * CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II, const ScheduleDAG *DAG) const override
Allocate and return a hazard recognizer to use for this target when scheduling the machine instructio...
std::pair< unsigned, unsigned > decomposeMachineOperandsTargetFlags(unsigned TF) const override
Decompose the machine operand's target flags into two values - the direct target flag value and any o...
bool producesStall(const MachineInstr &ProdMI, const MachineInstr &ConsMI) const
bool invertAndChangeJumpTarget(MachineInstr &MI, MachineBasicBlock *NewTarget) const
bool isPredictedTaken(unsigned Opcode) const
bool isSaveCalleeSavedRegsCall(const MachineInstr &MI) const
Register isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) const override
TargetInstrInfo overrides.
unsigned nonDbgBundleSize(MachineBasicBlock::const_iterator BundleHead) const
int getDotNewPredOp(const MachineInstr &MI, const MachineBranchProbabilityInfo *MBPI) const
bool ClobbersPredicate(MachineInstr &MI, std::vector< MachineOperand > &Pred, bool SkipDead) const override
If the specified instruction defines any predicate or condition code register(s) used for predication...
unsigned getInvertedPredicatedOpcode(const int Opc) const
bool isPureSlot0(const MachineInstr &MI) const
bool doesNotReturn(const MachineInstr &CallMI) const
HexagonII::SubInstructionGroup getDuplexCandidateGroup(const MachineInstr &MI) const
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
Analyze the branching code at the end of MBB, returning true if it cannot be understood (e....
bool getPredReg(ArrayRef< MachineOperand > Cond, Register &PredReg, unsigned &PredRegPos, unsigned &PredRegFlags) const
bool isPredicatedNew(const MachineInstr &MI) const
bool isSignExtendingLoad(const MachineInstr &MI) const
bool isVecAcc(const MachineInstr &MI) const
bool reversePredSense(MachineInstr &MI) const
unsigned getAddrMode(const MachineInstr &MI) const
MCInst getNop() const override
bool isJumpWithinBranchRange(const MachineInstr &MI, unsigned offset) const
bool mayBeNewStore(const MachineInstr &MI) const
bool isOperandExtended(const MachineInstr &MI, unsigned OperandNum) const
bool canExecuteInBundle(const MachineInstr &First, const MachineInstr &Second) const
Can these instructions execute at the same time in a bundle.
std::optional< unsigned > getOperandLatency(const InstrItineraryData *ItinData, const MachineInstr &DefMI, unsigned DefIdx, const MachineInstr &UseMI, unsigned UseIdx) const override
getOperandLatency - Compute and return the use operand latency of a given pair of def and use.
bool isAddrModeWithOffset(const MachineInstr &MI) const
bool getMemOperandsWithOffsetWidth(const MachineInstr &LdSt, SmallVectorImpl< const MachineOperand * > &BaseOps, int64_t &Offset, bool &OffsetIsScalable, LocationSize &Width, const TargetRegisterInfo *TRI) const override
Get the base register and byte offset of a load/store instr.
bool isValidOffset(unsigned Opcode, int Offset, const TargetRegisterInfo *TRI, bool Extend=true) const
bool isBaseImmOffset(const MachineInstr &MI) const
bool isAbsoluteSet(const MachineInstr &MI) const
short changeAddrMode_io_pi(short Opc) const
short changeAddrMode_pi_io(short Opc) const
bool analyzeCompare(const MachineInstr &MI, Register &SrcReg, Register &SrcReg2, int64_t &Mask, int64_t &Value) const override
For a comparison instruction, return the source registers in SrcReg and SrcReg2 if having two registe...
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const override
Reverses the branch condition of the specified condition list, returning false on success and true if...
std::unique_ptr< PipelinerLoopInfo > analyzeLoopForPipelining(MachineBasicBlock *LoopBB) const override
Analyze loop L, which must be a single-basic-block loop, and if the conditions can be understood enou...
bool isLoopN(const MachineInstr &MI) const
bool isSpillPredRegOp(const MachineInstr &MI) const
bool hasStoreToStackSlot(const MachineInstr &MI, SmallVectorImpl< const MachineMemOperand * > &Accesses) const override
Check if the instruction or the bundle of instructions has store to stack slots.
ArrayRef< std::pair< unsigned, const char * > > getSerializableDirectMachineOperandTargetFlags() const override
Return an array that contains the direct target flag values and their names.
bool isIndirectCall(const MachineInstr &MI) const
short changeAddrMode_ur_rr(short Opc) const
bool isValidAutoIncImm(const EVT VT, const int Offset) const
bool hasNonExtEquivalent(const MachineInstr &MI) const
bool isConstExtended(const MachineInstr &MI) const
bool getIncrementValue(const MachineInstr &MI, int &Value) const override
If the instruction is an increment of a constant value, return the amount.
int getCondOpcode(int Opc, bool sense) const
MachineInstr * findLoopInstr(MachineBasicBlock *BB, unsigned EndLoopOp, MachineBasicBlock *TargetBB, SmallPtrSet< MachineBasicBlock *, 8 > &Visited) const
Find the hardware loop instruction used to set-up the specified loop.
unsigned getInstrTimingClassLatency(const InstrItineraryData *ItinData, const MachineInstr &MI) const
bool isAccumulator(const MachineInstr &MI) const
unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, ArrayRef< MachineOperand > Cond, const DebugLoc &DL, int *BytesAdded=nullptr) const override
Insert branch code into the end of the specified MachineBasicBlock.
unsigned getInstrLatency(const InstrItineraryData *ItinData, const MachineInstr &MI, unsigned *PredCost=nullptr) const override
Compute the instruction latency of a given instruction.
bool PredOpcodeHasJMP_c(unsigned Opcode) const
bool isNewValue(const MachineInstr &MI) const
Register createVR(MachineFunction *MF, MVT VT) const
HexagonInstrInfo specifics.
bool isDotCurInst(const MachineInstr &MI) const
bool validateBranchCond(const ArrayRef< MachineOperand > &Cond) const
bool isExtended(const MachineInstr &MI) const
bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, unsigned ExtraPredCycles, BranchProbability Probability) const override
Return true if it's profitable to predicate instructions with accumulated instruction latency of "Num...
bool isAsCheapAsAMove(const MachineInstr &MI) const override
int getMaxValue(const MachineInstr &MI) const
bool isPredicateLate(unsigned Opcode) const
short changeAddrMode_rr_ur(short Opc) const
bool hasPseudoInstrPair(const MachineInstr &MI) const
bool isNewValueInst(const MachineInstr &MI) const
unsigned getInlineAsmLength(const char *Str, const MCAsmInfo &MAI, const TargetSubtargetInfo *STI=nullptr) const override
Measure the specified inline asm to determine an approximation of its length.
bool areMemAccessesTriviallyDisjoint(const MachineInstr &MIa, const MachineInstr &MIb) const override
int getNonDotCurOp(const MachineInstr &MI) const
bool isIndirectL4Return(const MachineInstr &MI) const
unsigned reversePrediction(unsigned Opcode) const
ArrayRef< std::pair< unsigned, const char * > > getSerializableBitmaskMachineOperandTargetFlags() const override
Return an array that contains the bitmask target flag values and their names.
InstrStage::FuncUnits getUnits(const MachineInstr &MI) const
unsigned getMemAccessSize(const MachineInstr &MI) const
bool predOpcodeHasNot(ArrayRef< MachineOperand > Cond) const
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
Store the specified register of the given register class to the specified stack frame index.
bool isComplex(const MachineInstr &MI) const
bool isPostIncrement(const MachineInstr &MI) const override
Return true for post-incremented instructions.
void setBundleNoShuf(MachineBasicBlock::instr_iterator MIB) const
MachineBasicBlock::instr_iterator expandVGatherPseudo(MachineInstr &MI) const
int getDotNewOp(const MachineInstr &MI) const
void changeDuplexOpcode(MachineBasicBlock::instr_iterator MII, bool ToBigInstrs) const
bool isMemOp(const MachineInstr &MI) const
int getDotOldOp(const MachineInstr &MI) const
short getPseudoInstrPair(const MachineInstr &MI) const
bool hasUncondBranch(const MachineBasicBlock *B) const
short getNonExtOpcode(const MachineInstr &MI) const
bool isTailCall(const MachineInstr &MI) const override
void insertNoop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
Insert a noop into the instruction stream at the specified point.
bool isDeallocRet(const MachineInstr &MI) const
unsigned getCExtOpNum(const MachineInstr &MI) const
bool isSolo(const MachineInstr &MI) const
DFAPacketizer * CreateTargetScheduleState(const TargetSubtargetInfo &STI) const override
Create machine specific model for scheduling.
bool isLateSourceInstr(const MachineInstr &MI) const
bool isDotNewInst(const MachineInstr &MI) const
void translateInstrsForDup(MachineFunction &MF, bool ToBigInstrs=true) const
bool isTC1(const MachineInstr &MI) const
bool isSchedulingBoundary(const MachineInstr &MI, const MachineBasicBlock *MBB, const MachineFunction &MF) const override
Test if the given instruction should be considered a scheduling boundary.
bool predCanBeUsedAsDotNew(const MachineInstr &MI, Register PredReg) const
unsigned getSize(const MachineInstr &MI) const
bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, BranchProbability Probability) const override
Return true if it's profitable for if-converter to duplicate instructions of specified accumulated in...
short changeAddrMode_io_abs(short Opc) const
int getDotCurOp(const MachineInstr &MI) const
bool expandPostRAPseudo(MachineInstr &MI) const override
This function is called for all pseudo instructions that remain after register allocation.
bool isExpr(unsigned OpType) const
void genAllInsnTimingClasses(MachineFunction &MF) const
bool isTC2Early(const MachineInstr &MI) const
bool hasEHLabel(const MachineBasicBlock *B) const
bool shouldSink(const MachineInstr &MI) const override
bool isZeroExtendingLoad(const MachineInstr &MI) const
short changeAddrMode_rr_io(short Opc) const
bool isHVXVec(const MachineInstr &MI) const
bool isDependent(const MachineInstr &ProdMI, const MachineInstr &ConsMI) const
short changeAddrMode_io_rr(short Opc) const
bool SubsumesPredicate(ArrayRef< MachineOperand > Pred1, ArrayRef< MachineOperand > Pred2) const override
Returns true if the first specified predicate subsumes the second, e.g.
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, const DebugLoc &DL, MCRegister DestReg, MCRegister SrcReg, bool KillSrc, bool RenamableDest=false, bool RenamableSrc=false) const override
Emit instructions to copy a pair of physical registers.
bool mayBeCurLoad(const MachineInstr &MI) const
bool getBundleNoShuf(const MachineInstr &MIB) const
bool isNewValueJump(const MachineInstr &MI) const
bool isTC4x(const MachineInstr &MI) const
bool PredicateInstruction(MachineInstr &MI, ArrayRef< MachineOperand > Cond) const override
Convert the instruction into a predicated instruction.
bool isFloat(const MachineInstr &MI) const
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
Load the specified register of the given register class from the specified stack frame index.
bool isToBeScheduledASAP(const MachineInstr &MI1, const MachineInstr &MI2) const
MachineOperand * getBaseAndOffset(const MachineInstr &MI, int64_t &Offset, LocationSize &AccessSize) const
bool getInvertedPredSense(SmallVectorImpl< MachineOperand > &Cond) const
unsigned nonDbgBBSize(const MachineBasicBlock *BB) const
getInstrTimingClassLatency - Compute the instruction latency of a given instruction using Timing Clas...
uint64_t getType(const MachineInstr &MI) const
bool isEndLoopN(unsigned Opcode) const
bool getBaseAndOffsetPosition(const MachineInstr &MI, unsigned &BasePos, unsigned &OffsetPos) const override
For instructions with a base and offset, return the position of the base register and offset operands...
bool isPredicable(const MachineInstr &MI) const override
Return true if the specified instruction can be predicated.
bool isExtendable(const MachineInstr &MI) const
void immediateExtend(MachineInstr &MI) const
immediateExtend - Changes the instruction in place to one using an immediate extender.
HexagonII::CompoundGroup getCompoundCandidateGroup(const MachineInstr &MI) const
bool hasLoadFromStackSlot(const MachineInstr &MI, SmallVectorImpl< const MachineMemOperand * > &Accesses) const override
Check if the instruction or the bundle of instructions has load from stack slots.
SmallVector< MachineInstr *, 2 > getBranchingInstrs(MachineBasicBlock &MBB) const
HexagonInstrInfo(HexagonSubtarget &ST)
bool isPredicatedTrue(const MachineInstr &MI) const
bool isNewValueStore(const MachineInstr &MI) const
int getMinValue(const MachineInstr &MI) const
bool isVecUsableNextPacket(const MachineInstr &ProdMI, const MachineInstr &ConsMI) const
unsigned getCompoundOpcode(const MachineInstr &GA, const MachineInstr &GB) const
bool addLatencyToSchedule(const MachineInstr &MI1, const MachineInstr &MI2) const
Register isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex) const override
If the specified machine instruction is a direct store to a stack slot, return the virtual or physica...
int getDotNewPredJumpOp(const MachineInstr &MI, const MachineBranchProbabilityInfo *MBPI) const
bool isTC2(const MachineInstr &MI) const
Register getFrameRegister(const MachineFunction &MF) const override
const InstrItineraryData * getInstrItineraryData() const override
getInstrItins - Return the instruction itineraries based on subtarget selection.
const HexagonRegisterInfo * getRegisterInfo() const override
bool useNewValueStores() const
Itinerary data supplied by a subtarget to be used by a target.
unsigned getStageLatency(unsigned ItinClassIndx) const
Return the total stage latency of the given class.
A set of physical registers with utility functions to track liveness when walking backward/forward th...
Definition: LivePhysRegs.h:52
bool contains(MCPhysReg Reg) const
Returns true if register Reg is contained in the set.
Definition: LivePhysRegs.h:109
void stepForward(const MachineInstr &MI, SmallVectorImpl< std::pair< MCPhysReg, const MachineOperand * > > &Clobbers)
Simulates liveness when stepping forward over an instruction(bundle).
bool available(const MachineRegisterInfo &MRI, MCPhysReg Reg) const
Returns true if register Reg and no aliasing register is in the set.
void stepBackward(const MachineInstr &MI)
Simulates liveness when stepping backwards over an instruction(bundle).
void addLiveIns(const MachineBasicBlock &MBB)
Adds all live-in registers of basic block MBB.
void addLiveOuts(const MachineBasicBlock &MBB)
Adds all live-out registers of basic block MBB.
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:39
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
virtual unsigned getMaxInstLength(const MCSubtargetInfo *STI=nullptr) const
Returns the maximum possible encoded instruction size in bytes.
Definition: MCAsmInfo.h:532
StringRef getCommentString() const
Definition: MCAsmInfo.h:543
const char * getSeparatorString() const
Definition: MCAsmInfo.h:538
MCInstBuilder & addInst(const MCInst *Val)
Add a new MCInst operand.
Definition: MCInstBuilder.h:67
MCInstBuilder & addImm(int64_t Val)
Add a new integer immediate operand.
Definition: MCInstBuilder.h:43
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:185
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:198
unsigned getSchedClass() const
Return the scheduling class for this instruction.
Definition: MCInstrDesc.h:600
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
Definition: MCInstrDesc.h:248
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:33
Machine Value Type.
SimpleValueType SimpleTy
instr_iterator instr_begin()
MachineInstrBundleIterator< const MachineInstr > const_iterator
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any debug instructions.
Instructions::iterator instr_iterator
bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB will be emitted immediately after this block, such that if this bloc...
instr_iterator instr_end()
Instructions::const_iterator const_instr_iterator
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
iterator_range< succ_iterator > successors()
iterator_range< pred_iterator > predecessors()
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
BranchProbability getEdgeProbability(const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, LLT MemTy, Align base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
const char * createExternalSymbolName(StringRef Name)
Allocate a string and populate it with the given external symbol name.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addFrameIndex(int Idx) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & cloneMemRefs(const MachineInstr &OtherMI) const
const MachineInstrBuilder & addUse(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
reverse_iterator getReverse() const
Get a reverse iterator to the same node.
Representation of each machine instruction.
Definition: MachineInstr.h:69
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:575
bool readsRegister(Register Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr reads the specified register.
bool isBundle() const
unsigned getNumOperands() const
Retuns the total number of operands.
Definition: MachineInstr.h:578
unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
Definition: MachineInstr.h:572
bool hasUnmodeledSideEffects() const
Return true if this instruction has side effects that are not modeled by mayLoad / mayStore,...
bool hasOrderedMemoryRef() const
Return true if this instruction may have an ordered or volatile memory reference, or if the informati...
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:585
bool isIndirectBranch(QueryType Type=AnyInBundle) const
Return true if this is an indirect branch, such as a branch through a register.
Definition: MachineInstr.h:995
A description of a memory reference used in the backend.
@ MOVolatile
The memory access is volatile.
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
void setImm(int64_t immVal)
int64_t getImm() const
bool isImplicit() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MachineBasicBlock * getMBB() const
bool isCPI() const
isCPI - Tests if this is a MO_ConstantPoolIndex operand.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
bool isJTI() const
isJTI - Tests if this is a MO_JumpTableIndex operand.
unsigned getTargetFlags() const
static MachineOperand CreateImm(int64_t Val)
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
bool isBlockAddress() const
isBlockAddress - Tests if this is a MO_BlockAddress operand.
Register getReg() const
getReg - Returns the register number.
void addTargetFlag(unsigned F)
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
@ MO_GlobalAddress
Address of a global value.
@ MO_BlockAddress
Address of a basic block.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_ExternalSymbol
Name of external global symbol.
@ MO_JumpTableIndex
Address of indexed Jump Table for switch.
bool isFPImm() const
isFPImm - Tests if this is a MO_FPImmediate operand.
bool isMBB() const
isMBB - Tests if this is a MO_MachineBasicBlock operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
void dump() const
Definition: Pass.cpp:136
Special value supplied for machine level alias analysis.
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition: Register.h:95
HazardRecognizer - This determines whether or not an instruction can be issued this cycle,...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:384
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:519
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
Register getReg() const
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:150
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:144
size_t count(char C) const
Return the number of occurrences of C in the string.
Definition: StringRef.h:451
Object returned by analyzeLoopForPipelining.
virtual ScheduleHazardRecognizer * CreateTargetPostRAHazardRecognizer(const InstrItineraryData *, const ScheduleDAG *DAG) const
Allocate and return a hazard recognizer to use for this target when scheduling the machine instructio...
virtual bool hasStoreToStackSlot(const MachineInstr &MI, SmallVectorImpl< const MachineMemOperand * > &Accesses) const
If the specified machine instruction has a store to a stack slot, return true along with the FrameInd...
virtual std::optional< unsigned > getOperandLatency(const InstrItineraryData *ItinData, SDNode *DefNode, unsigned DefIdx, SDNode *UseNode, unsigned UseIdx) const
virtual bool hasLoadFromStackSlot(const MachineInstr &MI, SmallVectorImpl< const MachineMemOperand * > &Accesses) const
If the specified machine instruction has a load from a stack slot, return true along with the FrameIn...
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual const InstrItineraryData * getInstrItineraryData() const
getInstrItineraryData - Returns instruction itinerary data for the target or specific subtarget.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
LLVM Value Representation.
Definition: Value.h:74
self_iterator getIterator()
Definition: ilist_node.h:132
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isSlot0Only(unsigned units)
unsigned const TypeCVI_LAST
unsigned const TypeCVI_FIRST
@ Implicit
Not emitted register (e.g. carry, or temporary result).
@ InternalRead
Register reads a value that is defined inside the same instruction or bundle.
@ Kill
The last use of a register.
@ Undef
Value of the register doesn't matter.
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
@ Length
Definition: DWP.cpp:480
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1739
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
@ Done
Definition: Threading.h:61
bool is_TC1(unsigned SchedClass)
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition: MathExtras.h:342
auto reverse(ContainerTy &&C)
Definition: STLExtras.h:420
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition: MathExtras.h:293
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
MachineBasicBlock::instr_iterator getBundleEnd(MachineBasicBlock::instr_iterator I)
Returns an iterator pointing beyond the bundle containing I.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
bool is_TC2(unsigned SchedClass)
unsigned getUndefRegState(bool B)
unsigned getRegState(const MachineOperand &RegOp)
Get all register state flags from machine operand RegOp.
bool is_TC2early(unsigned SchedClass)
unsigned getKillRegState(bool B)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1903
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
bool is_TC4x(unsigned SchedClass)
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
Extended Value Type.
Definition: ValueTypes.h:35
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:368
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition: ValueTypes.h:311
These values represent a non-pipelined step in the execution of an instruction.
FuncUnits getUnits() const
Returns the choice of FUs.
This class contains a discriminated union of information about pointers in memory operands,...
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.