Patchwork Ping / update: RFA: replace #ifdef with if/#if for HAVE_ATTR_*

login
register
mail settings
Submitter Joern Rennecke
Date Nov. 4, 2012, 7:25 p.m.
Message ID <20121104142500.4myx5afs0ko480cg-nzlynne@webmail.spamcop.net>
Download mbox | patch
Permalink /patch/197086/
State New
Headers show

Comments

Joern Rennecke - Nov. 4, 2012, 7:25 p.m.
Quoting Richard Sandiford <rdsandiford@googlemail.com>:

> OK with those changes for the rtl bits.  Can't approve the generator
> stuff though.

It appears we are momentarily short of reviewers for the generator files.

Till someone who feels he is competent to review the generator file patches
finds the time to review them, can we just patch the bits in final.c
(plus supporting hooks) that get in the way when revamping branch shortening?

This is a subset of the previous patch, with the requested change to use
gcc_assert in final.c, and a #ifdef / #else / #endif block at the top of
final.c to provide the things that we currently don't get from the generated
files.

Tested with building 'all-gcc' for i686-pc-linux-gnu X mmix-knuth-mmixware and
bootstrap on i686-pc-linux-gnu.  I'm also currently running a config-list.mk
test on gcc20.
2012-10-30  Joern Rennecke  <joern.rennecke@embecosm.com>

        * final.c [HAVE_ATTR_length] (HAVE_ATTR_length): Redefine as 1.
	[!HAVE_ATTR_length]: Include hooks.h and insn-addr.h.
	Define stubs for insn_*length* functions.
	[!HAVE_ATTR_length] (length_unit_log): Provide definition.
	[!HAVE_ATTR_length] (HAVE_ATTR_length): Define as 0.
	(asm_insn_count, align_fuzz): Always define.
        (insn_current_reference_address): Likewise.
        (init_insn_lengths): Use if (HAVE_ATTR_length) instead of
        #ifdef HAVE_ATTR_length.
        (get_attr_length_1, shorten_branches, final): Likewise.
        (final_scan_insn, output_asm_name): Likewise.
	* hooks.c (hook_int_rtx_unreachable): New function.
	* hooks.h (hook_int_rtx_unreachable): Declare.

Patch

Index: final.c
===================================================================
--- final.c	(revision 193137)
+++ final.c	(working copy)
@@ -198,15 +198,28 @@  Software Foundation; either version 3, o
 static int dialect_number;
 #endif
 
+/* Till we can get generator file patches reviewed, do our own stuff here.  */
+#ifdef HAVE_ATTR_length
+#undef HAVE_ATTR_length
+#define HAVE_ATTR_length 1
+#else /* !HAVE_ATTR_length */
+#include "hooks.h"
+#include "insn-addr.h"
+#define HAVE_ATTR_length 0
+const int length_unit_log = 0;
+#define insn_default_length hook_int_rtx_unreachable
+#define insn_min_length hook_int_rtx_unreachable
+#define insn_variable_length_p hook_int_rtx_unreachable
+#define insn_current_length hook_int_rtx_unreachable
+#endif /* !HAVE_ATTR_length */
+
 /* Nonnull if the insn currently being emitted was a COND_EXEC pattern.  */
 rtx current_insn_predicate;
 
 /* True if printing into -fdump-final-insns= dump.  */   
 bool final_insns_dump_p;
 
-#ifdef HAVE_ATTR_length
 static int asm_insn_count (rtx);
-#endif
 static void profile_function (FILE *);
 static void profile_after_prologue (FILE *);
 static bool notice_source_line (rtx, bool *);
@@ -224,9 +237,7 @@  static int alter_cond (rtx);
 #ifndef ADDR_VEC_ALIGN
 static int final_addr_vec_align (rtx);
 #endif
-#ifdef HAVE_ATTR_length
 static int align_fuzz (rtx, rtx, int, unsigned);
-#endif
 
 /* Initialize data in final at the beginning of a compilation.  */
 
@@ -362,9 +373,8 @@  init_insn_lengths (void)
       insn_lengths = 0;
       insn_lengths_max_uid = 0;
     }
-#ifdef HAVE_ATTR_length
-  INSN_ADDRESSES_FREE ();
-#endif
+  if (HAVE_ATTR_length)
+    INSN_ADDRESSES_FREE ();
   if (uid_align)
     {
       free (uid_align);
@@ -376,14 +386,15 @@  init_insn_lengths (void)
    get its actual length.  Otherwise, use FALLBACK_FN to calculate the
    length.  */
 static inline int
-get_attr_length_1 (rtx insn ATTRIBUTE_UNUSED,
-		   int (*fallback_fn) (rtx) ATTRIBUTE_UNUSED)
+get_attr_length_1 (rtx insn, int (*fallback_fn) (rtx))
 {
-#ifdef HAVE_ATTR_length
   rtx body;
   int i;
   int length = 0;
 
+  if (!HAVE_ATTR_length)
+    return 0;
+
   if (insn_lengths_max_uid > INSN_UID (insn))
     return insn_lengths[INSN_UID (insn)];
   else
@@ -432,11 +443,6 @@  get_attr_length_1 (rtx insn ATTRIBUTE_UN
   ADJUST_INSN_LENGTH (insn, length);
 #endif
   return length;
-#else /* not HAVE_ATTR_length */
-  return 0;
-#define insn_default_length 0
-#define insn_min_length 0
-#endif /* not HAVE_ATTR_length */
 }
 
 /* Obtain the current length of an insn.  If branch shortening has been done,
@@ -583,7 +589,6 @@  label_to_max_skip (rtx label)
   return 0;
 }
 
-#ifdef HAVE_ATTR_length
 /* The differences in addresses
    between a branch and its target might grow or shrink depending on
    the alignment the start insn of the range (the branch for a forward
@@ -686,7 +691,6 @@  insn_current_reference_address (rtx bran
 	      + align_fuzz (dest, seq, length_unit_log, ~0));
     }
 }
-#endif /* HAVE_ATTR_length */
 
 /* Compute branch alignments based on frequency information in the
    CFG.  */
@@ -851,14 +855,13 @@  struct rtl_opt_pass pass_compute_alignme
    slots.  */
 
 void
-shorten_branches (rtx first ATTRIBUTE_UNUSED)
+shorten_branches (rtx first)
 {
   rtx insn;
   int max_uid;
   int i;
   int max_log;
   int max_skip;
-#ifdef HAVE_ATTR_length
 #define MAX_CODE_ALIGN 16
   rtx seq;
   int something_changed = 1;
@@ -867,8 +870,6 @@  shorten_branches (rtx first ATTRIBUTE_UN
   int uid;
   rtx align_tab[MAX_CODE_ALIGN];
 
-#endif
-
   /* Compute maximum UID and allocate label_align / uid_shuid.  */
   max_uid = get_max_uid ();
 
@@ -975,7 +976,8 @@  shorten_branches (rtx first ATTRIBUTE_UN
 	      }
 	}
     }
-#ifdef HAVE_ATTR_length
+  if (!HAVE_ATTR_length)
+    return;
 
   /* Allocate the rest of the arrays.  */
   insn_lengths = XNEWVEC (int, max_uid);
@@ -1421,11 +1423,8 @@  shorten_branches (rtx first ATTRIBUTE_UN
     }
 
   free (varying_length);
-
-#endif /* HAVE_ATTR_length */
 }
 
-#ifdef HAVE_ATTR_length
 /* Given the body of an INSN known to be generated by an ASM statement, return
    the number of machine instructions likely to be generated for this insn.
    This is used to compute its length.  */
@@ -1442,7 +1441,6 @@  asm_insn_count (rtx body)
 
   return asm_str_count (templ);
 }
-#endif
 
 /* Return the number of machine instructions likely to be generated for the
    inline-asm template. */
@@ -1903,17 +1901,18 @@  final (rtx first, FILE *file, int optimi
   /* Output the insns.  */
   for (insn = first; insn;)
     {
-#ifdef HAVE_ATTR_length
-      if ((unsigned) INSN_UID (insn) >= INSN_ADDRESSES_SIZE ())
+      if (HAVE_ATTR_length)
 	{
-	  /* This can be triggered by bugs elsewhere in the compiler if
-	     new insns are created after init_insn_lengths is called.  */
-	  gcc_assert (NOTE_P (insn));
-	  insn_current_address = -1;
+	  if ((unsigned) INSN_UID (insn) >= INSN_ADDRESSES_SIZE ())
+	    {
+	      /* This can be triggered by bugs elsewhere in the compiler if
+		 new insns are created after init_insn_lengths is called.  */
+	      gcc_assert (NOTE_P (insn));
+	      insn_current_address = -1;
+	    }
+	  else
+	    insn_current_address = INSN_ADDRESSES (INSN_UID (insn));
 	}
-      else
-	insn_current_address = INSN_ADDRESSES (INSN_UID (insn));
-#endif /* HAVE_ATTR_length */
 
       dump_basic_block_info (file, insn, start_to_bb, end_to_bb,
                              bb_map_size, &bb_seqn);
@@ -2854,12 +2853,10 @@  final_scan_insn (rtx insn, FILE *file, i
 	    if (new_rtx == insn && PATTERN (new_rtx) == body)
 	      fatal_insn ("could not split insn", insn);
 
-#ifdef HAVE_ATTR_length
-	    /* This instruction should have been split in shorten_branches,
-	       to ensure that we would have valid length info for the
-	       splitees.  */
-	    gcc_unreachable ();
-#endif
+	    /* If we have a length attribute, this instruction should have
+	       been split in shorten_branches, to ensure that we would have
+	       valid length info for the splitees.  */
+	    gcc_assert (!HAVE_ATTR_length);
 
 	    return new_rtx;
 	  }
@@ -3293,10 +3290,11 @@  output_asm_name (void)
 	       insn_data[num].name);
       if (insn_data[num].n_alternatives > 1)
 	fprintf (asm_out_file, "/%d", which_alternative + 1);
-#ifdef HAVE_ATTR_length
-      fprintf (asm_out_file, "\t[length = %d]",
-	       get_attr_length (debug_insn));
-#endif
+
+      if (HAVE_ATTR_length)
+	fprintf (asm_out_file, "\t[length = %d]",
+		 get_attr_length (debug_insn));
+
       /* Clear this so only the first assembler insn
 	 of any rtl insn will get the special comment for -dp.  */
       debug_insn = 0;
Index: hooks.c
===================================================================
--- hooks.c	(revision 193137)
+++ hooks.c	(working copy)
@@ -203,6 +203,12 @@  hook_int_rtx_0 (rtx a ATTRIBUTE_UNUSED)
 }
 
 int
+hook_int_rtx_unreachable (rtx)
+{
+  gcc_unreachable ();
+}
+
+int
 hook_int_rtx_bool_0 (rtx a ATTRIBUTE_UNUSED, bool b ATTRIBUTE_UNUSED)
 {
   return 0;
Index: hooks.h
===================================================================
--- hooks.h	(revision 193137)
+++ hooks.h	(working copy)
@@ -75,6 +75,7 @@  extern int hook_int_uint_mode_1 (unsigne
 extern int hook_int_const_tree_0 (const_tree);
 extern int hook_int_const_tree_const_tree_1 (const_tree, const_tree);
 extern int hook_int_rtx_0 (rtx);
+extern int hook_int_rtx_unreachable (rtx);
 extern int hook_int_rtx_bool_0 (rtx, bool);
 extern int hook_int_rtx_mode_as_bool_0 (rtx, enum machine_mode, addr_space_t,
 					bool);