[PATCH] D100532: [RISCV] Don't emit save-restore call if function is a interrupt handler

Jim Lin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 15 21:57:07 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG2893570e86db: [RISCV] Don't emit save-restore call if function is a interrupt handler (authored by Jim).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100532/new/

https://reviews.llvm.org/D100532

Files:
  llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
  llvm/test/CodeGen/RISCV/saverestore.ll


Index: llvm/test/CodeGen/RISCV/saverestore.ll
===================================================================
--- llvm/test/CodeGen/RISCV/saverestore.ll
+++ llvm/test/CodeGen/RISCV/saverestore.ll
@@ -297,3 +297,34 @@
   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
+}
Index: llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
===================================================================
--- llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
+++ llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
@@ -60,9 +60,10 @@
 
   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; }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100532.337984.patch
Type: text/x-patch
Size: 2064 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210416/0de5aeb2/attachment.bin>


More information about the llvm-commits mailing list