From 26c95cae3937a421b5b9ac2af2fc0ad197bc6ed9 Mon Sep 17 00:00:00 2001 From: Wang Pengcheng Date: Thu, 24 Oct 2024 20:01:35 +0800 Subject: [PATCH 1/2] [CodeGen][MISched] Set DumpDirection after initPolicy 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. --- llvm/include/llvm/CodeGen/MachineScheduler.h | 7 ++++-- llvm/lib/CodeGen/MachineScheduler.cpp | 26 ++++++++------------ 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/llvm/include/llvm/CodeGen/MachineScheduler.h b/llvm/include/llvm/CodeGen/MachineScheduler.h index b15abf040058e..f82f8f9ccf664 100644 --- a/llvm/include/llvm/CodeGen/MachineScheduler.h +++ b/llvm/include/llvm/CodeGen/MachineScheduler.h @@ -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 @@ -1167,6 +1168,8 @@ class GenericSchedulerBase : public MachineSchedStrategy { const TargetSchedModel *SchedModel = nullptr; const TargetRegisterInfo *TRI = nullptr; + MachineSchedPolicy RegionPolicy; + SchedRemainder Rem; GenericSchedulerBase(const MachineSchedContext *C) : Context(C) {} @@ -1174,6 +1177,8 @@ class GenericSchedulerBase : public MachineSchedStrategy { void setPolicy(CandPolicy &Policy, bool IsPostRA, SchedBoundary &CurrZone, SchedBoundary *OtherZone); + MachineSchedPolicy getPolicy() const override { return RegionPolicy; } + #ifndef NDEBUG void traceCandidate(const SchedCandidate &Cand); #endif @@ -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; diff --git a/llvm/lib/CodeGen/MachineScheduler.cpp b/llvm/lib/CodeGen/MachineScheduler.cpp index 9b2862de22b69..757f49293993e 100644 --- a/llvm/lib/CodeGen/MachineScheduler.cpp +++ b/llvm/lib/CodeGen/MachineScheduler.cpp @@ -460,14 +460,6 @@ bool MachineScheduler::runOnMachineFunction(MachineFunction &mf) { // Instantiate the selected scheduler for this target, function, and // optimization level. std::unique_ptr 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()); @@ -501,14 +493,6 @@ bool PostMachineScheduler::runOnMachineFunction(MachineFunction &mf) { // Instantiate the selected scheduler for this target, function, and // optimization level. std::unique_ptr 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) @@ -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 From decf96ed177b508b89bc01c9931c8e089f1a1970 Mon Sep 17 00:00:00 2001 From: Wang Pengcheng Date: Wed, 6 Nov 2024 12:37:41 +0800 Subject: [PATCH 2/2] Remove RegionPolicy in PostGenericScheduler to fix test failure --- llvm/include/llvm/CodeGen/MachineScheduler.h | 1 - 1 file changed, 1 deletion(-) diff --git a/llvm/include/llvm/CodeGen/MachineScheduler.h b/llvm/include/llvm/CodeGen/MachineScheduler.h index f82f8f9ccf664..42d132efec2e7 100644 --- a/llvm/include/llvm/CodeGen/MachineScheduler.h +++ b/llvm/include/llvm/CodeGen/MachineScheduler.h @@ -1297,7 +1297,6 @@ class PostGenericScheduler : public GenericSchedulerBase { ScheduleDAGMI *DAG = nullptr; SchedBoundary Top; SchedBoundary Bot; - MachineSchedPolicy RegionPolicy; /// Candidate last picked from Top boundary. SchedCandidate TopCand;