[llvm] [MachineScheduler] Add option to skip large regions with high pressure (PR #178422)
Nathan Corbyn via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 28 05:50:29 PST 2026
https://github.com/cofibrant created https://github.com/llvm/llvm-project/pull/178422
None
>From 662f7d4de4d20c43555b7ed6994a31c05ef27482 Mon Sep 17 00:00:00 2001
From: Nathan Corbyn <n_corbyn at apple.com>
Date: Wed, 28 Jan 2026 13:42:34 +0000
Subject: [PATCH] [MachineScheduler] Add option to skip large regions with high
pressure
---
llvm/include/llvm/CodeGen/MachineScheduler.h | 5 +++++
llvm/lib/CodeGen/MachineScheduler.cpp | 22 ++++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/llvm/include/llvm/CodeGen/MachineScheduler.h b/llvm/include/llvm/CodeGen/MachineScheduler.h
index 33036030679e5..2d60c2faf18aa 100644
--- a/llvm/include/llvm/CodeGen/MachineScheduler.h
+++ b/llvm/include/llvm/CodeGen/MachineScheduler.h
@@ -218,6 +218,11 @@ struct MachineSchedPolicy {
// Compute DFSResult for use in scheduling heuristics.
bool ComputeDFSResult = false;
+ // Skip scheduling for large regions with critical register pressure.
+ // When a region has more instructions than this threshold and register
+ // pressure exceeds limits, scheduling is skipped. 0 disables this feature.
+ unsigned LargeRegionSkipThreshold = 0;
+
MachineSchedPolicy() = default;
};
diff --git a/llvm/lib/CodeGen/MachineScheduler.cpp b/llvm/lib/CodeGen/MachineScheduler.cpp
index 05df5ea59d7a3..cb363c8a7c0ee 100644
--- a/llvm/lib/CodeGen/MachineScheduler.cpp
+++ b/llvm/lib/CodeGen/MachineScheduler.cpp
@@ -268,6 +268,12 @@ static cl::opt<unsigned>
cl::desc("The threshold for fast cluster"),
cl::init(1000));
+static cl::opt<unsigned> LargeRegionSkipThreshold(
+ "misched-large-region-skip-threshold", cl::Hidden,
+ cl::desc("Skip scheduling regions with instruction count exceeding this "
+ "threshold when register pressure is critical. 0 disables."),
+ cl::init(0));
+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
static cl::opt<bool> MISchedDumpScheduleTrace(
"misched-dump-schedule-trace", cl::Hidden, cl::init(false),
@@ -1694,6 +1700,18 @@ void ScheduleDAGMILive::schedule() {
LLVM_DEBUG(SchedImpl->dumpPolicy());
buildDAGWithRegPressure();
+ // Skip scheduling for large regions with critical register pressure that
+ // exceed the large region skip threshold.
+ unsigned SkipThreshold = SchedImpl->getPolicy().LargeRegionSkipThreshold;
+ if (SkipThreshold && NumRegionInstrs > SkipThreshold &&
+ !RegionCriticalPSets.empty()) {
+ LLVM_DEBUG(dbgs() << "Skipping scheduling for region with "
+ << NumRegionInstrs << " instructions and "
+ << RegionCriticalPSets.size()
+ << " critical pressure sets\n");
+ return;
+ }
+
postProcessDAG();
SmallVector<SUnit*, 8> TopRoots, BotRoots;
@@ -3716,6 +3734,10 @@ void GenericScheduler::initPolicy(MachineBasicBlock::iterator Begin,
RegionPolicy.OnlyTopDown = false;
}
+ // Apply command-line override for large region skip threshold.
+ if (LargeRegionSkipThreshold.getNumOccurrences())
+ RegionPolicy.LargeRegionSkipThreshold = LargeRegionSkipThreshold;
+
BotIdx = NumRegionInstrs - 1;
this->NumRegionInstrs = NumRegionInstrs;
}
More information about the llvm-commits
mailing list