public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH]: Fix memory leaks in tree-ssa-alias.c
@ 2007-07-28 21:02 Daniel Berlin
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Berlin @ 2007-07-28 21:02 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 549 bytes --]

We are leaking a bunch of things per-function on the last may_aliases
call of that function.

This fixes that :)

Bootstrapped and regtested on i686-darwin
Committed to mainline
2007-07-28  Daniel Berlin  <dberlin@dberlin.org>

	* Makefile.in (tree-ssa-alias.o): Add alloc-pool.h

	* tree-ssa-alias.c: Add alloc-pool.h.
	(init_alias_info): Free alias_bitmap_obstack.
	(delete_alias_info): Call delete_mem_ref_stats.
	(get_mem_sym_stats_for): Use alloc_pool.
	(init_mem_ref_stats): Do not delete mem_ref_stats here.
	(delete_mem_sym_stats): Removed.

[-- Attachment #2: fixmemleaks.diff --]
[-- Type: text/x-diff, Size: 3844 bytes --]

Index: tree-ssa-alias.c
===================================================================
--- tree-ssa-alias.c	(revision 127013)
+++ tree-ssa-alias.c	(working copy)
@@ -47,6 +47,7 @@ along with GCC; see the file COPYING3.  
 #include "bitmap.h"
 #include "vecprim.h"
 #include "pointer-set.h"
+#include "alloc-pool.h"
 
 /* Broad overview of how aliasing works:
    
@@ -212,7 +213,7 @@ static void set_pt_anything (tree);
 
 void debug_mp_info (VEC(mem_sym_stats_t,heap) *);
 
-
+static alloc_pool mem_sym_stats_pool;
 
 /* Return memory reference stats for symbol VAR.  Create a new slot in
    cfun->gimple_df->mem_sym_stats if needed.  */
@@ -229,7 +230,7 @@ get_mem_sym_stats_for (tree var)
   slot = pointer_map_insert (map, var);
   if (*slot == NULL)
     {
-      stats = XCNEW (struct mem_sym_stats_d);
+      stats = pool_alloc (mem_sym_stats_pool);
       stats->var = var;
       *slot = (void *) stats;
     }
@@ -1876,20 +1877,6 @@ count_uses_and_derefs (tree ptr, tree st
   gcc_assert (*num_uses_p >= *num_loads_p + *num_stores_p);
 }
 
-
-/* Helper for delete_mem_ref_stats.  Free all the slots in the
-   mem_sym_stats map.  */
-
-static bool
-delete_mem_sym_stats (void *key ATTRIBUTE_UNUSED, void **value,
-		       void *data ATTRIBUTE_UNUSED)
-{
-  XDELETE (*value);
-  *value = NULL;
-  return false;
-}
-
-
 /* Remove memory references stats for function FN.  */
 
 void
@@ -1897,11 +1884,9 @@ delete_mem_ref_stats (struct function *f
 {
   if (gimple_mem_ref_stats (fn)->mem_sym_stats)
     {
-      pointer_map_traverse (gimple_mem_ref_stats (fn)->mem_sym_stats,
-			    delete_mem_sym_stats, NULL);
+      free_alloc_pool (mem_sym_stats_pool);
       pointer_map_destroy (gimple_mem_ref_stats (fn)->mem_sym_stats);
     }
-
   gimple_mem_ref_stats (fn)->mem_sym_stats = NULL;
 }
 
@@ -1913,9 +1898,9 @@ init_mem_ref_stats (void)
 {
   struct mem_ref_stats_d *mem_ref_stats = gimple_mem_ref_stats (cfun);
 
-  if (mem_ref_stats->mem_sym_stats)
-    delete_mem_ref_stats (cfun);
-
+  mem_sym_stats_pool = create_alloc_pool ("Mem sym stats",
+					  sizeof (struct mem_sym_stats_d),
+					  100);
   memset (mem_ref_stats, 0, sizeof (struct mem_ref_stats_d));
   mem_ref_stats->mem_sym_stats = pointer_map_create ();
 }
@@ -1946,8 +1931,6 @@ init_alias_info (void)
     {
       unsigned i;
       
-      bitmap_obstack_release (&alias_bitmap_obstack);
-      
       /* Similarly, clear the set of addressable variables.  In this
 	 case, we can just clear the set because addressability is
 	 only computed here.  */
@@ -2021,6 +2004,8 @@ init_alias_info (void)
 
   /* Next time, we will need to reset alias information.  */
   cfun->gimple_df->aliases_computed_p = true;
+  if (alias_bitmap_obstack.elements != NULL)
+    bitmap_obstack_release (&alias_bitmap_obstack);    
   bitmap_obstack_initialize (&alias_bitmap_obstack);
 
   return ai;
@@ -2051,6 +2036,7 @@ delete_alias_info (struct alias_info *ai
   pointer_set_destroy (ai->dereferenced_ptrs_load);
   free (ai);
 
+  delete_mem_ref_stats (cfun);
   delete_points_to_sets ();
 }
 
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 127012)
+++ Makefile.in	(working copy)
@@ -2172,7 +2172,7 @@ tree-ssa-alias.o : tree-ssa-alias.c $(TR
    $(FUNCTION_H) $(TIMEVAR_H) convert.h $(TM_H) coretypes.h langhooks.h \
    $(TREE_DUMP_H) tree-pass.h $(PARAMS_H) $(BASIC_BLOCK_H) $(DIAGNOSTIC_H) \
    hard-reg-set.h $(TREE_GIMPLE_H) vec.h tree-ssa-structalias.h \
-   $(IPA_TYPE_ESCAPE_H) vecprim.h pointer-set.h
+   $(IPA_TYPE_ESCAPE_H) vecprim.h pointer-set.h alloc-pool.h
 tree-ssa-reassoc.o : tree-ssa-reassoc.c $(TREE_FLOW_H) $(CONFIG_H) \
    $(SYSTEM_H) $(TREE_H) $(GGC_H) $(DIAGNOSTIC_H) errors.h $(TIMEVAR_H) \
    $(TM_H) coretypes.h $(TREE_DUMP_H) tree-pass.h $(FLAGS_H) tree-iterator.h\

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH]: Fix memory leaks in tree-ssa-alias.c
@ 2007-07-29  7:00 Daniel Berlin
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Berlin @ 2007-07-29  7:00 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 550 bytes --]

We are leaking a bunch of things per-function on the last may_aliases
call of that function.

This fixes that :)

Bootstrapped and regtested on i686-darwin
Committed to mainline

2007-07-28  Daniel Berlin  <dberlin@dberlin.org>

	* Makefile.in (tree-ssa-alias.o): Add alloc-pool.h

	* tree-ssa-alias.c: Add alloc-pool.h.
	(init_alias_info): Free alias_bitmap_obstack.
	(delete_alias_info): Call delete_mem_ref_stats.
	(get_mem_sym_stats_for): Use alloc_pool.
	(init_mem_ref_stats): Do not delete mem_ref_stats here.
	(delete_mem_sym_stats): Removed.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: fixmemleaks.diff --]
[-- Type: text/x-diff; name="fixmemleaks.diff", Size: 3887 bytes --]

Index: tree-ssa-alias.c
===================================================================
--- tree-ssa-alias.c	(revision 127013)
+++ tree-ssa-alias.c	(working copy)
@@ -47,6 +47,7 @@ along with GCC; see the file COPYING3.  
 #include "bitmap.h"
 #include "vecprim.h"
 #include "pointer-set.h"
+#include "alloc-pool.h"
 
 /* Broad overview of how aliasing works:
    
@@ -212,7 +213,7 @@ static void set_pt_anything (tree);
 
 void debug_mp_info (VEC(mem_sym_stats_t,heap) *);
 
-
+static alloc_pool mem_sym_stats_pool;
 
 /* Return memory reference stats for symbol VAR.  Create a new slot in
    cfun->gimple_df->mem_sym_stats if needed.  */
@@ -229,7 +230,8 @@ get_mem_sym_stats_for (tree var)
   slot = pointer_map_insert (map, var);
   if (*slot == NULL)
     {
-      stats = XCNEW (struct mem_sym_stats_d);
+      stats = pool_alloc (mem_sym_stats_pool);
+      memset (stats, 0, sizeof (*stats));
       stats->var = var;
       *slot = (void *) stats;
     }
@@ -1876,20 +1878,6 @@ count_uses_and_derefs (tree ptr, tree st
   gcc_assert (*num_uses_p >= *num_loads_p + *num_stores_p);
 }
 
-
-/* Helper for delete_mem_ref_stats.  Free all the slots in the
-   mem_sym_stats map.  */
-
-static bool
-delete_mem_sym_stats (void *key ATTRIBUTE_UNUSED, void **value,
-		       void *data ATTRIBUTE_UNUSED)
-{
-  XDELETE (*value);
-  *value = NULL;
-  return false;
-}
-
-
 /* Remove memory references stats for function FN.  */
 
 void
@@ -1897,11 +1885,9 @@ delete_mem_ref_stats (struct function *f
 {
   if (gimple_mem_ref_stats (fn)->mem_sym_stats)
     {
-      pointer_map_traverse (gimple_mem_ref_stats (fn)->mem_sym_stats,
-			    delete_mem_sym_stats, NULL);
+      free_alloc_pool (mem_sym_stats_pool);
       pointer_map_destroy (gimple_mem_ref_stats (fn)->mem_sym_stats);
     }
-
   gimple_mem_ref_stats (fn)->mem_sym_stats = NULL;
 }
 
@@ -1913,9 +1899,9 @@ init_mem_ref_stats (void)
 {
   struct mem_ref_stats_d *mem_ref_stats = gimple_mem_ref_stats (cfun);
 
-  if (mem_ref_stats->mem_sym_stats)
-    delete_mem_ref_stats (cfun);
-
+  mem_sym_stats_pool = create_alloc_pool ("Mem sym stats",
+					  sizeof (struct mem_sym_stats_d),
+					  100);
   memset (mem_ref_stats, 0, sizeof (struct mem_ref_stats_d));
   mem_ref_stats->mem_sym_stats = pointer_map_create ();
 }
@@ -1946,8 +1932,6 @@ init_alias_info (void)
     {
       unsigned i;
       
-      bitmap_obstack_release (&alias_bitmap_obstack);
-      
       /* Similarly, clear the set of addressable variables.  In this
 	 case, we can just clear the set because addressability is
 	 only computed here.  */
@@ -2021,6 +2005,8 @@ init_alias_info (void)
 
   /* Next time, we will need to reset alias information.  */
   cfun->gimple_df->aliases_computed_p = true;
+  if (alias_bitmap_obstack.elements != NULL)
+    bitmap_obstack_release (&alias_bitmap_obstack);    
   bitmap_obstack_initialize (&alias_bitmap_obstack);
 
   return ai;
@@ -2051,6 +2037,7 @@ delete_alias_info (struct alias_info *ai
   pointer_set_destroy (ai->dereferenced_ptrs_load);
   free (ai);
 
+  delete_mem_ref_stats (cfun);
   delete_points_to_sets ();
 }
 
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 127012)
+++ Makefile.in	(working copy)
@@ -2172,7 +2172,7 @@ tree-ssa-alias.o : tree-ssa-alias.c $(TR
    $(FUNCTION_H) $(TIMEVAR_H) convert.h $(TM_H) coretypes.h langhooks.h \
    $(TREE_DUMP_H) tree-pass.h $(PARAMS_H) $(BASIC_BLOCK_H) $(DIAGNOSTIC_H) \
    hard-reg-set.h $(TREE_GIMPLE_H) vec.h tree-ssa-structalias.h \
-   $(IPA_TYPE_ESCAPE_H) vecprim.h pointer-set.h
+   $(IPA_TYPE_ESCAPE_H) vecprim.h pointer-set.h alloc-pool.h
 tree-ssa-reassoc.o : tree-ssa-reassoc.c $(TREE_FLOW_H) $(CONFIG_H) \
    $(SYSTEM_H) $(TREE_H) $(GGC_H) $(DIAGNOSTIC_H) errors.h $(TIMEVAR_H) \
    $(TM_H) coretypes.h $(TREE_DUMP_H) tree-pass.h $(FLAGS_H) tree-iterator.h\

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-07-29  2:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-28 21:02 [PATCH]: Fix memory leaks in tree-ssa-alias.c Daniel Berlin
2007-07-29  7:00 Daniel Berlin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).