Patchwork Avoid option optimization hooks setting variables to 2

login
register
mail settings
Submitter Joseph S. Myers
Date Oct. 15, 2010, 11:28 p.m.
Message ID <Pine.LNX.4.64.1010152327250.1028@digraph.polyomino.org.uk>
Download mbox | patch
Permalink /patch/68011/
State New
Headers show

Comments

Joseph S. Myers - Oct. 15, 2010, 11:28 p.m.
This patch prepares for making default_options_optimization use lists
of implied options to handle by eliminating cases where
TARGET_OPTION_OPTIMIZATION hooks set variables for boolean options to
2, which does not directly correspond to implying a particular option.

This setting is done to signal to later code whether an option still
has a default value or has been explicitly set, so that later code can
handle the two cases differently.  With global_options_set this can
now be done without needing such a special value; this patch makes
code use global_options_set, or an opts_set pointer where available,
accordingly.

Note that this is specifically dealing with cases where the value 2 is
used in TARGET_OPTION_OPTIMIZATION hooks, not where it is used
elsewhere (including the new TARGET_OPTION_INIT_STRUCT hook, except
for the case of flag_section_anchors since target-independent changes
are involved there).  Some other cases may involve greater
complications (in particular, the SH case with flag_finite_math_only
is best done with global_options_set storing values that aren't simply
boolean to indicate options that have been changed from their default
by some other option - any of -f(no-)finite-math-only,
-f(no-)fast-math and -Ofast should override the target
flag_finite_math_only default - I commented further on this in
<http://gcc.gnu.org/ml/gcc-patches/2010-10/msg00606.html> where I
discussed what a full solution to PR 38716 would involve).

Bootstrapped with no regressions on x86_64-unknown-linux-gnu.  Also
tested building ccc1 for crosses to: arm-eabi i686-solaris2.10
powerpc-eabi sh-elf.  OK to commit?

2010-10-15  Joseph Myers  <joseph@codesourcery.com>

	* config/arm/arm.c (arm_option_optimization): Set
	flag_section_anchors to 1 not 2.
	* config/i386/i386.c (ix86_option_override_internal): Check
	global_options_set.x_flag_zee and
	global_options_set.x_flag_omit_frame_pointer.
	(ix86_option_optimization): Don't set flag_omit_frame_pointer and
	flag_zee to 2.
	* config/i386/sol2-10.h (SUBTARGET_OVERRIDE_OPTIONS): Check
	global_options_set.x_flag_omit_frame_pointer.
	* config/rs6000/rs6000.c (rs6000_option_init_struct): Set
	opts->x_flag_section_anchors to 1 not 2.
	* config/sh/sh.c (sh_option_optimization): Don't set
	flag_schedule_insns to 2.
	(sh_option_override): Check
	global_options_set.x_flag_schedule_insns.
	* opts.c (finish_options): Check opts_set->x_flag_section_anchors.
Richard Guenther - Oct. 16, 2010, 9:07 a.m.
On Sat, Oct 16, 2010 at 1:28 AM, Joseph S. Myers
<joseph@codesourcery.com> wrote:
> This patch prepares for making default_options_optimization use lists
> of implied options to handle by eliminating cases where
> TARGET_OPTION_OPTIMIZATION hooks set variables for boolean options to
> 2, which does not directly correspond to implying a particular option.
>
> This setting is done to signal to later code whether an option still
> has a default value or has been explicitly set, so that later code can
> handle the two cases differently.  With global_options_set this can
> now be done without needing such a special value; this patch makes
> code use global_options_set, or an opts_set pointer where available,
> accordingly.
>
> Note that this is specifically dealing with cases where the value 2 is
> used in TARGET_OPTION_OPTIMIZATION hooks, not where it is used
> elsewhere (including the new TARGET_OPTION_INIT_STRUCT hook, except
> for the case of flag_section_anchors since target-independent changes
> are involved there).  Some other cases may involve greater
> complications (in particular, the SH case with flag_finite_math_only
> is best done with global_options_set storing values that aren't simply
> boolean to indicate options that have been changed from their default
> by some other option - any of -f(no-)finite-math-only,
> -f(no-)fast-math and -Ofast should override the target
> flag_finite_math_only default - I commented further on this in
> <http://gcc.gnu.org/ml/gcc-patches/2010-10/msg00606.html> where I
> discussed what a full solution to PR 38716 would involve).
>
> Bootstrapped with no regressions on x86_64-unknown-linux-gnu.  Also
> tested building ccc1 for crosses to: arm-eabi i686-solaris2.10
> powerpc-eabi sh-elf.  OK to commit?

Ok.

Thanks,
Richard.

> 2010-10-15  Joseph Myers  <joseph@codesourcery.com>
>
>        * config/arm/arm.c (arm_option_optimization): Set
>        flag_section_anchors to 1 not 2.
>        * config/i386/i386.c (ix86_option_override_internal): Check
>        global_options_set.x_flag_zee and
>        global_options_set.x_flag_omit_frame_pointer.
>        (ix86_option_optimization): Don't set flag_omit_frame_pointer and
>        flag_zee to 2.
>        * config/i386/sol2-10.h (SUBTARGET_OVERRIDE_OPTIONS): Check
>        global_options_set.x_flag_omit_frame_pointer.
>        * config/rs6000/rs6000.c (rs6000_option_init_struct): Set
>        opts->x_flag_section_anchors to 1 not 2.
>        * config/sh/sh.c (sh_option_optimization): Don't set
>        flag_schedule_insns to 2.
>        (sh_option_override): Check
>        global_options_set.x_flag_schedule_insns.
>        * opts.c (finish_options): Check opts_set->x_flag_section_anchors.
>
> Index: gcc/opts.c
> ===================================================================
> --- gcc/opts.c  (revision 165519)
> +++ gcc/opts.c  (working copy)
> @@ -1005,7 +1005,7 @@ finish_options (struct gcc_options *opts
>      section-anchors.  */
>   if (!flag_unit_at_a_time)
>     {
> -      if (flag_section_anchors == 1)
> +      if (flag_section_anchors && opts_set->x_flag_section_anchors)
>        error ("Section anchors must be disabled when unit-at-a-time "
>               "is disabled.");
>       flag_section_anchors = 0;
> @@ -1022,14 +1022,16 @@ finish_options (struct gcc_options *opts
>   /* Unless the user has asked for section anchors, we disable toplevel
>      reordering at -O0 to disable transformations that might be surprising
>      to end users and to get -fno-toplevel-reorder tested.  */
> -  if (!optimize && flag_toplevel_reorder == 2 && flag_section_anchors != 1)
> +  if (!optimize
> +      && flag_toplevel_reorder == 2
> +      && !(flag_section_anchors && opts_set->x_flag_section_anchors))
>     {
>       flag_toplevel_reorder = 0;
>       flag_section_anchors = 0;
>     }
>   if (!flag_toplevel_reorder)
>     {
> -      if (flag_section_anchors == 1)
> +      if (flag_section_anchors && opts_set->x_flag_section_anchors)
>        error ("section anchors must be disabled when toplevel reorder"
>               " is disabled");
>       flag_section_anchors = 0;
> Index: gcc/config/i386/sol2-10.h
> ===================================================================
> --- gcc/config/i386/sol2-10.h   (revision 165519)
> +++ gcc/config/i386/sol2-10.h   (working copy)
> @@ -84,7 +84,7 @@ along with GCC; see the file COPYING3.
>  #define SUBTARGET_OVERRIDE_OPTIONS                             \
>   do                                                           \
>     {                                                          \
> -      if (flag_omit_frame_pointer == 2)                                \
> +      if (!global_options_set.x_flag_omit_frame_pointer)       \
>        flag_omit_frame_pointer = 0;                            \
>     }                                                          \
>   while (0)
> Index: gcc/config/i386/i386.c
> ===================================================================
> --- gcc/config/i386/i386.c      (revision 165519)
> +++ gcc/config/i386/i386.c      (working copy)
> @@ -3276,9 +3276,9 @@ ix86_option_override_internal (bool main
>      in case they weren't overwritten by command line options.  */
>   if (TARGET_64BIT)
>     {
> -      if (flag_zee == 2)
> +      if (optimize > 1 && !global_options_set.x_flag_zee)
>         flag_zee = 1;
> -      if (flag_omit_frame_pointer == 2)
> +      if (optimize >= 1 && !global_options_set.x_flag_omit_frame_pointer)
>        flag_omit_frame_pointer = 1;
>       if (flag_asynchronous_unwind_tables == 2)
>        flag_asynchronous_unwind_tables = 1;
> @@ -3287,9 +3287,7 @@ ix86_option_override_internal (bool main
>     }
>   else
>     {
> -      if (flag_zee == 2)
> -        flag_zee = 0;
> -      if (flag_omit_frame_pointer == 2)
> +      if (optimize >= 1 && !global_options_set.x_flag_omit_frame_pointer)
>        flag_omit_frame_pointer = !(USE_IX86_FRAME_POINTER || optimize_size);
>       if (flag_asynchronous_unwind_tables == 2)
>        flag_asynchronous_unwind_tables = !USE_IX86_FRAME_POINTER;
> @@ -4537,18 +4535,6 @@ ix86_option_optimization (int level, int
>     flag_schedule_insns = 0;
>  #endif
>
> -  /* The default values of these switches depend on the TARGET_64BIT
> -     that is not known at this moment.  Mark these values with 2 and
> -     let user the to override these.  In case there is no command line
> -     option specifying them, we will set the defaults in
> -     ix86_option_override_internal.  */
> -  if (optimize >= 1)
> -    flag_omit_frame_pointer = 2;
> -
> -  /* For -O2 and beyond, turn on -fzee for x86_64 target. */
> -  if (level > 1)
> -    flag_zee = 2;
> -
>  #ifdef SUBTARGET_OPTIMIZATION_OPTIONS
>   SUBTARGET_OPTIMIZATION_OPTIONS;
>  #endif
> Index: gcc/config/sh/sh.c
> ===================================================================
> --- gcc/config/sh/sh.c  (revision 165519)
> +++ gcc/config/sh/sh.c  (working copy)
> @@ -728,10 +728,6 @@ sh_option_optimization (int level, int s
>       if (!size)
>        target_flags |= MASK_SAVE_ALL_TARGET_REGS;
>     }
> -  /* If flag_schedule_insns is 1, we set it to 2 here so we know if
> -     the user explicitly requested this to be on or off.  */
> -  if (flag_schedule_insns > 0)
> -    flag_schedule_insns = 2;
>  }
>
>  /* Implement TARGET_OPTION_INIT_STRUCT.  */
> @@ -932,11 +928,12 @@ sh_option_override (void)
>          <http://gcc.gnu.org/ml/gcc-patches/2005-10/msg00816.html>.  */
>       else if (flag_exceptions)
>        {
> -         if (flag_schedule_insns == 1)
> +         if (flag_schedule_insns && global_options_set.x_flag_schedule_insns)
>            warning (0, "ignoring -fschedule-insns because of exception handling bug");
>          flag_schedule_insns = 0;
>        }
> -      else if (flag_schedule_insns == 2)
> +      else if (flag_schedule_insns
> +              && !global_options_set.x_flag_schedule_insns)
>        flag_schedule_insns = 0;
>     }
>
> Index: gcc/config/rs6000/rs6000.c
> ===================================================================
> --- gcc/config/rs6000/rs6000.c  (revision 165519)
> +++ gcc/config/rs6000/rs6000.c  (working copy)
> @@ -3693,7 +3693,7 @@ rs6000_option_init_struct (struct gcc_op
>
>   /* Enable section anchors by default.  */
>   if (!TARGET_MACHO)
> -    opts->x_flag_section_anchors = 2;
> +    opts->x_flag_section_anchors = 1;
>  }
>
>  /* Implement TARGET_OPTION_DEFAULT_PARAMS.  */
> Index: gcc/config/arm/arm.c
> ===================================================================
> --- gcc/config/arm/arm.c        (revision 165519)
> +++ gcc/config/arm/arm.c        (working copy)
> @@ -22823,11 +22823,9 @@ arm_order_regs_for_local_alloc (void)
>  static void
>  arm_option_optimization (int level, int size ATTRIBUTE_UNUSED)
>  {
> -  /* Enable section anchors by default at -O1 or higher.
> -     Use 2 to distinguish from an explicit -fsection-anchors
> -     given on the command line.  */
> +  /* Enable section anchors by default at -O1 or higher.  */
>   if (level > 0)
> -    flag_section_anchors = 2;
> +    flag_section_anchors = 1;
>  }
>
>  /* Implement TARGET_FRAME_POINTER_REQUIRED.  */
>
> --
> Joseph S. Myers
> joseph@codesourcery.com
>

Patch

Index: gcc/opts.c
===================================================================
--- gcc/opts.c	(revision 165519)
+++ gcc/opts.c	(working copy)
@@ -1005,7 +1005,7 @@  finish_options (struct gcc_options *opts
      section-anchors.  */
   if (!flag_unit_at_a_time)
     {
-      if (flag_section_anchors == 1)
+      if (flag_section_anchors && opts_set->x_flag_section_anchors)
 	error ("Section anchors must be disabled when unit-at-a-time "
 	       "is disabled.");
       flag_section_anchors = 0;
@@ -1022,14 +1022,16 @@  finish_options (struct gcc_options *opts
   /* Unless the user has asked for section anchors, we disable toplevel
      reordering at -O0 to disable transformations that might be surprising
      to end users and to get -fno-toplevel-reorder tested.  */
-  if (!optimize && flag_toplevel_reorder == 2 && flag_section_anchors != 1)
+  if (!optimize
+      && flag_toplevel_reorder == 2
+      && !(flag_section_anchors && opts_set->x_flag_section_anchors))
     {
       flag_toplevel_reorder = 0;
       flag_section_anchors = 0;
     }
   if (!flag_toplevel_reorder)
     {
-      if (flag_section_anchors == 1)
+      if (flag_section_anchors && opts_set->x_flag_section_anchors)
 	error ("section anchors must be disabled when toplevel reorder"
 	       " is disabled");
       flag_section_anchors = 0;
Index: gcc/config/i386/sol2-10.h
===================================================================
--- gcc/config/i386/sol2-10.h	(revision 165519)
+++ gcc/config/i386/sol2-10.h	(working copy)
@@ -84,7 +84,7 @@  along with GCC; see the file COPYING3.  
 #define SUBTARGET_OVERRIDE_OPTIONS				\
   do								\
     {								\
-      if (flag_omit_frame_pointer == 2)				\
+      if (!global_options_set.x_flag_omit_frame_pointer)	\
 	flag_omit_frame_pointer = 0;				\
     }								\
   while (0)
Index: gcc/config/i386/i386.c
===================================================================
--- gcc/config/i386/i386.c	(revision 165519)
+++ gcc/config/i386/i386.c	(working copy)
@@ -3276,9 +3276,9 @@  ix86_option_override_internal (bool main
      in case they weren't overwritten by command line options.  */
   if (TARGET_64BIT)
     {
-      if (flag_zee == 2)
+      if (optimize > 1 && !global_options_set.x_flag_zee)
         flag_zee = 1;
-      if (flag_omit_frame_pointer == 2)
+      if (optimize >= 1 && !global_options_set.x_flag_omit_frame_pointer)
 	flag_omit_frame_pointer = 1;
       if (flag_asynchronous_unwind_tables == 2)
 	flag_asynchronous_unwind_tables = 1;
@@ -3287,9 +3287,7 @@  ix86_option_override_internal (bool main
     }
   else
     {
-      if (flag_zee == 2)
-        flag_zee = 0;
-      if (flag_omit_frame_pointer == 2)
+      if (optimize >= 1 && !global_options_set.x_flag_omit_frame_pointer)
 	flag_omit_frame_pointer = !(USE_IX86_FRAME_POINTER || optimize_size);
       if (flag_asynchronous_unwind_tables == 2)
 	flag_asynchronous_unwind_tables = !USE_IX86_FRAME_POINTER;
@@ -4537,18 +4535,6 @@  ix86_option_optimization (int level, int
     flag_schedule_insns = 0;
 #endif
 
-  /* The default values of these switches depend on the TARGET_64BIT
-     that is not known at this moment.  Mark these values with 2 and
-     let user the to override these.  In case there is no command line
-     option specifying them, we will set the defaults in
-     ix86_option_override_internal.  */
-  if (optimize >= 1)
-    flag_omit_frame_pointer = 2;
-
-  /* For -O2 and beyond, turn on -fzee for x86_64 target. */
-  if (level > 1)
-    flag_zee = 2;
-
 #ifdef SUBTARGET_OPTIMIZATION_OPTIONS
   SUBTARGET_OPTIMIZATION_OPTIONS;
 #endif
Index: gcc/config/sh/sh.c
===================================================================
--- gcc/config/sh/sh.c	(revision 165519)
+++ gcc/config/sh/sh.c	(working copy)
@@ -728,10 +728,6 @@  sh_option_optimization (int level, int s
       if (!size)
 	target_flags |= MASK_SAVE_ALL_TARGET_REGS;
     }
-  /* If flag_schedule_insns is 1, we set it to 2 here so we know if
-     the user explicitly requested this to be on or off.  */
-  if (flag_schedule_insns > 0)
-    flag_schedule_insns = 2;
 }
 
 /* Implement TARGET_OPTION_INIT_STRUCT.  */
@@ -932,11 +928,12 @@  sh_option_override (void)
          <http://gcc.gnu.org/ml/gcc-patches/2005-10/msg00816.html>.  */
       else if (flag_exceptions)
 	{
-	  if (flag_schedule_insns == 1)
+	  if (flag_schedule_insns && global_options_set.x_flag_schedule_insns)
 	    warning (0, "ignoring -fschedule-insns because of exception handling bug");
 	  flag_schedule_insns = 0;
 	}
-      else if (flag_schedule_insns == 2)
+      else if (flag_schedule_insns
+	       && !global_options_set.x_flag_schedule_insns)
 	flag_schedule_insns = 0;
     }
 
Index: gcc/config/rs6000/rs6000.c
===================================================================
--- gcc/config/rs6000/rs6000.c	(revision 165519)
+++ gcc/config/rs6000/rs6000.c	(working copy)
@@ -3693,7 +3693,7 @@  rs6000_option_init_struct (struct gcc_op
 
   /* Enable section anchors by default.  */
   if (!TARGET_MACHO)
-    opts->x_flag_section_anchors = 2;
+    opts->x_flag_section_anchors = 1;
 }
 
 /* Implement TARGET_OPTION_DEFAULT_PARAMS.  */
Index: gcc/config/arm/arm.c
===================================================================
--- gcc/config/arm/arm.c	(revision 165519)
+++ gcc/config/arm/arm.c	(working copy)
@@ -22823,11 +22823,9 @@  arm_order_regs_for_local_alloc (void)
 static void
 arm_option_optimization (int level, int size ATTRIBUTE_UNUSED)
 {
-  /* Enable section anchors by default at -O1 or higher.
-     Use 2 to distinguish from an explicit -fsection-anchors
-     given on the command line.  */
+  /* Enable section anchors by default at -O1 or higher.  */
   if (level > 0)
-    flag_section_anchors = 2;
+    flag_section_anchors = 1;
 }
 
 /* Implement TARGET_FRAME_POINTER_REQUIRED.  */