LLVM 24.0.0git
HexagonVLIWPacketizer.cpp
Go to the documentation of this file.
1//===- HexagonPacketizer.cpp - VLIW packetizer ----------------------------===//
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 implements a simple VLIW packetizer using DFA. The packetizer works on
10// machine basic blocks. For each instruction I in BB, the packetizer consults
11// the DFA to see if machine resources are available to execute I. If so, the
12// packetizer checks if I depends on any instruction J in the current packet.
13// If no dependency is found, I is added to current packet and machine resource
14// is marked as taken. If any dependency is found, a target API call is made to
15// prune the dependence.
16//
17//===----------------------------------------------------------------------===//
18
20#include "Hexagon.h"
21#include "HexagonInstrInfo.h"
22#include "HexagonRegisterInfo.h"
23#include "HexagonSubtarget.h"
24#include "llvm/ADT/BitVector.h"
25#include "llvm/ADT/DenseSet.h"
26#include "llvm/ADT/STLExtras.h"
42#include "llvm/IR/DebugLoc.h"
44#include "llvm/MC/MCInstrDesc.h"
45#include "llvm/Pass.h"
47#include "llvm/Support/Debug.h"
50#include <cassert>
51#include <cstdint>
52#include <iterator>
53
54using namespace llvm;
55
56#define DEBUG_TYPE "packets"
57
59 cl::desc("Disable Hexagon packetizer pass"));
60
61static cl::opt<bool> Slot1Store("slot1-store-slot0-load", cl::Hidden,
62 cl::init(true),
63 cl::desc("Allow slot1 store and slot0 load"));
64
66 "hexagon-packetize-volatiles", cl::Hidden, cl::init(true),
67 cl::desc("Allow non-solo packetization of volatile memory references"));
68
69static cl::opt<bool>
71 cl::desc("Generate all instruction with TC"));
72
73static cl::opt<bool>
74 DisableVecDblNVStores("disable-vecdbl-nv-stores", cl::Hidden,
75 cl::desc("Disable vector double new-value-stores"));
76
78
79namespace {
80
81 class HexagonPacketizer : public MachineFunctionPass {
82 public:
83 static char ID;
84
85 HexagonPacketizer(bool Min = false)
86 : MachineFunctionPass(ID), Minimal(Min) {}
87
88 void getAnalysisUsage(AnalysisUsage &AU) const override {
89 AU.setPreservesCFG();
90 AU.addRequired<AAResultsWrapperPass>();
91 AU.addRequired<MachineBranchProbabilityInfoWrapperPass>();
92 AU.addRequired<MachineLoopInfoWrapperPass>();
94 }
95
96 StringRef getPassName() const override { return "Hexagon Packetizer"; }
97 bool runOnMachineFunction(MachineFunction &Fn) override;
98
99 MachineFunctionProperties getRequiredProperties() const override {
100 return MachineFunctionProperties().setNoVRegs();
101 }
102
103 private:
104 const HexagonInstrInfo *HII = nullptr;
105 const HexagonRegisterInfo *HRI = nullptr;
106 const bool Minimal = false;
107 };
108
109} // end anonymous namespace
110
111char HexagonPacketizer::ID = 0;
112
113INITIALIZE_PASS_BEGIN(HexagonPacketizer, "hexagon-packetizer",
114 "Hexagon Packetizer", false, false)
119INITIALIZE_PASS_END(HexagonPacketizer, "hexagon-packetizer",
120 "Hexagon Packetizer", false, false)
121
126 Minimal(Minimal) {
127 HII = MF.getSubtarget<HexagonSubtarget>().getInstrInfo();
128 HRI = MF.getSubtarget<HexagonSubtarget>().getRegisterInfo();
129
130 addMutation(std::make_unique<HexagonSubtarget::UsrOverflowMutation>());
131 addMutation(std::make_unique<HexagonSubtarget::HVXMemLatencyMutation>());
132 addMutation(std::make_unique<HexagonSubtarget::BankConflictMutation>());
133}
134
135// Check if FirstI modifies a register that SecondI reads.
136static bool hasWriteToReadDep(const MachineInstr &FirstI,
137 const MachineInstr &SecondI,
138 const TargetRegisterInfo *TRI) {
139 for (auto &MO : FirstI.operands()) {
140 if (!MO.isReg() || !MO.isDef())
141 continue;
142 Register R = MO.getReg();
143 if (SecondI.readsRegister(R, TRI))
144 return true;
145 }
146 return false;
147}
148
149
151 MachineBasicBlock::iterator BundleIt, bool Before) {
153 if (Before)
154 InsertPt = BundleIt.getInstrIterator();
155 else
156 InsertPt = std::next(BundleIt).getInstrIterator();
157
158 MachineBasicBlock &B = *MI.getParent();
159 // The instruction should at least be bundled with the preceding instruction
160 // (there will always be one, i.e. BUNDLE, if nothing else).
161 assert(MI.isBundledWithPred());
162 if (MI.isBundledWithSucc()) {
163 MI.clearFlag(MachineInstr::BundledSucc);
164 MI.clearFlag(MachineInstr::BundledPred);
165 } else {
166 // If it's not bundled with the successor (i.e. it is the last one
167 // in the bundle), then we can simply unbundle it from the predecessor,
168 // which will take care of updating the predecessor's flag.
169 MI.unbundleFromPred();
170 }
171 B.splice(InsertPt, &B, MI.getIterator());
172
173 // Get the size of the bundle without asserting.
176 unsigned Size = 0;
177 for (++I; I != E && I->isBundledWithPred(); ++I)
178 ++Size;
179
180 // If there are still two or more instructions, then there is nothing
181 // else to be done.
182 if (Size > 1)
183 return BundleIt;
184
185 // Otherwise, extract the single instruction out and delete the bundle.
186 MachineBasicBlock::iterator NextIt = std::next(BundleIt);
187 MachineInstr &SingleI = *BundleIt->getNextNode();
188 SingleI.unbundleFromPred();
189 assert(!SingleI.isBundledWithSucc());
190 BundleIt->eraseFromParent();
191 return NextIt;
192}
193
194bool HexagonPacketizer::runOnMachineFunction(MachineFunction &MF) {
195 // FIXME: This pass causes verification failures.
196 MF.getProperties().setFailsVerification();
197
198 auto &HST = MF.getSubtarget<HexagonSubtarget>();
199 HII = HST.getInstrInfo();
200 HRI = HST.getRegisterInfo();
201 auto &MLI = getAnalysis<MachineLoopInfoWrapperPass>().getLI();
202 auto *AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
203 auto *MBPI =
204 &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
205
207 HII->genAllInsnTimingClasses(MF);
208
209 // Instantiate the packetizer.
210 bool MinOnly = Minimal || DisablePacketizer || !HST.usePackets() ||
211 skipFunction(MF.getFunction());
212 HexagonPacketizerList Packetizer(MF, MLI, AA, MBPI, MinOnly);
213
214 // DFA state table should not be empty.
215 assert(Packetizer.getResourceTracker() && "Empty DFA table!");
216
217 // Loop over all basic blocks and remove KILL pseudo-instructions
218 // These instructions confuse the dependence analysis. Consider:
219 // D0 = ... (Insn 0)
220 // R0 = KILL R0, D0 (Insn 1)
221 // R0 = ... (Insn 2)
222 // Here, Insn 1 will result in the dependence graph not emitting an output
223 // dependence between Insn 0 and Insn 2. This can lead to incorrect
224 // packetization
225 for (MachineBasicBlock &MB : MF) {
226 for (MachineInstr &MI : llvm::make_early_inc_range(MB))
227 if (MI.isKill())
228 MB.erase(&MI);
229 }
230
231 // TinyCore with Duplexes: Translate to big-instructions.
232 if (HST.isTinyCoreWithDuplex())
233 HII->translateInstrsForDup(MF, true);
234
235 // Loop over all of the basic blocks.
236 for (auto &MB : MF) {
237 auto Begin = MB.begin(), End = MB.end();
238 while (Begin != End) {
239 // Find the first non-boundary starting from the end of the last
240 // scheduling region.
242 while (RB != End && HII->isSchedulingBoundary(*RB, &MB, MF))
243 ++RB;
244 // Find the first boundary starting from the beginning of the new
245 // region.
247 while (RE != End && !HII->isSchedulingBoundary(*RE, &MB, MF))
248 ++RE;
249 // Add the scheduling boundary if it's not block end.
250 if (RE != End)
251 ++RE;
252 // If RB == End, then RE == End.
253 if (RB != End)
254 Packetizer.PacketizeMIs(&MB, RB, RE);
255
256 Begin = RE;
257 }
258 }
259
260 // TinyCore with Duplexes: Translate to tiny-instructions.
261 if (HST.isTinyCoreWithDuplex())
262 HII->translateInstrsForDup(MF, false);
263
264 Packetizer.unpacketizeSoloInstrs(MF);
265 return true;
266}
267
268// Reserve resources for a constant extender. Trigger an assertion if the
269// reservation fails.
274
278
279// Allocate resources (i.e. 4 bytes) for constant extender. If succeeded,
280// return true, otherwise, return false.
282 auto *ExtMI = MF.CreateMachineInstr(HII->get(Hexagon::A4_ext), DebugLoc());
283 bool Avail = ResourceTracker->canReserveResources(*ExtMI);
284 if (Reserve && Avail)
285 ResourceTracker->reserveResources(*ExtMI);
286 MF.deleteMachineInstr(ExtMI);
287 return Avail;
288}
289
291 SDep::Kind DepType, unsigned DepReg) {
292 // Check for LR dependence.
293 if (DepReg == HRI->getRARegister())
294 return true;
295
296 if (HII->isDeallocRet(MI))
297 if (DepReg == HRI->getFrameRegister() || DepReg == HRI->getStackRegister())
298 return true;
299
300 // Call-like instructions can be packetized with preceding instructions
301 // that define registers implicitly used or modified by the call. Explicit
302 // uses are still prohibited, as in the case of indirect calls:
303 // r0 = ...
304 // J2_jumpr r0
305 if (DepType == SDep::Data) {
306 for (const MachineOperand &MO : MI.operands())
307 if (MO.isReg() && MO.getReg() == DepReg && !MO.isImplicit())
308 return true;
309 }
310
311 return false;
312}
313
314static bool isRegDependence(const SDep::Kind DepType) {
315 return DepType == SDep::Data || DepType == SDep::Anti ||
316 DepType == SDep::Output;
317}
318
319static bool isDirectJump(const MachineInstr &MI) {
320 return MI.getOpcode() == Hexagon::J2_jump;
321}
322
323static bool isSchedBarrier(const MachineInstr &MI) {
324 switch (MI.getOpcode()) {
325 case Hexagon::Y2_barrier:
326 return true;
327 }
328 return false;
329}
330
331static bool isControlFlow(const MachineInstr &MI) {
332 return MI.getDesc().isTerminator() || MI.getDesc().isCall();
333}
334
335/// Returns true if the instruction modifies a callee-saved register.
337 const TargetRegisterInfo *TRI) {
338 const MachineFunction &MF = *MI.getParent()->getParent();
339 for (auto *CSR = TRI->getCalleeSavedRegs(&MF); CSR && *CSR; ++CSR)
340 if (MI.modifiesRegister(*CSR, TRI))
341 return true;
342 return false;
343}
344
345// Returns true if an instruction can be promoted to .new predicate or
346// new-value store.
348 const TargetRegisterClass *NewRC) {
349 // Vector stores can be predicated, and can be new-value stores, but
350 // they cannot be predicated on a .new predicate value.
351 if (NewRC == &Hexagon::PredRegsRegClass) {
352 if (HII->isHVXVec(MI) && MI.mayStore())
353 return false;
354 return HII->isPredicated(MI) && HII->getDotNewPredOp(MI, nullptr) > 0;
355 }
356 // If the class is not PredRegs, it could only apply to new-value stores.
357 return HII->mayBeNewStore(MI);
358}
359
360// Promote an instructiont to its .cur form.
361// At this time, we have already made a call to canPromoteToDotCur and made
362// sure that it can *indeed* be promoted.
365 const TargetRegisterClass* RC) {
366 assert(DepType == SDep::Data);
367 int CurOpcode = HII->getDotCurOp(MI);
368 MI.setDesc(HII->get(CurOpcode));
369 return true;
370}
371
373 MachineInstr *MI = nullptr;
374 for (auto *BI : CurrentPacketMIs) {
375 LLVM_DEBUG(dbgs() << "Cleanup packet has "; BI->dump(););
376 if (HII->isDotCurInst(*BI)) {
377 MI = BI;
378 continue;
379 }
380 if (MI) {
381 for (auto &MO : BI->operands())
382 if (MO.isReg() && MO.getReg() == MI->getOperand(0).getReg())
383 return;
384 }
385 }
386 if (!MI)
387 return;
388 // We did not find a use of the CUR, so de-cur it.
389 MI->setDesc(HII->get(HII->getNonDotCurOp(*MI)));
390 LLVM_DEBUG(dbgs() << "Demoted CUR "; MI->dump(););
391}
392
393// Check to see if an instruction can be dot cur.
395 const SUnit *PacketSU, unsigned DepReg, MachineBasicBlock::iterator &MII,
396 const TargetRegisterClass *RC) {
397 if (!HII->isHVXVec(MI))
398 return false;
399 if (!HII->isHVXVec(*MII))
400 return false;
401
402 // Already a dot new instruction.
403 if (HII->isDotCurInst(MI) && !HII->mayBeCurLoad(MI))
404 return false;
405
406 if (!HII->mayBeCurLoad(MI))
407 return false;
408
409 // The "cur value" cannot come from inline asm.
410 if (PacketSU->getInstr()->isInlineAsm())
411 return false;
412
413 // Make sure candidate instruction uses cur.
414 LLVM_DEBUG(dbgs() << "Can we DOT Cur Vector MI\n"; MI.dump();
415 dbgs() << "in packet\n";);
416 MachineInstr &MJ = *MII;
417 LLVM_DEBUG({
418 dbgs() << "Checking CUR against ";
419 MJ.dump();
420 });
421 Register DestReg = MI.getOperand(0).getReg();
422 bool FoundMatch = false;
423 for (auto &MO : MJ.operands())
424 if (MO.isReg() && MO.getReg() == DestReg)
425 FoundMatch = true;
426 if (!FoundMatch)
427 return false;
428
429 // Check for existing uses of a vector register within the packet which
430 // would be affected by converting a vector load into .cur format.
431 for (auto *BI : CurrentPacketMIs) {
432 LLVM_DEBUG(dbgs() << "packet has "; BI->dump(););
433 if (BI->readsRegister(DepReg, MF.getSubtarget().getRegisterInfo()))
434 return false;
435 }
436
437 LLVM_DEBUG(dbgs() << "Can Dot CUR MI\n"; MI.dump(););
438 // We can convert the opcode into a .cur.
439 return true;
440}
441
442// Promote an instruction to its .new form. At this time, we have already
443// made a call to canPromoteToDotNew and made sure that it can *indeed* be
444// promoted.
447 const TargetRegisterClass* RC) {
448 assert(DepType == SDep::Data);
449 int NewOpcode;
450 if (RC == &Hexagon::PredRegsRegClass)
451 NewOpcode = HII->getDotNewPredOp(MI, MBPI);
452 else
453 NewOpcode = HII->getDotNewOp(MI);
454 MI.setDesc(HII->get(NewOpcode));
455 return true;
456}
457
459 int NewOpcode = HII->getDotOldOp(MI);
460 MI.setDesc(HII->get(NewOpcode));
461 return true;
462}
463
465 unsigned Opc = MI.getOpcode();
466 switch (Opc) {
467 case Hexagon::S2_storerd_io:
468 case Hexagon::S2_storeri_io:
469 case Hexagon::S2_storerh_io:
470 case Hexagon::S2_storerb_io:
471 break;
472 default:
473 llvm_unreachable("Unexpected instruction");
474 }
475 unsigned FrameSize = MF.getFrameInfo().getStackSize();
476 MachineOperand &Off = MI.getOperand(1);
477 int64_t NewOff = Off.getImm() - (FrameSize + HEXAGON_LRFP_SIZE);
478 if (HII->isValidOffset(Opc, NewOff, HRI)) {
479 Off.setImm(NewOff);
480 return true;
481 }
482 return false;
483}
484
486 unsigned Opc = MI.getOpcode();
487 switch (Opc) {
488 case Hexagon::S2_storerd_io:
489 case Hexagon::S2_storeri_io:
490 case Hexagon::S2_storerh_io:
491 case Hexagon::S2_storerb_io:
492 break;
493 default:
494 llvm_unreachable("Unexpected instruction");
495 }
496 unsigned FrameSize = MF.getFrameInfo().getStackSize();
497 MachineOperand &Off = MI.getOperand(1);
498 Off.setImm(Off.getImm() + FrameSize + HEXAGON_LRFP_SIZE);
499}
500
501/// Return true if we can update the offset in MI so that MI and MJ
502/// can be packetized together.
504 assert(SUI->getInstr() && SUJ->getInstr());
505 MachineInstr &MI = *SUI->getInstr();
506 MachineInstr &MJ = *SUJ->getInstr();
507
508 unsigned BPI, OPI;
509 if (!HII->getBaseAndOffsetPosition(MI, BPI, OPI))
510 return false;
511 unsigned BPJ, OPJ;
512 if (!HII->getBaseAndOffsetPosition(MJ, BPJ, OPJ))
513 return false;
514 Register Reg = MI.getOperand(BPI).getReg();
515 if (Reg != MJ.getOperand(BPJ).getReg())
516 return false;
517 // Make sure that the dependences do not restrict adding MI to the packet.
518 // That is, ignore anti dependences, and make sure the only data dependence
519 // involves the specific register.
520 for (const auto &PI : SUI->Preds)
521 if (PI.getKind() != SDep::Anti &&
522 (PI.getKind() != SDep::Data || PI.getReg() != Reg))
523 return false;
524 int Incr;
525 if (!HII->getIncrementValue(MJ, Incr))
526 return false;
527
528 int64_t Offset = MI.getOperand(OPI).getImm();
529 if (!HII->isValidOffset(MI.getOpcode(), Offset+Incr, HRI))
530 return false;
531
532 MI.getOperand(OPI).setImm(Offset + Incr);
533 ChangedOffset = Offset;
534 return true;
535}
536
537/// Undo the changed offset. This is needed if the instruction cannot be
538/// added to the current packet due to a different instruction.
540 unsigned BP, OP;
541 if (!HII->getBaseAndOffsetPosition(MI, BP, OP))
542 llvm_unreachable("Unable to find base and offset operands.");
543 MI.getOperand(OP).setImm(ChangedOffset);
544}
545
551
552/// Returns true if an instruction is predicated on p0 and false if it's
553/// predicated on !p0.
555 const HexagonInstrInfo *HII) {
556 if (!HII->isPredicated(MI))
557 return PK_Unknown;
558 if (HII->isPredicatedTrue(MI))
559 return PK_True;
560 return PK_False;
561}
562
564 const HexagonInstrInfo *HII) {
565 assert(HII->isPostIncrement(MI) && "Not a post increment operation.");
566#ifndef NDEBUG
567 // Post Increment means duplicates. Use dense map to find duplicates in the
568 // list. Caution: Densemap initializes with the minimum of 64 buckets,
569 // whereas there are at most 5 operands in the post increment.
570 DenseSet<unsigned> DefRegsSet;
571 for (auto &MO : MI.operands())
572 if (MO.isReg() && MO.isDef())
573 DefRegsSet.insert(MO.getReg());
574
575 for (auto &MO : MI.operands())
576 if (MO.isReg() && MO.isUse() && DefRegsSet.count(MO.getReg()))
577 return MO;
578#else
579 if (MI.mayLoad()) {
580 const MachineOperand &Op1 = MI.getOperand(1);
581 // The 2nd operand is always the post increment operand in load.
582 assert(Op1.isReg() && "Post increment operand has be to a register.");
583 return Op1;
584 }
585 if (MI.getDesc().mayStore()) {
586 const MachineOperand &Op0 = MI.getOperand(0);
587 // The 1st operand is always the post increment operand in store.
588 assert(Op0.isReg() && "Post increment operand has be to a register.");
589 return Op0;
590 }
591#endif
592 // we should never come here.
593 llvm_unreachable("mayLoad or mayStore not set for Post Increment operation");
594}
595
596// Get the value being stored.
598 // value being stored is always the last operand.
599 return MI.getOperand(MI.getNumOperands()-1);
600}
601
602static bool isLoadAbsSet(const MachineInstr &MI) {
603 unsigned Opc = MI.getOpcode();
604 switch (Opc) {
605 case Hexagon::L4_loadrd_ap:
606 case Hexagon::L4_loadrb_ap:
607 case Hexagon::L4_loadrh_ap:
608 case Hexagon::L4_loadrub_ap:
609 case Hexagon::L4_loadruh_ap:
610 case Hexagon::L4_loadri_ap:
611 return true;
612 }
613 return false;
614}
615
618 return MI.getOperand(1);
619}
620
621// Can be new value store?
622// Following restrictions are to be respected in convert a store into
623// a new value store.
624// 1. If an instruction uses auto-increment, its address register cannot
625// be a new-value register. Arch Spec 5.4.2.1
626// 2. If an instruction uses absolute-set addressing mode, its address
627// register cannot be a new-value register. Arch Spec 5.4.2.1.
628// 3. If an instruction produces a 64-bit result, its registers cannot be used
629// as new-value registers. Arch Spec 5.4.2.2.
630// 4. If the instruction that sets the new-value register is conditional, then
631// the instruction that uses the new-value register must also be conditional,
632// and both must always have their predicates evaluate identically.
633// Arch Spec 5.4.2.3.
634// 5. There is an implied restriction that a packet cannot have another store,
635// if there is a new value store in the packet. Corollary: if there is
636// already a store in a packet, there can not be a new value store.
637// Arch Spec: 3.4.4.2
639 const MachineInstr &PacketMI, unsigned DepReg) {
640 // Make sure we are looking at the store, that can be promoted.
641 if (!HII->mayBeNewStore(MI))
642 return false;
643
644 // Make sure there is dependency and can be new value'd.
646 if (Val.isReg() && Val.getReg() != DepReg)
647 return false;
648
649 const MCInstrDesc& MCID = PacketMI.getDesc();
650
651 // First operand is always the result.
652 const TargetRegisterClass *PacketRC = HII->getRegClass(MCID, 0);
653 // Double regs can not feed into new value store: PRM section: 5.4.2.2.
654 if (PacketRC == &Hexagon::DoubleRegsRegClass)
655 return false;
656
657 // New-value stores are of class NV (slot 0), dual stores require class ST
658 // in slot 0 (PRM 5.5).
659 for (auto *I : CurrentPacketMIs) {
660 SUnit *PacketSU = MIToSUnit.find(I)->second;
661 if (PacketSU->getInstr()->mayStore())
662 return false;
663 }
664
665 // Make sure it's NOT the post increment register that we are going to
666 // new value.
667 if (HII->isPostIncrement(MI) &&
668 getPostIncrementOperand(MI, HII).getReg() == DepReg) {
669 return false;
670 }
671
672 if (HII->isPostIncrement(PacketMI) && PacketMI.mayLoad() &&
673 getPostIncrementOperand(PacketMI, HII).getReg() == DepReg) {
674 // If source is post_inc, or absolute-set addressing, it can not feed
675 // into new value store
676 // r3 = memw(r2++#4)
677 // memw(r30 + #-1404) = r2.new -> can not be new value store
678 // arch spec section: 5.4.2.1.
679 return false;
680 }
681
682 if (isLoadAbsSet(PacketMI) && getAbsSetOperand(PacketMI).getReg() == DepReg)
683 return false;
684
685 // If the source that feeds the store is predicated, new value store must
686 // also be predicated.
687 if (HII->isPredicated(PacketMI)) {
688 if (!HII->isPredicated(MI))
689 return false;
690
691 // Check to make sure that they both will have their predicates
692 // evaluate identically.
693 unsigned predRegNumSrc = 0;
694 unsigned predRegNumDst = 0;
695 const TargetRegisterClass* predRegClass = nullptr;
696
697 // Get predicate register used in the source instruction.
698 for (auto &MO : PacketMI.operands()) {
699 if (!MO.isReg())
700 continue;
701 predRegNumSrc = MO.getReg();
702 predRegClass = HRI->getMinimalPhysRegClass(predRegNumSrc);
703 if (predRegClass == &Hexagon::PredRegsRegClass)
704 break;
705 }
706 assert((predRegClass == &Hexagon::PredRegsRegClass) &&
707 "predicate register not found in a predicated PacketMI instruction");
708
709 // Get predicate register used in new-value store instruction.
710 for (auto &MO : MI.operands()) {
711 if (!MO.isReg())
712 continue;
713 predRegNumDst = MO.getReg();
714 predRegClass = HRI->getMinimalPhysRegClass(predRegNumDst);
715 if (predRegClass == &Hexagon::PredRegsRegClass)
716 break;
717 }
718 assert((predRegClass == &Hexagon::PredRegsRegClass) &&
719 "predicate register not found in a predicated MI instruction");
720
721 // New-value register producer and user (store) need to satisfy these
722 // constraints:
723 // 1) Both instructions should be predicated on the same register.
724 // 2) If producer of the new-value register is .new predicated then store
725 // should also be .new predicated and if producer is not .new predicated
726 // then store should not be .new predicated.
727 // 3) Both new-value register producer and user should have same predicate
728 // sense, i.e, either both should be negated or both should be non-negated.
729 if (predRegNumDst != predRegNumSrc ||
730 HII->isDotNewInst(PacketMI) != HII->isDotNewInst(MI) ||
731 getPredicateSense(MI, HII) != getPredicateSense(PacketMI, HII))
732 return false;
733 }
734
735 // Make sure that other than the new-value register no other store instruction
736 // register has been modified in the same packet. Predicate registers can be
737 // modified by they should not be modified between the producer and the store
738 // instruction as it will make them both conditional on different values.
739 // We already know this to be true for all the instructions before and
740 // including PacketMI. However, we need to perform the check for the
741 // remaining instructions in the packet.
742
743 unsigned StartCheck = 0;
744
745 for (auto *I : CurrentPacketMIs) {
746 SUnit *TempSU = MIToSUnit.find(I)->second;
747 MachineInstr &TempMI = *TempSU->getInstr();
748
749 // Following condition is true for all the instructions until PacketMI is
750 // reached (StartCheck is set to 0 before the for loop).
751 // StartCheck flag is 1 for all the instructions after PacketMI.
752 if (&TempMI != &PacketMI && !StartCheck) // Start processing only after
753 continue; // encountering PacketMI.
754
755 StartCheck = 1;
756 if (&TempMI == &PacketMI) // We don't want to check PacketMI for dependence.
757 continue;
758
759 for (auto &MO : MI.operands())
760 if (MO.isReg() && TempSU->getInstr()->modifiesRegister(MO.getReg(), HRI))
761 return false;
762 }
763
764 // Make sure that for non-POST_INC stores:
765 // 1. The only use of reg is DepReg and no other registers.
766 // This handles base+index registers.
767 // The following store can not be dot new.
768 // Eg. r0 = add(r0, #3)
769 // memw(r1+r0<<#2) = r0
770 if (!HII->isPostIncrement(MI)) {
771 for (unsigned opNum = 0; opNum < MI.getNumOperands()-1; opNum++) {
772 const MachineOperand &MO = MI.getOperand(opNum);
773 if (MO.isReg() && MO.getReg() == DepReg)
774 return false;
775 }
776 }
777
778 // If data definition is because of implicit definition of the register,
779 // do not newify the store. Eg.
780 // %r9 = ZXTH %r12, implicit %d6, implicit-def %r12
781 // S2_storerh_io %r8, 2, killed %r12; mem:ST2[%scevgep343]
782 for (auto &MO : PacketMI.operands()) {
783 if (MO.isRegMask() && MO.clobbersPhysReg(DepReg))
784 return false;
785 if (!MO.isReg() || !MO.isDef() || !MO.isImplicit())
786 continue;
787 Register R = MO.getReg();
788 if (R == DepReg || HRI->isSuperRegister(DepReg, R))
789 return false;
790 }
791
792 // Handle imp-use of super reg case. There is a target independent side
793 // change that should prevent this situation but I am handling it for
794 // just-in-case. For example, we cannot newify R2 in the following case:
795 // %r3 = A2_tfrsi 0;
796 // S2_storeri_io killed %r0, 0, killed %r2, implicit killed %d1;
797 for (auto &MO : MI.operands()) {
798 if (MO.isReg() && MO.isUse() && MO.isImplicit() && MO.getReg() == DepReg)
799 return false;
800 }
801
802 // Can be dot new store.
803 return true;
804}
805
806// Can this MI to promoted to either new value store or new value jump.
808 const SUnit *PacketSU, unsigned DepReg,
810 if (!HII->mayBeNewStore(MI))
811 return false;
812
813 // Check to see the store can be new value'ed.
814 MachineInstr &PacketMI = *PacketSU->getInstr();
815 if (canPromoteToNewValueStore(MI, PacketMI, DepReg))
816 return true;
817
818 // Check to see the compare/jump can be new value'ed.
819 // This is done as a pass on its own. Don't need to check it here.
820 return false;
821}
822
823static bool isImplicitDependency(const MachineInstr &I, bool CheckDef,
824 unsigned DepReg) {
825 for (auto &MO : I.operands()) {
826 if (CheckDef && MO.isRegMask() && MO.clobbersPhysReg(DepReg))
827 return true;
828 if (!MO.isReg() || MO.getReg() != DepReg || !MO.isImplicit())
829 continue;
830 if (CheckDef == MO.isDef())
831 return true;
832 }
833 return false;
834}
835
836// Check to see if an instruction can be dot new.
838 const SUnit *PacketSU, unsigned DepReg, MachineBasicBlock::iterator &MII,
839 const TargetRegisterClass* RC) {
840 // Already a dot new instruction.
841 if (HII->isDotNewInst(MI) && !HII->mayBeNewStore(MI))
842 return false;
843
844 if (!isNewifiable(MI, RC))
845 return false;
846
847 const MachineInstr &PI = *PacketSU->getInstr();
848
849 // The "new value" cannot come from inline asm.
850 if (PI.isInlineAsm())
851 return false;
852
853 // IMPLICIT_DEFs won't materialize as real instructions, so .new makes no
854 // sense.
855 if (PI.isImplicitDef())
856 return false;
857
858 // If dependency is through an implicitly defined register, we should not
859 // newify the use.
860 if (isImplicitDependency(PI, true, DepReg) ||
861 isImplicitDependency(MI, false, DepReg))
862 return false;
863
864 const MCInstrDesc& MCID = PI.getDesc();
865 const TargetRegisterClass *VecRC = HII->getRegClass(MCID, 0);
866 if (DisableVecDblNVStores && VecRC == &Hexagon::HvxWRRegClass)
867 return false;
868
869 // predicate .new
870 if (RC == &Hexagon::PredRegsRegClass)
871 return HII->predCanBeUsedAsDotNew(PI, DepReg);
872
873 if (RC != &Hexagon::PredRegsRegClass && !HII->mayBeNewStore(MI))
874 return false;
875
876 // Create a dot new machine instruction to see if resources can be
877 // allocated. If not, bail out now.
878 int NewOpcode = (RC != &Hexagon::PredRegsRegClass) ? HII->getDotNewOp(MI) :
879 HII->getDotNewPredOp(MI, MBPI);
880 const MCInstrDesc &D = HII->get(NewOpcode);
881 MachineInstr *NewMI = MF.CreateMachineInstr(D, DebugLoc());
882 bool ResourcesAvailable = ResourceTracker->canReserveResources(*NewMI);
883 MF.deleteMachineInstr(NewMI);
884 if (!ResourcesAvailable)
885 return false;
886
887 // New Value Store only. New Value Jump generated as a separate pass.
888 if (!canPromoteToNewValue(MI, PacketSU, DepReg, MII))
889 return false;
890
891 return true;
892}
893
894// Go through the packet instructions and search for an anti dependency between
895// them and DepReg from MI. Consider this case:
896// Trying to add
897// a) %r1 = TFRI_cdNotPt %p3, 2
898// to this packet:
899// {
900// b) %p0 = C2_or killed %p3, killed %p0
901// c) %p3 = C2_tfrrp %r23
902// d) %r1 = C2_cmovenewit %p3, 4
903// }
904// The P3 from a) and d) will be complements after
905// a)'s P3 is converted to .new form
906// Anti-dep between c) and b) is irrelevant for this case
908 unsigned DepReg) {
909 SUnit *PacketSUDep = MIToSUnit.find(&MI)->second;
910
911 for (auto *I : CurrentPacketMIs) {
912 // We only care for dependencies to predicated instructions
913 if (!HII->isPredicated(*I))
914 continue;
915
916 // Scheduling Unit for current insn in the packet
917 SUnit *PacketSU = MIToSUnit.find(I)->second;
918
919 // Look at dependencies between current members of the packet and
920 // predicate defining instruction MI. Make sure that dependency is
921 // on the exact register we care about.
922 if (PacketSU->isSucc(PacketSUDep)) {
923 for (unsigned i = 0; i < PacketSU->Succs.size(); ++i) {
924 auto &Dep = PacketSU->Succs[i];
925 if (Dep.getSUnit() == PacketSUDep && Dep.getKind() == SDep::Anti &&
926 Dep.getReg() == DepReg)
927 return true;
928 }
929 }
930 }
931
932 return false;
933}
934
935/// Gets the predicate register of a predicated instruction.
937 const HexagonInstrInfo *QII) {
938 /// We use the following rule: The first predicate register that is a use is
939 /// the predicate register of a predicated instruction.
940 assert(QII->isPredicated(MI) && "Must be predicated instruction");
941
942 for (auto &Op : MI.operands()) {
943 if (Op.isReg() && Op.getReg() && Op.isUse() &&
944 Hexagon::PredRegsRegClass.contains(Op.getReg()))
945 return Op.getReg();
946 }
947
948 llvm_unreachable("Unknown instruction operand layout");
949 return 0;
950}
951
952// Given two predicated instructions, this function detects whether
953// the predicates are complements.
955 MachineInstr &MI2) {
956 // If we don't know the predicate sense of the instructions bail out early, we
957 // need it later.
958 if (getPredicateSense(MI1, HII) == PK_Unknown ||
959 getPredicateSense(MI2, HII) == PK_Unknown)
960 return false;
961
962 // Scheduling unit for candidate.
963 SUnit *SU = MIToSUnit[&MI1];
964
965 // One corner case deals with the following scenario:
966 // Trying to add
967 // a) %r24 = A2_tfrt %p0, %r25
968 // to this packet:
969 // {
970 // b) %r25 = A2_tfrf %p0, %r24
971 // c) %p0 = C2_cmpeqi %r26, 1
972 // }
973 //
974 // On general check a) and b) are complements, but presence of c) will
975 // convert a) to .new form, and then it is not a complement.
976 // We attempt to detect it by analyzing existing dependencies in the packet.
977
978 // Analyze relationships between all existing members of the packet.
979 // Look for Anti dependency on the same predicate reg as used in the
980 // candidate.
981 for (auto *I : CurrentPacketMIs) {
982 // Scheduling Unit for current insn in the packet.
983 SUnit *PacketSU = MIToSUnit.find(I)->second;
984
985 // If this instruction in the packet is succeeded by the candidate...
986 if (PacketSU->isSucc(SU)) {
987 for (unsigned i = 0; i < PacketSU->Succs.size(); ++i) {
988 auto Dep = PacketSU->Succs[i];
989 // The corner case exist when there is true data dependency between
990 // candidate and one of current packet members, this dep is on
991 // predicate reg, and there already exist anti dep on the same pred in
992 // the packet.
993 if (Dep.getSUnit() == SU && Dep.getKind() == SDep::Data &&
994 Hexagon::PredRegsRegClass.contains(Dep.getReg())) {
995 // Here I know that I is predicate setting instruction with true
996 // data dep to candidate on the register we care about - c) in the
997 // above example. Now I need to see if there is an anti dependency
998 // from c) to any other instruction in the same packet on the pred
999 // reg of interest.
1000 if (restrictingDepExistInPacket(*I, Dep.getReg()))
1001 return false;
1002 }
1003 }
1004 }
1005 }
1006
1007 // If the above case does not apply, check regular complement condition.
1008 // Check that the predicate register is the same and that the predicate
1009 // sense is different We also need to differentiate .old vs. .new: !p0
1010 // is not complementary to p0.new.
1011 unsigned PReg1 = getPredicatedRegister(MI1, HII);
1012 unsigned PReg2 = getPredicatedRegister(MI2, HII);
1013 return PReg1 == PReg2 &&
1014 Hexagon::PredRegsRegClass.contains(PReg1) &&
1015 Hexagon::PredRegsRegClass.contains(PReg2) &&
1016 getPredicateSense(MI1, HII) != getPredicateSense(MI2, HII) &&
1017 HII->isDotNewInst(MI1) == HII->isDotNewInst(MI2);
1018}
1019
1020// Initialize packetizer flags.
1022 Dependence = false;
1023 PromotedToDotNew = false;
1024 GlueToNewValueJump = false;
1025 GlueAllocframeStore = false;
1026 FoundSequentialDependence = false;
1027 ChangedOffset = INT64_MAX;
1028}
1029
1030// Ignore bundling of pseudo instructions.
1032 const MachineBasicBlock *) {
1033 if (MI.isDebugInstr())
1034 return true;
1035
1036 if (MI.isCFIInstruction())
1037 return false;
1038
1039 // We must print out inline assembly.
1040 if (MI.isInlineAsm())
1041 return false;
1042
1043 if (MI.isImplicitDef())
1044 return false;
1045
1046 // We check if MI has any functional units mapped to it. If it doesn't,
1047 // we ignore the instruction.
1048 const MCInstrDesc& TID = MI.getDesc();
1049 auto *IS = ResourceTracker->getInstrItins()->beginStage(TID.getSchedClass());
1050 return !IS->getUnits();
1051}
1052
1054 // Ensure any bundles created by gather packetize remain separate.
1055 if (MI.isBundle())
1056 return true;
1057
1058 if (MI.isEHLabel() || MI.isCFIInstruction())
1059 return true;
1060
1061 // Consider inline asm to not be a solo instruction by default.
1062 // Inline asm will be put in a packet temporarily, but then it will be
1063 // removed, and placed outside of the packet (before or after, depending
1064 // on dependencies). This is to reduce the impact of inline asm as a
1065 // "packet splitting" instruction.
1066 if (MI.isInlineAsm() && !ScheduleInlineAsm)
1067 return true;
1068
1069 if (isSchedBarrier(MI))
1070 return true;
1071
1072 if (HII->isSolo(MI))
1073 return true;
1074
1075 if (MI.getOpcode() == Hexagon::PATCHABLE_FUNCTION_ENTER ||
1076 MI.getOpcode() == Hexagon::PATCHABLE_FUNCTION_EXIT ||
1077 MI.getOpcode() == Hexagon::PATCHABLE_TAIL_CALL ||
1078 MI.getOpcode() == Hexagon::PATCHABLE_EVENT_CALL ||
1079 MI.getOpcode() == Hexagon::PATCHABLE_TYPED_EVENT_CALL)
1080 return true;
1081
1082 if (MI.getOpcode() == Hexagon::A2_nop)
1083 return true;
1084
1085 return false;
1086}
1087
1088// Quick check if instructions MI and MJ cannot coexist in the same packet.
1089// Limit the tests to be "one-way", e.g. "if MI->isBranch and MJ->isInlineAsm",
1090// but not the symmetric case: "if MJ->isBranch and MI->isInlineAsm".
1091// For full test call this function twice:
1092// cannotCoexistAsymm(MI, MJ) || cannotCoexistAsymm(MJ, MI)
1093// Doing the test only one way saves the amount of code in this function,
1094// since every test would need to be repeated with the MI and MJ reversed.
1095static bool cannotCoexistAsymm(const MachineInstr &MI, const MachineInstr &MJ,
1096 const HexagonInstrInfo &HII) {
1097 const MachineFunction *MF = MI.getParent()->getParent();
1099 HII.isHVXMemWithAIndirect(MI, MJ))
1100 return true;
1101
1102 // Don't allow a store and an instruction that must be in slot0 and
1103 // doesn't allow a slot1 instruction.
1104 if (MI.mayStore() && HII.isRestrictNoSlot1Store(MJ) && HII.isPureSlot0(MJ))
1105 return true;
1106
1107 // An inline asm cannot be together with a branch, because we may not be
1108 // able to remove the asm out after packetizing (i.e. if the asm must be
1109 // moved past the bundle). Similarly, two asms cannot be together to avoid
1110 // complications when determining their relative order outside of a bundle.
1111 if (MI.isInlineAsm())
1112 return MJ.isInlineAsm() || MJ.isBranch() || MJ.isBarrier() ||
1113 MJ.isCall() || MJ.isTerminator();
1114
1115 // New-value stores cannot coexist with any other stores.
1116 if (HII.isNewValueStore(MI) && MJ.mayStore())
1117 return true;
1118
1119 switch (MI.getOpcode()) {
1120 case Hexagon::S2_storew_locked:
1121 case Hexagon::S4_stored_locked:
1122 case Hexagon::L2_loadw_locked:
1123 case Hexagon::L4_loadd_locked:
1124 case Hexagon::Y2_dccleana:
1125 case Hexagon::Y2_dccleaninva:
1126 case Hexagon::Y2_dcinva:
1127 case Hexagon::Y2_dczeroa:
1128 case Hexagon::Y4_l2fetch:
1129 case Hexagon::Y5_l2fetch: {
1130 // These instructions can only be grouped with ALU32 or non-floating-point
1131 // XTYPE instructions. Since there is no convenient way of identifying fp
1132 // XTYPE instructions, only allow grouping with ALU32 for now.
1133 unsigned TJ = HII.getType(MJ);
1134 if (TJ != HexagonII::TypeALU32_2op &&
1137 return true;
1138 break;
1139 }
1140 default:
1141 break;
1142 }
1143
1144 // "False" really means that the quick check failed to determine if
1145 // I and J cannot coexist.
1146 return false;
1147}
1148
1149// Full, symmetric check.
1151 const MachineInstr &MJ) {
1152 return cannotCoexistAsymm(MI, MJ, *HII) || cannotCoexistAsymm(MJ, MI, *HII);
1153}
1154
1156 for (auto &B : MF) {
1158 for (MachineInstr &MI : llvm::make_early_inc_range(B.instrs())) {
1159 if (MI.isBundle())
1160 BundleIt = MI.getIterator();
1161 if (!MI.isInsideBundle())
1162 continue;
1163
1164 // Decide on where to insert the instruction that we are pulling out.
1165 // Debug instructions always go before the bundle, but the placement of
1166 // INLINE_ASM depends on potential dependencies. By default, try to
1167 // put it before the bundle, but if the asm writes to a register that
1168 // other instructions in the bundle read, then we need to place it
1169 // after the bundle (to preserve the bundle semantics).
1170 bool InsertBeforeBundle;
1171 if (MI.isInlineAsm())
1172 InsertBeforeBundle = !hasWriteToReadDep(MI, *BundleIt, HRI);
1173 else if (MI.isDebugInstr())
1174 InsertBeforeBundle = true;
1175 else
1176 continue;
1177
1178 BundleIt = moveInstrOut(MI, BundleIt, InsertBeforeBundle);
1179 }
1180 }
1181}
1182
1183// Check if a given instruction is of class "system".
1184static bool isSystemInstr(const MachineInstr &MI) {
1185 unsigned Opc = MI.getOpcode();
1186 switch (Opc) {
1187 case Hexagon::Y2_barrier:
1188 case Hexagon::Y2_dcfetchbo:
1189 case Hexagon::Y4_l2fetch:
1190 case Hexagon::Y5_l2fetch:
1191 return true;
1192 }
1193 return false;
1194}
1195
1197 const MachineInstr &J) {
1198 // The dependence graph may not include edges between dead definitions,
1199 // so without extra checks, we could end up packetizing two instruction
1200 // defining the same (dead) register.
1201 if (I.isCall() || J.isCall())
1202 return false;
1203 if (HII->isPredicated(I) || HII->isPredicated(J))
1204 return false;
1205
1206 BitVector DeadDefs(Hexagon::NUM_TARGET_REGS);
1207 for (auto &MO : I.operands()) {
1208 if (!MO.isReg() || !MO.isDef() || !MO.isDead())
1209 continue;
1210 DeadDefs[MO.getReg()] = true;
1211 }
1212
1213 for (auto &MO : J.operands()) {
1214 if (!MO.isReg() || !MO.isDef() || !MO.isDead())
1215 continue;
1216 Register R = MO.getReg();
1217 if (R != Hexagon::USR_OVF && DeadDefs[R])
1218 return true;
1219 }
1220 return false;
1221}
1222
1224 const MachineInstr &J) {
1225 // A save callee-save register function call can only be in a packet
1226 // with instructions that don't write to the callee-save registers.
1227 if ((HII->isSaveCalleeSavedRegsCall(I) &&
1228 doesModifyCalleeSavedReg(J, HRI)) ||
1229 (HII->isSaveCalleeSavedRegsCall(J) &&
1231 return true;
1232
1233 // Two control flow instructions cannot go in the same packet.
1234 if (isControlFlow(I) && isControlFlow(J))
1235 return true;
1236
1237 // \ref-manual (7.3.4) A loop setup packet in loopN or spNloop0 cannot
1238 // contain a speculative indirect jump,
1239 // a new-value compare jump or a dealloc_return.
1240 auto isBadForLoopN = [this] (const MachineInstr &MI) -> bool {
1241 if (MI.isCall() || HII->isDeallocRet(MI) || HII->isNewValueJump(MI))
1242 return true;
1243 if (HII->isPredicated(MI) && HII->isPredicatedNew(MI) && HII->isJumpR(MI))
1244 return true;
1245 return false;
1246 };
1247
1248 if (HII->isLoopN(I) && isBadForLoopN(J))
1249 return true;
1250 if (HII->isLoopN(J) && isBadForLoopN(I))
1251 return true;
1252
1253 // dealloc_return cannot appear in the same packet as a conditional or
1254 // unconditional jump.
1255 return HII->isDeallocRet(I) &&
1256 (J.isBranch() || J.isCall() || J.isBarrier());
1257}
1258
1260 const MachineInstr &J) {
1261 // Adding I to a packet that has J.
1262
1263 // Regmasks are not reflected in the scheduling dependency graph, so
1264 // we need to check them manually. This code assumes that regmasks only
1265 // occur on calls, and the problematic case is when we add an instruction
1266 // defining a register R to a packet that has a call that clobbers R via
1267 // a regmask. Those cannot be packetized together, because the call will
1268 // be executed last. That's also a reason why it is ok to add a call
1269 // clobbering R to a packet that defines R.
1270
1271 // Look for regmasks in J.
1272 for (const MachineOperand &OpJ : J.operands()) {
1273 if (!OpJ.isRegMask())
1274 continue;
1275 assert((J.isCall() || HII->isTailCall(J)) && "Regmask on a non-call");
1276 for (const MachineOperand &OpI : I.operands()) {
1277 if (OpI.isReg()) {
1278 if (OpJ.clobbersPhysReg(OpI.getReg()))
1279 return true;
1280 } else if (OpI.isRegMask()) {
1281 // Both are regmasks. Assume that they intersect.
1282 return true;
1283 }
1284 }
1285 }
1286 return false;
1287}
1288
1290 const MachineInstr &J) {
1291 bool SysI = isSystemInstr(I), SysJ = isSystemInstr(J);
1292 bool StoreI = I.mayStore(), StoreJ = J.mayStore();
1293 if ((SysI && StoreJ) || (SysJ && StoreI))
1294 return true;
1295
1296 if (StoreI && StoreJ) {
1297 if (HII->isNewValueInst(J) || HII->isMemOp(J) || HII->isMemOp(I))
1298 return true;
1299 } else {
1300 // A memop cannot be in the same packet with another memop or a store.
1301 // Two stores can be together, but here I and J cannot both be stores.
1302 bool MopStI = HII->isMemOp(I) || StoreI;
1303 bool MopStJ = HII->isMemOp(J) || StoreJ;
1304 if (MopStI && MopStJ)
1305 return true;
1306 }
1307
1308 return (StoreJ && HII->isDeallocRet(I)) || (StoreI && HII->isDeallocRet(J));
1309}
1310
1311// SUI is the current instruction that is outside of the current packet.
1312// SUJ is the current instruction inside the current packet against which that
1313// SUI will be packetized.
1315 assert(SUI->getInstr() && SUJ->getInstr());
1316 MachineInstr &I = *SUI->getInstr();
1317 MachineInstr &J = *SUJ->getInstr();
1318
1319 // Clear IgnoreDepMIs when Packet starts.
1320 if (CurrentPacketMIs.size() == 1)
1321 IgnoreDepMIs.clear();
1322
1323 MachineBasicBlock::iterator II = I.getIterator();
1324
1325 // Solo instructions cannot go in the packet.
1326 assert(!isSoloInstruction(I) && "Unexpected solo instr!");
1327
1328 if (cannotCoexist(I, J))
1329 return false;
1330
1331 Dependence = hasDeadDependence(I, J) || hasControlDependence(I, J);
1332 if (Dependence)
1333 return false;
1334
1335 // Regmasks are not accounted for in the scheduling graph, so we need
1336 // to explicitly check for dependencies caused by them. They should only
1337 // appear on calls, so it's not too pessimistic to reject all regmask
1338 // dependencies.
1339 Dependence = hasRegMaskDependence(I, J);
1340 if (Dependence)
1341 return false;
1342
1343 // Dual-store does not allow second store, if the first store is not
1344 // in SLOT0. New value store, new value jump, dealloc_return and memop
1345 // always take SLOT0. Arch spec 3.4.4.2.
1346 Dependence = hasDualStoreDependence(I, J);
1347 if (Dependence)
1348 return false;
1349
1350 // If an instruction feeds new value jump, glue it.
1351 MachineBasicBlock::iterator NextMII = I.getIterator();
1352 ++NextMII;
1353 if (NextMII != I.getParent()->end() && HII->isNewValueJump(*NextMII)) {
1354 MachineInstr &NextMI = *NextMII;
1355
1356 bool secondRegMatch = false;
1357 const MachineOperand &NOp0 = NextMI.getOperand(0);
1358 const MachineOperand &NOp1 = NextMI.getOperand(1);
1359
1360 if (NOp1.isReg() && I.getOperand(0).getReg() == NOp1.getReg())
1361 secondRegMatch = true;
1362
1363 for (MachineInstr *PI : CurrentPacketMIs) {
1364 // NVJ can not be part of the dual jump - Arch Spec: section 7.8.
1365 if (PI->isCall()) {
1366 Dependence = true;
1367 break;
1368 }
1369 // Validate:
1370 // 1. Packet does not have a store in it.
1371 // 2. If the first operand of the nvj is newified, and the second
1372 // operand is also a reg, it (second reg) is not defined in
1373 // the same packet.
1374 // 3. If the second operand of the nvj is newified, (which means
1375 // first operand is also a reg), first reg is not defined in
1376 // the same packet.
1377 if (PI->getOpcode() == Hexagon::S2_allocframe || PI->mayStore() ||
1378 HII->isLoopN(*PI)) {
1379 Dependence = true;
1380 break;
1381 }
1382 // Check #2/#3.
1383 const MachineOperand &OpR = secondRegMatch ? NOp0 : NOp1;
1384 if (OpR.isReg() && PI->modifiesRegister(OpR.getReg(), HRI)) {
1385 Dependence = true;
1386 break;
1387 }
1388 }
1389
1390 GlueToNewValueJump = true;
1391 if (Dependence)
1392 return false;
1393 }
1394
1395 // There no dependency between a prolog instruction and its successor.
1396 if (!SUJ->isSucc(SUI))
1397 return true;
1398
1399 for (unsigned i = 0; i < SUJ->Succs.size(); ++i) {
1400 if (FoundSequentialDependence)
1401 break;
1402
1403 if (SUJ->Succs[i].getSUnit() != SUI)
1404 continue;
1405
1406 SDep::Kind DepType = SUJ->Succs[i].getKind();
1407 // For direct calls:
1408 // Ignore register dependences for call instructions for packetization
1409 // purposes except for those due to r31 and predicate registers.
1410 //
1411 // For indirect calls:
1412 // Same as direct calls + check for true dependences to the register
1413 // used in the indirect call.
1414 //
1415 // We completely ignore Order dependences for call instructions.
1416 //
1417 // For returns:
1418 // Ignore register dependences for return instructions like jumpr,
1419 // dealloc return unless we have dependencies on the explicit uses
1420 // of the registers used by jumpr (like r31) or dealloc return
1421 // (like r29 or r30).
1422 unsigned DepReg = 0;
1423 const TargetRegisterClass *RC = nullptr;
1424 if (DepType == SDep::Data) {
1425 DepReg = SUJ->Succs[i].getReg();
1426 RC = HRI->getMinimalPhysRegClass(DepReg);
1427 }
1428
1429 if (I.isCall() || HII->isJumpR(I) || I.isReturn() || HII->isTailCall(I)) {
1430 if (!isRegDependence(DepType))
1431 continue;
1432 if (!isCallDependent(I, DepType, SUJ->Succs[i].getReg()))
1433 continue;
1434 }
1435
1436 if (DepType == SDep::Data) {
1437 if (canPromoteToDotCur(J, SUJ, DepReg, II, RC))
1438 if (promoteToDotCur(J, DepType, II, RC))
1439 continue;
1440 }
1441
1442 // Data dependence ok if we have load.cur.
1443 if (DepType == SDep::Data && HII->isDotCurInst(J)) {
1444 if (HII->isHVXVec(I))
1445 continue;
1446 }
1447
1448 // For instructions that can be promoted to dot-new, try to promote.
1449 if (DepType == SDep::Data) {
1450 if (canPromoteToDotNew(I, SUJ, DepReg, II, RC)) {
1451 if (promoteToDotNew(I, DepType, II, RC)) {
1452 PromotedToDotNew = true;
1453 if (cannotCoexist(I, J))
1454 FoundSequentialDependence = true;
1455 continue;
1456 }
1457 }
1458 if (HII->isNewValueJump(I))
1459 continue;
1460 }
1461
1462 // For predicated instructions, if the predicates are complements then
1463 // there can be no dependence.
1464 if (HII->isPredicated(I) && HII->isPredicated(J) &&
1466 // Not always safe to do this translation.
1467 // DAG Builder attempts to reduce dependence edges using transitive
1468 // nature of dependencies. Here is an example:
1469 //
1470 // r0 = tfr_pt ... (1)
1471 // r0 = tfr_pf ... (2)
1472 // r0 = tfr_pt ... (3)
1473 //
1474 // There will be an output dependence between (1)->(2) and (2)->(3).
1475 // However, there is no dependence edge between (1)->(3). This results
1476 // in all 3 instructions going in the same packet. We ignore dependce
1477 // only once to avoid this situation.
1478 auto Itr = find(IgnoreDepMIs, &J);
1479 if (Itr != IgnoreDepMIs.end()) {
1480 Dependence = true;
1481 return false;
1482 }
1483 IgnoreDepMIs.push_back(&I);
1484 continue;
1485 }
1486
1487 // Ignore Order dependences between unconditional direct branches
1488 // and non-control-flow instructions.
1489 if (isDirectJump(I) && !J.isBranch() && !J.isCall() &&
1490 DepType == SDep::Order)
1491 continue;
1492
1493 // Ignore all dependences for jumps except for true and output
1494 // dependences.
1495 if (I.isConditionalBranch() && DepType != SDep::Data &&
1496 DepType != SDep::Output)
1497 continue;
1498
1499 if (DepType == SDep::Output) {
1500 FoundSequentialDependence = true;
1501 break;
1502 }
1503
1504 // For Order dependences:
1505 // 1. Volatile loads/stores can be packetized together, unless other
1506 // rules prevent is.
1507 // 2. Store followed by a load is not allowed.
1508 // 3. Store followed by a store is valid.
1509 // 4. Load followed by any memory operation is allowed.
1510 if (DepType == SDep::Order) {
1511 if (!PacketizeVolatiles) {
1512 bool OrdRefs = I.hasOrderedMemoryRef() || J.hasOrderedMemoryRef();
1513 if (OrdRefs) {
1514 FoundSequentialDependence = true;
1515 break;
1516 }
1517 }
1518 // J is first, I is second.
1519 bool LoadJ = J.mayLoad(), StoreJ = J.mayStore();
1520 bool LoadI = I.mayLoad(), StoreI = I.mayStore();
1521 bool NVStoreJ = HII->isNewValueStore(J);
1522 bool NVStoreI = HII->isNewValueStore(I);
1523 bool IsVecJ = HII->isHVXVec(J);
1524 bool IsVecI = HII->isHVXVec(I);
1525
1526 // Don't reorder the loads if there is an order dependence. This would
1527 // occur if the first instruction must go in slot0.
1528 if (LoadJ && LoadI && HII->isPureSlot0(J)) {
1529 FoundSequentialDependence = true;
1530 break;
1531 }
1532
1533 if (Slot1Store && MF.getSubtarget<HexagonSubtarget>().hasV65Ops() &&
1534 ((LoadJ && StoreI && !NVStoreI) ||
1535 (StoreJ && LoadI && !NVStoreJ)) &&
1536 (J.getOpcode() != Hexagon::S2_allocframe &&
1537 I.getOpcode() != Hexagon::S2_allocframe) &&
1538 (J.getOpcode() != Hexagon::L2_deallocframe &&
1539 I.getOpcode() != Hexagon::L2_deallocframe) &&
1540 (!HII->isMemOp(J) && !HII->isMemOp(I)) && (!IsVecJ && !IsVecI))
1541 setmemShufDisabled(true);
1542 else
1543 if (StoreJ && LoadI && alias(J, I)) {
1544 FoundSequentialDependence = true;
1545 break;
1546 }
1547
1548 if (!StoreJ)
1549 if (!LoadJ || (!LoadI && !StoreI)) {
1550 // If J is neither load nor store, assume a dependency.
1551 // If J is a load, but I is neither, also assume a dependency.
1552 FoundSequentialDependence = true;
1553 break;
1554 }
1555 // Store followed by store: not OK on V2.
1556 // Store followed by load: not OK on all.
1557 // Load followed by store: OK on all.
1558 // Load followed by load: OK on all.
1559 continue;
1560 }
1561
1562 // Special case for ALLOCFRAME: even though there is dependency
1563 // between ALLOCFRAME and subsequent store, allow it to be packetized
1564 // in a same packet. This implies that the store is using the caller's
1565 // SP. Hence, offset needs to be updated accordingly.
1566 if (DepType == SDep::Data && J.getOpcode() == Hexagon::S2_allocframe) {
1567 unsigned Opc = I.getOpcode();
1568 switch (Opc) {
1569 case Hexagon::S2_storerd_io:
1570 case Hexagon::S2_storeri_io:
1571 case Hexagon::S2_storerh_io:
1572 case Hexagon::S2_storerb_io:
1573 if (I.getOperand(0).getReg() == HRI->getStackRegister()) {
1574 // Since this store is to be glued with allocframe in the same
1575 // packet, it will use SP of the previous stack frame, i.e.
1576 // caller's SP. Therefore, we need to recalculate offset
1577 // according to this change.
1578 GlueAllocframeStore = useCallersSP(I);
1579 if (GlueAllocframeStore)
1580 continue;
1581 }
1582 break;
1583 default:
1584 break;
1585 }
1586 }
1587
1588 // There are certain anti-dependencies that cannot be ignored.
1589 // Specifically:
1590 // J2_call ... implicit-def %r0 ; SUJ
1591 // R0 = ... ; SUI
1592 // Those cannot be packetized together, since the call will observe
1593 // the effect of the assignment to R0.
1594 if ((DepType == SDep::Anti || DepType == SDep::Output) && J.isCall()) {
1595 // Check if I defines any volatile register. We should also check
1596 // registers that the call may read, but these happen to be a
1597 // subset of the volatile register set.
1598 for (const MachineOperand &Op : I.operands()) {
1599 if (Op.isReg() && Op.isDef()) {
1600 Register R = Op.getReg();
1601 if (!J.readsRegister(R, HRI) && !J.modifiesRegister(R, HRI))
1602 continue;
1603 } else if (!Op.isRegMask()) {
1604 // If I has a regmask assume dependency.
1605 continue;
1606 }
1607 FoundSequentialDependence = true;
1608 break;
1609 }
1610 }
1611
1612 // Skip over remaining anti-dependences. Two instructions that are
1613 // anti-dependent can share a packet, since in most such cases all
1614 // operands are read before any modifications take place.
1615 // The exceptions are branch and call instructions, since they are
1616 // executed after all other instructions have completed (at least
1617 // conceptually).
1618 if (DepType != SDep::Anti) {
1619 FoundSequentialDependence = true;
1620 break;
1621 }
1622 }
1623
1624 if (FoundSequentialDependence) {
1625 Dependence = true;
1626 return false;
1627 }
1628
1629 return true;
1630}
1631
1633 assert(SUI->getInstr() && SUJ->getInstr());
1634 MachineInstr &I = *SUI->getInstr();
1635 MachineInstr &J = *SUJ->getInstr();
1636
1637 bool Coexist = !cannotCoexist(I, J);
1638
1639 if (Coexist && !Dependence)
1640 return true;
1641
1642 // Check if the instruction was promoted to a dot-new. If so, demote it
1643 // back into a dot-old.
1644 if (PromotedToDotNew)
1646
1647 cleanUpDotCur();
1648 // Check if the instruction (must be a store) was glued with an allocframe
1649 // instruction. If so, restore its offset to its original value, i.e. use
1650 // current SP instead of caller's SP.
1651 if (GlueAllocframeStore) {
1652 useCalleesSP(I);
1653 GlueAllocframeStore = false;
1654 }
1655
1656 if (ChangedOffset != INT64_MAX)
1658
1659 if (GlueToNewValueJump) {
1660 // Putting I and J together would prevent the new-value jump from being
1661 // packetized with the producer. In that case I and J must be separated.
1662 GlueToNewValueJump = false;
1663 return false;
1664 }
1665
1666 if (!Coexist)
1667 return false;
1668
1669 if (ChangedOffset == INT64_MAX && updateOffset(SUI, SUJ)) {
1670 FoundSequentialDependence = false;
1671 Dependence = false;
1672 return true;
1673 }
1674
1675 return false;
1676}
1677
1678
1680 bool FoundLoad = false;
1681 bool FoundStore = false;
1682
1683 for (auto *MJ : CurrentPacketMIs) {
1684 unsigned Opc = MJ->getOpcode();
1685 if (Opc == Hexagon::S2_allocframe || Opc == Hexagon::L2_deallocframe)
1686 continue;
1687 if (HII->isMemOp(*MJ))
1688 continue;
1689 if (MJ->mayLoad())
1690 FoundLoad = true;
1691 if (MJ->mayStore() && !HII->isNewValueStore(*MJ))
1692 FoundStore = true;
1693 }
1694 return FoundLoad && FoundStore;
1695}
1696
1697
1700 MachineBasicBlock::iterator MII = MI.getIterator();
1701 MachineBasicBlock *MBB = MI.getParent();
1702
1703 if (CurrentPacketMIs.empty()) {
1704 PacketStalls = false;
1705 PacketStallCycles = 0;
1706 }
1707 PacketStalls |= producesStall(MI);
1708 PacketStallCycles = std::max(PacketStallCycles, calcStall(MI));
1709
1710 if (MI.isImplicitDef()) {
1711 // Add to the packet to allow subsequent instructions to be checked
1712 // properly.
1713 CurrentPacketMIs.push_back(&MI);
1714 return MII;
1715 }
1716 assert(ResourceTracker->canReserveResources(MI));
1717
1718 bool ExtMI = HII->isExtended(MI) || HII->isConstExtended(MI);
1719 bool Good = true;
1720
1721 if (GlueToNewValueJump) {
1722 MachineInstr &NvjMI = *++MII;
1723 // We need to put both instructions in the same packet: MI and NvjMI.
1724 // Either of them can require a constant extender. Try to add both to
1725 // the current packet, and if that fails, end the packet and start a
1726 // new one.
1727 ResourceTracker->reserveResources(MI);
1728 if (ExtMI)
1730
1731 bool ExtNvjMI = HII->isExtended(NvjMI) || HII->isConstExtended(NvjMI);
1732 if (Good) {
1733 if (ResourceTracker->canReserveResources(NvjMI))
1734 ResourceTracker->reserveResources(NvjMI);
1735 else
1736 Good = false;
1737 }
1738 if (Good && ExtNvjMI)
1740
1741 if (!Good) {
1742 endPacket(MBB, MI);
1743 assert(ResourceTracker->canReserveResources(MI));
1744 ResourceTracker->reserveResources(MI);
1745 if (ExtMI) {
1748 }
1749 assert(ResourceTracker->canReserveResources(NvjMI));
1750 ResourceTracker->reserveResources(NvjMI);
1751 if (ExtNvjMI) {
1754 }
1755 }
1756 CurrentPacketMIs.push_back(&MI);
1757 CurrentPacketMIs.push_back(&NvjMI);
1758 return MII;
1759 }
1760
1761 ResourceTracker->reserveResources(MI);
1762 if (ExtMI && !tryAllocateResourcesForConstExt(true)) {
1763 endPacket(MBB, MI);
1764 if (PromotedToDotNew)
1766 if (GlueAllocframeStore) {
1768 GlueAllocframeStore = false;
1769 }
1770 ResourceTracker->reserveResources(MI);
1772 }
1773
1774 CurrentPacketMIs.push_back(&MI);
1775 return MII;
1776}
1777
1780 // Replace VLIWPacketizerList::endPacket(MBB, EndMI).
1781 LLVM_DEBUG({
1782 if (!CurrentPacketMIs.empty()) {
1783 dbgs() << "Finalizing packet:\n";
1784 unsigned Idx = 0;
1786 unsigned R = ResourceTracker->getUsedResources(Idx++);
1787 dbgs() << " * [res:0x" << utohexstr(R) << "] " << *MI;
1788 }
1789 }
1790 });
1791
1792 bool memShufDisabled = getmemShufDisabled();
1793 if (memShufDisabled && !foundLSInPacket()) {
1794 setmemShufDisabled(false);
1795 LLVM_DEBUG(dbgs() << " Not added to NoShufPacket\n");
1796 }
1797 memShufDisabled = getmemShufDisabled();
1798
1799 OldPacketMIs.clear();
1801 MachineBasicBlock::instr_iterator NextMI = std::next(MI->getIterator());
1802 for (auto &I : make_range(HII->expandVGatherPseudo(*MI), NextMI))
1803 OldPacketMIs.push_back(&I);
1804 }
1805 CurrentPacketMIs.clear();
1806
1807 if (OldPacketMIs.size() > 1) {
1808 MachineBasicBlock::instr_iterator FirstMI(OldPacketMIs.front());
1810 finalizeBundle(*MBB, FirstMI, LastMI);
1811 auto BundleMII = std::prev(FirstMI);
1812 if (memShufDisabled)
1813 HII->setBundleNoShuf(BundleMII);
1814
1815 setmemShufDisabled(false);
1816 }
1817
1818 PacketHasDuplex = false;
1819 PacketHasSLOT0OnlyInsn = false;
1820 ResourceTracker->clearResources();
1821 LLVM_DEBUG(dbgs() << "End packet\n");
1822}
1823
1825 if (Minimal)
1826 return false;
1827
1828 if (producesStall(MI))
1829 return false;
1830
1831 // If TinyCore with Duplexes is enabled, check if this MI can form a Duplex
1832 // with any other instruction in the existing packet.
1833 auto &HST = MI.getParent()->getParent()->getSubtarget<HexagonSubtarget>();
1834 // Constraint 1: Only one duplex allowed per packet.
1835 // Constraint 2: Consider duplex checks only if there is at least one
1836 // instruction in a packet.
1837 // Constraint 3: If one of the existing instructions in the packet has a
1838 // SLOT0 only instruction that can not be duplexed, do not attempt to form
1839 // duplexes. (TODO: This will invalidate the L4_return* instructions to form a
1840 // duplex)
1841 if (HST.isTinyCoreWithDuplex() && CurrentPacketMIs.size() > 0 &&
1842 !PacketHasDuplex) {
1843 // Check for SLOT0 only non-duplexable instruction in packet.
1844 for (auto &MJ : CurrentPacketMIs)
1845 PacketHasSLOT0OnlyInsn |= HII->isPureSlot0(*MJ);
1846 // Get the Big Core Opcode (dup_*).
1847 int Opcode = HII->getDuplexOpcode(MI, false);
1848 if (Opcode >= 0) {
1849 // We now have an instruction that can be duplexed.
1850 for (auto &MJ : CurrentPacketMIs) {
1851 if (HII->isDuplexPair(MI, *MJ) && !PacketHasSLOT0OnlyInsn) {
1852 PacketHasDuplex = true;
1853 return true;
1854 }
1855 }
1856 // If it can not be duplexed, check if there is a valid transition in DFA
1857 // with the original opcode.
1858 MachineInstr &MIRef = const_cast<MachineInstr &>(MI);
1859 MIRef.setDesc(HII->get(Opcode));
1860 return ResourceTracker->canReserveResources(MIRef);
1861 }
1862 }
1863
1864 return true;
1865}
1866
1867// V60 forward scheduling.
1869 // Check whether the previous packet is in a different loop. If this is the
1870 // case, there is little point in trying to avoid a stall because that would
1871 // favor the rare case (loop entry) over the common case (loop iteration).
1872 //
1873 // TODO: We should really be able to check all the incoming edges if this is
1874 // the first packet in a basic block, so we can avoid stalls from the loop
1875 // backedge.
1876 if (!OldPacketMIs.empty()) {
1877 auto *OldBB = OldPacketMIs.front()->getParent();
1878 auto *ThisBB = I.getParent();
1879 if (MLI->getLoopFor(OldBB) != MLI->getLoopFor(ThisBB))
1880 return 0;
1881 }
1882
1883 SUnit *SUI = MIToSUnit[const_cast<MachineInstr *>(&I)];
1884 if (!SUI)
1885 return 0;
1886
1887 // If the latency is 0 and there is a data dependence between this
1888 // instruction and any instruction in the current packet, we disregard any
1889 // potential stalls due to the instructions in the previous packet. Most of
1890 // the instruction pairs that can go together in the same packet have 0
1891 // latency between them. The exceptions are
1892 // 1. NewValueJumps as they're generated much later and the latencies can't
1893 // be changed at that point.
1894 // 2. .cur instructions, if its consumer has a 0 latency successor (such as
1895 // .new). In this case, the latency between .cur and the consumer stays
1896 // non-zero even though we can have both .cur and .new in the same packet.
1897 // Changing the latency to 0 is not an option as it causes software pipeliner
1898 // to not pipeline in some cases.
1899
1900 // For Example:
1901 // {
1902 // I1: v6.cur = vmem(r0++#1)
1903 // I2: v7 = valign(v6,v4,r2)
1904 // I3: vmem(r5++#1) = v7.new
1905 // }
1906 // Here I2 and I3 has 0 cycle latency, but I1 and I2 has 2.
1907
1908 for (auto *J : CurrentPacketMIs) {
1909 SUnit *SUJ = MIToSUnit[J];
1910 for (auto &Pred : SUI->Preds)
1911 if (Pred.getSUnit() == SUJ)
1912 if ((Pred.getLatency() == 0 && Pred.isAssignedRegDep()) ||
1913 HII->isNewValueJump(I) || HII->isToBeScheduledASAP(*J, I))
1914 return 0;
1915 }
1916
1917 // Check if the latency is greater than one between this instruction and any
1918 // instruction in the previous packet.
1919 for (auto *J : OldPacketMIs) {
1920 SUnit *SUJ = MIToSUnit[J];
1921 for (auto &Pred : SUI->Preds)
1922 if (Pred.getSUnit() == SUJ && Pred.getLatency() > 1)
1923 return Pred.getLatency();
1924 }
1925
1926 return 0;
1927}
1928
1930 unsigned int Latency = calcStall(I);
1931 if (Latency == 0)
1932 return false;
1933 // Ignore stall unless it stalls more than previous instruction in packet
1934 if (PacketStalls)
1935 return Latency > PacketStallCycles;
1936 return true;
1937}
1938
1939//===----------------------------------------------------------------------===//
1940// Public Constructor Functions
1941//===----------------------------------------------------------------------===//
1942
1944 return new HexagonPacketizer(Minimal);
1945}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
MachineBasicBlock & MBB
This file implements the BitVector class.
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")
This file defines the DenseSet and SmallDenseSet classes.
cl::opt< bool > ScheduleInlineAsm("hexagon-sched-inline-asm", cl::Hidden, cl::init(false), cl::desc("Do not consider inline-asm a scheduling/" "packetization boundary."))
#define HEXAGON_LRFP_SIZE
cl::opt< bool > DisablePacketizer
static bool cannotCoexistAsymm(const MachineInstr &MI, const MachineInstr &MJ, const HexagonInstrInfo &HII)
static bool isDirectJump(const MachineInstr &MI)
static MachineBasicBlock::iterator moveInstrOut(MachineInstr &MI, MachineBasicBlock::iterator BundleIt, bool Before)
static bool isRegDependence(const SDep::Kind DepType)
static const MachineOperand & getStoreValueOperand(const MachineInstr &MI)
static cl::opt< bool > EnableGenAllInsnClass("enable-gen-insn", cl::Hidden, cl::desc("Generate all instruction with TC"))
static bool isControlFlow(const MachineInstr &MI)
static cl::opt< bool > DisableVecDblNVStores("disable-vecdbl-nv-stores", cl::Hidden, cl::desc("Disable vector double new-value-stores"))
static PredicateKind getPredicateSense(const MachineInstr &MI, const HexagonInstrInfo *HII)
Returns true if an instruction is predicated on p0 and false if it's predicated on !...
static unsigned getPredicatedRegister(MachineInstr &MI, const HexagonInstrInfo *QII)
Gets the predicate register of a predicated instruction.
cl::opt< bool > DisablePacketizer("disable-packetizer", cl::Hidden, cl::desc("Disable Hexagon packetizer pass"))
static cl::opt< bool > Slot1Store("slot1-store-slot0-load", cl::Hidden, cl::init(true), cl::desc("Allow slot1 store and slot0 load"))
static cl::opt< bool > PacketizeVolatiles("hexagon-packetize-volatiles", cl::Hidden, cl::init(true), cl::desc("Allow non-solo packetization of volatile memory references"))
static bool hasWriteToReadDep(const MachineInstr &FirstI, const MachineInstr &SecondI, const TargetRegisterInfo *TRI)
static bool doesModifyCalleeSavedReg(const MachineInstr &MI, const TargetRegisterInfo *TRI)
Returns true if the instruction modifies a callee-saved register.
static bool isLoadAbsSet(const MachineInstr &MI)
static const MachineOperand & getAbsSetOperand(const MachineInstr &MI)
static const MachineOperand & getPostIncrementOperand(const MachineInstr &MI, const HexagonInstrInfo *HII)
static bool isImplicitDependency(const MachineInstr &I, bool CheckDef, unsigned DepReg)
static bool isSchedBarrier(const MachineInstr &MI)
static bool isSystemInstr(const MachineInstr &MI)
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:57
Register const TargetRegisterInfo * TRI
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
uint64_t IntrinsicInst * II
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition PassSupport.h:42
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition PassSupport.h:44
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition PassSupport.h:39
R600 Packetizer
This file contains some templates that are useful if you are working with the STL at all.
#define OP(OPC)
Definition Instruction.h:46
This file contains some functions that are useful when dealing with strings.
#define LLVM_DEBUG(...)
Definition Debug.h:119
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
AnalysisUsage & addRequired()
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition Pass.cpp:275
A debug info location.
Definition DebugLoc.h:126
Implements a dense probed hash-table based set.
Definition DenseSet.h:281
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
bool isPredicated(const MachineInstr &MI) const override
Returns true if the instruction is already predicated.
bool isHVXMemWithAIndirect(const MachineInstr &I, const MachineInstr &J) const
bool isRestrictNoSlot1Store(const MachineInstr &MI) const
bool isPureSlot0(const MachineInstr &MI) const
bool isPostIncrement(const MachineInstr &MI) const override
Return true for post-incremented instructions.
uint64_t getType(const MachineInstr &MI) const
bool isPredicatedTrue(const MachineInstr &MI) const
bool isNewValueStore(const MachineInstr &MI) const
bool arePredicatesComplements(MachineInstr &MI1, MachineInstr &MI2)
bool updateOffset(SUnit *SUI, SUnit *SUJ)
Return true if we can update the offset in MI so that MI and MJ can be packetized together.
void endPacket(MachineBasicBlock *MBB, MachineBasicBlock::iterator MI) override
HexagonPacketizerList(MachineFunction &MF, MachineLoopInfo &MLI, AAResults *AA, const MachineBranchProbabilityInfo *MBPI, bool Minimal)
bool isCallDependent(const MachineInstr &MI, SDep::Kind DepType, unsigned DepReg)
bool promoteToDotCur(MachineInstr &MI, SDep::Kind DepType, MachineBasicBlock::iterator &MII, const TargetRegisterClass *RC)
bool promoteToDotNew(MachineInstr &MI, SDep::Kind DepType, MachineBasicBlock::iterator &MII, const TargetRegisterClass *RC)
bool isLegalToPacketizeTogether(SUnit *SUI, SUnit *SUJ) override
bool canPromoteToDotCur(const MachineInstr &MI, const SUnit *PacketSU, unsigned DepReg, MachineBasicBlock::iterator &MII, const TargetRegisterClass *RC)
bool demoteToDotOld(MachineInstr &MI)
bool cannotCoexist(const MachineInstr &MI, const MachineInstr &MJ)
bool isSoloInstruction(const MachineInstr &MI) override
bool isLegalToPruneDependencies(SUnit *SUI, SUnit *SUJ) override
bool hasControlDependence(const MachineInstr &I, const MachineInstr &J)
bool restrictingDepExistInPacket(MachineInstr &, unsigned)
bool producesStall(const MachineInstr &MI)
void undoChangedOffset(MachineInstr &MI)
Undo the changed offset.
bool hasDualStoreDependence(const MachineInstr &I, const MachineInstr &J)
unsigned int calcStall(const MachineInstr &MI)
bool canPromoteToDotNew(const MachineInstr &MI, const SUnit *PacketSU, unsigned DepReg, MachineBasicBlock::iterator &MII, const TargetRegisterClass *RC)
bool canPromoteToNewValue(const MachineInstr &MI, const SUnit *PacketSU, unsigned DepReg, MachineBasicBlock::iterator &MII)
bool ignorePseudoInstruction(const MachineInstr &MI, const MachineBasicBlock *MBB) override
void unpacketizeSoloInstrs(MachineFunction &MF)
const MachineBranchProbabilityInfo * MBPI
A handle to the branch probability pass.
bool shouldAddToPacket(const MachineInstr &MI) override
bool canPromoteToNewValueStore(const MachineInstr &MI, const MachineInstr &PacketMI, unsigned DepReg)
bool tryAllocateResourcesForConstExt(bool Reserve)
MachineBasicBlock::iterator addToPacket(MachineInstr &MI) override
bool hasDeadDependence(const MachineInstr &I, const MachineInstr &J)
bool isNewifiable(const MachineInstr &MI, const TargetRegisterClass *NewRC)
bool hasRegMaskDependence(const MachineInstr &I, const MachineInstr &J)
const HexagonInstrInfo * getInstrInfo() const override
const HexagonRegisterInfo * getRegisterInfo() const override
Describe properties that are true of each instruction in the target description file.
unsigned getSchedClass() const
Return the scheduling class for this instruction.
Instructions::iterator instr_iterator
Instructions::const_iterator const_instr_iterator
MachineInstrBundleIterator< MachineInstr > iterator
Analysis pass which computes a MachineDominatorTree.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineFunctionProperties & getProperties() const
Get the function properties.
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.
bool isImplicitDef() const
bool readsRegister(Register Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr reads the specified register.
bool isBarrier(QueryType Type=AnyInBundle) const
Returns true if the specified instruction stops control flow from executing the instruction immediate...
bool isCall(QueryType Type=AnyInBundle) const
bool isInlineAsm() const
bool isBranch(QueryType Type=AnyInBundle) const
Returns true if this is a conditional, unconditional, or indirect branch.
bool modifiesRegister(Register Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr modifies (fully define or partially define) the specified register.
LLVM_ABI void unbundleFromPred()
Break bundle above this instruction.
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.
mop_range operands()
LLVM_ABI void setDesc(const MCInstrDesc &TID)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one.
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.
bool isBundledWithSucc() const
Return true if this instruction is part of a bundle, and it is not the last instruction in the bundle...
const MachineOperand & getOperand(unsigned i) const
MachineOperand class - Representation of each machine instruction operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Register getReg() const
getReg - Returns the register number.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
Kind
These are the different kinds of scheduling dependencies.
Definition ScheduleDAG.h:55
@ Output
A register output-dependence (aka WAW).
Definition ScheduleDAG.h:58
@ Order
Any other ordering dependency.
Definition ScheduleDAG.h:59
@ Anti
A register anti-dependence (aka WAR).
Definition ScheduleDAG.h:57
@ Data
Regular data dependence (aka true-dependence).
Definition ScheduleDAG.h:56
Scheduling unit. This is a node in the scheduling DAG.
bool isSucc(const SUnit *N) const
Tests if node N is a successor of this node.
SmallVector< SDep, 4 > Succs
All sunit successors.
SmallVector< SDep, 4 > Preds
All sunit predecessors.
MachineInstr * getInstr() const
Returns the representative MachineInstr for this SUnit.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
VLIWPacketizerList(MachineFunction &MF, MachineLoopInfo &MLI, AAResults *AA)
void addMutation(std::unique_ptr< ScheduleDAGMutation > Mutation)
bool alias(const MachineInstr &MI1, const MachineInstr &MI2, bool UseTBAA=true) const
std::vector< MachineInstr * > CurrentPacketMIs
std::map< MachineInstr *, SUnit * > MIToSUnit
DFAPacketizer * ResourceTracker
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:209
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition DenseSet.h:187
#define INT64_MAX
Definition DataTypes.h:71
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:578
LLVM_ABI void finalizeBundle(MachineBasicBlock &MBB, MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
finalizeBundle - Finalize a machine instruction bundle which includes a sequence of instructions star...
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1765
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
std::string utohexstr(uint64_t X, bool LowerCase=false, unsigned Width=0)
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition STLExtras.h:633
FunctionPass * createHexagonPacketizer(bool Minimal)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
DWARFExpression::Operation Op
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58