Skip to content

Commit eb45946

Browse files
committed
[AMDGPU] Introduce IGLPPhase
Change-Id: I3690e082b98b57392075cac783b853f3fb48b0e5
1 parent 209fe1f commit eb45946

File tree

4 files changed

+29
-21
lines changed

4 files changed

+29
-21
lines changed

llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp

Lines changed: 14 additions & 14 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,11 +1118,11 @@ 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 &&
1125+
assert((Phase != IGLPPhase::Initial || (DSWCount == 0 && DSWWithPermCount == 0 &&
11261126
DSWWithSharedVMEMCount == 0)) &&
11271127
"DSWCounters should be zero in pre-RA scheduling!");
11281128
SmallVector<SUnit *, 6> DSWithPerms;
@@ -1133,7 +1133,7 @@ void MFMASmallGemmSingleWaveOpt::applyIGLPStrategy(
11331133
else if (TII->isDS(*I)) {
11341134
if (I->mayLoad())
11351135
++DSRCount;
1136-
else if (I->mayStore() && !IsReentry) {
1136+
else if (I->mayStore() && Phase == IGLPPhase::Initial) {
11371137
++DSWCount;
11381138
for (auto Pred : SU.Preds) {
11391139
if (Pred.getSUnit()->getInstr()->getOpcode() ==
@@ -1146,7 +1146,7 @@ void MFMASmallGemmSingleWaveOpt::applyIGLPStrategy(
11461146
}
11471147
}
11481148

1149-
if (!IsReentry) {
1149+
if (Phase == IGLPPhase::Initial) {
11501150
DSWWithPermCount = DSWithPerms.size();
11511151
auto I = DSWithPerms.begin();
11521152
auto E = DSWithPerms.end();
@@ -1414,10 +1414,10 @@ class IGroupLPDAGMutation : public ScheduleDAGMutation {
14141414
bool IsBottomUp = 1;
14151415

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

14191419
IGroupLPDAGMutation() = default;
1420-
IGroupLPDAGMutation(bool IsReentry) : IsReentry(IsReentry) {}
1420+
IGroupLPDAGMutation(IGLPPhase Phase) : Phase(Phase) {}
14211421
};
14221422

14231423
unsigned SchedGroup::NumSchedGroups = 0;
@@ -1717,21 +1717,21 @@ void IGroupLPDAGMutation::initIGLPOpt(SUnit &SU) {
17171717
auto S = createIGLPStrategy(StrategyID, DAG, TII);
17181718
if (S->shouldApplyStrategy(DAG)) {
17191719
IsBottomUp = S->IsBottomUp;
1720-
S->applyIGLPStrategy(SyncedInstrs, SyncedSchedGroups, IsReentry);
1720+
S->applyIGLPStrategy(SyncedInstrs, SyncedSchedGroups, Phase);
17211721
}
17221722
}
17231723

17241724
} // namespace
17251725

17261726
namespace llvm {
17271727

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

17371737
} // end namespace llvm

llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@
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 {
20+
Initial = 0u,
21+
PreRAReentry = 1u << 0,
22+
PostRA = 1u << 1
23+
};
24+
25+
std::unique_ptr<ScheduleDAGMutation> createIGroupLPDAGMutation(IGLPPhase Phase);
1826

1927
} // namespace llvm
2028

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: 3 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,7 @@ 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(IsInitialStage ? IGLPPhase::Initial : IGLPPhase::PreRAReentry));
859859
}
860860

861861
return true;
@@ -1569,7 +1569,7 @@ void GCNPostScheduleDAGMILive::schedule() {
15691569
if (HasIGLPInstrs) {
15701570
SavedMutations.clear();
15711571
SavedMutations.swap(Mutations);
1572-
addMutation(createIGroupLPDAGMutation(/*IsReentry=*/true));
1572+
addMutation(createIGroupLPDAGMutation(/*IsReentry=*/IGLPPhase::PostRA));
15731573
}
15741574

15751575
ScheduleDAGMI::schedule();

0 commit comments

Comments
 (0)