[4/6] return auto_vec from get_dominated_by

Message ID 20210615055922.27205-4-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.
Signed-off-by: Trevor Saunders <tbsaunde@tbsaunde.org>


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

gcc/ChangeLog:

	* dominance.c (get_dominated_by): Return auto_vec<basic_block>.
	* dominance.h (get_dominated_by): Likewise.
	* auto-profile.c (afdo_find_equiv_class): Adjust.
	* cfgloopmanip.c (duplicate_loop_to_header_edge): Likewise.
	* loop-unroll.c (unroll_loop_runtime_iterations): Likewise.
	* tree-cfg.c (test_linear_chain): Likewise.
	(test_diamond): Likewise.
---
 gcc/auto-profile.c |  9 +++------
 gcc/cfgloopmanip.c |  4 +---
 gcc/dominance.c    |  6 +++---
 gcc/dominance.h    |  2 +-
 gcc/loop-unroll.c  | 12 +++---------
 gcc/tree-cfg.c     | 14 ++++++--------
 6 files changed, 17 insertions(+), 30 deletions(-)

-- 
2.20.1

Comments

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

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

>

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


OK.

Thanks,
Richard.

> gcc/ChangeLog:

>

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

>         * dominance.h (get_dominated_by): Likewise.

>         * auto-profile.c (afdo_find_equiv_class): Adjust.

>         * cfgloopmanip.c (duplicate_loop_to_header_edge): Likewise.

>         * loop-unroll.c (unroll_loop_runtime_iterations): Likewise.

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

>         (test_diamond): Likewise.

> ---

>  gcc/auto-profile.c |  9 +++------

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

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

>  gcc/dominance.h    |  2 +-

>  gcc/loop-unroll.c  | 12 +++---------

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

>  6 files changed, 17 insertions(+), 30 deletions(-)

>

> diff --git a/gcc/auto-profile.c b/gcc/auto-profile.c

> index ed788dc06a8..43d6fa0b1f0 100644

> --- a/gcc/auto-profile.c

> +++ b/gcc/auto-profile.c

> @@ -1155,13 +1155,10 @@ afdo_find_equiv_class (bb_set *annotated_bb)

>

>    FOR_ALL_BB_FN (bb, cfun)

>    {

> -    vec<basic_block> dom_bbs;

> -

>      if (bb->aux != NULL)

>        continue;

>      bb->aux = bb;

> -    dom_bbs = get_dominated_by (CDI_DOMINATORS, bb);

> -    for (basic_block bb1 : dom_bbs)

> +    for (basic_block bb1 : get_dominated_by (CDI_DOMINATORS, bb))

>        if (bb1->aux == NULL && dominated_by_p (CDI_POST_DOMINATORS, bb, bb1)

>           && bb1->loop_father == bb->loop_father)

>         {

> @@ -1172,8 +1169,8 @@ afdo_find_equiv_class (bb_set *annotated_bb)

>               set_bb_annotated (bb, annotated_bb);

>             }

>         }

> -    dom_bbs = get_dominated_by (CDI_POST_DOMINATORS, bb);

> -    for (basic_block bb1 : dom_bbs)

> +

> +    for (basic_block bb1 : get_dominated_by (CDI_POST_DOMINATORS, bb))

>        if (bb1->aux == NULL && dominated_by_p (CDI_DOMINATORS, bb, bb1)

>           && bb1->loop_father == bb->loop_father)

>         {

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

> index 4a9ab74642c..e6df28036c4 100644

> --- a/gcc/cfgloopmanip.c

> +++ b/gcc/cfgloopmanip.c

> @@ -1414,13 +1414,12 @@ duplicate_loop_to_header_edge (class loop *loop, edge e,

>    for (i = 0; i < n; i++)

>      {

>        basic_block dominated, dom_bb;

> -      vec<basic_block> dom_bbs;

>        unsigned j;

>

>        bb = bbs[i];

>        bb->aux = 0;

>

> -      dom_bbs = get_dominated_by (CDI_DOMINATORS, bb);

> +      auto_vec<basic_block> dom_bbs = get_dominated_by (CDI_DOMINATORS, bb);

>        FOR_EACH_VEC_ELT (dom_bbs, j, dominated)

>         {

>           if (flow_bb_inside_loop_p (loop, dominated))

> @@ -1429,7 +1428,6 @@ duplicate_loop_to_header_edge (class loop *loop, edge e,

>                         CDI_DOMINATORS, first_active[i], first_active_latch);

>           set_immediate_dominator (CDI_DOMINATORS, dominated, dom_bb);

>         }

> -      dom_bbs.release ();

>      }

>    free (first_active);

>

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

> index 5fa172f3280..0e464cb7282 100644

> --- a/gcc/dominance.c

> +++ b/gcc/dominance.c

> @@ -883,17 +883,17 @@ set_immediate_dominator (enum cdi_direction dir, basic_block bb,

>

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

>     direction DIR.  */

> -vec<basic_block>

> +auto_vec<basic_block>

>  get_dominated_by (enum cdi_direction dir, basic_block bb)

>  {

>    unsigned int dir_index = dom_convert_dir_to_idx (dir);

>    struct et_node *node = bb->dom[dir_index], *son = node->son, *ason;

> -  vec<basic_block> bbs = vNULL;

> +  auto_vec<basic_block> bbs;

>

>    gcc_checking_assert (dom_computed[dir_index]);

>

>    if (!son)

> -    return vNULL;

> +    return bbs;

>

>    bbs.safe_push ((basic_block) son->data);

>    for (ason = son->right; ason != son; ason = ason->right)

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

> index 4eeac59fc59..515a369aacf 100644

> --- a/gcc/dominance.h

> +++ b/gcc/dominance.h

> @@ -46,7 +46,7 @@ extern void free_dominance_info_for_region (function *,

>  extern basic_block get_immediate_dominator (enum cdi_direction, basic_block);

>  extern void set_immediate_dominator (enum cdi_direction, basic_block,

>                                      basic_block);

> -extern vec<basic_block> get_dominated_by (enum cdi_direction, basic_block);

> +extern auto_vec<basic_block> get_dominated_by (enum cdi_direction, basic_block);

>  extern vec<basic_block> get_dominated_by_region (enum cdi_direction,

>                                                          basic_block *,

>                                                          unsigned);

> diff --git a/gcc/loop-unroll.c b/gcc/loop-unroll.c

> index 8b6fcf5074c..66d93487e29 100644

> --- a/gcc/loop-unroll.c

> +++ b/gcc/loop-unroll.c

> @@ -884,7 +884,7 @@ unroll_loop_runtime_iterations (class loop *loop)

>  {

>    rtx old_niter, niter, tmp;

>    rtx_insn *init_code, *branch_code;

> -  unsigned i, j;

> +  unsigned i;

>    profile_probability p;

>    basic_block preheader, *body, swtch, ezc_swtch = NULL;

>    int may_exit_copy;

> @@ -908,15 +908,9 @@ unroll_loop_runtime_iterations (class loop *loop)

>    body = get_loop_body (loop);

>    for (i = 0; i < loop->num_nodes; i++)

>      {

> -      vec<basic_block> ldom;

> -      basic_block bb;

> -

> -      ldom = get_dominated_by (CDI_DOMINATORS, body[i]);

> -      FOR_EACH_VEC_ELT (ldom, j, bb)

> +      for (basic_block bb : get_dominated_by (CDI_DOMINATORS, body[i]))

>         if (!flow_bb_inside_loop_p (loop, bb))

>           dom_bbs.safe_push (bb);

> -

> -      ldom.release ();

>      }

>    free (body);

>

> @@ -1013,7 +1007,7 @@ unroll_loop_runtime_iterations (class loop *loop)

>        gcc_assert (ok);

>

>        /* Create item for switch.  */

> -      j = n_peel - i - (extra_zero_check ? 0 : 1);

> +      unsigned j = n_peel - i - (extra_zero_check ? 0 : 1);

>        p = profile_probability::always ().apply_scale (1, i + 2);

>

>        preheader = split_edge (loop_preheader_edge (loop));

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

> index 02256580c98..6bdd1a561fd 100644

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

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

> @@ -9917,22 +9917,20 @@ test_linear_chain ()

>    calculate_dominance_info (CDI_DOMINATORS);

>    ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_b));

>    ASSERT_EQ (bb_b, get_immediate_dominator (CDI_DOMINATORS, bb_c));

> -  vec<basic_block> dom_by_b = get_dominated_by (CDI_DOMINATORS, bb_b);

> +  auto_vec<basic_block> dom_by_b = get_dominated_by (CDI_DOMINATORS, bb_b);

>    ASSERT_EQ (1, dom_by_b.length ());

>    ASSERT_EQ (bb_c, dom_by_b[0]);

>    free_dominance_info (CDI_DOMINATORS);

> -  dom_by_b.release ();

>

>    /* Similarly for post-dominance: each BB in our chain is post-dominated

>       by the one after it.  */

>    calculate_dominance_info (CDI_POST_DOMINATORS);

>    ASSERT_EQ (bb_b, get_immediate_dominator (CDI_POST_DOMINATORS, bb_a));

>    ASSERT_EQ (bb_c, get_immediate_dominator (CDI_POST_DOMINATORS, bb_b));

> -  vec<basic_block> postdom_by_b = get_dominated_by (CDI_POST_DOMINATORS, bb_b);

> +  auto_vec<basic_block> postdom_by_b = get_dominated_by (CDI_POST_DOMINATORS, bb_b);

>    ASSERT_EQ (1, postdom_by_b.length ());

>    ASSERT_EQ (bb_a, postdom_by_b[0]);

>    free_dominance_info (CDI_POST_DOMINATORS);

> -  postdom_by_b.release ();

>

>    pop_cfun ();

>  }

> @@ -9991,10 +9989,10 @@ test_diamond ()

>    ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_b));

>    ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_c));

>    ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_d));

> -  vec<basic_block> dom_by_a = get_dominated_by (CDI_DOMINATORS, bb_a);

> +  auto_vec<basic_block> dom_by_a = get_dominated_by (CDI_DOMINATORS, bb_a);

>    ASSERT_EQ (3, dom_by_a.length ()); /* B, C, D, in some order.  */

>    dom_by_a.release ();

> -  vec<basic_block> dom_by_b = get_dominated_by (CDI_DOMINATORS, bb_b);

> +  auto_vec<basic_block> dom_by_b = get_dominated_by (CDI_DOMINATORS, bb_b);

>    ASSERT_EQ (0, dom_by_b.length ());

>    dom_by_b.release ();

>    free_dominance_info (CDI_DOMINATORS);

> @@ -10004,10 +10002,10 @@ test_diamond ()

>    ASSERT_EQ (bb_d, get_immediate_dominator (CDI_POST_DOMINATORS, bb_a));

>    ASSERT_EQ (bb_d, get_immediate_dominator (CDI_POST_DOMINATORS, bb_b));

>    ASSERT_EQ (bb_d, get_immediate_dominator (CDI_POST_DOMINATORS, bb_c));

> -  vec<basic_block> postdom_by_d = get_dominated_by (CDI_POST_DOMINATORS, bb_d);

> +  auto_vec<basic_block> postdom_by_d = get_dominated_by (CDI_POST_DOMINATORS, bb_d);

>    ASSERT_EQ (3, postdom_by_d.length ()); /* A, B, C in some order.  */

>    postdom_by_d.release ();

> -  vec<basic_block> postdom_by_b = get_dominated_by (CDI_POST_DOMINATORS, bb_b);

> +  auto_vec<basic_block> postdom_by_b = get_dominated_by (CDI_POST_DOMINATORS, bb_b);

>    ASSERT_EQ (0, postdom_by_b.length ());

>    postdom_by_b.release ();

>    free_dominance_info (CDI_POST_DOMINATORS);

> --

> 2.20.1

>
Michael Meissner via Gcc-patches June 15, 2021, 11:18 a.m. | #2
On 15 June 2021 08:46:57 CEST, Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
>On Tue, Jun 15, 2021 at 8:02 AM Trevor Saunders <tbsaunde@tbsaunde.org>

>wrote:

>>

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

>>

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

>

>OK.

>

>Thanks,

>Richard.

>

>> gcc/ChangeLog:

>>

>>         * dominance.c (get_dominated_by): Return

>auto_vec<basic_block>.

>>         * dominance.h (get_dominated_by): Likewise.

>>         * auto-profile.c (afdo_find_equiv_class): Adjust.

>>         * cfgloopmanip.c (duplicate_loop_to_header_edge): Likewise.

>>         * loop-unroll.c (unroll_loop_runtime_iterations): Likewise.

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

>>         (test_diamond): Likewise.

>> ---


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

>> index 02256580c98..6bdd1a561fd 100644

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

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

>> @@ -9917,22 +9917,20 @@ test_linear_chain ()

>>    calculate_dominance_info (CDI_DOMINATORS);

>>    ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_b));

>>    ASSERT_EQ (bb_b, get_immediate_dominator (CDI_DOMINATORS, bb_c));

>> -  vec<basic_block> dom_by_b = get_dominated_by (CDI_DOMINATORS,

>bb_b);

>> +  auto_vec<basic_block> dom_by_b = get_dominated_by (CDI_DOMINATORS,

>bb_b);

>>    ASSERT_EQ (1, dom_by_b.length ());

>>    ASSERT_EQ (bb_c, dom_by_b[0]);

>>    free_dominance_info (CDI_DOMINATORS);

>> -  dom_by_b.release ();

>>

>>    /* Similarly for post-dominance: each BB in our chain is

>post-dominated

>>       by the one after it.  */

>>    calculate_dominance_info (CDI_POST_DOMINATORS);

>>    ASSERT_EQ (bb_b, get_immediate_dominator (CDI_POST_DOMINATORS,

>bb_a));

>>    ASSERT_EQ (bb_c, get_immediate_dominator (CDI_POST_DOMINATORS,

>bb_b));

>> -  vec<basic_block> postdom_by_b = get_dominated_by

>(CDI_POST_DOMINATORS, bb_b);

>> +  auto_vec<basic_block> postdom_by_b = get_dominated_by

>(CDI_POST_DOMINATORS, bb_b);

>>    ASSERT_EQ (1, postdom_by_b.length ());

>>    ASSERT_EQ (bb_a, postdom_by_b[0]);

>>    free_dominance_info (CDI_POST_DOMINATORS);

>> -  postdom_by_b.release ();

>>

>>    pop_cfun ();

>>  }

>> @@ -9991,10 +9989,10 @@ test_diamond ()

>>    ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_b));

>>    ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_c));

>>    ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_d));

>> -  vec<basic_block> dom_by_a = get_dominated_by (CDI_DOMINATORS,

>bb_a);

>> +  auto_vec<basic_block> dom_by_a = get_dominated_by (CDI_DOMINATORS,

>bb_a);

>>    ASSERT_EQ (3, dom_by_a.length ()); /* B, C, D, in some order.  */

>>    dom_by_a.release ();


I'm curious why you keep the release() above and ...

>> -  vec<basic_block> dom_by_b = get_dominated_by (CDI_DOMINATORS,

>bb_b);

>> +  auto_vec<basic_block> dom_by_b = get_dominated_by (CDI_DOMINATORS,

>bb_b);

>>    ASSERT_EQ (0, dom_by_b.length ());

>>    dom_by_b.release ();


here and

>>    free_dominance_info (CDI_DOMINATORS);

>> @@ -10004,10 +10002,10 @@ test_diamond ()

>>    ASSERT_EQ (bb_d, get_immediate_dominator (CDI_POST_DOMINATORS,

>bb_a));

>>    ASSERT_EQ (bb_d, get_immediate_dominator (CDI_POST_DOMINATORS,

>bb_b));

>>    ASSERT_EQ (bb_d, get_immediate_dominator (CDI_POST_DOMINATORS,

>bb_c));

>> -  vec<basic_block> postdom_by_d = get_dominated_by

>(CDI_POST_DOMINATORS, bb_d);

>> +  auto_vec<basic_block> postdom_by_d = get_dominated_by

>(CDI_POST_DOMINATORS, bb_d);

>>    ASSERT_EQ (3, postdom_by_d.length ()); /* A, B, C in some order. 

>*/

>>    postdom_by_d.release ();


here and 

>> -  vec<basic_block> postdom_by_b = get_dominated_by

>(CDI_POST_DOMINATORS, bb_b);

>> +  auto_vec<basic_block> postdom_by_b = get_dominated_by

>(CDI_POST_DOMINATORS, bb_b);

>>    ASSERT_EQ (0, postdom_by_b.length ());

>>    postdom_by_b.release ();


here?

thanks,

>>    free_dominance_info (CDI_POST_DOMINATORS);

>> --

>> 2.20.1

>>
Trevor Saunders June 16, 2021, 3:09 a.m. | #3
On Tue, Jun 15, 2021 at 01:18:54PM +0200, Bernhard Reutner-Fischer wrote:
> On 15 June 2021 08:46:57 CEST, Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:

> >On Tue, Jun 15, 2021 at 8:02 AM Trevor Saunders <tbsaunde@tbsaunde.org>

> >wrote:

> >>

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

> >>

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

> >

> >OK.

> >

> >Thanks,

> >Richard.

> >

> >> gcc/ChangeLog:

> >>

> >>         * dominance.c (get_dominated_by): Return

> >auto_vec<basic_block>.

> >>         * dominance.h (get_dominated_by): Likewise.

> >>         * auto-profile.c (afdo_find_equiv_class): Adjust.

> >>         * cfgloopmanip.c (duplicate_loop_to_header_edge): Likewise.

> >>         * loop-unroll.c (unroll_loop_runtime_iterations): Likewise.

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

> >>         (test_diamond): Likewise.

> >> ---

> 

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

> >> index 02256580c98..6bdd1a561fd 100644

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

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

> >> @@ -9917,22 +9917,20 @@ test_linear_chain ()

> >>    calculate_dominance_info (CDI_DOMINATORS);

> >>    ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_b));

> >>    ASSERT_EQ (bb_b, get_immediate_dominator (CDI_DOMINATORS, bb_c));

> >> -  vec<basic_block> dom_by_b = get_dominated_by (CDI_DOMINATORS,

> >bb_b);

> >> +  auto_vec<basic_block> dom_by_b = get_dominated_by (CDI_DOMINATORS,

> >bb_b);

> >>    ASSERT_EQ (1, dom_by_b.length ());

> >>    ASSERT_EQ (bb_c, dom_by_b[0]);

> >>    free_dominance_info (CDI_DOMINATORS);

> >> -  dom_by_b.release ();

> >>

> >>    /* Similarly for post-dominance: each BB in our chain is

> >post-dominated

> >>       by the one after it.  */

> >>    calculate_dominance_info (CDI_POST_DOMINATORS);

> >>    ASSERT_EQ (bb_b, get_immediate_dominator (CDI_POST_DOMINATORS,

> >bb_a));

> >>    ASSERT_EQ (bb_c, get_immediate_dominator (CDI_POST_DOMINATORS,

> >bb_b));

> >> -  vec<basic_block> postdom_by_b = get_dominated_by

> >(CDI_POST_DOMINATORS, bb_b);

> >> +  auto_vec<basic_block> postdom_by_b = get_dominated_by

> >(CDI_POST_DOMINATORS, bb_b);

> >>    ASSERT_EQ (1, postdom_by_b.length ());

> >>    ASSERT_EQ (bb_a, postdom_by_b[0]);

> >>    free_dominance_info (CDI_POST_DOMINATORS);

> >> -  postdom_by_b.release ();

> >>

> >>    pop_cfun ();

> >>  }

> >> @@ -9991,10 +9989,10 @@ test_diamond ()

> >>    ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_b));

> >>    ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_c));

> >>    ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_d));

> >> -  vec<basic_block> dom_by_a = get_dominated_by (CDI_DOMINATORS,

> >bb_a);

> >> +  auto_vec<basic_block> dom_by_a = get_dominated_by (CDI_DOMINATORS,

> >bb_a);

> >>    ASSERT_EQ (3, dom_by_a.length ()); /* B, C, D, in some order.  */

> >>    dom_by_a.release ();

> 

> I'm curious why you keep the release() above and ...


There was no particular reason, I just didn't make a very complete
search to remove them all, as they should be harmless.  I'm certainly
happy to remove them, but wonder if it wouldn't make more sense to go on
a broader search for uses of release and see why they are necessary or
remove them.

thanks

Trev
Michael Meissner via Gcc-patches June 16, 2021, 5:45 a.m. | #4
On 16 June 2021 05:09:17 CEST, Trevor Saunders <tbsaunde@tbsaunde.org> wrote:

>> I'm curious why you keep the release() above and ...

>

>There was no particular reason, I just didn't make a very complete

>search to remove them all, as they should be harmless.  I'm certainly

>happy to remove them, but wonder if it wouldn't make more sense to go

>on

>a broader search for uses of release and see why they are necessary or

>remove them.


Yes.
One spot where you removed the early release() was in gimple_duplicate_sese_region and gimple_duplicate_sese_tail. I did wonder if there are adverse effects on memory usage for TUs with lots of basic blocks but you certainly thought about that when you removed the explicit doms.release().

thanks!
Trevor Saunders June 17, 2021, 6:56 a.m. | #5
On Wed, Jun 16, 2021 at 07:45:01AM +0200, Bernhard Reutner-Fischer wrote:
> On 16 June 2021 05:09:17 CEST, Trevor Saunders <tbsaunde@tbsaunde.org> wrote:

> 

> >> I'm curious why you keep the release() above and ...

> >

> >There was no particular reason, I just didn't make a very complete

> >search to remove them all, as they should be harmless.  I'm certainly

> >happy to remove them, but wonder if it wouldn't make more sense to go

> >on

> >a broader search for uses of release and see why they are necessary or

> >remove them.

> 

> Yes.

> One spot where you removed the early release() was in gimple_duplicate_sese_region and gimple_duplicate_sese_tail. I did wonder if there are adverse effects on memory usage for TUs with lots of basic blocks but you certainly thought about that when you removed the explicit doms.release().


It should have essentially no impact on memory usage as the vector will
be released when it goes out of scope either way, so removing release ()
is basically just cleaning up useless code.

thanks

Trev
> 

> thanks!

Patch

diff --git a/gcc/auto-profile.c b/gcc/auto-profile.c
index ed788dc06a8..43d6fa0b1f0 100644
--- a/gcc/auto-profile.c
+++ b/gcc/auto-profile.c
@@ -1155,13 +1155,10 @@  afdo_find_equiv_class (bb_set *annotated_bb)
 
   FOR_ALL_BB_FN (bb, cfun)
   {
-    vec<basic_block> dom_bbs;
-
     if (bb->aux != NULL)
       continue;
     bb->aux = bb;
-    dom_bbs = get_dominated_by (CDI_DOMINATORS, bb);
-    for (basic_block bb1 : dom_bbs)
+    for (basic_block bb1 : get_dominated_by (CDI_DOMINATORS, bb))
       if (bb1->aux == NULL && dominated_by_p (CDI_POST_DOMINATORS, bb, bb1)
 	  && bb1->loop_father == bb->loop_father)
 	{
@@ -1172,8 +1169,8 @@  afdo_find_equiv_class (bb_set *annotated_bb)
 	      set_bb_annotated (bb, annotated_bb);
 	    }
 	}
-    dom_bbs = get_dominated_by (CDI_POST_DOMINATORS, bb);
-    for (basic_block bb1 : dom_bbs)
+
+    for (basic_block bb1 : get_dominated_by (CDI_POST_DOMINATORS, bb))
       if (bb1->aux == NULL && dominated_by_p (CDI_DOMINATORS, bb, bb1)
 	  && bb1->loop_father == bb->loop_father)
 	{
diff --git a/gcc/cfgloopmanip.c b/gcc/cfgloopmanip.c
index 4a9ab74642c..e6df28036c4 100644
--- a/gcc/cfgloopmanip.c
+++ b/gcc/cfgloopmanip.c
@@ -1414,13 +1414,12 @@  duplicate_loop_to_header_edge (class loop *loop, edge e,
   for (i = 0; i < n; i++)
     {
       basic_block dominated, dom_bb;
-      vec<basic_block> dom_bbs;
       unsigned j;
 
       bb = bbs[i];
       bb->aux = 0;
 
-      dom_bbs = get_dominated_by (CDI_DOMINATORS, bb);
+      auto_vec<basic_block> dom_bbs = get_dominated_by (CDI_DOMINATORS, bb);
       FOR_EACH_VEC_ELT (dom_bbs, j, dominated)
 	{
 	  if (flow_bb_inside_loop_p (loop, dominated))
@@ -1429,7 +1428,6 @@  duplicate_loop_to_header_edge (class loop *loop, edge e,
 			CDI_DOMINATORS, first_active[i], first_active_latch);
 	  set_immediate_dominator (CDI_DOMINATORS, dominated, dom_bb);
 	}
-      dom_bbs.release ();
     }
   free (first_active);
 
diff --git a/gcc/dominance.c b/gcc/dominance.c
index 5fa172f3280..0e464cb7282 100644
--- a/gcc/dominance.c
+++ b/gcc/dominance.c
@@ -883,17 +883,17 @@  set_immediate_dominator (enum cdi_direction dir, basic_block bb,
 
 /* Returns the list of basic blocks immediately dominated by BB, in the
    direction DIR.  */
-vec<basic_block> 
+auto_vec<basic_block> 
 get_dominated_by (enum cdi_direction dir, basic_block bb)
 {
   unsigned int dir_index = dom_convert_dir_to_idx (dir);
   struct et_node *node = bb->dom[dir_index], *son = node->son, *ason;
-  vec<basic_block> bbs = vNULL;
+  auto_vec<basic_block> bbs;
 
   gcc_checking_assert (dom_computed[dir_index]);
 
   if (!son)
-    return vNULL;
+    return bbs;
 
   bbs.safe_push ((basic_block) son->data);
   for (ason = son->right; ason != son; ason = ason->right)
diff --git a/gcc/dominance.h b/gcc/dominance.h
index 4eeac59fc59..515a369aacf 100644
--- a/gcc/dominance.h
+++ b/gcc/dominance.h
@@ -46,7 +46,7 @@  extern void free_dominance_info_for_region (function *,
 extern basic_block get_immediate_dominator (enum cdi_direction, basic_block);
 extern void set_immediate_dominator (enum cdi_direction, basic_block,
 				     basic_block);
-extern vec<basic_block> get_dominated_by (enum cdi_direction, basic_block);
+extern auto_vec<basic_block> get_dominated_by (enum cdi_direction, basic_block);
 extern vec<basic_block> get_dominated_by_region (enum cdi_direction,
 							 basic_block *,
 							 unsigned);
diff --git a/gcc/loop-unroll.c b/gcc/loop-unroll.c
index 8b6fcf5074c..66d93487e29 100644
--- a/gcc/loop-unroll.c
+++ b/gcc/loop-unroll.c
@@ -884,7 +884,7 @@  unroll_loop_runtime_iterations (class loop *loop)
 {
   rtx old_niter, niter, tmp;
   rtx_insn *init_code, *branch_code;
-  unsigned i, j;
+  unsigned i;
   profile_probability p;
   basic_block preheader, *body, swtch, ezc_swtch = NULL;
   int may_exit_copy;
@@ -908,15 +908,9 @@  unroll_loop_runtime_iterations (class loop *loop)
   body = get_loop_body (loop);
   for (i = 0; i < loop->num_nodes; i++)
     {
-      vec<basic_block> ldom;
-      basic_block bb;
-
-      ldom = get_dominated_by (CDI_DOMINATORS, body[i]);
-      FOR_EACH_VEC_ELT (ldom, j, bb)
+      for (basic_block bb : get_dominated_by (CDI_DOMINATORS, body[i]))
 	if (!flow_bb_inside_loop_p (loop, bb))
 	  dom_bbs.safe_push (bb);
-
-      ldom.release ();
     }
   free (body);
 
@@ -1013,7 +1007,7 @@  unroll_loop_runtime_iterations (class loop *loop)
       gcc_assert (ok);
 
       /* Create item for switch.  */
-      j = n_peel - i - (extra_zero_check ? 0 : 1);
+      unsigned j = n_peel - i - (extra_zero_check ? 0 : 1);
       p = profile_probability::always ().apply_scale (1, i + 2);
 
       preheader = split_edge (loop_preheader_edge (loop));
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 02256580c98..6bdd1a561fd 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -9917,22 +9917,20 @@  test_linear_chain ()
   calculate_dominance_info (CDI_DOMINATORS);
   ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_b));
   ASSERT_EQ (bb_b, get_immediate_dominator (CDI_DOMINATORS, bb_c));
-  vec<basic_block> dom_by_b = get_dominated_by (CDI_DOMINATORS, bb_b);
+  auto_vec<basic_block> dom_by_b = get_dominated_by (CDI_DOMINATORS, bb_b);
   ASSERT_EQ (1, dom_by_b.length ());
   ASSERT_EQ (bb_c, dom_by_b[0]);
   free_dominance_info (CDI_DOMINATORS);
-  dom_by_b.release ();
 
   /* Similarly for post-dominance: each BB in our chain is post-dominated
      by the one after it.  */
   calculate_dominance_info (CDI_POST_DOMINATORS);
   ASSERT_EQ (bb_b, get_immediate_dominator (CDI_POST_DOMINATORS, bb_a));
   ASSERT_EQ (bb_c, get_immediate_dominator (CDI_POST_DOMINATORS, bb_b));
-  vec<basic_block> postdom_by_b = get_dominated_by (CDI_POST_DOMINATORS, bb_b);
+  auto_vec<basic_block> postdom_by_b = get_dominated_by (CDI_POST_DOMINATORS, bb_b);
   ASSERT_EQ (1, postdom_by_b.length ());
   ASSERT_EQ (bb_a, postdom_by_b[0]);
   free_dominance_info (CDI_POST_DOMINATORS);
-  postdom_by_b.release ();
 
   pop_cfun ();
 }
@@ -9991,10 +9989,10 @@  test_diamond ()
   ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_b));
   ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_c));
   ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_d));
-  vec<basic_block> dom_by_a = get_dominated_by (CDI_DOMINATORS, bb_a);
+  auto_vec<basic_block> dom_by_a = get_dominated_by (CDI_DOMINATORS, bb_a);
   ASSERT_EQ (3, dom_by_a.length ()); /* B, C, D, in some order.  */
   dom_by_a.release ();
-  vec<basic_block> dom_by_b = get_dominated_by (CDI_DOMINATORS, bb_b);
+  auto_vec<basic_block> dom_by_b = get_dominated_by (CDI_DOMINATORS, bb_b);
   ASSERT_EQ (0, dom_by_b.length ());
   dom_by_b.release ();
   free_dominance_info (CDI_DOMINATORS);
@@ -10004,10 +10002,10 @@  test_diamond ()
   ASSERT_EQ (bb_d, get_immediate_dominator (CDI_POST_DOMINATORS, bb_a));
   ASSERT_EQ (bb_d, get_immediate_dominator (CDI_POST_DOMINATORS, bb_b));
   ASSERT_EQ (bb_d, get_immediate_dominator (CDI_POST_DOMINATORS, bb_c));
-  vec<basic_block> postdom_by_d = get_dominated_by (CDI_POST_DOMINATORS, bb_d);
+  auto_vec<basic_block> postdom_by_d = get_dominated_by (CDI_POST_DOMINATORS, bb_d);
   ASSERT_EQ (3, postdom_by_d.length ()); /* A, B, C in some order.  */
   postdom_by_d.release ();
-  vec<basic_block> postdom_by_b = get_dominated_by (CDI_POST_DOMINATORS, bb_b);
+  auto_vec<basic_block> postdom_by_b = get_dominated_by (CDI_POST_DOMINATORS, bb_b);
   ASSERT_EQ (0, postdom_by_b.length ());
   postdom_by_b.release ();
   free_dominance_info (CDI_POST_DOMINATORS);