public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Christian Bruel <christian.bruel@st.com>
To: <Ramana.Radhakrishnan@arm.com>, <kyrylo.tkachov@arm.com>
Cc: <gcc-patches@gcc.gnu.org>
Subject: [PATCH ARM]: PR67745: Fix function alignment after __attribute__ 1/2
Date: Tue, 29 Sep 2015 13:39:00 -0000	[thread overview]
Message-ID: <560A8F0F.7090704@st.com> (raw)

[-- 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" } } */


             reply	other threads:[~2015-09-29 13:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-29 13:39 Christian Bruel [this message]
2015-10-07 21:14 ` Ramana Radhakrishnan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=560A8F0F.7090704@st.com \
    --to=christian.bruel@st.com \
    --cc=Ramana.Radhakrishnan@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=kyrylo.tkachov@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).