16#include "llvm/Config/llvm-config.h"
21#define DEBUG_TYPE "scheduler"
27 if (
LHS->isScheduleHigh && !
RHS->isScheduleHigh)
29 if (!
LHS->isScheduleHigh &&
RHS->isScheduleHigh)
32 unsigned LHSNum =
LHS->NodeNum;
33 unsigned RHSNum =
RHS->NodeNum;
38 if (LHSLatency < RHSLatency)
return true;
39 if (LHSLatency > RHSLatency)
return false;
45 if (LHSBlocked < RHSBlocked)
return true;
46 if (LHSBlocked > RHSBlocked)
return false;
50 return RHSNum < LHSNum;
56SUnit *LatencyPriorityQueue::getSingleUnscheduledPred(
SUnit *SU) {
57 SUnit *OnlyAvailablePred =
nullptr;
59 SUnit &Pred = *
P.getSUnit();
63 if (OnlyAvailablePred && OnlyAvailablePred != &Pred)
65 OnlyAvailablePred = &Pred;
69 return OnlyAvailablePred;
75 unsigned NumNodesBlocking = 0;
77 if (getSingleUnscheduledPred(Succ.
getSUnit()) == SU)
79 NumNodesSolelyBlocking[SU->
NodeNum] = NumNodesBlocking;
91 AdjustPriorityOfUnscheduledPreds(Succ.
getSUnit());
100void LatencyPriorityQueue::AdjustPriorityOfUnscheduledPreds(
SUnit *SU) {
103 SUnit *OnlyAvailablePred = getSingleUnscheduledPred(SU);
104 if (!OnlyAvailablePred || !OnlyAvailablePred->
isAvailable)
return;
108 remove(OnlyAvailablePred);
112 push(OnlyAvailablePred);
116 if (
empty())
return nullptr;
117 std::vector<SUnit *>::iterator Best = Queue.begin();
118 for (std::vector<SUnit *>::iterator
I = std::next(Queue.begin()),
119 E = Queue.end();
I != E; ++
I)
120 if (Picker(*Best, *
I))
123 if (Best != std::prev(Queue.end()))
130 assert(!Queue.empty() &&
"Queue is empty!");
131 std::vector<SUnit *>::iterator
I =
find(Queue, SU);
132 assert(
I != Queue.end() &&
"Queue doesn't contain the SU being removed!");
133 if (
I != std::prev(Queue.end()))
138#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
140 dbgs() <<
"Latency Priority Queue\n";
141 dbgs() <<
" Number of Queue Entries: " << Queue.size() <<
"\n";
142 for (
const SUnit *SU : Queue) {
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getNumSolelyBlockNodes(unsigned NodeNum) const
void push(SUnit *U) override
LLVM_DUMP_METHOD void dump(ScheduleDAG *DAG) const override
void remove(SUnit *SU) override
void scheduledNode(SUnit *SU) override
As each node is scheduled, this method is invoked.
unsigned getLatency(unsigned NodeNum) const
bool empty() const override
Scheduling unit. This is a node in the scheduling DAG.
unsigned NodeNum
Entry # of node in the node vector.
bool isScheduled
True once scheduled.
bool isAvailable
True once available.
SmallVector< SDep, 4 > Succs
All sunit successors.
SmallVector< SDep, 4 > Preds
All sunit predecessors.
virtual void dumpNode(const SUnit &SU) const =0
This is an optimization pass for GlobalISel generic memory operations.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
LatencyPriorityQueue * PQ
bool operator()(const SUnit *LHS, const SUnit *RHS) const