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]

New free_reg_info function


Today's CVS source calls allocate_reg_info with -1 as first argument to
tell it to free all memory.  Unfortunately, the first argument is of type
size_t, which is unsigned at least on sparc-sun-solaris2.6, so this change
caused a nasty machine lockup due to allocating a huge amount of memory.

Bernd

	* regclass.c (renumber, regno_allocated): New static variables, moved
	out of allocate_reg_info.
	(allocate_reg_info): Move these two variables outside the function.
	Move code to free memory into new function free_reg_info.
	(free_reg_info): New function, broken out of allocate_reg_info.
	* toplev.c (compile_file): Call free_reg_info, not allocate_reg_info.
	* rtl.h (allocate_reg_info): Don't declare.
	(free_reg_info): Declare.

Index: regclass.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/regclass.c,v
retrieving revision 1.39
diff -u -p -r1.39 regclass.c
--- regclass.c	1998/10/25 12:56:39	1.39
+++ regclass.c	1998/10/28 09:32:41
@@ -1827,6 +1827,9 @@ auto_inc_dec_reg_p (reg, mode)
 
 #endif /* REGISTER_CONSTRAINTS */
 
+static short *renumber = (short *)0;
+static size_t regno_allocated = 0;
+
 /* Allocate enough space to hold NUM_REGS registers for the tables used for
    reg_scan and flow_analysis that are indexed by the register number.  If
    NEW_P is non zero, initialize all of the registers, otherwise only
@@ -1840,38 +1843,12 @@ allocate_reg_info (num_regs, new_p, renu
      int new_p;
      int renumber_p;
 {
-  static size_t regno_allocated = 0;
-  static short *renumber = (short *)0;
   size_t size_info;
   size_t size_renumber;
   size_t min = (new_p) ? 0 : reg_n_max;
   struct reg_info_data *reg_data;
   struct reg_info_data *reg_next;
 
-  /* Free up all storage allocated */
-  if (num_regs < 0)
-    {
-      if (reg_n_info)
-	{
-	  VARRAY_FREE (reg_n_info);
-	  for (reg_data = reg_info_head; reg_data; reg_data = reg_next)
-	    {
-	      reg_next = reg_data->next;
-	      free ((char *)reg_data);
-	    }
-
-	  free (prefclass_buffer);
-	  free (altclass_buffer);
-	  prefclass_buffer = (char *)0;
-	  altclass_buffer = (char *)0;
-	  reg_info_head = (struct reg_info_data *)0;
-	  renumber = (short *)0;
-	}
-      regno_allocated = 0;
-      reg_n_max = 0;
-      return;
-    }
-
   if (num_regs > regno_allocated)
     {
       size_t old_allocated = regno_allocated;
@@ -1973,6 +1950,32 @@ allocate_reg_info (num_regs, new_p, renu
   MAX_REGNO_REG_SET (num_regs, new_p, renumber_p);
 }
 
+/* Free up the space allocated by allocate_reg_info.  */
+void
+free_reg_info ()
+{
+  if (reg_n_info)
+    {
+      struct reg_info_data *reg_data;
+      struct reg_info_data *reg_next;
+
+      VARRAY_FREE (reg_n_info);
+      for (reg_data = reg_info_head; reg_data; reg_data = reg_next)
+	{
+	  reg_next = reg_data->next;
+	  free ((char *)reg_data);
+	}
+
+      free (prefclass_buffer);
+      free (altclass_buffer);
+      prefclass_buffer = (char *)0;
+      altclass_buffer = (char *)0;
+      reg_info_head = (struct reg_info_data *)0;
+      renumber = (short *)0;
+    }
+  regno_allocated = 0;
+  reg_n_max = 0;
+}
 
 /* This is the `regscan' pass of the compiler, run just before cse
    and again just before loop.
Index: toplev.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/toplev.c,v
retrieving revision 1.117
diff -u -p -r1.117 toplev.c
--- toplev.c	1998/10/28 00:06:21	1.117
+++ toplev.c	1998/10/28 09:32:42
@@ -3099,7 +3099,7 @@ compile_file (name)
     fatal_io_error (asm_file_name);
 
   /* Free up memory for the benefit of leak detectors.  */
-  allocate_reg_info (-1, 0, 0);
+  free_reg_info ();
 
   /* Print the times.  */
 
Index: rtl.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/rtl.h,v
retrieving revision 1.60
diff -u -p -r1.60 rtl.h
--- rtl.h	1998/10/28 00:06:22	1.60
+++ rtl.h	1998/10/28 09:32:42
@@ -1010,7 +1010,7 @@ extern rtx find_use_as_address		PROTO((r
 extern int max_parallel;
 
 /* Free up register info memory.  */
-extern void allocate_reg_info		PROTO((size_t, int, int));
+extern void free_reg_info		PROTO((void));
 
 /* recog.c */
 extern int asm_noperands		PROTO((rtx));



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