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]

[PATCH] Fix PR58396


This fixes PR58396 and also fixes some memleaks.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2013-09-12  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/58396
	* tree-loop-distribution.c (create_rdg_edges): Free unused DDRs.
	(build_rdg): Take a loop-nest parameter, fix memleaks.
	(distribute_loop): Compute loop-nest here and pass it to build_rdg.

Index: gcc/tree-loop-distribution.c
===================================================================
*** gcc/tree-loop-distribution.c	(revision 202516)
--- gcc/tree-loop-distribution.c	(working copy)
*************** create_rdg_edges (struct graph *rdg, vec
*** 383,388 ****
--- 383,390 ----
    FOR_EACH_VEC_ELT (ddrs, i, ddr)
      if (DDR_ARE_DEPENDENT (ddr) == NULL_TREE)
        create_rdg_edge_for_ddr (rdg, ddr);
+     else
+       free_dependence_relation (ddr);
  
    for (i = 0; i < rdg->n_vertices; i++)
      FOR_EACH_PHI_OR_STMT_DEF (def_p, RDG_STMT (rdg, i),
*************** free_rdg (struct graph *rdg)
*** 519,568 ****
  }
  
  /* Build the Reduced Dependence Graph (RDG) with one vertex per
!    statement of the loop nest, and one edge per data dependence or
     scalar dependence.  */
  
  static struct graph *
! build_rdg (struct loop *loop)
  {
    struct graph *rdg;
-   vec<loop_p> loop_nest;
    vec<gimple> stmts;
    vec<data_reference_p> datarefs;
    vec<ddr_p> dependence_relations;
  
!   loop_nest.create (3);
!   if (!find_loop_nest (loop, &loop_nest))
!     {
!       loop_nest.release ();
!       return NULL;
!     }
! 
    stmts.create (10);
!   stmts_from_loop (loop, &stmts);
    rdg = build_empty_rdg (stmts.length ());
    datarefs.create (10);
!   if (!create_rdg_vertices (rdg, stmts, loop, &datarefs))
      {
        stmts.release ();
        free_rdg (rdg);
        return NULL;
      }
    stmts.release ();
    dependence_relations.create (100);
    if (!compute_all_dependences (datarefs, &dependence_relations, loop_nest,
  				false)
        || !known_dependences_p (dependence_relations))
      {
!       loop_nest.release ();
        datarefs.release ();
-       dependence_relations.release ();
        free_rdg (rdg);
        return NULL;
      }
-   loop_nest.release ();
    create_rdg_edges (rdg, dependence_relations);
    dependence_relations.release ();
  
    return rdg;
  }
--- 521,565 ----
  }
  
  /* Build the Reduced Dependence Graph (RDG) with one vertex per
!    statement of the loop nest LOOP_NEST, and one edge per data dependence or
     scalar dependence.  */
  
  static struct graph *
! build_rdg (vec<loop_p> loop_nest)
  {
    struct graph *rdg;
    vec<gimple> stmts;
    vec<data_reference_p> datarefs;
    vec<ddr_p> dependence_relations;
  
!   /* Create the RDG vertices from the stmts of the loop nest.  */
    stmts.create (10);
!   stmts_from_loop (loop_nest[0], &stmts);
    rdg = build_empty_rdg (stmts.length ());
    datarefs.create (10);
!   if (!create_rdg_vertices (rdg, stmts, loop_nest[0], &datarefs))
      {
        stmts.release ();
+       datarefs.release ();
        free_rdg (rdg);
        return NULL;
      }
    stmts.release ();
+ 
+   /* Create the RDG edges from the data dependences in the loop nest.  */
    dependence_relations.create (100);
    if (!compute_all_dependences (datarefs, &dependence_relations, loop_nest,
  				false)
        || !known_dependences_p (dependence_relations))
      {
!       free_dependence_relations (dependence_relations);
        datarefs.release ();
        free_rdg (rdg);
        return NULL;
      }
    create_rdg_edges (rdg, dependence_relations);
    dependence_relations.release ();
+   datarefs.release ();
  
    return rdg;
  }
*************** distribute_loop (struct loop *loop, vec<
*** 1809,1816 ****
    gimple s;
    unsigned i;
    vec<int> vertices;
  
!   rdg = build_rdg (loop);
    if (!rdg)
      {
        if (dump_file && (dump_flags & TDF_DETAILS))
--- 1806,1821 ----
    gimple s;
    unsigned i;
    vec<int> vertices;
+   vec<loop_p> loop_nest;
  
!   loop_nest.create (3);
!   if (!find_loop_nest (loop, &loop_nest))
!     {
!       loop_nest.release ();
!       return 0;
!     }
! 
!   rdg = build_rdg (loop_nest);
    if (!rdg)
      {
        if (dump_file && (dump_flags & TDF_DETAILS))
*************** distribute_loop (struct loop *loop, vec<
*** 1818,1823 ****
--- 1823,1829 ----
  		 "FIXME: Loop %d not distributed: failed to build the RDG.\n",
  		 loop->num);
  
+       loop_nest.release ();
        return res;
      }
  
*************** distribute_loop (struct loop *loop, vec<
*** 1843,1848 ****
--- 1849,1855 ----
    res = ldist_gen (loop, rdg, vertices);
    vertices.release ();
    free_rdg (rdg);
+   loop_nest.release ();
    return res;
  }
  


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