15
15
#include " llvm/ADT/ArrayRef.h"
16
16
#include " llvm/ADT/BitVector.h"
17
17
#include " llvm/ADT/DenseMap.h"
18
- #include " llvm/ADT/EquivalenceClasses.h"
19
18
#include " llvm/ADT/PriorityQueue.h"
20
19
#include " llvm/ADT/STLExtras.h"
21
20
#include " llvm/ADT/SmallVector.h"
@@ -944,6 +943,8 @@ void ScheduleDAGMI::releaseSucc(SUnit *SU, SDep *SuccEdge) {
944
943
945
944
if (SuccEdge->isWeak ()) {
946
945
--SuccSU->WeakPredsLeft ;
946
+ if (SuccEdge->isCluster ())
947
+ NextClusterSucc = SuccSU;
947
948
return ;
948
949
}
949
950
#ifndef NDEBUG
@@ -966,6 +967,12 @@ void ScheduleDAGMI::releaseSucc(SUnit *SU, SDep *SuccEdge) {
966
967
967
968
// / releaseSuccessors - Call releaseSucc on each of SU's successors.
968
969
void ScheduleDAGMI::releaseSuccessors (SUnit *SU) {
970
+ // Reset the next successor, For example, we want to cluster A B C.
971
+ // After A is picked, we will set B as next cluster succ, but if we pick
972
+ // D instead of B after A, then we need to reset the next cluster succ because
973
+ // we have decided to not pick the cluster candidate B during pickNode().
974
+ // Leaving B as the NextClusterSucc just make things messy.
975
+ NextClusterSucc = nullptr ;
969
976
for (SDep &Succ : SU->Succs )
970
977
releaseSucc (SU, &Succ);
971
978
}
@@ -979,6 +986,8 @@ void ScheduleDAGMI::releasePred(SUnit *SU, SDep *PredEdge) {
979
986
980
987
if (PredEdge->isWeak ()) {
981
988
--PredSU->WeakSuccsLeft ;
989
+ if (PredEdge->isCluster ())
990
+ NextClusterPred = PredSU;
982
991
return ;
983
992
}
984
993
#ifndef NDEBUG
@@ -1001,6 +1010,7 @@ void ScheduleDAGMI::releasePred(SUnit *SU, SDep *PredEdge) {
1001
1010
1002
1011
// / releasePredecessors - Call releasePred on each of SU's predecessors.
1003
1012
void ScheduleDAGMI::releasePredecessors (SUnit *SU) {
1013
+ NextClusterPred = nullptr ;
1004
1014
for (SDep &Pred : SU->Preds )
1005
1015
releasePred (SU, &Pred);
1006
1016
}
@@ -1174,8 +1184,11 @@ findRootsAndBiasEdges(SmallVectorImpl<SUnit*> &TopRoots,
1174
1184
}
1175
1185
1176
1186
// / Identify DAG roots and setup scheduler queues.
1177
- void ScheduleDAGMI::initQueues (ArrayRef<SUnit *> TopRoots,
1178
- ArrayRef<SUnit *> BotRoots) {
1187
+ void ScheduleDAGMI::initQueues (ArrayRef<SUnit*> TopRoots,
1188
+ ArrayRef<SUnit*> BotRoots) {
1189
+ NextClusterSucc = nullptr ;
1190
+ NextClusterPred = nullptr ;
1191
+
1179
1192
// Release all DAG roots for scheduling, not including EntrySU/ExitSU.
1180
1193
//
1181
1194
// Nodes with unreleased weak edges can still be roots.
@@ -2103,7 +2116,6 @@ void BaseMemOpClusterMutation::clusterNeighboringMemOps(
2103
2116
ScheduleDAGInstrs *DAG) {
2104
2117
// Keep track of the current cluster length and bytes for each SUnit.
2105
2118
DenseMap<unsigned , std::pair<unsigned , unsigned >> SUnit2ClusterInfo;
2106
- EquivalenceClasses<SUnit *> Clusters;
2107
2119
2108
2120
// At this point, `MemOpRecords` array must hold atleast two mem ops. Try to
2109
2121
// cluster mem ops collected within `MemOpRecords` array.
@@ -2143,15 +2155,13 @@ void BaseMemOpClusterMutation::clusterNeighboringMemOps(
2143
2155
2144
2156
SUnit *SUa = MemOpa.SU ;
2145
2157
SUnit *SUb = MemOpb.SU ;
2146
-
2147
2158
if (!ReorderWhileClustering && SUa->NodeNum > SUb->NodeNum )
2148
2159
std::swap (SUa, SUb);
2149
2160
2150
2161
// FIXME: Is this check really required?
2151
2162
if (!DAG->addEdge (SUb, SDep (SUa, SDep::Cluster)))
2152
2163
continue ;
2153
2164
2154
- Clusters.unionSets (SUa, SUb);
2155
2165
LLVM_DEBUG (dbgs () << " Cluster ld/st SU(" << SUa->NodeNum << " ) - SU("
2156
2166
<< SUb->NodeNum << " )\n " );
2157
2167
++NumClustered;
@@ -2191,21 +2201,6 @@ void BaseMemOpClusterMutation::clusterNeighboringMemOps(
2191
2201
<< " , Curr cluster bytes: " << CurrentClusterBytes
2192
2202
<< " \n " );
2193
2203
}
2194
-
2195
- // Add cluster group information.
2196
- // Iterate over all of the equivalence sets.
2197
- auto &AllClusters = DAG->getClusters ();
2198
- for (const EquivalenceClasses<SUnit *>::ECValue *I : Clusters) {
2199
- if (!I->isLeader ())
2200
- continue ;
2201
- ClusterInfo Group;
2202
- unsigned ClusterIdx = AllClusters.size ();
2203
- for (SUnit *MemberI : Clusters.members (*I)) {
2204
- MemberI->ParentClusterIdx = ClusterIdx;
2205
- Group.insert (MemberI);
2206
- }
2207
- AllClusters.push_back (Group);
2208
- }
2209
2204
}
2210
2205
2211
2206
void BaseMemOpClusterMutation::collectMemOpRecords (
@@ -3693,9 +3688,6 @@ void GenericScheduler::initialize(ScheduleDAGMI *dag) {
3693
3688
}
3694
3689
TopCand.SU = nullptr ;
3695
3690
BotCand.SU = nullptr ;
3696
-
3697
- TopCluster = nullptr ;
3698
- BotCluster = nullptr ;
3699
3691
}
3700
3692
3701
3693
// / Initialize the per-region scheduling policy.
@@ -4005,11 +3997,13 @@ bool GenericScheduler::tryCandidate(SchedCandidate &Cand,
4005
3997
// This is a best effort to set things up for a post-RA pass. Optimizations
4006
3998
// like generating loads of multiple registers should ideally be done within
4007
3999
// the scheduler pass by combining the loads during DAG postprocessing.
4008
- const ClusterInfo *CandCluster = Cand.AtTop ? TopCluster : BotCluster;
4009
- const ClusterInfo *TryCandCluster = TryCand.AtTop ? TopCluster : BotCluster;
4010
- if (tryGreater (TryCandCluster && TryCandCluster->contains (TryCand.SU ),
4011
- CandCluster && CandCluster->contains (Cand.SU ), TryCand, Cand,
4012
- Cluster))
4000
+ const SUnit *CandNextClusterSU =
4001
+ Cand.AtTop ? DAG->getNextClusterSucc () : DAG->getNextClusterPred ();
4002
+ const SUnit *TryCandNextClusterSU =
4003
+ TryCand.AtTop ? DAG->getNextClusterSucc () : DAG->getNextClusterPred ();
4004
+ if (tryGreater (TryCand.SU == TryCandNextClusterSU,
4005
+ Cand.SU == CandNextClusterSU,
4006
+ TryCand, Cand, Cluster))
4013
4007
return TryCand.Reason != NoCand;
4014
4008
4015
4009
if (SameBoundary) {
@@ -4268,25 +4262,11 @@ void GenericScheduler::reschedulePhysReg(SUnit *SU, bool isTop) {
4268
4262
void GenericScheduler::schedNode (SUnit *SU, bool IsTopNode) {
4269
4263
if (IsTopNode) {
4270
4264
SU->TopReadyCycle = std::max (SU->TopReadyCycle , Top.getCurrCycle ());
4271
- TopCluster = DAG->getCluster (SU->ParentClusterIdx );
4272
- LLVM_DEBUG (if (TopCluster) {
4273
- dbgs () << " Top Cluster: " ;
4274
- for (auto *N : *TopCluster)
4275
- dbgs () << N->NodeNum << ' \t ' ;
4276
- dbgs () << ' \n ' ;
4277
- });
4278
4265
Top.bumpNode (SU);
4279
4266
if (SU->hasPhysRegUses )
4280
4267
reschedulePhysReg (SU, true );
4281
4268
} else {
4282
4269
SU->BotReadyCycle = std::max (SU->BotReadyCycle , Bot.getCurrCycle ());
4283
- BotCluster = DAG->getCluster (SU->ParentClusterIdx );
4284
- LLVM_DEBUG (if (BotCluster) {
4285
- dbgs () << " Bot Cluster: " ;
4286
- for (auto *N : *BotCluster)
4287
- dbgs () << N->NodeNum << ' \t ' ;
4288
- dbgs () << ' \n ' ;
4289
- });
4290
4270
Bot.bumpNode (SU);
4291
4271
if (SU->hasPhysRegDefs )
4292
4272
reschedulePhysReg (SU, false );
@@ -4323,8 +4303,6 @@ void PostGenericScheduler::initialize(ScheduleDAGMI *Dag) {
4323
4303
if (!Bot.HazardRec ) {
4324
4304
Bot.HazardRec = DAG->TII ->CreateTargetMIHazardRecognizer (Itin, DAG);
4325
4305
}
4326
- TopCluster = nullptr ;
4327
- BotCluster = nullptr ;
4328
4306
}
4329
4307
4330
4308
void PostGenericScheduler::initPolicy (MachineBasicBlock::iterator Begin,
@@ -4389,12 +4367,14 @@ bool PostGenericScheduler::tryCandidate(SchedCandidate &Cand,
4389
4367
return TryCand.Reason != NoCand;
4390
4368
4391
4369
// Keep clustered nodes together.
4392
- const ClusterInfo *CandCluster = Cand.AtTop ? TopCluster : BotCluster;
4393
- const ClusterInfo *TryCandCluster = TryCand.AtTop ? TopCluster : BotCluster;
4394
- if (tryGreater (TryCandCluster && TryCandCluster->contains (TryCand.SU ),
4395
- CandCluster && CandCluster->contains (Cand.SU ), TryCand, Cand,
4396
- Cluster))
4370
+ const SUnit *CandNextClusterSU =
4371
+ Cand.AtTop ? DAG->getNextClusterSucc () : DAG->getNextClusterPred ();
4372
+ const SUnit *TryCandNextClusterSU =
4373
+ TryCand.AtTop ? DAG->getNextClusterSucc () : DAG->getNextClusterPred ();
4374
+ if (tryGreater (TryCand.SU == TryCandNextClusterSU,
4375
+ Cand.SU == CandNextClusterSU, TryCand, Cand, Cluster))
4397
4376
return TryCand.Reason != NoCand;
4377
+
4398
4378
// Avoid critical resource consumption and balance the schedule.
4399
4379
if (tryLess (TryCand.ResDelta .CritResources , Cand.ResDelta .CritResources ,
4400
4380
TryCand, Cand, ResourceReduce))
@@ -4591,11 +4571,9 @@ SUnit *PostGenericScheduler::pickNode(bool &IsTopNode) {
4591
4571
void PostGenericScheduler::schedNode (SUnit *SU, bool IsTopNode) {
4592
4572
if (IsTopNode) {
4593
4573
SU->TopReadyCycle = std::max (SU->TopReadyCycle , Top.getCurrCycle ());
4594
- TopCluster = DAG->getCluster (SU->ParentClusterIdx );
4595
4574
Top.bumpNode (SU);
4596
4575
} else {
4597
4576
SU->BotReadyCycle = std::max (SU->BotReadyCycle , Bot.getCurrCycle ());
4598
- BotCluster = DAG->getCluster (SU->ParentClusterIdx );
4599
4577
Bot.bumpNode (SU);
4600
4578
}
4601
4579
}
0 commit comments