Skip to content

Commit 1f4d9b3

Browse files
committed
[AMDGPU] Introduce IGLPPhase
Change-Id: I24170c286115863eebbf71973d8e86f4dea90c49
1 parent 99c5a66 commit 1f4d9b3

File tree

4 files changed

+30
-23
lines changed

4 files changed

+30
-23
lines changed

llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ class IGLPStrategy {
852852
virtual void applyIGLPStrategy(
853853
DenseMap<int, SUnitsToCandidateSGsMap> &SyncedInstrs,
854854
DenseMap<int, SmallVector<SchedGroup, 4>> &SyncedSchedGroups,
855-
bool IsReentry) = 0;
855+
IGLPPhase Phase) = 0;
856856

857857
// Returns true if this strategy should be applied to a ScheduleDAG.
858858
virtual bool shouldApplyStrategy(ScheduleDAGInstrs *DAG) = 0;
@@ -871,7 +871,7 @@ class MFMASmallGemmOpt final : public IGLPStrategy {
871871
void applyIGLPStrategy(
872872
DenseMap<int, SUnitsToCandidateSGsMap> &SyncedInstrs,
873873
DenseMap<int, SmallVector<SchedGroup, 4>> &SyncedSchedGroups,
874-
bool IsReentry) override;
874+
IGLPPhase Phase) override;
875875

876876
bool shouldApplyStrategy(ScheduleDAGInstrs *DAG) override { return true; }
877877

@@ -884,7 +884,7 @@ class MFMASmallGemmOpt final : public IGLPStrategy {
884884
void MFMASmallGemmOpt::applyIGLPStrategy(
885885
DenseMap<int, SUnitsToCandidateSGsMap> &SyncedInstrs,
886886
DenseMap<int, SmallVector<SchedGroup, 4>> &SyncedSchedGroups,
887-
bool IsReentry) {
887+
IGLPPhase Phase) {
888888
// Count the number of MFMA instructions.
889889
unsigned MFMACount = 0;
890890
for (const MachineInstr &I : *DAG)
@@ -1101,7 +1101,7 @@ class MFMASmallGemmSingleWaveOpt final : public IGLPStrategy {
11011101
void applyIGLPStrategy(
11021102
DenseMap<int, SUnitsToCandidateSGsMap> &SyncedInstrs,
11031103
DenseMap<int, SmallVector<SchedGroup, 4>> &SyncedSchedGroups,
1104-
bool IsReentry) override;
1104+
IGLPPhase Phase) override;
11051105

11061106
bool shouldApplyStrategy(ScheduleDAGInstrs *DAG) override { return true; }
11071107

@@ -1118,13 +1118,14 @@ static unsigned DSWWithSharedVMEMCount = 0;
11181118
void MFMASmallGemmSingleWaveOpt::applyIGLPStrategy(
11191119
DenseMap<int, SUnitsToCandidateSGsMap> &SyncedInstrs,
11201120
DenseMap<int, SmallVector<SchedGroup, 4>> &SyncedSchedGroups,
1121-
bool IsReentry) {
1121+
IGLPPhase Phase) {
11221122
unsigned MFMACount = 0;
11231123
unsigned DSRCount = 0;
11241124

1125-
assert((IsReentry || (DSWCount == 0 && DSWWithPermCount == 0 &&
1126-
DSWWithSharedVMEMCount == 0)) &&
1127-
"DSWCounters should be zero in pre-RA scheduling!");
1125+
assert(
1126+
(Phase != IGLPPhase::Initial || (DSWCount == 0 && DSWWithPermCount == 0 &&
1127+
DSWWithSharedVMEMCount == 0)) &&
1128+
"DSWCounters should be zero in pre-RA scheduling!");
11281129
SmallVector<SUnit *, 6> DSWithPerms;
11291130
for (auto &SU : DAG->SUnits) {
11301131
auto I = SU.getInstr();
@@ -1133,7 +1134,7 @@ void MFMASmallGemmSingleWaveOpt::applyIGLPStrategy(
11331134
else if (TII->isDS(*I)) {
11341135
if (I->mayLoad())
11351136
++DSRCount;
1136-
else if (I->mayStore() && !IsReentry) {
1137+
else if (I->mayStore() && Phase == IGLPPhase::Initial) {
11371138
++DSWCount;
11381139
for (auto Pred : SU.Preds) {
11391140
if (Pred.getSUnit()->getInstr()->getOpcode() ==
@@ -1146,7 +1147,7 @@ void MFMASmallGemmSingleWaveOpt::applyIGLPStrategy(
11461147
}
11471148
}
11481149

1149-
if (!IsReentry) {
1150+
if (Phase == IGLPPhase::Initial) {
11501151
DSWWithPermCount = DSWithPerms.size();
11511152
auto I = DSWithPerms.begin();
11521153
auto E = DSWithPerms.end();
@@ -1414,10 +1415,10 @@ class IGroupLPDAGMutation : public ScheduleDAGMutation {
14141415
bool IsBottomUp = 1;
14151416

14161417
// Whether or not this is a reentry into the IGroupLPDAGMutation.
1417-
bool IsReentry = false;
1418+
IGLPPhase Phase = IGLPPhase::Initial;
14181419

14191420
IGroupLPDAGMutation() = default;
1420-
IGroupLPDAGMutation(bool IsReentry) : IsReentry(IsReentry) {}
1421+
IGroupLPDAGMutation(IGLPPhase Phase) : Phase(Phase) {}
14211422
};
14221423

14231424
unsigned SchedGroup::NumSchedGroups = 0;
@@ -1717,21 +1718,22 @@ void IGroupLPDAGMutation::initIGLPOpt(SUnit &SU) {
17171718
auto S = createIGLPStrategy(StrategyID, DAG, TII);
17181719
if (S->shouldApplyStrategy(DAG)) {
17191720
IsBottomUp = S->IsBottomUp;
1720-
S->applyIGLPStrategy(SyncedInstrs, SyncedSchedGroups, IsReentry);
1721+
S->applyIGLPStrategy(SyncedInstrs, SyncedSchedGroups, Phase);
17211722
}
17221723
}
17231724

17241725
} // namespace
17251726

17261727
namespace llvm {
17271728

1728-
/// \p IsReentry specifes whether or not this is a reentry into the
1729+
/// \p Phase specifes whether or not this is a reentry into the
17291730
/// IGroupLPDAGMutation. Since there may be multiple scheduling passes on the
17301731
/// same scheduling region (e.g. pre and post-RA scheduling / multiple
17311732
/// scheduling "phases"), we can reenter this mutation framework more than once
17321733
/// for a given region.
1733-
std::unique_ptr<ScheduleDAGMutation> createIGroupLPDAGMutation(bool IsReentry) {
1734-
return std::make_unique<IGroupLPDAGMutation>(IsReentry);
1734+
std::unique_ptr<ScheduleDAGMutation>
1735+
createIGroupLPDAGMutation(IGLPPhase Phase) {
1736+
return std::make_unique<IGroupLPDAGMutation>(Phase);
17351737
}
17361738

17371739
} // end namespace llvm

llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414

1515
namespace llvm {
1616

17-
std::unique_ptr<ScheduleDAGMutation> createIGroupLPDAGMutation(bool IsReentry);
17+
// Components of the mask that determines which instruction types may be may be
18+
// classified into a SchedGroup.
19+
enum class IGLPPhase { Initial = 0u, PreRAReentry = 1u << 0, PostRA = 1u << 1 };
20+
21+
std::unique_ptr<ScheduleDAGMutation> createIGroupLPDAGMutation(IGLPPhase Phase);
1822

1923
} // namespace llvm
2024

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ createGCNMaxOccupancyMachineScheduler(MachineSchedContext *C) {
461461
DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
462462
if (ST.shouldClusterStores())
463463
DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
464-
DAG->addMutation(createIGroupLPDAGMutation(/*IsPostRA=*/false));
464+
DAG->addMutation(createIGroupLPDAGMutation(IGLPPhase::Initial));
465465
DAG->addMutation(createAMDGPUMacroFusionDAGMutation());
466466
DAG->addMutation(createAMDGPUExportClusteringDAGMutation());
467467
return DAG;
@@ -471,7 +471,7 @@ static ScheduleDAGInstrs *
471471
createGCNMaxILPMachineScheduler(MachineSchedContext *C) {
472472
ScheduleDAGMILive *DAG =
473473
new GCNScheduleDAGMILive(C, std::make_unique<GCNMaxILPSchedStrategy>(C));
474-
DAG->addMutation(createIGroupLPDAGMutation(/*IsPostRA=*/false));
474+
DAG->addMutation(createIGroupLPDAGMutation(IGLPPhase::Initial));
475475
return DAG;
476476
}
477477

@@ -934,7 +934,7 @@ class GCNPassConfig final : public AMDGPUPassConfig {
934934
if (ST.shouldClusterStores())
935935
DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
936936
DAG->addMutation(ST.createFillMFMAShadowMutation(DAG->TII));
937-
DAG->addMutation(createIGroupLPDAGMutation(/*IsPostRA=*/true));
937+
DAG->addMutation(createIGroupLPDAGMutation(IGLPPhase::PostRA));
938938
if (isPassEnabled(EnableVOPD, CodeGenOptLevel::Less))
939939
DAG->addMutation(createVOPDPairingMutation());
940940
return DAG;

llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ bool UnclusteredHighRPStage::initGCNSchedStage() {
713713
return false;
714714

715715
SavedMutations.swap(DAG.Mutations);
716-
DAG.addMutation(createIGroupLPDAGMutation(/*IsPostRA=*/false));
716+
DAG.addMutation(createIGroupLPDAGMutation(IGLPPhase::PreRAReentry));
717717

718718
InitialOccupancy = DAG.MinOccupancy;
719719
// Aggressivly try to reduce register pressure in the unclustered high RP
@@ -855,7 +855,8 @@ bool GCNSchedStage::initGCNRegion() {
855855
SavedMutations.swap(DAG.Mutations);
856856
bool IsInitialStage = StageID == GCNSchedStageID::OccInitialSchedule ||
857857
StageID == GCNSchedStageID::ILPInitialSchedule;
858-
DAG.addMutation(createIGroupLPDAGMutation(/*IsReentry=*/!IsInitialStage));
858+
DAG.addMutation(createIGroupLPDAGMutation(
859+
IsInitialStage ? IGLPPhase::Initial : IGLPPhase::PreRAReentry));
859860
}
860861

861862
return true;
@@ -1569,7 +1570,7 @@ void GCNPostScheduleDAGMILive::schedule() {
15691570
if (HasIGLPInstrs) {
15701571
SavedMutations.clear();
15711572
SavedMutations.swap(Mutations);
1572-
addMutation(createIGroupLPDAGMutation(/*IsReentry=*/true));
1573+
addMutation(createIGroupLPDAGMutation(/*IsReentry=*/IGLPPhase::PostRA));
15731574
}
15741575

15751576
ScheduleDAGMI::schedule();

0 commit comments

Comments
 (0)