@@ -12,6 +12,7 @@ SPDX-License-Identifier: MIT
1212#include < functional>
1313#include < fstream>
1414#include < iostream>
15+ #include < queue>
1516
1617using namespace vISA ;
1718
@@ -882,7 +883,7 @@ class QueueBase {
882883 // The data-dependency graph.
883884 preDDD& ddd;
884885
885- // Registre pressure related data.
886+ // Register pressure related data.
886887 RegisterPressure& rp;
887888
888889 // Options to customize scheduler.
@@ -920,6 +921,8 @@ class QueueBase {
920921 if (TheCurrTupleParts == 0 )
921922 TheCurrTupleLead = nullptr ;
922923 }
924+ virtual void push (preNode* N) = 0;
925+ virtual preNode* pop () = 0;
923926
924927protected:
925928 // The current (send) tuple lead.
@@ -947,7 +950,7 @@ class SethiUllmanQueue : public QueueBase {
947950 }
948951
949952 // Add a new ready node.
950- void push (preNode* N)
953+ void push (preNode* N) override
951954 {
952955 // Clustering nodes have been added.
953956 if (N->isClustered && !N->isClusterLead )
@@ -962,7 +965,7 @@ class SethiUllmanQueue : public QueueBase {
962965 }
963966
964967 // Schedule the top node.
965- preNode* pop ()
968+ preNode* pop () override
966969 {
967970 return select ();
968971 }
@@ -1323,37 +1326,44 @@ class LatencyQueue : public QueueBase {
13231326 // group will be scheduled for latency.
13241327 std::map<G4_INST *, unsigned > GroupInfo;
13251328
1326- // Instrction latency information.
1329+ // Instruction latency information.
13271330 const LatencyTable <
13281331
1332+ // TODO: Try to apply priority queue to SethiUllmanQueue as well.
1333+ std::priority_queue<preNode*, std::vector<preNode*>, std::function<bool (preNode*, preNode*)>> ReadyList;
1334+
13291335public:
13301336 LatencyQueue (preDDD& ddd, RegisterPressure& rp, SchedConfig config,
13311337 const LatencyTable& LT)
13321338 : QueueBase(ddd, rp, config)
13331339 , LT(LT)
1340+ , ReadyList([this ](preNode* a, preNode* b){ return compare (a, b);})
13341341 {
13351342 init ();
13361343 }
13371344
13381345 // Add a new ready node.
1339- void push (preNode* N)
1346+ void push (preNode* N) override
13401347 {
13411348 if (N->getInst () && N->getInst ()->isPseudoKill ())
13421349 pseudoKills.push_back (N);
13431350 else
1344- Q. push_back (N);
1351+ ReadyList. push (N);
13451352 }
13461353
13471354 // Schedule the top node.
1348- preNode* pop ()
1355+ preNode* pop () override
13491356 {
13501357 // Pop all pseudo-kills if any.
13511358 if (!pseudoKills.empty ()) {
13521359 preNode* N = pseudoKills.back ();
13531360 pseudoKills.pop_back ();
13541361 return N;
13551362 }
1356- return select ();
1363+ assert (!ReadyList.empty ());
1364+ preNode* N = ReadyList.top ();
1365+ ReadyList.pop ();
1366+ return N;
13571367 }
13581368
13591369 bool empty () const
@@ -1365,8 +1375,6 @@ class LatencyQueue : public QueueBase {
13651375 void init ();
13661376 unsigned calculatePriority (preNode *N);
13671377
1368- preNode* select ();
1369-
13701378 // Compare two ready nodes and decide which one should be scheduled first.
13711379 // Return true if N2 has a higher priority than N1, false otherwise.
13721380 bool compare (preNode* N1, preNode* N2);
@@ -1636,22 +1644,6 @@ unsigned LatencyQueue::calculatePriority(preNode* N)
16361644 return std::max (1U , Priority);
16371645}
16381646
1639- preNode* LatencyQueue::select ()
1640- {
1641- assert (!Q.empty ());
1642- auto TopIter = Q.end ();
1643- for (auto I = Q.begin (), E = Q.end (); I != E; ++I) {
1644- preNode* N = *I;
1645- if (TopIter == Q.end () || compare (*TopIter, N))
1646- TopIter = I;
1647- }
1648- assert (TopIter != Q.end ());
1649- preNode* Top = *TopIter;
1650- std::swap (*TopIter, Q.back ());
1651- Q.pop_back ();
1652- return Top;
1653- }
1654-
16551647// Compare two ready nodes and decide which one should be scheduled first.
16561648// Return true if N2 has a higher priority than N1, false otherwise.
16571649bool LatencyQueue::compare (preNode* N1, preNode* N2)
0 commit comments