Skip to content

Commit 8ea76a7

Browse files
author
Francis Visoiu Mistrih
committed
[RISCV] Remove CalleeSavedInfo for Zcmp/save-restore-libcalls registers
Registers that are pushed/popped by Zcmp or libcalls have pre-defined frame indices that are never allocated in MachineFrameInfo. They're being used throughout PEI, but the rest of codegen doesn't work that way and expects each frame index to be a valid index in MFI. This patch keeps it local to PEI and removes them from the CalleeSavedInfo list at the end of the pass. Before this pass, any MIR testing post-PEI is broken and asserts (see issue #79491).
1 parent 181eab2 commit 8ea76a7

File tree

3 files changed

+314
-0
lines changed

3 files changed

+314
-0
lines changed

llvm/lib/Target/RISCV/RISCVFrameLowering.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,30 @@ void RISCVFrameLowering::processFunctionBeforeFrameFinalized(
12521252
RVFI->setCalleeSavedStackSize(Size);
12531253
}
12541254

1255+
void RISCVFrameLowering::processFunctionBeforeFrameIndicesReplaced(
1256+
MachineFunction &MF, RegScavenger *RS) const {
1257+
// Remove CalleeSavedInfo for registers saved by Zcmp or save/restore
1258+
// libcalls.
1259+
MachineFrameInfo &MFI = MF.getFrameInfo();
1260+
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
1261+
const auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
1262+
if (!RVFI->isPushable(MF) && !RVFI->useSaveRestoreLibCalls(MF))
1263+
return;
1264+
const std::vector<CalleeSavedInfo> &CSIs = MFI.getCalleeSavedInfo();
1265+
std::vector<CalleeSavedInfo> NewCSIs;
1266+
for (const auto &CSI : CSIs) {
1267+
// Skip CSRs that have fake a frame index.
1268+
int ReservedFI = 0;
1269+
if (TRI->hasReservedSpillSlot(MF, CSI.getReg(), ReservedFI)) {
1270+
assert(CSI.getFrameIdx() == ReservedFI &&
1271+
"Reserved CSR spill slot frame index mismatch in CSI");
1272+
continue;
1273+
}
1274+
NewCSIs.push_back(CSI);
1275+
}
1276+
MFI.setCalleeSavedInfo(std::move(NewCSIs));
1277+
}
1278+
12551279
// Not preserve stack space within prologue for outgoing variables when the
12561280
// function contains variable size objects or there are vector objects accessed
12571281
// by the frame pointer.

llvm/lib/Target/RISCV/RISCVFrameLowering.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ class RISCVFrameLowering : public TargetFrameLowering {
3737
void processFunctionBeforeFrameFinalized(MachineFunction &MF,
3838
RegScavenger *RS) const override;
3939

40+
void
41+
processFunctionBeforeFrameIndicesReplaced(MachineFunction &MF,
42+
RegScavenger *RS) const override;
43+
4044
bool hasFP(const MachineFunction &MF) const override;
4145

4246
bool hasBP(const MachineFunction &MF) const;

0 commit comments

Comments
 (0)