Skip to content

[CodeGen][MISched] Set DumpDirection after initPolicy #115112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions llvm/include/llvm/CodeGen/MachineScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class MachineSchedStrategy {
MachineBasicBlock::iterator End,
unsigned NumRegionInstrs) {}

virtual MachineSchedPolicy getPolicy() const { return {}; }
virtual void dumpPolicy() const {}

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

MachineSchedPolicy RegionPolicy;

SchedRemainder Rem;

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

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

MachineSchedPolicy getPolicy() const override { return RegionPolicy; }

#ifndef NDEBUG
void traceCandidate(const SchedCandidate &Cand);
#endif
Expand Down Expand Up @@ -1254,8 +1259,6 @@ class GenericScheduler : public GenericSchedulerBase {
protected:
ScheduleDAGMILive *DAG = nullptr;

MachineSchedPolicy RegionPolicy;

// State of the top and bottom scheduled instruction boundaries.
SchedBoundary Top;
SchedBoundary Bot;
Expand Down Expand Up @@ -1294,7 +1297,6 @@ class PostGenericScheduler : public GenericSchedulerBase {
ScheduleDAGMI *DAG = nullptr;
SchedBoundary Top;
SchedBoundary Bot;
MachineSchedPolicy RegionPolicy;

/// Candidate last picked from Top boundary.
SchedCandidate TopCand;
Expand Down
26 changes: 10 additions & 16 deletions llvm/lib/CodeGen/MachineScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,6 @@ bool MachineScheduler::runOnMachineFunction(MachineFunction &mf) {
// Instantiate the selected scheduler for this target, function, and
// optimization level.
std::unique_ptr<ScheduleDAGInstrs> Scheduler(createMachineScheduler());
ScheduleDAGMI::DumpDirection D;
if (ForceTopDown)
D = ScheduleDAGMI::DumpDirection::TopDown;
else if (ForceBottomUp)
D = ScheduleDAGMI::DumpDirection::BottomUp;
else
D = ScheduleDAGMI::DumpDirection::Bidirectional;
Scheduler->setDumpDirection(D);
scheduleRegions(*Scheduler, false);

LLVM_DEBUG(LIS->dump());
Expand Down Expand Up @@ -501,14 +493,6 @@ bool PostMachineScheduler::runOnMachineFunction(MachineFunction &mf) {
// Instantiate the selected scheduler for this target, function, and
// optimization level.
std::unique_ptr<ScheduleDAGInstrs> Scheduler(createPostMachineScheduler());
ScheduleDAGMI::DumpDirection D;
if (PostRADirection == MISchedPostRASched::TopDown)
D = ScheduleDAGMI::DumpDirection::TopDown;
else if (PostRADirection == MISchedPostRASched::BottomUp)
D = ScheduleDAGMI::DumpDirection::BottomUp;
else
D = ScheduleDAGMI::DumpDirection::Bidirectional;
Scheduler->setDumpDirection(D);
scheduleRegions(*Scheduler, true);

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

SchedImpl->initPolicy(begin, end, regioninstrs);

// Set dump direction after initializing sched policy.
ScheduleDAGMI::DumpDirection D;
if (SchedImpl->getPolicy().OnlyTopDown)
D = ScheduleDAGMI::DumpDirection::TopDown;
else if (SchedImpl->getPolicy().OnlyBottomUp)
D = ScheduleDAGMI::DumpDirection::BottomUp;
else
D = ScheduleDAGMI::DumpDirection::Bidirectional;
setDumpDirection(D);
}

/// This is normally called from the main scheduler loop but may also be invoked
Expand Down
Loading