This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: malloc attributes and realloc
> From: "Zack Weinberg" <zack@codesourcery.com>
>
> "Kaveh R. Ghazi" <ghazi@caip.rutgers.edu> writes:
>
> > Another datapoint, I tried disabling the libiberty macro
> > ATTRIBUTE_MALLOC which is applied to several allocation functions in
> > libiberty like xmalloc, etc. I rebootstrapped GCC and found that
> > without the attribute it slowed down 1% to 1.5% compiling combine.c at
> > -g -O2.
> >
> > Note many (most?) allocation in GCC occurs in other functions besides
> > the few libiberty functions with the attribute. So I think the
> > optimization is pretty good to get as much as it does.
>
> Hmm. Wanna put ATTRIBUTE_MALLOC on ggc_alloc* in ggc.h and see what
> kind of speedup you get?
> zw
Odd, cc1 shrinks by 500 bytes but >slows down< 1.7%. Now I'd _really_
like it if someone would try and reproduce my results...
Here's the patch I tested on sparc-sun-solaris2.7 with
--enable-languages=c --disable-checking --disable-nls
--enable-multilib=no
--- ggc.h~ 2003-12-21 20:01:18.000000000 -0500
+++ ggc.h 2004-01-03 20:51:48.765601000 -0500
@@ -210,19 +210,19 @@ extern struct alloc_zone *rtl_zone;
extern struct alloc_zone *tree_zone;
/* The internal primitive. */
-extern void *ggc_alloc (size_t);
+extern void *ggc_alloc (size_t) ATTRIBUTE_MALLOC;
/* Allocate an object into the specified allocation zone. */
-extern void *ggc_alloc_zone (size_t, struct alloc_zone *);
+extern void *ggc_alloc_zone (size_t, struct alloc_zone *) ATTRIBUTE_MALLOC;
/* Allocate an object of the specified type and size. */
-extern void *ggc_alloc_typed (enum gt_types_enum, size_t);
+extern void *ggc_alloc_typed (enum gt_types_enum, size_t) ATTRIBUTE_MALLOC;
/* Like ggc_alloc, but allocates cleared memory. */
-extern void *ggc_alloc_cleared (size_t);
+extern void *ggc_alloc_cleared (size_t) ATTRIBUTE_MALLOC;
/* Like ggc_alloc_zone, but allocates cleared memory. */
-extern void *ggc_alloc_cleared_zone (size_t, struct alloc_zone *);
+extern void *ggc_alloc_cleared_zone (size_t, struct alloc_zone *) ATTRIBUTE_MALLOC;
/* Resize a block. */
-extern void *ggc_realloc (void *, size_t);
+extern void *ggc_realloc (void *, size_t) ATTRIBUTE_MALLOC;
/* Like ggc_alloc_cleared, but performs a multiplication. */
-extern void *ggc_calloc (size_t, size_t);
+extern void *ggc_calloc (size_t, size_t) ATTRIBUTE_MALLOC;
#define ggc_alloc_rtx(CODE) \
((rtx) ggc_alloc_typed (gt_ggc_e_7rtx_def, RTX_SIZE (CODE)))
@@ -240,13 +240,13 @@ extern void *ggc_calloc (size_t, size_t)
splay_tree_new_with_allocator (COMPARE, NULL, NULL, \
&ggc_splay_alloc, &ggc_splay_dont_free, \
NULL)
-extern void *ggc_splay_alloc (int, void *);
+extern void *ggc_splay_alloc (int, void *) ATTRIBUTE_MALLOC;
extern void ggc_splay_dont_free (void *, void *);
/* Allocate a gc-able string, and fill it with LENGTH bytes from CONTENTS.
If LENGTH is -1, then CONTENTS is assumed to be a
null-terminated string and the memory sized accordingly. */
-extern const char *ggc_alloc_string (const char *contents, int length);
+extern const char *ggc_alloc_string (const char *contents, int length) ATTRIBUTE_MALLOC;
/* Make a copy of S, in GC-able memory. */
#define ggc_strdup(S) ggc_alloc_string((S), -1)