Skip to content

Commit f9f78cf

Browse files
DoktorCfhahn
authored andcommitted
[MachineScheduler] improve reuse of 'releaseNode'method
The 'SchedBoundary::releaseNode' is merely invoked for releasing the Top/Bottom root nodes. However, 'SchedBoundary::releasePending' uses its same logic to check if the Pending queue has any releasable SUnit. It is possible to slightly modify the body of the two, allowing re-use of the former ('releaseNode') in the latter. Patch by Lorenzo Casalino <[email protected]> Reviewers: MatzeB, fhahn, atrick Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D65506
1 parent 1155243 commit f9f78cf

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

llvm/include/llvm/CodeGen/MachineScheduler.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,8 @@ class SchedBoundary {
757757

758758
unsigned getOtherResourceCount(unsigned &OtherCritIdx);
759759

760-
void releaseNode(SUnit *SU, unsigned ReadyCycle);
760+
template <bool InPQueue>
761+
void releaseNode(SUnit *SU, unsigned ReadyCycle, unsigned Idx = 0);
761762

762763
void bumpCycle(unsigned NextCycle);
763764

@@ -955,15 +956,15 @@ class GenericScheduler : public GenericSchedulerBase {
955956
if (SU->isScheduled)
956957
return;
957958

958-
Top.releaseNode(SU, SU->TopReadyCycle);
959+
Top.releaseNode<false>(SU, SU->TopReadyCycle);
959960
TopCand.SU = nullptr;
960961
}
961962

962963
void releaseBottomNode(SUnit *SU) override {
963964
if (SU->isScheduled)
964965
return;
965966

966-
Bot.releaseNode(SU, SU->BotReadyCycle);
967+
Bot.releaseNode<false>(SU, SU->BotReadyCycle);
967968
BotCand.SU = nullptr;
968969
}
969970

@@ -1043,7 +1044,7 @@ class PostGenericScheduler : public GenericSchedulerBase {
10431044
void releaseTopNode(SUnit *SU) override {
10441045
if (SU->isScheduled)
10451046
return;
1046-
Top.releaseNode(SU, SU->TopReadyCycle);
1047+
Top.releaseNode<false>(SU, SU->TopReadyCycle);
10471048
}
10481049

10491050
// Only called for roots.

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,7 +2088,8 @@ getOtherResourceCount(unsigned &OtherCritIdx) {
20882088
return OtherCritCount;
20892089
}
20902090

2091-
void SchedBoundary::releaseNode(SUnit *SU, unsigned ReadyCycle) {
2091+
template <bool InPQueue>
2092+
void SchedBoundary::releaseNode(SUnit *SU, unsigned ReadyCycle, unsigned Idx) {
20922093
assert(SU->getInstr() && "Scheduled SUnit must have instr");
20932094

20942095
#ifndef NDEBUG
@@ -2105,11 +2106,19 @@ void SchedBoundary::releaseNode(SUnit *SU, unsigned ReadyCycle) {
21052106
// Check for interlocks first. For the purpose of other heuristics, an
21062107
// instruction that cannot issue appears as if it's not in the ReadyQueue.
21072108
bool IsBuffered = SchedModel->getMicroOpBufferSize() != 0;
2108-
if ((!IsBuffered && ReadyCycle > CurrCycle) || checkHazard(SU) ||
2109-
Available.size() >= ReadyListLimit)
2110-
Pending.push(SU);
2111-
else
2109+
bool HazardDetected = (!IsBuffered && ReadyCycle > CurrCycle) ||
2110+
checkHazard(SU) || (Available.size() >= ReadyListLimit);
2111+
2112+
if (!HazardDetected) {
21122113
Available.push(SU);
2114+
2115+
if (InPQueue)
2116+
Pending.remove(Pending.begin() + Idx);
2117+
return;
2118+
}
2119+
2120+
if (!InPQueue)
2121+
Pending.push(SU);
21132122
}
21142123

21152124
/// Move the boundary of scheduled code by one cycle.
@@ -2349,26 +2358,21 @@ void SchedBoundary::releasePending() {
23492358

23502359
// Check to see if any of the pending instructions are ready to issue. If
23512360
// so, add them to the available queue.
2352-
bool IsBuffered = SchedModel->getMicroOpBufferSize() != 0;
2353-
for (unsigned i = 0, e = Pending.size(); i != e; ++i) {
2354-
SUnit *SU = *(Pending.begin()+i);
2361+
for (unsigned I = 0, E = Pending.size(); I < E; ++I) {
2362+
SUnit *SU = *(Pending.begin() + I);
23552363
unsigned ReadyCycle = isTop() ? SU->TopReadyCycle : SU->BotReadyCycle;
23562364

23572365
if (ReadyCycle < MinReadyCycle)
23582366
MinReadyCycle = ReadyCycle;
23592367

2360-
if (!IsBuffered && ReadyCycle > CurrCycle)
2361-
continue;
2362-
2363-
if (checkHazard(SU))
2364-
continue;
2365-
23662368
if (Available.size() >= ReadyListLimit)
23672369
break;
23682370

2369-
Available.push(SU);
2370-
Pending.remove(Pending.begin()+i);
2371-
--i; --e;
2371+
releaseNode<true>(SU, ReadyCycle, I);
2372+
if (E != Pending.size()) {
2373+
--I;
2374+
--E;
2375+
}
23722376
}
23732377
CheckPending = false;
23742378
}

0 commit comments

Comments
 (0)