Commit 0ce42fe1 by Andrew Waterman Committed by Jim Wilson

RISC-V: Add -mpreferred-stack-boundary option.

	2018-01-23  Andrew Waterman  <andrew@sifive.com>
	gcc/
	* config/riscv/riscv.c (riscv_stack_boundary): New.
	(riscv_option_override): Set riscv_stack_boundary.  Handle
	riscv_preferred_stack_boundary_arg.
	* config/riscv/riscv.h (MIN_STACK_BOUNDARY, ABI_STACK_BOUNDARY): New.
	(BIGGEST_ALIGNMENT): Set to STACK_BOUNDARY.
	(STACK_BOUNDARY): Set to riscv_stack_boundary.
	(RISCV_STACK_ALIGN): Use STACK_BOUNDARY.
	* config/riscv/riscv.opt (mpreferred-stack-boundary): New.
	* doc/invoke.tex (RISC-V Options): Add -mpreferred-stack-boundary.

Co-Authored-By: Jim Wilson <jimw@sifive.com>

From-SVN: r257005
parent 0889f168
2018-01-23 Andrew Waterman <andrew@sifive.com>
Jim Wilson <jimw@sifive.com>
* config/riscv/riscv.c (riscv_stack_boundary): New.
(riscv_option_override): Set riscv_stack_boundary. Handle
riscv_preferred_stack_boundary_arg.
* config/riscv/riscv.h (MIN_STACK_BOUNDARY, ABI_STACK_BOUNDARY): New.
(BIGGEST_ALIGNMENT): Set to STACK_BOUNDARY.
(STACK_BOUNDARY): Set to riscv_stack_boundary.
(RISCV_STACK_ALIGN): Use STACK_BOUNDARY.
* config/riscv/riscv.opt (mpreferred-stack-boundary): New.
* doc/invoke.tex (RISC-V Options): Add -mpreferred-stack-boundary.
2018-01-23 H.J. Lu <hongjiu.lu@intel.com>
PR target/83905
......
......@@ -222,6 +222,9 @@ struct riscv_cpu_info {
/* Whether unaligned accesses execute very slowly. */
bool riscv_slow_unaligned_access_p;
/* Stack alignment to assume/maintain. */
unsigned riscv_stack_boundary;
/* Which tuning parameters to use. */
static const struct riscv_tune_info *tune_info;
......@@ -4111,6 +4114,20 @@ riscv_option_override (void)
/* We do not yet support ILP32 on RV64. */
if (BITS_PER_WORD != POINTER_SIZE)
error ("ABI requires -march=rv%d", POINTER_SIZE);
/* Validate -mpreferred-stack-boundary= value. */
riscv_stack_boundary = ABI_STACK_BOUNDARY;
if (riscv_preferred_stack_boundary_arg)
{
int min = ctz_hwi (MIN_STACK_BOUNDARY / 8);
int max = 8;
if (!IN_RANGE (riscv_preferred_stack_boundary_arg, min, max))
error ("-mpreferred-stack-boundary=%d must be between %d and %d",
riscv_preferred_stack_boundary_arg, min, max);
riscv_stack_boundary = 8 << riscv_preferred_stack_boundary_arg;
}
}
/* Implement TARGET_CONDITIONAL_REGISTER_USAGE. */
......
......@@ -123,8 +123,14 @@ along with GCC; see the file COPYING3. If not see
/* Allocation boundary (in *bits*) for the code of a function. */
#define FUNCTION_BOUNDARY (TARGET_RVC ? 16 : 32)
/* The smallest supported stack boundary the calling convention supports. */
#define MIN_STACK_BOUNDARY (2 * BITS_PER_WORD)
/* The ABI stack alignment. */
#define ABI_STACK_BOUNDARY 128
/* There is no point aligning anything to a rounder boundary than this. */
#define BIGGEST_ALIGNMENT 128
#define BIGGEST_ALIGNMENT STACK_BOUNDARY
/* The user-level ISA permits unaligned accesses, but they are not required
of the privileged architecture. */
......@@ -472,8 +478,8 @@ enum reg_class
`crtl->outgoing_args_size'. */
#define OUTGOING_REG_PARM_STACK_SPACE(FNTYPE) 1
#define STACK_BOUNDARY 128
#define STACK_BOUNDARY riscv_stack_boundary
/* Symbolic macros for the registers used to return integer and floating
point values. */
......@@ -528,8 +534,9 @@ typedef struct {
#define EPILOGUE_USES(REGNO) ((REGNO) == RETURN_ADDR_REGNUM)
/* ABI requires 16-byte alignment, even on RV32. */
#define RISCV_STACK_ALIGN(LOC) (((LOC) + 15) & -16)
/* Align based on stack boundary, which might have been set by the user. */
#define RISCV_STACK_ALIGN(LOC) \
(((LOC) + ((STACK_BOUNDARY/8)-1)) & -(STACK_BOUNDARY/8))
/* EXIT_IGNORE_STACK should be nonzero if, when returning from a function,
the stack pointer does not matter. The value is tested only in
......
......@@ -33,6 +33,10 @@ mabi=
Target Report RejectNegative Joined Enum(abi_type) Var(riscv_abi) Init(ABI_ILP32)
Specify integer and floating-point calling convention.
mpreferred-stack-boundary=
Target RejectNegative Joined UInteger Var(riscv_preferred_stack_boundary_arg)
Attempt to keep stack aligned to this power of 2.
Enum
Name(abi_type) Type(enum riscv_abi_type)
Supported ABIs (for use with the -mabi= option):
......
......@@ -992,6 +992,7 @@ See RS/6000 and PowerPC Options.
-mdiv -mno-div @gol
-march=@var{ISA-string} @gol
-mtune=@var{processor-string} @gol
-mpreferred-stack-boundary=@var{num} @gol
-msmall-data-limit=@var{N-bytes} @gol
-msave-restore -mno-save-restore @gol
-mstrict-align -mno-strict-align @gol
......@@ -22072,6 +22073,16 @@ lower-case. Examples include @samp{rv64i}, @samp{rv32g}, and @samp{rv32imaf}.
Optimize the output for the given processor, specified by microarchitecture
name.
@item -mpreferred-stack-boundary=@var{num}
@opindex mpreferred-stack-boundary
Attempt to keep the stack boundary aligned to a 2 raised to @var{num}
byte boundary. If @option{-mpreferred-stack-boundary} is not specified,
the default is 4 (16 bytes or 128-bits).
@strong{Warning:} If you use this switch, then you must build all modules with
the same value, including any libraries. This includes the system libraries
and startup modules.
@item -msmall-data-limit=@var{n}
@opindex msmall-data-limit
Put global and static data smaller than @var{n} bytes into a special section
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment