PATCH: insn-attrtab vs. VM usage

Robert Lipe robertl@sco.com
Mon Oct 25 11:22:00 GMT 1999


Building insn-attrtab on my x86 targets would deplete VM (128Mb core +
150-300Mb of swap) when stage1/gcc hit insn-attrtab.o.  The problem was
that gcse on one of the large functions would go nuts consuming memory.
The problem disappeared when the bootstrap compiler had an intrinsic
alloca available.  It only showed up when using c-alloca.  I did find
a solution with a stragetically located alloca(0) that "cured" it, but
Mark encouraged me to take the moral high grounds.

This patch banishes alloca from gcse.c and therefore gives bounds
checkers a shot at catching naughtiness.  It's just an additional gift
that it happens to bootstrap once again.  GCC still isn't going to win
many compilation time benchmarks on this file, but it at least will
three-stage now.

Thanx to Mark and Jeff for providing fishing lessons.

 * gcse.c (expr_reaches_here_p): Use gmalloc and explit free instead
 of alloca.
 (pre_gcse): Likewise.
 (hoist_expr_reaches_here_p): Likewise.
 (hoist_code): Likewise.
 (pre_expr_reaches_here_p): Replace alloca with gmalloc.   Move core 
 code to ...
 (pre_expr_reaches_here_p_work): ... here.

Index: gcse.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/gcse.c,v
retrieving revision 1.58
diff -u -p -r1.58 gcse.c
--- gcse.c	1999/10/24 19:23:11	1.58
+++ gcse.c	1999/10/25 17:30:24
@@ -2892,7 +2892,7 @@ expr_reaches_here_p (occr, expr, bb, che
 
   if (visited == NULL)
     {
-      visited = (char *) alloca (n_basic_blocks);
+      visited = (char *) gmalloc (n_basic_blocks);
       bzero (visited, n_basic_blocks);
     }
 
@@ -4178,7 +4178,7 @@ compute_pre_data ()
    the closest such expression.  */
 
 static int
-pre_expr_reaches_here_p (occr_bb, expr, bb, check_pre_comp, visited)
+pre_expr_reaches_here_p_work (occr_bb, expr, bb, check_pre_comp, visited)
      int occr_bb;
      struct expr *expr;
      int bb;
@@ -4187,12 +4187,6 @@ pre_expr_reaches_here_p (occr_bb, expr, 
 {
   edge pred;
 
-  if (visited == NULL)
-    {
-      visited = (char *) alloca (n_basic_blocks);
-      bzero (visited, n_basic_blocks);
-    }
-
   for (pred = BASIC_BLOCK (bb)->pred; pred != NULL; pred = pred->pred_next)
     {
       int pred_bb = pred->src->index;
@@ -4230,6 +4224,36 @@ pre_expr_reaches_here_p (occr_bb, expr, 
   /* All paths have been checked.  */
   return 0;
 }
+
+/* The wrapper for pre_expr_reaches_here_work that ensures that any
+   memory allocated for that function is returned. */
+
+static int
+pre_expr_reaches_here_p (occr_bb, expr, bb, check_pre_comp, visited)
+     int occr_bb;
+     struct expr *expr;
+     int bb;
+     int check_pre_comp;
+     char *visited;
+{
+  int rval;
+  int visited_allocated_locally = 0;
+
+  if (visited == NULL)
+    {
+      visited = (char *) gmalloc (n_basic_blocks);
+      visited_allocated_locally = 1;
+      bzero (visited, n_basic_blocks);
+    }
+
+  rval = pre_expr_reaches_here_p_work(occr_bb, expr, bb, check_pre_comp, 
+				      visited);
+
+  if (visited_allocated_locally) 
+    free (visited);
+
+  return (rval);
+}
 
 
 /* Given an expr, generate RTL which we can insert at the end of a BB,
@@ -4719,7 +4743,7 @@ pre_gcse ()
   /* Compute a mapping from expression number (`bitmap_index') to
      hash table entry.  */
 
-  index_map = (struct expr **) alloca (n_exprs * sizeof (struct expr *));
+  index_map = (struct expr **) gmalloc (n_exprs * sizeof (struct expr *));
   bzero ((char *) index_map, n_exprs * sizeof (struct expr *));
   for (i = 0; i < expr_hash_table_size; i++)
     {
@@ -4749,6 +4773,7 @@ pre_gcse ()
       changed = 1;
     }
 
+  free (index_map);
   free (pre_redundant_insns);
 
   return changed;
@@ -4985,10 +5010,10 @@ delete_null_pointer_checks (f)
 
   /* We need predecessor/successor lists as well as pred/succ counts for
      each basic block.  */
-  s_preds = (int_list_ptr *) alloca (n_basic_blocks * sizeof (int_list_ptr));
-  s_succs = (int_list_ptr *) alloca (n_basic_blocks * sizeof (int_list_ptr));
-  num_preds = (int *) alloca (n_basic_blocks * sizeof (int));
-  num_succs = (int *) alloca (n_basic_blocks * sizeof (int));
+  s_preds = (int_list_ptr *) gmalloc (n_basic_blocks * sizeof (int_list_ptr));
+  s_succs = (int_list_ptr *) gmalloc (n_basic_blocks * sizeof (int_list_ptr));
+  num_preds = (int *) gmalloc (n_basic_blocks * sizeof (int));
+  num_succs = (int *) gmalloc (n_basic_blocks * sizeof (int));
   compute_preds_succs (s_preds, s_succs, num_preds, num_succs);
 
   /* Allocate bitmaps to hold local and global properties.  */
@@ -5141,6 +5166,12 @@ delete_null_pointer_checks (f)
   /* Free storage allocated by find_basic_blocks.  */
   free_basic_block_vars (0);
 
+  /* Free our local predecessor/successor lists. */
+  free (s_preds);
+  free (s_succs);
+  free (num_preds);
+  free (num_succs);
+
   /* Free bitmaps.  */
   free (nonnull_local);
   free (nonnull_killed);
@@ -5273,10 +5304,13 @@ hoist_expr_reaches_here_p (expr_bb, expr
      char *visited;
 {
   edge pred;
+  int visited_allocated_locally = 0;
+  
 
   if (visited == NULL)
     {
-      visited = (char *) alloca (n_basic_blocks);
+      visited = (char *) gmalloc (n_basic_blocks);
+      visited_allocated_locally = 1;
       bzero (visited, n_basic_blocks);
     }
 
@@ -5303,7 +5337,8 @@ hoist_expr_reaches_here_p (expr_bb, expr
 	    break;
 	}
     }
-
+  if (visited_allocated_locally) 
+    free (visited);
   return (pred == NULL);
 }
 
@@ -5319,7 +5354,7 @@ hoist_code ()
   /* Compute a mapping from expression number (`bitmap_index') to
      hash table entry.  */
 
-  index_map = (struct expr **) alloca (n_exprs * sizeof (struct expr *));
+  index_map = (struct expr **) gmalloc (n_exprs * sizeof (struct expr *));
   bzero ((char *) index_map, n_exprs * sizeof (struct expr *));
   for (i = 0; i < expr_hash_table_size; i++)
     {
@@ -5473,6 +5508,7 @@ hoist_code ()
 	    }
 	}
     }
+  free (index_map);
 }
 
 /* Top level routine to perform one code hoisting (aka unification) pass


More information about the Gcc-patches mailing list