[6/6] return auto_vec from more dominance functions

Message ID 20210615055922.27205-6-tbsaunde@tbsaunde.org
State New
Headers show
Series
  • [1/6] auto_vec copy/move improvements
Related show

Commit Message

Trevor Saunders June 15, 2021, 5:59 a.m.
This ensures the vector gets cleaned up by the caller when appropriate.

Signed-off-by: Trevor Saunders <tbsaunde@tbsaunde.org>


bootstrapped and regtested on x86_64-linux-gnu, ok?

gcc/ChangeLog:

	* dominance.c (get_dominated_to_depth): Return auto_vec<basic_block>.
	* dominance.h (get_dominated_to_depth): Likewise.
	(get_all_dominated_blocks): Likewise.
	* cfgcleanup.c (delete_unreachable_blocks): Adjust.
	* gcse.c (hoist_code): Likewise.
	* tree-cfg.c (remove_edge_and_dominated_blocks): Likewise.
	* tree-parloops.c (oacc_entry_exit_ok): Likewise.
	* tree-ssa-dce.c (eliminate_unnecessary_stmts): Likewise.
	* tree-ssa-phiprop.c (pass_phiprop::execute): Likewise.
---
 gcc/cfgcleanup.c       |  4 +---
 gcc/dominance.c        |  6 +++---
 gcc/dominance.h        |  8 ++++----
 gcc/gcse.c             | 13 +++++--------
 gcc/tree-cfg.c         |  3 +--
 gcc/tree-parloops.c    |  3 +--
 gcc/tree-ssa-dce.c     |  3 +--
 gcc/tree-ssa-phiprop.c |  7 +++----
 8 files changed, 19 insertions(+), 28 deletions(-)

-- 
2.20.1

Comments

Michael Meissner via Gcc-patches June 15, 2021, 6:50 a.m. | #1
On Tue, Jun 15, 2021 at 8:03 AM Trevor Saunders <tbsaunde@tbsaunde.org> wrote:
>

> This ensures the vector gets cleaned up by the caller when appropriate.

>

> Signed-off-by: Trevor Saunders <tbsaunde@tbsaunde.org>

>

> bootstrapped and regtested on x86_64-linux-gnu, ok?


OK.

Richard.

> gcc/ChangeLog:

>

>         * dominance.c (get_dominated_to_depth): Return auto_vec<basic_block>.

>         * dominance.h (get_dominated_to_depth): Likewise.

>         (get_all_dominated_blocks): Likewise.

>         * cfgcleanup.c (delete_unreachable_blocks): Adjust.

>         * gcse.c (hoist_code): Likewise.

>         * tree-cfg.c (remove_edge_and_dominated_blocks): Likewise.

>         * tree-parloops.c (oacc_entry_exit_ok): Likewise.

>         * tree-ssa-dce.c (eliminate_unnecessary_stmts): Likewise.

>         * tree-ssa-phiprop.c (pass_phiprop::execute): Likewise.

> ---

>  gcc/cfgcleanup.c       |  4 +---

>  gcc/dominance.c        |  6 +++---

>  gcc/dominance.h        |  8 ++++----

>  gcc/gcse.c             | 13 +++++--------

>  gcc/tree-cfg.c         |  3 +--

>  gcc/tree-parloops.c    |  3 +--

>  gcc/tree-ssa-dce.c     |  3 +--

>  gcc/tree-ssa-phiprop.c |  7 +++----

>  8 files changed, 19 insertions(+), 28 deletions(-)

>

> diff --git a/gcc/cfgcleanup.c b/gcc/cfgcleanup.c

> index 17edc4f37ad..7b1e1ba6e80 100644

> --- a/gcc/cfgcleanup.c

> +++ b/gcc/cfgcleanup.c

> @@ -3027,7 +3027,7 @@ delete_unreachable_blocks (void)

>                 delete_basic_block (b);

>               else

>                 {

> -                 vec<basic_block> h

> +                 auto_vec<basic_block> h

>                     = get_all_dominated_blocks (CDI_DOMINATORS, b);

>

>                   while (h.length ())

> @@ -3040,8 +3040,6 @@ delete_unreachable_blocks (void)

>

>                       delete_basic_block (b);

>                     }

> -

> -                 h.release ();

>                 }

>

>               changed = true;

> diff --git a/gcc/dominance.c b/gcc/dominance.c

> index 4943102ff1d..6a262ce8283 100644

> --- a/gcc/dominance.c

> +++ b/gcc/dominance.c

> @@ -933,10 +933,10 @@ get_dominated_by_region (enum cdi_direction dir, basic_block *region,

>     produce a vector containing all dominated blocks.  The vector will be sorted

>     in preorder.  */

>

> -vec<basic_block>

> +auto_vec<basic_block>

>  get_dominated_to_depth (enum cdi_direction dir, basic_block bb, int depth)

>  {

> -  vec<basic_block> bbs = vNULL;

> +  auto_vec<basic_block> bbs;

>    unsigned i;

>    unsigned next_level_start;

>

> @@ -965,7 +965,7 @@ get_dominated_to_depth (enum cdi_direction dir, basic_block bb, int depth)

>  /* Returns the list of basic blocks including BB dominated by BB, in the

>     direction DIR.  The vector will be sorted in preorder.  */

>

> -vec<basic_block>

> +auto_vec<basic_block>

>  get_all_dominated_blocks (enum cdi_direction dir, basic_block bb)

>  {

>    return get_dominated_to_depth (dir, bb, 0);

> diff --git a/gcc/dominance.h b/gcc/dominance.h

> index c74ad297c6a..1a8c248ee98 100644

> --- a/gcc/dominance.h

> +++ b/gcc/dominance.h

> @@ -50,10 +50,10 @@ extern auto_vec<basic_block> get_dominated_by (enum cdi_direction, basic_block);

>  extern auto_vec<basic_block> get_dominated_by_region (enum cdi_direction,

>                                                          basic_block *,

>                                                          unsigned);

> -extern vec<basic_block> get_dominated_to_depth (enum cdi_direction,

> -                                                       basic_block, int);

> -extern vec<basic_block> get_all_dominated_blocks (enum cdi_direction,

> -                                                         basic_block);

> +extern auto_vec<basic_block> get_dominated_to_depth (enum cdi_direction,

> +                                                    basic_block, int);

> +extern auto_vec<basic_block> get_all_dominated_blocks (enum cdi_direction,

> +                                                      basic_block);

>  extern void redirect_immediate_dominators (enum cdi_direction, basic_block,

>                                            basic_block);

>  extern basic_block nearest_common_dominator (enum cdi_direction,

> diff --git a/gcc/gcse.c b/gcc/gcse.c

> index 9114f30705e..ecf7e51aac5 100644

> --- a/gcc/gcse.c

> +++ b/gcc/gcse.c

> @@ -3050,9 +3050,7 @@ static int

>  hoist_code (void)

>  {

>    basic_block bb, dominated;

> -  vec<basic_block> dom_tree_walk;

>    unsigned int dom_tree_walk_index;

> -  vec<basic_block> domby;

>    unsigned int i, j, k;

>    struct gcse_expr **index_map;

>    struct gcse_expr *expr;

> @@ -3106,15 +3104,16 @@ hoist_code (void)

>    if (flag_ira_hoist_pressure)

>      hoisted_bbs = BITMAP_ALLOC (NULL);

>

> -  dom_tree_walk = get_all_dominated_blocks (CDI_DOMINATORS,

> -                                           ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb);

> +  auto_vec<basic_block> dom_tree_walk

> +  = get_all_dominated_blocks (CDI_DOMINATORS,

> +                             ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb);

>

>    /* Walk over each basic block looking for potentially hoistable

>       expressions, nothing gets hoisted from the entry block.  */

>    FOR_EACH_VEC_ELT (dom_tree_walk, dom_tree_walk_index, bb)

>      {

> -      domby = get_dominated_to_depth (CDI_DOMINATORS, bb,

> -                                     param_max_hoist_depth);

> +      auto_vec<basic_block> domby

> +       = get_dominated_to_depth (CDI_DOMINATORS, bb, param_max_hoist_depth);

>

>        if (domby.length () == 0)

>         continue;

> @@ -3315,10 +3314,8 @@ hoist_code (void)

>               bitmap_clear (from_bbs);

>             }

>         }

> -      domby.release ();

>      }

>

> -  dom_tree_walk.release ();

>    BITMAP_FREE (from_bbs);

>    if (flag_ira_hoist_pressure)

>      BITMAP_FREE (hoisted_bbs);

> diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c

> index c9403deed19..4c32f83257f 100644

> --- a/gcc/tree-cfg.c

> +++ b/gcc/tree-cfg.c

> @@ -8683,7 +8683,6 @@ gimple_flow_call_edges_add (sbitmap blocks)

>  void

>  remove_edge_and_dominated_blocks (edge e)

>  {

> -  vec<basic_block> bbs_to_remove = vNULL;

>    vec<basic_block> bbs_to_fix_dom = vNULL;

>    edge f;

>    edge_iterator ei;

> @@ -8734,6 +8733,7 @@ remove_edge_and_dominated_blocks (edge e)

>      }

>

>    auto_bitmap df, df_idom;

> +  auto_vec<basic_block> bbs_to_remove;

>    if (none_removed)

>      bitmap_set_bit (df_idom,

>                     get_immediate_dominator (CDI_DOMINATORS, e->dest)->index);

> @@ -8800,7 +8800,6 @@ remove_edge_and_dominated_blocks (edge e)

>

>    iterate_fix_dominators (CDI_DOMINATORS, bbs_to_fix_dom, true);

>

> -  bbs_to_remove.release ();

>    bbs_to_fix_dom.release ();

>  }

>

> diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c

> index deff2d5e08b..fe1baef32a7 100644

> --- a/gcc/tree-parloops.c

> +++ b/gcc/tree-parloops.c

> @@ -3949,7 +3949,7 @@ oacc_entry_exit_ok (class loop *loop,

>                     reduction_info_table_type *reduction_list)

>  {

>    basic_block *loop_bbs = get_loop_body_in_dom_order (loop);

> -  vec<basic_block> region_bbs

> +  auto_vec<basic_block> region_bbs

>      = get_all_dominated_blocks (CDI_DOMINATORS, ENTRY_BLOCK_PTR_FOR_FN (cfun));

>

>    bitmap in_loop_bbs = BITMAP_ALLOC (NULL);

> @@ -3972,7 +3972,6 @@ oacc_entry_exit_ok (class loop *loop,

>         }

>      }

>

> -  region_bbs.release ();

>    free (loop_bbs);

>

>    BITMAP_FREE (in_loop_bbs);

> diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c

> index def6ae69e24..e2d3b63a30c 100644

> --- a/gcc/tree-ssa-dce.c

> +++ b/gcc/tree-ssa-dce.c

> @@ -1275,7 +1275,6 @@ eliminate_unnecessary_stmts (void)

>    gimple_stmt_iterator gsi, psi;

>    gimple *stmt;

>    tree call;

> -  vec<basic_block> h;

>    auto_vec<edge> to_remove_edges;

>

>    if (dump_file && (dump_flags & TDF_DETAILS))

> @@ -1306,6 +1305,7 @@ eliminate_unnecessary_stmts (void)

>

>       as desired.  */

>    gcc_assert (dom_info_available_p (CDI_DOMINATORS));

> +  auto_vec<basic_block> h;

>    h = get_all_dominated_blocks (CDI_DOMINATORS,

>                                 single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)));

>

> @@ -1460,7 +1460,6 @@ eliminate_unnecessary_stmts (void)

>        something_changed |= remove_dead_phis (bb);

>      }

>

> -  h.release ();

>

>    /* Since we don't track liveness of virtual PHI nodes, it is possible that we

>       rendered some PHI nodes unreachable while they are still in use.

> diff --git a/gcc/tree-ssa-phiprop.c b/gcc/tree-ssa-phiprop.c

> index 64d6eda5f6c..78b0461c839 100644

> --- a/gcc/tree-ssa-phiprop.c

> +++ b/gcc/tree-ssa-phiprop.c

> @@ -484,7 +484,6 @@ public:

>  unsigned int

>  pass_phiprop::execute (function *fun)

>  {

> -  vec<basic_block> bbs;

>    struct phiprop_d *phivn;

>    bool did_something = false;

>    basic_block bb;

> @@ -499,8 +498,9 @@ pass_phiprop::execute (function *fun)

>    phivn = XCNEWVEC (struct phiprop_d, n);

>

>    /* Walk the dominator tree in preorder.  */

> -  bbs = get_all_dominated_blocks (CDI_DOMINATORS,

> -                                 single_succ (ENTRY_BLOCK_PTR_FOR_FN (fun)));

> +  auto_vec<basic_block> bbs

> +  = get_all_dominated_blocks (CDI_DOMINATORS,

> +                             single_succ (ENTRY_BLOCK_PTR_FOR_FN (fun)));

>    FOR_EACH_VEC_ELT (bbs, i, bb)

>      {

>        /* Since we're going to move dereferences across predecessor

> @@ -514,7 +514,6 @@ pass_phiprop::execute (function *fun)

>    if (did_something)

>      gsi_commit_edge_inserts ();

>

> -  bbs.release ();

>    free (phivn);

>

>    free_dominance_info (CDI_POST_DOMINATORS);

> --

> 2.20.1

>

Patch

diff --git a/gcc/cfgcleanup.c b/gcc/cfgcleanup.c
index 17edc4f37ad..7b1e1ba6e80 100644
--- a/gcc/cfgcleanup.c
+++ b/gcc/cfgcleanup.c
@@ -3027,7 +3027,7 @@  delete_unreachable_blocks (void)
 		delete_basic_block (b);
 	      else
 		{
-		  vec<basic_block> h
+		  auto_vec<basic_block> h
 		    = get_all_dominated_blocks (CDI_DOMINATORS, b);
 
 		  while (h.length ())
@@ -3040,8 +3040,6 @@  delete_unreachable_blocks (void)
 
 		      delete_basic_block (b);
 		    }
-
-		  h.release ();
 		}
 
 	      changed = true;
diff --git a/gcc/dominance.c b/gcc/dominance.c
index 4943102ff1d..6a262ce8283 100644
--- a/gcc/dominance.c
+++ b/gcc/dominance.c
@@ -933,10 +933,10 @@  get_dominated_by_region (enum cdi_direction dir, basic_block *region,
    produce a vector containing all dominated blocks.  The vector will be sorted
    in preorder.  */
 
-vec<basic_block> 
+auto_vec<basic_block> 
 get_dominated_to_depth (enum cdi_direction dir, basic_block bb, int depth)
 {
-  vec<basic_block> bbs = vNULL;
+  auto_vec<basic_block> bbs;
   unsigned i;
   unsigned next_level_start;
 
@@ -965,7 +965,7 @@  get_dominated_to_depth (enum cdi_direction dir, basic_block bb, int depth)
 /* Returns the list of basic blocks including BB dominated by BB, in the
    direction DIR.  The vector will be sorted in preorder.  */
 
-vec<basic_block> 
+auto_vec<basic_block> 
 get_all_dominated_blocks (enum cdi_direction dir, basic_block bb)
 {
   return get_dominated_to_depth (dir, bb, 0);
diff --git a/gcc/dominance.h b/gcc/dominance.h
index c74ad297c6a..1a8c248ee98 100644
--- a/gcc/dominance.h
+++ b/gcc/dominance.h
@@ -50,10 +50,10 @@  extern auto_vec<basic_block> get_dominated_by (enum cdi_direction, basic_block);
 extern auto_vec<basic_block> get_dominated_by_region (enum cdi_direction,
 							 basic_block *,
 							 unsigned);
-extern vec<basic_block> get_dominated_to_depth (enum cdi_direction,
-							basic_block, int);
-extern vec<basic_block> get_all_dominated_blocks (enum cdi_direction,
-							  basic_block);
+extern auto_vec<basic_block> get_dominated_to_depth (enum cdi_direction,
+						     basic_block, int);
+extern auto_vec<basic_block> get_all_dominated_blocks (enum cdi_direction,
+						       basic_block);
 extern void redirect_immediate_dominators (enum cdi_direction, basic_block,
 					   basic_block);
 extern basic_block nearest_common_dominator (enum cdi_direction,
diff --git a/gcc/gcse.c b/gcc/gcse.c
index 9114f30705e..ecf7e51aac5 100644
--- a/gcc/gcse.c
+++ b/gcc/gcse.c
@@ -3050,9 +3050,7 @@  static int
 hoist_code (void)
 {
   basic_block bb, dominated;
-  vec<basic_block> dom_tree_walk;
   unsigned int dom_tree_walk_index;
-  vec<basic_block> domby;
   unsigned int i, j, k;
   struct gcse_expr **index_map;
   struct gcse_expr *expr;
@@ -3106,15 +3104,16 @@  hoist_code (void)
   if (flag_ira_hoist_pressure)
     hoisted_bbs = BITMAP_ALLOC (NULL);
 
-  dom_tree_walk = get_all_dominated_blocks (CDI_DOMINATORS,
-					    ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb);
+  auto_vec<basic_block> dom_tree_walk
+  = get_all_dominated_blocks (CDI_DOMINATORS,
+			      ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb);
 
   /* Walk over each basic block looking for potentially hoistable
      expressions, nothing gets hoisted from the entry block.  */
   FOR_EACH_VEC_ELT (dom_tree_walk, dom_tree_walk_index, bb)
     {
-      domby = get_dominated_to_depth (CDI_DOMINATORS, bb,
-				      param_max_hoist_depth);
+      auto_vec<basic_block> domby
+	= get_dominated_to_depth (CDI_DOMINATORS, bb, param_max_hoist_depth);
 
       if (domby.length () == 0)
 	continue;
@@ -3315,10 +3314,8 @@  hoist_code (void)
 	      bitmap_clear (from_bbs);
 	    }
 	}
-      domby.release ();
     }
 
-  dom_tree_walk.release ();
   BITMAP_FREE (from_bbs);
   if (flag_ira_hoist_pressure)
     BITMAP_FREE (hoisted_bbs);
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index c9403deed19..4c32f83257f 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -8683,7 +8683,6 @@  gimple_flow_call_edges_add (sbitmap blocks)
 void
 remove_edge_and_dominated_blocks (edge e)
 {
-  vec<basic_block> bbs_to_remove = vNULL;
   vec<basic_block> bbs_to_fix_dom = vNULL;
   edge f;
   edge_iterator ei;
@@ -8734,6 +8733,7 @@  remove_edge_and_dominated_blocks (edge e)
     }
 
   auto_bitmap df, df_idom;
+  auto_vec<basic_block> bbs_to_remove;
   if (none_removed)
     bitmap_set_bit (df_idom,
 		    get_immediate_dominator (CDI_DOMINATORS, e->dest)->index);
@@ -8800,7 +8800,6 @@  remove_edge_and_dominated_blocks (edge e)
 
   iterate_fix_dominators (CDI_DOMINATORS, bbs_to_fix_dom, true);
 
-  bbs_to_remove.release ();
   bbs_to_fix_dom.release ();
 }
 
diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c
index deff2d5e08b..fe1baef32a7 100644
--- a/gcc/tree-parloops.c
+++ b/gcc/tree-parloops.c
@@ -3949,7 +3949,7 @@  oacc_entry_exit_ok (class loop *loop,
 		    reduction_info_table_type *reduction_list)
 {
   basic_block *loop_bbs = get_loop_body_in_dom_order (loop);
-  vec<basic_block> region_bbs
+  auto_vec<basic_block> region_bbs
     = get_all_dominated_blocks (CDI_DOMINATORS, ENTRY_BLOCK_PTR_FOR_FN (cfun));
 
   bitmap in_loop_bbs = BITMAP_ALLOC (NULL);
@@ -3972,7 +3972,6 @@  oacc_entry_exit_ok (class loop *loop,
 	}
     }
 
-  region_bbs.release ();
   free (loop_bbs);
 
   BITMAP_FREE (in_loop_bbs);
diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c
index def6ae69e24..e2d3b63a30c 100644
--- a/gcc/tree-ssa-dce.c
+++ b/gcc/tree-ssa-dce.c
@@ -1275,7 +1275,6 @@  eliminate_unnecessary_stmts (void)
   gimple_stmt_iterator gsi, psi;
   gimple *stmt;
   tree call;
-  vec<basic_block> h;
   auto_vec<edge> to_remove_edges;
 
   if (dump_file && (dump_flags & TDF_DETAILS))
@@ -1306,6 +1305,7 @@  eliminate_unnecessary_stmts (void)
 
      as desired.  */
   gcc_assert (dom_info_available_p (CDI_DOMINATORS));
+  auto_vec<basic_block> h;
   h = get_all_dominated_blocks (CDI_DOMINATORS,
 				single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
 
@@ -1460,7 +1460,6 @@  eliminate_unnecessary_stmts (void)
       something_changed |= remove_dead_phis (bb);
     }
 
-  h.release ();
 
   /* Since we don't track liveness of virtual PHI nodes, it is possible that we
      rendered some PHI nodes unreachable while they are still in use.
diff --git a/gcc/tree-ssa-phiprop.c b/gcc/tree-ssa-phiprop.c
index 64d6eda5f6c..78b0461c839 100644
--- a/gcc/tree-ssa-phiprop.c
+++ b/gcc/tree-ssa-phiprop.c
@@ -484,7 +484,6 @@  public:
 unsigned int
 pass_phiprop::execute (function *fun)
 {
-  vec<basic_block> bbs;
   struct phiprop_d *phivn;
   bool did_something = false;
   basic_block bb;
@@ -499,8 +498,9 @@  pass_phiprop::execute (function *fun)
   phivn = XCNEWVEC (struct phiprop_d, n);
 
   /* Walk the dominator tree in preorder.  */
-  bbs = get_all_dominated_blocks (CDI_DOMINATORS,
-				  single_succ (ENTRY_BLOCK_PTR_FOR_FN (fun)));
+  auto_vec<basic_block> bbs
+  = get_all_dominated_blocks (CDI_DOMINATORS,
+			      single_succ (ENTRY_BLOCK_PTR_FOR_FN (fun)));
   FOR_EACH_VEC_ELT (bbs, i, bb)
     {
       /* Since we're going to move dereferences across predecessor
@@ -514,7 +514,6 @@  pass_phiprop::execute (function *fun)
   if (did_something)
     gsi_commit_edge_inserts ();
 
-  bbs.release ();
   free (phivn);
 
   free_dominance_info (CDI_POST_DOMINATORS);