Skip to content

Commit f0a6816

Browse files
committed
[RISCV] Remove AllPopRegs array from RISCVFrameLowering.cpp. NFC
The same registers are listed in the same order in FixedCSRFIMap.
1 parent e5a277b commit f0a6816

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

llvm/lib/Target/RISCV/RISCVFrameLowering.cpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,16 @@ RISCVFrameLowering::RISCVFrameLowering(const RISCVSubtarget &STI)
4242
/*TransientStackAlignment=*/getABIStackAlignment(STI.getTargetABI())),
4343
STI(STI) {}
4444

45-
static const MCPhysReg AllPopRegs[] = {
46-
RISCV::X1, RISCV::X8, RISCV::X9, RISCV::X18, RISCV::X19,
47-
RISCV::X20, RISCV::X21, RISCV::X22, RISCV::X23, RISCV::X24,
48-
RISCV::X25, RISCV::X26, RISCV::X27};
45+
// Offsets which need to be scale by XLen representing locations of CSRs which
46+
// are given a fixed location by save/restore libcalls or Zcmp Push/Pop.
47+
static const std::pair<MCPhysReg, int8_t> FixedCSRFIMap[] = {
48+
{/*ra*/ RISCV::X1, -1}, {/*s0*/ RISCV::X8, -2},
49+
{/*s1*/ RISCV::X9, -3}, {/*s2*/ RISCV::X18, -4},
50+
{/*s3*/ RISCV::X19, -5}, {/*s4*/ RISCV::X20, -6},
51+
{/*s5*/ RISCV::X21, -7}, {/*s6*/ RISCV::X22, -8},
52+
{/*s7*/ RISCV::X23, -9}, {/*s8*/ RISCV::X24, -10},
53+
{/*s9*/ RISCV::X25, -11}, {/*s10*/ RISCV::X26, -12},
54+
{/*s11*/ RISCV::X27, -13}};
4955

5056
// For now we use x3, a.k.a gp, as pointer to shadow call stack.
5157
// User should not use x3 in their asm.
@@ -170,7 +176,7 @@ static int getLibCallID(const MachineFunction &MF,
170176

171177
Register MaxReg = RISCV::NoRegister;
172178
for (auto &CS : CSI)
173-
// RISCVRegisterInfo::hasReservedSpillSlot assigns negative frame indexes to
179+
// assignCalleeSavedSpillSlots assigns negative frame indexes to
174180
// registers which can be saved by libcall.
175181
if (CS.getFrameIdx() < 0)
176182
MaxReg = std::max(MaxReg.id(), CS.getReg().id());
@@ -291,7 +297,9 @@ static Register getMaxPushPopReg(const MachineFunction &MF,
291297
const std::vector<CalleeSavedInfo> &CSI) {
292298
Register MaxPushPopReg = RISCV::NoRegister;
293299
for (auto &CS : CSI) {
294-
if (llvm::is_contained(AllPopRegs, CS.getReg().id()))
300+
if (llvm::find_if(FixedCSRFIMap, [&](auto P) {
301+
return P.first == CS.getReg();
302+
}) != std::end(FixedCSRFIMap))
295303
MaxPushPopReg = std::max(MaxPushPopReg.id(), CS.getReg().id());
296304
}
297305
// if rlist is {rs, s0-s10}, then s11 will also be included
@@ -1385,17 +1393,6 @@ RISCVFrameLowering::getFirstSPAdjustAmount(const MachineFunction &MF) const {
13851393
return 0;
13861394
}
13871395

1388-
// Offsets which need to be scale by XLen representing locations of CSRs which
1389-
// are given a fixed location by save/restore libcalls or Zcmp Push/Pop.
1390-
static const std::pair<MCPhysReg, int8_t> FixedCSRFIMap[] = {
1391-
{/*ra*/ RISCV::X1, -1}, {/*s0*/ RISCV::X8, -2},
1392-
{/*s1*/ RISCV::X9, -3}, {/*s2*/ RISCV::X18, -4},
1393-
{/*s3*/ RISCV::X19, -5}, {/*s4*/ RISCV::X20, -6},
1394-
{/*s5*/ RISCV::X21, -7}, {/*s6*/ RISCV::X22, -8},
1395-
{/*s7*/ RISCV::X23, -9}, {/*s8*/ RISCV::X24, -10},
1396-
{/*s9*/ RISCV::X25, -11}, {/*s10*/ RISCV::X26, -12},
1397-
{/*s11*/ RISCV::X27, -13}};
1398-
13991396
bool RISCVFrameLowering::assignCalleeSavedSpillSlots(
14001397
MachineFunction &MF, const TargetRegisterInfo *TRI,
14011398
std::vector<CalleeSavedInfo> &CSI, unsigned &MinCSFrameIndex,
@@ -1498,7 +1495,7 @@ bool RISCVFrameLowering::spillCalleeSavedRegisters(
14981495
PushBuilder.addImm(0);
14991496

15001497
for (unsigned i = 0; i < PushedRegNum; i++)
1501-
PushBuilder.addUse(AllPopRegs[i], RegState::Implicit);
1498+
PushBuilder.addUse(FixedCSRFIMap[i].first, RegState::Implicit);
15021499
}
15031500
} else if (const char *SpillLibCall = getSpillLibCallName(*MF, CSI)) {
15041501
// Add spill libcall via non-callee-saved register t0.
@@ -1611,7 +1608,7 @@ bool RISCVFrameLowering::restoreCalleeSavedRegisters(
16111608
PopBuilder.addImm(0);
16121609

16131610
for (unsigned i = 0; i < RVFI->getRVPushRegs(); i++)
1614-
PopBuilder.addDef(AllPopRegs[i], RegState::ImplicitDefine);
1611+
PopBuilder.addDef(FixedCSRFIMap[i].first, RegState::ImplicitDefine);
16151612
}
16161613
} else {
16171614
const char *RestoreLibCall = getRestoreLibCallName(*MF, CSI);

0 commit comments

Comments
 (0)