@@ -2818,6 +2818,8 @@ void GenericSchedulerBase::traceCandidate(const SchedCandidate &Cand) {
2818
2818
2819
2819
namespace llvm {
2820
2820
// / Return true if this heuristic determines order.
2821
+ // / TODO: Consider refactor return type of these functions as integer or enum,
2822
+ // / as we may need to differentiate whether TryCand is better than Cand.
2821
2823
bool tryLess (int TryVal, int CandVal,
2822
2824
GenericSchedulerBase::SchedCandidate &TryCand,
2823
2825
GenericSchedulerBase::SchedCandidate &Cand,
@@ -3176,34 +3178,35 @@ void GenericScheduler::initCandidate(SchedCandidate &Cand, SUnit *SU,
3176
3178
// / \param Cand provides the policy and current best candidate.
3177
3179
// / \param TryCand refers to the next SUnit candidate, otherwise uninitialized.
3178
3180
// / \param Zone describes the scheduled zone that we are extending, or nullptr
3179
- // if Cand is from a different zone than TryCand.
3180
- void GenericScheduler::tryCandidate (SchedCandidate &Cand,
3181
+ // / if Cand is from a different zone than TryCand.
3182
+ // / \return \c true if TryCand is better than Cand (Reason is NOT NoCand)
3183
+ bool GenericScheduler::tryCandidate (SchedCandidate &Cand,
3181
3184
SchedCandidate &TryCand,
3182
3185
SchedBoundary *Zone) const {
3183
3186
// Initialize the candidate if needed.
3184
3187
if (!Cand.isValid ()) {
3185
3188
TryCand.Reason = NodeOrder;
3186
- return ;
3189
+ return true ;
3187
3190
}
3188
3191
3189
3192
// Bias PhysReg Defs and copies to their uses and defined respectively.
3190
3193
if (tryGreater (biasPhysReg (TryCand.SU , TryCand.AtTop ),
3191
3194
biasPhysReg (Cand.SU , Cand.AtTop ), TryCand, Cand, PhysReg))
3192
- return ;
3195
+ return TryCand. Reason != NoCand ;
3193
3196
3194
3197
// Avoid exceeding the target's limit.
3195
3198
if (DAG->isTrackingPressure () && tryPressure (TryCand.RPDelta .Excess ,
3196
3199
Cand.RPDelta .Excess ,
3197
3200
TryCand, Cand, RegExcess, TRI,
3198
3201
DAG->MF ))
3199
- return ;
3202
+ return TryCand. Reason != NoCand ;
3200
3203
3201
3204
// Avoid increasing the max critical pressure in the scheduled region.
3202
3205
if (DAG->isTrackingPressure () && tryPressure (TryCand.RPDelta .CriticalMax ,
3203
3206
Cand.RPDelta .CriticalMax ,
3204
3207
TryCand, Cand, RegCritical, TRI,
3205
3208
DAG->MF ))
3206
- return ;
3209
+ return TryCand. Reason != NoCand ;
3207
3210
3208
3211
// We only compare a subset of features when comparing nodes between
3209
3212
// Top and Bottom boundary. Some properties are simply incomparable, in many
@@ -3217,12 +3220,12 @@ void GenericScheduler::tryCandidate(SchedCandidate &Cand,
3217
3220
// heuristics to take precedence.
3218
3221
if (Rem.IsAcyclicLatencyLimited && !Zone->getCurrMOps () &&
3219
3222
tryLatency (TryCand, Cand, *Zone))
3220
- return ;
3223
+ return TryCand. Reason != NoCand ;
3221
3224
3222
3225
// Prioritize instructions that read unbuffered resources by stall cycles.
3223
3226
if (tryLess (Zone->getLatencyStallCycles (TryCand.SU ),
3224
3227
Zone->getLatencyStallCycles (Cand.SU ), TryCand, Cand, Stall))
3225
- return ;
3228
+ return TryCand. Reason != NoCand ;
3226
3229
}
3227
3230
3228
3231
// Keep clustered nodes together to encourage downstream peephole
@@ -3238,46 +3241,49 @@ void GenericScheduler::tryCandidate(SchedCandidate &Cand,
3238
3241
if (tryGreater (TryCand.SU == TryCandNextClusterSU,
3239
3242
Cand.SU == CandNextClusterSU,
3240
3243
TryCand, Cand, Cluster))
3241
- return ;
3244
+ return TryCand. Reason != NoCand ;
3242
3245
3243
3246
if (SameBoundary) {
3244
3247
// Weak edges are for clustering and other constraints.
3245
3248
if (tryLess (getWeakLeft (TryCand.SU , TryCand.AtTop ),
3246
3249
getWeakLeft (Cand.SU , Cand.AtTop ),
3247
3250
TryCand, Cand, Weak))
3248
- return ;
3251
+ return TryCand. Reason != NoCand ;
3249
3252
}
3250
3253
3251
3254
// Avoid increasing the max pressure of the entire region.
3252
3255
if (DAG->isTrackingPressure () && tryPressure (TryCand.RPDelta .CurrentMax ,
3253
3256
Cand.RPDelta .CurrentMax ,
3254
3257
TryCand, Cand, RegMax, TRI,
3255
3258
DAG->MF ))
3256
- return ;
3259
+ return TryCand. Reason != NoCand ;
3257
3260
3258
3261
if (SameBoundary) {
3259
3262
// Avoid critical resource consumption and balance the schedule.
3260
3263
TryCand.initResourceDelta (DAG, SchedModel);
3261
3264
if (tryLess (TryCand.ResDelta .CritResources , Cand.ResDelta .CritResources ,
3262
3265
TryCand, Cand, ResourceReduce))
3263
- return ;
3266
+ return TryCand. Reason != NoCand ;
3264
3267
if (tryGreater (TryCand.ResDelta .DemandedResources ,
3265
3268
Cand.ResDelta .DemandedResources ,
3266
3269
TryCand, Cand, ResourceDemand))
3267
- return ;
3270
+ return TryCand. Reason != NoCand ;
3268
3271
3269
3272
// Avoid serializing long latency dependence chains.
3270
3273
// For acyclic path limited loops, latency was already checked above.
3271
3274
if (!RegionPolicy.DisableLatencyHeuristic && TryCand.Policy .ReduceLatency &&
3272
3275
!Rem.IsAcyclicLatencyLimited && tryLatency (TryCand, Cand, *Zone))
3273
- return ;
3276
+ return TryCand. Reason != NoCand ;
3274
3277
3275
3278
// Fall through to original instruction order.
3276
3279
if ((Zone->isTop () && TryCand.SU ->NodeNum < Cand.SU ->NodeNum )
3277
3280
|| (!Zone->isTop () && TryCand.SU ->NodeNum > Cand.SU ->NodeNum )) {
3278
3281
TryCand.Reason = NodeOrder;
3282
+ return true ;
3279
3283
}
3280
3284
}
3285
+
3286
+ return false ;
3281
3287
}
3282
3288
3283
3289
// / Pick the best candidate from the queue.
@@ -3299,8 +3305,7 @@ void GenericScheduler::pickNodeFromQueue(SchedBoundary &Zone,
3299
3305
initCandidate (TryCand, SU, Zone.isTop (), RPTracker, TempTracker);
3300
3306
// Pass SchedBoundary only when comparing nodes from the same boundary.
3301
3307
SchedBoundary *ZoneArg = Cand.AtTop == TryCand.AtTop ? &Zone : nullptr ;
3302
- tryCandidate (Cand, TryCand, ZoneArg);
3303
- if (TryCand.Reason != NoCand) {
3308
+ if (tryCandidate (Cand, TryCand, ZoneArg)) {
3304
3309
// Initialize resource delta if needed in case future heuristics query it.
3305
3310
if (TryCand.ResDelta == SchedResourceDelta ())
3306
3311
TryCand.initResourceDelta (DAG, SchedModel);
@@ -3378,8 +3383,7 @@ SUnit *GenericScheduler::pickNodeBidirectional(bool &IsTopNode) {
3378
3383
assert (TopCand.isValid ());
3379
3384
SchedCandidate Cand = BotCand;
3380
3385
TopCand.Reason = NoCand;
3381
- tryCandidate (Cand, TopCand, nullptr );
3382
- if (TopCand.Reason != NoCand) {
3386
+ if (tryCandidate (Cand, TopCand, nullptr )) {
3383
3387
Cand.setBest (TopCand);
3384
3388
LLVM_DEBUG (traceCandidate (Cand));
3385
3389
}
@@ -3543,42 +3547,47 @@ void PostGenericScheduler::registerRoots() {
3543
3547
// /
3544
3548
// / \param Cand provides the policy and current best candidate.
3545
3549
// / \param TryCand refers to the next SUnit candidate, otherwise uninitialized.
3546
- void PostGenericScheduler::tryCandidate (SchedCandidate &Cand,
3550
+ // / \return \c true if TryCand is better than Cand (Reason is NOT NoCand)
3551
+ bool PostGenericScheduler::tryCandidate (SchedCandidate &Cand,
3547
3552
SchedCandidate &TryCand) {
3548
3553
// Initialize the candidate if needed.
3549
3554
if (!Cand.isValid ()) {
3550
3555
TryCand.Reason = NodeOrder;
3551
- return ;
3556
+ return true ;
3552
3557
}
3553
3558
3554
3559
// Prioritize instructions that read unbuffered resources by stall cycles.
3555
3560
if (tryLess (Top.getLatencyStallCycles (TryCand.SU ),
3556
3561
Top.getLatencyStallCycles (Cand.SU ), TryCand, Cand, Stall))
3557
- return ;
3562
+ return TryCand. Reason != NoCand ;
3558
3563
3559
3564
// Keep clustered nodes together.
3560
3565
if (tryGreater (TryCand.SU == DAG->getNextClusterSucc (),
3561
3566
Cand.SU == DAG->getNextClusterSucc (),
3562
3567
TryCand, Cand, Cluster))
3563
- return ;
3568
+ return TryCand. Reason != NoCand ;
3564
3569
3565
3570
// Avoid critical resource consumption and balance the schedule.
3566
3571
if (tryLess (TryCand.ResDelta .CritResources , Cand.ResDelta .CritResources ,
3567
3572
TryCand, Cand, ResourceReduce))
3568
- return ;
3573
+ return TryCand. Reason != NoCand ;
3569
3574
if (tryGreater (TryCand.ResDelta .DemandedResources ,
3570
3575
Cand.ResDelta .DemandedResources ,
3571
3576
TryCand, Cand, ResourceDemand))
3572
- return ;
3577
+ return TryCand. Reason != NoCand ;
3573
3578
3574
3579
// Avoid serializing long latency dependence chains.
3575
3580
if (Cand.Policy .ReduceLatency && tryLatency (TryCand, Cand, Top)) {
3576
- return ;
3581
+ return TryCand. Reason != NoCand ;
3577
3582
}
3578
3583
3579
3584
// Fall through to original instruction order.
3580
- if (TryCand.SU ->NodeNum < Cand.SU ->NodeNum )
3585
+ if (TryCand.SU ->NodeNum < Cand.SU ->NodeNum ) {
3581
3586
TryCand.Reason = NodeOrder;
3587
+ return true ;
3588
+ }
3589
+
3590
+ return false ;
3582
3591
}
3583
3592
3584
3593
void PostGenericScheduler::pickNodeFromQueue (SchedCandidate &Cand) {
@@ -3588,8 +3597,7 @@ void PostGenericScheduler::pickNodeFromQueue(SchedCandidate &Cand) {
3588
3597
TryCand.SU = SU;
3589
3598
TryCand.AtTop = true ;
3590
3599
TryCand.initResourceDelta (DAG, SchedModel);
3591
- tryCandidate (Cand, TryCand);
3592
- if (TryCand.Reason != NoCand) {
3600
+ if (tryCandidate (Cand, TryCand)) {
3593
3601
Cand.setBest (TryCand);
3594
3602
LLVM_DEBUG (traceCandidate (Cand));
3595
3603
}
0 commit comments