Patchwork Fix PR47002: memory leaks.

login
register
mail settings
Submitter Sebastian Pop
Date Dec. 22, 2010, 6:17 a.m.
Message ID <1292998630-14419-1-git-send-email-sebpop@gmail.com>
Download mbox | patch
Permalink /patch/76360/
State New
Headers show

Comments

Sebastian Pop - Dec. 22, 2010, 6:17 a.m.
Hi,

Although I am not able to reproduce the error reported on
http://gcc.gnu.org/PR47002 I went and fixed all the memory leaks I
found related to the tree-loop-distribution.c and tree-data-ref.c
reported by valgrind --leak-check=full ./cc1 -O3 pr47002.i
I am testing this patch on amd64-linux.  Ok for trunk after test?

Thanks,
Sebastian

2010-12-22  Sebastian Pop  <sebastian.pop@amd.com>

	PR tree-optimization/47002
	* tree-data-ref.c (compute_data_dependences_for_loop): Free vloops.
	(free_dependence_relations): Do not free loop_nest.
	(build_rdg): Pass in datarefs and dependence_relations.
	(free_rdg): Also free the data on edges.
	* tree-data-ref.h (build_rdg): Update declaration.
	* tree-loop-distribution.c (rdg_flag_loop_exits): Free conds.
	(rdg_build_partitions): Free comps.
	(ldist_gen): Free components.
	(distribute_loop): Update call to build_rdg.  Allocate and free
	datarefs and dependence_relations.
	* tree-vect-loop.c (destroy_loop_vec_info): Free
	LOOP_VINFO_MAY_ALIAS_DDRS.
	* tree-vect-slp.c (destroy_bb_vec_info): Call free_data_refs and
	free_dependence_relations.
---
 gcc/ChangeLog                |   18 +++++++++++
 gcc/tree-data-ref.c          |   70 ++++++++++++++++++------------------------
 gcc/tree-data-ref.h          |    3 +-
 gcc/tree-loop-distribution.c |   15 ++++++++-
 gcc/tree-vect-loop.c         |    1 +
 gcc/tree-vect-slp.c          |    2 +
 6 files changed, 66 insertions(+), 43 deletions(-)
Richard Guenther - Dec. 22, 2010, 12:18 p.m.
On Wed, Dec 22, 2010 at 7:17 AM, Sebastian Pop <sebpop@gmail.com> wrote:
> Hi,
>
> Although I am not able to reproduce the error reported on
> http://gcc.gnu.org/PR47002 I went and fixed all the memory leaks I
> found related to the tree-loop-distribution.c and tree-data-ref.c
> reported by valgrind --leak-check=full ./cc1 -O3 pr47002.i
> I am testing this patch on amd64-linux.  Ok for trunk after test?

Ok.

Thanks,
Richard.

> Thanks,
> Sebastian
>
> 2010-12-22  Sebastian Pop  <sebastian.pop@amd.com>
>
>        PR tree-optimization/47002
>        * tree-data-ref.c (compute_data_dependences_for_loop): Free vloops.
>        (free_dependence_relations): Do not free loop_nest.
>        (build_rdg): Pass in datarefs and dependence_relations.
>        (free_rdg): Also free the data on edges.
>        * tree-data-ref.h (build_rdg): Update declaration.
>        * tree-loop-distribution.c (rdg_flag_loop_exits): Free conds.
>        (rdg_build_partitions): Free comps.
>        (ldist_gen): Free components.
>        (distribute_loop): Update call to build_rdg.  Allocate and free
>        datarefs and dependence_relations.
>        * tree-vect-loop.c (destroy_loop_vec_info): Free
>        LOOP_VINFO_MAY_ALIAS_DDRS.
>        * tree-vect-slp.c (destroy_bb_vec_info): Call free_data_refs and
>        free_dependence_relations.
> ---
>  gcc/ChangeLog                |   18 +++++++++++
>  gcc/tree-data-ref.c          |   70 ++++++++++++++++++------------------------
>  gcc/tree-data-ref.h          |    3 +-
>  gcc/tree-loop-distribution.c |   15 ++++++++-
>  gcc/tree-vect-loop.c         |    1 +
>  gcc/tree-vect-slp.c          |    2 +
>  6 files changed, 66 insertions(+), 43 deletions(-)
>
> diff --git a/gcc/ChangeLog b/gcc/ChangeLog
> index 944f806..9fcdd6c 100644
> --- a/gcc/ChangeLog
> +++ b/gcc/ChangeLog
> @@ -1,3 +1,21 @@
> +2010-12-22  Sebastian Pop  <sebastian.pop@amd.com>
> +
> +       PR tree-optimization/47002
> +       * tree-data-ref.c (compute_data_dependences_for_loop): Free vloops.
> +       (free_dependence_relations): Do not free loop_nest.
> +       (build_rdg): Pass in datarefs and dependence_relations.
> +       (free_rdg): Also free the data on edges.
> +       * tree-data-ref.h (build_rdg): Update declaration.
> +       * tree-loop-distribution.c (rdg_flag_loop_exits): Free conds.
> +       (rdg_build_partitions): Free comps.
> +       (ldist_gen): Free components.
> +       (distribute_loop): Update call to build_rdg.  Allocate and free
> +       datarefs and dependence_relations.
> +       * tree-vect-loop.c (destroy_loop_vec_info): Free
> +       LOOP_VINFO_MAY_ALIAS_DDRS.
> +       * tree-vect-slp.c (destroy_bb_vec_info): Call free_data_refs and
> +       free_dependence_relations.
> +
>  2010-12-17  Paolo Bonzini  <bonzini@gnu.org>
>
>        PR c/20385
> diff --git a/gcc/tree-data-ref.c b/gcc/tree-data-ref.c
> index a6d0731..dc14989 100644
> --- a/gcc/tree-data-ref.c
> +++ b/gcc/tree-data-ref.c
> @@ -4274,6 +4274,9 @@ compute_data_dependences_for_loop (struct loop *loop,
>     compute_all_dependences (*datarefs, dependence_relations, vloops,
>                             compute_self_and_read_read_dependences);
>
> +  if (vloops)
> +    VEC_free (loop_p, heap, vloops);
> +
>   if (dump_file && (dump_flags & TDF_STATS))
>     {
>       fprintf (dump_file, "Dependence tester statistics:\n");
> @@ -4454,22 +4457,11 @@ free_dependence_relations (VEC (ddr_p, heap) *dependence_relations)
>  {
>   unsigned int i;
>   struct data_dependence_relation *ddr;
> -  VEC (loop_p, heap) *loop_nest = NULL;
>
>   FOR_EACH_VEC_ELT (ddr_p, dependence_relations, i, ddr)
> -    {
> -      if (ddr == NULL)
> -       continue;
> -      if (loop_nest == NULL)
> -       loop_nest = DDR_LOOP_NEST (ddr);
> -      else
> -       gcc_assert (DDR_LOOP_NEST (ddr) == NULL
> -                   || DDR_LOOP_NEST (ddr) == loop_nest);
> +    if (ddr)
>       free_dependence_relation (ddr);
> -    }
>
> -  if (loop_nest)
> -    VEC_free (loop_p, heap, loop_nest);
>   VEC_free (ddr_p, heap, dependence_relations);
>  }
>
> @@ -4905,37 +4897,23 @@ build_empty_rdg (int n_stmts)
>    scalar dependence.  */
>
>  struct graph *
> -build_rdg (struct loop *loop)
> +build_rdg (struct loop *loop,
> +          VEC (ddr_p, heap) **dependence_relations,
> +          VEC (data_reference_p, heap) **datarefs)
>  {
> -  int nb_data_refs = 10;
>   struct graph *rdg = NULL;
> -  VEC (ddr_p, heap) *dependence_relations;
> -  VEC (data_reference_p, heap) *datarefs;
> -  VEC (gimple, heap) *stmts = VEC_alloc (gimple, heap, nb_data_refs);
> -
> -  dependence_relations = VEC_alloc (ddr_p, heap, nb_data_refs * nb_data_refs) ;
> -  datarefs = VEC_alloc (data_reference_p, heap, nb_data_refs);
> -  compute_data_dependences_for_loop (loop,
> -                                     false,
> -                                     &datarefs,
> -                                     &dependence_relations);
> -
> -  if (!known_dependences_p (dependence_relations))
> -    {
> -      free_dependence_relations (dependence_relations);
> -      free_data_refs (datarefs);
> -      VEC_free (gimple, heap, stmts);
> -
> -      return rdg;
> -    }
> +  VEC (gimple, heap) *stmts = VEC_alloc (gimple, heap, 10);
>
> -  stmts_from_loop (loop, &stmts);
> -  rdg = build_empty_rdg (VEC_length (gimple, stmts));
> +  compute_data_dependences_for_loop (loop, false, datarefs,
> +                                    dependence_relations);
>
> -  rdg->indices = htab_create (nb_data_refs, hash_stmt_vertex_info,
> -                             eq_stmt_vertex_info, hash_stmt_vertex_del);
> -  create_rdg_vertices (rdg, stmts);
> -  create_rdg_edges (rdg, dependence_relations);
> +  if (known_dependences_p (*dependence_relations))
> +    {
> +      stmts_from_loop (loop, &stmts);
> +      rdg = build_empty_rdg (VEC_length (gimple, stmts));
> +      create_rdg_vertices (rdg, stmts);
> +      create_rdg_edges (rdg, *dependence_relations);
> +    }
>
>   VEC_free (gimple, heap, stmts);
>   return rdg;
> @@ -4949,7 +4927,19 @@ free_rdg (struct graph *rdg)
>   int i;
>
>   for (i = 0; i < rdg->n_vertices; i++)
> -    free (rdg->vertices[i].data);
> +    {
> +      struct vertex *v = &(rdg->vertices[i]);
> +      struct graph_edge *e;
> +
> +      for (e = v->succ; e; e = e->succ_next)
> +       {
> +         free_dependence_relation (RDGE_RELATION (e));
> +         if (e->data)
> +           free (e->data);
> +       }
> +
> +      free (v->data);
> +    }
>
>   htab_delete (rdg->indices);
>   free_graph (rdg);
> diff --git a/gcc/tree-data-ref.h b/gcc/tree-data-ref.h
> index b4f317f..8585b2b 100644
> --- a/gcc/tree-data-ref.h
> +++ b/gcc/tree-data-ref.h
> @@ -577,7 +577,8 @@ typedef struct rdg_edge
>  #define RDGE_LEVEL(E)       ((struct rdg_edge *) ((E)->data))->level
>  #define RDGE_RELATION(E)    ((struct rdg_edge *) ((E)->data))->relation
>
> -struct graph *build_rdg (struct loop *);
> +struct graph *build_rdg (struct loop *, VEC (ddr_p, heap) **,
> +                        VEC (data_reference_p, heap) **);
>  struct graph *build_empty_rdg (int);
>  void free_rdg (struct graph *);
>
> diff --git a/gcc/tree-loop-distribution.c b/gcc/tree-loop-distribution.c
> index a9ee67f..d095e8a 100644
> --- a/gcc/tree-loop-distribution.c
> +++ b/gcc/tree-loop-distribution.c
> @@ -653,6 +653,8 @@ rdg_flag_loop_exits (struct graph *rdg, bitmap loops, bitmap partition,
>
>       BITMAP_FREE (new_loops);
>     }
> +
> +  VEC_free (gimple, heap, conds);
>  }
>
>  /* Returns a bitmap in which all the statements needed for computing
> @@ -965,6 +967,7 @@ rdg_build_partitions (struct graph *rdg, VEC (rdgc, heap) *components,
>
>       VEC_free (int, heap, foo);
>       free_rdg_components (comps);
> +      VEC_free (rdgc, heap, comps);
>     }
>
>   add_scalar_computations_to_partition (rdg, *partitions, partition);
> @@ -1129,6 +1132,7 @@ ldist_gen (struct loop *loop, struct graph *rdg,
>   VEC_free (int, heap, other_stores);
>   VEC_free (bitmap, heap, partitions);
>   free_rdg_components (components);
> +  VEC_free (rdgc, heap, components);
>   return nbp;
>  }
>
> @@ -1146,6 +1150,8 @@ distribute_loop (struct loop *loop, VEC (gimple, heap) *stmts)
>   gimple s;
>   unsigned i;
>   VEC (int, heap) *vertices;
> +  VEC (ddr_p, heap) *dependence_relations;
> +  VEC (data_reference_p, heap) *datarefs;
>
>   if (loop->num_nodes > 2)
>     {
> @@ -1157,7 +1163,9 @@ distribute_loop (struct loop *loop, VEC (gimple, heap) *stmts)
>       return res;
>     }
>
> -  rdg = build_rdg (loop);
> +  datarefs = VEC_alloc (data_reference_p, heap, 10);
> +  dependence_relations = VEC_alloc (ddr_p, heap, 100);
> +  rdg = build_rdg (loop, &dependence_relations, &datarefs);
>
>   if (!rdg)
>     {
> @@ -1166,6 +1174,8 @@ distribute_loop (struct loop *loop, VEC (gimple, heap) *stmts)
>                 "FIXME: Loop %d not distributed: failed to build the RDG.\n",
>                 loop->num);
>
> +      free_dependence_relations (dependence_relations);
> +      free_data_refs (datarefs);
>       return res;
>     }
>
> @@ -1191,7 +1201,8 @@ distribute_loop (struct loop *loop, VEC (gimple, heap) *stmts)
>   res = ldist_gen (loop, rdg, vertices);
>   VEC_free (int, heap, vertices);
>   free_rdg (rdg);
> -
> +  free_dependence_relations (dependence_relations);
> +  free_data_refs (datarefs);
>   return res;
>  }
>
> diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
> index 2644c9e..3aa21c7 100644
> --- a/gcc/tree-vect-loop.c
> +++ b/gcc/tree-vect-loop.c
> @@ -794,6 +794,7 @@ destroy_loop_vec_info (loop_vec_info loop_vinfo, bool clean_stmts)
>       free_data_refs (LOOP_VINFO_DATAREFS (loop_vinfo));
>       free_dependence_relations (LOOP_VINFO_DDRS (loop_vinfo));
>       VEC_free (gimple, heap, LOOP_VINFO_MAY_MISALIGN_STMTS (loop_vinfo));
> +      VEC_free (ddr_p, heap, LOOP_VINFO_MAY_ALIAS_DDRS (loop_vinfo));
>
>       free (loop_vinfo);
>       loop->aux = NULL;
> diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
> index fdaaff2..00fb345 100644
> --- a/gcc/tree-vect-slp.c
> +++ b/gcc/tree-vect-slp.c
> @@ -1457,6 +1457,8 @@ destroy_bb_vec_info (bb_vec_info bb_vinfo)
>         free_stmt_vec_info (stmt);
>     }
>
> +  free_data_refs (BB_VINFO_DATAREFS (bb_vinfo));
> +  free_dependence_relations (BB_VINFO_DDRS (bb_vinfo));
>   VEC_free (gimple, heap, BB_VINFO_STRIDED_STORES (bb_vinfo));
>   VEC_free (slp_instance, heap, BB_VINFO_SLP_INSTANCES (bb_vinfo));
>   free (bb_vinfo);
> --
> 1.7.1
>
>
Jack Howarth - Dec. 22, 2010, 9:37 p.m.
On Wed, Dec 22, 2010 at 12:17:10AM -0600, Sebastian Pop wrote:
> Hi,
> 
> Although I am not able to reproduce the error reported on
> http://gcc.gnu.org/PR47002 I went and fixed all the memory leaks I
> found related to the tree-loop-distribution.c and tree-data-ref.c
> reported by valgrind --leak-check=full ./cc1 -O3 pr47002.i
> I am testing this patch on amd64-linux.  Ok for trunk after test?
> 
> Thanks,
> Sebastian

Sebastian,
   On x86_64-apple-darwin10 with a standard bootstrap and -fgraphite-identity
enabled at -O2, this seems to be causing an ICE in the libgfortran build...

/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/./gcc/xgcc -B/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/./gcc/ -B/sw/lib/gcc4.6/x86_64-apple-darwin10.5.0/bin/ -B/sw/lib/gcc4.6/x86_64-apple-darwin10.5.0/lib/ -isystem /sw/lib/gcc4.6/x86_64-apple-darwin10.5.0/include -isystem /sw/lib/gcc4.6/x86_64-apple-darwin10.5.0/sys-include -DHAVE_CONFIG_H -I. -I../../../gcc-4.6-20101222/libgfortran -iquote../../../gcc-4.6-20101222/libgfortran/io -I../../../gcc-4.6-20101222/libgfortran/../gcc -I../../../gcc-4.6-20101222/libgfortran/../gcc/config -I../../../gcc-4.6-20101222/libgfortran/../libquadmath -I../.././gcc -D_GNU_SOURCE -std=gnu99 -Wall -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Wextra -Wwrite-strings -fcx-fortran-rules -ffunction-sections -fdata-sections -ftree-vectorize -funroll-loops -g -O2 -MT matmul_i4.lo -MD -MP -MF .deps/matmul_i4.Tpo -c ../../../gcc-4.6-20101222/libgfortran/generated/matmul_i4.c  -fno-common -DPIC -o .libs/matmul_i4.o
../../../gcc-4.6-20101222/libgfortran/generated/matmul_i4.c: In function 'matmul_i4':
../../../gcc-4.6-20101222/libgfortran/generated/matmul_i4.c:79:1: internal compiler error: Segmentation fault

which backtraces as...

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
0x00000001007f1689 in vect_analyze_data_refs_alignment (loop_vinfo=0x142b2fcd0, bb_vinfo=0x0) at tree-data-ref.h:595
595	    if (loopi->num == var)
(gdb) bt
#0  0x00000001007f1689 in vect_analyze_data_refs_alignment (loop_vinfo=0x142b2fcd0, bb_vinfo=0x0) at tree-data-ref.h:595
#1  0x000000010080f3a8 in vect_analyze_loop (loop=0x100fc9b28) at ../../gcc-4.6-20101222/gcc/tree-vect-loop.c:1451

      Jack
> 
> 2010-12-22  Sebastian Pop  <sebastian.pop@amd.com>
> 
> 	PR tree-optimization/47002
> 	* tree-data-ref.c (compute_data_dependences_for_loop): Free vloops.
> 	(free_dependence_relations): Do not free loop_nest.
> 	(build_rdg): Pass in datarefs and dependence_relations.
> 	(free_rdg): Also free the data on edges.
> 	* tree-data-ref.h (build_rdg): Update declaration.
> 	* tree-loop-distribution.c (rdg_flag_loop_exits): Free conds.
> 	(rdg_build_partitions): Free comps.
> 	(ldist_gen): Free components.
> 	(distribute_loop): Update call to build_rdg.  Allocate and free
> 	datarefs and dependence_relations.
> 	* tree-vect-loop.c (destroy_loop_vec_info): Free
> 	LOOP_VINFO_MAY_ALIAS_DDRS.
> 	* tree-vect-slp.c (destroy_bb_vec_info): Call free_data_refs and
> 	free_dependence_relations.
> ---
>  gcc/ChangeLog                |   18 +++++++++++
>  gcc/tree-data-ref.c          |   70 ++++++++++++++++++------------------------
>  gcc/tree-data-ref.h          |    3 +-
>  gcc/tree-loop-distribution.c |   15 ++++++++-
>  gcc/tree-vect-loop.c         |    1 +
>  gcc/tree-vect-slp.c          |    2 +
>  6 files changed, 66 insertions(+), 43 deletions(-)
> 
> diff --git a/gcc/ChangeLog b/gcc/ChangeLog
> index 944f806..9fcdd6c 100644
> --- a/gcc/ChangeLog
> +++ b/gcc/ChangeLog
> @@ -1,3 +1,21 @@
> +2010-12-22  Sebastian Pop  <sebastian.pop@amd.com>
> +
> +	PR tree-optimization/47002
> +	* tree-data-ref.c (compute_data_dependences_for_loop): Free vloops.
> +	(free_dependence_relations): Do not free loop_nest.
> +	(build_rdg): Pass in datarefs and dependence_relations.
> +	(free_rdg): Also free the data on edges.
> +	* tree-data-ref.h (build_rdg): Update declaration.
> +	* tree-loop-distribution.c (rdg_flag_loop_exits): Free conds.
> +	(rdg_build_partitions): Free comps.
> +	(ldist_gen): Free components.
> +	(distribute_loop): Update call to build_rdg.  Allocate and free
> +	datarefs and dependence_relations.
> +	* tree-vect-loop.c (destroy_loop_vec_info): Free
> +	LOOP_VINFO_MAY_ALIAS_DDRS.
> +	* tree-vect-slp.c (destroy_bb_vec_info): Call free_data_refs and
> +	free_dependence_relations.
> +
>  2010-12-17  Paolo Bonzini  <bonzini@gnu.org>
>  
>  	PR c/20385
> diff --git a/gcc/tree-data-ref.c b/gcc/tree-data-ref.c
> index a6d0731..dc14989 100644
> --- a/gcc/tree-data-ref.c
> +++ b/gcc/tree-data-ref.c
> @@ -4274,6 +4274,9 @@ compute_data_dependences_for_loop (struct loop *loop,
>      compute_all_dependences (*datarefs, dependence_relations, vloops,
>  			     compute_self_and_read_read_dependences);
>  
> +  if (vloops)
> +    VEC_free (loop_p, heap, vloops);
> +
>    if (dump_file && (dump_flags & TDF_STATS))
>      {
>        fprintf (dump_file, "Dependence tester statistics:\n");
> @@ -4454,22 +4457,11 @@ free_dependence_relations (VEC (ddr_p, heap) *dependence_relations)
>  {
>    unsigned int i;
>    struct data_dependence_relation *ddr;
> -  VEC (loop_p, heap) *loop_nest = NULL;
>  
>    FOR_EACH_VEC_ELT (ddr_p, dependence_relations, i, ddr)
> -    {
> -      if (ddr == NULL)
> -	continue;
> -      if (loop_nest == NULL)
> -	loop_nest = DDR_LOOP_NEST (ddr);
> -      else
> -	gcc_assert (DDR_LOOP_NEST (ddr) == NULL
> -		    || DDR_LOOP_NEST (ddr) == loop_nest);
> +    if (ddr)
>        free_dependence_relation (ddr);
> -    }
>  
> -  if (loop_nest)
> -    VEC_free (loop_p, heap, loop_nest);
>    VEC_free (ddr_p, heap, dependence_relations);
>  }
>  
> @@ -4905,37 +4897,23 @@ build_empty_rdg (int n_stmts)
>     scalar dependence.  */
>  
>  struct graph *
> -build_rdg (struct loop *loop)
> +build_rdg (struct loop *loop,
> +	   VEC (ddr_p, heap) **dependence_relations,
> +	   VEC (data_reference_p, heap) **datarefs)
>  {
> -  int nb_data_refs = 10;
>    struct graph *rdg = NULL;
> -  VEC (ddr_p, heap) *dependence_relations;
> -  VEC (data_reference_p, heap) *datarefs;
> -  VEC (gimple, heap) *stmts = VEC_alloc (gimple, heap, nb_data_refs);
> -
> -  dependence_relations = VEC_alloc (ddr_p, heap, nb_data_refs * nb_data_refs) ;
> -  datarefs = VEC_alloc (data_reference_p, heap, nb_data_refs);
> -  compute_data_dependences_for_loop (loop,
> -                                     false,
> -                                     &datarefs,
> -                                     &dependence_relations);
> -
> -  if (!known_dependences_p (dependence_relations))
> -    {
> -      free_dependence_relations (dependence_relations);
> -      free_data_refs (datarefs);
> -      VEC_free (gimple, heap, stmts);
> -
> -      return rdg;
> -    }
> +  VEC (gimple, heap) *stmts = VEC_alloc (gimple, heap, 10);
>  
> -  stmts_from_loop (loop, &stmts);
> -  rdg = build_empty_rdg (VEC_length (gimple, stmts));
> +  compute_data_dependences_for_loop (loop, false, datarefs,
> +				     dependence_relations);
>  
> -  rdg->indices = htab_create (nb_data_refs, hash_stmt_vertex_info,
> -			      eq_stmt_vertex_info, hash_stmt_vertex_del);
> -  create_rdg_vertices (rdg, stmts);
> -  create_rdg_edges (rdg, dependence_relations);
> +  if (known_dependences_p (*dependence_relations))
> +    {
> +      stmts_from_loop (loop, &stmts);
> +      rdg = build_empty_rdg (VEC_length (gimple, stmts));
> +      create_rdg_vertices (rdg, stmts);
> +      create_rdg_edges (rdg, *dependence_relations);
> +    }
>  
>    VEC_free (gimple, heap, stmts);
>    return rdg;
> @@ -4949,7 +4927,19 @@ free_rdg (struct graph *rdg)
>    int i;
>  
>    for (i = 0; i < rdg->n_vertices; i++)
> -    free (rdg->vertices[i].data);
> +    {
> +      struct vertex *v = &(rdg->vertices[i]);
> +      struct graph_edge *e;
> +
> +      for (e = v->succ; e; e = e->succ_next)
> +	{
> +	  free_dependence_relation (RDGE_RELATION (e));
> +	  if (e->data)
> +	    free (e->data);
> +	}
> +
> +      free (v->data);
> +    }
>  
>    htab_delete (rdg->indices);
>    free_graph (rdg);
> diff --git a/gcc/tree-data-ref.h b/gcc/tree-data-ref.h
> index b4f317f..8585b2b 100644
> --- a/gcc/tree-data-ref.h
> +++ b/gcc/tree-data-ref.h
> @@ -577,7 +577,8 @@ typedef struct rdg_edge
>  #define RDGE_LEVEL(E)       ((struct rdg_edge *) ((E)->data))->level
>  #define RDGE_RELATION(E)    ((struct rdg_edge *) ((E)->data))->relation
>  
> -struct graph *build_rdg (struct loop *);
> +struct graph *build_rdg (struct loop *, VEC (ddr_p, heap) **,
> +			 VEC (data_reference_p, heap) **);
>  struct graph *build_empty_rdg (int);
>  void free_rdg (struct graph *);
>  
> diff --git a/gcc/tree-loop-distribution.c b/gcc/tree-loop-distribution.c
> index a9ee67f..d095e8a 100644
> --- a/gcc/tree-loop-distribution.c
> +++ b/gcc/tree-loop-distribution.c
> @@ -653,6 +653,8 @@ rdg_flag_loop_exits (struct graph *rdg, bitmap loops, bitmap partition,
>  
>        BITMAP_FREE (new_loops);
>      }
> +
> +  VEC_free (gimple, heap, conds);
>  }
>  
>  /* Returns a bitmap in which all the statements needed for computing
> @@ -965,6 +967,7 @@ rdg_build_partitions (struct graph *rdg, VEC (rdgc, heap) *components,
>  
>        VEC_free (int, heap, foo);
>        free_rdg_components (comps);
> +      VEC_free (rdgc, heap, comps);
>      }
>  
>    add_scalar_computations_to_partition (rdg, *partitions, partition);
> @@ -1129,6 +1132,7 @@ ldist_gen (struct loop *loop, struct graph *rdg,
>    VEC_free (int, heap, other_stores);
>    VEC_free (bitmap, heap, partitions);
>    free_rdg_components (components);
> +  VEC_free (rdgc, heap, components);
>    return nbp;
>  }
>  
> @@ -1146,6 +1150,8 @@ distribute_loop (struct loop *loop, VEC (gimple, heap) *stmts)
>    gimple s;
>    unsigned i;
>    VEC (int, heap) *vertices;
> +  VEC (ddr_p, heap) *dependence_relations;
> +  VEC (data_reference_p, heap) *datarefs;
>  
>    if (loop->num_nodes > 2)
>      {
> @@ -1157,7 +1163,9 @@ distribute_loop (struct loop *loop, VEC (gimple, heap) *stmts)
>        return res;
>      }
>  
> -  rdg = build_rdg (loop);
> +  datarefs = VEC_alloc (data_reference_p, heap, 10);
> +  dependence_relations = VEC_alloc (ddr_p, heap, 100);
> +  rdg = build_rdg (loop, &dependence_relations, &datarefs);
>  
>    if (!rdg)
>      {
> @@ -1166,6 +1174,8 @@ distribute_loop (struct loop *loop, VEC (gimple, heap) *stmts)
>  		 "FIXME: Loop %d not distributed: failed to build the RDG.\n",
>  		 loop->num);
>  
> +      free_dependence_relations (dependence_relations);
> +      free_data_refs (datarefs);
>        return res;
>      }
>  
> @@ -1191,7 +1201,8 @@ distribute_loop (struct loop *loop, VEC (gimple, heap) *stmts)
>    res = ldist_gen (loop, rdg, vertices);
>    VEC_free (int, heap, vertices);
>    free_rdg (rdg);
> -
> +  free_dependence_relations (dependence_relations);
> +  free_data_refs (datarefs);
>    return res;
>  }
>  
> diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
> index 2644c9e..3aa21c7 100644
> --- a/gcc/tree-vect-loop.c
> +++ b/gcc/tree-vect-loop.c
> @@ -794,6 +794,7 @@ destroy_loop_vec_info (loop_vec_info loop_vinfo, bool clean_stmts)
>        free_data_refs (LOOP_VINFO_DATAREFS (loop_vinfo));
>        free_dependence_relations (LOOP_VINFO_DDRS (loop_vinfo));
>        VEC_free (gimple, heap, LOOP_VINFO_MAY_MISALIGN_STMTS (loop_vinfo));
> +      VEC_free (ddr_p, heap, LOOP_VINFO_MAY_ALIAS_DDRS (loop_vinfo));
>  
>        free (loop_vinfo);
>        loop->aux = NULL;
> diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
> index fdaaff2..00fb345 100644
> --- a/gcc/tree-vect-slp.c
> +++ b/gcc/tree-vect-slp.c
> @@ -1457,6 +1457,8 @@ destroy_bb_vec_info (bb_vec_info bb_vinfo)
>          free_stmt_vec_info (stmt);
>      }
>  
> +  free_data_refs (BB_VINFO_DATAREFS (bb_vinfo));
> +  free_dependence_relations (BB_VINFO_DDRS (bb_vinfo));
>    VEC_free (gimple, heap, BB_VINFO_STRIDED_STORES (bb_vinfo));
>    VEC_free (slp_instance, heap, BB_VINFO_SLP_INSTANCES (bb_vinfo));
>    free (bb_vinfo);
> -- 
> 1.7.1

Patch

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 944f806..9fcdd6c 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,21 @@ 
+2010-12-22  Sebastian Pop  <sebastian.pop@amd.com>
+
+	PR tree-optimization/47002
+	* tree-data-ref.c (compute_data_dependences_for_loop): Free vloops.
+	(free_dependence_relations): Do not free loop_nest.
+	(build_rdg): Pass in datarefs and dependence_relations.
+	(free_rdg): Also free the data on edges.
+	* tree-data-ref.h (build_rdg): Update declaration.
+	* tree-loop-distribution.c (rdg_flag_loop_exits): Free conds.
+	(rdg_build_partitions): Free comps.
+	(ldist_gen): Free components.
+	(distribute_loop): Update call to build_rdg.  Allocate and free
+	datarefs and dependence_relations.
+	* tree-vect-loop.c (destroy_loop_vec_info): Free
+	LOOP_VINFO_MAY_ALIAS_DDRS.
+	* tree-vect-slp.c (destroy_bb_vec_info): Call free_data_refs and
+	free_dependence_relations.
+
 2010-12-17  Paolo Bonzini  <bonzini@gnu.org>
 
 	PR c/20385
diff --git a/gcc/tree-data-ref.c b/gcc/tree-data-ref.c
index a6d0731..dc14989 100644
--- a/gcc/tree-data-ref.c
+++ b/gcc/tree-data-ref.c
@@ -4274,6 +4274,9 @@  compute_data_dependences_for_loop (struct loop *loop,
     compute_all_dependences (*datarefs, dependence_relations, vloops,
 			     compute_self_and_read_read_dependences);
 
+  if (vloops)
+    VEC_free (loop_p, heap, vloops);
+
   if (dump_file && (dump_flags & TDF_STATS))
     {
       fprintf (dump_file, "Dependence tester statistics:\n");
@@ -4454,22 +4457,11 @@  free_dependence_relations (VEC (ddr_p, heap) *dependence_relations)
 {
   unsigned int i;
   struct data_dependence_relation *ddr;
-  VEC (loop_p, heap) *loop_nest = NULL;
 
   FOR_EACH_VEC_ELT (ddr_p, dependence_relations, i, ddr)
-    {
-      if (ddr == NULL)
-	continue;
-      if (loop_nest == NULL)
-	loop_nest = DDR_LOOP_NEST (ddr);
-      else
-	gcc_assert (DDR_LOOP_NEST (ddr) == NULL
-		    || DDR_LOOP_NEST (ddr) == loop_nest);
+    if (ddr)
       free_dependence_relation (ddr);
-    }
 
-  if (loop_nest)
-    VEC_free (loop_p, heap, loop_nest);
   VEC_free (ddr_p, heap, dependence_relations);
 }
 
@@ -4905,37 +4897,23 @@  build_empty_rdg (int n_stmts)
    scalar dependence.  */
 
 struct graph *
-build_rdg (struct loop *loop)
+build_rdg (struct loop *loop,
+	   VEC (ddr_p, heap) **dependence_relations,
+	   VEC (data_reference_p, heap) **datarefs)
 {
-  int nb_data_refs = 10;
   struct graph *rdg = NULL;
-  VEC (ddr_p, heap) *dependence_relations;
-  VEC (data_reference_p, heap) *datarefs;
-  VEC (gimple, heap) *stmts = VEC_alloc (gimple, heap, nb_data_refs);
-
-  dependence_relations = VEC_alloc (ddr_p, heap, nb_data_refs * nb_data_refs) ;
-  datarefs = VEC_alloc (data_reference_p, heap, nb_data_refs);
-  compute_data_dependences_for_loop (loop,
-                                     false,
-                                     &datarefs,
-                                     &dependence_relations);
-
-  if (!known_dependences_p (dependence_relations))
-    {
-      free_dependence_relations (dependence_relations);
-      free_data_refs (datarefs);
-      VEC_free (gimple, heap, stmts);
-
-      return rdg;
-    }
+  VEC (gimple, heap) *stmts = VEC_alloc (gimple, heap, 10);
 
-  stmts_from_loop (loop, &stmts);
-  rdg = build_empty_rdg (VEC_length (gimple, stmts));
+  compute_data_dependences_for_loop (loop, false, datarefs,
+				     dependence_relations);
 
-  rdg->indices = htab_create (nb_data_refs, hash_stmt_vertex_info,
-			      eq_stmt_vertex_info, hash_stmt_vertex_del);
-  create_rdg_vertices (rdg, stmts);
-  create_rdg_edges (rdg, dependence_relations);
+  if (known_dependences_p (*dependence_relations))
+    {
+      stmts_from_loop (loop, &stmts);
+      rdg = build_empty_rdg (VEC_length (gimple, stmts));
+      create_rdg_vertices (rdg, stmts);
+      create_rdg_edges (rdg, *dependence_relations);
+    }
 
   VEC_free (gimple, heap, stmts);
   return rdg;
@@ -4949,7 +4927,19 @@  free_rdg (struct graph *rdg)
   int i;
 
   for (i = 0; i < rdg->n_vertices; i++)
-    free (rdg->vertices[i].data);
+    {
+      struct vertex *v = &(rdg->vertices[i]);
+      struct graph_edge *e;
+
+      for (e = v->succ; e; e = e->succ_next)
+	{
+	  free_dependence_relation (RDGE_RELATION (e));
+	  if (e->data)
+	    free (e->data);
+	}
+
+      free (v->data);
+    }
 
   htab_delete (rdg->indices);
   free_graph (rdg);
diff --git a/gcc/tree-data-ref.h b/gcc/tree-data-ref.h
index b4f317f..8585b2b 100644
--- a/gcc/tree-data-ref.h
+++ b/gcc/tree-data-ref.h
@@ -577,7 +577,8 @@  typedef struct rdg_edge
 #define RDGE_LEVEL(E)       ((struct rdg_edge *) ((E)->data))->level
 #define RDGE_RELATION(E)    ((struct rdg_edge *) ((E)->data))->relation
 
-struct graph *build_rdg (struct loop *);
+struct graph *build_rdg (struct loop *, VEC (ddr_p, heap) **,
+			 VEC (data_reference_p, heap) **);
 struct graph *build_empty_rdg (int);
 void free_rdg (struct graph *);
 
diff --git a/gcc/tree-loop-distribution.c b/gcc/tree-loop-distribution.c
index a9ee67f..d095e8a 100644
--- a/gcc/tree-loop-distribution.c
+++ b/gcc/tree-loop-distribution.c
@@ -653,6 +653,8 @@  rdg_flag_loop_exits (struct graph *rdg, bitmap loops, bitmap partition,
 
       BITMAP_FREE (new_loops);
     }
+
+  VEC_free (gimple, heap, conds);
 }
 
 /* Returns a bitmap in which all the statements needed for computing
@@ -965,6 +967,7 @@  rdg_build_partitions (struct graph *rdg, VEC (rdgc, heap) *components,
 
       VEC_free (int, heap, foo);
       free_rdg_components (comps);
+      VEC_free (rdgc, heap, comps);
     }
 
   add_scalar_computations_to_partition (rdg, *partitions, partition);
@@ -1129,6 +1132,7 @@  ldist_gen (struct loop *loop, struct graph *rdg,
   VEC_free (int, heap, other_stores);
   VEC_free (bitmap, heap, partitions);
   free_rdg_components (components);
+  VEC_free (rdgc, heap, components);
   return nbp;
 }
 
@@ -1146,6 +1150,8 @@  distribute_loop (struct loop *loop, VEC (gimple, heap) *stmts)
   gimple s;
   unsigned i;
   VEC (int, heap) *vertices;
+  VEC (ddr_p, heap) *dependence_relations;
+  VEC (data_reference_p, heap) *datarefs;
 
   if (loop->num_nodes > 2)
     {
@@ -1157,7 +1163,9 @@  distribute_loop (struct loop *loop, VEC (gimple, heap) *stmts)
       return res;
     }
 
-  rdg = build_rdg (loop);
+  datarefs = VEC_alloc (data_reference_p, heap, 10);
+  dependence_relations = VEC_alloc (ddr_p, heap, 100);
+  rdg = build_rdg (loop, &dependence_relations, &datarefs);
 
   if (!rdg)
     {
@@ -1166,6 +1174,8 @@  distribute_loop (struct loop *loop, VEC (gimple, heap) *stmts)
 		 "FIXME: Loop %d not distributed: failed to build the RDG.\n",
 		 loop->num);
 
+      free_dependence_relations (dependence_relations);
+      free_data_refs (datarefs);
       return res;
     }
 
@@ -1191,7 +1201,8 @@  distribute_loop (struct loop *loop, VEC (gimple, heap) *stmts)
   res = ldist_gen (loop, rdg, vertices);
   VEC_free (int, heap, vertices);
   free_rdg (rdg);
-
+  free_dependence_relations (dependence_relations);
+  free_data_refs (datarefs);
   return res;
 }
 
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index 2644c9e..3aa21c7 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -794,6 +794,7 @@  destroy_loop_vec_info (loop_vec_info loop_vinfo, bool clean_stmts)
       free_data_refs (LOOP_VINFO_DATAREFS (loop_vinfo));
       free_dependence_relations (LOOP_VINFO_DDRS (loop_vinfo));
       VEC_free (gimple, heap, LOOP_VINFO_MAY_MISALIGN_STMTS (loop_vinfo));
+      VEC_free (ddr_p, heap, LOOP_VINFO_MAY_ALIAS_DDRS (loop_vinfo));
 
       free (loop_vinfo);
       loop->aux = NULL;
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index fdaaff2..00fb345 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -1457,6 +1457,8 @@  destroy_bb_vec_info (bb_vec_info bb_vinfo)
         free_stmt_vec_info (stmt);
     }
 
+  free_data_refs (BB_VINFO_DATAREFS (bb_vinfo));
+  free_dependence_relations (BB_VINFO_DDRS (bb_vinfo));
   VEC_free (gimple, heap, BB_VINFO_STRIDED_STORES (bb_vinfo));
   VEC_free (slp_instance, heap, BB_VINFO_SLP_INSTANCES (bb_vinfo));
   free (bb_vinfo);