Skip to content

Commit 0f80bdf

Browse files
Implement getIPRACSRegs hook for riscv
This patch implements the getIPRACSRegs hook for riscv, similar to how it's done for x86 in 14b567d. Differently from the x86 hook, in this patch we only save ra (x1) and not the frame pointer. I'm still working on a test case that shows the need to save the fp. The fixed test case was extracted from the gcc torture suite, but the same issue is found in SPEC's xz.
1 parent d156b85 commit 0f80bdf

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

llvm/lib/Target/RISCV/RISCVCallingConv.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def CSR_ILP32D_LP64D_V
4242
// Needed for implementation of RISCVRegisterInfo::getNoPreservedMask()
4343
def CSR_NoRegs : CalleeSavedRegs<(add)>;
4444

45+
def CSR_IPRA : CalleeSavedRegs<(add X1)>;
46+
4547
// Interrupt handler needs to save/restore all registers that are used,
4648
// both Caller and Callee saved registers.
4749
def CSR_Interrupt : CalleeSavedRegs<(add X1, (sequence "X%u", 5, 31))>;

llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ RISCVRegisterInfo::RISCVRegisterInfo(unsigned HwMode)
5555
: RISCVGenRegisterInfo(RISCV::X1, /*DwarfFlavour*/0, /*EHFlavor*/0,
5656
/*PC*/0, HwMode) {}
5757

58+
const MCPhysReg *
59+
RISCVRegisterInfo::getIPRACSRegs(const MachineFunction *MF) const {
60+
return CSR_IPRA_SaveList;
61+
}
62+
5863
const MCPhysReg *
5964
RISCVRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
6065
auto &Subtarget = MF->getSubtarget<RISCVSubtarget>();

llvm/lib/Target/RISCV/RISCVRegisterInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ struct RISCVRegisterInfo : public RISCVGenRegisterInfo {
6262

6363
const MCPhysReg *getCalleeSavedRegs(const MachineFunction *MF) const override;
6464

65+
const MCPhysReg *getIPRACSRegs(const MachineFunction *MF) const override;
66+
6567
BitVector getReservedRegs(const MachineFunction &MF) const override;
6668
bool isAsmClobberable(const MachineFunction &MF,
6769
MCRegister PhysReg) const override;

0 commit comments

Comments
 (0)