-
Notifications
You must be signed in to change notification settings - Fork 44
Description
Currently it (at least seems to me that) the stack frame layout used for __riscv_{save,restore}_N functions is the same for both GCC and LLVM:
- GCC: https://github.com/gcc-mirror/gcc/blob/master/libgcc/config/riscv/save-restore.S
- LLVM: https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/builtins/riscv/save.S
And it's compatible with the frame pointer convention defined over at psABI at https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc#frame-pointer-convention.
Is perhaps worthwhile to standardize the layout in which ra and s registers are saved on the stack somewhat? Like for example, how many bytes of stack are used for each N and the order for them. It would allow for frame pointers to be used with -msave-restore, and would allow for calculating the precise stack usage when using these routines.
Observation: For now, LLVM can use __riscv_save_N with addi s0, sp, ... for -msave-restore -fno-omit-frame-pointers, but GCC (as of 12.2.0) doesn't seem to know how to do that and emits longhand sequences for the saves and restores instead (See https://godbolt.org/z/6YYhxxzxx).