@@ -219,6 +219,14 @@ class ScheduleDAGRRList : public ScheduleDAGSDNodes {
219
219
return Topo.WillCreateCycle (SU, TargetSU);
220
220
}
221
221
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
+
222
230
// / AddPred - adds a predecessor edge to SUnit SU.
223
231
// / This returns true if this is a new predecessor.
224
232
// / Updates the topological ordering if required.
@@ -266,24 +274,22 @@ class ScheduleDAGRRList : public ScheduleDAGSDNodes {
266
274
void ListScheduleBottomUp ();
267
275
268
276
// / CreateNewSUnit - Creates a new SUnit and returns a pointer to it.
269
- // / Updates the topological ordering if required.
270
277
SUnit *CreateNewSUnit (SDNode *N) {
271
278
unsigned NumSUnits = SUnits.size ();
272
279
SUnit *NewNode = newSUnit (N);
273
280
// Update the topological ordering.
274
281
if (NewNode->NodeNum >= NumSUnits)
275
- Topo.InitDAGTopologicalSorting ();
282
+ Topo.MarkDirty ();
276
283
return NewNode;
277
284
}
278
285
279
286
// / CreateClone - Creates a new SUnit from an existing one.
280
- // / Updates the topological ordering if required.
281
287
SUnit *CreateClone (SUnit *N) {
282
288
unsigned NumSUnits = SUnits.size ();
283
289
SUnit *NewNode = Clone (N);
284
290
// Update the topological ordering.
285
291
if (NewNode->NodeNum >= NumSUnits)
286
- Topo.InitDAGTopologicalSorting ();
292
+ Topo.MarkDirty ();
287
293
return NewNode;
288
294
}
289
295
@@ -365,7 +371,7 @@ void ScheduleDAGRRList::Schedule() {
365
371
BuildSchedGraph (nullptr );
366
372
367
373
LLVM_DEBUG (dump ());
368
- Topo.InitDAGTopologicalSorting ();
374
+ Topo.MarkDirty ();
369
375
370
376
AvailableQueue->initNodes (SUnits);
371
377
@@ -1017,8 +1023,9 @@ SUnit *ScheduleDAGRRList::TryUnfoldSU(SUnit *SU) {
1017
1023
NewSU = &SUnits[N->getNodeId ()];
1018
1024
// If NewSU has already been scheduled, we need to clone it, but this
1019
1025
// negates the benefit to unfolding so just return SU.
1020
- if (NewSU->isScheduled )
1026
+ if (NewSU->isScheduled ) {
1021
1027
return SU;
1028
+ }
1022
1029
isNewN = false ;
1023
1030
} else {
1024
1031
NewSU = CreateNewSUnit (N);
@@ -1071,23 +1078,23 @@ SUnit *ScheduleDAGRRList::TryUnfoldSU(SUnit *SU) {
1071
1078
for (const SDep &Pred : ChainPreds) {
1072
1079
RemovePred (SU, Pred);
1073
1080
if (isNewLoad)
1074
- AddPred (LoadSU, Pred);
1081
+ AddPredQueued (LoadSU, Pred);
1075
1082
}
1076
1083
for (const SDep &Pred : LoadPreds) {
1077
1084
RemovePred (SU, Pred);
1078
1085
if (isNewLoad)
1079
- AddPred (LoadSU, Pred);
1086
+ AddPredQueued (LoadSU, Pred);
1080
1087
}
1081
1088
for (const SDep &Pred : NodePreds) {
1082
1089
RemovePred (SU, Pred);
1083
- AddPred (NewSU, Pred);
1090
+ AddPredQueued (NewSU, Pred);
1084
1091
}
1085
1092
for (SDep D : NodeSuccs) {
1086
1093
SUnit *SuccDep = D.getSUnit ();
1087
1094
D.setSUnit (SU);
1088
1095
RemovePred (SuccDep, D);
1089
1096
D.setSUnit (NewSU);
1090
- AddPred (SuccDep, D);
1097
+ AddPredQueued (SuccDep, D);
1091
1098
// Balance register pressure.
1092
1099
if (AvailableQueue->tracksRegPressure () && SuccDep->isScheduled &&
1093
1100
!D.isCtrl () && NewSU->NumRegDefsLeft > 0 )
@@ -1099,15 +1106,15 @@ SUnit *ScheduleDAGRRList::TryUnfoldSU(SUnit *SU) {
1099
1106
RemovePred (SuccDep, D);
1100
1107
if (isNewLoad) {
1101
1108
D.setSUnit (LoadSU);
1102
- AddPred (SuccDep, D);
1109
+ AddPredQueued (SuccDep, D);
1103
1110
}
1104
1111
}
1105
1112
1106
1113
// Add a data dependency to reflect that NewSU reads the value defined
1107
1114
// by LoadSU.
1108
1115
SDep D (LoadSU, SDep::Data, 0 );
1109
1116
D.setLatency (LoadSU->Latency );
1110
- AddPred (NewSU, D);
1117
+ AddPredQueued (NewSU, D);
1111
1118
1112
1119
if (isNewLoad)
1113
1120
AvailableQueue->addNode (LoadSU);
@@ -1179,7 +1186,7 @@ SUnit *ScheduleDAGRRList::CopyAndMoveSuccessors(SUnit *SU) {
1179
1186
// New SUnit has the exact same predecessors.
1180
1187
for (SDep &Pred : SU->Preds )
1181
1188
if (!Pred.isArtificial ())
1182
- AddPred (NewSU, Pred);
1189
+ AddPredQueued (NewSU, Pred);
1183
1190
1184
1191
// Only copy scheduled successors. Cut them from old node's successor
1185
1192
// list and move them over.
@@ -1191,7 +1198,7 @@ SUnit *ScheduleDAGRRList::CopyAndMoveSuccessors(SUnit *SU) {
1191
1198
if (SuccSU->isScheduled ) {
1192
1199
SDep D = Succ;
1193
1200
D.setSUnit (NewSU);
1194
- AddPred (SuccSU, D);
1201
+ AddPredQueued (SuccSU, D);
1195
1202
D.setSUnit (SU);
1196
1203
DelDeps.push_back (std::make_pair (SuccSU, D));
1197
1204
}
@@ -1230,25 +1237,25 @@ void ScheduleDAGRRList::InsertCopiesAndMoveSuccs(SUnit *SU, unsigned Reg,
1230
1237
if (SuccSU->isScheduled ) {
1231
1238
SDep D = Succ;
1232
1239
D.setSUnit (CopyToSU);
1233
- AddPred (SuccSU, D);
1240
+ AddPredQueued (SuccSU, D);
1234
1241
DelDeps.push_back (std::make_pair (SuccSU, Succ));
1235
1242
}
1236
1243
else {
1237
1244
// Avoid scheduling the def-side copy before other successors. Otherwise
1238
1245
// we could introduce another physreg interference on the copy and
1239
1246
// continue inserting copies indefinitely.
1240
- AddPred (SuccSU, SDep (CopyFromSU, SDep::Artificial));
1247
+ AddPredQueued (SuccSU, SDep (CopyFromSU, SDep::Artificial));
1241
1248
}
1242
1249
}
1243
1250
for (auto &DelDep : DelDeps)
1244
1251
RemovePred (DelDep.first , DelDep.second );
1245
1252
1246
1253
SDep FromDep (SU, SDep::Data, Reg);
1247
1254
FromDep.setLatency (SU->Latency );
1248
- AddPred (CopyFromSU, FromDep);
1255
+ AddPredQueued (CopyFromSU, FromDep);
1249
1256
SDep ToDep (CopyFromSU, SDep::Data, 0 );
1250
1257
ToDep.setLatency (CopyFromSU->Latency );
1251
- AddPred (CopyToSU, ToDep);
1258
+ AddPredQueued (CopyToSU, ToDep);
1252
1259
1253
1260
AvailableQueue->updateNode (SU);
1254
1261
AvailableQueue->addNode (CopyFromSU);
@@ -1478,6 +1485,11 @@ SUnit *ScheduleDAGRRList::PickNodeToScheduleBottomUp() {
1478
1485
if (CurSU)
1479
1486
return CurSU;
1480
1487
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
+
1481
1493
// All candidates are delayed due to live physical reg dependencies.
1482
1494
// Try backtracking, code duplication, or inserting cross class copies
1483
1495
// to resolve it.
@@ -1507,7 +1519,7 @@ SUnit *ScheduleDAGRRList::PickNodeToScheduleBottomUp() {
1507
1519
}
1508
1520
LLVM_DEBUG (dbgs () << " ARTIFICIAL edge from SU(" << BtSU->NodeNum
1509
1521
<< " ) to SU(" << TrySU->NodeNum << " )\n " );
1510
- AddPred (TrySU, SDep (BtSU, SDep::Artificial));
1522
+ AddPredQueued (TrySU, SDep (BtSU, SDep::Artificial));
1511
1523
1512
1524
// If one or more successors has been unscheduled, then the current
1513
1525
// node is no longer available.
@@ -1561,14 +1573,14 @@ SUnit *ScheduleDAGRRList::PickNodeToScheduleBottomUp() {
1561
1573
InsertCopiesAndMoveSuccs (LRDef, Reg, DestRC, RC, Copies);
1562
1574
LLVM_DEBUG (dbgs () << " Adding an edge from SU #" << TrySU->NodeNum
1563
1575
<< " to SU #" << Copies.front ()->NodeNum << " \n " );
1564
- AddPred (TrySU, SDep (Copies.front (), SDep::Artificial));
1576
+ AddPredQueued (TrySU, SDep (Copies.front (), SDep::Artificial));
1565
1577
NewDef = Copies.back ();
1566
1578
}
1567
1579
1568
1580
LLVM_DEBUG (dbgs () << " Adding an edge from SU #" << NewDef->NodeNum
1569
1581
<< " to SU #" << TrySU->NodeNum << " \n " );
1570
1582
LiveRegDefs[Reg] = NewDef;
1571
- AddPred (NewDef, SDep (TrySU, SDep::Artificial));
1583
+ AddPredQueued (NewDef, SDep (TrySU, SDep::Artificial));
1572
1584
TrySU->isAvailable = false ;
1573
1585
CurSU = NewDef;
1574
1586
}
@@ -3017,9 +3029,9 @@ void RegReductionPQBase::PrescheduleNodesWithMultipleUses() {
3017
3029
if (SuccSU != &SU) {
3018
3030
Edge.setSUnit (PredSU);
3019
3031
scheduleDAG->RemovePred (SuccSU, Edge);
3020
- scheduleDAG->AddPred (&SU, Edge);
3032
+ scheduleDAG->AddPredQueued (&SU, Edge);
3021
3033
Edge.setSUnit (&SU);
3022
- scheduleDAG->AddPred (SuccSU, Edge);
3034
+ scheduleDAG->AddPredQueued (SuccSU, Edge);
3023
3035
--i;
3024
3036
}
3025
3037
}
@@ -3101,7 +3113,7 @@ void RegReductionPQBase::AddPseudoTwoAddrDeps() {
3101
3113
LLVM_DEBUG (dbgs ()
3102
3114
<< " Adding a pseudo-two-addr edge from SU #"
3103
3115
<< SU.NodeNum << " to SU #" << SuccSU->NodeNum << " \n " );
3104
- scheduleDAG->AddPred (&SU, SDep (SuccSU, SDep::Artificial));
3116
+ scheduleDAG->AddPredQueued (&SU, SDep (SuccSU, SDep::Artificial));
3105
3117
}
3106
3118
}
3107
3119
}
0 commit comments