@@ -219,6 +219,14 @@ class ScheduleDAGRRList : public ScheduleDAGSDNodes {
219219 return Topo.WillCreateCycle (SU, TargetSU);
220220 }
221221
222+ // / AddPredQueued - Queues and update to add a predecessor edge to SUnit SU.
223+ // / This returns true if this is a new predecessor.
224+ // / Does *NOT* update the topological ordering! It just queues an update.
225+ void AddPredQueued (SUnit *SU, const SDep &D) {
226+ Topo.AddPredQueued (SU, D.getSUnit ());
227+ SU->addPred (D);
228+ }
229+
222230 // / AddPred - adds a predecessor edge to SUnit SU.
223231 // / This returns true if this is a new predecessor.
224232 // / Updates the topological ordering if required.
@@ -266,24 +274,22 @@ class ScheduleDAGRRList : public ScheduleDAGSDNodes {
266274 void ListScheduleBottomUp ();
267275
268276 // / CreateNewSUnit - Creates a new SUnit and returns a pointer to it.
269- // / Updates the topological ordering if required.
270277 SUnit *CreateNewSUnit (SDNode *N) {
271278 unsigned NumSUnits = SUnits.size ();
272279 SUnit *NewNode = newSUnit (N);
273280 // Update the topological ordering.
274281 if (NewNode->NodeNum >= NumSUnits)
275- Topo.InitDAGTopologicalSorting ();
282+ Topo.MarkDirty ();
276283 return NewNode;
277284 }
278285
279286 // / CreateClone - Creates a new SUnit from an existing one.
280- // / Updates the topological ordering if required.
281287 SUnit *CreateClone (SUnit *N) {
282288 unsigned NumSUnits = SUnits.size ();
283289 SUnit *NewNode = Clone (N);
284290 // Update the topological ordering.
285291 if (NewNode->NodeNum >= NumSUnits)
286- Topo.InitDAGTopologicalSorting ();
292+ Topo.MarkDirty ();
287293 return NewNode;
288294 }
289295
@@ -365,7 +371,7 @@ void ScheduleDAGRRList::Schedule() {
365371 BuildSchedGraph (nullptr );
366372
367373 LLVM_DEBUG (dump ());
368- Topo.InitDAGTopologicalSorting ();
374+ Topo.MarkDirty ();
369375
370376 AvailableQueue->initNodes (SUnits);
371377
@@ -1017,8 +1023,9 @@ SUnit *ScheduleDAGRRList::TryUnfoldSU(SUnit *SU) {
10171023 NewSU = &SUnits[N->getNodeId ()];
10181024 // If NewSU has already been scheduled, we need to clone it, but this
10191025 // negates the benefit to unfolding so just return SU.
1020- if (NewSU->isScheduled )
1026+ if (NewSU->isScheduled ) {
10211027 return SU;
1028+ }
10221029 isNewN = false ;
10231030 } else {
10241031 NewSU = CreateNewSUnit (N);
@@ -1071,23 +1078,23 @@ SUnit *ScheduleDAGRRList::TryUnfoldSU(SUnit *SU) {
10711078 for (const SDep &Pred : ChainPreds) {
10721079 RemovePred (SU, Pred);
10731080 if (isNewLoad)
1074- AddPred (LoadSU, Pred);
1081+ AddPredQueued (LoadSU, Pred);
10751082 }
10761083 for (const SDep &Pred : LoadPreds) {
10771084 RemovePred (SU, Pred);
10781085 if (isNewLoad)
1079- AddPred (LoadSU, Pred);
1086+ AddPredQueued (LoadSU, Pred);
10801087 }
10811088 for (const SDep &Pred : NodePreds) {
10821089 RemovePred (SU, Pred);
1083- AddPred (NewSU, Pred);
1090+ AddPredQueued (NewSU, Pred);
10841091 }
10851092 for (SDep D : NodeSuccs) {
10861093 SUnit *SuccDep = D.getSUnit ();
10871094 D.setSUnit (SU);
10881095 RemovePred (SuccDep, D);
10891096 D.setSUnit (NewSU);
1090- AddPred (SuccDep, D);
1097+ AddPredQueued (SuccDep, D);
10911098 // Balance register pressure.
10921099 if (AvailableQueue->tracksRegPressure () && SuccDep->isScheduled &&
10931100 !D.isCtrl () && NewSU->NumRegDefsLeft > 0 )
@@ -1099,15 +1106,15 @@ SUnit *ScheduleDAGRRList::TryUnfoldSU(SUnit *SU) {
10991106 RemovePred (SuccDep, D);
11001107 if (isNewLoad) {
11011108 D.setSUnit (LoadSU);
1102- AddPred (SuccDep, D);
1109+ AddPredQueued (SuccDep, D);
11031110 }
11041111 }
11051112
11061113 // Add a data dependency to reflect that NewSU reads the value defined
11071114 // by LoadSU.
11081115 SDep D (LoadSU, SDep::Data, 0 );
11091116 D.setLatency (LoadSU->Latency );
1110- AddPred (NewSU, D);
1117+ AddPredQueued (NewSU, D);
11111118
11121119 if (isNewLoad)
11131120 AvailableQueue->addNode (LoadSU);
@@ -1179,7 +1186,7 @@ SUnit *ScheduleDAGRRList::CopyAndMoveSuccessors(SUnit *SU) {
11791186 // New SUnit has the exact same predecessors.
11801187 for (SDep &Pred : SU->Preds )
11811188 if (!Pred.isArtificial ())
1182- AddPred (NewSU, Pred);
1189+ AddPredQueued (NewSU, Pred);
11831190
11841191 // Only copy scheduled successors. Cut them from old node's successor
11851192 // list and move them over.
@@ -1191,7 +1198,7 @@ SUnit *ScheduleDAGRRList::CopyAndMoveSuccessors(SUnit *SU) {
11911198 if (SuccSU->isScheduled ) {
11921199 SDep D = Succ;
11931200 D.setSUnit (NewSU);
1194- AddPred (SuccSU, D);
1201+ AddPredQueued (SuccSU, D);
11951202 D.setSUnit (SU);
11961203 DelDeps.push_back (std::make_pair (SuccSU, D));
11971204 }
@@ -1230,25 +1237,25 @@ void ScheduleDAGRRList::InsertCopiesAndMoveSuccs(SUnit *SU, unsigned Reg,
12301237 if (SuccSU->isScheduled ) {
12311238 SDep D = Succ;
12321239 D.setSUnit (CopyToSU);
1233- AddPred (SuccSU, D);
1240+ AddPredQueued (SuccSU, D);
12341241 DelDeps.push_back (std::make_pair (SuccSU, Succ));
12351242 }
12361243 else {
12371244 // Avoid scheduling the def-side copy before other successors. Otherwise
12381245 // we could introduce another physreg interference on the copy and
12391246 // continue inserting copies indefinitely.
1240- AddPred (SuccSU, SDep (CopyFromSU, SDep::Artificial));
1247+ AddPredQueued (SuccSU, SDep (CopyFromSU, SDep::Artificial));
12411248 }
12421249 }
12431250 for (auto &DelDep : DelDeps)
12441251 RemovePred (DelDep.first , DelDep.second );
12451252
12461253 SDep FromDep (SU, SDep::Data, Reg);
12471254 FromDep.setLatency (SU->Latency );
1248- AddPred (CopyFromSU, FromDep);
1255+ AddPredQueued (CopyFromSU, FromDep);
12491256 SDep ToDep (CopyFromSU, SDep::Data, 0 );
12501257 ToDep.setLatency (CopyFromSU->Latency );
1251- AddPred (CopyToSU, ToDep);
1258+ AddPredQueued (CopyToSU, ToDep);
12521259
12531260 AvailableQueue->updateNode (SU);
12541261 AvailableQueue->addNode (CopyFromSU);
@@ -1478,6 +1485,11 @@ SUnit *ScheduleDAGRRList::PickNodeToScheduleBottomUp() {
14781485 if (CurSU)
14791486 return CurSU;
14801487
1488+ // We query the topological order in the loop body, so make sure outstanding
1489+ // updates are applied before entering it (we only enter the loop if there
1490+ // are some interferences). If we make changes to the ordering, we exit
1491+ // the loop.
1492+
14811493 // All candidates are delayed due to live physical reg dependencies.
14821494 // Try backtracking, code duplication, or inserting cross class copies
14831495 // to resolve it.
@@ -1507,7 +1519,7 @@ SUnit *ScheduleDAGRRList::PickNodeToScheduleBottomUp() {
15071519 }
15081520 LLVM_DEBUG (dbgs () << " ARTIFICIAL edge from SU(" << BtSU->NodeNum
15091521 << " ) to SU(" << TrySU->NodeNum << " )\n " );
1510- AddPred (TrySU, SDep (BtSU, SDep::Artificial));
1522+ AddPredQueued (TrySU, SDep (BtSU, SDep::Artificial));
15111523
15121524 // If one or more successors has been unscheduled, then the current
15131525 // node is no longer available.
@@ -1561,14 +1573,14 @@ SUnit *ScheduleDAGRRList::PickNodeToScheduleBottomUp() {
15611573 InsertCopiesAndMoveSuccs (LRDef, Reg, DestRC, RC, Copies);
15621574 LLVM_DEBUG (dbgs () << " Adding an edge from SU #" << TrySU->NodeNum
15631575 << " to SU #" << Copies.front ()->NodeNum << " \n " );
1564- AddPred (TrySU, SDep (Copies.front (), SDep::Artificial));
1576+ AddPredQueued (TrySU, SDep (Copies.front (), SDep::Artificial));
15651577 NewDef = Copies.back ();
15661578 }
15671579
15681580 LLVM_DEBUG (dbgs () << " Adding an edge from SU #" << NewDef->NodeNum
15691581 << " to SU #" << TrySU->NodeNum << " \n " );
15701582 LiveRegDefs[Reg] = NewDef;
1571- AddPred (NewDef, SDep (TrySU, SDep::Artificial));
1583+ AddPredQueued (NewDef, SDep (TrySU, SDep::Artificial));
15721584 TrySU->isAvailable = false ;
15731585 CurSU = NewDef;
15741586 }
@@ -3017,9 +3029,9 @@ void RegReductionPQBase::PrescheduleNodesWithMultipleUses() {
30173029 if (SuccSU != &SU) {
30183030 Edge.setSUnit (PredSU);
30193031 scheduleDAG->RemovePred (SuccSU, Edge);
3020- scheduleDAG->AddPred (&SU, Edge);
3032+ scheduleDAG->AddPredQueued (&SU, Edge);
30213033 Edge.setSUnit (&SU);
3022- scheduleDAG->AddPred (SuccSU, Edge);
3034+ scheduleDAG->AddPredQueued (SuccSU, Edge);
30233035 --i;
30243036 }
30253037 }
@@ -3101,7 +3113,7 @@ void RegReductionPQBase::AddPseudoTwoAddrDeps() {
31013113 LLVM_DEBUG (dbgs ()
31023114 << " Adding a pseudo-two-addr edge from SU #"
31033115 << SU.NodeNum << " to SU #" << SuccSU->NodeNum << " \n " );
3104- scheduleDAG->AddPred (&SU, SDep (SuccSU, SDep::Artificial));
3116+ scheduleDAG->AddPredQueued (&SU, SDep (SuccSU, SDep::Artificial));
31053117 }
31063118 }
31073119 }
0 commit comments