Skip to content

[MISched] Add a hook to override PostRA scheduling policy #115455

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 12, 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
10 changes: 10 additions & 0 deletions llvm/include/llvm/CodeGen/TargetSubtargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ class TargetSubtargetInfo : public MCSubtargetInfo {
virtual void overrideSchedPolicy(MachineSchedPolicy &Policy,
unsigned NumRegionInstrs) const {}

/// Override generic post-ra scheduling policy within a region.
///
/// This is a convenient way for targets that don't provide any custom
/// scheduling heuristics (no custom MachineSchedStrategy) to make
/// changes to the generic post-ra scheduling policy.
/// Note that some options like tracking register pressure won't take effect
/// in post-ra scheduling.
virtual void overridePostRASchedPolicy(MachineSchedPolicy &Policy,
unsigned NumRegionInstrs) const {}

// Perform target-specific adjustments to the latency of a schedule
// dependency.
// If a pair of operands is associated with the schedule dependency, DefOpIdx
Expand Down
31 changes: 22 additions & 9 deletions llvm/lib/CodeGen/MachineScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3897,15 +3897,28 @@ void PostGenericScheduler::initialize(ScheduleDAGMI *Dag) {
void PostGenericScheduler::initPolicy(MachineBasicBlock::iterator Begin,
MachineBasicBlock::iterator End,
unsigned NumRegionInstrs) {
if (PostRADirection == MISchedPostRASched::TopDown) {
RegionPolicy.OnlyTopDown = true;
RegionPolicy.OnlyBottomUp = false;
} else if (PostRADirection == MISchedPostRASched::BottomUp) {
RegionPolicy.OnlyTopDown = false;
RegionPolicy.OnlyBottomUp = true;
} else if (PostRADirection == MISchedPostRASched::Bidirectional) {
RegionPolicy.OnlyBottomUp = false;
RegionPolicy.OnlyTopDown = false;
const MachineFunction &MF = *Begin->getMF();

// Default to top-down because it was implemented first and existing targets
// expect that behavior by default.
RegionPolicy.OnlyTopDown = true;
RegionPolicy.OnlyBottomUp = false;

// Allow the subtarget to override default policy.
MF.getSubtarget().overridePostRASchedPolicy(RegionPolicy, NumRegionInstrs);

// After subtarget overrides, apply command line options.
if (PostRADirection.getNumOccurrences() > 0) {
if (PostRADirection == MISchedPostRASched::TopDown) {
RegionPolicy.OnlyTopDown = true;
RegionPolicy.OnlyBottomUp = false;
} else if (PostRADirection == MISchedPostRASched::BottomUp) {
RegionPolicy.OnlyTopDown = false;
RegionPolicy.OnlyBottomUp = true;
} else if (PostRADirection == MISchedPostRASched::Bidirectional) {
RegionPolicy.OnlyBottomUp = false;
RegionPolicy.OnlyTopDown = false;
}
}
}

Expand Down
Loading