Skip to content

Commit 5a1f239

Browse files
authored
[MISched] Add a hook to override PostRA scheduling policy (#115455)
PostRA scheduling supports different directions now, but we can only specify it via command line options. This patch adds a new hook `overridePostRASchedPolicy` for targets to override PostRA scheduling policy. Note that some options like tracking register pressure won't take effect in PostRA scheduling.
1 parent 4213bca commit 5a1f239

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

llvm/include/llvm/CodeGen/TargetSubtargetInfo.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,16 @@ class TargetSubtargetInfo : public MCSubtargetInfo {
232232
virtual void overrideSchedPolicy(MachineSchedPolicy &Policy,
233233
unsigned NumRegionInstrs) const {}
234234

235+
/// Override generic post-ra scheduling policy within a region.
236+
///
237+
/// This is a convenient way for targets that don't provide any custom
238+
/// scheduling heuristics (no custom MachineSchedStrategy) to make
239+
/// changes to the generic post-ra scheduling policy.
240+
/// Note that some options like tracking register pressure won't take effect
241+
/// in post-ra scheduling.
242+
virtual void overridePostRASchedPolicy(MachineSchedPolicy &Policy,
243+
unsigned NumRegionInstrs) const {}
244+
235245
// Perform target-specific adjustments to the latency of a schedule
236246
// dependency.
237247
// If a pair of operands is associated with the schedule dependency, DefOpIdx

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3897,15 +3897,28 @@ void PostGenericScheduler::initialize(ScheduleDAGMI *Dag) {
38973897
void PostGenericScheduler::initPolicy(MachineBasicBlock::iterator Begin,
38983898
MachineBasicBlock::iterator End,
38993899
unsigned NumRegionInstrs) {
3900-
if (PostRADirection == MISchedPostRASched::TopDown) {
3901-
RegionPolicy.OnlyTopDown = true;
3902-
RegionPolicy.OnlyBottomUp = false;
3903-
} else if (PostRADirection == MISchedPostRASched::BottomUp) {
3904-
RegionPolicy.OnlyTopDown = false;
3905-
RegionPolicy.OnlyBottomUp = true;
3906-
} else if (PostRADirection == MISchedPostRASched::Bidirectional) {
3907-
RegionPolicy.OnlyBottomUp = false;
3908-
RegionPolicy.OnlyTopDown = false;
3900+
const MachineFunction &MF = *Begin->getMF();
3901+
3902+
// Default to top-down because it was implemented first and existing targets
3903+
// expect that behavior by default.
3904+
RegionPolicy.OnlyTopDown = true;
3905+
RegionPolicy.OnlyBottomUp = false;
3906+
3907+
// Allow the subtarget to override default policy.
3908+
MF.getSubtarget().overridePostRASchedPolicy(RegionPolicy, NumRegionInstrs);
3909+
3910+
// After subtarget overrides, apply command line options.
3911+
if (PostRADirection.getNumOccurrences() > 0) {
3912+
if (PostRADirection == MISchedPostRASched::TopDown) {
3913+
RegionPolicy.OnlyTopDown = true;
3914+
RegionPolicy.OnlyBottomUp = false;
3915+
} else if (PostRADirection == MISchedPostRASched::BottomUp) {
3916+
RegionPolicy.OnlyTopDown = false;
3917+
RegionPolicy.OnlyBottomUp = true;
3918+
} else if (PostRADirection == MISchedPostRASched::Bidirectional) {
3919+
RegionPolicy.OnlyBottomUp = false;
3920+
RegionPolicy.OnlyTopDown = false;
3921+
}
39093922
}
39103923
}
39113924

0 commit comments

Comments
 (0)