From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6126 invoked by alias); 16 Oct 2015 14:12:54 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 6114 invoked by uid 89); 16 Oct 2015 14:12:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL,BAYES_00,KAM_ASCII_DIVIDERS,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mx07-00178001.pphosted.com Received: from mx08-00178001.pphosted.com (HELO mx07-00178001.pphosted.com) (91.207.212.93) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 16 Oct 2015 14:12:50 +0000 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.14.5/8.14.5) with SMTP id t9GE9PY8009600; Fri, 16 Oct 2015 16:12:45 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 1xk0bg8nyp-1 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 16 Oct 2015 16:12:45 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id D0D1E31; Fri, 16 Oct 2015 14:12:21 +0000 (GMT) Received: from Webmail-eu.st.com (safex1hubcas4.st.com [10.75.90.69]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 33BC016A4; Fri, 16 Oct 2015 14:12:43 +0000 (GMT) Received: from [164.129.122.197] (164.129.122.197) by webmail-eu.st.com (10.75.90.13) with Microsoft SMTP Server (TLS) id 8.3.389.2; Fri, 16 Oct 2015 16:12:42 +0200 Subject: Re: [PATCH ARM]: PR67745: Fix function alignment after __attribute__ 2/2 To: Ramana Radhakrishnan References: <560A90F2.5010708@st.com> <560C31CD.7060009@redhat.com> <560CDCD7.9080108@st.com> <560D5B36.2020600@st.com> <5614C412.5080400@st.com> <5614F17B.5060402@redhat.com> <5614F7D0.8010409@st.com> <56155841.6000404@redhat.com> <56155B72.4020807@redhat.com> <56166C36.7040600@st.com> <56166DA5.3030909@redhat.com> <561674C1.8030008@st.com> <56167E09.3010502@redhat.com> <561B91DE.5040909@st.com> <561CBAB7.7080104@foss.arm.com> CC: Bernd Schmidt , "gcc-patches@gcc.gnu.org" From: Christian Bruel X-No-Archive: yes Message-ID: <562105DA.6070005@st.com> Date: Fri, 16 Oct 2015 14:18:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <561CBAB7.7080104@foss.arm.com> Content-Type: multipart/mixed; boundary="------------000602070203010008020405" X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.14.151,1.0.33,0.0.0000 definitions=2015-10-16_10:2015-10-15,2015-10-16,1970-01-01 signatures=0 X-IsSubscribed: yes X-SW-Source: 2015-10/txt/msg01607.txt.bz2 --------------000602070203010008020405 Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit Content-length: 115 committed patch attached. with the default_relayout_function replaced by hook_void_tree as suggested by Ramana, --------------000602070203010008020405 Content-Type: text/x-patch; name="commit_align1.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="commit_align1.patch" Content-length: 11830 Index: gcc/ChangeLog =================================================================== --- gcc/ChangeLog (revision 228903) +++ gcc/ChangeLog (revision 228904) @@ -1,3 +1,13 @@ +2015-10-16 Christian Bruel + + 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-10-11 Jan Hubicka Revert: 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 (revision 228904) @@ -0,0 +1,27 @@ +/* PR target/67745 + Verify alignment when both attribute optimize and target are used. */ +/* { dg-do compile } */ +/* { dg-skip-if "" { ! { arm_thumb1_ok || arm_thumb2_ok } } } */ + +void +__attribute__ ((target ("arm"))) +bar() +{ +} + +void +__attribute__ ((target ("thumb"))) +__attribute__ ((optimize ("Os"))) +foo() +{ +} + +void +__attribute__ ((target ("thumb"))) +__attribute__ ((optimize ("O2"))) +rab() +{ +} + +/* { dg-final { scan-assembler-times ".align\[ \t]2" 2 } } */ +/* { dg-final { scan-assembler ".align\[ \t]1" } } */ Index: gcc/testsuite/gcc.target/arm/no-align.c =================================================================== --- gcc/testsuite/gcc.target/arm/no-align.c (revision 0) +++ gcc/testsuite/gcc.target/arm/no-align.c (revision 228904) @@ -0,0 +1,12 @@ +/* PR target/67745 + Verify that -mthumb code is not aligned. */ +/* { dg-do compile } */ +/* { dg-options "-O2 -mthumb -fno-align-functions" } */ +/* { dg-skip-if "" { ! { arm_thumb1_ok || arm_thumb2_ok } } } */ + +void +foo() +{ +} + +/* { dg-final { scan-assembler-not ".align\[ \t]2" } } */ 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 (revision 228904) @@ -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 (revision 228904) @@ -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 arm code is always 4 bytes aligned. */ +void __attribute__ ((target ("arm"))) +c(void) +{ +} + +/* { dg-final { scan-assembler-not ".align\[ \t]1" } } */ Index: gcc/testsuite/ChangeLog =================================================================== --- gcc/testsuite/ChangeLog (revision 228903) +++ gcc/testsuite/ChangeLog (revision 228904) @@ -1,3 +1,11 @@ +2015-10-16 Christian Bruel + + PR target/67745 + * gcc.target/arm/no-align.c: New test. + * gcc.target/arm/attr-align1.c: New test. + * gcc.target/arm/attr-align2.c: New test. + * gcc.target/arm/attr-align3.c: New test. + 2015-10-11 Jan Hubicka * gcc.c-torture/compile/icfmatch.c: Add testcase Index: gcc/config/arm/arm.c =================================================================== --- gcc/config/arm/arm.c (revision 228903) +++ gcc/config/arm/arm.c (revision 228904) @@ -246,6 +246,7 @@ 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 @@ #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 @@ /* 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 228903) +++ gcc/config/arm/arm.h (revision 228904) @@ -565,7 +565,7 @@ #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/doc/tm.texi =================================================================== --- gcc/doc/tm.texi (revision 228911) +++ gcc/doc/tm.texi (revision 228912) @@ -9985,6 +9985,10 @@ 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 Index: gcc/doc/tm.texi.in =================================================================== --- gcc/doc/tm.texi.in (revision 228911) +++ gcc/doc/tm.texi.in (revision 228912) @@ -7274,6 +7274,8 @@ @hook TARGET_CAN_INLINE_P +@hook TARGET_RELAYOUT_FUNCTION + @node Emulated TLS @section Emulating TLS @cindex Emulated TLS Index: gcc/target.def =================================================================== --- gcc/target.def (revision 228911) +++ gcc/target.def (revision 228912) @@ -5620,6 +5620,12 @@ 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 Index: gcc/ChangeLog =================================================================== --- gcc/ChangeLog (revision 228911) +++ gcc/ChangeLog (revision 228912) @@ -1,5 +1,18 @@ 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 * config/arm/arm.h (FUNCTION_BOUNDARY): Move optimize_size condition to: * config/arm/arm.c (arm_option_override_internal): Call Index: gcc/function.c =================================================================== --- gcc/function.c (revision 228911) +++ gcc/function.c (revision 228912) @@ -4840,6 +4840,9 @@ 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)) Index: gcc/passes.c =================================================================== --- gcc/passes.c (revision 228911) +++ gcc/passes.c (revision 228912) @@ -253,6 +253,11 @@ } #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 Index: gcc/config/arm/arm.c =================================================================== --- gcc/config/arm/arm.c (revision 228911) +++ gcc/config/arm/arm.c (revision 228912) @@ -250,6 +250,7 @@ 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 @@ #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 @@ 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. */ Index: gcc/config/arm/arm.h =================================================================== --- gcc/config/arm/arm.h (revision 228911) +++ gcc/config/arm/arm.h (revision 228912) @@ -565,7 +565,8 @@ #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 --------------000602070203010008020405--