@@ -316,13 +316,13 @@ GCNScheduleDAGMILive::GCNScheduleDAGMILive(MachineSchedContext *C,
316
316
ST(MF.getSubtarget<GCNSubtarget>()),
317
317
MFI(*MF.getInfo<SIMachineFunctionInfo>()),
318
318
StartingOccupancy(MFI.getOccupancy()),
319
- MinOccupancy(StartingOccupancy), Stage(0 ), RegionIdx(0 ) {
319
+ MinOccupancy(StartingOccupancy), Stage(Collect ), RegionIdx(0 ) {
320
320
321
321
LLVM_DEBUG (dbgs () << " Starting occupancy is " << StartingOccupancy << " .\n " );
322
322
}
323
323
324
324
void GCNScheduleDAGMILive::schedule () {
325
- if (Stage == 0 ) {
325
+ if (Stage == Collect ) {
326
326
// Just record regions at the first pass.
327
327
Regions.push_back (std::make_pair (RegionBegin, RegionEnd));
328
328
return ;
@@ -348,6 +348,7 @@ void GCNScheduleDAGMILive::schedule() {
348
348
349
349
ScheduleDAGMILive::schedule ();
350
350
Regions[RegionIdx] = std::make_pair (RegionBegin, RegionEnd);
351
+ RescheduleRegions[RegionIdx] = false ;
351
352
352
353
if (!LIS)
353
354
return ;
@@ -389,20 +390,28 @@ void GCNScheduleDAGMILive::schedule() {
389
390
<< MinOccupancy << " .\n " );
390
391
}
391
392
393
+ unsigned MaxVGPRs = ST.getMaxNumVGPRs (MF);
394
+ unsigned MaxSGPRs = ST.getMaxNumSGPRs (MF);
395
+ if (PressureAfter.getVGPRNum () > MaxVGPRs ||
396
+ PressureAfter.getSGPRNum () > MaxSGPRs)
397
+ RescheduleRegions[RegionIdx] = true ;
398
+
392
399
if (WavesAfter >= MinOccupancy) {
393
- unsigned TotalVGPRs = AMDGPU::IsaInfo::getAddressableNumVGPRs (&ST);
394
- unsigned TotalSGPRs = AMDGPU::IsaInfo::getAddressableNumSGPRs (&ST);
395
- if (WavesAfter > MFI.getMinWavesPerEU () ||
400
+ if (Stage == UnclusteredReschedule &&
401
+ !PressureAfter.less (ST, PressureBefore)) {
402
+ LLVM_DEBUG (dbgs () << " Unclustered reschedule did not help.\n " );
403
+ } else if (WavesAfter > MFI.getMinWavesPerEU () ||
396
404
PressureAfter.less (ST, PressureBefore) ||
397
- (TotalVGPRs >= PressureAfter.getVGPRNum () &&
398
- TotalSGPRs >= PressureAfter.getSGPRNum ())) {
405
+ !RescheduleRegions[RegionIdx]) {
399
406
Pressure[RegionIdx] = PressureAfter;
400
407
return ;
408
+ } else {
409
+ LLVM_DEBUG (dbgs () << " New pressure will result in more spilling.\n " );
401
410
}
402
- LLVM_DEBUG (dbgs () << " New pressure will result in more spilling.\n " );
403
411
}
404
412
405
413
LLVM_DEBUG (dbgs () << " Attempting to revert scheduling.\n " );
414
+ RescheduleRegions[RegionIdx] = true ;
406
415
RegionEnd = RegionBegin;
407
416
for (MachineInstr *MI : Unsched) {
408
417
if (MI->isDebugInstr ())
@@ -532,41 +541,63 @@ void GCNScheduleDAGMILive::finalizeSchedule() {
532
541
533
542
LiveIns.resize (Regions.size ());
534
543
Pressure.resize (Regions.size ());
544
+ RescheduleRegions.resize (Regions.size ());
545
+ RescheduleRegions.set ();
535
546
536
547
if (!Regions.empty ())
537
548
BBLiveInMap = getBBLiveInMap ();
538
549
550
+ std::vector<std::unique_ptr<ScheduleDAGMutation>> SavedMutations;
551
+
539
552
do {
540
553
Stage++;
541
554
RegionIdx = 0 ;
542
555
MachineBasicBlock *MBB = nullptr ;
543
556
544
- if (Stage > 1 ) {
557
+ if (Stage > InitialSchedule) {
558
+ if (!LIS)
559
+ break ;
560
+
545
561
// Retry function scheduling if we found resulting occupancy and it is
546
562
// lower than used for first pass scheduling. This will give more freedom
547
563
// to schedule low register pressure blocks.
548
564
// Code is partially copied from MachineSchedulerBase::scheduleRegions().
549
565
550
- if (!LIS || StartingOccupancy <= MinOccupancy)
551
- break ;
566
+ if (Stage == UnclusteredReschedule) {
567
+ if (RescheduleRegions.none ())
568
+ continue ;
569
+ LLVM_DEBUG (dbgs () <<
570
+ " Retrying function scheduling without clustering.\n " );
571
+ }
572
+
573
+ if (Stage == ClusteredLowOccupancyReschedule) {
574
+ if (StartingOccupancy <= MinOccupancy)
575
+ break ;
552
576
553
- LLVM_DEBUG (
554
- dbgs ()
555
- << " Retrying function scheduling with lowest recorded occupancy "
556
- << MinOccupancy << " .\n " );
577
+ LLVM_DEBUG (
578
+ dbgs ()
579
+ << " Retrying function scheduling with lowest recorded occupancy "
580
+ << MinOccupancy << " .\n " );
557
581
558
- S.setTargetOccupancy (MinOccupancy);
582
+ S.setTargetOccupancy (MinOccupancy);
583
+ }
559
584
}
560
585
586
+ if (Stage == UnclusteredReschedule)
587
+ SavedMutations.swap (Mutations);
588
+
561
589
for (auto Region : Regions) {
590
+ if (Stage == UnclusteredReschedule && !RescheduleRegions[RegionIdx])
591
+ continue ;
592
+
562
593
RegionBegin = Region.first ;
563
594
RegionEnd = Region.second ;
564
595
565
596
if (RegionBegin->getParent () != MBB) {
566
597
if (MBB) finishBlock ();
567
598
MBB = RegionBegin->getParent ();
568
599
startBlock (MBB);
569
- if (Stage == 1 )
600
+ if (Stage == InitialSchedule )
570
601
computeBlockPressure (MBB);
571
602
}
572
603
@@ -594,5 +625,7 @@ void GCNScheduleDAGMILive::finalizeSchedule() {
594
625
}
595
626
finishBlock ();
596
627
597
- } while (Stage < 2 );
628
+ if (Stage == UnclusteredReschedule)
629
+ SavedMutations.swap (Mutations);
630
+ } while (Stage != LastStage);
598
631
}
0 commit comments