public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch, ping] PR 38018 & 37565 - Option pragma and attribute handling
@ 2009-10-22 16:49 Steve Ellcey
  2009-10-28 14:10 ` Ian Lance Taylor
  0 siblings, 1 reply; 3+ messages in thread
From: Steve Ellcey @ 2009-10-22 16:49 UTC (permalink / raw)
  To: gcc-patches

This is a resubmission / ping for a patch to fix PR target/38018 and
PR middle-end/37565.  The original patch was submitted back in June here:

http://gcc.gnu.org/ml/gcc-patches/2009-06/msg00348.html

I have updated it so it would apply to the ToT but otherwise made
no changes to it.  I got no approval or rejection last time so
any comments would be welcome.

--------

This patch fixes PR target/38018, where GCC aborts on IA64 because we
don't (can't) override options after changing them via an optimize
attribute or pragma.  It also addresses PR middle-end/37565, though
other targets may need to define OVERRIDE_OPTIONS_AFTER_CHANGE to work
correctly.

I used HJ's idea of having a new macro but it is a little different in
that the new macro, OVERRIDE_OPTIONS_AFTER_CHANGE, is only called when
changing the opt level via an attribute or pragma (and when changing it
back after reaching the end of the affected code).  It is not called
directly at the beginning of the program, but if you want the code
executed then you can have OVERRIDE_OPTIONS call the same code.  This is
what I did for IA64 (ia64_override_options calls
ia64_override_options_after_change).

The tricky part here was realizing that I had to have
cl_target_option_restore call this macro in addition to having
parse_optimize_options call it so that we are still OK after restoring
the options after changing them via the attribute.

Tested on IA64 HP-UX and Linux with no regressions.

OK for checkin?

Steve Ellcey
sje@cup.hp.com

2009-10-22  Steve Ellcey  <sje@cup.hp.com>

	PR middle-end/37565
	PR target/38018
	* doc/tm.texi (OVERRIDE_OPTIONS): Update.
	(OVERRIDE_OPTIONS_AFTER_CHANGE): New.
	* optc-gen.awk (cl_target_option_restore): Include call to 
	OVERRIDE_OPTIONS_AFTER_CHANGE.
	* c-common.c (parse_optimize_options): Call
	OVERRIDE_OPTIONS_AFTER_CHANGE.
	* ia64-protos.h (ia64_override_options_after_change): New.
	* ia64.h (OVERRIDE_OPTIONS_AFTER_CHANGE): New.
	* ia64.c (ia64_override_options_after_change): New.
	(ia64_override_options) Add call to above.


Index: doc/tm.texi
===================================================================
--- doc/tm.texi	(revision 153444)
+++ doc/tm.texi	(working copy)
@@ -813,6 +813,20 @@ parsed.
 
 Don't use this macro to turn on various extra optimizations for
 @option{-O}.  That is what @code{OPTIMIZATION_OPTIONS} is for.
+
+If you need to do something whenever the optimization level is
+changed via the optimize attribute or pragma, see
+@code{OVERRIDE_OPTIONS_AFTER_CHANGE}
+@end defmac
+
+@defmac OVERRIDE_OPTIONS_AFTER_CHANGE
+This macro is like @code{OVERRIDE_OPTIONS} but is called when the
+optimize level is changed via an attribute or pragma or when it
+is reset at the end of the code affected by the attribute or pragma.
+It is not called at the beginning of compilation when
+@code{OVERRIDE_OPTIONS} is called so if you want to perform these
+actions then, you should have @code{OVERRIDE_OPTIONS} call
+@code{OVERRIDE_OPTIONS_AFTER_CHANGE}.
 @end defmac
 
 @defmac C_COMMON_OVERRIDE_OPTIONS
Index: c-common.c
===================================================================
--- c-common.c	(revision 153444)
+++ c-common.c	(working copy)
@@ -7797,6 +7797,10 @@ parse_optimize_options (tree args, bool 
   /* Now parse the options.  */
   decode_options (opt_argc, opt_argv);
 
+#ifdef OVERRIDE_OPTIONS_AFTER_CHANGE
+  OVERRIDE_OPTIONS_AFTER_CHANGE;
+#endif
+
   /* Don't allow changing -fstrict-aliasing.  */
   flag_strict_aliasing = saved_flag_strict_aliasing;
 
Index: config/ia64/ia64-protos.h
===================================================================
--- config/ia64/ia64-protos.h	(revision 153444)
+++ config/ia64/ia64-protos.h	(working copy)
@@ -89,6 +89,7 @@ extern int ia64_eh_uses (int);
 extern void emit_safe_across_calls (void);
 extern void ia64_init_builtins (void);
 extern void ia64_override_options (void);
+extern void ia64_override_options_after_change (void);
 extern int ia64_dbx_register_number (int);
 
 extern rtx ia64_return_addr_rtx (HOST_WIDE_INT, rtx);
Index: config/ia64/ia64.h
===================================================================
--- config/ia64/ia64.h	(revision 153444)
+++ config/ia64/ia64.h	(working copy)
@@ -123,6 +123,13 @@ extern enum processor_type ia64_tune;
 
 #define OVERRIDE_OPTIONS ia64_override_options ()
 
+/* Since options can be changed by attributes or pragmas
+   OVERRIDE_OPTIONS_AFTER_CHANGE is called after the options are
+   changed in order to reset anything that needs to be fixed
+   for a particular target machine.  */
+
+#define OVERRIDE_OPTIONS_AFTER_CHANGE ia64_override_options_after_change ()
+
 /* Some machines may desire to change what optimizations are performed for
    various optimization levels.  This macro, if defined, is executed once just
    after the optimization level is determined and before the remainder of the
Index: config/ia64/ia64.c
===================================================================
--- config/ia64/ia64.c	(revision 153444)
+++ config/ia64/ia64.c	(working copy)
@@ -5496,6 +5496,25 @@ ia64_override_options (void)
   if (TARGET_AUTO_PIC)
     target_flags |= MASK_CONST_GP;
 
+  ia64_section_threshold = g_switch_set ? g_switch_value : IA64_DEFAULT_GVALUE;
+
+  init_machine_status = ia64_init_machine_status;
+
+  if (align_functions <= 0)
+    align_functions = 64;
+  if (align_loops <= 0)
+    align_loops = 32;
+  if (TARGET_ABI_OPEN_VMS)
+    flag_no_common = 1;
+
+  ia64_override_options_after_change();
+}
+
+/* Implement OVERRIDE_OPTIONS_AFTER_CHANGE.  */
+
+void
+ia64_override_options_after_change (void)
+{
   ia64_flag_schedule_insns2 = flag_schedule_insns_after_reload;
   flag_schedule_insns_after_reload = 0;
 
@@ -5517,18 +5536,6 @@ ia64_override_options (void)
          a transformation.  */
       flag_auto_inc_dec = 0;
     }
-
-  ia64_section_threshold = g_switch_set ? g_switch_value : IA64_DEFAULT_GVALUE;
-
-  init_machine_status = ia64_init_machine_status;
-
-  if (align_functions <= 0)
-    align_functions = 64;
-  if (align_loops <= 0)
-    align_loops = 32;
-
-  if (TARGET_ABI_OPEN_VMS)
-    flag_no_common = 1;
 }
 
 /* Initialize the record of emitted frame related registers.  */

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

* Re: [patch, ping] PR 38018 & 37565 - Option pragma and attribute handling
  2009-10-22 16:49 [patch, ping] PR 38018 & 37565 - Option pragma and attribute handling Steve Ellcey
@ 2009-10-28 14:10 ` Ian Lance Taylor
  2009-10-28 21:09   ` Steve Ellcey
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2009-10-28 14:10 UTC (permalink / raw)
  To: sje; +Cc: gcc-patches

Steve Ellcey <sje@cup.hp.com> writes:

> 2009-10-22  Steve Ellcey  <sje@cup.hp.com>
>
> 	PR middle-end/37565
> 	PR target/38018
> 	* doc/tm.texi (OVERRIDE_OPTIONS): Update.
> 	(OVERRIDE_OPTIONS_AFTER_CHANGE): New.
> 	* optc-gen.awk (cl_target_option_restore): Include call to 
> 	OVERRIDE_OPTIONS_AFTER_CHANGE.
> 	* c-common.c (parse_optimize_options): Call
> 	OVERRIDE_OPTIONS_AFTER_CHANGE.
> 	* ia64-protos.h (ia64_override_options_after_change): New.
> 	* ia64.h (OVERRIDE_OPTIONS_AFTER_CHANGE): New.
> 	* ia64.c (ia64_override_options_after_change): New.
> 	(ia64_override_options) Add call to above.

I can't see any reason to make this a macro rather than a target hook.
The default for the target hook would be hook_void_void.  This patch
is OK if you make it a target hook.

Thanks.

Ian

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

* Re: [patch, ping] PR 38018 & 37565 - Option pragma and attribute  handling
  2009-10-28 14:10 ` Ian Lance Taylor
@ 2009-10-28 21:09   ` Steve Ellcey
  0 siblings, 0 replies; 3+ messages in thread
From: Steve Ellcey @ 2009-10-28 21:09 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-patches

On Wed, 2009-10-28 at 07:03 -0700, Ian Lance Taylor wrote:

> I can't see any reason to make this a macro rather than a target hook.
> The default for the target hook would be hook_void_void.  This patch
> is OK if you make it a target hook.
> 
> Thanks.
> 
> Ian

Here is the patch reworked to use a target hook instead of a macro.  I
will check it in after I get through a new bootstrap and test to make
sure I didn't break anything in the change.

Steve Ellcey
sje@cup.hp.com


2009-10-28  Steve Ellcey  <sje@cup.hp.com>

        PR middle-end/37565
        PR target/38018
        * doc/tm.texi (OVERRIDE_OPTIONS): Update.
        (TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE): New.
        * optc-gen.awk (cl_target_option_restore): Include call to 
        targetm.override_options_after_change.
        * target-def.h (TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE): New.
        * target.h (override_options_after_change): New.
        * c-common.c (parse_optimize_options): Call
        targetm.override_options_after_change.
        * config/ia64/ia64.c (TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE): New.
        (ia64_override_options_after_change): New.
        (ia64_override_options) Add call to above.



Index: doc/tm.texi
===================================================================
--- doc/tm.texi	(revision 153642)
+++ doc/tm.texi	(working copy)
@@ -814,8 +814,22 @@ parsed.
 
 Don't use this macro to turn on various extra optimizations for
 @option{-O}.  That is what @code{OPTIMIZATION_OPTIONS} is for.
+
+If you need to do something whenever the optimization level is
+changed via the optimize attribute or pragma, see
+@code{TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE}
 @end defmac
 
+@deftypefn {Target Hook} void TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE
(void)
+This target function is similar to the macro @code{OVERRIDE_OPTIONS}
+but is called when the optimize level is changed via an attribute or
+pragma or when it is reset at the end of the code affected by the
+attribute or pragma.  It is not called at the beginning of compilation
+when @code{OVERRIDE_OPTIONS} is called so if you want to perform these
+actions then, you should have @code{OVERRIDE_OPTIONS} call
+@code{TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE}.
+@end deftypefn
+
 @defmac C_COMMON_OVERRIDE_OPTIONS
 This is similar to @code{OVERRIDE_OPTIONS} but is only used in the C
 language frontends (C, Objective-C, C++, Objective-C++) and so can be
Index: optc-gen.awk
===================================================================
--- optc-gen.awk	(revision 153642)
+++ optc-gen.awk	(working copy)
@@ -327,6 +327,7 @@ for (i = 0; i < n_opt_char; i++) {
 	print "  " var_opt_char[i] " = ptr->" var_opt_char[i] ";";
 }
 
+print "  targetm.override_options_after_change ();";
 print "}";
 
 print "";
Index: target-def.h
===================================================================
--- target-def.h	(revision 153642)
+++ target-def.h	(working copy)
@@ -410,6 +410,8 @@
 
 #define TARGET_DEFAULT_TARGET_FLAGS 0
 
+#define TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE hook_void_void
+
 #define TARGET_HANDLE_OPTION hook_bool_size_t_constcharptr_int_true
 #define TARGET_HELP NULL
 
@@ -905,6 +907,7 @@
   TARGET_SCHED,					\
   TARGET_VECTORIZE,				\
   TARGET_DEFAULT_TARGET_FLAGS,			\
+  TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE,		\
   TARGET_HANDLE_OPTION,				\
   TARGET_HELP,					\
   TARGET_EH_RETURN_FILTER_MODE,			\
Index: target.h
===================================================================
--- target.h	(revision 153642)
+++ target.h	(working copy)
@@ -500,6 +500,11 @@ struct gcc_target
   /* The initial value of target_flags.  */
   int default_target_flags;
 
+  /* Allow target specific overriding of option settings after options
have
+     been changed by an attribute or pragma or when it is reset at the
+     end of the code affected by an attribute or pragma.  */
+  void (* override_options_after_change) (void);
+
   /* Handle target switch CODE (an OPT_* value).  ARG is the argument
      passed to the switch; it is NULL if no argument was.  VALUE is the
      value of ARG if CODE specifies a UInteger option, otherwise it is
Index: c-common.c
===================================================================
--- c-common.c	(revision 153642)
+++ c-common.c	(working copy)
@@ -7825,6 +7825,8 @@ parse_optimize_options (tree args, bool 
   /* Now parse the options.  */
   decode_options (opt_argc, opt_argv);
 
+  targetm.override_options_after_change();
+
   /* Don't allow changing -fstrict-aliasing.  */
   flag_strict_aliasing = saved_flag_strict_aliasing;
 
Index: config/ia64/ia64.c
===================================================================
--- config/ia64/ia64.c	(revision 153642)
+++ config/ia64/ia64.c	(working copy)
@@ -303,6 +303,7 @@ static enum machine_mode ia64_promote_fu
 						     const_tree,
 						     int);
 static void ia64_trampoline_init (rtx, tree, rtx);
+static void ia64_override_options_after_change (void);
 \f
 /* Table of valid machine attributes.  */
 static const struct attribute_spec ia64_attribute_table[] =
@@ -536,6 +537,9 @@ static const struct attribute_spec ia64_
 #undef TARGET_TRAMPOLINE_INIT
 #define TARGET_TRAMPOLINE_INIT ia64_trampoline_init
 
+#undef TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE
+#define TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE
ia64_override_options_after_change
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 \f
 typedef enum
@@ -5504,6 +5508,25 @@ ia64_override_options (void)
     flag_ira_loop_pressure = 1;
 
 
+  ia64_section_threshold = g_switch_set ? g_switch_value :
IA64_DEFAULT_GVALUE;
+
+  init_machine_status = ia64_init_machine_status;
+
+  if (align_functions <= 0)
+    align_functions = 64;
+  if (align_loops <= 0)
+    align_loops = 32;
+  if (TARGET_ABI_OPEN_VMS)
+    flag_no_common = 1;
+
+  ia64_override_options_after_change();
+}
+
+/* Implement targetm.override_options_after_change.  */
+
+static void
+ia64_override_options_after_change (void)
+{
   ia64_flag_schedule_insns2 = flag_schedule_insns_after_reload;
   flag_schedule_insns_after_reload = 0;
 
@@ -5525,18 +5548,6 @@ ia64_override_options (void)
          a transformation.  */
       flag_auto_inc_dec = 0;
     }
-
-  ia64_section_threshold = g_switch_set ? g_switch_value :
IA64_DEFAULT_GVALUE;
-
-  init_machine_status = ia64_init_machine_status;
-
-  if (align_functions <= 0)
-    align_functions = 64;
-  if (align_loops <= 0)
-    align_loops = 32;
-
-  if (TARGET_ABI_OPEN_VMS)
-    flag_no_common = 1;
 }
 
 /* Initialize the record of emitted frame related registers.  */



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

end of thread, other threads:[~2009-10-28 21:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-22 16:49 [patch, ping] PR 38018 & 37565 - Option pragma and attribute handling Steve Ellcey
2009-10-28 14:10 ` Ian Lance Taylor
2009-10-28 21:09   ` Steve Ellcey

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).