This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Trim down cselib memory usage
> > Date: Wed, 21 Jan 2004 19:02:36 +0100
> > From: Jan Hubicka <jh@suse.cz>
>
> > Does adding ggc_unsafe into ggc.h/ggc.c and increment/decrement of it
> > in cselib.c sound like sane sollution to you?
>
> I think something like this would be a very good idea. I suggest a
> function, though, not a variable.
HI,
here is patch I tested on i686-linux.
Hope that it will make my other two cselib patches more useable. I've
added a alloc_pool statistics and got data that peaks at about 200Kb,
compare it to roughtly 100MB of garbage produced by old scheme.
in fact I am thinking about going even further. The cselib produces a
lot of VALUE RTX nodes. All these nodes are local to CSE pass and as
such, is there something preventing this nodes from being allocated by
varpool too?
If not, I will make alternate sollution using the freelists, but
varpools are faster and easier to do, so I don't want to throw this idea
off.
Honza
2004-01-21 Jan Hubicka <jh@suse.cz>
* cselib.c (cselib_init): Enter unsafe region.
(cselib_finish): Leave unsafe region.
* ggc-common.c (unsafe_region_depth): New satic variable.
(ggc_enter_unsafe_region, ggc_leave_unsafe_region,
ggc_unsafe_region_p): New functions.
* ggc-page.c (ggc_collect): Check region.
* ggc-zone.c (ggc_collect): Check region.
Index: cselib.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cselib.c,v
retrieving revision 1.33
diff -c -3 -p -r1.33 cselib.c
*** cselib.c 20 Jan 2004 20:36:18 -0000 1.33
--- cselib.c 21 Jan 2004 19:21:54 -0000
*************** cselib_update_varray_sizes (void)
*** 1386,1391 ****
--- 1386,1392 ----
void
cselib_init (void)
{
+ ggc_enter_unsafe_region ();
elt_list_pool = create_alloc_pool ("elt_list",
sizeof (struct elt_list), 10);
elt_loc_list_pool = create_alloc_pool ("elt_loc_list",
*************** cselib_init (void)
*** 1417,1422 ****
--- 1418,1424 ----
void
cselib_finish (void)
{
+ ggc_leave_unsafe_region ();
free_alloc_pool (elt_list_pool);
free_alloc_pool (elt_loc_list_pool);
free_alloc_pool (cselib_val_pool);
Index: ggc-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ggc-common.c,v
retrieving revision 1.78
diff -c -3 -p -r1.78 ggc-common.c
*** ggc-common.c 29 Oct 2003 22:13:59 -0000 1.78
--- ggc-common.c 21 Jan 2004 19:21:54 -0000
*************** static void relocate_ptrs (void *, void
*** 75,80 ****
--- 75,104 ----
static void write_pch_globals (const struct ggc_root_tab * const *tab,
struct traversal_state *state);
static double ggc_rlimit_bound (double);
+ static int unsafe_region_depth;
+
+ /* After calling ggc_enter_unsafe_region, ggc_collect call will abort. */
+ void
+ ggc_enter_unsafe_region ()
+ {
+ unsafe_region_depth++;
+ }
+
+ /* Use to leave unsafe region. */
+ void
+ ggc_leave_unsafe_region ()
+ {
+ unsafe_region_depth--;
+ if (unsafe_region_depth < 0)
+ abort ();
+ }
+
+ /* Check whether we are inside unsafe region. */
+ bool
+ ggc_unsafe_region_p ()
+ {
+ return unsafe_region_depth;
+ }
/* Maintain global roots that are preserved during GC. */
Index: ggc-page.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ggc-page.c,v
retrieving revision 1.84
diff -c -3 -p -r1.84 ggc-page.c
*** ggc-page.c 22 Dec 2003 07:42:37 -0000 1.84
--- ggc-page.c 21 Jan 2004 19:21:54 -0000
*************** poison_pages (void)
*** 1774,1779 ****
--- 1774,1782 ----
void
ggc_collect (void)
{
+ if (ggc_unsafe_region_p ())
+ abort ();
+
/* Avoid frequent unnecessary work by skipping collection if the
total allocations haven't expanded much since the last
collection. */
Index: ggc-zone.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ggc-zone.c,v
retrieving revision 2.11
diff -c -3 -p -r2.11 ggc-zone.c
*** ggc-zone.c 6 Jan 2004 16:51:16 -0000 2.11
--- ggc-zone.c 21 Jan 2004 19:21:54 -0000
*************** ggc_collect (void)
*** 1157,1162 ****
--- 1157,1165 ----
bool marked = false;
float f;
+ if (ggc_unsafe_region_p ())
+ abort ();
+
timevar_push (TV_GC);
check_cookies ();
/* Start by possibly collecting the main zone. */
Index: ggc.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ggc.h,v
retrieving revision 1.61
diff -c -3 -p -r1.61 ggc.h
*** ggc.h 21 Dec 2003 14:08:33 -0000 1.61
--- ggc.h 21 Jan 2004 19:21:54 -0000
*************** extern int ggc_min_expand_heuristic (voi
*** 287,290 ****
--- 287,293 ----
extern int ggc_min_heapsize_heuristic (void);
extern void init_ggc_heuristics (void);
+ extern void ggc_enter_unsafe_region (void);
+ extern void ggc_leave_unsafe_region (void);
+ extern bool ggc_unsafe_region_p (void);
#endif