On 4/21/23 04:07, Fei Gao wrote:
Currently in rv32e, stack allocation for GPR callee-saved registers is
always 12 bytes w/o save-restore. Actually, for the case without save-restore,
less stack memory can be reserved. This patch decouples stack allocation for
rv32e w/o save-restore and makes riscv_compute_frame_info more readable.
output of testcase rv32e_stack.c
before patch:
addi sp,sp,-16
sw ra,12(sp)
call getInt
sw a0,0(sp)
lw a0,0(sp)
call PrintInts
lw a5,0(sp)
mv a0,a5
lw ra,12(sp)
addi sp,sp,16
jr ra
after patch:
addi sp,sp,-8
sw ra,4(sp)
call getInt
sw a0,0(sp)
lw a0,0(sp)
call PrintInts
lw a5,0(sp)
mv a0,a5
lw ra,4(sp)
addi sp,sp,8
jr ra
gcc/ChangeLog:
* config/riscv/riscv.cc (riscv_forbid_save_libcall): helper function
for riscv_use_save_libcall.
(riscv_use_save_libcall): call riscv_forbid_save_libcall.
(riscv_compute_frame_info): restructure to decouple stack allocation
for rv32e w/o save-restore.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/rv32e_stack.c: New test.
---
gcc/config/riscv/riscv.cc | 57 ++++++++++++--------
gcc/testsuite/gcc.target/riscv/rv32e_stack.c | 14 +++++
2 files changed, 49 insertions(+), 22 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/riscv/rv32e_stack.c
diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 5d2550871c7..6ccdfe96fe7 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -4772,12 +4772,26 @@ riscv_save_reg_p (unsigned int regno)
return false;
}
+/* Determine whether to disable GPR save/restore routines. */
+static bool
+riscv_forbid_save_libcall (void)
I would suggest something like this for the function comment:
/* Return TRUE if a libcall to save/restore GPRs should be
avoided. FALSE otherwise. */
I would also change the name from "forbid" to "avoid".
With those changes I think this will be ready for the trunk. So repost
after those changes and I'll get it pushed into the trunk.
Thanks,
Jeff