From: Kaveh R. Ghazi Date: Mon, 11 Aug 2003 21:50:06 +0000 (+0000) Subject: gcse.c (gmalloc): Argument is a size_t. X-Git-Tag: releases/gcc-3.4.0~4296 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9fe15a12b4eb70d064776e3f27bb9cb90179bf34;p=thirdparty%2Fgcc.git gcse.c (gmalloc): Argument is a size_t. * 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. From-SVN: r70338 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d204bc35a0f6..f26963e179b7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,10 @@ 2003-08-11 Kaveh R. Ghazi + * 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. + * config/avr/avr.c (avr_init_once): Use xcalloc in lieu of xmalloc/memset. * config/ia64/ia64.c (ia64_reorg): Likewise. diff --git a/gcc/gcse.c b/gcc/gcse.c index 06f7fd9efa0e..066747b3c3a8 100644 --- a/gcc/gcse.c +++ b/gcc/gcse.c @@ -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 (®_set_obstack); }