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