Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

Commit ac43954

Browse files
aswatermanpalmer-dabbelt
authored andcommitted
Support -mpreferred-stack-boundary flag
This supports reducing the stack alignment to 8 bytes for RV32I.
1 parent c7048c4 commit ac43954

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

gcc/config/riscv/riscv.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ struct riscv_cpu_info {
219219
/* Whether unaligned accesses execute very slowly. */
220220
static bool riscv_slow_unaligned_access_p;
221221

222+
/* Stack alignment to assume/maintain. */
223+
unsigned riscv_stack_boundary;
224+
222225
/* Which tuning parameters to use. */
223226
static const struct riscv_tune_info *tune_info;
224227

@@ -3835,6 +3838,20 @@ riscv_option_override (void)
38353838
/* We do not yet support ILP32 on RV64. */
38363839
if (BITS_PER_WORD != POINTER_SIZE)
38373840
error ("ABI requires -march=rv%d", POINTER_SIZE);
3841+
3842+
/* Validate -mpreferred-stack-boundary= value. */
3843+
riscv_stack_boundary = ABI_STACK_BOUNDARY;
3844+
if (riscv_preferred_stack_boundary_arg)
3845+
{
3846+
int min = ctz_hwi (MIN_STACK_BOUNDARY / 8);
3847+
int max = 8;
3848+
3849+
if (!IN_RANGE (riscv_preferred_stack_boundary_arg, min, max))
3850+
error ("-mpreferred-stack-boundary=%d must be between %d and %d",
3851+
riscv_preferred_stack_boundary_arg, min, max);
3852+
3853+
riscv_stack_boundary = 8 << riscv_preferred_stack_boundary_arg;
3854+
}
38383855
}
38393856

38403857
/* Implement TARGET_CONDITIONAL_REGISTER_USAGE. */

gcc/config/riscv/riscv.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,14 @@ along with GCC; see the file COPYING3. If not see
123123
/* Allocation boundary (in *bits*) for the code of a function. */
124124
#define FUNCTION_BOUNDARY (TARGET_RVC ? 16 : 32)
125125

126+
/* The smallest supported stack boundary the calling convention supports. */
127+
#define MIN_STACK_BOUNDARY (TARGET_RVE ? BITS_PER_WORD : 2 * BITS_PER_WORD)
128+
129+
/* The ABI stack alignment. */
130+
#define ABI_STACK_BOUNDARY (TARGET_RVE ? BITS_PER_WORD : 128)
131+
126132
/* There is no point aligning anything to a rounder boundary than this. */
127-
#define BIGGEST_ALIGNMENT (TARGET_RVE ? 32 : 128)
133+
#define BIGGEST_ALIGNMENT STACK_BOUNDARY
128134

129135
/* The user-level ISA permits unaligned accesses, but they are not required
130136
of the privileged architecture. */
@@ -472,7 +478,7 @@ enum reg_class
472478
`crtl->outgoing_args_size'. */
473479
#define OUTGOING_REG_PARM_STACK_SPACE(FNTYPE) 1
474480

475-
#define STACK_BOUNDARY (TARGET_RVE ? 32 : 128)
481+
#define STACK_BOUNDARY riscv_stack_boundary
476482

477483
/* Symbolic macros for the registers used to return integer and floating
478484
point values. */
@@ -823,6 +829,9 @@ while (0)
823829

824830
#ifndef USED_FOR_TARGET
825831
extern const enum reg_class riscv_regno_to_class[];
832+
extern bool riscv_hard_regno_mode_ok[][FIRST_PSEUDO_REGISTER];
833+
extern bool riscv_slow_unaligned_access;
834+
extern unsigned riscv_stack_boundary;
826835
#endif
827836

828837
#define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL) \

gcc/config/riscv/riscv.opt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ mabi=
3333
Target Report RejectNegative Joined Enum(abi_type) Var(riscv_abi) Init(ABI_ILP32)
3434
Specify integer and floating-point calling convention.
3535

36+
mpreferred-stack-boundary=
37+
Target RejectNegative Joined UInteger Var(riscv_preferred_stack_boundary_arg)
38+
Attempt to keep stack aligned to this power of 2.
39+
3640
Enum
3741
Name(abi_type) Type(enum riscv_abi_type)
3842
Supported ABIs (for use with the -mabi= option):

0 commit comments

Comments
 (0)