LLVM 24.0.0git
HexagonMachineScheduler.cpp
Go to the documentation of this file.
1//===- HexagonMachineScheduler.cpp - MI Scheduler for Hexagon -------------===//
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// MachineScheduler schedules machine instructions after phi elimination. It
10// preserves LiveIntervals so it can be invoked before register allocation.
11//
12//===----------------------------------------------------------------------===//
13
15#include "HexagonInstrInfo.h"
16#include "HexagonSubtarget.h"
20
21using namespace llvm;
22
23#define DEBUG_TYPE "machine-scheduler"
24
25/// Return true if there is a dependence between SUd and SUu.
27 const SUnit *SUu) {
28 const auto *QII = static_cast<const HexagonInstrInfo *>(TII);
29
30 // Enable .cur formation.
31 if (QII->mayBeCurLoad(*SUd->getInstr()))
32 return false;
33
34 if (QII->canExecuteInBundle(*SUd->getInstr(), *SUu->getInstr()))
35 return false;
36
37 return VLIWResourceModel::hasDependence(SUd, SUu);
38}
39
44
46 SchedCandidate &Candidate,
47 RegPressureDelta &Delta,
48 bool verbose) {
49 int ResCount =
50 ConvergingVLIWScheduler::SchedulingCost(Q, SU, Candidate, Delta, verbose);
51
52 if (!SU || SU->isScheduled || !SU->isInstr())
53 return ResCount;
54
55 auto &QST = DAG->MF.getSubtarget<HexagonSubtarget>();
56 auto &QII = *QST.getInstrInfo();
57 MachineInstr *MI = SU->getInstr();
58 if (QII.mayBeCurLoad(*MI)) {
59 if (Q.getID() == TopQID &&
60 Top.ResourceModel->isResourceAvailable(SU, true)) {
61 ResCount += PriorityTwo;
62 LLVM_DEBUG(if (verbose) dbgs() << "C|");
63 } else if (Q.getID() == BotQID &&
64 Bot.ResourceModel->isResourceAvailable(SU, false)) {
65 ResCount += PriorityTwo;
66 LLVM_DEBUG(if (verbose) dbgs() << "C|");
67 }
68 return ResCount;
69 }
70
71 // Keep HLX load uses and store definitions close to their pseudos so the
72 // packetizer can place each pair in the same packet.
73 if (Q.getID() == TopQID) {
74 if (QII.isNewStorePseudo(*MI)) {
75 ResCount += PriorityOne;
76 } else if (!QII.isTmpLoadPseudo(*MI)) {
77 for (const SDep &PredDep : SU->Preds) {
78 SUnit *Pred = PredDep.getSUnit();
79 if (PredDep.getKind() == SDep::Data && Pred->isInstr() &&
80 QII.isTmpLoadPseudo(*Pred->getInstr()) && Pred->NumSuccs < 3)
81 ResCount += PriorityOne;
82 }
83 }
84 } else if (Q.getID() == BotQID) {
85 if (QII.isTmpLoadPseudo(*MI) && SU->NumSuccs < 3) {
86 ResCount += PriorityOne;
87 } else if (!QII.isNewStorePseudo(*MI)) {
88 for (const SDep &SuccDep : SU->Succs) {
89 SUnit *Succ = SuccDep.getSUnit();
90 if (SuccDep.getKind() == SDep::Data && Succ->isInstr() &&
91 QII.isNewStorePseudo(*Succ->getInstr()))
92 ResCount += PriorityOne;
93 }
94 }
95 }
96
97 return ResCount;
98}
IRTranslator LLVM IR MI
#define LLVM_DEBUG(...)
Definition Debug.h:119
static constexpr unsigned PriorityOne
static constexpr unsigned PriorityTwo
const TargetSchedModel * SchedModel
virtual int SchedulingCost(ReadyQueue &Q, SUnit *SU, SchedCandidate &Candidate, RegPressureDelta &Delta, bool verbose)
Single point to compute overall scheduling cost.
VLIWResourceModel * createVLIWResourceModel(const TargetSubtargetInfo &STI, const TargetSchedModel *SchedModel) const override
int SchedulingCost(ReadyQueue &Q, SUnit *SU, SchedCandidate &Candidate, RegPressureDelta &Delta, bool verbose) override
Single point to compute overall scheduling cost.
const HexagonInstrInfo * getInstrInfo() const override
bool hasDependence(const SUnit *SUd, const SUnit *SUu) override
Return true if there is a dependence between SUd and SUu.
Representation of each machine instruction.
Helpers for implementing custom MachineSchedStrategy classes.
unsigned getID() const
Scheduling dependency.
Definition ScheduleDAG.h:54
SUnit * getSUnit() const
Kind getKind() const
Returns an enum value representing the kind of the dependence.
@ Data
Regular data dependence (aka true-dependence).
Definition ScheduleDAG.h:58
Scheduling unit. This is a node in the scheduling DAG.
unsigned NumSuccs
bool isInstr() const
Returns true if this SUnit refers to a machine instruction as opposed to an SDNode.
bool isScheduled
True once scheduled.
SmallVector< SDep, 4 > Succs
All sunit successors.
SmallVector< SDep, 4 > Preds
All sunit predecessors.
MachineInstr * getInstr() const
Returns the representative MachineInstr for this SUnit.
Provide an instruction scheduling machine model to CodeGen passes.
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual bool hasDependence(const SUnit *SUd, const SUnit *SUu)
Return true if there is a dependence between SUd and SUu.
const TargetInstrInfo * TII
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
Store the state used by ConvergingVLIWScheduler heuristics, required for the lifetime of one invocati...
Store the effects of a change in pressure on things that MI scheduler cares about.