Skip to content

Commit

Permalink
[RISCV] Refine getMaxPushPopReg like getLibCallID. NFC.
Browse files Browse the repository at this point in the history
If save/restore libcall or Zcmp push/pop are enabled, callee-saved registers including ra would be
assigned a negative frame index (-1 for ra, -2 for s0, ..., -13 for s11) by RISCVRegisterInfo::hasReservedSpillSlot.

getLibCallID would find a callee-saved register that has max register id and with assigned negative frame index.
And use this max register to get which save/restore libcall should be selected.

In getMaxPushPopReg (for Zcmp push/pop, similar getLibCallID), it uses extra register class (PGPR) to
check the saved register is in ra, s0-s11 instead of checking the frame index is negative.

This patch just changes the checking for the saved register from `is contained in PGPR` to `has a negative frame index`.

Reviewed By: fakepaper56

Differential Revision: https://reviews.llvm.org/D156393
  • Loading branch information
tclin914 committed Aug 7, 2023
1 parent 4e84ec8 commit 5f94f3b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
7 changes: 4 additions & 3 deletions llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,10 @@ static Register getMaxPushPopReg(const MachineFunction &MF,
const std::vector<CalleeSavedInfo> &CSI) {
Register MaxPushPopReg = RISCV::NoRegister;
for (auto &CS : CSI) {
Register Reg = CS.getReg();
if (RISCV::PGPRRegClass.contains(Reg))
MaxPushPopReg = std::max(MaxPushPopReg.id(), Reg.id());
// RISCVRegisterInfo::hasReservedSpillSlot assigns negative frame indices to
// registers which can be saved by Zcmp Push.
if (CS.getFrameIdx() < 0)
MaxPushPopReg = std::max(MaxPushPopReg.id(), CS.getReg().id());
}
// if rlist is {rs, s0-s10}, then s11 will also be included
if (MaxPushPopReg == RISCV::X26)
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const uint32_t *RISCVRegisterInfo::getNoPreservedMask() const {
}

// Frame indexes representing locations of CSRs which are given a fixed location
// by save/restore libcalls.
// by save/restore libcalls or Zcmp Push/Pop.
static const std::pair<unsigned, int> FixedCSRFIMap[] = {
{/*ra*/ RISCV::X1, -1},
{/*s0*/ RISCV::X8, -2},
Expand Down
9 changes: 0 additions & 9 deletions llvm/lib/Target/RISCV/RISCVRegisterInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,6 @@ def SP : GPRRegisterClass<(add X2)>;
def SR07 : GPRRegisterClass<(add (sequence "X%u", 8, 9),
(sequence "X%u", 18, 23))>;

// Registers saveable by PUSH/POP instruction in Zcmp extension
def PGPR : RegisterClass<"RISCV", [XLenVT], 32, (add
(sequence "X%u", 8, 9),
(sequence "X%u", 18, 27),
X1
)> {
let RegInfos = XLenRI;
}

// Floating point registers
let RegAltNameIndices = [ABIRegAltName] in {
def F0_H : RISCVReg16<0, "f0", ["ft0"]>, DwarfRegNum<[32]>;
Expand Down

0 comments on commit 5f94f3b

Please sign in to comment.