Skip to content

Commit

Permalink
[MachinePipeliner] Skip reserved registers when computing register pr…
Browse files Browse the repository at this point in the history
…essure (#120694)

We used to skip fixed registers, but fixed registers are not enough
because there are some runtime unusable registers like registers
reserved by `-ffixed-xxx` options.

Here we change to use reserved registers so that the estimated
pressure is more accurate.
  • Loading branch information
wangpc-pp authored Dec 20, 2024
1 parent 2fa2c21 commit d66f653
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions llvm/lib/CodeGen/MachinePipeliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,9 +1283,9 @@ class HighRegisterPressureDetector {
}
}

// Return true if Reg is fixed one, for example, stack pointer
bool isFixedRegister(Register Reg) const {
return Reg.isPhysical() && TRI->isFixedRegister(MF, Reg.asMCReg());
// Return true if Reg is reserved one, for example, stack pointer
bool isReservedRegister(Register Reg) const {
return Reg.isPhysical() && MRI.isReserved(Reg.asMCReg());
}

bool isDefinedInThisLoop(Register Reg) const {
Expand All @@ -1311,7 +1311,7 @@ class HighRegisterPressureDetector {
// because it's used only at the first iteration.
if (MI.isPHI() && Reg != getLoopPhiReg(MI, OrigMBB))
continue;
if (isFixedRegister(Reg))
if (isReservedRegister(Reg))
continue;
if (isDefinedInThisLoop(Reg))
continue;
Expand Down Expand Up @@ -1423,7 +1423,7 @@ class HighRegisterPressureDetector {

const auto InsertReg = [this, &CurSetPressure](RegSetTy &RegSet,
Register Reg) {
if (!Reg.isValid() || isFixedRegister(Reg))
if (!Reg.isValid() || isReservedRegister(Reg))
return;

bool Inserted = RegSet.insert(Reg).second;
Expand All @@ -1437,7 +1437,7 @@ class HighRegisterPressureDetector {

const auto EraseReg = [this, &CurSetPressure](RegSetTy &RegSet,
Register Reg) {
if (!Reg.isValid() || isFixedRegister(Reg))
if (!Reg.isValid() || isReservedRegister(Reg))
return;

// live-in register
Expand Down

0 comments on commit d66f653

Please sign in to comment.