Patchwork More leak plugs for PR54146

login
register
mail settings
Submitter Richard Guenther
Date Aug. 17, 2012, 7:46 a.m.
Message ID <alpine.LNX.2.00.1208170946030.28649@zhemvz.fhfr.qr>
Download mbox | patch
Permalink /patch/178155/
State New
Headers show

Comments

Richard Guenther - Aug. 17, 2012, 7:46 a.m.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2012-08-16  Richard Guenther  <rguenther@suse.de>

	* tree-sra.c (modify_function): Free redirect_callers vector.
	* ipa-split.c (split_function): Free args_to_pass vector.
	* tree-vect-data-refs.c (vect_peeling_hash_get_lowest_cost): Free
	body_cost_vec properly.
	(vect_enhance_data_refs_alignment): Likewise.
	* tree-vect-stmts.c (vectorizable_operation): Do not pre-allocate
	vec_oprnds.
	(new_stmt_vec_info): Do not pre-allocate STMT_VINFO_SAME_ALIGN_REFS.
	* tree-vect-slp.c (vect_free_slp_instance): Free the instance.
	(vect_analyze_slp_instance): Free everything.
	(destroy_bb_vec_info): Free the SLP instances.
Jakub Jelinek - Aug. 17, 2012, 7:54 a.m.
On Fri, Aug 17, 2012 at 09:46:35AM +0200, Richard Guenther wrote:
> --- gcc/tree-vect-slp.c	(revision 190447)
> +++ gcc/tree-vect-slp.c	(working copy)
> @@ -1858,8 +1862,11 @@ new_bb_vec_info (basic_block bb)
>  static void
>  destroy_bb_vec_info (bb_vec_info bb_vinfo)
>  {
> +  VEC (slp_instance, heap) *slp_instances;
> +  slp_instance instance;
>    basic_block bb;
>    gimple_stmt_iterator si;
> +  unsigned i;
>  
>    if (!bb_vinfo)
>      return;
> @@ -1879,6 +1886,9 @@ destroy_bb_vec_info (bb_vec_info bb_vinf
>    free_data_refs (BB_VINFO_DATAREFS (bb_vinfo));
>    free_dependence_relations (BB_VINFO_DDRS (bb_vinfo));
>    VEC_free (gimple, heap, BB_VINFO_GROUPED_STORES (bb_vinfo));
> +  slp_instances = BB_VINFO_SLP_INSTANCES (bb_vinfo);
> +  FOR_EACH_VEC_ELT (slp_instance, slp_instances, i, instance)
> +    vect_free_slp_instance (instance);
>    VEC_free (slp_instance, heap, BB_VINFO_SLP_INSTANCES (bb_vinfo));

In this case you should use slp_instances instead of
BB_VINFO_SLP_INSTANCES (bb_vinfo) also in the above VEC_free call.

>    destroy_cost_data (BB_VINFO_TARGET_COST_DATA (bb_vinfo));
>    free (bb_vinfo);

	Jakub
Richard Guenther - Aug. 17, 2012, 8:03 a.m.
On Fri, 17 Aug 2012, Jakub Jelinek wrote:

> On Fri, Aug 17, 2012 at 09:46:35AM +0200, Richard Guenther wrote:
> > --- gcc/tree-vect-slp.c	(revision 190447)
> > +++ gcc/tree-vect-slp.c	(working copy)
> > @@ -1858,8 +1862,11 @@ new_bb_vec_info (basic_block bb)
> >  static void
> >  destroy_bb_vec_info (bb_vec_info bb_vinfo)
> >  {
> > +  VEC (slp_instance, heap) *slp_instances;
> > +  slp_instance instance;
> >    basic_block bb;
> >    gimple_stmt_iterator si;
> > +  unsigned i;
> >  
> >    if (!bb_vinfo)
> >      return;
> > @@ -1879,6 +1886,9 @@ destroy_bb_vec_info (bb_vec_info bb_vinf
> >    free_data_refs (BB_VINFO_DATAREFS (bb_vinfo));
> >    free_dependence_relations (BB_VINFO_DDRS (bb_vinfo));
> >    VEC_free (gimple, heap, BB_VINFO_GROUPED_STORES (bb_vinfo));
> > +  slp_instances = BB_VINFO_SLP_INSTANCES (bb_vinfo);
> > +  FOR_EACH_VEC_ELT (slp_instance, slp_instances, i, instance)
> > +    vect_free_slp_instance (instance);
> >    VEC_free (slp_instance, heap, BB_VINFO_SLP_INSTANCES (bb_vinfo));
> 
> In this case you should use slp_instances instead of
> BB_VINFO_SLP_INSTANCES (bb_vinfo) also in the above VEC_free call.

I followed the destroy_loop_vec_info pattern which probably uses
BB_VINFO_SLP_INSTANCES because it NULLs the vector in the place
we actually store it.  Which is not really important of course,
as we free bb_vinfo immediately.

Richard.

> >    destroy_cost_data (BB_VINFO_TARGET_COST_DATA (bb_vinfo));
> >    free (bb_vinfo);
> 
> 	Jakub
> 
>

Patch

Index: gcc/ipa-split.c
===================================================================
--- gcc/ipa-split.c	(revision 190447)
+++ gcc/ipa-split.c	(working copy)
@@ -1230,6 +1230,7 @@  split_function (struct split_point *spli
       }
   call = gimple_build_call_vec (node->symbol.decl, args_to_pass);
   gimple_set_block (call, DECL_INITIAL (current_function_decl));
+  VEC_free (tree, heap, args_to_pass);
 
   /* We avoid address being taken on any variable used by split part,
      so return slot optimization is always possible.  Moreover this is
Index: gcc/tree-vect-data-refs.c
===================================================================
--- gcc/tree-vect-data-refs.c	(revision 190447)
+++ gcc/tree-vect-data-refs.c	(working copy)
@@ -1368,6 +1368,7 @@  vect_peeling_hash_get_lowest_cost (void
     {
       min->inside_cost = inside_cost;
       min->outside_cost = outside_cost;
+      VEC_free (stmt_info_for_cost, heap, min->body_cost_vec);
       min->body_cost_vec = body_cost_vec;
       min->peel_info.dr = elem->dr;
       min->peel_info.npeel = elem->npeel;
@@ -1880,7 +1881,10 @@  vect_enhance_data_refs_alignment (loop_v
           if (!stat)
             do_peeling = false;
           else
-            return stat;
+	    {
+	      VEC_free (stmt_info_for_cost, heap, body_cost_vec);
+	      return stat;
+	    }
         }
 
       if (do_peeling)
@@ -1930,6 +1934,8 @@  vect_enhance_data_refs_alignment (loop_v
 	  gcc_assert (stat);
           return stat;
         }
+      else
+	VEC_free (stmt_info_for_cost, heap, body_cost_vec);
     }
 
 
Index: gcc/tree-vect-stmts.c
===================================================================
--- gcc/tree-vect-stmts.c	(revision 190447)
+++ gcc/tree-vect-stmts.c	(working copy)
@@ -3585,22 +3585,6 @@  vectorizable_operation (gimple stmt, gim
   /* Handle def.  */
   vec_dest = vect_create_destination_var (scalar_dest, vectype);
 
-  /* Allocate VECs for vector operands.  In case of SLP, vector operands are
-     created in the previous stages of the recursion, so no allocation is
-     needed, except for the case of shift with scalar shift argument.  In that
-     case we store the scalar operand in VEC_OPRNDS1 for every vector stmt to
-     be created to vectorize the SLP group, i.e., SLP_NODE->VEC_STMTS_SIZE.
-     In case of loop-based vectorization we allocate VECs of size 1.  We
-     allocate VEC_OPRNDS1 only in case of binary operation.  */
-  if (!slp_node)
-    {
-      vec_oprnds0 = VEC_alloc (tree, heap, 1);
-      if (op_type == binary_op || op_type == ternary_op)
-        vec_oprnds1 = VEC_alloc (tree, heap, 1);
-      if (op_type == ternary_op)
-        vec_oprnds2 = VEC_alloc (tree, heap, 1);
-    }
-
   /* In case the vectorization factor (VF) is bigger than the number
      of elements that we can fit in a vectype (nunits), we have to generate
      more than one vector stmt - i.e - we need to "unroll" the
@@ -5866,7 +5850,7 @@  new_stmt_vec_info (gimple stmt, loop_vec
   else
     STMT_VINFO_DEF_TYPE (res) = vect_internal_def;
 
-  STMT_VINFO_SAME_ALIGN_REFS (res) = VEC_alloc (dr_p, heap, 5);
+  STMT_VINFO_SAME_ALIGN_REFS (res) = NULL;
   STMT_SLP_TYPE (res) = loop_vect;
   GROUP_FIRST_ELEMENT (res) = NULL;
   GROUP_NEXT_ELEMENT (res) = NULL;
Index: gcc/tree-sra.c
===================================================================
--- gcc/tree-sra.c	(revision 190447)
+++ gcc/tree-sra.c	(working copy)
@@ -4698,6 +4698,8 @@  modify_function (struct cgraph_node *nod
 
   new_node = cgraph_function_versioning (node, redirect_callers, NULL, NULL,
 					 false, NULL, NULL, "isra");
+  VEC_free (cgraph_edge_p, heap, redirect_callers);
+
   current_function_decl = new_node->symbol.decl;
   push_cfun (DECL_STRUCT_FUNCTION (new_node->symbol.decl));
 
Index: gcc/tree-vect-slp.c
===================================================================
--- gcc/tree-vect-slp.c	(revision 190447)
+++ gcc/tree-vect-slp.c	(working copy)
@@ -94,6 +94,7 @@  vect_free_slp_instance (slp_instance ins
   VEC_free (int, heap, SLP_INSTANCE_LOAD_PERMUTATION (instance));
   VEC_free (slp_tree, heap, SLP_INSTANCE_LOADS (instance));
   VEC_free (stmt_info_for_cost, heap, SLP_INSTANCE_BODY_COST_VEC (instance));
+  free (instance);
 }
 
 
@@ -1581,8 +1582,11 @@  vect_analyze_slp_instance (loop_vec_info
           if (vect_print_dump_info (REPORT_SLP))
             fprintf (vect_dump, "Build SLP failed: unrolling required in basic"
                                " block SLP");
+	  vect_free_slp_tree (node);
 	  VEC_free (stmt_info_for_cost, heap, body_cost_vec);
 	  VEC_free (stmt_info_for_cost, heap, prologue_cost_vec);
+	  VEC_free (int, heap, load_permutation);
+	  VEC_free (slp_tree, heap, loads);
           return false;
         }
 
@@ -1858,8 +1862,11 @@  new_bb_vec_info (basic_block bb)
 static void
 destroy_bb_vec_info (bb_vec_info bb_vinfo)
 {
+  VEC (slp_instance, heap) *slp_instances;
+  slp_instance instance;
   basic_block bb;
   gimple_stmt_iterator si;
+  unsigned i;
 
   if (!bb_vinfo)
     return;
@@ -1879,6 +1886,9 @@  destroy_bb_vec_info (bb_vec_info bb_vinf
   free_data_refs (BB_VINFO_DATAREFS (bb_vinfo));
   free_dependence_relations (BB_VINFO_DDRS (bb_vinfo));
   VEC_free (gimple, heap, BB_VINFO_GROUPED_STORES (bb_vinfo));
+  slp_instances = BB_VINFO_SLP_INSTANCES (bb_vinfo);
+  FOR_EACH_VEC_ELT (slp_instance, slp_instances, i, instance)
+    vect_free_slp_instance (instance);
   VEC_free (slp_instance, heap, BB_VINFO_SLP_INSTANCES (bb_vinfo));
   destroy_cost_data (BB_VINFO_TARGET_COST_DATA (bb_vinfo));
   free (bb_vinfo);