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]

[vta] discount debug insns in gcse hash tables sizes


gcse was recently changed to no longer compute cuid tables, and rely on
get_max_uid() instead to compute its hash tables sizes.

As a consequence, -fmin-insn-uid may change the generated code, and so
may debug insns, because different table sizes cause gcse-introduced
pseudos to be created in different orders.

This patch arranges for the total debug insn count to be maintained
while emitting debug insns, regardless of -fmin-insn-uid, and for debug
insns and any gap caused by -fmin-insn-uid to be discounted when
computing the hash tables sizes.

I'm installing this in the vta branch, to this fixes a bunch of
-fcompare-debug failures observed in bootstraps.

for  gcc/ChangeLog.vta
from  Alexandre Oliva  <aoliva@redhat.com>

	* emit-rtl.c (get_max_insn_count): New.
	(make_debug_insn_raw): Count debug insns past flag_min_insn_uid.
	(set_new_first_and_last_insn): Likewise.
	(init_emit): Check that flag_min_insn_uid is positive.
	* rtl.h (get_max_insn_count): New.
	* gcse.c (alloc_hash_table): Drop n_insns parameter.  Adjust all
	callers.
	
Index: gcc/gcse.c
===================================================================
--- gcc/gcse.c.orig	2009-05-12 15:40:54.000000000 -0300
+++ gcc/gcse.c	2009-05-15 04:07:17.000000000 -0300
@@ -464,7 +464,7 @@ static void record_last_reg_set_info (rt
 static void record_last_mem_set_info (rtx);
 static void record_last_set_info (rtx, const_rtx, void *);
 static void compute_hash_table (struct hash_table *);
-static void alloc_hash_table (int, struct hash_table *, int);
+static void alloc_hash_table (struct hash_table *, int);
 static void free_hash_table (struct hash_table *);
 static void compute_hash_table_work (struct hash_table *);
 static void dump_hash_table (FILE *, const char *, struct hash_table *);
@@ -1700,17 +1700,18 @@ compute_hash_table_work (struct hash_tab
 }
 
 /* Allocate space for the set/expr hash TABLE.
-   N_INSNS is the number of instructions in the function.
    It is used to determine the number of buckets to use.
    SET_P determines whether set or expression table will
    be created.  */
 
 static void
-alloc_hash_table (int n_insns, struct hash_table *table, int set_p)
+alloc_hash_table (struct hash_table *table, int set_p)
 {
   int n;
 
-  table->size = n_insns / 4;
+  n = get_max_insn_count ();
+
+  table->size = n / 4;
   if (table->size < 11)
     table->size = 11;
 
@@ -3956,7 +3957,7 @@ one_pre_gcse_pass (void)
   gcc_obstack_init (&gcse_obstack);
   alloc_gcse_mem ();
 
-  alloc_hash_table (get_max_uid (), &expr_hash_table, 0);
+  alloc_hash_table (&expr_hash_table, 0);
   add_noreturn_fake_exit_edges ();
   if (flag_gcse_lm)
     compute_ld_motion_mems ();
@@ -4437,7 +4438,7 @@ one_code_hoisting_pass (void)
   gcc_obstack_init (&gcse_obstack);
   alloc_gcse_mem ();
 
-  alloc_hash_table (get_max_uid (), &expr_hash_table, 0);
+  alloc_hash_table (&expr_hash_table, 0);
   compute_hash_table (&expr_hash_table);
   if (dump_file)
     dump_hash_table (dump_file, "Code Hosting Expressions", &expr_hash_table);
@@ -4977,7 +4978,7 @@ one_cprop_pass (void)
   implicit_sets = XCNEWVEC (rtx, last_basic_block);
   find_implicit_sets ();
 
-  alloc_hash_table (get_max_uid (), &set_hash_table, 1);
+  alloc_hash_table (&set_hash_table, 1);
   compute_hash_table (&set_hash_table);
 
   /* Free implicit_sets before peak usage.  */
Index: gcc/emit-rtl.c
===================================================================
--- gcc/emit-rtl.c.orig	2009-05-12 03:47:03.000000000 -0300
+++ gcc/emit-rtl.c	2009-05-15 04:01:13.000000000 -0300
@@ -2314,8 +2314,10 @@ set_new_first_and_last_insn (rtx first, 
   last_insn = last;
   cur_insn_uid = 0;
 
-  if (flag_min_insn_uid)
+  if (flag_min_insn_uid || MAY_HAVE_DEBUG_INSNS)
     {
+      int debug_count = 0;
+
       cur_insn_uid = flag_min_insn_uid - 1;
       cur_debug_insn_uid = 0;
 
@@ -2323,9 +2325,16 @@ set_new_first_and_last_insn (rtx first, 
 	if (INSN_UID (insn) < flag_min_insn_uid)
 	  cur_debug_insn_uid = MAX (cur_debug_insn_uid, INSN_UID (insn));
 	else
-	  cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn));
+	  {
+	    cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn));
+	    if (DEBUG_INSN_P (insn))
+	      debug_count++;
+	  }
 
-      cur_debug_insn_uid++;
+      if (debug_count)
+	cur_debug_insn_uid = flag_min_insn_uid + debug_count;
+      else
+	cur_debug_insn_uid++;
     }
   else
     for (insn = first; insn; insn = NEXT_INSN (insn))
@@ -3010,6 +3019,27 @@ get_max_uid (void)
 {
   return cur_insn_uid;
 }
+
+/* Return the number of actual (non-debug) insns emitted in this
+   function.  */
+
+int
+get_max_insn_count (void)
+{
+  int n = cur_insn_uid;
+
+  /* The table size must be stable across -g, to avoid codegen
+     differences due to debug insns, and not be affected by
+     -fmin-insn-uid, to avoid excessive table size and to simplify
+     debugging of -fcompare-debug failures.  */
+  if (cur_debug_insn_uid > flag_min_insn_uid)
+    n -= cur_debug_insn_uid;
+  else
+    n -= flag_min_insn_uid;
+
+  return n;
+}
+
 
 /* Return the next insn.  If it is a SEQUENCE, return the first insn
    of the sequence.  */
@@ -3585,9 +3615,9 @@ make_debug_insn_raw (rtx pattern)
   rtx insn;
 
   insn = rtx_alloc (DEBUG_INSN);
-  INSN_UID (insn) = cur_debug_insn_uid < flag_min_insn_uid
-    ? cur_debug_insn_uid++
-    : cur_insn_uid++;
+  INSN_UID (insn) = cur_debug_insn_uid++;
+  if (cur_debug_insn_uid > flag_min_insn_uid)
+    INSN_UID (insn) = cur_insn_uid++;
 
   PATTERN (insn) = pattern;
   INSN_CODE (insn) = -1;
@@ -5492,7 +5522,10 @@ init_emit (void)
   first_insn = NULL;
   last_insn = NULL;
   if (flag_min_insn_uid)
-    cur_insn_uid = flag_min_insn_uid;
+    {
+      cur_insn_uid = flag_min_insn_uid;
+      gcc_assert (flag_min_insn_uid > 0);
+    }
   else
     cur_insn_uid = 1;
   cur_debug_insn_uid = 1;
Index: gcc/rtl.h
===================================================================
--- gcc/rtl.h.orig	2009-05-12 15:19:27.000000000 -0300
+++ gcc/rtl.h	2009-05-15 03:59:15.000000000 -0300
@@ -2162,6 +2162,7 @@ extern void set_used_flags (rtx);
 extern void reorder_insns (rtx, rtx, rtx);
 extern void reorder_insns_nobb (rtx, rtx, rtx);
 extern int get_max_uid (void);
+extern int get_max_insn_count (void);
 extern int in_sequence_p (void);
 extern void force_next_line_note (void);
 extern void init_emit (void);

-- 
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist      Red Hat Brazil Compiler Engineer

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