From 2e4106b73da2bd2845f9676e79ea43d4d3540813 Mon Sep 17 00:00:00 2001 From: Ana Pazos Date: Thu, 26 Jul 2018 17:49:43 +0000 Subject: [RISCV] Add support for _interrupt attribute - Save/restore only registers that are used. This includes Callee saved registers and Caller saved registers (arguments and temporaries) for integer and FP registers. - If there is a call in the interrupt handler, save/restore all Caller saved registers (arguments and temporaries) and all FP registers. - Emit special return instructions depending on "interrupt" attribute type. Based on initial patch by Zhaoshi Zheng. Reviewers: asb Reviewed By: asb Subscribers: rkruppe, the_o, MartinMosbeck, brucehoult, rbar, johnrusso, simoncook, sabuasal, niosHD, kito-cheng, shiva0217, zzheng, edward-jones, mgrang, rogfer01, llvm-commits Differential Revision: https://reviews.llvm.org/D48411 llvm-svn: 338047 --- llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp') diff --git a/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp b/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp index f72730fb1a0..3ed1dec434c 100644 --- a/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp +++ b/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp @@ -33,6 +33,13 @@ RISCVRegisterInfo::RISCVRegisterInfo(unsigned HwMode) const MCPhysReg * RISCVRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const { + if (MF->getFunction().hasFnAttribute("interrupt")) { + if (MF->getSubtarget().hasStdExtD()) + return CSR_XLEN_F64_Interrupt_SaveList; + if (MF->getSubtarget().hasStdExtF()) + return CSR_XLEN_F32_Interrupt_SaveList; + return CSR_Interrupt_SaveList; + } return CSR_SaveList; } @@ -108,7 +115,14 @@ unsigned RISCVRegisterInfo::getFrameRegister(const MachineFunction &MF) const { } const uint32_t * -RISCVRegisterInfo::getCallPreservedMask(const MachineFunction & /*MF*/, +RISCVRegisterInfo::getCallPreservedMask(const MachineFunction & MF, CallingConv::ID /*CC*/) const { + if (MF.getFunction().hasFnAttribute("interrupt")) { + if (MF.getSubtarget().hasStdExtD()) + return CSR_XLEN_F64_Interrupt_RegMask; + if (MF.getSubtarget().hasStdExtF()) + return CSR_XLEN_F32_Interrupt_RegMask; + return CSR_Interrupt_RegMask; + } return CSR_RegMask; } -- cgit v1.2.3