This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Preliminary patch to fix some function specific option breakage


I've been iterating with H. J. Lu about the breakage on the IA-64, which was
due to the cold attribute turning on options that that the backend had turned
off in OVERRIDE_OPTIONS.  This patch should fix the ia-64, and not enable
scheduling on the x86.

On the theory that there are other ports that have the same issue, this patch
also disables cold/hot attributes on ports that define OVERRIDE_OPTIONS but not
the new SECONDARY_OVERRIDE_OPTIONS until we can fix the ports.  At this point,
I just wrote the patch and did some preliminary checking on it, but I'm posting
it now to get feedback from the other port maintainers to see if it allows
their ports to bootstrap where previously it did not.

2008-07-25  Michael Meissner  <gnu@the-meissners.org>

	* doc/tm.texi (SECONDARY_OVERRIDE_OPTIONS): Document.

	* opts.c (decode_options): If SECONDARY_OVERRIDE_OPTIONS is
	defined, run it.

	* c-common.c (handle_hot_attribute): Do not change the
	optimization level if a port has not been modified for function
	specific option support.
	(handle_cold_attribute): Ditto.

	* config/i386/i386.h (SECONDARY_OVERRIDE_OPTIONS): Define, turn
	off scheduling unless the target would benefit from it.

	* config/ia64/ia64.c (ia64_override_options): Don't set
	ia64_flag_schedule_insns2 or flag_schedule_insns_after_reload
	here, move code to ia64_secondary_override_options.
	(ia64_secondary_override_options): New functions, set
	ia64_flag_schedule_insns2 and flag_schedule_insns_after_reload
	based on flag_schedule_insns_after_reload.

	* config/ia64/ia64.h (SECONDARY_OVERRIDE_OPTIONS): New macro,
	define.

	* config/ia64/ia64-protos.h (ia64_secondary_override_options): Add
	declaration.

Index: gcc/doc/tm.texi
===================================================================
--- gcc/doc/tm.texi	(revision 138117)
+++ gcc/doc/tm.texi	(working copy)
@@ -814,6 +814,12 @@ Don't use this macro to turn on various 
 @option{-O}.  That is what @code{OPTIMIZATION_OPTIONS} is for.
 @end defmac
 
+@defmac SECONDARY_OVERRIDE_OPTIONS
+This is similar to @code{OVERRIDE_OPTIONS} but it is run after the
+compiler processes the @code{optimize}, @code{hot}, or @code{cold}
+attributes to change the optimization options.
+@end defmac
+
 @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: gcc/opts.c
===================================================================
--- gcc/opts.c	(revision 138117)
+++ gcc/opts.c	(working copy)
@@ -1066,6 +1066,11 @@ decode_options (unsigned int argc, const
       flag_unwind_tables = targetm.unwind_tables_default;
     }
 
+#ifdef SECONDARY_OVERRIDE_OPTIONS
+  /* Some machines may reject certain combinations of options.  */
+  SECONDARY_OVERRIDE_OPTIONS;
+#endif
+
 #ifdef OPTIMIZATION_OPTIONS
   /* Allow default optimizations to be specified on a per-machine basis.  */
   OPTIMIZATION_OPTIONS (optimize, optimize_size);
Index: gcc/c-common.c
===================================================================
--- gcc/c-common.c	(revision 138117)
+++ gcc/c-common.c	(working copy)
@@ -5052,7 +5052,10 @@ handle_hot_attribute (tree *node, tree n
 	  tree old_opts = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node);
 
 	  /* If we are not at -O3, but are optimizing, turn on -O3
-	     optimizations just for this one function.  */
+	     optimizations just for this one function.  XXX -- for now only do
+	     this if SECONDARY_OVERRIDE_OPTIONS is defined when
+	     OVERRIDE_OPTIONS which indicates that a port has been fixed.  */
+#if !defined(OVERRIDE_OPTIONS) || defined(SECONDARY_OVERRIDE_OPTIONS)
 	  if (((optimize > 0 && optimize < 3) || optimize_size)
 	      && (!old_opts || old_opts == optimization_default_node))
 	    {
@@ -5071,6 +5074,7 @@ handle_hot_attribute (tree *node, tree n
 	      DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node)
 		= optimization_hot_node;
 	    }
+#endif
 	}
       /* Most of the rest of the hot processing is done later with
 	 lookup_attribute.  */
@@ -5103,7 +5107,10 @@ handle_cold_attribute (tree *node, tree 
 	  tree old_opts = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node);
 
 	  /* If we are optimizing, but not optimizing for space, turn on -Os
-	     optimizations just for this one function.  */
+	     optimizations just for this one function.  XXX -- for now only do
+	     this if SECONDARY_OVERRIDE_OPTIONS is defined when
+	     OVERRIDE_OPTIONS which indicates that a port has been fixed.  */
+#if !defined(OVERRIDE_OPTIONS) || defined(SECONDARY_OVERRIDE_OPTIONS)
 	  if (optimize && !optimize_size
 	      && (!old_opts || old_opts == optimization_default_node))
 	    {
@@ -5122,6 +5129,7 @@ handle_cold_attribute (tree *node, tree 
 	      DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node)
 		= optimization_cold_node;
 	    }
+#endif
 	}
     }
   else
Index: gcc/config/i386/i386.h
===================================================================
--- gcc/config/i386/i386.h	(revision 138117)
+++ gcc/config/i386/i386.h	(working copy)
@@ -476,6 +476,17 @@ enum calling_abi
 
 #define OVERRIDE_OPTIONS override_options (true)
 
+
+/* Like OVERRIDE_OPTIONS, but run after the optimize, hot, or cold attributes
+   are processed.  */
+
+#define SECONDARY_OVERRIDE_OPTIONS					\
+do {									\
+  if (!TARGET_SCHEDULE)							\
+    flag_schedule_insns_after_reload = flag_schedule_insns = 0;		\
+} while (0)
+
+
 /* Define this to change the optimizations performed by default.  */
 #define OPTIMIZATION_OPTIONS(LEVEL, SIZE) \
   optimization_options ((LEVEL), (SIZE))
Index: gcc/config/ia64/ia64.c
===================================================================
--- gcc/config/ia64/ia64.c	(revision 138117)
+++ gcc/config/ia64/ia64.c	(working copy)
@@ -5232,14 +5232,20 @@ ia64_override_options (void)
       TARGET_INLINE_SQRT = INL_MAX_THR;
     }
 
-  ia64_flag_schedule_insns2 = flag_schedule_insns_after_reload;
-  flag_schedule_insns_after_reload = 0;
-
   ia64_section_threshold = g_switch_set ? g_switch_value : IA64_DEFAULT_GVALUE;
 
   init_machine_status = ia64_init_machine_status;
 }
 
+/* Implement SECONDARY_OVERRIDE_OPTIONS.  */
+
+void
+ia64_secondary_override_options ()
+{
+  ia64_flag_schedule_insns2 = flag_schedule_insns_after_reload;
+  flag_schedule_insns_after_reload = 0;
+}
+
 /* Initialize the record of emitted frame related registers.  */
 
 void ia64_init_expanders (void)
Index: gcc/config/ia64/ia64.h
===================================================================
--- gcc/config/ia64/ia64.h	(revision 138117)
+++ gcc/config/ia64/ia64.h	(working copy)
@@ -121,6 +121,11 @@ extern enum processor_type ia64_tune;
 
 #define OVERRIDE_OPTIONS ia64_override_options ()
 
+/* Like OVERRIDE_OPTIONS, but run after the optimize, hot, or cold attributes
+   are processed.  */
+
+#define SECONDARY_OVERRIDE_OPTIONS ia64_secondary_override_options ()
+
 /* 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: gcc/config/ia64/ia64-protos.h
===================================================================
--- gcc/config/ia64/ia64-protos.h	(revision 138117)
+++ gcc/config/ia64/ia64-protos.h	(working copy)
@@ -93,6 +93,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_secondary_override_options (void);
 extern int ia64_dbx_register_number (int);
 
 extern rtx ia64_return_addr_rtx (HOST_WIDE_INT, rtx);


-- 
Michael Meissner
email: gnu@the-meissners.org
http://www.the-meissners.org


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]