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]

Re: [PATCH] Free memory in et-forest


On Mon, 19 Jun 2006, Ian Lance Taylor wrote:

> Richard Guenther <rguenther@suse.de> writes:
> 
> > 2006-06-15  Michael Matz  <matz@suse.de>
> > 	Richard Guenther  <rguenther@suse.de>
> > 
> > 	* et-forest.c (et_free_tree_force): Correctly free the
> > 	et-forest pools.
> > 
> > Index: et-forest.c
> > ===================================================================
> > --- et-forest.c	(Revision 114599)
> > +++ et-forest.c	(Arbeitskopie)
> > @@ -505,7 +505,19 @@ void
> >  et_free_tree_force (struct et_node *t)
> >  {
> >    pool_free (et_occurrences, t->rightmost_occ);
> > +  if (t->parent_occ)
> > +    pool_free (et_occurrences, t->parent_occ);
> > +  if (et_occurrences->elts_free == et_occurrences->elts_allocated)
> > +    {
> > +      free_alloc_pool (et_occurrences);
> > +      et_occurrences = NULL;
> > +    }
> >    pool_free (et_nodes, t);
> > +  if (et_nodes->elts_free == et_nodes->elts_allocated)
> > +    {
> > +      free_alloc_pool (et_nodes);
> > +      et_nodes = NULL;
> > +    }
> >  }
> >  
> >  /* Sets father of et tree T to FATHER.  */
> 
> I think it would be better to remove the two instances of elts_free ==
> elts_allocated.  Those are currently private variables of
> alloc-pool.c.  Instead, add a new function to alloc-pool.c to check
> for that, something like
>     void free_alloc_pool_if_empty (alloc_pool *arg);
> which sets *ARG to NULL if it is freed.
> 
> Then add a function
>     et_free_pools (void)
> which calls that on both pools, and then call that from
> free_dominance_info, instead of checking each time through
> et_free_tree_force.
> 
> At least, I think that would be a little bit cleaner and a little bit
> easier to maintain.  But feel free to disagree.
> 
> If you like those changes, then patch is approved with those changes
> after bootstrap and testing.

This is what I bootstrapped and tested on x86_64-unknown-linux-gnu.
I will apply it once I get around to do so.

Thanks,
Richard.

2006-06-20  Richard Guenther  <rguenther@suse.de>
	Michael Matz  <matz@suse.de>

	* alloc-pool.h (free_alloc_pool_if_empty): Prototype new
	function.
	* alloc-pool.c (free_alloc_pool_if_empty): New function.
	* et-forest.h (et_free_pools): Prototype new function.
	* et-forest.c (et_free_tree_force): Free parent occurrence. 
	(et_free_pools): New function.
	* dominance.c (free_dominance_info): Free et-forest alloc
	pools.

Index: alloc-pool.h
===================================================================
*** alloc-pool.h	(revision 114807)
--- alloc-pool.h	(working copy)
*************** typedef struct alloc_pool_def
*** 49,54 ****
--- 49,55 ----
  
  extern alloc_pool create_alloc_pool (const char *, size_t, size_t);
  extern void free_alloc_pool (alloc_pool);
+ extern void free_alloc_pool_if_empty (alloc_pool *);
  extern void *pool_alloc (alloc_pool);
  extern void pool_free (alloc_pool, void *);
  extern void dump_alloc_pool_statistics (void);
Index: alloc-pool.c
===================================================================
*** alloc-pool.c	(revision 114807)
--- alloc-pool.c	(working copy)
*************** free_alloc_pool (alloc_pool pool)
*** 207,212 ****
--- 207,223 ----
    free (pool);
  }
  
+ /* Frees the alloc_pool, if it is empty and zero *POOL in this case.  */
+ void
+ free_alloc_pool_if_empty (alloc_pool *pool)
+ {
+   if ((*pool)->elts_free == (*pool)->elts_allocated)
+     {
+       free_alloc_pool (*pool);
+       *pool = NULL;
+     }
+ }
+ 
  /* Allocates one element from the pool specified.  */
  void *
  pool_alloc (alloc_pool pool)
Index: et-forest.h
===================================================================
*** et-forest.h	(revision 114807)
--- et-forest.h	(working copy)
*************** struct et_node
*** 74,79 ****
--- 74,80 ----
  struct et_node *et_new_tree (void *data);
  void et_free_tree (struct et_node *);
  void et_free_tree_force (struct et_node *);
+ void et_free_pools (void);
  void et_set_father (struct et_node *, struct et_node *);
  void et_split (struct et_node *);
  struct et_node *et_nca (struct et_node *, struct et_node *);
Index: et-forest.c
===================================================================
*** et-forest.c	(revision 114807)
--- et-forest.c	(working copy)
*************** void
*** 505,513 ****
--- 505,524 ----
  et_free_tree_force (struct et_node *t)
  {
    pool_free (et_occurrences, t->rightmost_occ);
+   if (t->parent_occ)
+     pool_free (et_occurrences, t->parent_occ);
    pool_free (et_nodes, t);
  }
  
+ /* Release the alloc pools, if they are empty.  */
+ 
+ void
+ et_free_pools (void)
+ {
+   free_alloc_pool_if_empty (&et_occurrences);
+   free_alloc_pool_if_empty (&et_nodes);
+ }
+ 
  /* Sets father of et tree T to FATHER.  */
  
  void
Index: dominance.c
===================================================================
*** dominance.c	(revision 114807)
--- dominance.c	(working copy)
*************** free_dominance_info (enum cdi_direction 
*** 663,668 ****
--- 663,669 ----
        et_free_tree_force (bb->dom[dir]);
        bb->dom[dir] = NULL;
      }
+   et_free_pools ();
  
    n_bbs_in_dom_tree[dir] = 0;
  


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