[llvm] 2893570 - [RISCV] Don't emit save-restore call if function is a interrupt handler
Jim Lin via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 15 21:56:55 PDT 2021
Author: Jim Lin
Date: 2021-04-16T12:54:47+08:00
New Revision: 2893570e86dbb6b9b6b7f7779d9988ff6a686fe1
URL: https://github.com/llvm/llvm-project/commit/2893570e86dbb6b9b6b7f7779d9988ff6a686fe1
DIFF: https://github.com/llvm/llvm-project/commit/2893570e86dbb6b9b6b7f7779d9988ff6a686fe1.diff
LOG: [RISCV] Don't emit save-restore call if function is a interrupt handler
It has to save all caller-saved registers before a call in the handler.
So don't emit a call that save/restore registers.
Reviewed By: simoncook, luismarques, asb
Differential Revision: https://reviews.llvm.org/D100532
Added:
Modified:
llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
llvm/test/CodeGen/RISCV/saverestore.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h b/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
index b46bff8843b8b..b5609e9a3890d 100644
--- a/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
+++ b/llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
@@ -60,9 +60,10 @@ class RISCVMachineFunctionInfo : public MachineFunctionInfo {
bool useSaveRestoreLibCalls(const MachineFunction &MF) const {
// We cannot use fixed locations for the callee saved spill slots if the
- // function uses a varargs save area.
+ // function uses a varargs save area, or is an interrupt handler.
return MF.getSubtarget<RISCVSubtarget>().enableSaveRestore() &&
- VarArgsSaveSize == 0 && !MF.getFrameInfo().hasTailCall();
+ VarArgsSaveSize == 0 && !MF.getFrameInfo().hasTailCall() &&
+ !MF.getFunction().hasFnAttribute("interrupt");
}
uint64_t getRVVStackSize() const { return RVVStackSize; }
diff --git a/llvm/test/CodeGen/RISCV/saverestore.ll b/llvm/test/CodeGen/RISCV/saverestore.ll
index ef1b2a52afa91..bb6f0e0605b67 100644
--- a/llvm/test/CodeGen/RISCV/saverestore.ll
+++ b/llvm/test/CodeGen/RISCV/saverestore.ll
@@ -297,3 +297,34 @@ define void @alloca(i32 %n) nounwind {
call void @llvm.stackrestore(i8* %sp)
ret void
}
+
+; Check that functions with interrupt attribute do not use save/restore code
+
+declare i32 @foo(...)
+define void @interrupt() nounwind "interrupt"="user" {
+; RV32I-LABEL: interrupt:
+; RV32I-NOT: call t0, __riscv_save
+; RV32I-NOT: tail __riscv_restore
+;
+; RV64I-LABEL: interrupt:
+; RV64I-NOT: call t0, __riscv_save
+; RV64I-NOT: tail __riscv_restore
+;
+; RV32I-SR-LABEL: interrupt:
+; RV32I-SR-NOT: call t0, __riscv_save
+; RV32I-SR-NOT: tail __riscv_restore
+;
+; RV64I-SR-LABEL: interrupt:
+; RV64I-SR-NOT: call t0, __riscv_save
+; RV64I-SR-NOT: tail __riscv_restore
+;
+; RV32I-FP-SR-LABEL: interrupt:
+; RV32I-FP-SR-NOT: call t0, __riscv_save
+; RV32I-FP-SR-NOT: tail __riscv_restore
+;
+; RV64I-FP-SR-LABEL: interrupt:
+; RV64I-FP-SR-NOT: call t0, __riscv_save
+; RV64I-FP-SR-NOT: tail __riscv_restore
+ %call = call i32 bitcast (i32 (...)* @foo to i32 ()*)()
+ ret void
+}
More information about the llvm-commits
mailing list