Skip to content

Commit ee1608d

Browse files
authored
[CodeGen][MISched] Set DumpDirection after initPolicy (#115112)
Previously we set the dump direction according to command line options, but we may override the scheduling direction in `initPolicy` and this results in mismatch between dump and actual policy. Here we simply set the dump direction after initializing the policy.
1 parent 8440ced commit ee1608d

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

llvm/include/llvm/CodeGen/MachineScheduler.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ class MachineSchedStrategy {
219219
MachineBasicBlock::iterator End,
220220
unsigned NumRegionInstrs) {}
221221

222+
virtual MachineSchedPolicy getPolicy() const { return {}; }
222223
virtual void dumpPolicy() const {}
223224

224225
/// Check if pressure tracking is needed before building the DAG and
@@ -1167,13 +1168,17 @@ class GenericSchedulerBase : public MachineSchedStrategy {
11671168
const TargetSchedModel *SchedModel = nullptr;
11681169
const TargetRegisterInfo *TRI = nullptr;
11691170

1171+
MachineSchedPolicy RegionPolicy;
1172+
11701173
SchedRemainder Rem;
11711174

11721175
GenericSchedulerBase(const MachineSchedContext *C) : Context(C) {}
11731176

11741177
void setPolicy(CandPolicy &Policy, bool IsPostRA, SchedBoundary &CurrZone,
11751178
SchedBoundary *OtherZone);
11761179

1180+
MachineSchedPolicy getPolicy() const override { return RegionPolicy; }
1181+
11771182
#ifndef NDEBUG
11781183
void traceCandidate(const SchedCandidate &Cand);
11791184
#endif
@@ -1254,8 +1259,6 @@ class GenericScheduler : public GenericSchedulerBase {
12541259
protected:
12551260
ScheduleDAGMILive *DAG = nullptr;
12561261

1257-
MachineSchedPolicy RegionPolicy;
1258-
12591262
// State of the top and bottom scheduled instruction boundaries.
12601263
SchedBoundary Top;
12611264
SchedBoundary Bot;
@@ -1294,7 +1297,6 @@ class PostGenericScheduler : public GenericSchedulerBase {
12941297
ScheduleDAGMI *DAG = nullptr;
12951298
SchedBoundary Top;
12961299
SchedBoundary Bot;
1297-
MachineSchedPolicy RegionPolicy;
12981300

12991301
/// Candidate last picked from Top boundary.
13001302
SchedCandidate TopCand;

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -460,14 +460,6 @@ bool MachineScheduler::runOnMachineFunction(MachineFunction &mf) {
460460
// Instantiate the selected scheduler for this target, function, and
461461
// optimization level.
462462
std::unique_ptr<ScheduleDAGInstrs> Scheduler(createMachineScheduler());
463-
ScheduleDAGMI::DumpDirection D;
464-
if (ForceTopDown)
465-
D = ScheduleDAGMI::DumpDirection::TopDown;
466-
else if (ForceBottomUp)
467-
D = ScheduleDAGMI::DumpDirection::BottomUp;
468-
else
469-
D = ScheduleDAGMI::DumpDirection::Bidirectional;
470-
Scheduler->setDumpDirection(D);
471463
scheduleRegions(*Scheduler, false);
472464

473465
LLVM_DEBUG(LIS->dump());
@@ -501,14 +493,6 @@ bool PostMachineScheduler::runOnMachineFunction(MachineFunction &mf) {
501493
// Instantiate the selected scheduler for this target, function, and
502494
// optimization level.
503495
std::unique_ptr<ScheduleDAGInstrs> Scheduler(createPostMachineScheduler());
504-
ScheduleDAGMI::DumpDirection D;
505-
if (PostRADirection == MISchedPostRASched::TopDown)
506-
D = ScheduleDAGMI::DumpDirection::TopDown;
507-
else if (PostRADirection == MISchedPostRASched::BottomUp)
508-
D = ScheduleDAGMI::DumpDirection::BottomUp;
509-
else
510-
D = ScheduleDAGMI::DumpDirection::Bidirectional;
511-
Scheduler->setDumpDirection(D);
512496
scheduleRegions(*Scheduler, true);
513497

514498
if (VerifyScheduling)
@@ -796,6 +780,16 @@ void ScheduleDAGMI::enterRegion(MachineBasicBlock *bb,
796780
ScheduleDAGInstrs::enterRegion(bb, begin, end, regioninstrs);
797781

798782
SchedImpl->initPolicy(begin, end, regioninstrs);
783+
784+
// Set dump direction after initializing sched policy.
785+
ScheduleDAGMI::DumpDirection D;
786+
if (SchedImpl->getPolicy().OnlyTopDown)
787+
D = ScheduleDAGMI::DumpDirection::TopDown;
788+
else if (SchedImpl->getPolicy().OnlyBottomUp)
789+
D = ScheduleDAGMI::DumpDirection::BottomUp;
790+
else
791+
D = ScheduleDAGMI::DumpDirection::Bidirectional;
792+
setDumpDirection(D);
799793
}
800794

801795
/// This is normally called from the main scheduler loop but may also be invoked

0 commit comments

Comments
 (0)