@@ -69,12 +69,6 @@ static cl::opt<bool> GCNTrackers(
6969 cl::desc (" Use the AMDGPU specific RPTrackers during scheduling" ),
7070 cl::init(false ));
7171
72- static cl::opt<unsigned > PendingQueueLimit (
73- " amdgpu-scheduler-pending-queue-limit" , cl::Hidden,
74- cl::desc (
75- " Max (Available+Pending) size to inspect pending queue (0 disables)" ),
76- cl::init(256 ));
77-
7872#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
7973#define DUMP_MAX_REG_PRESSURE
8074static cl::opt<bool > PrintMaxRPRegUsageBeforeScheduler (
@@ -341,52 +335,17 @@ void GCNSchedStrategy::initCandidate(SchedCandidate &Cand, SUnit *SU,
341335 }
342336}
343337
344- static bool shouldCheckPending (SchedBoundary &Zone,
345- const TargetSchedModel *SchedModel) {
346- bool HasBufferedModel =
347- SchedModel->hasInstrSchedModel () && SchedModel->getMicroOpBufferSize ();
348- unsigned Combined = Zone.Available .size () + Zone.Pending .size ();
349- return Combined <= PendingQueueLimit && HasBufferedModel;
350- }
351-
352- static SUnit *pickOnlyChoice (SchedBoundary &Zone,
353- const TargetSchedModel *SchedModel) {
354- // pickOnlyChoice() releases pending instructions and checks for new hazards.
355- SUnit *OnlyChoice = Zone.pickOnlyChoice ();
356- if (!shouldCheckPending (Zone, SchedModel) || Zone.Pending .empty ())
357- return OnlyChoice;
358-
359- return nullptr ;
360- }
361-
362- void GCNSchedStrategy::printCandidateDecision (const SchedCandidate &Current,
363- const SchedCandidate &Preferred) {
364- LLVM_DEBUG ({
365- dbgs () << " Prefer:\t\t " ;
366- DAG->dumpNode (*Preferred.SU );
367-
368- if (Current.SU ) {
369- dbgs () << " Not:\t " ;
370- DAG->dumpNode (*Current.SU );
371- }
372-
373- dbgs () << " Reason:\t\t " ;
374- traceCandidate (Preferred);
375- });
376- }
377-
378338// This function is mostly cut and pasted from
379339// GenericScheduler::pickNodeFromQueue()
380340void GCNSchedStrategy::pickNodeFromQueue (SchedBoundary &Zone,
381341 const CandPolicy &ZonePolicy,
382342 const RegPressureTracker &RPTracker,
383- SchedCandidate &Cand, bool &IsPending,
343+ SchedCandidate &Cand,
384344 bool IsBottomUp) {
385345 const SIRegisterInfo *SRI = static_cast <const SIRegisterInfo *>(TRI);
386346 ArrayRef<unsigned > Pressure = RPTracker.getRegSetPressureAtPos ();
387347 unsigned SGPRPressure = 0 ;
388348 unsigned VGPRPressure = 0 ;
389- IsPending = false ;
390349 if (DAG->isTrackingPressure ()) {
391350 if (!GCNTrackers) {
392351 SGPRPressure = Pressure[AMDGPU::RegisterPressureSets::SReg_32];
@@ -399,9 +358,8 @@ void GCNSchedStrategy::pickNodeFromQueue(SchedBoundary &Zone,
399358 VGPRPressure = T->getPressure ().getArchVGPRNum ();
400359 }
401360 }
402- LLVM_DEBUG (dbgs () << " Available Q:\n " );
403- ReadyQueue &AQ = Zone.Available ;
404- for (SUnit *SU : AQ) {
361+ ReadyQueue &Q = Zone.Available ;
362+ for (SUnit *SU : Q) {
405363
406364 SchedCandidate TryCand (ZonePolicy);
407365 initCandidate (TryCand, SU, Zone.isTop (), RPTracker, SRI, SGPRPressure,
@@ -413,70 +371,40 @@ void GCNSchedStrategy::pickNodeFromQueue(SchedBoundary &Zone,
413371 // Initialize resource delta if needed in case future heuristics query it.
414372 if (TryCand.ResDelta == SchedResourceDelta ())
415373 TryCand.initResourceDelta (Zone.DAG , SchedModel);
416- LLVM_DEBUG (printCandidateDecision (Cand, TryCand));
417374 Cand.setBest (TryCand);
418- } else {
419- printCandidateDecision (TryCand, Cand);
420- }
421- }
422-
423- if (!shouldCheckPending (Zone, SchedModel))
424- return ;
425-
426- LLVM_DEBUG (dbgs () << " Pending Q:\n " );
427- ReadyQueue &PQ = Zone.Pending ;
428- for (SUnit *SU : PQ) {
429-
430- SchedCandidate TryCand (ZonePolicy);
431- initCandidate (TryCand, SU, Zone.isTop (), RPTracker, SRI, SGPRPressure,
432- VGPRPressure, IsBottomUp);
433- // Pass SchedBoundary only when comparing nodes from the same boundary.
434- SchedBoundary *ZoneArg = Cand.AtTop == TryCand.AtTop ? &Zone : nullptr ;
435- tryPendingCandidate (Cand, TryCand, ZoneArg);
436- if (TryCand.Reason != NoCand) {
437- // Initialize resource delta if needed in case future heuristics query it.
438- if (TryCand.ResDelta == SchedResourceDelta ())
439- TryCand.initResourceDelta (Zone.DAG , SchedModel);
440- LLVM_DEBUG (printCandidateDecision (Cand, TryCand));
441- IsPending = true ;
442- Cand.setBest (TryCand);
443- } else {
444- printCandidateDecision (TryCand, Cand);
375+ LLVM_DEBUG (traceCandidate (Cand));
445376 }
446377 }
447378}
448379
449380// This function is mostly cut and pasted from
450381// GenericScheduler::pickNodeBidirectional()
451- SUnit *GCNSchedStrategy::pickNodeBidirectional (bool &IsTopNode,
452- bool &PickedPending) {
382+ SUnit *GCNSchedStrategy::pickNodeBidirectional (bool &IsTopNode) {
453383 // Schedule as far as possible in the direction of no choice. This is most
454384 // efficient, but also provides the best heuristics for CriticalPSets.
455- if (SUnit *SU = pickOnlyChoice (Bot, SchedModel )) {
385+ if (SUnit *SU = Bot. pickOnlyChoice ()) {
456386 IsTopNode = false ;
457387 return SU;
458388 }
459- if (SUnit *SU = pickOnlyChoice (Top, SchedModel )) {
389+ if (SUnit *SU = Top. pickOnlyChoice ()) {
460390 IsTopNode = true ;
461391 return SU;
462392 }
463- // Set the bottom-up policy based on the state of the current bottom zone
464- // and the instructions outside the zone, including the top zone.
393+ // Set the bottom-up policy based on the state of the current bottom zone and
394+ // the instructions outside the zone, including the top zone.
465395 CandPolicy BotPolicy;
466396 setPolicy (BotPolicy, /* IsPostRA=*/ false , Bot, &Top);
467397 // Set the top-down policy based on the state of the current top zone and
468398 // the instructions outside the zone, including the bottom zone.
469399 CandPolicy TopPolicy;
470400 setPolicy (TopPolicy, /* IsPostRA=*/ false , Top, &Bot);
471401
472- bool BotPending = false ;
473402 // See if BotCand is still valid (because we previously scheduled from Top).
474403 LLVM_DEBUG (dbgs () << " Picking from Bot:\n " );
475404 if (!BotCand.isValid () || BotCand.SU ->isScheduled ||
476405 BotCand.Policy != BotPolicy) {
477406 BotCand.reset (CandPolicy ());
478407 pickNodeFromQueue (Bot, BotPolicy, DAG->getBotRPTracker (), BotCand,
479- BotPending,
480408 /* IsBottomUp=*/ true );
481409 assert (BotCand.Reason != NoCand && " failed to find the first candidate" );
482410 } else {
@@ -486,22 +414,19 @@ SUnit *GCNSchedStrategy::pickNodeBidirectional(bool &IsTopNode,
486414 SchedCandidate TCand;
487415 TCand.reset (CandPolicy ());
488416 pickNodeFromQueue (Bot, BotPolicy, DAG->getBotRPTracker (), TCand,
489- BotPending,
490417 /* IsBottomUp=*/ true );
491418 assert (TCand.SU == BotCand.SU &&
492419 " Last pick result should correspond to re-picking right now" );
493420 }
494421#endif
495422 }
496423
497- bool TopPending = false ;
498424 // Check if the top Q has a better candidate.
499425 LLVM_DEBUG (dbgs () << " Picking from Top:\n " );
500426 if (!TopCand.isValid () || TopCand.SU ->isScheduled ||
501427 TopCand.Policy != TopPolicy) {
502428 TopCand.reset (CandPolicy ());
503429 pickNodeFromQueue (Top, TopPolicy, DAG->getTopRPTracker (), TopCand,
504- TopPending,
505430 /* IsBottomUp=*/ false );
506431 assert (TopCand.Reason != NoCand && " failed to find the first candidate" );
507432 } else {
@@ -511,7 +436,6 @@ SUnit *GCNSchedStrategy::pickNodeBidirectional(bool &IsTopNode,
511436 SchedCandidate TCand;
512437 TCand.reset (CandPolicy ());
513438 pickNodeFromQueue (Top, TopPolicy, DAG->getTopRPTracker (), TCand,
514- TopPending,
515439 /* IsBottomUp=*/ false );
516440 assert (TCand.SU == TopCand.SU &&
517441 " Last pick result should correspond to re-picking right now" );
@@ -522,21 +446,12 @@ SUnit *GCNSchedStrategy::pickNodeBidirectional(bool &IsTopNode,
522446 // Pick best from BotCand and TopCand.
523447 LLVM_DEBUG (dbgs () << " Top Cand: " ; traceCandidate (TopCand);
524448 dbgs () << " Bot Cand: " ; traceCandidate (BotCand););
525- SchedCandidate Cand = BotPending ? TopCand : BotCand;
526- SchedCandidate TryCand = BotPending ? BotCand : TopCand;
527- PickedPending = BotPending && TopPending;
528-
529- TryCand.Reason = NoCand;
530- if (BotPending || TopPending) {
531- PickedPending |= tryPendingCandidate (Cand, TopCand, nullptr );
532- } else {
533- tryCandidate (Cand, TryCand, nullptr );
534- }
535-
536- if (TryCand.Reason != NoCand) {
537- Cand.setBest (TryCand);
449+ SchedCandidate Cand = BotCand;
450+ TopCand.Reason = NoCand;
451+ tryCandidate (Cand, TopCand, nullptr );
452+ if (TopCand.Reason != NoCand) {
453+ Cand.setBest (TopCand);
538454 }
539-
540455 LLVM_DEBUG (dbgs () << " Picking: " ; traceCandidate (Cand););
541456
542457 IsTopNode = Cand.AtTop ;
@@ -551,55 +466,35 @@ SUnit *GCNSchedStrategy::pickNode(bool &IsTopNode) {
551466 Bot.Available .empty () && Bot.Pending .empty () && " ReadyQ garbage" );
552467 return nullptr ;
553468 }
554- bool PickedPending;
555469 SUnit *SU;
556470 do {
557- PickedPending = false ;
558471 if (RegionPolicy.OnlyTopDown ) {
559- SU = pickOnlyChoice (Top, SchedModel );
472+ SU = Top. pickOnlyChoice ();
560473 if (!SU) {
561474 CandPolicy NoPolicy;
562475 TopCand.reset (NoPolicy);
563476 pickNodeFromQueue (Top, NoPolicy, DAG->getTopRPTracker (), TopCand,
564- PickedPending,
565477 /* IsBottomUp=*/ false );
566478 assert (TopCand.Reason != NoCand && " failed to find a candidate" );
567479 SU = TopCand.SU ;
568480 }
569481 IsTopNode = true ;
570482 } else if (RegionPolicy.OnlyBottomUp ) {
571- SU = pickOnlyChoice (Bot, SchedModel );
483+ SU = Bot. pickOnlyChoice ();
572484 if (!SU) {
573485 CandPolicy NoPolicy;
574486 BotCand.reset (NoPolicy);
575487 pickNodeFromQueue (Bot, NoPolicy, DAG->getBotRPTracker (), BotCand,
576- PickedPending,
577488 /* IsBottomUp=*/ true );
578489 assert (BotCand.Reason != NoCand && " failed to find a candidate" );
579490 SU = BotCand.SU ;
580491 }
581492 IsTopNode = false ;
582493 } else {
583- SU = pickNodeBidirectional (IsTopNode, PickedPending );
494+ SU = pickNodeBidirectional (IsTopNode);
584495 }
585496 } while (SU->isScheduled );
586497
587- if (PickedPending) {
588- unsigned ReadyCycle = IsTopNode ? SU->TopReadyCycle : SU->BotReadyCycle ;
589- SchedBoundary &Zone = IsTopNode ? Top : Bot;
590- unsigned CurrentCycle = Zone.getCurrCycle ();
591- if (ReadyCycle > CurrentCycle)
592- Zone.bumpCycle (ReadyCycle);
593-
594- // FIXME: checkHazard() doesn't give information about which cycle the
595- // hazard will resolve so just keep bumping the cycle by 1. This could be
596- // made more efficient if checkHazard() returned more details.
597- while (Zone.checkHazard (SU))
598- Zone.bumpCycle (Zone.getCurrCycle () + 1 );
599-
600- Zone.releasePending ();
601- }
602-
603498 if (SU->isTopReady ())
604499 Top.removeReady (SU);
605500 if (SU->isBottomReady ())
@@ -645,47 +540,6 @@ GCNSchedStageID GCNSchedStrategy::getNextStage() const {
645540 return *std::next (CurrentStage);
646541}
647542
648- bool GCNSchedStrategy::tryPendingCandidate (SchedCandidate &Cand,
649- SchedCandidate &TryCand,
650- SchedBoundary *Zone) const {
651- // Initialize the candidate if needed.
652- if (!Cand.isValid ()) {
653- TryCand.Reason = NodeOrder;
654- return true ;
655- }
656-
657- // Bias PhysReg Defs and copies to their uses and defined respectively.
658- if (tryGreater (biasPhysReg (TryCand.SU , TryCand.AtTop ),
659- biasPhysReg (Cand.SU , Cand.AtTop ), TryCand, Cand, PhysReg))
660- return TryCand.Reason != NoCand;
661-
662- // Avoid exceeding the target's limit.
663- if (DAG->isTrackingPressure () &&
664- tryPressure (TryCand.RPDelta .Excess , Cand.RPDelta .Excess , TryCand, Cand,
665- RegExcess, TRI, DAG->MF ))
666- return TryCand.Reason != NoCand;
667-
668- // Avoid increasing the max critical pressure in the scheduled region.
669- if (DAG->isTrackingPressure () &&
670- tryPressure (TryCand.RPDelta .CriticalMax , Cand.RPDelta .CriticalMax ,
671- TryCand, Cand, RegCritical, TRI, DAG->MF ))
672- return TryCand.Reason != NoCand;
673-
674- bool SameBoundary = Zone != nullptr ;
675- if (SameBoundary) {
676- TryCand.initResourceDelta (DAG, SchedModel);
677- if (tryLess (TryCand.ResDelta .CritResources , Cand.ResDelta .CritResources ,
678- TryCand, Cand, ResourceReduce))
679- return TryCand.Reason != NoCand;
680- if (tryGreater (TryCand.ResDelta .DemandedResources ,
681- Cand.ResDelta .DemandedResources , TryCand, Cand,
682- ResourceDemand))
683- return TryCand.Reason != NoCand;
684- }
685-
686- return false ;
687- }
688-
689543GCNMaxOccupancySchedStrategy::GCNMaxOccupancySchedStrategy (
690544 const MachineSchedContext *C, bool IsLegacyScheduler)
691545 : GCNSchedStrategy(C) {
0 commit comments