public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH ARM]: PR67745: Fix function alignment after __attribute__ 1/2
@ 2015-09-29 13:39 Christian Bruel
  2015-10-07 21:14 ` Ramana Radhakrishnan
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Bruel @ 2015-09-29 13:39 UTC (permalink / raw)
  To: Ramana.Radhakrishnan, kyrylo.tkachov; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 458 bytes --]

This patch is the ARM part to make the function's alignment more
sensible to current function attributes that depends on both
opts->target_flags and opts->x_optimize_size.

- Does not change FUNCTION_BOUNDARY's value between functions for a
given ABI (arm or thumb). Setting done per function with override_options.

- Implements the TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE hook to track
aligns between functions.

No regressions for arm-none-eabi.

Christian


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: align.patch --]
[-- Type: text/x-patch; name="align.patch", Size: 5095 bytes --]

2015-09-29  Christian Bruel  <christian.bruel@st.com>

	PR target/67745
	* config/arm/arm.h (FUNCTION_BOUNDARY): Move optimize_size condition to:
	* config/arm/arm.c (arm_option_override_internal): Call
	arm_override_options_after_change_1.
	(arm_override_options_after_change): New function.
	(arm_override_options_after_change_1): Likewise.
	(TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE): Define hook.

2015-09-29  Christian Bruel  <christian.bruel@st.com>

	PR target/67745
        * gcc.target/arm/attr-align1.c: New test.
        * gcc.target/arm/attr-align2.c: New test.
        * gcc.target/arm/attr-align3.c: New test.

Index: gcc/config/arm/arm.c
===================================================================
--- gcc/config/arm/arm.c	(revision 228229)
+++ gcc/config/arm/arm.c	(working copy)
@@ -246,6 +246,7 @@ static tree arm_build_builtin_va_list (v
 static void arm_expand_builtin_va_start (tree, rtx);
 static tree arm_gimplify_va_arg_expr (tree, tree, gimple_seq *, gimple_seq *);
 static void arm_option_override (void);
+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);
@@ -407,6 +408,9 @@ static const struct attribute_spec arm_a
 #undef  TARGET_OPTION_OVERRIDE
 #define TARGET_OPTION_OVERRIDE arm_option_override
 
+#undef TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE
+#define TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE arm_override_options_after_change
+
 #undef TARGET_OPTION_PRINT
 #define TARGET_OPTION_PRINT arm_option_print
 
@@ -2810,11 +2814,29 @@ static GTY(()) bool thumb_flipper;
 /* Options after initial target override.  */
 static GTY(()) tree init_optimize;
 
+static void
+arm_override_options_after_change_1 (struct gcc_options *opts)
+{
+  if (opts->x_align_functions <= 0)
+    opts->x_align_functions = TARGET_THUMB_P (opts->x_target_flags)
+      && opts->x_optimize_size ? 2 : 4;
+}
+
+/* Implement targetm.override_options_after_change.  */
+
+static void
+arm_override_options_after_change (void)
+{
+  arm_override_options_after_change_1 (&global_options);
+}
+
 /* Reset options between modes that the user has specified.  */
 static void
 arm_option_override_internal (struct gcc_options *opts,
 			      struct gcc_options *opts_set)
 {
+  arm_override_options_after_change_1 (opts);
+
   if (TARGET_THUMB_P (opts->x_target_flags)
       && !(ARM_FSET_HAS_CPU1 (insn_flags, FL_THUMB)))
     {
Index: gcc/config/arm/arm.h
===================================================================
--- gcc/config/arm/arm.h	(revision 228229)
+++ gcc/config/arm/arm.h	(working copy)
@@ -565,7 +565,7 @@ extern int arm_arch_crc;
 #define PREFERRED_STACK_BOUNDARY \
     (arm_abi == ARM_ABI_ATPCS ? 64 : STACK_BOUNDARY)
 
-#define FUNCTION_BOUNDARY  ((TARGET_THUMB && optimize_size) ? 16 : 32)
+#define FUNCTION_BOUNDARY           (TARGET_THUMB ? 16 : 32)
 
 /* The lowest bit is used to indicate Thumb-mode functions, so the
    vbit must go into the delta field of pointers to member
Index: gcc/testsuite/gcc.target/arm/attr-align1.c
===================================================================
--- gcc/testsuite/gcc.target/arm/attr-align1.c	(revision 0)
+++ gcc/testsuite/gcc.target/arm/attr-align1.c	(working copy)
@@ -0,0 +1,13 @@
+/* PR target/67745
+   Verify alignment when attribute target is used with -falign-functions.  */
+/* { dg-do compile } */
+/* { dg-options "-falign-functions=2" }  */
+
+/* Check that arm code is always 4 bytes aligned.  */
+void  __attribute__ ((target ("arm")))
+c(void)
+{
+}
+
+
+/* { dg-final { scan-assembler-not ".align\[ \t]*1" } } */
Index: gcc/testsuite/gcc.target/arm/attr-align2.c
===================================================================
--- gcc/testsuite/gcc.target/arm/attr-align2.c	(revision 0)
+++ gcc/testsuite/gcc.target/arm/attr-align2.c	(working copy)
@@ -0,0 +1,15 @@
+/* PR target/67745
+   Verify alignment when attribute optimize is used.  */
+/* { dg-do compile } */
+/* { dg-skip-if "" { ! { arm_thumb1_ok || arm_thumb2_ok } } } */
+/* { dg-options "-O2 -mthumb" }  */
+
+/* Check that thumb code is always 2 bytes aligned for -Os.  */
+
+void
+__attribute__ ((optimize("Os")))
+foo()
+{
+}
+
+/* { dg-final { scan-assembler ".align\[ \t]*1" } } */
Index: gcc/testsuite/gcc.target/arm/attr-align3.c
===================================================================
--- gcc/testsuite/gcc.target/arm/attr-align3.c	(revision 0)
+++ gcc/testsuite/gcc.target/arm/attr-align3.c	(working copy)
@@ -0,0 +1,13 @@
+/* PR target/67745
+   Verify alignment when attribute target is used.  */
+/* { dg-do compile } */
+/* { dg-skip-if "" { ! { arm_thumb1_ok || arm_thumb2_ok } } } */
+/* { dg-options "-Os -mthumb" }  */
+
+/* Check that thumb code is always 4 bytes aligned.  */
+void  __attribute__ ((target ("arm")))
+c(void)
+{
+}
+
+/* { dg-final { scan-assembler-not ".align\[ \t]*1" } } */


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH ARM]: PR67745: Fix function alignment after __attribute__ 1/2
  2015-09-29 13:39 [PATCH ARM]: PR67745: Fix function alignment after __attribute__ 1/2 Christian Bruel
@ 2015-10-07 21:14 ` Ramana Radhakrishnan
  0 siblings, 0 replies; 2+ messages in thread
From: Ramana Radhakrishnan @ 2015-10-07 21:14 UTC (permalink / raw)
  To: Christian Bruel; +Cc: Ramana Radhakrishnan, Kyrylo Tkachov, gcc-patches

On Tue, Sep 29, 2015 at 2:15 PM, Christian Bruel <christian.bruel@st.com> wrote:
> This patch is the ARM part to make the function's alignment more
> sensible to current function attributes that depends on both
> opts->target_flags and opts->x_optimize_size.
>
> - Does not change FUNCTION_BOUNDARY's value between functions for a
> given ABI (arm or thumb). Setting done per function with override_options.
>
> - Implements the TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE hook to track
> aligns between functions.
>
> No regressions for arm-none-eabi.

In this particular case I'd feel more comfortable with the testsuite
being run flipping arm and thumb states just to be sure it all works
fine.


Ok to apply this patch once the 2/2 reaches a suitable conclusion.

Ramana

>
> Christian
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-10-07 21:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-29 13:39 [PATCH ARM]: PR67745: Fix function alignment after __attribute__ 1/2 Christian Bruel
2015-10-07 21:14 ` Ramana Radhakrishnan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).