Patchwork [3/3] Loop flattening on loop-SSA.

login
register
mail settings
Submitter Sebastian Pop
Date Nov. 16, 2010, 11:03 p.m.
Message ID <AANLkTimjUaO4aHfWwrOJPQdzu=FQi8F9MhawVcmbV6Pa@mail.gmail.com>
Download mbox | patch
Permalink /patch/71471/
State New
Headers show

Comments

Sebastian Pop - Nov. 16, 2010, 11:03 p.m.
Hi,

I ran valgrind on cc1 and I still have found several memory leaks in
the code exercised by the loop flattening.  Attached is the patch on
top of the previous changes.  I will test this as well on amd64-linux.
Ok for trunk?

Thanks,
Sebastian

Patch

From ca452b744393b1cc78a123e6a4c27498b60429bf Mon Sep 17 00:00:00 2001
From: Sebastian Pop <sebpop@gmail.com>
Date: Tue, 16 Nov 2010 17:01:14 -0600
Subject: [PATCH] Fix memory leaks.

---
 gcc/cfgloop.c              |    1 +
 gcc/tree-loop-flattening.c |   10 ++++++----
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/gcc/cfgloop.c b/gcc/cfgloop.c
index bfab67b..109dc72 100644
--- a/gcc/cfgloop.c
+++ b/gcc/cfgloop.c
@@ -1285,6 +1285,7 @@  cancel_loop (struct loop *loop)
   for (i = 0; i < loop->num_nodes; i++)
     bbs[i]->loop_father = outer;
 
+  free (bbs);
   delete_loop (loop);
 }
 
diff --git a/gcc/tree-loop-flattening.c b/gcc/tree-loop-flattening.c
index cd49be1..e94ff2a 100644
--- a/gcc/tree-loop-flattening.c
+++ b/gcc/tree-loop-flattening.c
@@ -469,9 +469,7 @@  flatten_loop (loop_p loop, tree *scratch_pad)
 
   mark_dfs_back_edges ();
   bbs = get_loop_body (loop);
-
   back_edges = VEC_alloc (edge, heap, 3);
-  loop_body = VEC_alloc (basic_block, heap, 3);
 
   for (i = 0; i < n; i++)
     FOR_EACH_EDGE (e, ei, bbs[i]->succs)
@@ -484,9 +482,13 @@  flatten_loop (loop_p loop, tree *scratch_pad)
   /* Early return and do not modify the code when there are no back
      edges.  */
   if (VEC_empty (edge, back_edges))
-    return 0;
+    {
+      VEC_free (edge, heap, back_edges);
+      return 0;
+    }
 
   cancel_subloops (loop);
+  loop_body = VEC_alloc (basic_block, heap, VEC_length (edge, back_edges));
 
   /* Split the latch edge to make sure that the latch basic block does
      not contain code.  */
@@ -501,7 +503,7 @@  flatten_loop (loop_p loop, tree *scratch_pad)
       redirect_edge_and_branch_force (e, loop->latch);
 
       /* Save the basic block where it was pointing.  */
-      VEC_safe_push (basic_block, heap, loop_body, dest);
+      VEC_quick_push (basic_block, loop_body, dest);
     }
 
   update_loop_phi_nodes (loop, pred_e);
-- 
1.7.0.4