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 to add gcalloc to gcse.c


In gcse.c, we have special "g" versions of the allocator functions
which keep track of how many bytes have been allocated.  I added a
gcalloc to allow replacing gmalloc/memset.  I also added
ATTRIBUTE_MALLOC and changed the size arguments to size_t.

Bootstrapped on sparc-sun-solaris2.7 (minus libgcj) no regressions.

Ok for mainline?

		Thanks,
		--Kaveh


2003-08-09  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* gcse.c (gmalloc): Argument is a size_t.  Add ATTRIBUTE_MALLOC.
	(grealloc): Size argument is a size_t.
	(gcalloc): New function.  Use throughout in lieu of
	gmalloc/memset.

--- orig/egcc-CVS20030809/gcc/gcse.c	2003-08-05 20:01:49.000000000 -0400
+++ egcc-CVS20030809/gcc/gcse.c	2003-08-09 23:42:30.887731000 -0400
@@ -549,8 +549,9 @@ struct null_pointer_info
 };
 
 static void compute_can_copy (void);
-static void *gmalloc (unsigned int);
-static void *grealloc (void *, unsigned int);
+static void *gmalloc (size_t) ATTRIBUTE_MALLOC;
+static void *gcalloc (size_t, size_t) ATTRIBUTE_MALLOC;
+static void *grealloc (void *, size_t);
 static void *gcse_alloc (unsigned long);
 static void alloc_gcse_mem (rtx);
 static void free_gcse_mem (void);
@@ -821,11 +822,8 @@ gcse_main (rtx f, FILE *file)
 	  if (changed)
 	    {
 	      free_modify_mem_tables ();
-	      modify_mem_list = gmalloc (last_basic_block * sizeof (rtx));
-	      canon_modify_mem_list
-		= gmalloc (last_basic_block * sizeof (rtx));
-	      memset (modify_mem_list, 0, last_basic_block * sizeof (rtx));
-	      memset (canon_modify_mem_list, 0, last_basic_block * sizeof (rtx));
+	      modify_mem_list = gcalloc (last_basic_block, sizeof (rtx));
+	      canon_modify_mem_list = gcalloc (last_basic_block, sizeof (rtx));
 	    }
 	  free_reg_set_mem ();
 	  alloc_reg_set_mem (max_reg_num ());
@@ -960,12 +958,21 @@ gmalloc (unsigned int size)
   return xmalloc (size);
 }
 
+/* Cover function to xcalloc to record bytes allocated.  */
+
+static void *
+gcalloc (size_t nelem, size_t elsize)
+{
+  bytes_used += nelem * elsize;
+  return xcalloc (nelem, elsize);
+}
+
 /* Cover function to xrealloc.
    We don't record the additional size since we don't know it.
    It won't affect memory usage stats much anyway.  */
 
 static void *
-grealloc (void *ptr, unsigned int size)
+grealloc (void *ptr, size_t size)
 {
   return xrealloc (ptr, size);
 }
@@ -987,7 +994,7 @@ gcse_alloc (unsigned long size)
 static void
 alloc_gcse_mem (rtx f)
 {
-  int i, n;
+  int i;
   rtx insn;
 
   /* Find the largest UID and create a mapping from UIDs to CUIDs.
@@ -995,9 +1002,7 @@ alloc_gcse_mem (rtx f)
      and only apply to real insns.  */
 
   max_uid = get_max_uid ();
-  n = (max_uid + 1) * sizeof (int);
-  uid_cuid = gmalloc (n);
-  memset (uid_cuid, 0, n);
+  uid_cuid = gcalloc (max_uid + 1, sizeof (int));
   for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
     {
       if (INSN_P (insn))
@@ -1009,9 +1014,7 @@ alloc_gcse_mem (rtx f)
   /* Create a table mapping cuids to insns.  */
 
   max_cuid = i;
-  n = (max_cuid + 1) * sizeof (rtx);
-  cuid_insn = gmalloc (n);
-  memset (cuid_insn, 0, n);
+  cuid_insn = gcalloc (max_cuid + 1, sizeof (rtx));
   for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
     if (INSN_P (insn))
       CUID_INSN (i++) = insn;
@@ -1023,10 +1026,8 @@ alloc_gcse_mem (rtx f)
   reg_set_in_block = sbitmap_vector_alloc (last_basic_block, max_gcse_regno);
   /* Allocate array to keep a list of insns which modify memory in each
      basic block.  */
-  modify_mem_list = gmalloc (last_basic_block * sizeof (rtx));
-  canon_modify_mem_list = gmalloc (last_basic_block * sizeof (rtx));
-  memset (modify_mem_list, 0, last_basic_block * sizeof (rtx));
-  memset (canon_modify_mem_list, 0, last_basic_block * sizeof (rtx));
+  modify_mem_list = gcalloc (last_basic_block, sizeof (rtx));
+  canon_modify_mem_list = gcalloc (last_basic_block, sizeof (rtx));
   modify_mem_list_set = BITMAP_XMALLOC ();
   canon_modify_mem_list_set = BITMAP_XMALLOC ();
 }
@@ -1189,12 +1190,8 @@ static struct obstack reg_set_obstack;
 static void
 alloc_reg_set_mem (int n_regs)
 {
-  unsigned int n;
-
   reg_set_table_size = n_regs + REG_SET_TABLE_SLOP;
-  n = reg_set_table_size * sizeof (struct reg_set *);
-  reg_set_table = gmalloc (n);
-  memset (reg_set_table, 0, n);
+  reg_set_table = gcalloc (reg_set_table_size, sizeof (struct reg_set *));
 
   gcc_obstack_init (&reg_set_obstack);
 }


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