LLVM 24.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"
17#include "HexagonRegisterInfo.h"
18#include "HexagonSubtarget.h"
19#include "llvm/ADT/ArrayRef.h"
23#include "llvm/ADT/StringRef.h"
44#include "llvm/IR/DebugLoc.h"
46#include "llvm/MC/MCAsmInfo.h"
48#include "llvm/MC/MCInstrDesc.h"
52#include "llvm/Support/Debug.h"
57#include <cassert>
58#include <cstdint>
59#include <cstring>
60#include <iterator>
61#include <optional>
62#include <string>
63#include <utility>
64
65using namespace llvm;
66
67#define DEBUG_TYPE "hexagon-instrinfo"
68
69#define GET_INSTRINFO_CTOR_DTOR
70#define GET_INSTRMAP_INFO
72#include "HexagonGenDFAPacketizer.inc"
73#include "HexagonGenInstrInfo.inc"
74
75cl::opt<bool> ScheduleInlineAsm("hexagon-sched-inline-asm", cl::Hidden,
76 cl::init(false), cl::desc("Do not consider inline-asm a scheduling/"
77 "packetization boundary."));
78
79static cl::opt<bool> EnableBranchPrediction("hexagon-enable-branch-prediction",
80 cl::Hidden, cl::init(true), cl::desc("Enable branch prediction"));
81
83 "disable-hexagon-nv-schedule", cl::Hidden,
84 cl::desc("Disable schedule adjustment for new value stores."));
85
87 "enable-timing-class-latency", cl::Hidden, cl::init(false),
88 cl::desc("Enable timing class latency"));
89
91 "enable-alu-forwarding", cl::Hidden, cl::init(true),
92 cl::desc("Enable vec alu forwarding"));
93
95 "enable-acc-forwarding", cl::Hidden, cl::init(true),
96 cl::desc("Enable vec acc forwarding"));
97
98static cl::opt<bool> BranchRelaxAsmLarge("branch-relax-asm-large",
99 cl::init(true), cl::Hidden,
100 cl::desc("branch relax asm"));
101
102static cl::opt<bool>
103 UseDFAHazardRec("dfa-hazard-rec", cl::init(true), cl::Hidden,
104 cl::desc("Use the DFA based hazard recognizer."));
105
106/// Constants for Hexagon instructions.
107const int Hexagon_MEMW_OFFSET_MAX = 4095;
108const int Hexagon_MEMW_OFFSET_MIN = -4096;
109const int Hexagon_MEMD_OFFSET_MAX = 8191;
110const int Hexagon_MEMD_OFFSET_MIN = -8192;
111const int Hexagon_MEMH_OFFSET_MAX = 2047;
112const int Hexagon_MEMH_OFFSET_MIN = -2048;
113const int Hexagon_MEMB_OFFSET_MAX = 1023;
114const int Hexagon_MEMB_OFFSET_MIN = -1024;
115const int Hexagon_ADDI_OFFSET_MAX = 32767;
116const int Hexagon_ADDI_OFFSET_MIN = -32768;
117
118// Pin the vtable to this file.
119void HexagonInstrInfo::anchor() {}
120
122 : HexagonGenInstrInfo(ST, RegInfo, Hexagon::ADJCALLSTACKDOWN,
123 Hexagon::ADJCALLSTACKUP),
124 RegInfo(ST.getHwMode()), Subtarget(ST) {}
125
126namespace llvm {
127namespace HexagonFUnits {
128 bool isSlot0Only(unsigned units);
129}
130}
131
133 return (Reg >= Hexagon::R0 && Reg <= Hexagon::R7) ||
134 (Reg >= Hexagon::R16 && Reg <= Hexagon::R23);
135}
136
138 return isIntRegForSubInst(HRI.getSubReg(Reg, Hexagon::isub_lo)) &&
139 isIntRegForSubInst(HRI.getSubReg(Reg, Hexagon::isub_hi));
140}
141
142/// Calculate number of instructions excluding the debug instructions.
145 unsigned Count = 0;
146 for (; MIB != MIE; ++MIB) {
147 if (!MIB->isDebugInstr())
148 ++Count;
149 }
150 return Count;
151}
152
153// Check if the A2_tfrsi instruction is cheap or not. If the operand has
154// to be constant-extendend it is not cheap since it occupies two slots
155// in a packet.
157 // Enable the following steps only at Os/Oz
158 if (!(MI.getMF()->getFunction().hasOptSize()))
159 return MI.isAsCheapAsAMove();
160
161 if (MI.getOpcode() == Hexagon::A2_tfrsi) {
162 auto Op = MI.getOperand(1);
163 // If the instruction has a global address as operand, it is not cheap
164 // since the operand will be constant extended.
165 if (Op.isGlobal())
166 return false;
167 // If the instruction has an operand of size > 16bits, its will be
168 // const-extended and hence, it is not cheap.
169 if (Op.isImm()) {
170 int64_t Imm = Op.getImm();
171 if (!isInt<16>(Imm))
172 return false;
173 }
174 }
175 return MI.isAsCheapAsAMove();
176}
177
178// Do not sink floating point instructions that updates USR register.
179// Example:
180// feclearexcept
181// F2_conv_w2sf
182// fetestexcept
183// MachineSink sinks F2_conv_w2sf and we are not able to catch exceptions.
184// TODO: On some of these floating point instructions, USR is marked as Use.
185// In reality, these instructions also Def the USR. If USR is marked as Def,
186// some of the assumptions in assembler packetization are broken.
188 // Assumption: A floating point instruction that reads the USR will write
189 // the USR as well.
190 if (isFloat(MI) && MI.hasRegisterImplicitUseOperand(Hexagon::USR))
191 return false;
192 return true;
193}
194
195/// Find the hardware loop instruction used to set-up the specified loop.
196/// On Hexagon, we have two instructions used to set-up the hardware loop
197/// (LOOP0, LOOP1) with corresponding endloop (ENDLOOP0, ENDLOOP1) instructions
198/// to indicate the end of a loop.
200 unsigned EndLoopOp, MachineBasicBlock *TargetBB,
202 unsigned LOOPi;
203 unsigned LOOPr;
204 if (EndLoopOp == Hexagon::ENDLOOP0) {
205 LOOPi = Hexagon::J2_loop0i;
206 LOOPr = Hexagon::J2_loop0r;
207 } else { // EndLoopOp == Hexagon::EndLOOP1
208 LOOPi = Hexagon::J2_loop1i;
209 LOOPr = Hexagon::J2_loop1r;
210 }
211
212 // The loop set-up instruction will be in a predecessor block
213 for (MachineBasicBlock *PB : BB->predecessors()) {
214 // If this has been visited, already skip it.
215 if (!Visited.insert(PB).second)
216 continue;
217 if (PB == BB)
218 continue;
219 for (MachineInstr &I : llvm::reverse(PB->instrs())) {
220 unsigned Opc = I.getOpcode();
221 if (Opc == LOOPi || Opc == LOOPr)
222 return &I;
223 // We've reached a different loop, which means the loop01 has been
224 // removed.
225 if (Opc == EndLoopOp && I.getOperand(0).getMBB() != TargetBB)
226 return nullptr;
227 }
228 // Check the predecessors for the LOOP instruction.
229 if (MachineInstr *Loop = findLoopInstr(PB, EndLoopOp, TargetBB, Visited))
230 return Loop;
231 }
232 return nullptr;
233}
234
235/// Gather register def/uses from MI.
236/// This treats possible (predicated) defs as actually happening ones
237/// (conservatively).
238static inline void parseOperands(const MachineInstr &MI,
240 Defs.clear();
241 Uses.clear();
242
243 for (const MachineOperand &MO : MI.operands()) {
244 if (!MO.isReg())
245 continue;
246
247 Register Reg = MO.getReg();
248 if (!Reg)
249 continue;
250
251 if (MO.isUse())
252 Uses.push_back(MO.getReg());
253
254 if (MO.isDef())
255 Defs.push_back(MO.getReg());
256 }
257}
258
259// Position dependent, so check twice for swap.
260static bool isDuplexPairMatch(unsigned Ga, unsigned Gb) {
261 switch (Ga) {
263 default:
264 return false;
266 return (Gb == HexagonII::HSIG_L1 || Gb == HexagonII::HSIG_A);
268 return (Gb == HexagonII::HSIG_L1 || Gb == HexagonII::HSIG_L2 ||
269 Gb == HexagonII::HSIG_A);
271 return (Gb == HexagonII::HSIG_L1 || Gb == HexagonII::HSIG_L2 ||
274 return (Gb == HexagonII::HSIG_L1 || Gb == HexagonII::HSIG_L2 ||
275 Gb == HexagonII::HSIG_S1 || Gb == HexagonII::HSIG_S2 ||
276 Gb == HexagonII::HSIG_A);
278 return (Gb == HexagonII::HSIG_A);
280 return (Gb == HexagonII::HSIG_Compound);
281 }
282 return false;
283}
284
285/// isLoadFromStackSlot - If the specified machine instruction is a direct
286/// load from a stack slot, return the virtual or physical register number of
287/// the destination along with the FrameIndex of the loaded stack slot. If
288/// not, return 0. This predicate must return 0 if the instruction has
289/// any side effects other than loading from the stack slot.
291 int &FrameIndex) const {
292 switch (MI.getOpcode()) {
293 default:
294 break;
295 case Hexagon::L2_loadri_io:
296 case Hexagon::L2_loadrd_io:
297 case Hexagon::V6_vL32b_ai:
298 case Hexagon::V6_vL32b_nt_ai:
299 case Hexagon::V6_vL32Ub_ai:
300 case Hexagon::LDriw_pred:
301 case Hexagon::LDriw_ctr:
302 case Hexagon::PS_vloadrq_ai:
303 case Hexagon::PS_vloadrw_ai:
304 case Hexagon::PS_vloadrw_nt_ai:
305 case Hexagon::PS_loadrl:
306 case Hexagon::PS_loadrll: {
307 const MachineOperand OpFI = MI.getOperand(1);
308 if (!OpFI.isFI())
309 return 0;
310 const MachineOperand OpOff = MI.getOperand(2);
311 if (!OpOff.isImm() || OpOff.getImm() != 0)
312 return 0;
313 FrameIndex = OpFI.getIndex();
314 return MI.getOperand(0).getReg();
315 }
316
317 case Hexagon::L2_ploadrit_io:
318 case Hexagon::L2_ploadrif_io:
319 case Hexagon::L2_ploadrdt_io:
320 case Hexagon::L2_ploadrdf_io: {
321 const MachineOperand OpFI = MI.getOperand(2);
322 if (!OpFI.isFI())
323 return 0;
324 const MachineOperand OpOff = MI.getOperand(3);
325 if (!OpOff.isImm() || OpOff.getImm() != 0)
326 return 0;
327 FrameIndex = OpFI.getIndex();
328 return MI.getOperand(0).getReg();
329 }
330 }
331
332 return 0;
333}
334
335/// isStoreToStackSlot - If the specified machine instruction is a direct
336/// store to a stack slot, return the virtual or physical register number of
337/// the source reg along with the FrameIndex of the loaded stack slot. If
338/// not, return 0. This predicate must return 0 if the instruction has
339/// any side effects other than storing to the stack slot.
341 int &FrameIndex) const {
342 switch (MI.getOpcode()) {
343 default:
344 break;
345 case Hexagon::S2_storerb_io:
346 case Hexagon::S2_storerh_io:
347 case Hexagon::S2_storeri_io:
348 case Hexagon::S2_storerd_io:
349 case Hexagon::V6_vS32b_ai:
350 case Hexagon::V6_vS32Ub_ai:
351 case Hexagon::STriw_pred:
352 case Hexagon::STriw_ctr:
353 case Hexagon::PS_vstorerq_ai:
354 case Hexagon::PS_vstorerw_ai:
355 case Hexagon::PS_storerl:
356 case Hexagon::PS_storerll: {
357 const MachineOperand &OpFI = MI.getOperand(0);
358 if (!OpFI.isFI())
359 return 0;
360 const MachineOperand &OpOff = MI.getOperand(1);
361 if (!OpOff.isImm() || OpOff.getImm() != 0)
362 return 0;
363 FrameIndex = OpFI.getIndex();
364 return MI.getOperand(2).getReg();
365 }
366
367 case Hexagon::S2_pstorerbt_io:
368 case Hexagon::S2_pstorerbf_io:
369 case Hexagon::S2_pstorerht_io:
370 case Hexagon::S2_pstorerhf_io:
371 case Hexagon::S2_pstorerit_io:
372 case Hexagon::S2_pstorerif_io:
373 case Hexagon::S2_pstorerdt_io:
374 case Hexagon::S2_pstorerdf_io: {
375 const MachineOperand &OpFI = MI.getOperand(1);
376 if (!OpFI.isFI())
377 return 0;
378 const MachineOperand &OpOff = MI.getOperand(2);
379 if (!OpOff.isImm() || OpOff.getImm() != 0)
380 return 0;
381 FrameIndex = OpFI.getIndex();
382 return MI.getOperand(3).getReg();
383 }
384 }
385
386 return 0;
387}
388
389/// This function checks if the instruction or bundle of instructions
390/// has load from stack slot and returns frameindex and machine memory
391/// operand of that instruction if true.
393 const MachineInstr &MI,
395 if (MI.isBundle()) {
396 const MachineBasicBlock *MBB = MI.getParent();
398 for (++MII; MII != MBB->instr_end() && MII->isInsideBundle(); ++MII)
400 return true;
401 return false;
402 }
403
405}
406
407/// This function checks if the instruction or bundle of instructions
408/// has store to stack slot and returns frameindex and machine memory
409/// operand of that instruction if true.
411 const MachineInstr &MI,
413 if (MI.isBundle()) {
414 const MachineBasicBlock *MBB = MI.getParent();
416 for (++MII; MII != MBB->instr_end() && MII->isInsideBundle(); ++MII)
418 return true;
419 return false;
420 }
421
423}
424
425/// This function can analyze one/two way branching only and should (mostly) be
426/// called by target independent side.
427/// First entry is always the opcode of the branching instruction, except when
428/// the Cond vector is supposed to be empty, e.g., when analyzeBranch fails, a
429/// BB with only unconditional jump. Subsequent entries depend upon the opcode,
430/// e.g. Jump_c p will have
431/// Cond[0] = Jump_c
432/// Cond[1] = p
433/// HW-loop ENDLOOP:
434/// Cond[0] = ENDLOOP
435/// Cond[1] = MBB
436/// New value jump:
437/// Cond[0] = Hexagon::CMPEQri_f_Jumpnv_t_V4 -- specific opcode
438/// Cond[1] = R
439/// Cond[2] = Imm
442 MachineBasicBlock *&FBB,
444 bool AllowModify) const {
445 TBB = nullptr;
446 FBB = nullptr;
447 Cond.clear();
448
449 // If the block has no terminators, it just falls into the block after it.
451 if (I == MBB.instr_begin())
452 return false;
453
454 // A basic block may looks like this:
455 //
456 // [ insn
457 // EH_LABEL
458 // insn
459 // insn
460 // insn
461 // EH_LABEL
462 // insn ]
463 //
464 // It has two succs but does not have a terminator
465 // Don't know how to handle it.
466 do {
467 --I;
468 if (I->isEHLabel())
469 // Don't analyze EH branches.
470 return true;
471 } while (I != MBB.instr_begin());
472
473 I = MBB.instr_end();
474 --I;
475
476 while (I->isDebugInstr()) {
477 if (I == MBB.instr_begin())
478 return false;
479 --I;
480 }
481
482 bool JumpToBlock = I->getOpcode() == Hexagon::J2_jump &&
483 I->getOperand(0).isMBB();
484 // Delete the J2_jump if it's equivalent to a fall-through.
485 if (AllowModify && JumpToBlock &&
486 MBB.isLayoutSuccessor(I->getOperand(0).getMBB())) {
487 LLVM_DEBUG(dbgs() << "\nErasing the jump to successor block\n";);
488 I->eraseFromParent();
489 I = MBB.instr_end();
490 if (I == MBB.instr_begin())
491 return false;
492 --I;
493 }
494 if (!isUnpredicatedTerminator(*I))
495 return false;
496
497 // Get the last instruction in the block.
498 MachineInstr *LastInst = &*I;
499 MachineInstr *SecondLastInst = nullptr;
500 // Find one more terminator if present.
501 while (true) {
502 if (&*I != LastInst && !I->isBundle() && isUnpredicatedTerminator(*I)) {
503 if (!SecondLastInst)
504 SecondLastInst = &*I;
505 else
506 // This is a third branch.
507 return true;
508 }
509 if (I == MBB.instr_begin())
510 break;
511 --I;
512 }
513
514 int LastOpcode = LastInst->getOpcode();
515 int SecLastOpcode = SecondLastInst ? SecondLastInst->getOpcode() : 0;
516 // If the branch target is not a basic block, it could be a tail call.
517 // (It is, if the target is a function.)
518 if (LastOpcode == Hexagon::J2_jump && !LastInst->getOperand(0).isMBB())
519 return true;
520 if (SecLastOpcode == Hexagon::J2_jump &&
521 !SecondLastInst->getOperand(0).isMBB())
522 return true;
523
524 bool LastOpcodeHasJMP_c = PredOpcodeHasJMP_c(LastOpcode);
525 bool LastOpcodeHasNVJump = isNewValueJump(*LastInst);
526
527 if (LastOpcodeHasJMP_c && !LastInst->getOperand(1).isMBB())
528 return true;
529
530 // If there is only one terminator instruction, process it.
531 if (LastInst && !SecondLastInst) {
532 if (LastOpcode == Hexagon::J2_jump) {
533 TBB = LastInst->getOperand(0).getMBB();
534 return false;
535 }
536 if (isEndLoopN(LastOpcode)) {
537 TBB = LastInst->getOperand(0).getMBB();
538 Cond.push_back(MachineOperand::CreateImm(LastInst->getOpcode()));
539 Cond.push_back(LastInst->getOperand(0));
540 return false;
541 }
542 if (LastOpcodeHasJMP_c) {
543 TBB = LastInst->getOperand(1).getMBB();
544 Cond.push_back(MachineOperand::CreateImm(LastInst->getOpcode()));
545 Cond.push_back(LastInst->getOperand(0));
546 return false;
547 }
548 // Only supporting rr/ri versions of new-value jumps.
549 if (LastOpcodeHasNVJump && (LastInst->getNumExplicitOperands() == 3)) {
550 TBB = LastInst->getOperand(2).getMBB();
551 Cond.push_back(MachineOperand::CreateImm(LastInst->getOpcode()));
552 Cond.push_back(LastInst->getOperand(0));
553 Cond.push_back(LastInst->getOperand(1));
554 return false;
555 }
556 LLVM_DEBUG(dbgs() << "\nCant analyze " << printMBBReference(MBB)
557 << " with one jump\n";);
558 // Otherwise, don't know what this is.
559 return true;
560 }
561
562 bool SecLastOpcodeHasJMP_c = PredOpcodeHasJMP_c(SecLastOpcode);
563 bool SecLastOpcodeHasNVJump = isNewValueJump(*SecondLastInst);
564 if (SecLastOpcodeHasJMP_c && (LastOpcode == Hexagon::J2_jump)) {
565 if (!SecondLastInst->getOperand(1).isMBB())
566 return true;
567 TBB = SecondLastInst->getOperand(1).getMBB();
568 Cond.push_back(MachineOperand::CreateImm(SecondLastInst->getOpcode()));
569 Cond.push_back(SecondLastInst->getOperand(0));
570 FBB = LastInst->getOperand(0).getMBB();
571 return false;
572 }
573
574 // Only supporting rr/ri versions of new-value jumps.
575 if (SecLastOpcodeHasNVJump &&
576 (SecondLastInst->getNumExplicitOperands() == 3) &&
577 (LastOpcode == Hexagon::J2_jump)) {
578 TBB = SecondLastInst->getOperand(2).getMBB();
579 Cond.push_back(MachineOperand::CreateImm(SecondLastInst->getOpcode()));
580 Cond.push_back(SecondLastInst->getOperand(0));
581 Cond.push_back(SecondLastInst->getOperand(1));
582 FBB = LastInst->getOperand(0).getMBB();
583 return false;
584 }
585
586 // If the block ends with two Hexagon:JMPs, handle it. The second one is not
587 // executed, so remove it.
588 if (SecLastOpcode == Hexagon::J2_jump && LastOpcode == Hexagon::J2_jump) {
589 TBB = SecondLastInst->getOperand(0).getMBB();
590 I = LastInst->getIterator();
591 if (AllowModify)
592 I->eraseFromParent();
593 return false;
594 }
595
596 // If the block ends with an ENDLOOP, and J2_jump, handle it.
597 if (isEndLoopN(SecLastOpcode) && LastOpcode == Hexagon::J2_jump) {
598 TBB = SecondLastInst->getOperand(0).getMBB();
599 Cond.push_back(MachineOperand::CreateImm(SecondLastInst->getOpcode()));
600 Cond.push_back(SecondLastInst->getOperand(0));
601 FBB = LastInst->getOperand(0).getMBB();
602 return false;
603 }
604 LLVM_DEBUG(dbgs() << "\nCant analyze " << printMBBReference(MBB)
605 << " with two jumps";);
606 // Otherwise, can't handle this.
607 return true;
608}
609
611 int *BytesRemoved) const {
612 assert(!BytesRemoved && "code size not handled");
613
614 LLVM_DEBUG(dbgs() << "\nRemoving branches out of " << printMBBReference(MBB));
616 unsigned Count = 0;
617 while (I != MBB.begin()) {
618 --I;
619 if (I->isDebugInstr())
620 continue;
621 // Only removing branches from end of MBB.
622 if (!I->isBranch())
623 return Count;
624 if (Count && (I->getOpcode() == Hexagon::J2_jump))
625 llvm_unreachable("Malformed basic block: unconditional branch not last");
626 MBB.erase(&MBB.back());
627 I = MBB.end();
628 ++Count;
629 }
630 return Count;
631}
632
637 const DebugLoc &DL,
638 int *BytesAdded) const {
639 unsigned BOpc = Hexagon::J2_jump;
640 unsigned BccOpc = Hexagon::J2_jumpt;
641 assert(validateBranchCond(Cond) && "Invalid branching condition");
642 assert(TBB && "insertBranch must not be told to insert a fallthrough");
643 assert(!BytesAdded && "code size not handled");
644
645 // Check if reverseBranchCondition has asked to reverse this branch
646 // If we want to reverse the branch an odd number of times, we want
647 // J2_jumpf.
648 if (!Cond.empty() && Cond[0].isImm())
649 BccOpc = Cond[0].getImm();
650
651 if (!FBB) {
652 if (Cond.empty()) {
653 // Due to a bug in TailMerging/CFG Optimization, we need to add a
654 // special case handling of a predicated jump followed by an
655 // unconditional jump. If not, Tail Merging and CFG Optimization go
656 // into an infinite loop.
657 MachineBasicBlock *NewTBB, *NewFBB;
659 auto Term = MBB.getFirstTerminator();
660 if (Term != MBB.end() && isPredicated(*Term) &&
661 !analyzeBranch(MBB, NewTBB, NewFBB, Cond, false) &&
662 MachineFunction::iterator(NewTBB) == ++MBB.getIterator()) {
665 return insertBranch(MBB, TBB, nullptr, Cond, DL);
666 }
667 BuildMI(&MBB, DL, get(BOpc)).addMBB(TBB);
668 } else if (isEndLoopN(Cond[0].getImm())) {
669 int EndLoopOp = Cond[0].getImm();
670 assert(Cond[1].isMBB());
671 // Since we're adding an ENDLOOP, there better be a LOOP instruction.
672 // Check for it, and change the BB target if needed.
674 MachineInstr *Loop = findLoopInstr(TBB, EndLoopOp, Cond[1].getMBB(),
675 VisitedBBs);
676 assert(Loop != nullptr && "Inserting an ENDLOOP without a LOOP");
677 Loop->getOperand(0).setMBB(TBB);
678 // Add the ENDLOOP after the finding the LOOP0.
679 BuildMI(&MBB, DL, get(EndLoopOp)).addMBB(TBB);
680 } else if (isNewValueJump(Cond[0].getImm())) {
681 assert((Cond.size() == 3) && "Only supporting rr/ri version of nvjump");
682 // New value jump
683 // (ins IntRegs:$src1, IntRegs:$src2, brtarget:$offset)
684 // (ins IntRegs:$src1, u5Imm:$src2, brtarget:$offset)
685 RegState Flags1 = getUndefRegState(Cond[1].isUndef());
686 LLVM_DEBUG(dbgs() << "\nInserting NVJump for "
688 if (Cond[2].isReg()) {
689 RegState Flags2 = getUndefRegState(Cond[2].isUndef());
690 BuildMI(&MBB, DL, get(BccOpc)).addReg(Cond[1].getReg(), Flags1).
691 addReg(Cond[2].getReg(), Flags2).addMBB(TBB);
692 } else if(Cond[2].isImm()) {
693 BuildMI(&MBB, DL, get(BccOpc)).addReg(Cond[1].getReg(), Flags1).
694 addImm(Cond[2].getImm()).addMBB(TBB);
695 } else
696 llvm_unreachable("Invalid condition for branching");
697 } else {
698 assert((Cond.size() == 2) && "Malformed cond vector");
699 const MachineOperand &RO = Cond[1];
700 RegState Flags = getUndefRegState(RO.isUndef());
701 BuildMI(&MBB, DL, get(BccOpc)).addReg(RO.getReg(), Flags).addMBB(TBB);
702 }
703 return 1;
704 }
705 assert((!Cond.empty()) &&
706 "Cond. cannot be empty when multiple branchings are required");
707 assert((!isNewValueJump(Cond[0].getImm())) &&
708 "NV-jump cannot be inserted with another branch");
709 // Special case for hardware loops. The condition is a basic block.
710 if (isEndLoopN(Cond[0].getImm())) {
711 int EndLoopOp = Cond[0].getImm();
712 assert(Cond[1].isMBB());
713 // Since we're adding an ENDLOOP, there better be a LOOP instruction.
714 // Check for it, and change the BB target if needed.
716 MachineInstr *Loop = findLoopInstr(TBB, EndLoopOp, Cond[1].getMBB(),
717 VisitedBBs);
718 assert(Loop != nullptr && "Inserting an ENDLOOP without a LOOP");
719 Loop->getOperand(0).setMBB(TBB);
720 // Add the ENDLOOP after the finding the LOOP0.
721 BuildMI(&MBB, DL, get(EndLoopOp)).addMBB(TBB);
722 } else {
723 const MachineOperand &RO = Cond[1];
724 RegState Flags = getUndefRegState(RO.isUndef());
725 BuildMI(&MBB, DL, get(BccOpc)).addReg(RO.getReg(), Flags).addMBB(TBB);
726 }
727 BuildMI(&MBB, DL, get(BOpc)).addMBB(FBB);
728
729 return 2;
730}
731
732namespace {
733class HexagonPipelinerLoopInfo : public TargetInstrInfo::PipelinerLoopInfo {
734 MachineInstr *Loop, *EndLoop;
735 MachineFunction *MF;
736 const HexagonInstrInfo *TII;
737 int64_t TripCount;
738 Register LoopCount;
739 DebugLoc DL;
740
741public:
742 HexagonPipelinerLoopInfo(MachineInstr *Loop, MachineInstr *EndLoop)
743 : Loop(Loop), EndLoop(EndLoop), MF(Loop->getParent()->getParent()),
744 TII(MF->getSubtarget<HexagonSubtarget>().getInstrInfo()),
745 DL(Loop->getDebugLoc()) {
746 // Inspect the Loop instruction up-front, as it may be deleted when we call
747 // createTripCountGreaterCondition.
748 TripCount = Loop->getOpcode() == Hexagon::J2_loop0r
749 ? -1
750 : Loop->getOperand(1).getImm();
751 if (TripCount == -1)
752 LoopCount = Loop->getOperand(1).getReg();
753 }
754
755 bool shouldIgnoreForPipelining(const MachineInstr *MI) const override {
756 // Only ignore the terminator.
757 return MI == EndLoop || TII->isHMXActivateInstr(*MI) ||
758 TII->isHMXWeightInstr(*MI);
759 }
760
761 std::optional<bool> createTripCountGreaterCondition(
762 int TC, MachineBasicBlock &MBB,
763 SmallVectorImpl<MachineOperand> &Cond) override {
764 if (TripCount == -1) {
765 // Check if we're done with the loop.
766 Register Done = TII->createVR(MF, MVT::i1);
767 MachineInstr *NewCmp = BuildMI(&MBB, DL,
768 TII->get(Hexagon::C2_cmpgtui), Done)
769 .addReg(LoopCount)
770 .addImm(TC);
771 Cond.push_back(MachineOperand::CreateImm(Hexagon::J2_jumpf));
772 Cond.push_back(NewCmp->getOperand(0));
773 return {};
774 }
775
776 return TripCount > TC;
777 }
778
779 void setPreheader(MachineBasicBlock *NewPreheader) override {
780 NewPreheader->splice(NewPreheader->getFirstTerminator(), Loop->getParent(),
781 Loop);
782 }
783
784 void adjustTripCount(int TripCountAdjust) override {
785 // If the loop trip count is a compile-time value, then just change the
786 // value.
787 if (Loop->getOpcode() == Hexagon::J2_loop0i ||
788 Loop->getOpcode() == Hexagon::J2_loop1i) {
789 int64_t TripCount = Loop->getOperand(1).getImm() + TripCountAdjust;
790 assert(TripCount > 0 && "Can't create an empty or negative loop!");
791 Loop->getOperand(1).setImm(TripCount);
792 return;
793 }
794
795 // The loop trip count is a run-time value. We generate code to subtract
796 // one from the trip count, and update the loop instruction.
797 Register LoopCount = Loop->getOperand(1).getReg();
798 Register NewLoopCount = TII->createVR(MF, MVT::i32);
799 BuildMI(*Loop->getParent(), Loop, Loop->getDebugLoc(),
800 TII->get(Hexagon::A2_addi), NewLoopCount)
801 .addReg(LoopCount)
802 .addImm(TripCountAdjust);
803 Loop->getOperand(1).setReg(NewLoopCount);
804 }
805
806 void disposed(LiveIntervals *LIS) override {
807 if (LIS)
809 Loop->eraseFromParent();
810 }
811};
812} // namespace
813
814std::unique_ptr<TargetInstrInfo::PipelinerLoopInfo>
816 // We really "analyze" only hardware loops right now.
818
819 if (I != LoopBB->end() && isEndLoopN(I->getOpcode())) {
821 MachineInstr *LoopInst = findLoopInstr(
822 LoopBB, I->getOpcode(), I->getOperand(0).getMBB(), VisitedBBs);
823 if (LoopInst)
824 return std::make_unique<HexagonPipelinerLoopInfo>(LoopInst, &*I);
825 }
826 return nullptr;
827}
828
830 unsigned NumCycles, unsigned ExtraPredCycles,
831 BranchProbability Probability) const {
832 return nonDbgBBSize(&MBB) <= 3;
833}
834
836 unsigned NumTCycles, unsigned ExtraTCycles, MachineBasicBlock &FMBB,
837 unsigned NumFCycles, unsigned ExtraFCycles, BranchProbability Probability)
838 const {
839 return nonDbgBBSize(&TMBB) <= 3 && nonDbgBBSize(&FMBB) <= 3;
840}
841
843 unsigned NumInstrs, BranchProbability Probability) const {
844 return NumInstrs <= 4;
845}
846
847static void getLiveInRegsAt(LivePhysRegs &Regs, const MachineInstr &MI) {
849 const MachineBasicBlock &B = *MI.getParent();
850 Regs.addLiveIns(B);
851 auto E = MachineBasicBlock::const_iterator(MI.getIterator());
852 for (auto I = B.begin(); I != E; ++I) {
853 Clobbers.clear();
854 Regs.stepForward(*I, Clobbers);
855 }
856}
857
858static void getLiveOutRegsAt(LivePhysRegs &Regs, const MachineInstr &MI) {
859 const MachineBasicBlock &B = *MI.getParent();
860 Regs.addLiveOuts(B);
861 auto E = ++MachineBasicBlock::const_iterator(MI.getIterator()).getReverse();
862 for (auto I = B.rbegin(); I != E; ++I)
863 Regs.stepBackward(*I);
864}
865
868 const DebugLoc &DL, Register DestReg,
869 Register SrcReg, bool KillSrc,
870 bool RenamableDest,
871 bool RenamableSrc) const {
872 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
873 RegState KillFlag = getKillRegState(KillSrc);
874
875 if (Hexagon::IntRegsRegClass.contains(SrcReg, DestReg)) {
876 BuildMI(MBB, I, DL, get(Hexagon::A2_tfr), DestReg)
877 .addReg(SrcReg, KillFlag);
878 return;
879 }
880 if (Hexagon::DoubleRegsRegClass.contains(SrcReg, DestReg)) {
881 BuildMI(MBB, I, DL, get(Hexagon::A2_tfrp), DestReg)
882 .addReg(SrcReg, KillFlag);
883 return;
884 }
885 if (Hexagon::PredRegsRegClass.contains(SrcReg, DestReg)) {
886 // Map Pd = Ps to Pd = or(Ps, Ps).
887 BuildMI(MBB, I, DL, get(Hexagon::C2_or), DestReg)
888 .addReg(SrcReg).addReg(SrcReg, KillFlag);
889 return;
890 }
891 if (Hexagon::CtrRegsRegClass.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::IntRegsRegClass.contains(DestReg) &&
898 Hexagon::CtrRegsRegClass.contains(SrcReg)) {
899 BuildMI(MBB, I, DL, get(Hexagon::A2_tfrcrr), DestReg)
900 .addReg(SrcReg, KillFlag);
901 return;
902 }
903 if (Hexagon::ModRegsRegClass.contains(DestReg) &&
904 Hexagon::IntRegsRegClass.contains(SrcReg)) {
905 BuildMI(MBB, I, DL, get(Hexagon::A2_tfrrcr), 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::IntRegsRegClass.contains(SrcReg) &&
916 Hexagon::PredRegsRegClass.contains(DestReg)) {
917 BuildMI(MBB, I, DL, get(Hexagon::C2_tfrrp), DestReg)
918 .addReg(SrcReg, KillFlag);
919 return;
920 }
921 if (Hexagon::PredRegsRegClass.contains(SrcReg) &&
922 Hexagon::IntRegsRegClass.contains(DestReg)) {
923 BuildMI(MBB, I, DL, get(Hexagon::C2_tfrpr), DestReg)
924 .addReg(SrcReg, KillFlag);
925 return;
926 }
927 if (Hexagon::HvxVRRegClass.contains(SrcReg, DestReg)) {
928 BuildMI(MBB, I, DL, get(Hexagon::V6_vassign), DestReg).
929 addReg(SrcReg, KillFlag);
930 return;
931 }
932 if (Hexagon::HvxWRRegClass.contains(SrcReg, DestReg)) {
933 LivePhysRegs LiveAtMI(HRI);
934 getLiveInRegsAt(LiveAtMI, *I);
935 Register SrcLo = HRI.getSubReg(SrcReg, Hexagon::vsub_lo);
936 Register SrcHi = HRI.getSubReg(SrcReg, Hexagon::vsub_hi);
937 RegState UndefLo = getUndefRegState(!LiveAtMI.contains(SrcLo));
938 RegState UndefHi = getUndefRegState(!LiveAtMI.contains(SrcHi));
939 BuildMI(MBB, I, DL, get(Hexagon::V6_vcombine), DestReg)
940 .addReg(SrcHi, KillFlag | UndefHi)
941 .addReg(SrcLo, KillFlag | UndefLo);
942 return;
943 }
944 if (Hexagon::HvxQRRegClass.contains(SrcReg, DestReg)) {
945 BuildMI(MBB, I, DL, get(Hexagon::V6_pred_and), DestReg)
946 .addReg(SrcReg)
947 .addReg(SrcReg, KillFlag);
948 return;
949 }
950 if (Hexagon::HvxQRRegClass.contains(SrcReg) &&
951 Hexagon::HvxVRRegClass.contains(DestReg)) {
952 llvm_unreachable("Unimplemented pred to vec");
953 return;
954 }
955 if (Hexagon::HvxQRRegClass.contains(DestReg) &&
956 Hexagon::HvxVRRegClass.contains(SrcReg)) {
957 llvm_unreachable("Unimplemented vec to pred");
958 return;
959 }
960 if (Hexagon::HlxLRRegClass.contains(SrcReg, DestReg)) {
961 BuildMI(MBB, I, DL, get(Hexagon::LX_assign), DestReg)
962 .addReg(SrcReg, KillFlag);
963 return;
964 }
965 if (Hexagon::HlxLLRRegClass.contains(SrcReg, DestReg)) {
966 BuildMI(MBB, I, DL, get(Hexagon::LX_assign_w), DestReg)
967 .addReg(SrcReg, KillFlag);
968 return;
969 }
970
971#ifndef NDEBUG
972 // Show the invalid registers to ease debugging.
973 dbgs() << "Invalid registers for copy in " << printMBBReference(MBB) << ": "
974 << printReg(DestReg, &HRI) << " = " << printReg(SrcReg, &HRI) << '\n';
975#endif
976 llvm_unreachable("Unimplemented");
977}
978
981 Register SrcReg, bool isKill, int FI,
982 const TargetRegisterClass *RC,
983 Register VReg,
984 MachineInstr::MIFlag Flags) const {
985 DebugLoc DL = MBB.findDebugLoc(I);
986 MachineFunction &MF = *MBB.getParent();
987 MachineFrameInfo &MFI = MF.getFrameInfo();
988 auto &HMFI = *MF.getInfo<HexagonMachineFunctionInfo>();
989 RegState KillFlag = getKillRegState(isKill);
990
991 int MFIIndex = FI;
992 MachineFrameInfo *MMFI = &MFI;
993 if (HMFI.isVTCMStackIndex(FI)) {
994 MFIIndex = HMFI.getMappedVTCMObjectIndex(FI);
995 MMFI = &HMFI.getVTCMFrameInfo();
996 }
999 MMFI->getObjectSize(MFIIndex), MMFI->getObjectAlign(MFIIndex));
1000
1001 if (Hexagon::IntRegsRegClass.hasSubClassEq(RC)) {
1002 BuildMI(MBB, I, DL, get(Hexagon::S2_storeri_io))
1003 .addFrameIndex(FI).addImm(0)
1004 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
1005 } else if (Hexagon::DoubleRegsRegClass.hasSubClassEq(RC)) {
1006 BuildMI(MBB, I, DL, get(Hexagon::S2_storerd_io))
1007 .addFrameIndex(FI).addImm(0)
1008 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
1009 } else if (Hexagon::PredRegsRegClass.hasSubClassEq(RC)) {
1010 BuildMI(MBB, I, DL, get(Hexagon::STriw_pred))
1011 .addFrameIndex(FI).addImm(0)
1012 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
1013 } else if (Hexagon::ModRegsRegClass.hasSubClassEq(RC)) {
1014 BuildMI(MBB, I, DL, get(Hexagon::STriw_ctr))
1015 .addFrameIndex(FI).addImm(0)
1016 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
1017 } else if (Hexagon::CircRegsRegClass.hasSubClassEq(RC)) {
1018 BuildMI(MBB, I, DL, get(Hexagon::STriw_circ))
1019 .addFrameIndex(FI)
1020 .addReg(SrcReg, KillFlag)
1021 .addMemOperand(MMO);
1022 } else if (Hexagon::HvxQRRegClass.hasSubClassEq(RC)) {
1023 BuildMI(MBB, I, DL, get(Hexagon::PS_vstorerq_ai))
1024 .addFrameIndex(FI).addImm(0)
1025 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
1026 } else if (Hexagon::HvxVRRegClass.hasSubClassEq(RC)) {
1027 BuildMI(MBB, I, DL, get(Hexagon::PS_vstorerv_ai))
1028 .addFrameIndex(FI).addImm(0)
1029 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
1030 } else if (Hexagon::HvxWRRegClass.hasSubClassEq(RC)) {
1031 BuildMI(MBB, I, DL, get(Hexagon::PS_vstorerw_ai))
1032 .addFrameIndex(FI).addImm(0)
1033 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
1034 } else if (Hexagon::HlxLRRegClass.hasSubClassEq(RC)) {
1035 BuildMI(MBB, I, DL, get(Hexagon::PS_storerl))
1036 .addFrameIndex(FI)
1037 .addImm(0)
1038 .addReg(SrcReg, KillFlag)
1039 .addMemOperand(MMO);
1040 } else if (Hexagon::HlxLLRRegClass.hasSubClassEq(RC)) {
1041 BuildMI(MBB, I, DL, get(Hexagon::PS_storerll))
1042 .addFrameIndex(FI)
1043 .addImm(0)
1044 .addReg(SrcReg, KillFlag)
1045 .addMemOperand(MMO);
1046 } else {
1047 llvm_unreachable("Unimplemented");
1048 }
1049}
1050
1053 Register DestReg, int FI,
1054 const TargetRegisterClass *RC,
1055 Register VReg, unsigned SubReg,
1056 MachineInstr::MIFlag Flags) const {
1057 DebugLoc DL = MBB.findDebugLoc(I);
1058 MachineFunction &MF = *MBB.getParent();
1059 MachineFrameInfo &MFI = MF.getFrameInfo();
1060 auto &HMFI = *MF.getInfo<HexagonMachineFunctionInfo>();
1061
1062 int MFIIndex = FI;
1063 MachineFrameInfo *MMFI = &MFI;
1064 if (HMFI.isVTCMStackIndex(FI)) {
1065 MFIIndex = HMFI.getMappedVTCMObjectIndex(FI);
1066 MMFI = &HMFI.getVTCMFrameInfo();
1067 }
1070 MMFI->getObjectSize(MFIIndex), MMFI->getObjectAlign(MFIIndex));
1071
1072 if (Hexagon::IntRegsRegClass.hasSubClassEq(RC)) {
1073 BuildMI(MBB, I, DL, get(Hexagon::L2_loadri_io), DestReg)
1074 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
1075 } else if (Hexagon::DoubleRegsRegClass.hasSubClassEq(RC)) {
1076 BuildMI(MBB, I, DL, get(Hexagon::L2_loadrd_io), DestReg)
1077 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
1078 } else if (Hexagon::PredRegsRegClass.hasSubClassEq(RC)) {
1079 BuildMI(MBB, I, DL, get(Hexagon::LDriw_pred), DestReg)
1080 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
1081 } else if (Hexagon::ModRegsRegClass.hasSubClassEq(RC)) {
1082 BuildMI(MBB, I, DL, get(Hexagon::LDriw_ctr), DestReg)
1083 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
1084 } else if (Hexagon::CircRegsRegClass.hasSubClassEq(RC)) {
1085 BuildMI(MBB, I, DL, get(Hexagon::LDriw_circ), DestReg)
1086 .addFrameIndex(FI)
1087 .addMemOperand(MMO);
1088 } else if (Hexagon::HvxQRRegClass.hasSubClassEq(RC)) {
1089 BuildMI(MBB, I, DL, get(Hexagon::PS_vloadrq_ai), DestReg)
1090 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
1091 } else if (Hexagon::HvxVRRegClass.hasSubClassEq(RC)) {
1092 BuildMI(MBB, I, DL, get(Hexagon::PS_vloadrv_ai), DestReg)
1093 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
1094 } else if (Hexagon::HvxWRRegClass.hasSubClassEq(RC)) {
1095 BuildMI(MBB, I, DL, get(Hexagon::PS_vloadrw_ai), DestReg)
1096 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
1097 } else if (Hexagon::HlxLRRegClass.hasSubClassEq(RC)) {
1098 BuildMI(MBB, I, DL, get(Hexagon::PS_loadrl), DestReg)
1099 .addFrameIndex(FI)
1100 .addImm(0)
1101 .addMemOperand(MMO);
1102 } else if (Hexagon::HlxLLRRegClass.hasSubClassEq(RC)) {
1103 BuildMI(MBB, I, DL, get(Hexagon::PS_loadrll), DestReg)
1104 .addFrameIndex(FI)
1105 .addImm(0)
1106 .addMemOperand(MMO);
1107 } else {
1108 llvm_unreachable("Can't store this register to stack slot");
1109 }
1110}
1111
1112/// expandPostRAPseudo - This function is called for all pseudo instructions
1113/// that remain after register allocation. Many pseudo instructions are
1114/// created to help register allocation. This is the place to convert them
1115/// into real instructions. The target can edit MI in place, or it can insert
1116/// new instructions and erase MI. The function should return true if
1117/// anything was changed.
1119 MachineBasicBlock &MBB = *MI.getParent();
1120 MachineFunction &MF = *MBB.getParent();
1122 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
1123 LivePhysRegs LiveIn(HRI), LiveOut(HRI);
1124 DebugLoc DL = MI.getDebugLoc();
1125 unsigned Opc = MI.getOpcode();
1126
1127 auto RealCirc = [&](unsigned Opc, bool HasImm, unsigned MxOp) {
1128 Register M_CSx = MI.getOperand(MxOp).getReg();
1129 Register Mx = HRI.getSubReg(M_CSx, Hexagon::isub_hi);
1130 unsigned CSOp = HasImm ? 5 : 4;
1131 auto MIB = BuildMI(MBB, MI, DL, get(Opc));
1132 for (unsigned i = 0; i != CSOp; ++i)
1133 if (i == MxOp)
1134 MIB.addReg(Mx);
1135 else
1136 MIB.add(MI.getOperand(i));
1137 Register CSx = (M_CSx == Hexagon::CS_M0 ? Hexagon::CS0 : Hexagon::CS1);
1138 MIB.addReg(CSx, RegState::Implicit);
1139 MBB.erase(MI);
1140 return true;
1141 };
1142
1143 auto UseAligned = [&](const MachineInstr &MI, Align NeedAlign) {
1144 if (MI.memoperands().empty())
1145 return false;
1146 return all_of(MI.memoperands(), [NeedAlign](const MachineMemOperand *MMO) {
1147 return MMO->getAlign() >= NeedAlign;
1148 });
1149 };
1150
1151 switch (Opc) {
1152 case Hexagon::PS_call_instrprof_custom: {
1153 auto Op0 = MI.getOperand(0);
1154 assert(Op0.isGlobal() &&
1155 "First operand must be a global containing handler name.");
1156 const GlobalValue *NameVar = Op0.getGlobal();
1157 const GlobalVariable *GV = dyn_cast<GlobalVariable>(NameVar);
1158 auto *Arr = cast<ConstantDataArray>(GV->getInitializer());
1159 StringRef NameStr = Arr->isCString() ? Arr->getAsCString() : Arr->getAsString();
1160
1161 MachineOperand &Op1 = MI.getOperand(1);
1162 // Set R0 with the imm value to be passed to the custom profiling handler.
1163 BuildMI(MBB, MI, DL, get(Hexagon::A2_tfrsi), Hexagon::R0)
1164 .addImm(Op1.getImm());
1165 // The call to the custom handler is being treated as a special one as the
1166 // callee is responsible for saving and restoring all the registers
1167 // (including caller saved registers) it needs to modify. This is
1168 // done to reduce the impact of instrumentation on the code being
1169 // instrumented/profiled.
1170 // NOTE: R14, R15 and R28 are reserved for PLT handling. These registers
1171 // are in the Def list of the Hexagon::PS_call_instrprof_custom and
1172 // therefore will be handled appropriately duing register allocation.
1173
1174 // TODO: It may be a good idea to add a separate pseudo instruction for
1175 // static relocation which doesn't need to reserve r14, r15 and r28.
1176
1177 auto MIB = BuildMI(MBB, MI, DL, get(Hexagon::J2_call))
1178 .addUse(Hexagon::R0, RegState::Implicit)
1179 .addDef(Hexagon::R29, RegState::ImplicitDefine)
1180 .addDef(Hexagon::R30, RegState::ImplicitDefine)
1181 .addDef(Hexagon::R14, RegState::ImplicitDefine)
1182 .addDef(Hexagon::R15, RegState::ImplicitDefine)
1183 .addDef(Hexagon::R28, RegState::ImplicitDefine);
1184 const char *cstr = MF.createExternalSymbolName(NameStr);
1185 MIB.addExternalSymbol(cstr);
1186 MBB.erase(MI);
1187 return true;
1188 }
1189 case TargetOpcode::COPY: {
1190 MachineOperand &MD = MI.getOperand(0);
1191 MachineOperand &MS = MI.getOperand(1);
1192 MachineBasicBlock::iterator MBBI = MI.getIterator();
1193 if (MD.getReg() != MS.getReg() && !MS.isUndef()) {
1194 copyPhysReg(MBB, MI, DL, MD.getReg(), MS.getReg(), MS.isKill());
1195 std::prev(MBBI)->copyImplicitOps(*MBB.getParent(), MI);
1196 }
1197 MBB.erase(MBBI);
1198 return true;
1199 }
1200 case Hexagon::PS_aligna:
1201 BuildMI(MBB, MI, DL, get(Hexagon::A2_andir), MI.getOperand(0).getReg())
1202 .addReg(HRI.getFrameRegister())
1203 .addImm(-MI.getOperand(1).getImm());
1204 MBB.erase(MI);
1205 return true;
1206 case Hexagon::V6_vassignp: {
1207 Register SrcReg = MI.getOperand(1).getReg();
1208 Register DstReg = MI.getOperand(0).getReg();
1209 Register SrcLo = HRI.getSubReg(SrcReg, Hexagon::vsub_lo);
1210 Register SrcHi = HRI.getSubReg(SrcReg, Hexagon::vsub_hi);
1211 getLiveInRegsAt(LiveIn, MI);
1212 RegState UndefLo = getUndefRegState(!LiveIn.contains(SrcLo));
1213 RegState UndefHi = getUndefRegState(!LiveIn.contains(SrcHi));
1214 RegState Kill = getKillRegState(MI.getOperand(1).isKill());
1215 BuildMI(MBB, MI, DL, get(Hexagon::V6_vcombine), DstReg)
1216 .addReg(SrcHi, UndefHi)
1217 .addReg(SrcLo, Kill | UndefLo);
1218 MBB.erase(MI);
1219 return true;
1220 }
1221 case Hexagon::V6_lo:
1222 case Hexagon::LX_lo: {
1223 Register SrcReg = MI.getOperand(1).getReg();
1224 Register DstReg = MI.getOperand(0).getReg();
1225 Register SrcSubLo = HRI.getSubReg(SrcReg, Hexagon::vsub_lo);
1226 copyPhysReg(MBB, MI, DL, DstReg, SrcSubLo, MI.getOperand(1).isKill());
1227 MBB.erase(MI);
1228 return true;
1229 }
1230 case Hexagon::V6_hi:
1231 case Hexagon::LX_hi: {
1232 Register SrcReg = MI.getOperand(1).getReg();
1233 Register DstReg = MI.getOperand(0).getReg();
1234 Register SrcSubHi = HRI.getSubReg(SrcReg, Hexagon::vsub_hi);
1235 copyPhysReg(MBB, MI, DL, DstReg, SrcSubHi, MI.getOperand(1).isKill());
1236 MBB.erase(MI);
1237 return true;
1238 }
1239 case Hexagon::PS_vloadrv_ai: {
1240 Register DstReg = MI.getOperand(0).getReg();
1241 const MachineOperand &BaseOp = MI.getOperand(1);
1242 assert(BaseOp.getSubReg() == 0);
1243 int Offset = MI.getOperand(2).getImm();
1244 Align NeedAlign = HRI.getSpillAlign(Hexagon::HvxVRRegClass);
1245 unsigned NewOpc = UseAligned(MI, NeedAlign) ? Hexagon::V6_vL32b_ai
1246 : Hexagon::V6_vL32Ub_ai;
1247 BuildMI(MBB, MI, DL, get(NewOpc), DstReg)
1248 .addReg(BaseOp.getReg(), getRegState(BaseOp))
1249 .addImm(Offset)
1250 .cloneMemRefs(MI);
1251 MBB.erase(MI);
1252 return true;
1253 }
1254 case Hexagon::PS_loadrl: {
1255 Register DstReg = MI.getOperand(0).getReg();
1256 const MachineOperand &BaseOp = MI.getOperand(1);
1257 assert(BaseOp.getSubReg() == 0);
1258 int Offset = MI.getOperand(2).getImm();
1259 Register BaseReg = BaseOp.getReg();
1260 BuildMI(MBB, MI, DL, get(Hexagon::A2_addi), BaseReg)
1261 .addReg(BaseReg, getRegState(BaseOp) | RegState::Kill)
1262 .addImm(Offset);
1263 BuildMI(MBB, MI, DL, get(Hexagon::LX_L16b_pseudo), DstReg)
1264 .addReg(BaseReg, getRegState(BaseOp))
1265 .addReg(Hexagon::VSP, RegState::Implicit)
1266 .cloneMemRefs(MI);
1267 MBB.erase(MI);
1268 return true;
1269 }
1270 case Hexagon::PS_vloadrw_ai: {
1271 Register DstReg = MI.getOperand(0).getReg();
1272 const MachineOperand &BaseOp = MI.getOperand(1);
1273 assert(BaseOp.getSubReg() == 0);
1274 int Offset = MI.getOperand(2).getImm();
1275 unsigned VecOffset = HRI.getSpillSize(Hexagon::HvxVRRegClass);
1276 Align NeedAlign = HRI.getSpillAlign(Hexagon::HvxVRRegClass);
1277 unsigned NewOpc = UseAligned(MI, NeedAlign) ? Hexagon::V6_vL32b_ai
1278 : Hexagon::V6_vL32Ub_ai;
1279 BuildMI(MBB, MI, DL, get(NewOpc),
1280 HRI.getSubReg(DstReg, Hexagon::vsub_lo))
1281 .addReg(BaseOp.getReg(), getRegState(BaseOp) & ~RegState::Kill)
1282 .addImm(Offset)
1283 .cloneMemRefs(MI);
1284 BuildMI(MBB, MI, DL, get(NewOpc),
1285 HRI.getSubReg(DstReg, Hexagon::vsub_hi))
1286 .addReg(BaseOp.getReg(), getRegState(BaseOp))
1287 .addImm(Offset + VecOffset)
1288 .cloneMemRefs(MI);
1289 MBB.erase(MI);
1290 return true;
1291 }
1292 case Hexagon::PS_vstorerv_ai: {
1293 const MachineOperand &SrcOp = MI.getOperand(2);
1294 assert(SrcOp.getSubReg() == 0);
1295 const MachineOperand &BaseOp = MI.getOperand(0);
1296 assert(BaseOp.getSubReg() == 0);
1297 int Offset = MI.getOperand(1).getImm();
1298 Align NeedAlign = HRI.getSpillAlign(Hexagon::HvxVRRegClass);
1299 unsigned NewOpc = UseAligned(MI, NeedAlign) ? Hexagon::V6_vS32b_ai
1300 : Hexagon::V6_vS32Ub_ai;
1301 BuildMI(MBB, MI, DL, get(NewOpc))
1302 .addReg(BaseOp.getReg(), getRegState(BaseOp))
1303 .addImm(Offset)
1305 .cloneMemRefs(MI);
1306 MBB.erase(MI);
1307 return true;
1308 }
1309 case Hexagon::PS_storerl: {
1310 const MachineOperand &SrcOp = MI.getOperand(2);
1311 assert(SrcOp.getSubReg() == 0);
1312 const MachineOperand &BaseOp = MI.getOperand(0);
1313 assert(BaseOp.getSubReg() == 0);
1314 Register BaseReg = BaseOp.getReg();
1315 int Offset = MI.getOperand(1).getImm();
1316 BuildMI(MBB, MI, DL, get(Hexagon::A2_addi), BaseReg)
1317 .addReg(BaseReg, getRegState(BaseOp) | RegState::Kill)
1318 .addImm(Offset);
1319 BuildMI(MBB, MI, DL, get(Hexagon::LX_S16b_pseudo))
1320 .addReg(BaseReg, getRegState(BaseOp))
1322 .addReg(Hexagon::VSP, RegState::Implicit)
1323 .cloneMemRefs(MI);
1324 MBB.erase(MI);
1325 return true;
1326 }
1327 case Hexagon::PS_vstorerw_ai: {
1328 Register SrcReg = MI.getOperand(2).getReg();
1329 const MachineOperand &BaseOp = MI.getOperand(0);
1330 assert(BaseOp.getSubReg() == 0);
1331 int Offset = MI.getOperand(1).getImm();
1332 unsigned VecOffset = HRI.getSpillSize(Hexagon::HvxVRRegClass);
1333 Align NeedAlign = HRI.getSpillAlign(Hexagon::HvxVRRegClass);
1334 unsigned NewOpc = UseAligned(MI, NeedAlign) ? Hexagon::V6_vS32b_ai
1335 : Hexagon::V6_vS32Ub_ai;
1336 BuildMI(MBB, MI, DL, get(NewOpc))
1337 .addReg(BaseOp.getReg(), getRegState(BaseOp) & ~RegState::Kill)
1338 .addImm(Offset)
1339 .addReg(HRI.getSubReg(SrcReg, Hexagon::vsub_lo))
1340 .cloneMemRefs(MI);
1341 BuildMI(MBB, MI, DL, get(NewOpc))
1342 .addReg(BaseOp.getReg(), getRegState(BaseOp))
1343 .addImm(Offset + VecOffset)
1344 .addReg(HRI.getSubReg(SrcReg, Hexagon::vsub_hi))
1345 .cloneMemRefs(MI);
1346 MBB.erase(MI);
1347 return true;
1348 }
1349 case Hexagon::PS_true: {
1350 Register Reg = MI.getOperand(0).getReg();
1351 BuildMI(MBB, MI, DL, get(Hexagon::C2_orn), Reg)
1352 .addReg(Reg, RegState::Undef)
1353 .addReg(Reg, RegState::Undef);
1354 MBB.erase(MI);
1355 return true;
1356 }
1357 case Hexagon::PS_false: {
1358 Register Reg = MI.getOperand(0).getReg();
1359 BuildMI(MBB, MI, DL, get(Hexagon::C2_andn), Reg)
1360 .addReg(Reg, RegState::Undef)
1361 .addReg(Reg, RegState::Undef);
1362 MBB.erase(MI);
1363 return true;
1364 }
1365 case Hexagon::PS_qtrue: {
1366 BuildMI(MBB, MI, DL, get(Hexagon::V6_veqw), MI.getOperand(0).getReg())
1367 .addReg(Hexagon::V0, RegState::Undef)
1368 .addReg(Hexagon::V0, RegState::Undef);
1369 MBB.erase(MI);
1370 return true;
1371 }
1372 case Hexagon::PS_qfalse: {
1373 BuildMI(MBB, MI, DL, get(Hexagon::V6_vgtw), MI.getOperand(0).getReg())
1374 .addReg(Hexagon::V0, RegState::Undef)
1375 .addReg(Hexagon::V0, RegState::Undef);
1376 MBB.erase(MI);
1377 return true;
1378 }
1379 case Hexagon::PS_vdd0: {
1380 Register Vd = MI.getOperand(0).getReg();
1381 BuildMI(MBB, MI, DL, get(Hexagon::V6_vsubw_dv), Vd)
1383 .addReg(Vd, RegState::Undef);
1384 MBB.erase(MI);
1385 return true;
1386 }
1387 case Hexagon::PS_vmulw: {
1388 // Expand a 64-bit vector multiply into 2 32-bit scalar multiplies.
1389 Register DstReg = MI.getOperand(0).getReg();
1390 Register Src1Reg = MI.getOperand(1).getReg();
1391 Register Src2Reg = MI.getOperand(2).getReg();
1392 Register Src1SubHi = HRI.getSubReg(Src1Reg, Hexagon::isub_hi);
1393 Register Src1SubLo = HRI.getSubReg(Src1Reg, Hexagon::isub_lo);
1394 Register Src2SubHi = HRI.getSubReg(Src2Reg, Hexagon::isub_hi);
1395 Register Src2SubLo = HRI.getSubReg(Src2Reg, Hexagon::isub_lo);
1396 BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::M2_mpyi),
1397 HRI.getSubReg(DstReg, Hexagon::isub_hi))
1398 .addReg(Src1SubHi)
1399 .addReg(Src2SubHi);
1400 BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::M2_mpyi),
1401 HRI.getSubReg(DstReg, Hexagon::isub_lo))
1402 .addReg(Src1SubLo)
1403 .addReg(Src2SubLo);
1404 MBB.erase(MI);
1405 return true;
1406 }
1407 case Hexagon::PS_vmulw_acc: {
1408 // Expand 64-bit vector multiply with addition into 2 scalar multiplies.
1409 Register DstReg = MI.getOperand(0).getReg();
1410 Register Src1Reg = MI.getOperand(1).getReg();
1411 Register Src2Reg = MI.getOperand(2).getReg();
1412 Register Src3Reg = MI.getOperand(3).getReg();
1413 Register Src1SubHi = HRI.getSubReg(Src1Reg, Hexagon::isub_hi);
1414 Register Src1SubLo = HRI.getSubReg(Src1Reg, Hexagon::isub_lo);
1415 Register Src2SubHi = HRI.getSubReg(Src2Reg, Hexagon::isub_hi);
1416 Register Src2SubLo = HRI.getSubReg(Src2Reg, Hexagon::isub_lo);
1417 Register Src3SubHi = HRI.getSubReg(Src3Reg, Hexagon::isub_hi);
1418 Register Src3SubLo = HRI.getSubReg(Src3Reg, Hexagon::isub_lo);
1419 BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::M2_maci),
1420 HRI.getSubReg(DstReg, Hexagon::isub_hi))
1421 .addReg(Src1SubHi)
1422 .addReg(Src2SubHi)
1423 .addReg(Src3SubHi);
1424 BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::M2_maci),
1425 HRI.getSubReg(DstReg, Hexagon::isub_lo))
1426 .addReg(Src1SubLo)
1427 .addReg(Src2SubLo)
1428 .addReg(Src3SubLo);
1429 MBB.erase(MI);
1430 return true;
1431 }
1432 case Hexagon::PS_pselect: {
1433 const MachineOperand &Op0 = MI.getOperand(0);
1434 const MachineOperand &Op1 = MI.getOperand(1);
1435 const MachineOperand &Op2 = MI.getOperand(2);
1436 const MachineOperand &Op3 = MI.getOperand(3);
1437 Register Rd = Op0.getReg();
1438 Register Pu = Op1.getReg();
1439 Register Rs = Op2.getReg();
1440 Register Rt = Op3.getReg();
1441 DebugLoc DL = MI.getDebugLoc();
1442 RegState K1 = getKillRegState(Op1.isKill());
1443 RegState K2 = getKillRegState(Op2.isKill());
1444 RegState K3 = getKillRegState(Op3.isKill());
1445 if (Rd != Rs)
1446 BuildMI(MBB, MI, DL, get(Hexagon::A2_tfrpt), Rd)
1447 .addReg(Pu, (Rd == Rt) ? K1 : RegState::NoFlags)
1448 .addReg(Rs, K2);
1449 if (Rd != Rt)
1450 BuildMI(MBB, MI, DL, get(Hexagon::A2_tfrpf), Rd)
1451 .addReg(Pu, K1)
1452 .addReg(Rt, K3);
1453 MBB.erase(MI);
1454 return true;
1455 }
1456 case Hexagon::PS_vselect: {
1457 const MachineOperand &Op0 = MI.getOperand(0);
1458 const MachineOperand &Op1 = MI.getOperand(1);
1459 const MachineOperand &Op2 = MI.getOperand(2);
1460 const MachineOperand &Op3 = MI.getOperand(3);
1461 getLiveOutRegsAt(LiveOut, MI);
1462 bool IsDestLive = !LiveOut.available(MRI, Op0.getReg());
1463 Register PReg = Op1.getReg();
1464 assert(Op1.getSubReg() == 0);
1465 RegState PState = getRegState(Op1);
1466
1467 if (Op0.getReg() != Op2.getReg()) {
1468 RegState S =
1469 Op0.getReg() != Op3.getReg() ? PState & ~RegState::Kill : PState;
1470 auto T = BuildMI(MBB, MI, DL, get(Hexagon::V6_vcmov))
1471 .add(Op0)
1472 .addReg(PReg, S)
1473 .add(Op2);
1474 if (IsDestLive)
1475 T.addReg(Op0.getReg(), RegState::Implicit);
1476 IsDestLive = true;
1477 }
1478 if (Op0.getReg() != Op3.getReg()) {
1479 auto T = BuildMI(MBB, MI, DL, get(Hexagon::V6_vncmov))
1480 .add(Op0)
1481 .addReg(PReg, PState)
1482 .add(Op3);
1483 if (IsDestLive)
1484 T.addReg(Op0.getReg(), RegState::Implicit);
1485 }
1486 MBB.erase(MI);
1487 return true;
1488 }
1489 case Hexagon::PS_wselect: {
1490 MachineOperand &Op0 = MI.getOperand(0);
1491 MachineOperand &Op1 = MI.getOperand(1);
1492 MachineOperand &Op2 = MI.getOperand(2);
1493 MachineOperand &Op3 = MI.getOperand(3);
1494 getLiveOutRegsAt(LiveOut, MI);
1495 bool IsDestLive = !LiveOut.available(MRI, Op0.getReg());
1496 Register PReg = Op1.getReg();
1497 assert(Op1.getSubReg() == 0);
1498 RegState PState = getRegState(Op1);
1499
1500 if (Op0.getReg() != Op2.getReg()) {
1501 RegState S =
1502 Op0.getReg() != Op3.getReg() ? PState & ~RegState::Kill : PState;
1503 Register SrcLo = HRI.getSubReg(Op2.getReg(), Hexagon::vsub_lo);
1504 Register SrcHi = HRI.getSubReg(Op2.getReg(), Hexagon::vsub_hi);
1505 auto T = BuildMI(MBB, MI, DL, get(Hexagon::V6_vccombine))
1506 .add(Op0)
1507 .addReg(PReg, S)
1508 .addReg(SrcHi)
1509 .addReg(SrcLo);
1510 if (IsDestLive)
1511 T.addReg(Op0.getReg(), RegState::Implicit);
1512 IsDestLive = true;
1513 }
1514 if (Op0.getReg() != Op3.getReg()) {
1515 Register SrcLo = HRI.getSubReg(Op3.getReg(), Hexagon::vsub_lo);
1516 Register SrcHi = HRI.getSubReg(Op3.getReg(), Hexagon::vsub_hi);
1517 auto T = BuildMI(MBB, MI, DL, get(Hexagon::V6_vnccombine))
1518 .add(Op0)
1519 .addReg(PReg, PState)
1520 .addReg(SrcHi)
1521 .addReg(SrcLo);
1522 if (IsDestLive)
1523 T.addReg(Op0.getReg(), RegState::Implicit);
1524 }
1525 MBB.erase(MI);
1526 return true;
1527 }
1528
1529 case Hexagon::PS_crash: {
1530 // Generate a misaligned load that is guaranteed to cause a crash.
1531 class CrashPseudoSourceValue : public PseudoSourceValue {
1532 public:
1533 CrashPseudoSourceValue(const TargetMachine &TM)
1534 : PseudoSourceValue(TargetCustom, TM) {}
1535
1536 bool isConstant(const MachineFrameInfo *) const override {
1537 return false;
1538 }
1539 bool isAliased(const MachineFrameInfo *) const override {
1540 return false;
1541 }
1542 bool mayAlias(const MachineFrameInfo *) const override {
1543 return false;
1544 }
1545 void printCustom(raw_ostream &OS) const override {
1546 OS << "MisalignedCrash";
1547 }
1548 };
1549
1550 static const CrashPseudoSourceValue CrashPSV(MF.getTarget());
1552 MachinePointerInfo(&CrashPSV),
1554 Align(1));
1555 BuildMI(MBB, MI, DL, get(Hexagon::PS_loadrdabs), Hexagon::D13)
1556 .addImm(0xBADC0FEE) // Misaligned load.
1557 .addMemOperand(MMO);
1558 MBB.erase(MI);
1559 return true;
1560 }
1561
1562 case Hexagon::PS_tailcall_i:
1563 MI.setDesc(get(Hexagon::J2_jump));
1564 return true;
1565 case Hexagon::PS_tailcall_r:
1566 case Hexagon::PS_jmpret:
1567 MI.setDesc(get(Hexagon::J2_jumpr));
1568 return true;
1569 case Hexagon::PS_jmprett:
1570 MI.setDesc(get(Hexagon::J2_jumprt));
1571 return true;
1572 case Hexagon::PS_jmpretf:
1573 MI.setDesc(get(Hexagon::J2_jumprf));
1574 return true;
1575 case Hexagon::PS_jmprettnewpt:
1576 MI.setDesc(get(Hexagon::J2_jumprtnewpt));
1577 return true;
1578 case Hexagon::PS_jmpretfnewpt:
1579 MI.setDesc(get(Hexagon::J2_jumprfnewpt));
1580 return true;
1581 case Hexagon::PS_jmprettnew:
1582 MI.setDesc(get(Hexagon::J2_jumprtnew));
1583 return true;
1584 case Hexagon::PS_jmpretfnew:
1585 MI.setDesc(get(Hexagon::J2_jumprfnew));
1586 return true;
1587
1588 case Hexagon::PS_loadrub_pci:
1589 return RealCirc(Hexagon::L2_loadrub_pci, /*HasImm*/true, /*MxOp*/4);
1590 case Hexagon::PS_loadrb_pci:
1591 return RealCirc(Hexagon::L2_loadrb_pci, /*HasImm*/true, /*MxOp*/4);
1592 case Hexagon::PS_loadruh_pci:
1593 return RealCirc(Hexagon::L2_loadruh_pci, /*HasImm*/true, /*MxOp*/4);
1594 case Hexagon::PS_loadrh_pci:
1595 return RealCirc(Hexagon::L2_loadrh_pci, /*HasImm*/true, /*MxOp*/4);
1596 case Hexagon::PS_loadri_pci:
1597 return RealCirc(Hexagon::L2_loadri_pci, /*HasImm*/true, /*MxOp*/4);
1598 case Hexagon::PS_loadrd_pci:
1599 return RealCirc(Hexagon::L2_loadrd_pci, /*HasImm*/true, /*MxOp*/4);
1600 case Hexagon::PS_loadrub_pcr:
1601 return RealCirc(Hexagon::L2_loadrub_pcr, /*HasImm*/false, /*MxOp*/3);
1602 case Hexagon::PS_loadrb_pcr:
1603 return RealCirc(Hexagon::L2_loadrb_pcr, /*HasImm*/false, /*MxOp*/3);
1604 case Hexagon::PS_loadruh_pcr:
1605 return RealCirc(Hexagon::L2_loadruh_pcr, /*HasImm*/false, /*MxOp*/3);
1606 case Hexagon::PS_loadrh_pcr:
1607 return RealCirc(Hexagon::L2_loadrh_pcr, /*HasImm*/false, /*MxOp*/3);
1608 case Hexagon::PS_loadri_pcr:
1609 return RealCirc(Hexagon::L2_loadri_pcr, /*HasImm*/false, /*MxOp*/3);
1610 case Hexagon::PS_loadrd_pcr:
1611 return RealCirc(Hexagon::L2_loadrd_pcr, /*HasImm*/false, /*MxOp*/3);
1612 case Hexagon::PS_storerb_pci:
1613 return RealCirc(Hexagon::S2_storerb_pci, /*HasImm*/true, /*MxOp*/3);
1614 case Hexagon::PS_storerh_pci:
1615 return RealCirc(Hexagon::S2_storerh_pci, /*HasImm*/true, /*MxOp*/3);
1616 case Hexagon::PS_storerf_pci:
1617 return RealCirc(Hexagon::S2_storerf_pci, /*HasImm*/true, /*MxOp*/3);
1618 case Hexagon::PS_storeri_pci:
1619 return RealCirc(Hexagon::S2_storeri_pci, /*HasImm*/true, /*MxOp*/3);
1620 case Hexagon::PS_storerd_pci:
1621 return RealCirc(Hexagon::S2_storerd_pci, /*HasImm*/true, /*MxOp*/3);
1622 case Hexagon::PS_storerb_pcr:
1623 return RealCirc(Hexagon::S2_storerb_pcr, /*HasImm*/false, /*MxOp*/2);
1624 case Hexagon::PS_storerh_pcr:
1625 return RealCirc(Hexagon::S2_storerh_pcr, /*HasImm*/false, /*MxOp*/2);
1626 case Hexagon::PS_storerf_pcr:
1627 return RealCirc(Hexagon::S2_storerf_pcr, /*HasImm*/false, /*MxOp*/2);
1628 case Hexagon::PS_storeri_pcr:
1629 return RealCirc(Hexagon::S2_storeri_pcr, /*HasImm*/false, /*MxOp*/2);
1630 case Hexagon::PS_storerd_pcr:
1631 return RealCirc(Hexagon::S2_storerd_pcr, /*HasImm*/false, /*MxOp*/2);
1632 }
1633
1634 return false;
1635}
1636
1639 MachineBasicBlock &MBB = *MI.getParent();
1640 const DebugLoc &DL = MI.getDebugLoc();
1641 unsigned Opc = MI.getOpcode();
1643
1644 switch (Opc) {
1645 case Hexagon::V6_vgather_vscatter_mh_pseudo:
1646 // This is mainly a place holder. It will be extended.
1647 First = BuildMI(MBB, MI, DL, get(Hexagon::V6_vgathermh))
1648 .add(MI.getOperand(2))
1649 .add(MI.getOperand(3))
1650 .add(MI.getOperand(4));
1651 BuildMI(MBB, MI, DL, get(Hexagon::V6_vscattermh))
1652 .add(MI.getOperand(2))
1653 .add(MI.getOperand(3))
1654 .add(MI.getOperand(4))
1655 .addReg(Hexagon::VTMP);
1656 MBB.erase(MI);
1657 return First.getInstrIterator();
1658 case Hexagon::V6_vgathermh_pseudo:
1659 First = BuildMI(MBB, MI, DL, get(Hexagon::V6_vgathermh))
1660 .add(MI.getOperand(2))
1661 .add(MI.getOperand(3))
1662 .add(MI.getOperand(4));
1663 BuildMI(MBB, MI, DL, get(Hexagon::V6_vS32b_new_ai))
1664 .add(MI.getOperand(0))
1665 .addImm(MI.getOperand(1).getImm())
1666 .addReg(Hexagon::VTMP);
1667 MBB.erase(MI);
1668 return First.getInstrIterator();
1669
1670 case Hexagon::V6_vgathermw_pseudo:
1671 First = BuildMI(MBB, MI, DL, get(Hexagon::V6_vgathermw))
1672 .add(MI.getOperand(2))
1673 .add(MI.getOperand(3))
1674 .add(MI.getOperand(4));
1675 BuildMI(MBB, MI, DL, get(Hexagon::V6_vS32b_new_ai))
1676 .add(MI.getOperand(0))
1677 .addImm(MI.getOperand(1).getImm())
1678 .addReg(Hexagon::VTMP);
1679 MBB.erase(MI);
1680 return First.getInstrIterator();
1681
1682 case Hexagon::V6_vgathermhw_pseudo:
1683 First = BuildMI(MBB, MI, DL, get(Hexagon::V6_vgathermhw))
1684 .add(MI.getOperand(2))
1685 .add(MI.getOperand(3))
1686 .add(MI.getOperand(4));
1687 BuildMI(MBB, MI, DL, get(Hexagon::V6_vS32b_new_ai))
1688 .add(MI.getOperand(0))
1689 .addImm(MI.getOperand(1).getImm())
1690 .addReg(Hexagon::VTMP);
1691 MBB.erase(MI);
1692 return First.getInstrIterator();
1693
1694 case Hexagon::V6_vgathermhq_pseudo:
1695 First = BuildMI(MBB, MI, DL, get(Hexagon::V6_vgathermhq))
1696 .add(MI.getOperand(2))
1697 .add(MI.getOperand(3))
1698 .add(MI.getOperand(4))
1699 .add(MI.getOperand(5));
1700 BuildMI(MBB, MI, DL, get(Hexagon::V6_vS32b_new_ai))
1701 .add(MI.getOperand(0))
1702 .addImm(MI.getOperand(1).getImm())
1703 .addReg(Hexagon::VTMP);
1704 MBB.erase(MI);
1705 return First.getInstrIterator();
1706
1707 case Hexagon::V6_vgathermwq_pseudo:
1708 First = BuildMI(MBB, MI, DL, get(Hexagon::V6_vgathermwq))
1709 .add(MI.getOperand(2))
1710 .add(MI.getOperand(3))
1711 .add(MI.getOperand(4))
1712 .add(MI.getOperand(5));
1713 BuildMI(MBB, MI, DL, get(Hexagon::V6_vS32b_new_ai))
1714 .add(MI.getOperand(0))
1715 .addImm(MI.getOperand(1).getImm())
1716 .addReg(Hexagon::VTMP);
1717 MBB.erase(MI);
1718 return First.getInstrIterator();
1719
1720 case Hexagon::V6_vgathermhwq_pseudo:
1721 First = BuildMI(MBB, MI, DL, get(Hexagon::V6_vgathermhwq))
1722 .add(MI.getOperand(2))
1723 .add(MI.getOperand(3))
1724 .add(MI.getOperand(4))
1725 .add(MI.getOperand(5));
1726 BuildMI(MBB, MI, DL, get(Hexagon::V6_vS32b_new_ai))
1727 .add(MI.getOperand(0))
1728 .addImm(MI.getOperand(1).getImm())
1729 .addReg(Hexagon::VTMP);
1730 MBB.erase(MI);
1731 return First.getInstrIterator();
1732 }
1733
1734 return MI.getIterator();
1735}
1736
1737// We indicate that we want to reverse the branch by
1738// inserting the reversed branching opcode.
1741 if (Cond.empty())
1742 return true;
1743 assert(Cond[0].isImm() && "First entry in the cond vector not imm-val");
1744 unsigned opcode = Cond[0].getImm();
1745 //unsigned temp;
1746 assert(get(opcode).isBranch() && "Should be a branching condition.");
1747 if (isEndLoopN(opcode))
1748 return true;
1749 unsigned NewOpcode = getInvertedPredicatedOpcode(opcode);
1750 Cond[0].setImm(NewOpcode);
1751 return false;
1752}
1753
1759
1763
1765 unsigned BasePos, OffsetPos;
1766 if (!getBaseAndOffsetPosition(MI, BasePos, OffsetPos))
1767 return false;
1768 return isPostIncrement(MI) && MI.getOperand(OffsetPos).isImm();
1769}
1770
1771// Returns true if an instruction is predicated irrespective of the predicate
1772// sense. For example, all of the following will return true.
1773// if (p0) R1 = add(R2, R3)
1774// if (!p0) R1 = add(R2, R3)
1775// if (p0.new) R1 = add(R2, R3)
1776// if (!p0.new) R1 = add(R2, R3)
1777// Note: New-value stores are not included here as in the current
1778// implementation, we don't need to check their predicate sense.
1780 const uint64_t F = MI.getDesc().TSFlags;
1782}
1783
1786 if (Cond.empty() || isNewValueJump(Cond[0].getImm()) ||
1787 isEndLoopN(Cond[0].getImm())) {
1788 LLVM_DEBUG(dbgs() << "\nCannot predicate:"; MI.dump(););
1789 return false;
1790 }
1791 int Opc = MI.getOpcode();
1792 assert (isPredicable(MI) && "Expected predicable instruction");
1793 bool invertJump = predOpcodeHasNot(Cond);
1794
1795 // We have to predicate MI "in place", i.e. after this function returns,
1796 // MI will need to be transformed into a predicated form. To avoid com-
1797 // plicated manipulations with the operands (handling tied operands,
1798 // etc.), build a new temporary instruction, then overwrite MI with it.
1799
1800 MachineBasicBlock &B = *MI.getParent();
1801 DebugLoc DL = MI.getDebugLoc();
1802 unsigned PredOpc = getCondOpcode(Opc, invertJump);
1803 MachineInstrBuilder T = BuildMI(B, MI, DL, get(PredOpc));
1804 unsigned NOp = 0, NumOps = MI.getNumOperands();
1805 while (NOp < NumOps) {
1806 MachineOperand &Op = MI.getOperand(NOp);
1807 if (!Op.isReg() || !Op.isDef() || Op.isImplicit())
1808 break;
1809 T.add(Op);
1810 NOp++;
1811 }
1812
1813 Register PredReg;
1814 unsigned PredRegPos;
1815 RegState PredRegFlags = {};
1816 bool GotPredReg = getPredReg(Cond, PredReg, PredRegPos, PredRegFlags);
1817 (void)GotPredReg;
1818 assert(GotPredReg);
1819 if (isPredicatedNew(Cond[0].getImm()) && MI.isBundledWithPred()) {
1820 auto BundleStart = getBundleStart(MI.getIterator());
1821 for (auto I = std::next(BundleStart), E = MI.getIterator(); I != E; ++I)
1822 if (I->definesRegister(PredReg, &getRegisterInfo())) {
1823 PredRegFlags |= RegState::InternalRead;
1824 break;
1825 }
1826 }
1827 T.addReg(PredReg, PredRegFlags);
1828 while (NOp < NumOps)
1829 T.add(MI.getOperand(NOp++));
1830
1831 MI.setDesc(get(PredOpc));
1832 while (unsigned n = MI.getNumOperands())
1833 MI.removeOperand(n-1);
1834 for (unsigned i = 0, n = T->getNumOperands(); i < n; ++i)
1835 MI.addOperand(T->getOperand(i));
1836
1837 MachineBasicBlock::instr_iterator TI = T->getIterator();
1838 B.erase(TI);
1839
1840 MachineRegisterInfo &MRI = B.getParent()->getRegInfo();
1841 MRI.clearKillFlags(PredReg);
1842 return true;
1843}
1844
1846 ArrayRef<MachineOperand> Pred2) const {
1847 // TODO: Fix this
1848 return false;
1849}
1850
1852 std::vector<MachineOperand> &Pred,
1853 bool SkipDead) const {
1854 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
1855
1856 for (const MachineOperand &MO : MI.operands()) {
1857 if (MO.isReg()) {
1858 if (!MO.isDef())
1859 continue;
1860 const TargetRegisterClass* RC = HRI.getMinimalPhysRegClass(MO.getReg());
1861 if (RC == &Hexagon::PredRegsRegClass) {
1862 Pred.push_back(MO);
1863 return true;
1864 }
1865 continue;
1866 } else if (MO.isRegMask()) {
1867 for (Register PR : Hexagon::PredRegsRegClass) {
1868 if (!MI.modifiesRegister(PR, &HRI))
1869 continue;
1870 Pred.push_back(MO);
1871 return true;
1872 }
1873 }
1874 }
1875 return false;
1876}
1877
1879 if (!MI.getDesc().isPredicable())
1880 return false;
1881
1882 if (MI.isCall() || isTailCall(MI)) {
1883 if (!Subtarget.usePredicatedCalls())
1884 return false;
1885 }
1886
1887 // HVX loads are not predicable on v60, but are on v62.
1888 if (!Subtarget.hasV62Ops()) {
1889 switch (MI.getOpcode()) {
1890 case Hexagon::V6_vL32b_ai:
1891 case Hexagon::V6_vL32b_pi:
1892 case Hexagon::V6_vL32b_ppu:
1893 case Hexagon::V6_vL32b_cur_ai:
1894 case Hexagon::V6_vL32b_cur_pi:
1895 case Hexagon::V6_vL32b_cur_ppu:
1896 case Hexagon::V6_vL32b_nt_ai:
1897 case Hexagon::V6_vL32b_nt_pi:
1898 case Hexagon::V6_vL32b_nt_ppu:
1899 case Hexagon::V6_vL32b_tmp_ai:
1900 case Hexagon::V6_vL32b_tmp_pi:
1901 case Hexagon::V6_vL32b_tmp_ppu:
1902 case Hexagon::V6_vL32b_nt_cur_ai:
1903 case Hexagon::V6_vL32b_nt_cur_pi:
1904 case Hexagon::V6_vL32b_nt_cur_ppu:
1905 case Hexagon::V6_vL32b_nt_tmp_ai:
1906 case Hexagon::V6_vL32b_nt_tmp_pi:
1907 case Hexagon::V6_vL32b_nt_tmp_ppu:
1908 return false;
1909 }
1910 }
1911 return true;
1912}
1913
1915 bool Invert) const {
1916 if (Invert)
1917 return false;
1918
1919 switch (Inst.getOpcode()) {
1920 // TODO: Add more instructions to be handled by MachineCombiner.
1921 case Hexagon::F2_sfadd:
1923 default:
1924 return false;
1925 }
1926}
1927
1929 const MachineBasicBlock *MBB,
1930 const MachineFunction &MF) const {
1931 // Debug info is never a scheduling boundary. It's necessary to be explicit
1932 // due to the special treatment of IT instructions below, otherwise a
1933 // dbg_value followed by an IT will result in the IT instruction being
1934 // considered a scheduling hazard, which is wrong. It should be the actual
1935 // instruction preceding the dbg_value instruction(s), just like it is
1936 // when debug info is not present.
1937 if (MI.isDebugInstr())
1938 return false;
1939
1940 // Throwing call is a boundary.
1941 if (MI.isCall()) {
1942 // Don't mess around with no return calls.
1943 if (doesNotReturn(MI))
1944 return true;
1945 // If any of the block's successors is a landing pad, this could be a
1946 // throwing call.
1947 for (auto *I : MBB->successors())
1948 if (I->isEHPad())
1949 return true;
1950 }
1951
1952 // Terminators and labels can't be scheduled around.
1953 if (MI.getDesc().isTerminator() || MI.isPosition())
1954 return true;
1955
1956 // INLINEASM_BR can jump to another block
1957 if (MI.getOpcode() == TargetOpcode::INLINEASM_BR)
1958 return true;
1959
1960 if (MI.isInlineAsm() && !ScheduleInlineAsm)
1961 return true;
1962
1963 return false;
1964}
1965
1966/// Measure the specified inline asm to determine an approximation of its
1967/// length.
1968/// Comments (which run till the next SeparatorString or newline) do not
1969/// count as an instruction.
1970/// Any other non-whitespace text is considered an instruction, with
1971/// multiple instructions separated by SeparatorString or newlines.
1972/// Variable-length instructions are not handled here; this function
1973/// may be overloaded in the target code to do that.
1974/// Hexagon counts the number of ##'s and adjust for that many
1975/// constant exenders.
1977 const MCAsmInfo &MAI,
1978 unsigned MaxInstLength) const {
1979 StringRef AStr(Str);
1980 // Count the number of instructions in the asm.
1981 bool atInsnStart = true;
1982 unsigned Length = 0;
1983 if (MaxInstLength == 0)
1984 MaxInstLength = MAI.getMaxInstLength();
1985 for (; *Str; ++Str) {
1986 if (*Str == '\n' || strncmp(Str, MAI.getSeparatorString(),
1987 strlen(MAI.getSeparatorString())) == 0)
1988 atInsnStart = true;
1989 if (atInsnStart && !isSpace(static_cast<unsigned char>(*Str))) {
1990 Length += MaxInstLength;
1991 atInsnStart = false;
1992 }
1993 if (atInsnStart && strncmp(Str, MAI.getCommentString().data(),
1994 MAI.getCommentString().size()) == 0)
1995 atInsnStart = false;
1996 }
1997
1998 // Add to size number of constant extenders seen * 4.
1999 StringRef Occ("##");
2000 Length += AStr.count(Occ)*4;
2001 return Length;
2002}
2003
2011
2012/// For a comparison instruction, return the source registers in
2013/// \p SrcReg and \p SrcReg2 if having two register operands, and the value it
2014/// compares against in CmpValue. Return true if the comparison instruction
2015/// can be analyzed.
2017 Register &SrcReg2, int64_t &Mask,
2018 int64_t &Value) const {
2019 unsigned Opc = MI.getOpcode();
2020
2021 // Set mask and the first source register.
2022 switch (Opc) {
2023 case Hexagon::C2_cmpeq:
2024 case Hexagon::C2_cmpeqp:
2025 case Hexagon::C2_cmpgt:
2026 case Hexagon::C2_cmpgtp:
2027 case Hexagon::C2_cmpgtu:
2028 case Hexagon::C2_cmpgtup:
2029 case Hexagon::C4_cmpneq:
2030 case Hexagon::C4_cmplte:
2031 case Hexagon::C4_cmplteu:
2032 case Hexagon::C2_cmpeqi:
2033 case Hexagon::C2_cmpgti:
2034 case Hexagon::C2_cmpgtui:
2035 case Hexagon::C4_cmpneqi:
2036 case Hexagon::C4_cmplteui:
2037 case Hexagon::C4_cmpltei:
2038 SrcReg = MI.getOperand(1).getReg();
2039 Mask = ~0;
2040 break;
2041 case Hexagon::A4_cmpbeq:
2042 case Hexagon::A4_cmpbgt:
2043 case Hexagon::A4_cmpbgtu:
2044 case Hexagon::A4_cmpbeqi:
2045 case Hexagon::A4_cmpbgti:
2046 case Hexagon::A4_cmpbgtui:
2047 SrcReg = MI.getOperand(1).getReg();
2048 Mask = 0xFF;
2049 break;
2050 case Hexagon::A4_cmpheq:
2051 case Hexagon::A4_cmphgt:
2052 case Hexagon::A4_cmphgtu:
2053 case Hexagon::A4_cmpheqi:
2054 case Hexagon::A4_cmphgti:
2055 case Hexagon::A4_cmphgtui:
2056 SrcReg = MI.getOperand(1).getReg();
2057 Mask = 0xFFFF;
2058 break;
2059 }
2060
2061 // Set the value/second source register.
2062 switch (Opc) {
2063 case Hexagon::C2_cmpeq:
2064 case Hexagon::C2_cmpeqp:
2065 case Hexagon::C2_cmpgt:
2066 case Hexagon::C2_cmpgtp:
2067 case Hexagon::C2_cmpgtu:
2068 case Hexagon::C2_cmpgtup:
2069 case Hexagon::A4_cmpbeq:
2070 case Hexagon::A4_cmpbgt:
2071 case Hexagon::A4_cmpbgtu:
2072 case Hexagon::A4_cmpheq:
2073 case Hexagon::A4_cmphgt:
2074 case Hexagon::A4_cmphgtu:
2075 case Hexagon::C4_cmpneq:
2076 case Hexagon::C4_cmplte:
2077 case Hexagon::C4_cmplteu:
2078 SrcReg2 = MI.getOperand(2).getReg();
2079 Value = 0;
2080 return true;
2081
2082 case Hexagon::C2_cmpeqi:
2083 case Hexagon::C2_cmpgtui:
2084 case Hexagon::C2_cmpgti:
2085 case Hexagon::C4_cmpneqi:
2086 case Hexagon::C4_cmplteui:
2087 case Hexagon::C4_cmpltei:
2088 case Hexagon::A4_cmpbeqi:
2089 case Hexagon::A4_cmpbgti:
2090 case Hexagon::A4_cmpbgtui:
2091 case Hexagon::A4_cmpheqi:
2092 case Hexagon::A4_cmphgti:
2093 case Hexagon::A4_cmphgtui: {
2094 SrcReg2 = 0;
2095 const MachineOperand &Op2 = MI.getOperand(2);
2096 if (!Op2.isImm())
2097 return false;
2098 Value = MI.getOperand(2).getImm();
2099 return true;
2100 }
2101 }
2102
2103 return false;
2104}
2105
2107 const MachineInstr &MI,
2108 unsigned *PredCost) const {
2109 return getInstrTimingClassLatency(ItinData, MI);
2110}
2111
2113 const TargetSubtargetInfo &STI) const {
2115 return static_cast<const HexagonSubtarget&>(STI).createDFAPacketizer(II);
2116}
2117
2118// Inspired by this pair:
2119// %r13 = L2_loadri_io %r29, 136; mem:LD4[FixedStack0]
2120// S2_storeri_io %r29, 132, killed %r1; flags: mem:ST4[FixedStack1]
2121// Currently AA considers the addresses in these instructions to be aliasing.
2123 const MachineInstr &MIa, const MachineInstr &MIb) const {
2126 return false;
2127
2128 // Instructions that are pure loads, not loads and stores like memops are not
2129 // dependent.
2130 if (MIa.mayLoad() && !isMemOp(MIa) && MIb.mayLoad() && !isMemOp(MIb))
2131 return true;
2132
2133 // Get the base register in MIa.
2134 unsigned BasePosA, OffsetPosA;
2135 if (!getBaseAndOffsetPosition(MIa, BasePosA, OffsetPosA))
2136 return false;
2137 const MachineOperand &BaseA = MIa.getOperand(BasePosA);
2138 Register BaseRegA = BaseA.getReg();
2139 unsigned BaseSubA = BaseA.getSubReg();
2140
2141 // Get the base register in MIb.
2142 unsigned BasePosB, OffsetPosB;
2143 if (!getBaseAndOffsetPosition(MIb, BasePosB, OffsetPosB))
2144 return false;
2145 const MachineOperand &BaseB = MIb.getOperand(BasePosB);
2146 Register BaseRegB = BaseB.getReg();
2147 unsigned BaseSubB = BaseB.getSubReg();
2148
2149 if (BaseRegA != BaseRegB || BaseSubA != BaseSubB)
2150 return false;
2151
2152 // Get the access sizes.
2153 unsigned SizeA = getMemAccessSize(MIa);
2154 unsigned SizeB = getMemAccessSize(MIb);
2155
2156 // Get the offsets. Handle immediates only for now.
2157 const MachineOperand &OffA = MIa.getOperand(OffsetPosA);
2158 const MachineOperand &OffB = MIb.getOperand(OffsetPosB);
2159 if (!MIa.getOperand(OffsetPosA).isImm() ||
2160 !MIb.getOperand(OffsetPosB).isImm())
2161 return false;
2162 int OffsetA = isPostIncrement(MIa) ? 0 : OffA.getImm();
2163 int OffsetB = isPostIncrement(MIb) ? 0 : OffB.getImm();
2164
2165 // This is a mem access with the same base register and known offsets from it.
2166 // Reason about it.
2167 if (OffsetA > OffsetB) {
2168 uint64_t OffDiff = (uint64_t)((int64_t)OffsetA - (int64_t)OffsetB);
2169 return SizeB <= OffDiff;
2170 }
2171 if (OffsetA < OffsetB) {
2172 uint64_t OffDiff = (uint64_t)((int64_t)OffsetB - (int64_t)OffsetA);
2173 return SizeA <= OffDiff;
2174 }
2175
2176 return false;
2177}
2178
2179// This MI might have either incomplete info, or known to be unsafe
2180// to deal with (i.e. volatile object).
2182 if (!MI || MI->memoperands_empty())
2183 return true;
2184
2185 if ((*MI->memoperands_begin())->isVolatile() || MI->hasUnmodeledSideEffects())
2186 return true;
2187
2188 if (!(*MI->memoperands_begin())->getValue())
2189 return true;
2190
2191 return false;
2192}
2193
2194/// This returns true if the two MIs could be memory dependent.
2196 const MachineInstr *MIa,
2197 const MachineInstr *MIb) const {
2198 // Cover a trivial case - no edge is need to itself.
2199 if (MIa == MIb)
2200 return false;
2201
2202 if (areMemAccessesTriviallyDisjoint(*MIa, *MIb))
2203 return false;
2204
2206 return true;
2207
2208 // If we are dealing with two "normal" loads, we do not need an edge
2209 // between them - they could be reordered.
2210 if (!MIa->mayStore() && !MIb->mayStore())
2211 return false;
2212
2213 // To this point analysis is generic. From here on we do need AA.
2214 if (!AA)
2215 return true;
2216
2217 MachineMemOperand *MMOa = *MIa->memoperands_begin();
2218 MachineMemOperand *MMOb = *MIb->memoperands_begin();
2219
2220 // TODO: Need to handle multiple memory operands.
2221 // if either instruction has more than one memory operand, punt.
2222 if (!(MIa->hasOneMemOperand() && MIb->hasOneMemOperand()))
2223 return true;
2224
2225 if (!MMOa->getSize().hasValue() || !MMOb->getSize().hasValue())
2226 return true;
2227
2228 assert((MMOa->getOffset() >= 0) && "Negative MachineMemOperand offset");
2229 assert((MMOb->getOffset() >= 0) && "Negative MachineMemOperand offset");
2230 assert((MMOa->getSize().hasValue() && MMOb->getSize().hasValue()) &&
2231 "Size 0 memory access");
2232
2233 // If the base address of the two memoperands is the same. For instance,
2234 // x and x+4, then we can easily reason about them using the offset and size
2235 // of access.
2236 if (MMOa->getValue() == MMOb->getValue()) {
2237 if (MMOa->getOffset() > MMOb->getOffset()) {
2238 uint64_t offDiff = MMOa->getOffset() - MMOb->getOffset();
2239 return !(MMOb->getSize().getValue() <= offDiff);
2240 } else if (MMOa->getOffset() < MMOb->getOffset()) {
2241 uint64_t offDiff = MMOb->getOffset() - MMOa->getOffset();
2242 return !(MMOa->getSize().getValue() <= offDiff);
2243 }
2244 // MMOa->getOffset() == MMOb->getOffset()
2245 return true;
2246 }
2247
2248 int64_t MinOffset = std::min(MMOa->getOffset(), MMOb->getOffset());
2249 int64_t Overlapa = MMOa->getSize().getValue() + MMOa->getOffset() - MinOffset;
2250 int64_t Overlapb = MMOb->getSize().getValue() + MMOb->getOffset() - MinOffset;
2251
2252 AliasResult AAResult =
2253 AA->alias(MemoryLocation(MMOa->getValue(), Overlapa, MMOa->getAAInfo()),
2254 MemoryLocation(MMOb->getValue(), Overlapb, MMOb->getAAInfo()));
2255
2256 return (AAResult != AliasResult::NoAlias);
2257}
2258
2259/// If the instruction is an increment of a constant value, return the amount.
2261 int &Value) const {
2262 if (isPostIncrement(MI)) {
2263 unsigned BasePos = 0, OffsetPos = 0;
2264 if (!getBaseAndOffsetPosition(MI, BasePos, OffsetPos))
2265 return false;
2266 const MachineOperand &OffsetOp = MI.getOperand(OffsetPos);
2267 if (OffsetOp.isImm()) {
2268 Value = OffsetOp.getImm();
2269 return true;
2270 }
2271 } else if (MI.getOpcode() == Hexagon::A2_addi) {
2272 const MachineOperand &AddOp = MI.getOperand(2);
2273 if (AddOp.isImm()) {
2274 Value = AddOp.getImm();
2275 return true;
2276 }
2277 }
2278
2279 return false;
2280}
2281
2282std::pair<unsigned, unsigned>
2284 return std::make_pair(TF & ~HexagonII::MO_Bitmasks,
2286}
2287
2290 using namespace HexagonII;
2291
2292 static const std::pair<unsigned, const char*> Flags[] = {
2293 {MO_PCREL, "hexagon-pcrel"},
2294 {MO_GOT, "hexagon-got"},
2295 {MO_LO16, "hexagon-lo16"},
2296 {MO_HI16, "hexagon-hi16"},
2297 {MO_GPREL, "hexagon-gprel"},
2298 {MO_GDGOT, "hexagon-gdgot"},
2299 {MO_GDPLT, "hexagon-gdplt"},
2300 {MO_IE, "hexagon-ie"},
2301 {MO_IEGOT, "hexagon-iegot"},
2302 {MO_TPREL, "hexagon-tprel"}
2303 };
2304 return ArrayRef(Flags);
2305}
2306
2309 using namespace HexagonII;
2310
2311 static const std::pair<unsigned, const char*> Flags[] = {
2312 {HMOTF_ConstExtended, "hexagon-ext"}
2313 };
2314 return ArrayRef(Flags);
2315}
2316
2319 const TargetRegisterClass *TRC;
2320 if (VT == MVT::i1) {
2321 TRC = &Hexagon::PredRegsRegClass;
2322 } else if (VT == MVT::i32 || VT == MVT::f32) {
2323 TRC = &Hexagon::IntRegsRegClass;
2324 } else if (VT == MVT::i64 || VT == MVT::f64) {
2325 TRC = &Hexagon::DoubleRegsRegClass;
2326 } else {
2327 llvm_unreachable("Cannot handle this register class");
2328 }
2329
2330 Register NewReg = MRI.createVirtualRegister(TRC);
2331 return NewReg;
2332}
2333
2337
2339 const uint64_t F = MI.getDesc().TSFlags;
2341}
2342
2346
2348 return !isTC1(MI) && !isTC2Early(MI) && !MI.getDesc().mayLoad() &&
2349 !MI.getDesc().mayStore() &&
2350 MI.getDesc().getOpcode() != Hexagon::S2_allocframe &&
2351 MI.getDesc().getOpcode() != Hexagon::L2_deallocframe &&
2352 !isMemOp(MI) && !MI.isBranch() && !MI.isReturn() && !MI.isCall();
2353}
2354
2355// Return true if the instruction is a compound branch instruction.
2357 return getType(MI) == HexagonII::TypeCJ && MI.isBranch();
2358}
2359
2360// TODO: In order to have isExtendable for fpimm/f32Ext, we need to handle
2361// isFPImm and later getFPImm as well.
2363 const uint64_t F = MI.getDesc().TSFlags;
2365 if (isExtended) // Instruction must be extended.
2366 return true;
2367
2368 unsigned isExtendable =
2370 if (!isExtendable)
2371 return false;
2372
2373 if (MI.isCall())
2374 return false;
2375
2376 short ExtOpNum = getCExtOpNum(MI);
2377 const MachineOperand &MO = MI.getOperand(ExtOpNum);
2378 // Use MO operand flags to determine if MO
2379 // has the HMOTF_ConstExtended flag set.
2381 return true;
2382 // If this is a Machine BB address we are talking about, and it is
2383 // not marked as extended, say so.
2384 if (MO.isMBB())
2385 return false;
2386
2387 // We could be using an instruction with an extendable immediate and shoehorn
2388 // a global address into it. If it is a global address it will be constant
2389 // extended. We do this for COMBINE.
2390 if (MO.isGlobal() || MO.isSymbol() || MO.isBlockAddress() ||
2391 MO.isJTI() || MO.isCPI() || MO.isFPImm())
2392 return true;
2393
2394 // If the extendable operand is not 'Immediate' type, the instruction should
2395 // have 'isExtended' flag set.
2396 assert(MO.isImm() && "Extendable operand must be Immediate type");
2397
2398 int64_t Value = MO.getImm();
2400 int32_t SValue = Value;
2401 int32_t MinValue = getMinValue(MI);
2402 int32_t MaxValue = getMaxValue(MI);
2403 return SValue < MinValue || SValue > MaxValue;
2404 }
2405 uint32_t UValue = Value;
2406 uint32_t MinValue = getMinValue(MI);
2407 uint32_t MaxValue = getMaxValue(MI);
2408 return UValue < MinValue || UValue > MaxValue;
2409}
2410
2412 switch (MI.getOpcode()) {
2413 case Hexagon::L4_return:
2414 case Hexagon::L4_return_t:
2415 case Hexagon::L4_return_f:
2416 case Hexagon::L4_return_tnew_pnt:
2417 case Hexagon::L4_return_fnew_pnt:
2418 case Hexagon::L4_return_tnew_pt:
2419 case Hexagon::L4_return_fnew_pt:
2420 return true;
2421 }
2422 return false;
2423}
2424
2425// Return true when ConsMI uses a register defined by ProdMI.
2427 const MachineInstr &ConsMI) const {
2428 if (!ProdMI.getDesc().getNumDefs())
2429 return false;
2430 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
2431
2436
2437 parseOperands(ProdMI, DefsA, UsesA);
2438 parseOperands(ConsMI, DefsB, UsesB);
2439
2440 for (auto &RegA : DefsA)
2441 for (auto &RegB : UsesB) {
2442 // True data dependency.
2443 if (RegA == RegB)
2444 return true;
2445
2446 if (RegA.isPhysical() && llvm::is_contained(HRI.subregs(RegA), RegB))
2447 return true;
2448
2449 if (RegB.isPhysical() && llvm::is_contained(HRI.subregs(RegB), RegA))
2450 return true;
2451 }
2452
2453 return false;
2454}
2455
2456// Returns true if the instruction is already a .cur.
2458 // TODO: Use an attribute instead of switch case of opcodes.
2459 // This would be more maintainable and allow TableGen to generate the list.
2460 switch (MI.getOpcode()) {
2461 // HVX vector load instructions with .cur suffix.
2462 // Variants include:
2463 // - Base addressing modes: pi (post-increment), ai (absolute immediate),
2464 // ppu (post-increment by register)
2465 // - Predicated versions: pred (if true), npred (if false)
2466 // - Non-temporal hint: nt (non-temporal)
2467 // Note: Does not include pseudo instructions.
2468 case Hexagon::V6_vL32b_cur_pi:
2469 case Hexagon::V6_vL32b_nt_cur_pi:
2470 case Hexagon::V6_vL32b_cur_pred_pi:
2471 case Hexagon::V6_vL32b_nt_cur_pred_pi:
2472 case Hexagon::V6_vL32b_cur_npred_pi:
2473 case Hexagon::V6_vL32b_nt_cur_npred_pi:
2474 case Hexagon::V6_vL32b_cur_ai:
2475 case Hexagon::V6_vL32b_nt_cur_ai:
2476 case Hexagon::V6_vL32b_cur_pred_ai:
2477 case Hexagon::V6_vL32b_nt_cur_pred_ai:
2478 case Hexagon::V6_vL32b_cur_npred_ai:
2479 case Hexagon::V6_vL32b_nt_cur_npred_ai:
2480 case Hexagon::V6_vL32b_cur_ppu:
2481 case Hexagon::V6_vL32b_nt_cur_ppu:
2482 case Hexagon::V6_vL32b_cur_pred_ppu:
2483 case Hexagon::V6_vL32b_nt_cur_pred_ppu:
2484 case Hexagon::V6_vL32b_cur_npred_ppu:
2485 case Hexagon::V6_vL32b_nt_cur_npred_ppu:
2486 return true;
2487 }
2488 return false;
2489}
2490
2491/// Should be able to tell if the operand in question is .new.
2492/// Instead of exhaustive case statement (which would be prohibitively large)
2493/// we use a set of rules.
2495 unsigned OpIndex) const {
2496 // If it is not MI that has "any" .new, return false.
2497 if (!isDotNewInst(MI))
2498 return false;
2499
2500 const MachineOperand &MO = MI.getOperand(OpIndex);
2501 // If it is a def, or not a register, it could not be .new.
2502 if (MO.isDef() || !MO.isReg())
2503 return false;
2504
2505 // If it is a predicated instruction, it reduces options on
2506 // what could be a .new operand.
2507 if (isPredicated(MI)) {
2508 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
2509 if (HRI.isFakeReg(MO.getReg()))
2510 return false;
2511 else {
2512 const TargetRegisterClass *RC = HRI.getMinimalPhysRegClass(MO.getReg());
2513 return (RC == &Hexagon::PredRegsRegClass);
2514 }
2515 }
2516
2517 // For a NVJ by definition, operand with .new must be an internal read.
2518 if (isNewValueJump(MI)) {
2519 if (MO.isReg() && MO.isInternalRead())
2520 return true;
2521 else
2522 return false;
2523 }
2524
2525 // Each new value store has different "position"
2526 // of the .new operand. But it always should be
2527 // an internal read.
2528 // S2_storerinew_io %R29, 28, %R1<internal>
2529 // Use: [0] is.new(0) reg(%R29)
2530 // Use: [2] is.new(1) reg(%R1)
2531 if (isNewValueStore(MI)) {
2532 if (MO.isInternalRead())
2533 return true;
2534 else
2535 return false;
2536 }
2537
2538 llvm_unreachable("Unhandled operand.");
2539 return false;
2540}
2541
2542// Returns true, if any of the operands of the instruction,
2543// is a dot tmp register
2547
2548/// Returns true if the specified operand is a .tmp (temporary) operand.
2549/// .tmp operands represent temporary values that are used in the same packet.
2550/// This function checks:
2551/// 1. The instruction is a .tmp instruction (isDotTmpInst)
2552/// 2. The operand is a def register
2553/// 3. The operand is not tied (excludes post-increment base registers)
2555 unsigned OpIndex) const {
2556 // If it is not MI that has "any" .tmp, return false.
2557 if (!isDotTmpInst(MI))
2558 return false;
2559
2560 const MachineOperand &MO = MI.getOperand(OpIndex);
2561
2562 // .tmp only applies to def registers.
2563 // Also, make sure that MO is not a tied (post-inc) operand
2564 if (MO.isDef() && MO.isReg() && !MO.isTied())
2565 return true;
2566 return false;
2567}
2568
2569/// Returns true if the specified operand is a .cur (current) operand.
2570/// .cur operands can be used immediately in the same packet.
2571/// This function checks:
2572/// 1. The instruction is a .cur instruction (isDotCurInst)
2573/// 2. The operand is a def register
2574/// 3. The operand is not tied (excludes post-increment base registers)
2576 unsigned OpIndex) const {
2577 // If it is not MI that has "any" .cur, return false.
2578 if (!isDotCurInst(MI))
2579 return false;
2580
2581 const MachineOperand &MO = MI.getOperand(OpIndex);
2582
2583 // .cur only applies to def registers.
2584 // Also, make sure that MO is not a tied (post-inc) operand
2585 if (MO.isDef() && MO.isReg() && !MO.isTied())
2586 return true;
2587 return false;
2588}
2589
2591 unsigned DefOpIdx,
2592 const MachineInstr &UseMI,
2593 unsigned UseOpIdx, bool IsPullDown,
2594 bool DefViaRegMask) const {
2595 // Push-down needs in-packet forwarding (.cur/.new) so the use sees the new
2596 // value; that analysis is not implemented, so reject it. Only pull-up today.
2597 if (IsPullDown)
2598 return false;
2599 if (!DefViaRegMask) {
2600 // A forwarding .cur/.tmp def exposes its value in-packet, making the use
2601 // read the new value, a disguised RAW, not a safe WAR. (A regmask clobber
2602 // never forwards, so these checks are skipped for it.)
2603 if (!DefMI.getOperand(DefOpIdx).isReg())
2604 return false;
2605 if (isDotCurOperand(DefMI, DefOpIdx))
2606 return false;
2607 if (isDotTmpOperand(DefMI, DefOpIdx))
2608 return false;
2609 }
2610 if (isDotNewOperand(UseMI, UseOpIdx))
2611 return false;
2612 if (UseMI.isTerminator())
2613 return false;
2614 return true;
2615}
2616
2617// Returns true, if any one of the operands is a dot new
2618// insn, whether it is predicated dot new or register dot new.
2621 return true;
2622
2623 return false;
2624}
2625
2626/// Symmetrical. See if these two instructions are fit for duplex pair.
2628 const MachineInstr &MIb) const {
2631 return (isDuplexPairMatch(MIaG, MIbG) || isDuplexPairMatch(MIbG, MIaG));
2632}
2633
2637
2641
2643 const MachineInstr &MIb) const {
2644 return (isHMXActivateInstr(MIa) && isHMXWeightInstr(MIb)) ||
2645 (isHMXWeightInstr(MIa) && isHMXActivateInstr(MIb));
2646}
2647
2648bool HexagonInstrInfo::isEndLoopN(unsigned Opcode) const {
2649 return (Opcode == Hexagon::ENDLOOP0 ||
2650 Opcode == Hexagon::ENDLOOP1);
2651}
2652
2653bool HexagonInstrInfo::isExpr(unsigned OpType) const {
2654 switch(OpType) {
2661 return true;
2662 default:
2663 return false;
2664 }
2665}
2666
2668 const MCInstrDesc &MID = MI.getDesc();
2669 const uint64_t F = MID.TSFlags;
2671 return true;
2672
2673 // TODO: This is largely obsolete now. Will need to be removed
2674 // in consecutive patches.
2675 switch (MI.getOpcode()) {
2676 // PS_fi and PS_fia remain special cases.
2677 case Hexagon::PS_fi:
2678 case Hexagon::PS_fia:
2679 return true;
2680 default:
2681 return false;
2682 }
2683 return false;
2684}
2685
2686// This returns true in two cases:
2687// - The OP code itself indicates that this is an extended instruction.
2688// - One of MOs has been marked with HMOTF_ConstExtended flag.
2690 // First check if this is permanently extended op code.
2691 const uint64_t F = MI.getDesc().TSFlags;
2693 return true;
2694 // Use MO operand flags to determine if one of MI's operands
2695 // has HMOTF_ConstExtended flag set.
2696 for (const MachineOperand &MO : MI.operands())
2697 if (MO.getTargetFlags() & HexagonII::HMOTF_ConstExtended)
2698 return true;
2699 return false;
2700}
2701
2703 unsigned Opcode = MI.getOpcode();
2704 const uint64_t F = get(Opcode).TSFlags;
2705 return (F >> HexagonII::FPPos) & HexagonII::FPMask;
2706}
2707
2708// No V60 HVX VMEM with A_INDIRECT.
2710 const MachineInstr &J) const {
2711 if (!isHVXVec(I))
2712 return false;
2713 if (!I.mayLoad() && !I.mayStore())
2714 return false;
2715 return J.isIndirectBranch() || isIndirectCall(J) || isIndirectL4Return(J);
2716}
2717
2719 switch (MI.getOpcode()) {
2720 case Hexagon::J2_callr:
2721 case Hexagon::J2_callrf:
2722 case Hexagon::J2_callrt:
2723 case Hexagon::PS_call_nr:
2724 return true;
2725 }
2726 return false;
2727}
2728
2730 switch (MI.getOpcode()) {
2731 case Hexagon::L4_return:
2732 case Hexagon::L4_return_t:
2733 case Hexagon::L4_return_f:
2734 case Hexagon::L4_return_fnew_pnt:
2735 case Hexagon::L4_return_fnew_pt:
2736 case Hexagon::L4_return_tnew_pnt:
2737 case Hexagon::L4_return_tnew_pt:
2738 return true;
2739 }
2740 return false;
2741}
2742
2744 switch (MI.getOpcode()) {
2745 case Hexagon::J2_jumpr:
2746 case Hexagon::J2_jumprt:
2747 case Hexagon::J2_jumprf:
2748 case Hexagon::J2_jumprtnewpt:
2749 case Hexagon::J2_jumprfnewpt:
2750 case Hexagon::J2_jumprtnew:
2751 case Hexagon::J2_jumprfnew:
2752 return true;
2753 }
2754 return false;
2755}
2756
2757// Return true if a given MI can accommodate given offset.
2758// Use abs estimate as oppose to the exact number.
2759// TODO: This will need to be changed to use MC level
2760// definition of instruction extendable field size.
2762 unsigned offset) const {
2763 // This selection of jump instructions matches to that what
2764 // analyzeBranch can parse, plus NVJ.
2765 if (isNewValueJump(MI)) // r9:2
2766 return isInt<11>(offset);
2767
2768 switch (MI.getOpcode()) {
2769 // Still missing Jump to address condition on register value.
2770 default:
2771 return false;
2772 case Hexagon::J2_jump: // bits<24> dst; // r22:2
2773 case Hexagon::J2_call:
2774 case Hexagon::PS_call_nr:
2775 return isInt<24>(offset);
2776 case Hexagon::J2_jumpt: //bits<17> dst; // r15:2
2777 case Hexagon::J2_jumpf:
2778 case Hexagon::J2_jumptnew:
2779 case Hexagon::J2_jumptnewpt:
2780 case Hexagon::J2_jumpfnew:
2781 case Hexagon::J2_jumpfnewpt:
2782 case Hexagon::J2_callt:
2783 case Hexagon::J2_callf:
2784 return isInt<17>(offset);
2785 case Hexagon::J2_loop0i:
2786 case Hexagon::J2_loop0iext:
2787 case Hexagon::J2_loop0r:
2788 case Hexagon::J2_loop0rext:
2789 case Hexagon::J2_loop1i:
2790 case Hexagon::J2_loop1iext:
2791 case Hexagon::J2_loop1r:
2792 case Hexagon::J2_loop1rext:
2793 return isInt<9>(offset);
2794 // TODO: Add all the compound branches here. Can we do this in Relation model?
2795 case Hexagon::J4_cmpeqi_tp0_jump_nt:
2796 case Hexagon::J4_cmpeqi_tp1_jump_nt:
2797 case Hexagon::J4_cmpeqn1_tp0_jump_nt:
2798 case Hexagon::J4_cmpeqn1_tp1_jump_nt:
2799 return isInt<11>(offset);
2800 }
2801}
2802
2804 // Instructions with iclass A_CVI_VX and attribute A_CVI_LATE uses a multiply
2805 // resource, but all operands can be received late like an ALU instruction.
2807}
2808
2810 unsigned Opcode = MI.getOpcode();
2811 return Opcode == Hexagon::J2_loop0i ||
2812 Opcode == Hexagon::J2_loop0r ||
2813 Opcode == Hexagon::J2_loop0iext ||
2814 Opcode == Hexagon::J2_loop0rext ||
2815 Opcode == Hexagon::J2_loop1i ||
2816 Opcode == Hexagon::J2_loop1r ||
2817 Opcode == Hexagon::J2_loop1iext ||
2818 Opcode == Hexagon::J2_loop1rext;
2819}
2820
2822 switch (MI.getOpcode()) {
2823 default: return false;
2824 case Hexagon::L4_iadd_memopw_io:
2825 case Hexagon::L4_isub_memopw_io:
2826 case Hexagon::L4_add_memopw_io:
2827 case Hexagon::L4_sub_memopw_io:
2828 case Hexagon::L4_and_memopw_io:
2829 case Hexagon::L4_or_memopw_io:
2830 case Hexagon::L4_iadd_memoph_io:
2831 case Hexagon::L4_isub_memoph_io:
2832 case Hexagon::L4_add_memoph_io:
2833 case Hexagon::L4_sub_memoph_io:
2834 case Hexagon::L4_and_memoph_io:
2835 case Hexagon::L4_or_memoph_io:
2836 case Hexagon::L4_iadd_memopb_io:
2837 case Hexagon::L4_isub_memopb_io:
2838 case Hexagon::L4_add_memopb_io:
2839 case Hexagon::L4_sub_memopb_io:
2840 case Hexagon::L4_and_memopb_io:
2841 case Hexagon::L4_or_memopb_io:
2842 case Hexagon::L4_ior_memopb_io:
2843 case Hexagon::L4_ior_memoph_io:
2844 case Hexagon::L4_ior_memopw_io:
2845 case Hexagon::L4_iand_memopb_io:
2846 case Hexagon::L4_iand_memoph_io:
2847 case Hexagon::L4_iand_memopw_io:
2848 return true;
2849 }
2850 return false;
2851}
2852
2854 const uint64_t F = MI.getDesc().TSFlags;
2856}
2857
2858bool HexagonInstrInfo::isNewValue(unsigned Opcode) const {
2859 const uint64_t F = get(Opcode).TSFlags;
2861}
2862
2866
2868 return isNewValue(MI) && MI.isBranch();
2869}
2870
2871bool HexagonInstrInfo::isNewValueJump(unsigned Opcode) const {
2872 return isNewValue(Opcode) && get(Opcode).isBranch() && isPredicated(Opcode);
2873}
2874
2876 const uint64_t F = MI.getDesc().TSFlags;
2878}
2879
2880bool HexagonInstrInfo::isNewValueStore(unsigned Opcode) const {
2881 const uint64_t F = get(Opcode).TSFlags;
2883}
2884
2885// Returns true if a particular operand is extendable for an instruction.
2887 unsigned OperandNum) const {
2888 const uint64_t F = MI.getDesc().TSFlags;
2890 == OperandNum;
2891}
2892
2894 const uint64_t F = MI.getDesc().TSFlags;
2897}
2898
2899bool HexagonInstrInfo::isPredicatedNew(unsigned Opcode) const {
2900 const uint64_t F = get(Opcode).TSFlags;
2901 assert(isPredicated(Opcode));
2903}
2904
2906 const uint64_t F = MI.getDesc().TSFlags;
2907 return !((F >> HexagonII::PredicatedFalsePos) &
2909}
2910
2911bool HexagonInstrInfo::isPredicatedTrue(unsigned Opcode) const {
2912 const uint64_t F = get(Opcode).TSFlags;
2913 // Make sure that the instruction is predicated.
2915 return !((F >> HexagonII::PredicatedFalsePos) &
2917}
2918
2919bool HexagonInstrInfo::isPredicated(unsigned Opcode) const {
2920 const uint64_t F = get(Opcode).TSFlags;
2922}
2923
2924bool HexagonInstrInfo::isPredicateLate(unsigned Opcode) const {
2925 const uint64_t F = get(Opcode).TSFlags;
2927}
2928
2929bool HexagonInstrInfo::isPredictedTaken(unsigned Opcode) const {
2930 const uint64_t F = get(Opcode).TSFlags;
2931 assert(get(Opcode).isBranch() &&
2932 (isPredicatedNew(Opcode) || isNewValue(Opcode)));
2934}
2935
2937 return MI.getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4 ||
2938 MI.getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4_EXT ||
2939 MI.getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4_PIC ||
2940 MI.getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4_EXT_PIC;
2941}
2942
2944 switch (MI.getOpcode()) {
2945 // Byte
2946 case Hexagon::L2_loadrb_io:
2947 case Hexagon::L4_loadrb_ur:
2948 case Hexagon::L4_loadrb_ap:
2949 case Hexagon::L2_loadrb_pr:
2950 case Hexagon::L2_loadrb_pbr:
2951 case Hexagon::L2_loadrb_pi:
2952 case Hexagon::L2_loadrb_pci:
2953 case Hexagon::L2_loadrb_pcr:
2954 case Hexagon::L2_loadbsw2_io:
2955 case Hexagon::L4_loadbsw2_ur:
2956 case Hexagon::L4_loadbsw2_ap:
2957 case Hexagon::L2_loadbsw2_pr:
2958 case Hexagon::L2_loadbsw2_pbr:
2959 case Hexagon::L2_loadbsw2_pi:
2960 case Hexagon::L2_loadbsw2_pci:
2961 case Hexagon::L2_loadbsw2_pcr:
2962 case Hexagon::L2_loadbsw4_io:
2963 case Hexagon::L4_loadbsw4_ur:
2964 case Hexagon::L4_loadbsw4_ap:
2965 case Hexagon::L2_loadbsw4_pr:
2966 case Hexagon::L2_loadbsw4_pbr:
2967 case Hexagon::L2_loadbsw4_pi:
2968 case Hexagon::L2_loadbsw4_pci:
2969 case Hexagon::L2_loadbsw4_pcr:
2970 case Hexagon::L4_loadrb_rr:
2971 case Hexagon::L2_ploadrbt_io:
2972 case Hexagon::L2_ploadrbt_pi:
2973 case Hexagon::L2_ploadrbf_io:
2974 case Hexagon::L2_ploadrbf_pi:
2975 case Hexagon::L2_ploadrbtnew_io:
2976 case Hexagon::L2_ploadrbfnew_io:
2977 case Hexagon::L4_ploadrbt_rr:
2978 case Hexagon::L4_ploadrbf_rr:
2979 case Hexagon::L4_ploadrbtnew_rr:
2980 case Hexagon::L4_ploadrbfnew_rr:
2981 case Hexagon::L2_ploadrbtnew_pi:
2982 case Hexagon::L2_ploadrbfnew_pi:
2983 case Hexagon::L4_ploadrbt_abs:
2984 case Hexagon::L4_ploadrbf_abs:
2985 case Hexagon::L4_ploadrbtnew_abs:
2986 case Hexagon::L4_ploadrbfnew_abs:
2987 case Hexagon::L2_loadrbgp:
2988 // Half
2989 case Hexagon::L2_loadrh_io:
2990 case Hexagon::L4_loadrh_ur:
2991 case Hexagon::L4_loadrh_ap:
2992 case Hexagon::L2_loadrh_pr:
2993 case Hexagon::L2_loadrh_pbr:
2994 case Hexagon::L2_loadrh_pi:
2995 case Hexagon::L2_loadrh_pci:
2996 case Hexagon::L2_loadrh_pcr:
2997 case Hexagon::L4_loadrh_rr:
2998 case Hexagon::L2_ploadrht_io:
2999 case Hexagon::L2_ploadrht_pi:
3000 case Hexagon::L2_ploadrhf_io:
3001 case Hexagon::L2_ploadrhf_pi:
3002 case Hexagon::L2_ploadrhtnew_io:
3003 case Hexagon::L2_ploadrhfnew_io:
3004 case Hexagon::L4_ploadrht_rr:
3005 case Hexagon::L4_ploadrhf_rr:
3006 case Hexagon::L4_ploadrhtnew_rr:
3007 case Hexagon::L4_ploadrhfnew_rr:
3008 case Hexagon::L2_ploadrhtnew_pi:
3009 case Hexagon::L2_ploadrhfnew_pi:
3010 case Hexagon::L4_ploadrht_abs:
3011 case Hexagon::L4_ploadrhf_abs:
3012 case Hexagon::L4_ploadrhtnew_abs:
3013 case Hexagon::L4_ploadrhfnew_abs:
3014 case Hexagon::L2_loadrhgp:
3015 return true;
3016 default:
3017 return false;
3018 }
3019}
3020
3022 const uint64_t F = MI.getDesc().TSFlags;
3024}
3025
3027 switch (MI.getOpcode()) {
3028 case Hexagon::STriw_pred:
3029 case Hexagon::LDriw_pred:
3030 return true;
3031 default:
3032 return false;
3033 }
3034}
3035
3037 if (!MI.isBranch())
3038 return false;
3039
3040 for (auto &Op : MI.operands())
3041 if (Op.isGlobal() || Op.isSymbol())
3042 return true;
3043 return false;
3044}
3045
3046// Returns true when SU has a timing class TC1.
3048 unsigned SchedClass = MI.getDesc().getSchedClass();
3049 return is_TC1(SchedClass);
3050}
3051
3053 unsigned SchedClass = MI.getDesc().getSchedClass();
3054 return is_TC2(SchedClass);
3055}
3056
3058 unsigned SchedClass = MI.getDesc().getSchedClass();
3059 return is_TC2early(SchedClass);
3060}
3061
3063 unsigned SchedClass = MI.getDesc().getSchedClass();
3064 return is_TC4x(SchedClass);
3065}
3066
3067// Schedule this ASAP.
3069 const MachineInstr &MI2) const {
3070 if (mayBeCurLoad(MI1)) {
3071 // if (result of SU is used in Next) return true;
3072 Register DstReg = MI1.getOperand(0).getReg();
3073 int N = MI2.getNumOperands();
3074 for (int I = 0; I < N; I++)
3075 if (MI2.getOperand(I).isReg() && DstReg == MI2.getOperand(I).getReg())
3076 return true;
3077 }
3078 if (mayBeNewStore(MI2))
3079 if (MI2.getOpcode() == Hexagon::V6_vS32b_pi)
3080 if (MI1.getOperand(0).isReg() && MI2.getOperand(3).isReg() &&
3081 MI1.getOperand(0).getReg() == MI2.getOperand(3).getReg())
3082 return true;
3083 return false;
3084}
3085
3087 const uint64_t V = getType(MI);
3089}
3090
3092 return (MI.getDesc().TSFlags >> HexagonII::isHLXPos) & HexagonII::isHLXMask;
3093}
3094
3095// Check if the Offset is a valid auto-inc imm by Load/Store Type.
3097 int Size = VT.getSizeInBits() / 8;
3098 if (Offset % Size != 0)
3099 return false;
3100 int Count = Offset / Size;
3101
3102 switch (VT.getSimpleVT().SimpleTy) {
3103 // For scalars the auto-inc is s4
3104 case MVT::i8:
3105 case MVT::i16:
3106 case MVT::i32:
3107 case MVT::i64:
3108 case MVT::f32:
3109 case MVT::f64:
3110 case MVT::v2i16:
3111 case MVT::v2i32:
3112 case MVT::v4i8:
3113 case MVT::v4i16:
3114 case MVT::v8i8:
3115 return isInt<4>(Count);
3116 // For HVX vectors the auto-inc is s3
3117 case MVT::v64i8:
3118 case MVT::v32i16:
3119 case MVT::v16i32:
3120 case MVT::v8i64:
3121 case MVT::v128i8:
3122 case MVT::v64i16:
3123 case MVT::v32i32:
3124 case MVT::v16i64:
3125 return isInt<3>(Count);
3126 default:
3127 break;
3128 }
3129
3130 llvm_unreachable("Not an valid type!");
3131}
3132
3133bool HexagonInstrInfo::isValidOffset(unsigned Opcode, int Offset,
3134 bool Extend) const {
3135 // This function is to check whether the "Offset" is in the correct range of
3136 // the given "Opcode". If "Offset" is not in the correct range, "A2_addi" is
3137 // inserted to calculate the final address. Due to this reason, the function
3138 // assumes that the "Offset" has correct alignment.
3139 // We used to assert if the offset was not properly aligned, however,
3140 // there are cases where a misaligned pointer recast can cause this
3141 // problem, and we need to allow for it. The front end warns of such
3142 // misaligns with respect to load size.
3143 switch (Opcode) {
3144 case Hexagon::PS_vstorerq_ai:
3145 case Hexagon::PS_vstorerv_ai:
3146 case Hexagon::PS_vstorerw_ai:
3147 case Hexagon::PS_vstorerw_nt_ai:
3148 case Hexagon::PS_vloadrq_ai:
3149 case Hexagon::PS_vloadrv_ai:
3150 case Hexagon::PS_vloadrw_ai:
3151 case Hexagon::PS_vloadrw_nt_ai:
3152 case Hexagon::V6_vL32b_ai:
3153 case Hexagon::V6_vS32b_ai:
3154 case Hexagon::V6_vS32b_pred_ai:
3155 case Hexagon::V6_vS32b_npred_ai:
3156 case Hexagon::V6_vS32b_qpred_ai:
3157 case Hexagon::V6_vS32b_nqpred_ai:
3158 case Hexagon::V6_vS32b_new_ai:
3159 case Hexagon::V6_vS32b_new_pred_ai:
3160 case Hexagon::V6_vS32b_new_npred_ai:
3161 case Hexagon::V6_vS32b_nt_pred_ai:
3162 case Hexagon::V6_vS32b_nt_npred_ai:
3163 case Hexagon::V6_vS32b_nt_new_ai:
3164 case Hexagon::V6_vS32b_nt_new_pred_ai:
3165 case Hexagon::V6_vS32b_nt_new_npred_ai:
3166 case Hexagon::V6_vS32b_nt_qpred_ai:
3167 case Hexagon::V6_vS32b_nt_nqpred_ai:
3168 case Hexagon::V6_vL32b_nt_ai:
3169 case Hexagon::V6_vS32b_nt_ai:
3170 case Hexagon::V6_vL32Ub_ai:
3171 case Hexagon::V6_vS32Ub_ai:
3172 case Hexagon::V6_vL32b_cur_ai:
3173 case Hexagon::V6_vL32b_tmp_ai:
3174 case Hexagon::V6_vL32b_pred_ai:
3175 case Hexagon::V6_vL32b_npred_ai:
3176 case Hexagon::V6_vL32b_cur_pred_ai:
3177 case Hexagon::V6_vL32b_cur_npred_ai:
3178 case Hexagon::V6_vL32b_tmp_pred_ai:
3179 case Hexagon::V6_vL32b_tmp_npred_ai:
3180 case Hexagon::V6_vL32b_nt_cur_ai:
3181 case Hexagon::V6_vL32b_nt_tmp_ai:
3182 case Hexagon::V6_vL32b_nt_pred_ai:
3183 case Hexagon::V6_vL32b_nt_npred_ai:
3184 case Hexagon::V6_vL32b_nt_cur_pred_ai:
3185 case Hexagon::V6_vL32b_nt_cur_npred_ai:
3186 case Hexagon::V6_vL32b_nt_tmp_pred_ai:
3187 case Hexagon::V6_vL32b_nt_tmp_npred_ai:
3188 case Hexagon::V6_vS32Ub_pred_ai:
3189 case Hexagon::V6_vS32Ub_npred_ai:
3190 case Hexagon::V6_vgathermh_pseudo:
3191 case Hexagon::V6_vgather_vscatter_mh_pseudo:
3192 case Hexagon::V6_vgathermw_pseudo:
3193 case Hexagon::V6_vgathermhw_pseudo:
3194 case Hexagon::V6_vgathermhq_pseudo:
3195 case Hexagon::V6_vgathermwq_pseudo:
3196 case Hexagon::V6_vgathermhwq_pseudo: {
3197 unsigned VectorSize = RegInfo.getSpillSize(Hexagon::HvxVRRegClass);
3198 assert(isPowerOf2_32(VectorSize));
3199 if (Offset & (VectorSize-1))
3200 return false;
3201 return isInt<4>(Offset >> Log2_32(VectorSize));
3202 }
3203
3204 case Hexagon::J2_loop0i:
3205 case Hexagon::J2_loop1i:
3206 return isUInt<10>(Offset);
3207
3208 case Hexagon::S4_storeirb_io:
3209 case Hexagon::S4_storeirbt_io:
3210 case Hexagon::S4_storeirbf_io:
3211 return isUInt<6>(Offset);
3212
3213 case Hexagon::S4_storeirh_io:
3214 case Hexagon::S4_storeirht_io:
3215 case Hexagon::S4_storeirhf_io:
3216 return isShiftedUInt<6,1>(Offset);
3217
3218 case Hexagon::S4_storeiri_io:
3219 case Hexagon::S4_storeirit_io:
3220 case Hexagon::S4_storeirif_io:
3221 return isShiftedUInt<6,2>(Offset);
3222 // Handle these two compare instructions that are not extendable.
3223 case Hexagon::A4_cmpbeqi:
3224 return isUInt<8>(Offset);
3225 case Hexagon::A4_cmpbgti:
3226 return isInt<8>(Offset);
3227 }
3228
3229 if (Extend)
3230 return true;
3231
3232 switch (Opcode) {
3233 case Hexagon::L2_loadri_io:
3234 case Hexagon::S2_storeri_io:
3235 return (Offset >= Hexagon_MEMW_OFFSET_MIN) &&
3237
3238 case Hexagon::L2_loadrd_io:
3239 case Hexagon::S2_storerd_io:
3240 return (Offset >= Hexagon_MEMD_OFFSET_MIN) &&
3242
3243 case Hexagon::L2_loadrh_io:
3244 case Hexagon::L2_loadruh_io:
3245 case Hexagon::S2_storerh_io:
3246 case Hexagon::S2_storerf_io:
3247 return (Offset >= Hexagon_MEMH_OFFSET_MIN) &&
3249
3250 case Hexagon::L2_loadrb_io:
3251 case Hexagon::L2_loadrub_io:
3252 case Hexagon::S2_storerb_io:
3253 return (Offset >= Hexagon_MEMB_OFFSET_MIN) &&
3255
3256 case Hexagon::A2_addi:
3257 return (Offset >= Hexagon_ADDI_OFFSET_MIN) &&
3259
3260 case Hexagon::L4_iadd_memopw_io:
3261 case Hexagon::L4_isub_memopw_io:
3262 case Hexagon::L4_add_memopw_io:
3263 case Hexagon::L4_sub_memopw_io:
3264 case Hexagon::L4_iand_memopw_io:
3265 case Hexagon::L4_ior_memopw_io:
3266 case Hexagon::L4_and_memopw_io:
3267 case Hexagon::L4_or_memopw_io:
3268 return (0 <= Offset && Offset <= 255);
3269
3270 case Hexagon::L4_iadd_memoph_io:
3271 case Hexagon::L4_isub_memoph_io:
3272 case Hexagon::L4_add_memoph_io:
3273 case Hexagon::L4_sub_memoph_io:
3274 case Hexagon::L4_iand_memoph_io:
3275 case Hexagon::L4_ior_memoph_io:
3276 case Hexagon::L4_and_memoph_io:
3277 case Hexagon::L4_or_memoph_io:
3278 return (0 <= Offset && Offset <= 127);
3279
3280 case Hexagon::L4_iadd_memopb_io:
3281 case Hexagon::L4_isub_memopb_io:
3282 case Hexagon::L4_add_memopb_io:
3283 case Hexagon::L4_sub_memopb_io:
3284 case Hexagon::L4_iand_memopb_io:
3285 case Hexagon::L4_ior_memopb_io:
3286 case Hexagon::L4_and_memopb_io:
3287 case Hexagon::L4_or_memopb_io:
3288 return (0 <= Offset && Offset <= 63);
3289
3290 // LDriw_xxx and STriw_xxx are pseudo operations, so it has to take offset of
3291 // any size. Later pass knows how to handle it.
3292 case Hexagon::STriw_pred:
3293 case Hexagon::LDriw_pred:
3294 case Hexagon::STriw_ctr:
3295 case Hexagon::LDriw_ctr:
3296 return true;
3297
3298 case Hexagon::PS_fi:
3299 case Hexagon::PS_fia:
3300 case Hexagon::INLINEASM:
3301 return true;
3302
3303 case Hexagon::L2_ploadrbt_io:
3304 case Hexagon::L2_ploadrbf_io:
3305 case Hexagon::L2_ploadrubt_io:
3306 case Hexagon::L2_ploadrubf_io:
3307 case Hexagon::S2_pstorerbt_io:
3308 case Hexagon::S2_pstorerbf_io:
3309 return isUInt<6>(Offset);
3310
3311 case Hexagon::L2_ploadrht_io:
3312 case Hexagon::L2_ploadrhf_io:
3313 case Hexagon::L2_ploadruht_io:
3314 case Hexagon::L2_ploadruhf_io:
3315 case Hexagon::S2_pstorerht_io:
3316 case Hexagon::S2_pstorerhf_io:
3317 case Hexagon::S2_pstorerft_io:
3318 case Hexagon::S2_pstorerff_io:
3319 return isShiftedUInt<6,1>(Offset);
3320
3321 case Hexagon::L2_ploadrit_io:
3322 case Hexagon::L2_ploadrif_io:
3323 case Hexagon::S2_pstorerit_io:
3324 case Hexagon::S2_pstorerif_io:
3325 return isShiftedUInt<6,2>(Offset);
3326
3327 case Hexagon::L2_ploadrdt_io:
3328 case Hexagon::L2_ploadrdf_io:
3329 case Hexagon::S2_pstorerdt_io:
3330 case Hexagon::S2_pstorerdf_io:
3331 return isShiftedUInt<6,3>(Offset);
3332
3333 case Hexagon::L2_loadbsw2_io:
3334 case Hexagon::L2_loadbzw2_io:
3335 return isShiftedInt<11,1>(Offset);
3336
3337 case Hexagon::L2_loadbsw4_io:
3338 case Hexagon::L2_loadbzw4_io:
3339 return isShiftedInt<11,2>(Offset);
3340 } // switch
3341
3342 dbgs() << "Failed Opcode is : " << Opcode << " (" << getName(Opcode)
3343 << ")\n";
3344 llvm_unreachable("No offset range is defined for this opcode. "
3345 "Please define it in the above switch statement!");
3346}
3347
3349 return isHVXVec(MI) && isAccumulator(MI);
3350}
3351
3353 const uint64_t F = get(MI.getOpcode()).TSFlags;
3354 const uint64_t V = ((F >> HexagonII::TypePos) & HexagonII::TypeMask);
3355 return
3356 V == HexagonII::TypeCVI_VA ||
3358}
3359
3361 const MachineInstr &ConsMI) const {
3362 if (EnableACCForwarding && isVecAcc(ProdMI) && isVecAcc(ConsMI))
3363 return true;
3364
3365 if (EnableALUForwarding && (isVecALU(ConsMI) || isLateSourceInstr(ConsMI)))
3366 return true;
3367
3368 if (mayBeNewStore(ConsMI))
3369 return true;
3370
3371 return false;
3372}
3373
3375 switch (MI.getOpcode()) {
3376 // Byte
3377 case Hexagon::L2_loadrub_io:
3378 case Hexagon::L4_loadrub_ur:
3379 case Hexagon::L4_loadrub_ap:
3380 case Hexagon::L2_loadrub_pr:
3381 case Hexagon::L2_loadrub_pbr:
3382 case Hexagon::L2_loadrub_pi:
3383 case Hexagon::L2_loadrub_pci:
3384 case Hexagon::L2_loadrub_pcr:
3385 case Hexagon::L2_loadbzw2_io:
3386 case Hexagon::L4_loadbzw2_ur:
3387 case Hexagon::L4_loadbzw2_ap:
3388 case Hexagon::L2_loadbzw2_pr:
3389 case Hexagon::L2_loadbzw2_pbr:
3390 case Hexagon::L2_loadbzw2_pi:
3391 case Hexagon::L2_loadbzw2_pci:
3392 case Hexagon::L2_loadbzw2_pcr:
3393 case Hexagon::L2_loadbzw4_io:
3394 case Hexagon::L4_loadbzw4_ur:
3395 case Hexagon::L4_loadbzw4_ap:
3396 case Hexagon::L2_loadbzw4_pr:
3397 case Hexagon::L2_loadbzw4_pbr:
3398 case Hexagon::L2_loadbzw4_pi:
3399 case Hexagon::L2_loadbzw4_pci:
3400 case Hexagon::L2_loadbzw4_pcr:
3401 case Hexagon::L4_loadrub_rr:
3402 case Hexagon::L2_ploadrubt_io:
3403 case Hexagon::L2_ploadrubt_pi:
3404 case Hexagon::L2_ploadrubf_io:
3405 case Hexagon::L2_ploadrubf_pi:
3406 case Hexagon::L2_ploadrubtnew_io:
3407 case Hexagon::L2_ploadrubfnew_io:
3408 case Hexagon::L4_ploadrubt_rr:
3409 case Hexagon::L4_ploadrubf_rr:
3410 case Hexagon::L4_ploadrubtnew_rr:
3411 case Hexagon::L4_ploadrubfnew_rr:
3412 case Hexagon::L2_ploadrubtnew_pi:
3413 case Hexagon::L2_ploadrubfnew_pi:
3414 case Hexagon::L4_ploadrubt_abs:
3415 case Hexagon::L4_ploadrubf_abs:
3416 case Hexagon::L4_ploadrubtnew_abs:
3417 case Hexagon::L4_ploadrubfnew_abs:
3418 case Hexagon::L2_loadrubgp:
3419 // Half
3420 case Hexagon::L2_loadruh_io:
3421 case Hexagon::L4_loadruh_ur:
3422 case Hexagon::L4_loadruh_ap:
3423 case Hexagon::L2_loadruh_pr:
3424 case Hexagon::L2_loadruh_pbr:
3425 case Hexagon::L2_loadruh_pi:
3426 case Hexagon::L2_loadruh_pci:
3427 case Hexagon::L2_loadruh_pcr:
3428 case Hexagon::L4_loadruh_rr:
3429 case Hexagon::L2_ploadruht_io:
3430 case Hexagon::L2_ploadruht_pi:
3431 case Hexagon::L2_ploadruhf_io:
3432 case Hexagon::L2_ploadruhf_pi:
3433 case Hexagon::L2_ploadruhtnew_io:
3434 case Hexagon::L2_ploadruhfnew_io:
3435 case Hexagon::L4_ploadruht_rr:
3436 case Hexagon::L4_ploadruhf_rr:
3437 case Hexagon::L4_ploadruhtnew_rr:
3438 case Hexagon::L4_ploadruhfnew_rr:
3439 case Hexagon::L2_ploadruhtnew_pi:
3440 case Hexagon::L2_ploadruhfnew_pi:
3441 case Hexagon::L4_ploadruht_abs:
3442 case Hexagon::L4_ploadruhf_abs:
3443 case Hexagon::L4_ploadruhtnew_abs:
3444 case Hexagon::L4_ploadruhfnew_abs:
3445 case Hexagon::L2_loadruhgp:
3446 return true;
3447 default:
3448 return false;
3449 }
3450}
3451
3452// Add latency to instruction.
3454 const MachineInstr &MI2) const {
3455 if (isHVXVec(MI1) && isHVXVec(MI2))
3456 if (!isVecUsableNextPacket(MI1, MI2))
3457 return true;
3458 return false;
3459}
3460
3461/// Get the base register and byte offset of a load/store instr.
3464 int64_t &Offset, bool &OffsetIsScalable, LocationSize &Width) const {
3465 OffsetIsScalable = false;
3466 const MachineOperand *BaseOp = getBaseAndOffset(LdSt, Offset, Width);
3467 if (!BaseOp || !BaseOp->isReg())
3468 return false;
3469 BaseOps.push_back(BaseOp);
3470 return true;
3471}
3472
3473/// Can these instructions execute at the same time in a bundle.
3475 const MachineInstr &Second) const {
3476 if (Second.mayStore() && First.getOpcode() == Hexagon::S2_allocframe) {
3477 const MachineOperand &Op = Second.getOperand(0);
3478 if (Op.isReg() && Op.isUse() && Op.getReg() == Hexagon::R29)
3479 return true;
3480 }
3482 return false;
3483 if (mayBeNewStore(Second)) {
3484 // Make sure the definition of the first instruction is the value being
3485 // stored.
3486 const MachineOperand &Stored =
3487 Second.getOperand(Second.getNumOperands() - 1);
3488 if (!Stored.isReg())
3489 return false;
3490 for (unsigned i = 0, e = First.getNumOperands(); i < e; ++i) {
3491 const MachineOperand &Op = First.getOperand(i);
3492 if (Op.isReg() && Op.isDef() && Op.getReg() == Stored.getReg())
3493 return true;
3494 }
3495 }
3496 return false;
3497}
3498
3500 unsigned Opc = CallMI.getOpcode();
3501 return Opc == Hexagon::PS_call_nr || Opc == Hexagon::PS_callr_nr;
3502}
3503
3505 for (auto &I : *B)
3506 if (I.isEHLabel())
3507 return true;
3508 return false;
3509}
3510
3511// Returns true if an instruction can be converted into a non-extended
3512// equivalent instruction.
3514 short NonExtOpcode;
3515 // Check if the instruction has a register form that uses register in place
3516 // of the extended operand, if so return that as the non-extended form.
3517 if (Hexagon::getRegForm(MI.getOpcode()) >= 0)
3518 return true;
3519
3520 if (MI.getDesc().mayLoad() || MI.getDesc().mayStore()) {
3521 // Check addressing mode and retrieve non-ext equivalent instruction.
3522
3523 switch (getAddrMode(MI)) {
3525 // Load/store with absolute addressing mode can be converted into
3526 // base+offset mode.
3527 NonExtOpcode = Hexagon::changeAddrMode_abs_io(MI.getOpcode());
3528 break;
3530 // Load/store with base+offset addressing mode can be converted into
3531 // base+register offset addressing mode. However left shift operand should
3532 // be set to 0.
3533 NonExtOpcode = Hexagon::changeAddrMode_io_rr(MI.getOpcode());
3534 break;
3536 NonExtOpcode = Hexagon::changeAddrMode_ur_rr(MI.getOpcode());
3537 break;
3538 default:
3539 return false;
3540 }
3541 if (NonExtOpcode < 0)
3542 return false;
3543 return true;
3544 }
3545 return false;
3546}
3547
3549 const {
3550 MachineBasicBlock::const_iterator I = B->getFirstTerminator(), E = B->end();
3551 while (I != E) {
3552 if (I->isBarrier())
3553 return true;
3554 ++I;
3555 }
3556 return false;
3557}
3558
3559// Returns true, if a LD insn can be promoted to a cur load.
3561 const uint64_t F = MI.getDesc().TSFlags;
3563 Subtarget.hasV60Ops();
3564}
3565
3566// Returns true, if a ST insn can be promoted to a new-value store.
3568 if (MI.mayStore() && !Subtarget.useNewValueStores())
3569 return false;
3570
3571 const uint64_t F = MI.getDesc().TSFlags;
3573}
3574
3576 return MI.getOpcode() == Hexagon::LX_L16b_pseudo;
3577}
3578
3580 return MI.getOpcode() == Hexagon::LX_S16b_pseudo;
3581}
3582
3584 const MachineInstr &ConsMI) const {
3585 // There is no stall when ProdMI is not a V60 vector.
3586 if (!isHVXVec(ProdMI))
3587 return false;
3588
3589 // There is no stall when ProdMI and ConsMI are not dependent.
3590 if (!isDependent(ProdMI, ConsMI))
3591 return false;
3592
3593 // When Forward Scheduling is enabled, there is no stall if ProdMI and ConsMI
3594 // are scheduled in consecutive packets.
3595 if (isVecUsableNextPacket(ProdMI, ConsMI))
3596 return false;
3597
3598 return true;
3599}
3600
3603 // There is no stall when I is not a V60 vector.
3604 if (!isHVXVec(MI))
3605 return false;
3606
3608 MachineBasicBlock::const_instr_iterator MIE = MII->getParent()->instr_end();
3609
3610 if (!MII->isBundle())
3611 return producesStall(*MII, MI);
3612
3613 for (++MII; MII != MIE && MII->isInsideBundle(); ++MII) {
3614 const MachineInstr &J = *MII;
3615 if (producesStall(J, MI))
3616 return true;
3617 }
3618 return false;
3619}
3620
3622 Register PredReg) const {
3623 for (const MachineOperand &MO : MI.operands()) {
3624 // Predicate register must be explicitly defined.
3625 if (MO.isRegMask() && MO.clobbersPhysReg(PredReg))
3626 return false;
3627 if (MO.isReg() && MO.isDef() && MO.isImplicit() && (MO.getReg() == PredReg))
3628 return false;
3629 }
3630
3631 // Instruction that produce late predicate cannot be used as sources of
3632 // dot-new.
3633 switch (MI.getOpcode()) {
3634 case Hexagon::A4_addp_c:
3635 case Hexagon::A4_subp_c:
3636 case Hexagon::A4_tlbmatch:
3637 case Hexagon::A5_ACS:
3638 case Hexagon::F2_sfinvsqrta:
3639 case Hexagon::F2_sfrecipa:
3640 case Hexagon::J2_endloop0:
3641 case Hexagon::J2_endloop01:
3642 case Hexagon::J2_ploop1si:
3643 case Hexagon::J2_ploop1sr:
3644 case Hexagon::J2_ploop2si:
3645 case Hexagon::J2_ploop2sr:
3646 case Hexagon::J2_ploop3si:
3647 case Hexagon::J2_ploop3sr:
3648 case Hexagon::S2_cabacdecbin:
3649 case Hexagon::S2_storew_locked:
3650 case Hexagon::S4_stored_locked:
3651 return false;
3652 }
3653 return true;
3654}
3655
3656bool HexagonInstrInfo::PredOpcodeHasJMP_c(unsigned Opcode) const {
3657 return Opcode == Hexagon::J2_jumpt ||
3658 Opcode == Hexagon::J2_jumptpt ||
3659 Opcode == Hexagon::J2_jumpf ||
3660 Opcode == Hexagon::J2_jumpfpt ||
3661 Opcode == Hexagon::J2_jumptnew ||
3662 Opcode == Hexagon::J2_jumpfnew ||
3663 Opcode == Hexagon::J2_jumptnewpt ||
3664 Opcode == Hexagon::J2_jumpfnewpt;
3665}
3666
3668 if (Cond.empty() || !isPredicated(Cond[0].getImm()))
3669 return false;
3670 return !isPredicatedTrue(Cond[0].getImm());
3671}
3672
3674 const uint64_t F = MI.getDesc().TSFlags;
3676}
3677
3678// Returns the base register in a memory access (load/store). The offset is
3679// returned in Offset and the access size is returned in AccessSize.
3680// If the base operand has a subregister or the offset field does not contain
3681// an immediate value, return nullptr.
3684 LocationSize &AccessSize) const {
3685 // Return if it is not a base+offset type instruction or a MemOp.
3689 return nullptr;
3690
3692
3693 unsigned BasePos = 0, OffsetPos = 0;
3694 if (!getBaseAndOffsetPosition(MI, BasePos, OffsetPos))
3695 return nullptr;
3696
3697 // Post increment updates its EA after the mem access,
3698 // so we need to treat its offset as zero.
3699 if (isPostIncrement(MI)) {
3700 Offset = 0;
3701 } else {
3702 const MachineOperand &OffsetOp = MI.getOperand(OffsetPos);
3703 if (!OffsetOp.isImm())
3704 return nullptr;
3705 Offset = OffsetOp.getImm();
3706 }
3707
3708 const MachineOperand &BaseOp = MI.getOperand(BasePos);
3709 if (BaseOp.getSubReg() != 0)
3710 return nullptr;
3711 return &const_cast<MachineOperand&>(BaseOp);
3712}
3713
3714/// Return the position of the base and offset operands for this instruction.
3716 unsigned &BasePos, unsigned &OffsetPos) const {
3718 return false;
3719
3720 // Deal with memops first.
3721 if (isMemOp(MI)) {
3722 BasePos = 0;
3723 OffsetPos = 1;
3724 } else if (MI.mayStore()) {
3725 BasePos = 0;
3726 OffsetPos = 1;
3727 } else if (MI.mayLoad()) {
3728 BasePos = 1;
3729 OffsetPos = 2;
3730 } else
3731 return false;
3732
3733 if (isPredicated(MI)) {
3734 BasePos++;
3735 OffsetPos++;
3736 }
3737 if (isPostIncrement(MI)) {
3738 BasePos++;
3739 OffsetPos++;
3740 }
3741
3742 if (!MI.getOperand(BasePos).isReg() || !MI.getOperand(OffsetPos).isImm())
3743 return false;
3744
3745 return true;
3746}
3747
3748// Inserts branching instructions in reverse order of their occurrence.
3749// e.g. jump_t t1 (i1)
3750// jump t2 (i2)
3751// Jumpers = {i2, i1}
3753 MachineBasicBlock& MBB) const {
3755 // If the block has no terminators, it just falls into the block after it.
3757 if (I == MBB.instr_begin())
3758 return Jumpers;
3759
3760 // A basic block may looks like this:
3761 //
3762 // [ insn
3763 // EH_LABEL
3764 // insn
3765 // insn
3766 // insn
3767 // EH_LABEL
3768 // insn ]
3769 //
3770 // It has two succs but does not have a terminator
3771 // Don't know how to handle it.
3772 do {
3773 --I;
3774 if (I->isEHLabel())
3775 return Jumpers;
3776 } while (I != MBB.instr_begin());
3777
3778 I = MBB.instr_end();
3779 --I;
3780
3781 while (I->isDebugInstr()) {
3782 if (I == MBB.instr_begin())
3783 return Jumpers;
3784 --I;
3785 }
3786 if (!isUnpredicatedTerminator(*I))
3787 return Jumpers;
3788
3789 // Get the last instruction in the block.
3790 MachineInstr *LastInst = &*I;
3791 Jumpers.push_back(LastInst);
3792 MachineInstr *SecondLastInst = nullptr;
3793 // Find one more terminator if present.
3794 do {
3795 if (&*I != LastInst && !I->isBundle() && isUnpredicatedTerminator(*I)) {
3796 if (!SecondLastInst) {
3797 SecondLastInst = &*I;
3798 Jumpers.push_back(SecondLastInst);
3799 } else // This is a third branch.
3800 return Jumpers;
3801 }
3802 if (I == MBB.instr_begin())
3803 break;
3804 --I;
3805 } while (true);
3806 return Jumpers;
3807}
3808
3809// Returns Operand Index for the constant extended instruction.
3811 const uint64_t F = MI.getDesc().TSFlags;
3813}
3814
3815// See if instruction could potentially be a duplex candidate.
3816// If so, return its group. Zero otherwise.
3818 const MachineInstr &MI) const {
3819 Register DstReg, SrcReg, Src1Reg, Src2Reg;
3820
3821 switch (MI.getOpcode()) {
3822 default:
3823 return HexagonII::HCG_None;
3824 //
3825 // Compound pairs.
3826 // "p0=cmp.eq(Rs16,Rt16); if (p0.new) jump:nt #r9:2"
3827 // "Rd16=#U6 ; jump #r9:2"
3828 // "Rd16=Rs16 ; jump #r9:2"
3829 //
3830 case Hexagon::C2_cmpeq:
3831 case Hexagon::C2_cmpgt:
3832 case Hexagon::C2_cmpgtu:
3833 DstReg = MI.getOperand(0).getReg();
3834 Src1Reg = MI.getOperand(1).getReg();
3835 Src2Reg = MI.getOperand(2).getReg();
3836 if (Hexagon::PredRegsRegClass.contains(DstReg) &&
3837 (Hexagon::P0 == DstReg || Hexagon::P1 == DstReg) &&
3838 isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg))
3839 return HexagonII::HCG_A;
3840 break;
3841 case Hexagon::C2_cmpeqi:
3842 case Hexagon::C2_cmpgti:
3843 case Hexagon::C2_cmpgtui:
3844 // P0 = cmp.eq(Rs,#u2)
3845 DstReg = MI.getOperand(0).getReg();
3846 SrcReg = MI.getOperand(1).getReg();
3847 if (Hexagon::PredRegsRegClass.contains(DstReg) &&
3848 (Hexagon::P0 == DstReg || Hexagon::P1 == DstReg) &&
3849 isIntRegForSubInst(SrcReg) && MI.getOperand(2).isImm() &&
3850 ((isUInt<5>(MI.getOperand(2).getImm())) ||
3851 (MI.getOperand(2).getImm() == -1)))
3852 return HexagonII::HCG_A;
3853 break;
3854 case Hexagon::A2_tfr:
3855 // Rd = Rs
3856 DstReg = MI.getOperand(0).getReg();
3857 SrcReg = MI.getOperand(1).getReg();
3858 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg))
3859 return HexagonII::HCG_A;
3860 break;
3861 case Hexagon::A2_tfrsi:
3862 // Rd = #u6
3863 // Do not test for #u6 size since the const is getting extended
3864 // regardless and compound could be formed.
3865 DstReg = MI.getOperand(0).getReg();
3866 if (isIntRegForSubInst(DstReg))
3867 return HexagonII::HCG_A;
3868 break;
3869 case Hexagon::S2_tstbit_i:
3870 DstReg = MI.getOperand(0).getReg();
3871 Src1Reg = MI.getOperand(1).getReg();
3872 if (Hexagon::PredRegsRegClass.contains(DstReg) &&
3873 (Hexagon::P0 == DstReg || Hexagon::P1 == DstReg) &&
3874 MI.getOperand(2).isImm() &&
3875 isIntRegForSubInst(Src1Reg) && (MI.getOperand(2).getImm() == 0))
3876 return HexagonII::HCG_A;
3877 break;
3878 // The fact that .new form is used pretty much guarantees
3879 // that predicate register will match. Nevertheless,
3880 // there could be some false positives without additional
3881 // checking.
3882 case Hexagon::J2_jumptnew:
3883 case Hexagon::J2_jumpfnew:
3884 case Hexagon::J2_jumptnewpt:
3885 case Hexagon::J2_jumpfnewpt:
3886 Src1Reg = MI.getOperand(0).getReg();
3887 if (Hexagon::PredRegsRegClass.contains(Src1Reg) &&
3888 (Hexagon::P0 == Src1Reg || Hexagon::P1 == Src1Reg))
3889 return HexagonII::HCG_B;
3890 break;
3891 // Transfer and jump:
3892 // Rd=#U6 ; jump #r9:2
3893 // Rd=Rs ; jump #r9:2
3894 // Do not test for jump range here.
3895 case Hexagon::J2_jump:
3896 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4:
3897 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC:
3898 return HexagonII::HCG_C;
3899 }
3900
3901 return HexagonII::HCG_None;
3902}
3903
3904// Returns -1 when there is no opcode found.
3906 const MachineInstr &GB) const {
3909 if ((GA.getOpcode() != Hexagon::C2_cmpeqi) ||
3910 (GB.getOpcode() != Hexagon::J2_jumptnew))
3911 return -1u;
3912 Register DestReg = GA.getOperand(0).getReg();
3913 if (!GB.readsRegister(DestReg, /*TRI=*/nullptr))
3914 return -1u;
3915 if (DestReg != Hexagon::P0 && DestReg != Hexagon::P1)
3916 return -1u;
3917 // The value compared against must be either u5 or -1.
3918 const MachineOperand &CmpOp = GA.getOperand(2);
3919 if (!CmpOp.isImm())
3920 return -1u;
3921 int V = CmpOp.getImm();
3922 if (V == -1)
3923 return DestReg == Hexagon::P0 ? Hexagon::J4_cmpeqn1_tp0_jump_nt
3924 : Hexagon::J4_cmpeqn1_tp1_jump_nt;
3925 if (!isUInt<5>(V))
3926 return -1u;
3927 return DestReg == Hexagon::P0 ? Hexagon::J4_cmpeqi_tp0_jump_nt
3928 : Hexagon::J4_cmpeqi_tp1_jump_nt;
3929}
3930
3931// Returns -1 if there is no opcode found.
3933 bool ForBigCore) const {
3934 // Static table to switch the opcodes across Tiny Core and Big Core.
3935 // dup_ opcodes are Big core opcodes.
3936 // NOTE: There are special instructions that need to handled later.
3937 // L4_return* instructions, they will only occupy SLOT0 (on big core too).
3938 // PS_jmpret - This pseudo translates to J2_jumpr which occupies only SLOT2.
3939 // The compiler need to base the root instruction to L6_return_map_to_raw
3940 // which can go any slot.
3941 static const std::map<unsigned, unsigned> DupMap = {
3942 {Hexagon::A2_add, Hexagon::dup_A2_add},
3943 {Hexagon::A2_addi, Hexagon::dup_A2_addi},
3944 {Hexagon::A2_andir, Hexagon::dup_A2_andir},
3945 {Hexagon::A2_combineii, Hexagon::dup_A2_combineii},
3946 {Hexagon::A2_sxtb, Hexagon::dup_A2_sxtb},
3947 {Hexagon::A2_sxth, Hexagon::dup_A2_sxth},
3948 {Hexagon::A2_tfr, Hexagon::dup_A2_tfr},
3949 {Hexagon::A2_tfrsi, Hexagon::dup_A2_tfrsi},
3950 {Hexagon::A2_zxtb, Hexagon::dup_A2_zxtb},
3951 {Hexagon::A2_zxth, Hexagon::dup_A2_zxth},
3952 {Hexagon::A4_combineii, Hexagon::dup_A4_combineii},
3953 {Hexagon::A4_combineir, Hexagon::dup_A4_combineir},
3954 {Hexagon::A4_combineri, Hexagon::dup_A4_combineri},
3955 {Hexagon::C2_cmoveif, Hexagon::dup_C2_cmoveif},
3956 {Hexagon::C2_cmoveit, Hexagon::dup_C2_cmoveit},
3957 {Hexagon::C2_cmovenewif, Hexagon::dup_C2_cmovenewif},
3958 {Hexagon::C2_cmovenewit, Hexagon::dup_C2_cmovenewit},
3959 {Hexagon::C2_cmpeqi, Hexagon::dup_C2_cmpeqi},
3960 {Hexagon::L2_deallocframe, Hexagon::dup_L2_deallocframe},
3961 {Hexagon::L2_loadrb_io, Hexagon::dup_L2_loadrb_io},
3962 {Hexagon::L2_loadrd_io, Hexagon::dup_L2_loadrd_io},
3963 {Hexagon::L2_loadrh_io, Hexagon::dup_L2_loadrh_io},
3964 {Hexagon::L2_loadri_io, Hexagon::dup_L2_loadri_io},
3965 {Hexagon::L2_loadrub_io, Hexagon::dup_L2_loadrub_io},
3966 {Hexagon::L2_loadruh_io, Hexagon::dup_L2_loadruh_io},
3967 {Hexagon::S2_allocframe, Hexagon::dup_S2_allocframe},
3968 {Hexagon::S2_storerb_io, Hexagon::dup_S2_storerb_io},
3969 {Hexagon::S2_storerd_io, Hexagon::dup_S2_storerd_io},
3970 {Hexagon::S2_storerh_io, Hexagon::dup_S2_storerh_io},
3971 {Hexagon::S2_storeri_io, Hexagon::dup_S2_storeri_io},
3972 {Hexagon::S4_storeirb_io, Hexagon::dup_S4_storeirb_io},
3973 {Hexagon::S4_storeiri_io, Hexagon::dup_S4_storeiri_io},
3974 };
3975 unsigned OpNum = MI.getOpcode();
3976 // Conversion to Big core.
3977 if (ForBigCore) {
3978 auto Iter = DupMap.find(OpNum);
3979 if (Iter != DupMap.end())
3980 return Iter->second;
3981 } else { // Conversion to Tiny core.
3982 for (const auto &Iter : DupMap)
3983 if (Iter.second == OpNum)
3984 return Iter.first;
3985 }
3986 return -1;
3987}
3988
3989int HexagonInstrInfo::getCondOpcode(int Opc, bool invertPredicate) const {
3990 enum Hexagon::PredSense inPredSense;
3991 inPredSense = invertPredicate ? Hexagon::PredSense_false :
3992 Hexagon::PredSense_true;
3993 int CondOpcode = Hexagon::getPredOpcode(Opc, inPredSense);
3994 if (CondOpcode >= 0) // Valid Conditional opcode/instruction
3995 return CondOpcode;
3996
3997 llvm_unreachable("Unexpected predicable instruction");
3998}
3999
4000// Return the cur value instruction for a given store.
4002 switch (MI.getOpcode()) {
4003 default: llvm_unreachable("Unknown .cur type");
4004 case Hexagon::V6_vL32b_pi:
4005 return Hexagon::V6_vL32b_cur_pi;
4006 case Hexagon::V6_vL32b_ai:
4007 return Hexagon::V6_vL32b_cur_ai;
4008 case Hexagon::V6_vL32b_nt_pi:
4009 return Hexagon::V6_vL32b_nt_cur_pi;
4010 case Hexagon::V6_vL32b_nt_ai:
4011 return Hexagon::V6_vL32b_nt_cur_ai;
4012 case Hexagon::V6_vL32b_ppu:
4013 return Hexagon::V6_vL32b_cur_ppu;
4014 case Hexagon::V6_vL32b_nt_ppu:
4015 return Hexagon::V6_vL32b_nt_cur_ppu;
4016 }
4017 return 0;
4018}
4019
4020// Return the regular version of the .cur instruction.
4022 switch (MI.getOpcode()) {
4023 default: llvm_unreachable("Unknown .cur type");
4024 case Hexagon::V6_vL32b_cur_pi:
4025 return Hexagon::V6_vL32b_pi;
4026 case Hexagon::V6_vL32b_cur_ai:
4027 return Hexagon::V6_vL32b_ai;
4028 case Hexagon::V6_vL32b_nt_cur_pi:
4029 return Hexagon::V6_vL32b_nt_pi;
4030 case Hexagon::V6_vL32b_nt_cur_ai:
4031 return Hexagon::V6_vL32b_nt_ai;
4032 case Hexagon::V6_vL32b_cur_ppu:
4033 return Hexagon::V6_vL32b_ppu;
4034 case Hexagon::V6_vL32b_nt_cur_ppu:
4035 return Hexagon::V6_vL32b_nt_ppu;
4036 }
4037 return 0;
4038}
4039
4040// The diagram below shows the steps involved in the conversion of a predicated
4041// store instruction to its .new predicated new-value form.
4042//
4043// Note: It doesn't include conditional new-value stores as they can't be
4044// converted to .new predicate.
4045//
4046// p.new NV store [ if(p0.new)memw(R0+#0)=R2.new ]
4047// ^ ^
4048// / \ (not OK. it will cause new-value store to be
4049// / X conditional on p0.new while R2 producer is
4050// / \ on p0)
4051// / \.
4052// p.new store p.old NV store
4053// [if(p0.new)memw(R0+#0)=R2] [if(p0)memw(R0+#0)=R2.new]
4054// ^ ^
4055// \ /
4056// \ /
4057// \ /
4058// p.old store
4059// [if (p0)memw(R0+#0)=R2]
4060//
4061// The following set of instructions further explains the scenario where
4062// conditional new-value store becomes invalid when promoted to .new predicate
4063// form.
4064//
4065// { 1) if (p0) r0 = add(r1, r2)
4066// 2) p0 = cmp.eq(r3, #0) }
4067//
4068// 3) if (p0) memb(r1+#0) = r0 --> this instruction can't be grouped with
4069// the first two instructions because in instr 1, r0 is conditional on old value
4070// of p0 but its use in instr 3 is conditional on p0 modified by instr 2 which
4071// is not valid for new-value stores.
4072// Predicated new value stores (i.e. if (p0) memw(..)=r0.new) are excluded
4073// from the "Conditional Store" list. Because a predicated new value store
4074// would NOT be promoted to a double dot new store. See diagram below:
4075// This function returns yes for those stores that are predicated but not
4076// yet promoted to predicate dot new instructions.
4077//
4078// +---------------------+
4079// /-----| if (p0) memw(..)=r0 |---------\~
4080// || +---------------------+ ||
4081// promote || /\ /\ || promote
4082// || /||\ /||\ ||
4083// \||/ demote || \||/
4084// \/ || || \/
4085// +-------------------------+ || +-------------------------+
4086// | if (p0.new) memw(..)=r0 | || | if (p0) memw(..)=r0.new |
4087// +-------------------------+ || +-------------------------+
4088// || || ||
4089// || demote \||/
4090// promote || \/ NOT possible
4091// || || /\~
4092// \||/ || /||\~
4093// \/ || ||
4094// +-----------------------------+
4095// | if (p0.new) memw(..)=r0.new |
4096// +-----------------------------+
4097// Double Dot New Store
4098//
4099// Returns the most basic instruction for the .new predicated instructions and
4100// new-value stores.
4101// For example, all of the following instructions will be converted back to the
4102// same instruction:
4103// 1) if (p0.new) memw(R0+#0) = R1.new --->
4104// 2) if (p0) memw(R0+#0)= R1.new -------> if (p0) memw(R0+#0) = R1
4105// 3) if (p0.new) memw(R0+#0) = R1 --->
4106//
4107// To understand the translation of instruction 1 to its original form, consider
4108// a packet with 3 instructions.
4109// { p0 = cmp.eq(R0,R1)
4110// if (p0.new) R2 = add(R3, R4)
4111// R5 = add (R3, R1)
4112// }
4113// if (p0) memw(R5+#0) = R2 <--- trying to include it in the previous packet
4114//
4115// This instruction can be part of the previous packet only if both p0 and R2
4116// are promoted to .new values. This promotion happens in steps, first
4117// predicate register is promoted to .new and in the next iteration R2 is
4118// promoted. Therefore, in case of dependence check failure (due to R5) during
4119// next iteration, it should be converted back to its most basic form.
4120
4121// Return the new value instruction for a given store.
4123 int NVOpcode = Hexagon::getNewValueOpcode(MI.getOpcode());
4124 if (NVOpcode >= 0) // Valid new-value store instruction.
4125 return NVOpcode;
4126
4127 switch (MI.getOpcode()) {
4128 default:
4129 report_fatal_error(Twine("Unknown .new type: ") +
4130 std::to_string(MI.getOpcode()));
4131 case Hexagon::S4_storerb_ur:
4132 return Hexagon::S4_storerbnew_ur;
4133
4134 case Hexagon::S2_storerb_pci:
4135 return Hexagon::S2_storerb_pci;
4136
4137 case Hexagon::S2_storeri_pci:
4138 return Hexagon::S2_storeri_pci;
4139
4140 case Hexagon::S2_storerh_pci:
4141 return Hexagon::S2_storerh_pci;
4142
4143 case Hexagon::S2_storerd_pci:
4144 return Hexagon::S2_storerd_pci;
4145
4146 case Hexagon::S2_storerf_pci:
4147 return Hexagon::S2_storerf_pci;
4148
4149 case Hexagon::V6_vS32b_ai:
4150 return Hexagon::V6_vS32b_new_ai;
4151
4152 case Hexagon::V6_vS32b_pi:
4153 return Hexagon::V6_vS32b_new_pi;
4154 }
4155 return 0;
4156}
4157
4158// Returns the opcode to use when converting MI, which is a conditional jump,
4159// into a conditional instruction which uses the .new value of the predicate.
4160// We also use branch probabilities to add a hint to the jump.
4161// If MBPI is null, all edges will be treated as equally likely for the
4162// purposes of establishing a predication hint.
4164 const MachineBranchProbabilityInfo *MBPI) const {
4165 // We assume that block can have at most two successors.
4166 const MachineBasicBlock *Src = MI.getParent();
4167 const MachineOperand &BrTarget = MI.getOperand(1);
4168 bool Taken = false;
4169 const BranchProbability OneHalf(1, 2);
4170
4171 auto getEdgeProbability = [MBPI] (const MachineBasicBlock *Src,
4172 const MachineBasicBlock *Dst) {
4173 if (MBPI)
4174 return MBPI->getEdgeProbability(Src, Dst);
4175 return BranchProbability(1, Src->succ_size());
4176 };
4177
4178 if (BrTarget.isMBB()) {
4179 const MachineBasicBlock *Dst = BrTarget.getMBB();
4180 Taken = getEdgeProbability(Src, Dst) >= OneHalf;
4181 } else {
4182 // The branch target is not a basic block (most likely a function).
4183 // Since BPI only gives probabilities for targets that are basic blocks,
4184 // try to identify another target of this branch (potentially a fall-
4185 // -through) and check the probability of that target.
4186 //
4187 // The only handled branch combinations are:
4188 // - one conditional branch,
4189 // - one conditional branch followed by one unconditional branch.
4190 // Otherwise, assume not-taken.
4191 assert(MI.isConditionalBranch());
4192 const MachineBasicBlock &B = *MI.getParent();
4193 bool SawCond = false, Bad = false;
4194 for (const MachineInstr &I : B) {
4195 if (!I.isBranch())
4196 continue;
4197 if (I.isConditionalBranch()) {
4198 SawCond = true;
4199 if (&I != &MI) {
4200 Bad = true;
4201 break;
4202 }
4203 }
4204 if (I.isUnconditionalBranch() && !SawCond) {
4205 Bad = true;
4206 break;
4207 }
4208 }
4209 if (!Bad) {
4211 MachineBasicBlock::const_instr_iterator NextIt = std::next(It);
4212 if (NextIt == B.instr_end()) {
4213 // If this branch is the last, look for the fall-through block.
4214 for (const MachineBasicBlock *SB : B.successors()) {
4215 if (!B.isLayoutSuccessor(SB))
4216 continue;
4217 Taken = getEdgeProbability(Src, SB) < OneHalf;
4218 break;
4219 }
4220 } else {
4221 assert(NextIt->isUnconditionalBranch());
4222 // Find the first MBB operand and assume it's the target.
4223 const MachineBasicBlock *BT = nullptr;
4224 for (const MachineOperand &Op : NextIt->operands()) {
4225 if (!Op.isMBB())
4226 continue;
4227 BT = Op.getMBB();
4228 break;
4229 }
4230 Taken = BT && getEdgeProbability(Src, BT) < OneHalf;
4231 }
4232 } // if (!Bad)
4233 }
4234
4235 // The Taken flag should be set to something reasonable by this point.
4236
4237 switch (MI.getOpcode()) {
4238 case Hexagon::J2_jumpt:
4239 return Taken ? Hexagon::J2_jumptnewpt : Hexagon::J2_jumptnew;
4240 case Hexagon::J2_jumpf:
4241 return Taken ? Hexagon::J2_jumpfnewpt : Hexagon::J2_jumpfnew;
4242
4243 default:
4244 llvm_unreachable("Unexpected jump instruction.");
4245 }
4246}
4247
4248// Return .new predicate version for an instruction.
4250 const MachineBranchProbabilityInfo *MBPI) const {
4251 switch (MI.getOpcode()) {
4252 // Conditional Jumps
4253 case Hexagon::J2_jumpt:
4254 case Hexagon::J2_jumpf:
4255 return getDotNewPredJumpOp(MI, MBPI);
4256 }
4257
4258 int NewOpcode = Hexagon::getPredNewOpcode(MI.getOpcode());
4259 if (NewOpcode >= 0)
4260 return NewOpcode;
4261 return 0;
4262}
4263
4265 int NewOp = MI.getOpcode();
4266 if (isPredicated(NewOp) && isPredicatedNew(NewOp)) { // Get predicate old form
4267 NewOp = Hexagon::getPredOldOpcode(NewOp);
4268 // All Hexagon architectures have prediction bits on dot-new branches,
4269 // but only Hexagon V60+ has prediction bits on dot-old ones. Make sure
4270 // to pick the right opcode when converting back to dot-old.
4271 if (!Subtarget.hasFeature(Hexagon::ArchV60)) {
4272 switch (NewOp) {
4273 case Hexagon::J2_jumptpt:
4274 NewOp = Hexagon::J2_jumpt;
4275 break;
4276 case Hexagon::J2_jumpfpt:
4277 NewOp = Hexagon::J2_jumpf;
4278 break;
4279 case Hexagon::J2_jumprtpt:
4280 NewOp = Hexagon::J2_jumprt;
4281 break;
4282 case Hexagon::J2_jumprfpt:
4283 NewOp = Hexagon::J2_jumprf;
4284 break;
4285 }
4286 }
4287 assert(NewOp >= 0 &&
4288 "Couldn't change predicate new instruction to its old form.");
4289 }
4290
4291 if (isNewValueStore(NewOp)) { // Convert into non-new-value format
4292 NewOp = Hexagon::getNonNVStore(NewOp);
4293 assert(NewOp >= 0 && "Couldn't change new-value store to its old form.");
4294 }
4295
4296 if (Subtarget.hasV60Ops())
4297 return NewOp;
4298
4299 // Subtargets prior to V60 didn't support 'taken' forms of predicated jumps.
4300 switch (NewOp) {
4301 case Hexagon::J2_jumpfpt:
4302 return Hexagon::J2_jumpf;
4303 case Hexagon::J2_jumptpt:
4304 return Hexagon::J2_jumpt;
4305 case Hexagon::J2_jumprfpt:
4306 return Hexagon::J2_jumprf;
4307 case Hexagon::J2_jumprtpt:
4308 return Hexagon::J2_jumprt;
4309 }
4310 return NewOp;
4311}
4312
4313// See if instruction could potentially be a duplex candidate.
4314// If so, return its group. Zero otherwise.
4316 const MachineInstr &MI) const {
4317 Register DstReg, SrcReg, Src1Reg, Src2Reg;
4318 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
4319
4320 switch (MI.getOpcode()) {
4321 default:
4322 return HexagonII::HSIG_None;
4323 //
4324 // Group L1:
4325 //
4326 // Rd = memw(Rs+#u4:2)
4327 // Rd = memub(Rs+#u4:0)
4328 case Hexagon::L2_loadri_io:
4329 case Hexagon::dup_L2_loadri_io:
4330 DstReg = MI.getOperand(0).getReg();
4331 SrcReg = MI.getOperand(1).getReg();
4332 // Special case this one from Group L2.
4333 // Rd = memw(r29+#u5:2)
4334 if (isIntRegForSubInst(DstReg)) {
4335 if (Hexagon::IntRegsRegClass.contains(SrcReg) &&
4336 HRI.getStackRegister() == SrcReg &&
4337 MI.getOperand(2).isImm() &&
4338 isShiftedUInt<5,2>(MI.getOperand(2).getImm()))
4339 return HexagonII::HSIG_L2;
4340 // Rd = memw(Rs+#u4:2)
4341 if (isIntRegForSubInst(SrcReg) &&
4342 (MI.getOperand(2).isImm() &&
4343 isShiftedUInt<4,2>(MI.getOperand(2).getImm())))
4344 return HexagonII::HSIG_L1;
4345 }
4346 break;
4347 case Hexagon::L2_loadrub_io:
4348 case Hexagon::dup_L2_loadrub_io:
4349 // Rd = memub(Rs+#u4:0)
4350 DstReg = MI.getOperand(0).getReg();
4351 SrcReg = MI.getOperand(1).getReg();
4352 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) &&
4353 MI.getOperand(2).isImm() && isUInt<4>(MI.getOperand(2).getImm()))
4354 return HexagonII::HSIG_L1;
4355 break;
4356 //
4357 // Group L2:
4358 //
4359 // Rd = memh/memuh(Rs+#u3:1)
4360 // Rd = memb(Rs+#u3:0)
4361 // Rd = memw(r29+#u5:2) - Handled above.
4362 // Rdd = memd(r29+#u5:3)
4363 // deallocframe
4364 // [if ([!]p0[.new])] dealloc_return
4365 // [if ([!]p0[.new])] jumpr r31
4366 case Hexagon::L2_loadrh_io:
4367 case Hexagon::L2_loadruh_io:
4368 case Hexagon::dup_L2_loadrh_io:
4369 case Hexagon::dup_L2_loadruh_io:
4370 // Rd = memh/memuh(Rs+#u3:1)
4371 DstReg = MI.getOperand(0).getReg();
4372 SrcReg = MI.getOperand(1).getReg();
4373 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) &&
4374 MI.getOperand(2).isImm() &&
4375 isShiftedUInt<3,1>(MI.getOperand(2).getImm()))
4376 return HexagonII::HSIG_L2;
4377 break;
4378 case Hexagon::L2_loadrb_io:
4379 case Hexagon::dup_L2_loadrb_io:
4380 // Rd = memb(Rs+#u3:0)
4381 DstReg = MI.getOperand(0).getReg();
4382 SrcReg = MI.getOperand(1).getReg();
4383 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) &&
4384 MI.getOperand(2).isImm() &&
4385 isUInt<3>(MI.getOperand(2).getImm()))
4386 return HexagonII::HSIG_L2;
4387 break;
4388 case Hexagon::L2_loadrd_io:
4389 case Hexagon::dup_L2_loadrd_io:
4390 // Rdd = memd(r29+#u5:3)
4391 DstReg = MI.getOperand(0).getReg();
4392 SrcReg = MI.getOperand(1).getReg();
4393 if (isDblRegForSubInst(DstReg, HRI) &&
4394 Hexagon::IntRegsRegClass.contains(SrcReg) &&
4395 HRI.getStackRegister() == SrcReg &&
4396 MI.getOperand(2).isImm() &&
4397 isShiftedUInt<5,3>(MI.getOperand(2).getImm()))
4398 return HexagonII::HSIG_L2;
4399 break;
4400 // dealloc_return is not documented in Hexagon Manual, but marked
4401 // with A_SUBINSN attribute in iset_v4classic.py.
4402 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4:
4403 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC:
4404 case Hexagon::L4_return:
4405 case Hexagon::L2_deallocframe:
4406 case Hexagon::dup_L2_deallocframe:
4407 return HexagonII::HSIG_L2;
4408 case Hexagon::EH_RETURN_JMPR:
4409 case Hexagon::PS_jmpret:
4410 case Hexagon::SL2_jumpr31:
4411 // jumpr r31
4412 // Actual form JMPR implicit-def %pc, implicit %r31, implicit internal %r0
4413 DstReg = MI.getOperand(0).getReg();
4414 if (Hexagon::IntRegsRegClass.contains(DstReg) && (Hexagon::R31 == DstReg))
4415 return HexagonII::HSIG_L2;
4416 break;
4417 case Hexagon::PS_jmprett:
4418 case Hexagon::PS_jmpretf:
4419 case Hexagon::PS_jmprettnewpt:
4420 case Hexagon::PS_jmpretfnewpt:
4421 case Hexagon::PS_jmprettnew:
4422 case Hexagon::PS_jmpretfnew:
4423 case Hexagon::SL2_jumpr31_t:
4424 case Hexagon::SL2_jumpr31_f:
4425 case Hexagon::SL2_jumpr31_tnew:
4426 case Hexagon::SL2_jumpr31_fnew:
4427 DstReg = MI.getOperand(1).getReg();
4428 SrcReg = MI.getOperand(0).getReg();
4429 // [if ([!]p0[.new])] jumpr r31
4430 if ((Hexagon::PredRegsRegClass.contains(SrcReg) &&
4431 (Hexagon::P0 == SrcReg)) &&
4432 (Hexagon::IntRegsRegClass.contains(DstReg) && (Hexagon::R31 == DstReg)))
4433 return HexagonII::HSIG_L2;
4434 break;
4435 case Hexagon::L4_return_t:
4436 case Hexagon::L4_return_f:
4437 case Hexagon::L4_return_tnew_pnt:
4438 case Hexagon::L4_return_fnew_pnt:
4439 case Hexagon::L4_return_tnew_pt:
4440 case Hexagon::L4_return_fnew_pt:
4441 // [if ([!]p0[.new])] dealloc_return
4442 SrcReg = MI.getOperand(0).getReg();
4443 if (Hexagon::PredRegsRegClass.contains(SrcReg) && (Hexagon::P0 == SrcReg))
4444 return HexagonII::HSIG_L2;
4445 break;
4446 //
4447 // Group S1:
4448 //
4449 // memw(Rs+#u4:2) = Rt
4450 // memb(Rs+#u4:0) = Rt
4451 case Hexagon::S2_storeri_io:
4452 case Hexagon::dup_S2_storeri_io:
4453 // Special case this one from Group S2.
4454 // memw(r29+#u5:2) = Rt
4455 Src1Reg = MI.getOperand(0).getReg();
4456 Src2Reg = MI.getOperand(2).getReg();
4457 if (Hexagon::IntRegsRegClass.contains(Src1Reg) &&
4458 isIntRegForSubInst(Src2Reg) &&
4459 HRI.getStackRegister() == Src1Reg && MI.getOperand(1).isImm() &&
4460 isShiftedUInt<5,2>(MI.getOperand(1).getImm()))
4461 return HexagonII::HSIG_S2;
4462 // memw(Rs+#u4:2) = Rt
4463 if (isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg) &&
4464 MI.getOperand(1).isImm() &&
4465 isShiftedUInt<4,2>(MI.getOperand(1).getImm()))
4466 return HexagonII::HSIG_S1;
4467 break;
4468 case Hexagon::S2_storerb_io:
4469 case Hexagon::dup_S2_storerb_io:
4470 // memb(Rs+#u4:0) = Rt
4471 Src1Reg = MI.getOperand(0).getReg();
4472 Src2Reg = MI.getOperand(2).getReg();
4473 if (isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg) &&
4474 MI.getOperand(1).isImm() && isUInt<4>(MI.getOperand(1).getImm()))
4475 return HexagonII::HSIG_S1;
4476 break;
4477 //
4478 // Group S2:
4479 //
4480 // memh(Rs+#u3:1) = Rt
4481 // memw(r29+#u5:2) = Rt
4482 // memd(r29+#s6:3) = Rtt
4483 // memw(Rs+#u4:2) = #U1
4484 // memb(Rs+#u4) = #U1
4485 // allocframe(#u5:3)
4486 case Hexagon::S2_storerh_io:
4487 case Hexagon::dup_S2_storerh_io:
4488 // memh(Rs+#u3:1) = Rt
4489 Src1Reg = MI.getOperand(0).getReg();
4490 Src2Reg = MI.getOperand(2).getReg();
4491 if (isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg) &&
4492 MI.getOperand(1).isImm() &&
4493 isShiftedUInt<3,1>(MI.getOperand(1).getImm()))
4494 return HexagonII::HSIG_S1;
4495 break;
4496 case Hexagon::S2_storerd_io:
4497 case Hexagon::dup_S2_storerd_io:
4498 // memd(r29+#s6:3) = Rtt
4499 Src1Reg = MI.getOperand(0).getReg();
4500 Src2Reg = MI.getOperand(2).getReg();
4501 if (isDblRegForSubInst(Src2Reg, HRI) &&
4502 Hexagon::IntRegsRegClass.contains(Src1Reg) &&
4503 HRI.getStackRegister() == Src1Reg && MI.getOperand(1).isImm() &&
4504 isShiftedInt<6,3>(MI.getOperand(1).getImm()))
4505 return HexagonII::HSIG_S2;
4506 break;
4507 case Hexagon::S4_storeiri_io:
4508 case Hexagon::dup_S4_storeiri_io:
4509 // memw(Rs+#u4:2) = #U1
4510 Src1Reg = MI.getOperand(0).getReg();
4511 if (isIntRegForSubInst(Src1Reg) && MI.getOperand(1).isImm() &&
4512 isShiftedUInt<4,2>(MI.getOperand(1).getImm()) &&
4513 MI.getOperand(2).isImm() && isUInt<1>(MI.getOperand(2).getImm()))
4514 return HexagonII::HSIG_S2;
4515 break;
4516 case Hexagon::S4_storeirb_io:
4517 case Hexagon::dup_S4_storeirb_io:
4518 // memb(Rs+#u4) = #U1
4519 Src1Reg = MI.getOperand(0).getReg();
4520 if (isIntRegForSubInst(Src1Reg) &&
4521 MI.getOperand(1).isImm() && isUInt<4>(MI.getOperand(1).getImm()) &&
4522 MI.getOperand(2).isImm() && isUInt<1>(MI.getOperand(2).getImm()))
4523 return HexagonII::HSIG_S2;
4524 break;
4525 case Hexagon::S2_allocframe:
4526 case Hexagon::dup_S2_allocframe:
4527 if (MI.getOperand(2).isImm() &&
4528 isShiftedUInt<5,3>(MI.getOperand(2).getImm()))
4529 return HexagonII::HSIG_S1;
4530 break;
4531 //
4532 // Group A:
4533 //
4534 // Rx = add(Rx,#s7)
4535 // Rd = Rs
4536 // Rd = #u6
4537 // Rd = #-1
4538 // if ([!]P0[.new]) Rd = #0
4539 // Rd = add(r29,#u6:2)
4540 // Rx = add(Rx,Rs)
4541 // P0 = cmp.eq(Rs,#u2)
4542 // Rdd = combine(#0,Rs)
4543 // Rdd = combine(Rs,#0)
4544 // Rdd = combine(#u2,#U2)
4545 // Rd = add(Rs,#1)
4546 // Rd = add(Rs,#-1)
4547 // Rd = sxth/sxtb/zxtb/zxth(Rs)
4548 // Rd = and(Rs,#1)
4549 case Hexagon::A2_addi:
4550 case Hexagon::dup_A2_addi:
4551 DstReg = MI.getOperand(0).getReg();
4552 SrcReg = MI.getOperand(1).getReg();
4553 if (isIntRegForSubInst(DstReg)) {
4554 // Rd = add(r29,#u6:2)
4555 if (Hexagon::IntRegsRegClass.contains(SrcReg) &&
4556 HRI.getStackRegister() == SrcReg && MI.getOperand(2).isImm() &&
4557 isShiftedUInt<6,2>(MI.getOperand(2).getImm()))
4558 return HexagonII::HSIG_A;
4559 // Rx = add(Rx,#s7)
4560 if ((DstReg == SrcReg) && MI.getOperand(2).isImm() &&
4561 isInt<7>(MI.getOperand(2).getImm()))
4562 return HexagonII::HSIG_A;
4563 // Rd = add(Rs,#1)
4564 // Rd = add(Rs,#-1)
4565 if (isIntRegForSubInst(SrcReg) && MI.getOperand(2).isImm() &&
4566 ((MI.getOperand(2).getImm() == 1) ||
4567 (MI.getOperand(2).getImm() == -1)))
4568 return HexagonII::HSIG_A;
4569 }
4570 break;
4571 case Hexagon::A2_add:
4572 case Hexagon::dup_A2_add:
4573 // Rx = add(Rx,Rs)
4574 DstReg = MI.getOperand(0).getReg();
4575 Src1Reg = MI.getOperand(1).getReg();
4576 Src2Reg = MI.getOperand(2).getReg();
4577 if (isIntRegForSubInst(DstReg) && (DstReg == Src1Reg) &&
4578 isIntRegForSubInst(Src2Reg))
4579 return HexagonII::HSIG_A;
4580 break;
4581 case Hexagon::A2_andir:
4582 case Hexagon::dup_A2_andir:
4583 // Same as zxtb.
4584 // Rd16=and(Rs16,#255)
4585 // Rd16=and(Rs16,#1)
4586 DstReg = MI.getOperand(0).getReg();
4587 SrcReg = MI.getOperand(1).getReg();
4588 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) &&
4589 MI.getOperand(2).isImm() &&
4590 ((MI.getOperand(2).getImm() == 1) ||
4591 (MI.getOperand(2).getImm() == 255)))
4592 return HexagonII::HSIG_A;
4593 break;
4594 case Hexagon::A2_tfr:
4595 case Hexagon::dup_A2_tfr:
4596 // Rd = Rs
4597 DstReg = MI.getOperand(0).getReg();
4598 SrcReg = MI.getOperand(1).getReg();
4599 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg))
4600 return HexagonII::HSIG_A;
4601 break;
4602 case Hexagon::A2_tfrsi:
4603 case Hexagon::dup_A2_tfrsi:
4604 // Rd = #u6
4605 // Do not test for #u6 size since the const is getting extended
4606 // regardless and compound could be formed.
4607 // Rd = #-1
4608 DstReg = MI.getOperand(0).getReg();
4609 if (isIntRegForSubInst(DstReg))
4610 return HexagonII::HSIG_A;
4611 break;
4612 case Hexagon::C2_cmoveit:
4613 case Hexagon::C2_cmovenewit:
4614 case Hexagon::C2_cmoveif:
4615 case Hexagon::C2_cmovenewif:
4616 case Hexagon::dup_C2_cmoveit:
4617 case Hexagon::dup_C2_cmovenewit:
4618 case Hexagon::dup_C2_cmoveif:
4619 case Hexagon::dup_C2_cmovenewif:
4620 // if ([!]P0[.new]) Rd = #0
4621 // Actual form:
4622 // %r16 = C2_cmovenewit internal %p0, 0, implicit undef %r16;
4623 DstReg = MI.getOperand(0).getReg();
4624 SrcReg = MI.getOperand(1).getReg();
4625 if (isIntRegForSubInst(DstReg) &&
4626 Hexagon::PredRegsRegClass.contains(SrcReg) && Hexagon::P0 == SrcReg &&
4627 MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0)
4628 return HexagonII::HSIG_A;
4629 break;
4630 case Hexagon::C2_cmpeqi:
4631 case Hexagon::dup_C2_cmpeqi:
4632 // P0 = cmp.eq(Rs,#u2)
4633 DstReg = MI.getOperand(0).getReg();
4634 SrcReg = MI.getOperand(1).getReg();
4635 if (Hexagon::PredRegsRegClass.contains(DstReg) &&
4636 Hexagon::P0 == DstReg && isIntRegForSubInst(SrcReg) &&
4637 MI.getOperand(2).isImm() && isUInt<2>(MI.getOperand(2).getImm()))
4638 return HexagonII::HSIG_A;
4639 break;
4640 case Hexagon::A2_combineii:
4641 case Hexagon::A4_combineii:
4642 case Hexagon::dup_A2_combineii:
4643 case Hexagon::dup_A4_combineii:
4644 // Rdd = combine(#u2,#U2)
4645 DstReg = MI.getOperand(0).getReg();
4646 if (isDblRegForSubInst(DstReg, HRI) &&
4647 ((MI.getOperand(1).isImm() && isUInt<2>(MI.getOperand(1).getImm())) ||
4648 (MI.getOperand(1).isGlobal() &&
4649 isUInt<2>(MI.getOperand(1).getOffset()))) &&
4650 ((MI.getOperand(2).isImm() && isUInt<2>(MI.getOperand(2).getImm())) ||
4651 (MI.getOperand(2).isGlobal() &&
4652 isUInt<2>(MI.getOperand(2).getOffset()))))
4653 return HexagonII::HSIG_A;
4654 break;
4655 case Hexagon::A4_combineri:
4656 case Hexagon::dup_A4_combineri:
4657 // Rdd = combine(Rs,#0)
4658 // Rdd = combine(Rs,#0)
4659 DstReg = MI.getOperand(0).getReg();
4660 SrcReg = MI.getOperand(1).getReg();
4661 if (isDblRegForSubInst(DstReg, HRI) && isIntRegForSubInst(SrcReg) &&
4662 ((MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0) ||
4663 (MI.getOperand(2).isGlobal() && MI.getOperand(2).getOffset() == 0)))
4664 return HexagonII::HSIG_A;
4665 break;
4666 case Hexagon::A4_combineir:
4667 case Hexagon::dup_A4_combineir:
4668 // Rdd = combine(#0,Rs)
4669 DstReg = MI.getOperand(0).getReg();
4670 SrcReg = MI.getOperand(2).getReg();
4671 if (isDblRegForSubInst(DstReg, HRI) && isIntRegForSubInst(SrcReg) &&
4672 ((MI.getOperand(1).isImm() && MI.getOperand(1).getImm() == 0) ||
4673 (MI.getOperand(1).isGlobal() && MI.getOperand(1).getOffset() == 0)))
4674 return HexagonII::HSIG_A;
4675 break;
4676 case Hexagon::A2_sxtb:
4677 case Hexagon::A2_sxth:
4678 case Hexagon::A2_zxtb:
4679 case Hexagon::A2_zxth:
4680 case Hexagon::dup_A2_sxtb:
4681 case Hexagon::dup_A2_sxth:
4682 case Hexagon::dup_A2_zxtb:
4683 case Hexagon::dup_A2_zxth:
4684 // Rd = sxth/sxtb/zxtb/zxth(Rs)
4685 DstReg = MI.getOperand(0).getReg();
4686 SrcReg = MI.getOperand(1).getReg();
4687 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg))
4688 return HexagonII::HSIG_A;
4689 break;
4690 }
4691
4692 return HexagonII::HSIG_None;
4693}
4694
4696 const InstrItineraryData *ItinData, const MachineInstr &MI) const {
4697 // Default to one cycle for no itinerary. However, an "empty" itinerary may
4698 // still have a MinLatency property, which getStageLatency checks.
4699 if (!ItinData)
4700 return getInstrLatency(ItinData, MI);
4701
4702 if (MI.isTransient())
4703 return 0;
4704 return ItinData->getStageLatency(MI.getDesc().getSchedClass());
4705}
4706
4707/// getOperandLatency - Compute and return the use operand latency of a given
4708/// pair of def and use.
4709/// In most cases, the static scheduling itinerary was enough to determine the
4710/// operand latency. But it may not be possible for instructions with variable
4711/// number of defs / uses.
4712///
4713/// This is a raw interface to the itinerary that may be directly overridden by
4714/// a target. Use computeOperandLatency to get the best estimate of latency.
4716 const InstrItineraryData *ItinData, const MachineInstr &DefMI,
4717 unsigned DefIdx, const MachineInstr &UseMI, unsigned UseIdx) const {
4718 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
4719
4720 // Get DefIdx and UseIdx for super registers.
4721 const MachineOperand &DefMO = DefMI.getOperand(DefIdx);
4722
4723 if (DefMO.isReg() && DefMO.getReg().isPhysical()) {
4724 if (DefMO.isImplicit()) {
4725 for (MCPhysReg SR : HRI.superregs(DefMO.getReg())) {
4726 int Idx = DefMI.findRegisterDefOperandIdx(SR, &HRI, false, false);
4727 if (Idx != -1) {
4728 DefIdx = Idx;
4729 break;
4730 }
4731 }
4732 }
4733
4734 const MachineOperand &UseMO = UseMI.getOperand(UseIdx);
4735 if (UseMO.isImplicit()) {
4736 for (MCPhysReg SR : HRI.superregs(UseMO.getReg())) {
4737 int Idx = UseMI.findRegisterUseOperandIdx(SR, &HRI, false);
4738 if (Idx != -1) {
4739 UseIdx = Idx;
4740 break;
4741 }
4742 }
4743 }
4744 }
4745
4746 std::optional<unsigned> Latency = TargetInstrInfo::getOperandLatency(
4747 ItinData, DefMI, DefIdx, UseMI, UseIdx);
4748 if (Latency == 0)
4749 // We should never have 0 cycle latency between two instructions unless
4750 // they can be packetized together. However, this decision can't be made
4751 // here.
4752 Latency = 1;
4753 return Latency;
4754}
4755
4756// inverts the predication logic.
4757// p -> NotP
4758// NotP -> P
4761 if (Cond.empty())
4762 return false;
4763 unsigned Opc = getInvertedPredicatedOpcode(Cond[0].getImm());
4764 Cond[0].setImm(Opc);
4765 return true;
4766}
4767
4769 int InvPredOpcode;
4770 InvPredOpcode = isPredicatedTrue(Opc) ? Hexagon::getFalsePredOpcode(Opc)
4771 : Hexagon::getTruePredOpcode(Opc);
4772 if (InvPredOpcode >= 0) // Valid instruction with the inverted predicate.
4773 return InvPredOpcode;
4774
4775 llvm_unreachable("Unexpected predicated instruction");
4776}
4777
4778// Returns the max value that doesn't need to be extended.
4780 const uint64_t F = MI.getDesc().TSFlags;
4781 unsigned isSigned = (F >> HexagonII::ExtentSignedPos)
4783 unsigned bits = (F >> HexagonII::ExtentBitsPos)
4785
4786 if (isSigned) // if value is signed
4787 return ~(-1U << (bits - 1));
4788 else
4789 return ~(-1U << bits);
4790}
4791
4792
4794 switch (MI.getOpcode()) {
4795 case Hexagon::L2_loadrbgp:
4796 case Hexagon::L2_loadrdgp:
4797 case Hexagon::L2_loadrhgp:
4798 case Hexagon::L2_loadrigp:
4799 case Hexagon::L2_loadrubgp:
4800 case Hexagon::L2_loadruhgp:
4801 case Hexagon::S2_storerbgp:
4802 case Hexagon::S2_storerbnewgp:
4803 case Hexagon::S2_storerhgp:
4804 case Hexagon::S2_storerhnewgp:
4805 case Hexagon::S2_storerigp:
4806 case Hexagon::S2_storerinewgp:
4807 case Hexagon::S2_storerdgp:
4808 case Hexagon::S2_storerfgp:
4809 return true;
4810 }
4811 const uint64_t F = MI.getDesc().TSFlags;
4812 unsigned addrMode =
4814 // Disallow any base+offset instruction. The assembler does not yet reorder
4815 // based up any zero offset instruction.
4816 return (addrMode == HexagonII::BaseRegOffset ||
4817 addrMode == HexagonII::BaseImmOffset ||
4818 addrMode == HexagonII::BaseLongOffset);
4819}
4820
4822 // Workaround for the Global Scheduler. Sometimes, it creates
4823 // A4_ext as a Pseudo instruction and calls this function to see if
4824 // it can be added to an existing bundle. Since the instruction doesn't
4825 // belong to any BB yet, we can't use getUnits API.
4826 if (MI.getOpcode() == Hexagon::A4_ext)
4827 return false;
4828
4829 unsigned FuncUnits = getUnits(MI);
4830 return HexagonFUnits::isSlot0Only(FuncUnits);
4831}
4832
4834 const uint64_t F = MI.getDesc().TSFlags;
4837}
4838
4840 bool ToBigInstrs) const {
4841 int Opcode = -1;
4842 if (ToBigInstrs) { // To BigCore Instr.
4843 // Check if the instruction can form a Duplex.
4844 if (getDuplexCandidateGroup(*MII))
4845 // Get the opcode marked "dup_*" tag.
4846 Opcode = getDuplexOpcode(*MII, ToBigInstrs);
4847 } else // To TinyCore Instr.
4848 Opcode = getDuplexOpcode(*MII, ToBigInstrs);
4849
4850 // Change the opcode of the instruction.
4851 if (Opcode >= 0)
4852 MII->setDesc(get(Opcode));
4853}
4854
4855// This function is used to translate instructions to facilitate generating
4856// Duplexes on TinyCore.
4858 bool ToBigInstrs) const {
4859 for (auto &MB : MF)
4860 for (MachineBasicBlock::instr_iterator Instr = MB.instr_begin(),
4861 End = MB.instr_end();
4862 Instr != End; ++Instr)
4863 changeDuplexOpcode(Instr, ToBigInstrs);
4864}
4865
4866// This is a specialized form of above function.
4868 MachineBasicBlock::instr_iterator MII, bool ToBigInstrs) const {
4869 MachineBasicBlock *MBB = MII->getParent();
4870 while ((MII != MBB->instr_end()) && MII->isInsideBundle()) {
4871 changeDuplexOpcode(MII, ToBigInstrs);
4872 ++MII;
4873 }
4874}
4875
4877 using namespace HexagonII;
4878
4879 const uint64_t F = MI.getDesc().TSFlags;
4880 unsigned S = (F >> MemAccessSizePos) & MemAccesSizeMask;
4881 unsigned Size = getMemAccessSizeInBytes(MemAccessSize(S));
4882 if (Size != 0)
4883 return Size;
4884 // Y2_dcfetchbo is special
4885 if (MI.getOpcode() == Hexagon::Y2_dcfetchbo)
4887
4888 // Handle vector access sizes.
4889 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
4890 switch (S) {
4892 return HRI.getSpillSize(Hexagon::HvxVRRegClass);
4894 return HRI.getSpillSize(Hexagon::HlxLRRegClass);
4895 default:
4896 llvm_unreachable("Unexpected instruction");
4897 }
4898}
4899
4900// Returns the min value that doesn't need to be extended.
4902 const uint64_t F = MI.getDesc().TSFlags;
4903 unsigned isSigned = (F >> HexagonII::ExtentSignedPos)
4905 unsigned bits = (F >> HexagonII::ExtentBitsPos)
4907
4908 if (isSigned) // if value is signed
4909 return -1U << (bits - 1);
4910 else
4911 return 0;
4912}
4913
4914// Returns opcode of the non-extended equivalent instruction.
4916 // Check if the instruction has a register form that uses register in place
4917 // of the extended operand, if so return that as the non-extended form.
4918 short NonExtOpcode = Hexagon::getRegForm(MI.getOpcode());
4919 if (NonExtOpcode >= 0)
4920 return NonExtOpcode;
4921
4922 if (MI.getDesc().mayLoad() || MI.getDesc().mayStore()) {
4923 // Check addressing mode and retrieve non-ext equivalent instruction.
4924 switch (getAddrMode(MI)) {
4926 return Hexagon::changeAddrMode_abs_io(MI.getOpcode());
4928 return Hexagon::changeAddrMode_io_rr(MI.getOpcode());
4930 return Hexagon::changeAddrMode_ur_rr(MI.getOpcode());
4931
4932 default:
4933 return -1;
4934 }
4935 }
4936 return -1;
4937}
4938
4940 Register &PredReg, unsigned &PredRegPos,
4941 RegState &PredRegFlags) const {
4942 if (Cond.empty())
4943 return false;
4944 assert(Cond.size() == 2);
4945 if (isNewValueJump(Cond[0].getImm()) || Cond[1].isMBB()) {
4946 LLVM_DEBUG(dbgs() << "No predregs for new-value jumps/endloop");
4947 return false;
4948 }
4949 PredReg = Cond[1].getReg();
4950 PredRegPos = 1;
4951 // See IfConversion.cpp why we add RegState::Implicit | RegState::Undef
4952 PredRegFlags = {};
4953 if (Cond[1].isImplicit())
4954 PredRegFlags = RegState::Implicit;
4955 if (Cond[1].isUndef())
4956 PredRegFlags |= RegState::Undef;
4957 return true;
4958}
4959
4961 return Hexagon::getRegForm(MI.getOpcode());
4962}
4963
4964// Return the number of bytes required to encode the instruction.
4965// Hexagon instructions are fixed length, 4 bytes, unless they
4966// use a constant extender, which requires another 4 bytes.
4967// For debug instructions and prolog labels, return 0.
4969 if (MI.isDebugInstr() || MI.isPosition())
4970 return 0;
4971
4972 unsigned Size = MI.getDesc().getSize();
4973 if (!Size)
4974 // Assume the default insn size in case it cannot be determined
4975 // for whatever reason.
4977
4980
4981 // Try and compute number of instructions in asm.
4982 if (BranchRelaxAsmLarge && MI.getOpcode() == Hexagon::INLINEASM) {
4983 const MachineBasicBlock &MBB = *MI.getParent();
4984 const MachineFunction *MF = MBB.getParent();
4985 const MCAsmInfo &MAI = MF->getTarget().getMCAsmInfo();
4986
4987 // Count the number of register definitions to find the asm string.
4988 unsigned NumDefs = 0;
4989 for (; MI.getOperand(NumDefs).isReg() && MI.getOperand(NumDefs).isDef();
4990 ++NumDefs)
4991 assert(NumDefs != MI.getNumOperands()-2 && "No asm string?");
4992
4993 assert(MI.getOperand(NumDefs).isSymbol() && "No asm string?");
4994 // Disassemble the AsmStr and approximate number of instructions.
4995 const char *AsmStr = MI.getOperand(NumDefs).getSymbolName();
4996 Size = getInlineAsmLength(AsmStr, MAI);
4997 }
4998
4999 return Size;
5000}
5001
5003 const uint64_t F = MI.getDesc().TSFlags;
5005}
5006
5008 const InstrItineraryData &II = *Subtarget.getInstrItineraryData();
5009 const InstrStage &IS = *II.beginStage(MI.getDesc().getSchedClass());
5010
5011 return IS.getUnits();
5012}
5013
5014// Calculate size of the basic block without debug instructions.
5016 return nonDbgMICount(BB->instr_begin(), BB->instr_end());
5017}
5018
5020 MachineBasicBlock::const_iterator BundleHead) const {
5021 assert(BundleHead->isBundle() && "Not a bundle header");
5022 auto MII = BundleHead.getInstrIterator();
5023 // Skip the bundle header.
5024 return nonDbgMICount(++MII, getBundleEnd(BundleHead.getInstrIterator()));
5025}
5026
5027/// immediateExtend - Changes the instruction in place to one using an immediate
5028/// extender.
5031 "Instruction must be extendable");
5032 // Find which operand is extendable.
5033 short ExtOpNum = getCExtOpNum(MI);
5034 MachineOperand &MO = MI.getOperand(ExtOpNum);
5035 // This needs to be something we understand.
5036 assert((MO.isMBB() || MO.isImm()) &&
5037 "Branch with unknown extendable field type");
5038 // Mark given operand as extended.
5040}
5041
5043 MachineInstr &MI, MachineBasicBlock *NewTarget) const {
5044 LLVM_DEBUG(dbgs() << "\n[invertAndChangeJumpTarget] to "
5045 << printMBBReference(*NewTarget);
5046 MI.dump(););
5047 assert(MI.isBranch());
5048 unsigned NewOpcode = getInvertedPredicatedOpcode(MI.getOpcode());
5049 int TargetPos = MI.getNumOperands() - 1;
5050 // In general branch target is the last operand,
5051 // but some implicit defs added at the end might change it.
5052 while ((TargetPos > -1) && !MI.getOperand(TargetPos).isMBB())
5053 --TargetPos;
5054 assert((TargetPos >= 0) && MI.getOperand(TargetPos).isMBB());
5055 MI.getOperand(TargetPos).setMBB(NewTarget);
5057 NewOpcode = reversePrediction(NewOpcode);
5058 }
5059 MI.setDesc(get(NewOpcode));
5060 return true;
5061}
5062
5064 /* +++ The code below is used to generate complete set of Hexagon Insn +++ */
5066 MachineBasicBlock &B = *A;
5068 DebugLoc DL = I->getDebugLoc();
5069 MachineInstr *NewMI;
5070
5071 for (unsigned insn = TargetOpcode::GENERIC_OP_END+1;
5072 insn < Hexagon::INSTRUCTION_LIST_END; ++insn) {
5073 NewMI = BuildMI(B, I, DL, get(insn));
5074 LLVM_DEBUG(dbgs() << "\n"
5075 << getName(NewMI->getOpcode())
5076 << " Class: " << NewMI->getDesc().getSchedClass());
5077 NewMI->eraseFromParent();
5078 }
5079 /* --- The code above is used to generate complete set of Hexagon Insn --- */
5080}
5081
5082// inverts the predication logic.
5083// p -> NotP
5084// NotP -> P
5086 LLVM_DEBUG(dbgs() << "\nTrying to reverse pred. sense of:"; MI.dump());
5087 MI.setDesc(get(getInvertedPredicatedOpcode(MI.getOpcode())));
5088 return true;
5089}
5090
5091// Reverse the branch prediction.
5092unsigned HexagonInstrInfo::reversePrediction(unsigned Opcode) const {
5093 int PredRevOpcode = -1;
5094 if (isPredictedTaken(Opcode))
5095 PredRevOpcode = Hexagon::notTakenBranchPrediction(Opcode);
5096 else
5097 PredRevOpcode = Hexagon::takenBranchPrediction(Opcode);
5098 assert(PredRevOpcode > 0);
5099 return PredRevOpcode;
5100}
5101
5102// TODO: Add more rigorous validation.
5104 const {
5105 return Cond.empty() || (Cond[0].isImm() && (Cond.size() != 1));
5106}
5107
5110 assert(MIB->isBundle());
5111 MachineOperand &Operand = MIB->getOperand(0);
5112 if (Operand.isImm())
5113 Operand.setImm(Operand.getImm() | memShufDisabledMask);
5114 else
5115 MIB->addOperand(MachineOperand::CreateImm(memShufDisabledMask));
5116}
5117
5119 assert(MIB.isBundle());
5120 const MachineOperand &Operand = MIB.getOperand(0);
5121 return (Operand.isImm() && (Operand.getImm() & memShufDisabledMask) != 0);
5122}
5123
5125 return (MI->getOpcode() == Hexagon::V6_vmpy_qf16_hf ||
5126 MI->getOpcode() == Hexagon::V6_vmpy_qf16_mix_hf ||
5127 MI->getOpcode() == Hexagon::V6_vmpy_qf32_hf ||
5128 MI->getOpcode() == Hexagon::V6_vmpy_qf32_mix_hf ||
5129 MI->getOpcode() == Hexagon::V6_vmpy_qf32_sf ||
5130 MI->getOpcode() == Hexagon::V6_vmpy_qf16_mix_hf ||
5131 MI->getOpcode() == Hexagon::V6_vmpy_qf16 ||
5132 MI->getOpcode() == Hexagon::V6_vmpy_qf32_mix_hf ||
5133 MI->getOpcode() == Hexagon::V6_vmpy_qf32_qf16 ||
5134 MI->getOpcode() == Hexagon::V6_vmpy_qf32);
5135}
5136
5137namespace llvm::HexagonII {
5138
5141 RegType In3 = RegType::Unknown) {
5142 RegTypeInfo I;
5143 I.Output = Out;
5144 I.Input1 = In1;
5145 I.Input2 = In2;
5146 I.Input3 = In3;
5147 return I;
5148}
5149
5150RegTypeInfo getRegTypeInfo(unsigned Opcode) {
5151 switch (Opcode) {
5152 default:
5153 return {};
5154
5155 case Hexagon::V6_vabs_qf16_hf:
5156 return make(RegType::QF16);
5157 case Hexagon::V6_vabs_qf16_qf16:
5159 case Hexagon::V6_vabs_qf32_qf32:
5161 case Hexagon::V6_vabs_qf32_sf:
5162 return make(RegType::QF32);
5163 case Hexagon::V6_vadd_hf:
5164 return make(RegType::QF16);
5165 case Hexagon::V6_vadd_qf16:
5167 case Hexagon::V6_vadd_qf16_mix:
5169 case Hexagon::V6_vadd_qf32:
5171 case Hexagon::V6_vadd_qf32_mix:
5173 case Hexagon::V6_vadd_sf:
5174 return make(RegType::QF32);
5175 case Hexagon::V6_vconv_bf_qf32:
5177 case Hexagon::V6_vconv_f8_qf16:
5179 case Hexagon::V6_vconv_hf_qf16:
5181 case Hexagon::V6_vconv_hf_qf32:
5183 case Hexagon::V6_vconv_qf16_f8:
5184 return make(RegType::QF16);
5185 case Hexagon::V6_vconv_qf16_hf:
5186 return make(RegType::QF16);
5187 case Hexagon::V6_vconv_qf16_qf16:
5189 case Hexagon::V6_vconv_qf32_qf32:
5191 case Hexagon::V6_vconv_qf32_sf:
5192 return make(RegType::QF32);
5193 case Hexagon::V6_vconv_sf_qf32:
5195 case Hexagon::V6_vilog2_qf16:
5197 case Hexagon::V6_vilog2_qf32:
5199 case Hexagon::V6_vmpy_qf16:
5201 case Hexagon::V6_vmpy_qf16_hf:
5202 return make(RegType::QF16);
5203 case Hexagon::V6_vmpy_qf16_mix_hf:
5205 case Hexagon::V6_vmpy_qf32:
5207 case Hexagon::V6_vmpy_qf32_hf:
5208 return make(RegType::QF32);
5209 case Hexagon::V6_vmpy_qf32_mix_hf:
5211 case Hexagon::V6_vmpy_qf32_qf16:
5213 case Hexagon::V6_vmpy_qf32_sf:
5214 return make(RegType::QF32);
5215 case Hexagon::V6_vmpy_rt_hf:
5216 return make(RegType::QF16);
5217 case Hexagon::V6_vmpy_rt_qf16:
5219 case Hexagon::V6_vmpy_rt_sf:
5220 return make(RegType::QF32);
5221 case Hexagon::V6_vneg_qf16_hf:
5222 return make(RegType::QF16);
5223 case Hexagon::V6_vneg_qf16_qf16:
5225 case Hexagon::V6_vneg_qf32_qf32:
5227 case Hexagon::V6_vneg_qf32_sf:
5228 return make(RegType::QF32);
5229 case Hexagon::V6_vsub_hf:
5230 return make(RegType::QF16);
5231 case Hexagon::V6_vsub_qf16:
5233 case Hexagon::V6_vsub_qf16_mix:
5235 case Hexagon::V6_vsub_qf32:
5237 case Hexagon::V6_vsub_qf32_mix:
5239 case Hexagon::V6_vsub_sf:
5240 return make(RegType::QF32);
5241 case Hexagon::V6_vsub_sf_mix:
5243 case Hexagon::V6_vsub_hf_mix:
5245 }
5246}
5247
5248} // namespace llvm::HexagonII
5249
5251 auto Info = HexagonII::getRegTypeInfo(MI->getOpcode());
5252 switch (Index) {
5253 case 1:
5254 return Info.Input1 == HexagonII::RegType::QF32;
5255 case 2:
5256 return Info.Input2 == HexagonII::RegType::QF32;
5257 case 3:
5258 return Info.Input3 == HexagonII::RegType::QF32;
5259 case 0:
5260 return Info.Input1 == HexagonII::RegType::QF32 ||
5261 Info.Input2 == HexagonII::RegType::QF32 ||
5262 Info.Input3 == HexagonII::RegType::QF32;
5263 default: // No instruction with more than 3 operands uses QF32.
5264 return false;
5265 }
5266 return false;
5267}
5268
5270 auto Info = HexagonII::getRegTypeInfo(MI->getOpcode());
5271 switch (Index) {
5272 case 1:
5273 return Info.Input1 == HexagonII::RegType::QF16;
5274 case 2:
5275 return Info.Input2 == HexagonII::RegType::QF16;
5276 case 3:
5277 return Info.Input3 == HexagonII::RegType::QF16;
5278 case 0:
5279 return Info.Input1 == HexagonII::RegType::QF16 ||
5280 Info.Input2 == HexagonII::RegType::QF16 ||
5281 Info.Input3 == HexagonII::RegType::QF16;
5282 default: // No instruction with more than 3 operands uses QF16.
5283 return false;
5284 }
5285 return false;
5286}
5287
5289 return usesQF32Operand(MI, Index) || usesQF16Operand(MI, Index);
5290}
5291
5295
5299
5303
5304// Return true if the function contains any qf-generating instructions.
5306 for (const MachineBasicBlock &MBB : MF)
5307 for (const MachineInstr &MI : MBB)
5308 if (isQFPInstr(const_cast<MachineInstr *>(&MI)))
5309 return true;
5310 return false;
5311}
5312
5313// Returns true if A appears before B within the same basic block.
5315 const MachineInstr *B) const {
5316 if (!A || !B || A->getParent() != B->getParent())
5317 return false;
5318
5319 for (const MachineInstr &MI : *A->getParent()) {
5320 if (&MI == A)
5321 return true;
5322 if (&MI == B)
5323 return false;
5324 }
5325 return false;
5326}
5327
5328// Returns false if a call, or an instruction between MI and Second, changes a
5329// register MI reads, so MI cannot be copied to just after Second.
5331 const TargetRegisterInfo *TRI) {
5332 for (MachineInstr &Between :
5333 make_range(std::next(MI.getIterator()), Second.getIterator()))
5334 for (const MachineOperand &MO : MI.debug_operands())
5335 if (MO.isReg() && MO.getReg().isValid() &&
5336 (Between.isCall() || Between.modifiesRegister(MO.getReg(), TRI)))
5337 return false;
5338 return true;
5339}
5340
5342 MachineInstr &Second) const {
5343 MachineBasicBlock &MBB = *Second.getParent();
5344 MachineFunction &MF = *MBB.getParent();
5346 Register DefReg = First.getOperand(0).getReg();
5347 auto Gap = make_range(std::next(First.getIterator()), Second.getIterator());
5348
5349 // The variables with a value that reads DefReg. All values of these
5350 // variables are copied, so that their order holds.
5352 for (MachineInstr &MI : Gap)
5353 if (MI.isDebugValue() && !MI.isDebugEntryValue() &&
5354 MI.readsRegister(DefReg, TRI) &&
5355 !is_contained(Vars, MI.getDebugVariable()))
5356 Vars.push_back(MI.getDebugVariable());
5357
5359 for (MachineInstr &MI : Gap)
5360 if (MI.isDebugValue() && is_contained(Vars, MI.getDebugVariable()))
5361 Group.push_back(&MI);
5362
5363 bool CanMove = !Second.isTerminator();
5364 for (MachineInstr *MI : Group)
5365 CanMove = CanMove && canMoveDebugValue(*MI, Second, TRI);
5366
5367 // Computed once, so that the copies stay in order.
5368 MachineBasicBlock::iterator FinalPos = std::next(Second.getIterator());
5369 for (MachineInstr *MI : Group)
5370 if (CanMove)
5371 MBB.insert(FinalPos, MF.CloneMachineInstr(MI));
5372 for (MachineInstr *MI : Group)
5373 if (!MI->isDebugEntryValue() && MI->readsRegister(DefReg, TRI))
5374 MI->setDebugValueUndef();
5375}
5376
5377// Addressing mode relations.
5379 return Opc >= 0 ? Hexagon::changeAddrMode_abs_io(Opc) : Opc;
5380}
5381
5383 return Opc >= 0 ? Hexagon::changeAddrMode_io_abs(Opc) : Opc;
5384}
5385
5387 return Opc >= 0 ? Hexagon::changeAddrMode_io_pi(Opc) : Opc;
5388}
5389
5391 return Opc >= 0 ? Hexagon::changeAddrMode_io_rr(Opc) : Opc;
5392}
5393
5395 return Opc >= 0 ? Hexagon::changeAddrMode_pi_io(Opc) : Opc;
5396}
5397
5399 return Opc >= 0 ? Hexagon::changeAddrMode_rr_io(Opc) : Opc;
5400}
5401
5403 return Opc >= 0 ? Hexagon::changeAddrMode_rr_ur(Opc) : Opc;
5404}
5405
5407 return Opc >= 0 ? Hexagon::changeAddrMode_ur_rr(Opc) : Opc;
5408}
5409
5411 static const MCInst Nop = MCInstBuilder(Hexagon::A2_nop);
5412
5413 return MCInstBuilder(Hexagon::BUNDLE)
5414 .addImm(0)
5415 .addInst(&Nop);
5416}
5417
5418// Returns true if \p MI has any internal (same-packet, .new) register read.
5419static bool usesInternalDefs(const MachineInstr &MI) {
5420 for (const MachineOperand &MO : MI.operands())
5421 if (MO.isReg() && MO.isInternalRead())
5422 return true;
5423 return false;
5424}
5425
5429 const MIUseDefMap &MIUseDefs,
5431 bool PreventDuplexSep,
5432 bool IsPullDown) const {
5433 const HexagonRegisterInfo *TRI = Subtarget.getRegisterInfo();
5434
5435 // No src dependence for single instruction bundles.
5436 MachineInstr *BundleMI = &*SrcBeg;
5437 if (BundleMI->getBundleSize() == 1)
5439
5440 // An HVX instruction that would stall in this packet.
5441 if (producesStall(*RMII, SrcBeg))
5442 return Dependency::Unknown;
5443 unsigned Dep = Dependency::Independent;
5444 // Special checks for preventing duplex separation.
5445 bool IsDuplexCandidate = false;
5446 if (PreventDuplexSep &&
5448 IsDuplexCandidate = true;
5449
5450 MIUseDefMap::const_iterator MIUseDef = MIUseDefs.find(&*RMII);
5451 assert(MIUseDef != MIUseDefs.end());
5452 BitVector Uses = MIUseDef->second.first;
5453 BitVector Defs = MIUseDef->second.second;
5454
5455 // For global pullup, which does not need full cluster dependence checks,
5456 // reject MIs with multiple defs.
5457 if (!DepSet && Defs.count() > 1)
5459
5460 // Use all_defs()/all_uses() to include implicit register defs/uses.
5461 // Implicit defs (e.g. L2_deallocframe's implicit-def $r29) are real
5462 // register writes that establish dependencies with sibling instructions
5463 // in the same packet; missing them caused the pull-down RAW between
5464 // L2_deallocframe and a sibling load of $r29 to be ignored, producing a
5465 // functionally incorrect split.
5466 for (auto &RMIDef : RMII->all_defs()) {
5467 if (!RMIDef.isReg())
5468 continue;
5469 for (MCRegAliasIterator AI(RMIDef.getReg(), TRI, true); AI.isValid(); ++AI)
5470 Defs.set(*AI);
5471 }
5472 for (auto &RMIUse : RMII->all_uses()) {
5473 if (!RMIUse.isReg())
5474 continue;
5475 for (MCRegAliasIterator AI(RMIUse.getReg(), TRI, true); AI.isValid(); ++AI)
5476 Uses.set(*AI);
5477 }
5478
5479 // Avoid the local pullup of a load against a store when the bundle is
5480 // marked with disabled memory shuffling.
5481 if ((&*RMII)->mayLoad() && BundleMI->mayStore() && BundleMI->isBundle() &&
5482 getBundleNoShuf(*BundleMI))
5483 return Dependency::Unknown;
5484
5485 // If DepSet was provided, find all dependencies and add to the set.
5486 if (DepSet)
5487 DepSet->insert(&*RMII);
5488 else {
5489 if (isDotNewInst(*RMII) || usesInternalDefs(*RMII))
5491 }
5492 for (auto MII = SrcBeg; MII != SrcEnd; ++MII) {
5493 MachineInstr *MI = &*MII;
5494 if (MI == &*RMII)
5495 continue;
5496 // Make sure MI has defs or uses.
5497 MIUseDefMap::const_iterator MIUseDefP = MIUseDefs.find(MI);
5498 if (MIUseDefP == MIUseDefs.end()) {
5499 assert(MI->isBundle() || MI->isDebugInstr());
5500 continue;
5501 }
5502 if (PreventDuplexSep && IsDuplexCandidate && isDuplexPair(*RMII, *MI))
5503 return Dependency::Duplex;
5504
5505 // Check if use (.new) of RMII aliases with def (.tmp, .cur) of MI.
5506 for (auto &SrcDef : MI->all_defs()) {
5507 if (!SrcDef.isReg() || !Uses[SrcDef.getReg()])
5508 continue;
5509 int DefIdx = SrcDef.getOperandNo();
5510 int UseIdx = RMII->findRegisterUseOperandIdx(SrcDef.getReg(), TRI);
5511 if (UseIdx >= 0 && isDotNewOperand(*RMII, UseIdx)) {
5512 if (DepSet && DepSet->insert(MI).second)
5513 Dep |= srcDependence(SrcBeg, SrcEnd, MII, MIUseDefs, DepSet,
5514 PreventDuplexSep, IsPullDown);
5516 } else if (DefIdx >= 0 && (isDotTmpOperand(*MI, DefIdx) ||
5517 isDotCurOperand(*MI, DefIdx))) {
5518 if (DepSet && DepSet->insert(MI).second)
5519 Dep |= srcDependence(SrcBeg, SrcEnd, MII, MIUseDefs, DepSet,
5520 PreventDuplexSep, IsPullDown);
5522 } else if (DepSet && IsPullDown) {
5523 // Pull-down: RMII's regular read of MI's def must move with MI.
5524 if (DepSet->insert(MI).second)
5525 Dep |= srcDependence(SrcBeg, SrcEnd, MII, MIUseDefs, DepSet,
5526 PreventDuplexSep, IsPullDown);
5528 }
5529 // Regular def of MI could alias with regular use of RMII.
5530 // Safe to pullup RMII in this case.
5531 }
5532 // Check if def (.tmp, .cur) of RMII aliases with use (.new) of MI.
5533 // Regular def of RMII should not alias with regular use.
5534 for (auto &SrcUse : MI->all_uses()) {
5535 if (!SrcUse.isReg() || !Defs[SrcUse.getReg()])
5536 continue;
5537 int DefIdx = RMII->findRegisterDefOperandIdx(SrcUse.getReg(), TRI);
5538 if (isDotNewOperand(*MI, SrcUse.getOperandNo())) {
5539 if (DepSet && DepSet->insert(MI).second)
5540 Dep |= srcDependence(SrcBeg, SrcEnd, MII, MIUseDefs, DepSet,
5541 PreventDuplexSep, IsPullDown);
5543 } else if (DefIdx >= 0 && (isDotTmpOperand(*RMII, DefIdx) ||
5544 isDotCurOperand(*RMII, DefIdx))) {
5545 if (DepSet && DepSet->insert(MI).second)
5546 Dep |= srcDependence(SrcBeg, SrcEnd, MII, MIUseDefs, DepSet,
5547 PreventDuplexSep, IsPullDown);
5549 } else if (DepSet) {
5550 // Regular def of RMII aliases with regular use of MI.
5551 // Pullup for RMII is legal only if MI is pulled up along with RMII.
5552 if (DepSet->insert(MI).second)
5553 Dep |= srcDependence(SrcBeg, SrcEnd, MII, MIUseDefs, DepSet,
5554 PreventDuplexSep, IsPullDown);
5556 } else {
5557 // If only RMII is being pulled up, regular def of RMII should not
5558 // alias with regular use.
5559 return Dependency::WAR;
5560 }
5561 }
5562 // Def of RMII can only alias with def on MI, if one of them is .tmp.
5563 // .tmp does not write to register file, so there cannot be a dependency.
5564 }
5565 return Dep;
5566}
5567
5569 for (const MachineOperand &MO : MI.operands()) {
5570 if (MO.isReg() && MO.isDef() && MO.getReg().isPhysical())
5571 if (Hexagon::PredRegsRegClass.contains(MO.getReg()))
5572 return true;
5573 }
5574 return false;
5575}
5576
5577std::optional<unsigned>
5579
5580 switch (OpC) {
5581 // compares
5582 case Hexagon::C2_cmpeqi:
5583 return Hexagon::C4_cmpneqi;
5584 case Hexagon::C4_cmpneqi:
5585 return Hexagon::C2_cmpeqi;
5586 case Hexagon::C2_cmpgti:
5587 return Hexagon::C4_cmpltei;
5588 case Hexagon::C4_cmpltei:
5589 return Hexagon::C2_cmpgti;
5590 case Hexagon::C2_cmpgtui:
5591 return Hexagon::C4_cmplteui;
5592 case Hexagon::C4_cmplteui:
5593 return Hexagon::C2_cmpgtui;
5594 case Hexagon::C2_cmpeq:
5595 return Hexagon::C4_cmpneq;
5596 case Hexagon::C4_cmpneq:
5597 return Hexagon::C2_cmpeq;
5598 case Hexagon::C2_cmpgt:
5599 return Hexagon::C4_cmplte;
5600 case Hexagon::C4_cmplte:
5601 return Hexagon::C2_cmpgt;
5602 case Hexagon::C2_cmpgtu:
5603 return Hexagon::C4_cmplteu;
5604 case Hexagon::C4_cmplteu:
5605 return Hexagon::C2_cmpgtu;
5606 // bitmask and bitset
5607 case Hexagon::C2_bitsclri:
5608 return Hexagon::C4_nbitsclri;
5609 case Hexagon::C4_nbitsclri:
5610 return Hexagon::C2_bitsclri;
5611 case Hexagon::C2_bitsclr:
5612 return Hexagon::C4_nbitsclr;
5613 case Hexagon::C4_nbitsclr:
5614 return Hexagon::C2_bitsclr;
5615 case Hexagon::C2_bitsset:
5616 return Hexagon::C4_nbitsset;
5617 case Hexagon::C4_nbitsset:
5618 return Hexagon::C2_bitsset;
5619 // tstbit
5620 case Hexagon::S2_tstbit_i:
5621 return Hexagon::S4_ntstbit_i;
5622 case Hexagon::S4_ntstbit_i:
5623 return Hexagon::S2_tstbit_i;
5624 case Hexagon::S2_tstbit_r:
5625 return Hexagon::S4_ntstbit_r;
5626 case Hexagon::S4_ntstbit_r:
5627 return Hexagon::S2_tstbit_r;
5628 // FIXME: vector cmp bytes for any match?
5629 default:
5630 return std::nullopt;
5631 }
5632}
5633
5635 const MachineInstr &MI) const {
5636 auto OpC = MI.getOpcode();
5637 return OpC == Hexagon::J2_ploop1sr || OpC == Hexagon::J2_ploop2sr ||
5638 OpC == Hexagon::J2_ploop3sr || OpC == Hexagon::J2_ploop1si ||
5639 OpC == Hexagon::J2_ploop2si || OpC == Hexagon::J2_ploop3si;
5640}
5641
5643 const MCInstrDesc &D = MI.getDesc();
5644 return isFloat(MI) && D.isCompare();
5645}
5646
5649 MachineBasicBlock::const_instr_iterator MIEnd, unsigned Reg,
5650 const TargetRegisterInfo &TRI) const {
5651 for (auto I = MIBegin; I != MIEnd; ++I) {
5652 const MachineInstr &MI = *I;
5653 if (MI.isBundle() || MI.isDebugInstr())
5654 continue;
5655 if (!MI.isCall())
5656 continue;
5657 if (MI.readsRegister(Reg, &TRI))
5658 return true;
5659 }
5660 return false;
5661}
5662
5663/// findInstrPredicate - Set the predicate of the instruction
5664/// in the specified predicate vector
5665/// First entry is the opcode, subsequent entries can be used to
5666/// reproduce the predication.
5669 if (isNewValueJump(*MI)) {
5670 LLVM_DEBUG(dbgs() << "\nPredication in NV-jump different from other ins.");
5671 return;
5672 }
5673 MachineFunction &MF = *MI->getParent()->getParent();
5674 const auto &HRI = *MF.getSubtarget<HexagonSubtarget>().getRegisterInfo();
5675
5676 for (unsigned oper = 0; oper < MI->getNumOperands(); ++oper) {
5677 MachineOperand MO = MI->getOperand(oper);
5678 if (MO.isReg() && MO.isUse()) {
5679 if (HRI.isFakeReg(MO.getReg()))
5680 continue;
5681 const TargetRegisterClass *RC = HRI.getMinimalPhysRegClass(MO.getReg());
5682 if ((RC == &Hexagon::PredRegsRegClass) &&
5683 !MI->definesRegister(MO.getReg(), &HRI)) {
5684 Cond.push_back(MachineOperand::CreateImm(MI->getOpcode()));
5685 Cond.push_back(MO);
5686 return;
5687 }
5688 }
5689 }
5690}
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
static bool mayAlias(MachineInstr &MIa, SmallVectorImpl< MachineInstr * > &MemInsns, AliasAnalysis *AA)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t Imm
static bool isConstant(const MachineInstr &MI)
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static const Function * getParent(const Value *V)
BitTracker BT
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
DXIL Forward Handle Accesses
static bool isSigned(unsigned Opcode)
const HexagonInstrInfo * TII
static cl::opt< bool > PreventDuplexSep("prevent-duplex-sep-v2", cl::Hidden, cl::init(true), cl::desc("Prevent separation of duplex while pullup in global scheduler V2"))
static void parseOperands(MachineInstr *MI, SmallVector< unsigned, 4 > &Defs, SmallVector< unsigned, 8 > &Uses)
Gather register def/uses from MI.
static bool usesInternalDefs(const MachineInstr &MI)
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"))
static bool isUnsafeMemoryObject(const MachineInstr *MI)
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 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 bool canMoveDebugValue(MachineInstr &MI, MachineInstr &Second, const TargetRegisterInfo *TRI)
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
std::pair< Instruction::BinaryOps, Value * > OffsetOp
Find all possible pairs (BinOp, RHS) that BinOp V, RHS can be simplified.
static constexpr Value * getValue(Ty &ValueOrUse)
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
SmallVector< MachineOperand, 4 > Cond
unsigned Opc
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first DebugLoc that has line number information, given a range of instructions.
static bool isUndef(const MachineInstr &MI)
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define T
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static bool isReg(const MCInst &MI, unsigned OpNo)
uint64_t IntrinsicInst * II
PassBuilder PB(Mod->getContext(), Machine, PassOpts->PTO, std::nullopt, &PIC)
if(PassOpts->AAPipeline)
static StringRef getName(Value *V)
static bool isBranch(unsigned Opcode)
MachineRegisterInfo & MRI
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
Remove Loads Into Fake Uses
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:479
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file contains some functions that are useful when dealing with strings.
#define LLVM_DEBUG(...)
Definition Debug.h:119
The possible results of an alias query.
@ NoAlias
The two locations do not alias at all.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_type count() const
Returns the number of bits which are set.
Definition BitVector.h:182
BitVector & set()
Set all bits in the bitvector.
Definition BitVector.h:367
A debug info location.
Definition DebugLoc.h:126
iterator find(const_arg_type_t< KeyT > Val)
Definition DenseMap.h:766
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
Definition DenseMap.h:679
iterator end()
Definition DenseMap.h:686
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool isTmpLoadPseudo(const MachineInstr &MI) const
int getDuplexOpcode(const MachineInstr &MI, bool ForBigCore=true) const
bool isHLXVec(const MachineInstr &MI) 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 definesPredicateReg(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...
unsigned getInlineAsmLength(const char *Str, const MCAsmInfo &MAI, unsigned MaxInstLength=0) const override
Measure the specified inline asm to determine an approximation of its length.
bool getMemOperandsWithOffsetWidth(const MachineInstr &LdSt, SmallVectorImpl< const MachineOperand * > &BaseOps, int64_t &Offset, bool &OffsetIsScalable, LocationSize &Width) const override
Get the base register and byte offset of a load/store instr.
bool producesStall(const MachineInstr &ProdMI, const MachineInstr &ConsMI) const
bool invertAndChangeJumpTarget(MachineInstr &MI, MachineBasicBlock *NewTarget) const
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, 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 isDotTmpInst(const MachineInstr &MI) const
bool isSoftwarePipelineLoopInstr(const MachineInstr &MI) const
bool isPredictedTaken(unsigned Opcode) const
bool isSaveCalleeSavedRegsCall(const MachineInstr &MI) const
bool hasQFPInstrs(const MachineFunction &MF) 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 isQFP32Instr(MachineInstr *MI) 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 usesQF16Operand(MachineInstr *MI, unsigned Index=0) const
bool isPredicatedNew(const MachineInstr &MI) const
bool isSignExtendingLoad(const MachineInstr &MI) const
bool isVecAcc(const MachineInstr &MI) const
bool reversePredSense(MachineInstr &MI) const
bool isPostIncWithImmOffset(const MachineInstr &MI) const
bool isQFPMul(const MachineInstr *MF) 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.
bool isQFP16Instr(MachineInstr *MI) const
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.
int srcDependence(MachineBasicBlock::instr_iterator SrcBeg, MachineBasicBlock::instr_iterator SrcEnd, MachineBasicBlock::instr_iterator RMII, const MIUseDefMap &MIUseDefs, SmallPtrSetImpl< MachineInstr * > *DepSet=nullptr, bool PreventDuplexSep=true, bool IsPullDown=false) const
Compute the intra-packet dependence of RMII against the rest of the bundle [SrcBeg,...
bool isAddrModeWithOffset(const MachineInstr &MI) const
bool hasCallUseInBundle(MachineBasicBlock::const_instr_iterator MIBegin, MachineBasicBlock::const_instr_iterator MIEnd, unsigned Reg, const TargetRegisterInfo &TRI) const
bool isBaseImmOffset(const MachineInstr &MI) const
bool isAbsoluteSet(const MachineInstr &MI) const
short changeAddrMode_io_pi(short Opc) const
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, const DebugLoc &DL, Register DestReg, Register SrcReg, bool KillSrc, bool RenamableDest=false, bool RenamableSrc=false) const override
Emit instructions to copy a pair of physical registers.
void findInstrPredicate(MachineInstr *MI, SmallVectorImpl< MachineOperand > &Cond) const
findInstrPredicate - Set the predicate of the instruction in the specified predicate vector First ent...
const HexagonRegisterInfo & getRegisterInfo() 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.
bool isFloatCompare(const MachineInstr &MI) const
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
void moveDependentDebugValues(MachineInstr &First, MachineInstr &Second) const
Copies the debug values of the variables that read the register First and Second define to just after...
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 usesQF32Operand(MachineInstr *MI, unsigned Index=0) 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 areMemAccessesDependent(AAResults *AA, const MachineInstr *MIa, const MachineInstr *MIb) const
Return true if the memory accesses of MIa and MIb may depend on each other.
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 isNewValueInst(const MachineInstr &MI) const
bool isHMXWeightInstr(const MachineInstr &MI) const
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.
bool isAssociativeAndCommutative(const MachineInstr &Inst, bool Invert) const override
InstrStage::FuncUnits getUnits(const MachineInstr &MI) const
unsigned getMemAccessSize(const MachineInstr &MI) const
bool predOpcodeHasNot(ArrayRef< MachineOperand > Cond) const
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
bool isDotCurOperand(const MachineInstr &MI, unsigned OpIndex) const
Returns true if the specified operand is a .cur (current) operand.
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, Register VReg, unsigned SubReg=0, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
Load the specified register of the given register class from the specified stack frame index.
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
bool hasUncondBranch(const MachineBasicBlock *B) const
short getNonExtOpcode(const MachineInstr &MI) const
bool isNewStorePseudo(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
HexagonInstrInfo(const HexagonSubtarget &ST)
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
std::optional< unsigned > getInvertedCompare(const int OpC) const
bool isDotNewOperand(const MachineInstr &MI, unsigned OpIndex) const
Should be able to tell if the operand in question is .new.
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 isMIBefore(const MachineInstr *A, const MachineInstr *B) const
bool isExpr(unsigned OpType) const
bool isSafeInBundleWAR(const MachineInstr &DefMI, unsigned DefOpIdx, const MachineInstr &UseMI, unsigned UseOpIdx, bool IsPullDown=false, bool DefViaRegMask=false) const
A use (UseMI) can share a bundle with an instruction that redefines the same register (DefMI),...
DenseMap< const MachineInstr *, UseDefBitVectors > MIUseDefMap
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 isDotTmpOperand(const MachineInstr &MI, unsigned OpIndex) const
Returns true if the specified operand is a .tmp (temporary) operand.
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.
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 getPredReg(ArrayRef< MachineOperand > Cond, Register &PredReg, unsigned &PredRegPos, RegState &PredRegFlags) const
bool isFloat(const MachineInstr &MI) const
bool isQFPInstr(MachineInstr *MI) const
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 isHMXActivateInstr(const MachineInstr &MI) const
bool isExtendable(const MachineInstr &MI) const
void immediateExtend(MachineInstr &MI) const
immediateExtend - Changes the instruction in place to one using an immediate extender.
bool isValidOffset(unsigned Opcode, int Offset, bool Extend=true) const
bool isActivateWeightPair(const MachineInstr &MIa, const MachineInstr &MIb) const
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
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 usesQFOperand(MachineInstr *MI, unsigned Index=0) const
bool isTC2(const MachineInstr &MI) const
Hexagon target-specific information for each MachineFunction.
Register getFrameRegister(const MachineFunction &MF) const override
bool isFakeReg(MCPhysReg Reg) const
Returns true if the given reserved physical register Reg is live across function calls/returns.
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.
void RemoveMachineInstrFromMaps(MachineInstr &MI)
A set of physical registers with utility functions to track liveness when walking backward/forward th...
LLVM_ABI void stepForward(const MachineInstr &MI, SmallVectorImpl< std::pair< MCPhysReg, const MachineOperand * > > &Clobbers)
Simulates liveness when stepping forward over an instruction(bundle).
LLVM_ABI void stepBackward(const MachineInstr &MI)
Simulates liveness when stepping backwards over an instruction(bundle).
LLVM_ABI void addLiveIns(const MachineBasicBlock &MBB)
Adds all live-in registers of basic block MBB.
LLVM_ABI bool available(const MachineRegisterInfo &MRI, MCRegister Reg) const
Returns true if register Reg and no aliasing register is in the set.
LLVM_ABI void addLiveOuts(const MachineBasicBlock &MBB)
Adds all live-out registers of basic block MBB.
bool contains(MCRegister Reg) const
Returns true if register Reg is contained in the set.
bool hasValue() const
static LocationSize precise(uint64_t Value)
TypeSize getValue() const
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:69
unsigned getMaxInstLength() const
Returns the maximum possible encoded instruction size in bytes.
Definition MCAsmInfo.h:578
StringRef getCommentString() const
Definition MCAsmInfo.h:587
const char * getSeparatorString() const
Definition MCAsmInfo.h:582
MCInstBuilder & addInst(const MCInst *Val)
Add a new MCInst operand.
MCInstBuilder & addImm(int64_t Val)
Add a new integer immediate operand.
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:187
Describe properties that are true of each instruction in the target description file.
unsigned getSchedClass() const
Return the scheduling class for this instruction.
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
MCRegAliasIterator enumerates all registers aliasing Reg.
Machine Value Type.
SimpleValueType SimpleTy
MachineInstrBundleIterator< const MachineInstr > const_iterator
LLVM_ABI iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
Instructions::iterator instr_iterator
Instructions::const_iterator const_instr_iterator
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 '...
MachineInstrBundleIterator< MachineInstr > iterator
LLVM_ABI 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.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
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.
BasicBlockListType::iterator iterator
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags F, LLT MemTy, Align BaseAlignment, const MMOMetadata &Metadata=MMOMetadata(), SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineInstrBuilder & addUse(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register use operand.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
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 & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & addDef(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register definition operand.
const MachineInstrBuilder & cloneMemRefs(const MachineInstr &OtherMI) const
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
reverse_iterator getReverse() const
Get a reverse iterator to the same node.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool isTerminator(QueryType Type=AnyInBundle) const
Returns true if this instruction part of the terminator for a basic block.
const MachineBasicBlock * getParent() const
bool readsRegister(Register Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr reads the specified register.
bool getFlag(MIFlag Flag) const
Return whether an MI flag is set.
bool isBundle() const
unsigned getNumOperands() const
Retuns the total number of operands.
LLVM_ABI 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.
LLVM_ABI unsigned getBundleSize() const
Return the number of instructions inside the MI bundle, excluding the bundle header.
LLVM_ABI bool hasUnmodeledSideEffects() const
Return true if this instruction has side effects that are not modeled by mayLoad / mayStore,...
bool hasOneMemOperand() const
Return true if this instruction has exactly one MachineMemOperand.
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.
LLVM_ABI 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.
const MachineOperand & getOperand(unsigned i) const
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
bool isIndirectBranch(QueryType Type=AnyInBundle) const
Return true if this is an indirect branch, such as a branch through a register.
A description of a memory reference used in the backend.
LocationSize getSize() const
Return the size in bytes of the memory reference.
@ MOVolatile
The memory access is volatile.
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
AAMDNodes getAAInfo() const
Return the AA tags for the memory reference.
const Value * getValue() const
Return the base address of the memory access.
int64_t getOffset() const
For normal values, this is a byte offset added to the base address.
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
void setImm(int64_t immVal)
int64_t getImm() 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.
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
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 isInternalRead() const
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,...
Representation for a specific memory location.
Special value supplied for machine level alias analysis.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition Register.h:83
HazardRecognizer - This determines whether or not an instruction can be issued this cycle,...
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Register getReg() const
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:138
size_t count(char C) const
Return the number of occurrences of C in the string.
Definition StringRef.h:463
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.
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 TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
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:82
LLVM Value Representation.
Definition Value.h:75
self_iterator getIterator()
Definition ilist_node.h:123
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Abstract Attribute helper functions.
Definition Attributor.h:166
bool isSlot0Only(unsigned units)
HexagonII - This namespace holds all of the target specific flags that instruction info tracks.
unsigned const TypeCVI_LAST
static constexpr RegTypeInfo make(RegType Out, RegType In1=RegType::Unknown, RegType In2=RegType::Unknown, RegType In3=RegType::Unknown)
unsigned const TypeCVI_FIRST
RegType getOpRegType(unsigned Opcode)
RegTypeInfo getRegTypeInfo(unsigned Opcode)
bool getTSFlag(const MCInstrDesc &MID, HexagonTSFlagsVal Pos)
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
@ Length
Definition DWP.cpp:577
MachineBasicBlock::instr_iterator getBundleStart(MachineBasicBlock::instr_iterator I)
Returns an iterator to the first instruction in the bundle containing I.
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:1755
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition MathExtras.h:166
RegState
Flags to represent properties of register accesses.
@ Implicit
Not emitted register (e.g. carry, or temporary result).
@ Kill
The last use of a register.
@ InternalRead
Register reads a value that is defined inside the same instruction or bundle.
@ Undef
Value of the register doesn't matter.
@ NoFlags
No Specific Flags.
constexpr RegState getKillRegState(bool B)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
@ Done
Definition Threading.h:60
bool is_TC1(unsigned SchedClass)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
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:326
auto reverse(ContainerTy &&C)
Definition STLExtras.h:408
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition MathExtras.h:280
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
MachineBasicBlock::instr_iterator getBundleEnd(MachineBasicBlock::instr_iterator I)
Returns an iterator pointing beyond the bundle containing I.
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:190
RegState getRegState(const MachineOperand &RegOp)
Get all register state flags from machine operand RegOp.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:74
bool is_TC2(unsigned SchedClass)
bool is_TC2early(unsigned SchedClass)
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
constexpr bool isShiftedInt(int64_t x)
Checks if a signed integer is an N bit number shifted left by S.
Definition MathExtras.h:183
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
bool isSpace(char C)
Checks whether character C is whitespace in the "C" locale.
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:320
constexpr RegState getUndefRegState(bool B)
LLVM_ABI 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.
constexpr bool isShiftedUInt(uint64_t x)
Checks if a unsigned integer is an N bit number shifted left by S.
Definition MathExtras.h:199
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
bool is_TC4x(unsigned SchedClass)
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
#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:411
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition ValueTypes.h:354
These values represent a non-pipelined step in the execution of an instruction.
uint64_t FuncUnits
Bitmask representing a set of functional units.
This class contains a discriminated union of information about pointers in memory operands,...
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.