aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineScheduler.cpp
diff options
context:
space:
mode:
authorPengcheng Wang <wangpengcheng.pp@bytedance.com>2024-11-12 18:14:57 +0800
committerGitHub <noreply@github.com>2024-11-12 18:14:57 +0800
commit5a1f239df55c25d49d6c193ef469606713fc74de (patch)
treedd8bd0be3c46137592ab699bbda14eb2b485fe93 /llvm/lib/CodeGen/MachineScheduler.cpp
parent4213bca8717dbf675558148b7d4186cd3980355d (diff)
downloadllvm-5a1f239df55c25d49d6c193ef469606713fc74de.zip
llvm-5a1f239df55c25d49d6c193ef469606713fc74de.tar.gz
llvm-5a1f239df55c25d49d6c193ef469606713fc74de.tar.bz2
[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.
Diffstat (limited to 'llvm/lib/CodeGen/MachineScheduler.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineScheduler.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/MachineScheduler.cpp b/llvm/lib/CodeGen/MachineScheduler.cpp
index 757f492..d65db91 100644
--- a/llvm/lib/CodeGen/MachineScheduler.cpp
+++ b/llvm/lib/CodeGen/MachineScheduler.cpp
@@ -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;
+ }
}
}