From: Christian Bruel Date: Fri, 16 Oct 2015 13:52:51 +0000 (+0200) Subject: re PR target/67745 ([ARM] wrong alignments when __attribute__ ((optimize,target,align... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=63b0cb0436382abe256360ca3e83c02041b8ffe2;p=gcc.git re PR target/67745 ([ARM] wrong alignments when __attribute__ ((optimize,target,align) is used) 2015-10-16 Christian Bruel PR target/67745 * config/arm/arm.h (FUNCTION_BOUNDARY): Use FUNCTION_BOUNDARY_P. (FUNCTION_BOUNDARY_P): New macro: * config/arm/arm.c (TARGET_RELAYOUT_FUNCTION, arm_relayout_function): New hook. * doc/tm.texi.in (TARGET_RELAYOUT_FUNCTION): Document. * doc/tm.texi (TARGET_RELAYOUT_FUNCTION): New hook. * gcc/target.def (TARGET_RELAYOUT_FUNCTION): Likewise. * gcc/function.c (allocate_struct_function): Call relayout_function hook. * gcc/passes.c (rest_of_decl_compilation): Likewise. From-SVN: r228912 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 24deaaccef3..fe2d8ce67b1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,16 @@ +2015-10-16 Christian Bruel + + PR target/67745 + * config/arm/arm.h (FUNCTION_BOUNDARY): Use FUNCTION_BOUNDARY_P. + (FUNCTION_BOUNDARY_P): New macro: + * config/arm/arm.c (TARGET_RELAYOUT_FUNCTION, arm_relayout_function): + New hook. + * doc/tm.texi.in (TARGET_RELAYOUT_FUNCTION): Document. + * doc/tm.texi (TARGET_RELAYOUT_FUNCTION): New hook. + * gcc/target.def (TARGET_RELAYOUT_FUNCTION): Likewise. + * gcc/function.c (allocate_struct_function): Call relayout_function hook. + * gcc/passes.c (rest_of_decl_compilation): Likewise. + 2015-10-16 Christian Bruel PR target/67745 diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 2c8215cb513..b80ec08512a 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -250,6 +250,7 @@ static void arm_override_options_after_change (void); static void arm_option_print (FILE *, int, struct cl_target_option *); static void arm_set_current_function (tree); static bool arm_can_inline_p (tree, tree); +static void arm_relayout_function (tree); static bool arm_valid_target_attribute_p (tree, tree, tree, int); static unsigned HOST_WIDE_INT arm_shift_truncation_mask (machine_mode); static bool arm_macro_fusion_p (void); @@ -405,6 +406,9 @@ static const struct attribute_spec arm_attribute_table[] = #undef TARGET_CAN_INLINE_P #define TARGET_CAN_INLINE_P arm_can_inline_p +#undef TARGET_RELAYOUT_FUNCTION +#define TARGET_RELAYOUT_FUNCTION arm_relayout_function + #undef TARGET_OPTION_OVERRIDE #define TARGET_OPTION_OVERRIDE arm_option_override @@ -29825,6 +29829,23 @@ arm_can_inline_p (tree caller ATTRIBUTE_UNUSED, tree callee ATTRIBUTE_UNUSED) return true; } +/* Hook to fix function's alignment affected by target attribute. */ + +static void +arm_relayout_function (tree fndecl) +{ + if (DECL_USER_ALIGN (fndecl)) + return; + + tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (fndecl); + + if (!callee_tree) + callee_tree = target_option_default_node; + + DECL_ALIGN (fndecl) = + FUNCTION_BOUNDARY_P (TREE_TARGET_OPTION (callee_tree)->x_target_flags); +} + /* Inner function to process the attribute((target(...))), take an argument and set the current options from the argument. If we have a list, recursively go over the list. */ diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h index 9715969a5e5..585bd1d95f3 100644 --- a/gcc/config/arm/arm.h +++ b/gcc/config/arm/arm.h @@ -565,7 +565,8 @@ extern int arm_arch_crc; #define PREFERRED_STACK_BOUNDARY \ (arm_abi == ARM_ABI_ATPCS ? 64 : STACK_BOUNDARY) -#define FUNCTION_BOUNDARY (TARGET_THUMB ? 16 : 32) +#define FUNCTION_BOUNDARY_P(flags) (TARGET_THUMB_P (flags) ? 16 : 32) +#define FUNCTION_BOUNDARY (FUNCTION_BOUNDARY_P (target_flags)) /* The lowest bit is used to indicate Thumb-mode functions, so the vbit must go into the delta field of pointers to member diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index d09e6461683..731e63043f3 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -9985,6 +9985,10 @@ default, inlining is not allowed if the callee function has function specific target options and the caller does not use the same options. @end deftypefn +@deftypefn {Target Hook} void TARGET_RELAYOUT_FUNCTION (tree @var{fndecl}) +This target hook fixes function @var{fndecl} after attributes are processed. Default does nothing. On ARM, the default function's alignment is updated with the attribute target. +@end deftypefn + @node Emulated TLS @section Emulating TLS @cindex Emulated TLS diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index 33939ec77f4..0b52250d372 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -7274,6 +7274,8 @@ on this implementation detail. @hook TARGET_CAN_INLINE_P +@hook TARGET_RELAYOUT_FUNCTION + @node Emulated TLS @section Emulating TLS @cindex Emulated TLS diff --git a/gcc/function.c b/gcc/function.c index db5bc1c4754..f7742148cfb 100644 --- a/gcc/function.c +++ b/gcc/function.c @@ -4840,6 +4840,9 @@ allocate_struct_function (tree fndecl, bool abstract_p) for (tree parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm)) relayout_decl (parm); + + /* Similarly relayout the function decl. */ + targetm.target_option.relayout_function (fndecl); } if (!abstract_p && aggregate_value_p (result, fndecl)) diff --git a/gcc/passes.c b/gcc/passes.c index 5b41102e04f..6ef6d2e50ff 100644 --- a/gcc/passes.c +++ b/gcc/passes.c @@ -253,6 +253,11 @@ rest_of_decl_compilation (tree decl, } #endif + /* Now that we have activated any function-specific attributes + that might affect function decl, particularly align, relayout it. */ + if (TREE_CODE (decl) == FUNCTION_DECL) + targetm.target_option.relayout_function (decl); + timevar_pop (TV_VARCONST); } else if (TREE_CODE (decl) == TYPE_DECL diff --git a/gcc/target.def b/gcc/target.def index d29aad5c3f8..694e455f570 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -5620,6 +5620,12 @@ specific target options and the caller does not use the same options.", bool, (tree caller, tree callee), default_target_can_inline_p) +DEFHOOK +(relayout_function, +"This target hook fixes function @var{fndecl} after attributes are processed. Default does nothing. On ARM, the default function's alignment is updated with the attribute target.", + void, (tree fndecl), + hook_void_tree) + HOOK_VECTOR_END (target_option) /* For targets that need to mark extra registers as live on entry to