[MachinePipeliner] Use RegisterClassInfo::getRegPressureSetLimit (#119827)

`RegisterClassInfo::getRegPressureSetLimit` is a wrapper of
`TargetRegisterInfo::getRegPressureSetLimit` with some logics to
adjust the limit by removing reserved registers.

It seems that we shouldn't use
`TargetRegisterInfo::getRegPressureSetLimit`
directly, just like the comment "This limit must be adjusted
dynamically for reserved registers" said.

Thus we should use `RegisterClassInfo::getRegPressureSetLimit` and
remove replicated code.

Separate from https://github.com/llvm/llvm-project/pull/118787
This commit is contained in:
Pengcheng Wang 2024-12-18 15:13:03 +08:00 committed by GitHub
parent d6e8ab1fa6
commit 1235a93fae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1326,48 +1326,7 @@ private:
// Calculate the upper limit of each pressure set
void computePressureSetLimit(const RegisterClassInfo &RCI) {
for (unsigned PSet = 0; PSet < PSetNum; PSet++)
PressureSetLimit[PSet] = TRI->getRegPressureSetLimit(MF, PSet);
// We assume fixed registers, such as stack pointer, are already in use.
// Therefore subtracting the weight of the fixed registers from the limit of
// each pressure set in advance.
SmallDenseSet<Register, 8> FixedRegs;
for (const TargetRegisterClass *TRC : TRI->regclasses()) {
for (const MCPhysReg Reg : *TRC)
if (isFixedRegister(Reg))
FixedRegs.insert(Reg);
}
LLVM_DEBUG({
for (auto Reg : FixedRegs) {
dbgs() << printReg(Reg, TRI, 0, &MRI) << ": [";
for (MCRegUnit Unit : TRI->regunits(Reg)) {
const int *Sets = TRI->getRegUnitPressureSets(Unit);
for (; *Sets != -1; Sets++) {
dbgs() << TRI->getRegPressureSetName(*Sets) << ", ";
}
}
dbgs() << "]\n";
}
});
for (auto Reg : FixedRegs) {
LLVM_DEBUG(dbgs() << "fixed register: " << printReg(Reg, TRI, 0, &MRI)
<< "\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");
}
}
}
PressureSetLimit[PSet] = RCI.getRegPressureSetLimit(PSet);
}
// There are two patterns of last-use.