This patch adds a new hook that gives the preferred alignment for a static rtx...

TARGET_STATIC_RTX_ALIGNMENT

This patch adds a new hook that gives the preferred alignment for
a static rtx, so that we don't need to query the front end in
force_const_mem.

2017-10-26  Richard Sandiford  <richard.sandiford@linaro.org>

gcc/
	* target.def (static_rtx_alignment): New hook.
	* targhooks.h (default_static_rtx_alignment): Declare.
	* targhooks.c (default_static_rtx_alignment): New function.
	* doc/tm.texi.in (TARGET_STATIC_RTX_ALIGNMENT): New hook.
	* doc/tm.texi: Regenerate.
	* varasm.c (force_const_mem): Use targetm.static_rtx_alignment
	instead of targetm.constant_alignment.  Remove call to
	set_mem_attributes.
	* config/cris/cris.c (TARGET_STATIC_RTX_ALIGNMENT): Redefine.
	(cris_preferred_mininum_alignment): New function, split out from...
	(cris_constant_alignment): ...here.
	(cris_static_rtx_alignment): New function.
	* config/i386/i386.c (ix86_static_rtx_alignment): New function,
	split out from...
	(ix86_constant_alignment): ...here.
	(TARGET_STATIC_RTX_ALIGNMENT): Redefine.
	* config/mmix/mmix.c (TARGET_STATIC_RTX_ALIGNMENT): Redefine.
	(mmix_static_rtx_alignment): New function.
	* config/spu/spu.c (spu_static_rtx_alignment): New function.
	(TARGET_STATIC_RTX_ALIGNMENT): Redefine.

From-SVN: r254102
This commit is contained in:
Richard Sandiford 2017-10-26 11:28:25 +00:00 committed by Richard Sandiford
parent 4bc19a3b1a
commit f073de07ad
11 changed files with 118 additions and 15 deletions

View File

@ -1,3 +1,26 @@
2017-10-26 Richard Sandiford <richard.sandiford@linaro.org>
* target.def (static_rtx_alignment): New hook.
* targhooks.h (default_static_rtx_alignment): Declare.
* targhooks.c (default_static_rtx_alignment): New function.
* doc/tm.texi.in (TARGET_STATIC_RTX_ALIGNMENT): New hook.
* doc/tm.texi: Regenerate.
* varasm.c (force_const_mem): Use targetm.static_rtx_alignment
instead of targetm.constant_alignment. Remove call to
set_mem_attributes.
* config/cris/cris.c (TARGET_STATIC_RTX_ALIGNMENT): Redefine.
(cris_preferred_mininum_alignment): New function, split out from...
(cris_constant_alignment): ...here.
(cris_static_rtx_alignment): New function.
* config/i386/i386.c (ix86_static_rtx_alignment): New function,
split out from...
(ix86_constant_alignment): ...here.
(TARGET_STATIC_RTX_ALIGNMENT): Redefine.
* config/mmix/mmix.c (TARGET_STATIC_RTX_ALIGNMENT): Redefine.
(mmix_static_rtx_alignment): New function.
* config/spu/spu.c (spu_static_rtx_alignment): New function.
(TARGET_STATIC_RTX_ALIGNMENT): Redefine.
2017-10-26 Tamar Christina <tamar.christina@arm.com>
PR target/81800

View File

@ -165,6 +165,7 @@ static bool cris_function_value_regno_p (const unsigned int);
static void cris_file_end (void);
static unsigned int cris_hard_regno_nregs (unsigned int, machine_mode);
static bool cris_hard_regno_mode_ok (unsigned int, machine_mode);
static HOST_WIDE_INT cris_static_rtx_alignment (machine_mode);
static HOST_WIDE_INT cris_constant_alignment (const_tree, HOST_WIDE_INT);
/* This is the parsed result of the "-max-stack-stackframe=" option. If
@ -288,6 +289,8 @@ int cris_cpu_version = CRIS_DEFAULT_CPU_VERSION;
#undef TARGET_HARD_REGNO_MODE_OK
#define TARGET_HARD_REGNO_MODE_OK cris_hard_regno_mode_ok
#undef TARGET_STATIC_RTX_ALIGNMENT
#define TARGET_STATIC_RTX_ALIGNMENT cris_static_rtx_alignment
#undef TARGET_CONSTANT_ALIGNMENT
#define TARGET_CONSTANT_ALIGNMENT cris_constant_alignment
@ -4329,6 +4332,26 @@ cris_hard_regno_mode_ok (unsigned int regno, machine_mode mode)
|| (regno != CRIS_MOF_REGNUM && regno != CRIS_ACR_REGNUM)));
}
/* Return the preferred minimum alignment for a static object. */
static HOST_WIDE_INT
cris_preferred_mininum_alignment (void)
{
if (!TARGET_CONST_ALIGN)
return 8;
if (TARGET_ALIGN_BY_32)
return 32;
return 16;
}
/* Implement TARGET_STATIC_RTX_ALIGNMENT. */
static HOST_WIDE_INT
cris_static_rtx_alignment (machine_mode mode)
{
return MAX (cris_preferred_mininum_alignment (), GET_MODE_ALIGNMENT (mode));
}
/* Implement TARGET_CONSTANT_ALIGNMENT. Note that this hook has the
effect of making gcc believe that ALL references to constant stuff
(in code segment, like strings) have this alignment. That is a rather
@ -4339,11 +4362,7 @@ cris_hard_regno_mode_ok (unsigned int regno, machine_mode mode)
static HOST_WIDE_INT
cris_constant_alignment (const_tree, HOST_WIDE_INT basic_align)
{
if (!TARGET_CONST_ALIGN)
return basic_align;
if (TARGET_ALIGN_BY_32)
return MAX (basic_align, 32);
return MAX (basic_align, 16);
return MAX (cris_preferred_mininum_alignment (), basic_align);
}
#if 0

View File

@ -28741,6 +28741,18 @@ ix86_sched_init_global (FILE *, int, int)
}
/* Implement TARGET_STATIC_RTX_ALIGNMENT. */
static HOST_WIDE_INT
ix86_static_rtx_alignment (machine_mode mode)
{
if (mode == DFmode)
return 64;
if (ALIGN_MODE_128 (mode))
return MAX (128, GET_MODE_ALIGNMENT (mode));
return GET_MODE_ALIGNMENT (mode);
}
/* Implement TARGET_CONSTANT_ALIGNMENT. */
static HOST_WIDE_INT
@ -28749,10 +28761,9 @@ ix86_constant_alignment (const_tree exp, HOST_WIDE_INT align)
if (TREE_CODE (exp) == REAL_CST || TREE_CODE (exp) == VECTOR_CST
|| TREE_CODE (exp) == INTEGER_CST)
{
if (TYPE_MODE (TREE_TYPE (exp)) == DFmode && align < 64)
return 64;
else if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (exp))) && align < 128)
return 128;
machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
HOST_WIDE_INT mode_align = ix86_static_rtx_alignment (mode);
return MAX (mode_align, align);
}
else if (!optimize_size && TREE_CODE (exp) == STRING_CST
&& TREE_STRING_LENGTH (exp) >= 31 && align < BITS_PER_WORD)
@ -50295,6 +50306,8 @@ ix86_run_selftests (void)
#undef TARGET_CAN_CHANGE_MODE_CLASS
#define TARGET_CAN_CHANGE_MODE_CLASS ix86_can_change_mode_class
#undef TARGET_STATIC_RTX_ALIGNMENT
#define TARGET_STATIC_RTX_ALIGNMENT ix86_static_rtx_alignment
#undef TARGET_CONSTANT_ALIGNMENT
#define TARGET_CONSTANT_ALIGNMENT ix86_constant_alignment

View File

@ -168,6 +168,7 @@ static void mmix_print_operand (FILE *, rtx, int);
static void mmix_print_operand_address (FILE *, machine_mode, rtx);
static bool mmix_print_operand_punct_valid_p (unsigned char);
static void mmix_conditional_register_usage (void);
static HOST_WIDE_INT mmix_static_rtx_alignment (machine_mode);
static HOST_WIDE_INT mmix_constant_alignment (const_tree, HOST_WIDE_INT);
static HOST_WIDE_INT mmix_starting_frame_offset (void);
@ -284,6 +285,8 @@ static HOST_WIDE_INT mmix_starting_frame_offset (void);
#undef TARGET_OPTION_OVERRIDE
#define TARGET_OPTION_OVERRIDE mmix_option_override
#undef TARGET_STATIC_RTX_ALIGNMENT
#define TARGET_STATIC_RTX_ALIGNMENT mmix_static_rtx_alignment
#undef TARGET_CONSTANT_ALIGNMENT
#define TARGET_CONSTANT_ALIGNMENT mmix_constant_alignment
@ -342,6 +345,14 @@ mmix_data_alignment (tree type ATTRIBUTE_UNUSED, int basic_align)
return basic_align;
}
/* Implement TARGET_STATIC_RTX_ALIGNMENT. */
static HOST_WIDE_INT
mmix_static_rtx_alignment (machine_mode mode)
{
return MAX (GET_MODE_ALIGNMENT (mode), 32);
}
/* Implement tARGET_CONSTANT_ALIGNMENT. */
static HOST_WIDE_INT

View File

@ -7196,6 +7196,18 @@ spu_truly_noop_truncation (unsigned int outprec, unsigned int inprec)
return inprec <= 32 && outprec <= inprec;
}
/* Implement TARGET_STATIC_RTX_ALIGNMENT.
Make all static objects 16-byte aligned. This allows us to assume
they are also padded to 16 bytes, which means we can use a single
load or store instruction to access them. */
static HOST_WIDE_INT
spu_static_rtx_alignment (machine_mode mode)
{
return MAX (GET_MODE_ALIGNMENT (mode), 128);
}
/* Implement TARGET_CONSTANT_ALIGNMENT.
Make all static objects 16-byte aligned. This allows us to assume
@ -7447,6 +7459,8 @@ static const struct attribute_spec spu_attribute_table[] =
#undef TARGET_TRULY_NOOP_TRUNCATION
#define TARGET_TRULY_NOOP_TRUNCATION spu_truly_noop_truncation
#undef TARGET_STATIC_RTX_ALIGNMENT
#define TARGET_STATIC_RTX_ALIGNMENT spu_static_rtx_alignment
#undef TARGET_CONSTANT_ALIGNMENT
#define TARGET_CONSTANT_ALIGNMENT spu_constant_alignment

View File

@ -1078,6 +1078,13 @@ On 32-bit ELF the largest supported section alignment in bits is
@samp{(0x80000000 * 8)}, but this is not representable on 32-bit hosts.
@end defmac
@deftypefn {Target Hook} HOST_WIDE_INT TARGET_STATIC_RTX_ALIGNMENT (machine_mode @var{mode})
This hook returns the preferred alignment in bits for a
statically-allocated rtx, such as a constant pool entry. @var{mode}
is the mode of the rtx. The default implementation returns
@samp{GET_MODE_ALIGNMENT (@var{mode})}.
@end deftypefn
@defmac DATA_ALIGNMENT (@var{type}, @var{basic-align})
If defined, a C expression to compute the alignment for a variable in
the static store. @var{type} is the data type, and @var{basic-align} is

View File

@ -1026,6 +1026,8 @@ On 32-bit ELF the largest supported section alignment in bits is
@samp{(0x80000000 * 8)}, but this is not representable on 32-bit hosts.
@end defmac
@hook TARGET_STATIC_RTX_ALIGNMENT
@defmac DATA_ALIGNMENT (@var{type}, @var{basic-align})
If defined, a C expression to compute the alignment for a variable in
the static store. @var{type} is the data type, and @var{basic-align} is

View File

@ -3335,6 +3335,15 @@ HOOK_VECTOR_END (addr_space)
#undef HOOK_PREFIX
#define HOOK_PREFIX "TARGET_"
DEFHOOK
(static_rtx_alignment,
"This hook returns the preferred alignment in bits for a\n\
statically-allocated rtx, such as a constant pool entry. @var{mode}\n\
is the mode of the rtx. The default implementation returns\n\
@samp{GET_MODE_ALIGNMENT (@var{mode})}.",
HOST_WIDE_INT, (machine_mode mode),
default_static_rtx_alignment)
DEFHOOK
(constant_alignment,
"This hook returns the alignment in bits of a constant that is being\n\

View File

@ -1173,6 +1173,14 @@ tree default_mangle_decl_assembler_name (tree decl ATTRIBUTE_UNUSED,
return id;
}
/* The default implementation of TARGET_STATIC_RTX_ALIGNMENT. */
HOST_WIDE_INT
default_static_rtx_alignment (machine_mode mode)
{
return GET_MODE_ALIGNMENT (mode);
}
/* The default implementation of TARGET_CONSTANT_ALIGNMENT. */
HOST_WIDE_INT

View File

@ -94,6 +94,7 @@ extern int default_builtin_vectorization_cost (enum vect_cost_for_stmt, tree, in
extern tree default_builtin_reciprocal (tree);
extern HOST_WIDE_INT default_static_rtx_alignment (machine_mode);
extern HOST_WIDE_INT default_constant_alignment (const_tree, HOST_WIDE_INT);
extern HOST_WIDE_INT constant_alignment_word_strings (const_tree,
HOST_WIDE_INT);

View File

@ -3783,11 +3783,8 @@ force_const_mem (machine_mode mode, rtx x)
*slot = desc;
/* Align the location counter as required by EXP's data type. */
align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
tree type = lang_hooks.types.type_for_mode (mode, 0);
if (type != NULL_TREE)
align = targetm.constant_alignment (make_tree (type, x), align);
machine_mode align_mode = (mode == VOIDmode ? word_mode : mode);
align = targetm.static_rtx_alignment (align_mode);
pool->offset += (align / BITS_PER_UNIT) - 1;
pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
@ -3829,7 +3826,6 @@ force_const_mem (machine_mode mode, rtx x)
/* Construct the MEM. */
desc->mem = def = gen_const_mem (mode, symbol);
set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
set_mem_align (def, align);
/* If we're dropping a label to the constant pool, make sure we