[llvm] [MachinePipeliner] Fix incorrect use of getPressureSets. (PR #109179)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 18 12:02:45 PDT 2024
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/109179
The code was passing a physical register directly to getPressureSets which expects a register unit.
Fix this by looping over the register units and calling getPressureSets for each of them.
Found while trying to add a RegisterUnit class to stop storing register units in `Register`. 0 is a valid register unit but not a valid Register.
>From 872341f375200b7e606c528af4e9ab121b64ea66 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Wed, 18 Sep 2024 11:56:25 -0700
Subject: [PATCH] [MachinePipeliner] Fix incorrect use of getPressureSets.
The code was passing a physical register directly to getPressureSets
which expects a register unit.
Fix this by looping over the register units and calling getPressureSets
for each of them.
Found while trying to add a RegisterUnit class to stop storing
register units in Register. 0 is a valid register unit but not a valid
Register.
---
llvm/lib/CodeGen/MachinePipeliner.cpp | 29 ++++++++++++++++-----------
1 file changed, 17 insertions(+), 12 deletions(-)
diff --git a/llvm/lib/CodeGen/MachinePipeliner.cpp b/llvm/lib/CodeGen/MachinePipeliner.cpp
index 34eaf211c17a30..cd8333931bb5f9 100644
--- a/llvm/lib/CodeGen/MachinePipeliner.cpp
+++ b/llvm/lib/CodeGen/MachinePipeliner.cpp
@@ -1344,9 +1344,11 @@ class HighRegisterPressureDetector {
LLVM_DEBUG({
for (auto Reg : FixedRegs) {
dbgs() << printReg(Reg, TRI, 0, &MRI) << ": [";
- const int *Sets = TRI->getRegUnitPressureSets(Reg);
- for (; *Sets != -1; Sets++) {
- dbgs() << TRI->getRegPressureSetName(*Sets) << ", ";
+ for (MCRegUnit Unit : TRI->regunits(Reg)) {
+ const int *Sets = TRI->getRegUnitPressureSets(Unit);
+ for (; *Sets != -1; Sets++) {
+ dbgs() << TRI->getRegPressureSetName(*Sets) << ", ";
+ }
}
dbgs() << "]\n";
}
@@ -1355,15 +1357,18 @@ class HighRegisterPressureDetector {
for (auto Reg : FixedRegs) {
LLVM_DEBUG(dbgs() << "fixed register: " << printReg(Reg, TRI, 0, &MRI)
<< "\n");
- auto PSetIter = MRI.getPressureSets(Reg);
- unsigned Weight = PSetIter.getWeight();
- for (; PSetIter.isValid(); ++PSetIter) {
- unsigned &Limit = PressureSetLimit[*PSetIter];
- assert(Limit >= Weight &&
- "register pressure limit must be greater than or equal weight");
- Limit -= Weight;
- LLVM_DEBUG(dbgs() << "PSet=" << *PSetIter << " Limit=" << Limit
- << " (decreased by " << Weight << ")\n");
+ for (MCRegUnit Unit : TRI->regunits(Reg)) {
+ auto PSetIter = MRI.getPressureSets(Unit);
+ unsigned Weight = PSetIter.getWeight();
+ for (; PSetIter.isValid(); ++PSetIter) {
+ unsigned &Limit = PressureSetLimit[*PSetIter];
+ assert(
+ Limit >= Weight &&
+ "register pressure limit must be greater than or equal weight");
+ Limit -= Weight;
+ LLVM_DEBUG(dbgs() << "PSet=" << *PSetIter << " Limit=" << Limit
+ << " (decreased by " << Weight << ")\n");
+ }
}
}
}
More information about the llvm-commits
mailing list