Skip to content

Commit 96f3872

Browse files
authored
[AMDGPU][Scheduler] Delete RegionsWithMinOcc bitvector from scheduler (NFC) (#142361)
The `GCNScheduleDAGMILive`'s `RegionsWithMinOcc` bitvector is only used by the `UnclusteredHighRPStage`. Its presence in the scheduler's state forces us to maintain its value throughout scheduling even though it is of no use to the iterative scheduling process itself. At any point during scheduling it is possible to cheaply compute the occupancy induced by a particular register pressure. Furthermore, the field doesn't appear to be updated correctly throughout scheduling i.e., bits corresponding to regions at minimum occupancy are not always set in the vector. This removes the bitvector from `GCNScheduleDAGMILive`. `UnclusteredHighRPStage::initGCNRegion` now directly computes the occupancy of possibly reschedulable regions instead of querying the vector. Since it is the most expensive check, it is done last in the list.
1 parent dfbbb74 commit 96f3872

File tree

2 files changed

+12
-30
lines changed

2 files changed

+12
-30
lines changed

llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -942,11 +942,9 @@ void GCNScheduleDAGMILive::finalizeSchedule() {
942942
Pressure.resize(Regions.size());
943943
RegionsWithHighRP.resize(Regions.size());
944944
RegionsWithExcessRP.resize(Regions.size());
945-
RegionsWithMinOcc.resize(Regions.size());
946945
RegionsWithIGLPInstrs.resize(Regions.size());
947946
RegionsWithHighRP.reset();
948947
RegionsWithExcessRP.reset();
949-
RegionsWithMinOcc.reset();
950948
RegionsWithIGLPInstrs.reset();
951949

952950
runSchedStages();
@@ -1096,8 +1094,7 @@ bool PreRARematStage::initGCNSchedStage() {
10961094
// fixed if there is another pass after this pass.
10971095
assert(!S.hasNextStage());
10981096

1099-
if (!GCNSchedStage::initGCNSchedStage() || DAG.RegionsWithMinOcc.none() ||
1100-
DAG.Regions.size() == 1)
1097+
if (!GCNSchedStage::initGCNSchedStage() || DAG.Regions.size() == 1)
11011098
return false;
11021099

11031100
// Before performing any IR modification record the parent region of each MI
@@ -1139,11 +1136,6 @@ void UnclusteredHighRPStage::finalizeGCNSchedStage() {
11391136
SavedMutations.swap(DAG.Mutations);
11401137
S.SGPRLimitBias = S.VGPRLimitBias = 0;
11411138
if (DAG.MinOccupancy > InitialOccupancy) {
1142-
for (unsigned IDX = 0; IDX < DAG.Pressure.size(); ++IDX)
1143-
DAG.RegionsWithMinOcc[IDX] =
1144-
DAG.Pressure[IDX].getOccupancy(
1145-
DAG.ST, DAG.MFI.getDynamicVGPRBlockSize()) == DAG.MinOccupancy;
1146-
11471139
LLVM_DEBUG(dbgs() << StageID
11481140
<< " stage successfully increased occupancy to "
11491141
<< DAG.MinOccupancy << '\n');
@@ -1215,11 +1207,15 @@ bool GCNSchedStage::initGCNRegion() {
12151207
}
12161208

12171209
bool UnclusteredHighRPStage::initGCNRegion() {
1218-
// Only reschedule regions with the minimum occupancy or regions that may have
1219-
// spilling (excess register pressure).
1220-
if ((!DAG.RegionsWithMinOcc[RegionIdx] ||
1221-
DAG.MinOccupancy <= InitialOccupancy) &&
1222-
!DAG.RegionsWithExcessRP[RegionIdx])
1210+
// Only reschedule regions that have excess register pressure (i.e. spilling)
1211+
// or had minimum occupancy at the beginning of the stage (as long as
1212+
// rescheduling of previous regions did not make occupancy drop back down to
1213+
// the initial minimum).
1214+
unsigned DynamicVGPRBlockSize = DAG.MFI.getDynamicVGPRBlockSize();
1215+
if (!DAG.RegionsWithExcessRP[RegionIdx] &&
1216+
(DAG.MinOccupancy <= InitialOccupancy ||
1217+
DAG.Pressure[RegionIdx].getOccupancy(ST, DynamicVGPRBlockSize) !=
1218+
InitialOccupancy))
12231219
return false;
12241220

12251221
return GCNSchedStage::initGCNRegion();
@@ -1284,9 +1280,6 @@ void GCNSchedStage::checkScheduling() {
12841280
if (PressureAfter.getSGPRNum() <= S.SGPRCriticalLimit &&
12851281
PressureAfter.getVGPRNum(ST.hasGFX90AInsts()) <= S.VGPRCriticalLimit) {
12861282
DAG.Pressure[RegionIdx] = PressureAfter;
1287-
DAG.RegionsWithMinOcc[RegionIdx] =
1288-
PressureAfter.getOccupancy(ST, DynamicVGPRBlockSize) ==
1289-
DAG.MinOccupancy;
12901283

12911284
// Early out if we have achieved the occupancy target.
12921285
LLVM_DEBUG(dbgs() << "Pressure in desired limits, done.\n");
@@ -1320,7 +1313,6 @@ void GCNSchedStage::checkScheduling() {
13201313
if (NewOccupancy < DAG.MinOccupancy) {
13211314
DAG.MinOccupancy = NewOccupancy;
13221315
MFI.limitOccupancy(DAG.MinOccupancy);
1323-
DAG.RegionsWithMinOcc.reset();
13241316
LLVM_DEBUG(dbgs() << "Occupancy lowered for the function to "
13251317
<< DAG.MinOccupancy << ".\n");
13261318
}
@@ -1342,14 +1334,10 @@ void GCNSchedStage::checkScheduling() {
13421334

13431335
// Revert if this region's schedule would cause a drop in occupancy or
13441336
// spilling.
1345-
if (shouldRevertScheduling(WavesAfter)) {
1337+
if (shouldRevertScheduling(WavesAfter))
13461338
revertScheduling();
1347-
} else {
1339+
else
13481340
DAG.Pressure[RegionIdx] = PressureAfter;
1349-
DAG.RegionsWithMinOcc[RegionIdx] =
1350-
PressureAfter.getOccupancy(ST, DynamicVGPRBlockSize) ==
1351-
DAG.MinOccupancy;
1352-
}
13531341
}
13541342

13551343
unsigned
@@ -1579,9 +1567,6 @@ bool GCNSchedStage::mayCauseSpilling(unsigned WavesAfter) {
15791567
}
15801568

15811569
void GCNSchedStage::revertScheduling() {
1582-
DAG.RegionsWithMinOcc[RegionIdx] =
1583-
PressureBefore.getOccupancy(ST, DAG.MFI.getDynamicVGPRBlockSize()) ==
1584-
DAG.MinOccupancy;
15851570
LLVM_DEBUG(dbgs() << "Attempting to revert scheduling.\n");
15861571
DAG.RegionEnd = DAG.RegionBegin;
15871572
int SkippedDebugInstr = 0;

llvm/lib/Target/AMDGPU/GCNSchedStrategy.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,6 @@ class GCNScheduleDAGMILive final : public ScheduleDAGMILive {
250250
// limit. Register pressure in these regions usually will result in spilling.
251251
BitVector RegionsWithExcessRP;
252252

253-
// Regions that has the same occupancy as the latest MinOccupancy
254-
BitVector RegionsWithMinOcc;
255-
256253
// Regions that have IGLP instructions (SCHED_GROUP_BARRIER or IGLP_OPT).
257254
BitVector RegionsWithIGLPInstrs;
258255

0 commit comments

Comments
 (0)