Skip to content

Commit e15709c

Browse files
arch: riscv: Add -msave-restore option to reduce code footprint
Add `-msave-restore` option to reduce the code footprint of function prologue and epilogue. Signed-off-by: Andy Lin <andylinpersonal@gmail.com>
1 parent 81c77d5 commit e15709c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

‎arch/riscv/Kconfig‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ config FLOAT_HARD
1919
This option enables the hard-float calling convention.
2020
Adds eight floating-point argument registers.
2121

22+
config RISCV_USE_MSAVE_RESTORE
23+
bool "Compile with -msave-restore to reduce some code footprint"
24+
help
25+
The `-msave-restore` option enables the compiler to emit calls to library
26+
routines `__riscv_save_X` and `__riscv_restore_X` for preserving the
27+
callee-saved registers instead of inlining them in every function. This
28+
can reduce code size in some large functions. However, it introduces extra
29+
branching overhead, which may impact the performance in hot paths.
30+
31+
If supported by your SoC, the `Zcmp` ISA extension should be preferred.
32+
2233
choice RISCV_GP_PURPOSE
2334
prompt "Purpose of the global pointer (GP) register"
2435
default RISCV_GP if RISCV_SOC_HAS_GP_RELATIVE_ADDRESSING

‎cmake/compiler/gcc/target_riscv.cmake‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ if(NOT CONFIG_RISCV_ISA_EXT_M AND
136136
string(APPEND riscv_march "_zmmul")
137137
endif()
138138

139+
if(CONFIG_RISCV_USE_MSAVE_RESTORE)
140+
list(APPEND RISCV_C_FLAGS -msave-restore)
141+
endif()
142+
139143
list(APPEND RISCV_C_FLAGS
140144
-mabi=${riscv_mabi}
141145
-march=${riscv_march}

0 commit comments

Comments
 (0)