@@ -535,6 +535,11 @@ void ScheduleDAGMI::releaseSucc(SUnit *SU, SDep *SuccEdge) {
535
535
llvm_unreachable (nullptr );
536
536
}
537
537
#endif
538
+ // SU->TopReadyCycle was set to CurrCycle when it was scheduled. However,
539
+ // CurrCycle may have advanced since then.
540
+ if (SuccSU->TopReadyCycle < SU->TopReadyCycle + SuccEdge->getLatency ())
541
+ SuccSU->TopReadyCycle = SU->TopReadyCycle + SuccEdge->getLatency ();
542
+
538
543
--SuccSU->NumPredsLeft ;
539
544
if (SuccSU->NumPredsLeft == 0 && SuccSU != &ExitSU)
540
545
SchedImpl->releaseTopNode (SuccSU);
@@ -569,6 +574,11 @@ void ScheduleDAGMI::releasePred(SUnit *SU, SDep *PredEdge) {
569
574
llvm_unreachable (nullptr );
570
575
}
571
576
#endif
577
+ // SU->BotReadyCycle was set to CurrCycle when it was scheduled. However,
578
+ // CurrCycle may have advanced since then.
579
+ if (PredSU->BotReadyCycle < SU->BotReadyCycle + PredEdge->getLatency ())
580
+ PredSU->BotReadyCycle = SU->BotReadyCycle + PredEdge->getLatency ();
581
+
572
582
--PredSU->NumSuccsLeft ;
573
583
if (PredSU->NumSuccsLeft == 0 && PredSU != &EntrySU)
574
584
SchedImpl->releaseBottomNode (PredSU);
@@ -680,10 +690,13 @@ void ScheduleDAGMI::schedule() {
680
690
CurrentBottom = MI;
681
691
}
682
692
}
683
- updateQueues (SU, IsTopNode);
684
-
685
- // Notify the scheduling strategy after updating the DAG.
693
+ // Notify the scheduling strategy before updating the DAG.
694
+ // This sets the scheduled nodes ReadyCycle to CurrCycle. When updateQueues
695
+ // runs, it can then use the accurate ReadyCycle time to determine whether
696
+ // newly released nodes can move to the readyQ.
686
697
SchedImpl->schedNode (SU, IsTopNode);
698
+
699
+ updateQueues (SU, IsTopNode);
687
700
}
688
701
assert (CurrentTop == CurrentBottom && " Nonempty unscheduled zone." );
689
702
@@ -1574,7 +1587,7 @@ void SchedBoundary::reset() {
1574
1587
// Track the maximum number of stall cycles that could arise either from the
1575
1588
// latency of a DAG edge or the number of cycles that a processor resource is
1576
1589
// reserved (SchedBoundary::ReservedCycles).
1577
- MaxObservedLatency = 0 ;
1590
+ MaxObservedStall = 0 ;
1578
1591
#endif
1579
1592
// Reserve a zero-count for invalid CritResIdx.
1580
1593
ExecutedResCounts.resize (1 );
@@ -1731,6 +1744,12 @@ getOtherResourceCount(unsigned &OtherCritIdx) {
1731
1744
}
1732
1745
1733
1746
void SchedBoundary::releaseNode (SUnit *SU, unsigned ReadyCycle) {
1747
+ assert (SU->getInstr () && " Scheduled SUnit must have instr" );
1748
+
1749
+ #ifndef NDEBUG
1750
+ MaxObservedStall = std::max (ReadyCycle - CurrCycle, MaxObservedStall);
1751
+ #endif
1752
+
1734
1753
if (ReadyCycle < MinReadyCycle)
1735
1754
MinReadyCycle = ReadyCycle;
1736
1755
@@ -1750,39 +1769,13 @@ void SchedBoundary::releaseTopNode(SUnit *SU) {
1750
1769
if (SU->isScheduled )
1751
1770
return ;
1752
1771
1753
- for (SUnit::pred_iterator I = SU->Preds .begin (), E = SU->Preds .end ();
1754
- I != E; ++I) {
1755
- if (I->isWeak ())
1756
- continue ;
1757
- unsigned PredReadyCycle = I->getSUnit ()->TopReadyCycle ;
1758
- unsigned Latency = I->getLatency ();
1759
- #ifndef NDEBUG
1760
- MaxObservedLatency = std::max (Latency, MaxObservedLatency);
1761
- #endif
1762
- if (SU->TopReadyCycle < PredReadyCycle + Latency)
1763
- SU->TopReadyCycle = PredReadyCycle + Latency;
1764
- }
1765
1772
releaseNode (SU, SU->TopReadyCycle );
1766
1773
}
1767
1774
1768
1775
void SchedBoundary::releaseBottomNode (SUnit *SU) {
1769
1776
if (SU->isScheduled )
1770
1777
return ;
1771
1778
1772
- assert (SU->getInstr () && " Scheduled SUnit must have instr" );
1773
-
1774
- for (SUnit::succ_iterator I = SU->Succs .begin (), E = SU->Succs .end ();
1775
- I != E; ++I) {
1776
- if (I->isWeak ())
1777
- continue ;
1778
- unsigned SuccReadyCycle = I->getSUnit ()->BotReadyCycle ;
1779
- unsigned Latency = I->getLatency ();
1780
- #ifndef NDEBUG
1781
- MaxObservedLatency = std::max (Latency, MaxObservedLatency);
1782
- #endif
1783
- if (SU->BotReadyCycle < SuccReadyCycle + Latency)
1784
- SU->BotReadyCycle = SuccReadyCycle + Latency;
1785
- }
1786
1779
releaseNode (SU, SU->BotReadyCycle );
1787
1780
}
1788
1781
@@ -1951,7 +1944,7 @@ void SchedBoundary::bumpNode(SUnit *SU) {
1951
1944
if (SchedModel->getProcResource (PIdx)->BufferSize == 0 ) {
1952
1945
ReservedCycles[PIdx] = isTop () ? NextCycle + PI->Cycles : NextCycle;
1953
1946
#ifndef NDEBUG
1954
- MaxObservedLatency = std::max (PI->Cycles , MaxObservedLatency );
1947
+ MaxObservedStall = std::max (PI->Cycles , MaxObservedStall );
1955
1948
#endif
1956
1949
}
1957
1950
}
@@ -2055,7 +2048,7 @@ SUnit *SchedBoundary::pickOnlyChoice() {
2055
2048
}
2056
2049
}
2057
2050
for (unsigned i = 0 ; Available.empty (); ++i) {
2058
- assert (i <= (HazardRec->getMaxLookAhead () + MaxObservedLatency ) &&
2051
+ assert (i <= (HazardRec->getMaxLookAhead () + MaxObservedStall ) &&
2059
2052
" permanent hazard" ); (void )i;
2060
2053
bumpCycle (CurrCycle + 1 );
2061
2054
releasePending ();
0 commit comments