public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Alexandre Oliva <oliva@adacore.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: make FOR_EACH_IMM_USE_STMT safe for early exits (was: Re: move sincos after pre)
Date: Mon, 4 Jan 2021 14:10:04 +0100	[thread overview]
Message-ID: <CAFiYyc22_-KzKTWWjTXn8p+7ybNeJ_7pEsQnYpVR_g9YA93VfA@mail.gmail.com> (raw)
In-Reply-To: <orh7odfqhi.fsf_-_@lxoliva.fsfla.org>

On Tue, Dec 22, 2020 at 11:03 PM Alexandre Oliva <oliva@adacore.com> wrote:
>
> On Oct 28, 2020, Richard Biener <richard.guenther@gmail.com> wrote:
>
> >> BTW, any reason why we are not (yet?) using something like:
> >>
> >> #define FOR_EACH_IMM_USE_STMT(STMT, ITER, SSAVAR)               \
> >> for (auto_end_imm_use_stmt_traverse auto_end                  \
> >> ((((STMT) = first_imm_use_stmt (&(ITER), (SSAVAR))),     \
> >> &(ITER)));                                             \
> >> !end_imm_use_stmt_p (&(ITER));                           \
> >> (void) ((STMT) = next_imm_use_stmt (&(ITER))))
>
> > Just laziness.  Or rather last time I remembered this I tried to do it
> > more fancy via range-for but didn't get very far due to the nested
> > iteration ...
>
> Use a dtor to automatically remove ITER from IMM_USE list in
> FOR_EACH_IMM_USE_STMT.
>
> Regstrapped on x86_64-linux-gnu.  Ok to install?

Hmm - while the change looks good, doesn't it end up
calling end_imm_use_stmt_tranverse twice for those
uses still calling BREAK_FROM_IMM_USE_STMT?

Thus, please remove uses of BREAK_FROM_IMM_USE_STMT
together with this patch.

Thanks,
Richard.

>
> for  gcc/ChangeLog
>
>         * ssa-iterators.h (end_imm_use_stmt_traverse): Forward
>         declare.
>         (auto_end_imm_use_stmt_traverse): New struct.
>         (FOR_EACH_IMM_USE_STMT): Use it.
> ---
>  gcc/ssa-iterators.h |   29 ++++++++++++++++++++++++-----
>  1 file changed, 24 insertions(+), 5 deletions(-)
>
> diff --git a/gcc/ssa-iterators.h b/gcc/ssa-iterators.h
> index 98724da14522d..817997aa952d4 100644
> --- a/gcc/ssa-iterators.h
> +++ b/gcc/ssa-iterators.h
> @@ -77,16 +77,35 @@ struct imm_use_iterator
>         !end_readonly_imm_use_p (&(ITER));                      \
>         (void) ((DEST) = next_readonly_imm_use (&(ITER))))
>
> -/* Use this iterator to visit each stmt which has a use of SSAVAR.  */
> +/* Forward declare for use in the class below.  */
> +static inline void end_imm_use_stmt_traverse (imm_use_iterator *);
> +
> +/* arrange to automatically call, upon descruction, end_imm_use_stmt_traverse
> +   with a given pointer to imm_use_iterator.  */
> +struct auto_end_imm_use_stmt_traverse
> +{
> +  imm_use_iterator *imm;
> +  auto_end_imm_use_stmt_traverse (imm_use_iterator *imm)
> +  : imm (imm) {}
> +  ~auto_end_imm_use_stmt_traverse ()
> +  { end_imm_use_stmt_traverse (imm); }
> +};
> +
> +/* Use this iterator to visit each stmt which has a use of SSAVAR.  The
> +   destructor of the auto_end_imm_use_stmt_traverse object deals with removing
> +   ITER from SSAVAR's IMM_USE list even when leaving the scope early.  */
>
>  #define FOR_EACH_IMM_USE_STMT(STMT, ITER, SSAVAR)              \
> -  for ((STMT) = first_imm_use_stmt (&(ITER), (SSAVAR));                \
> +  for (struct auto_end_imm_use_stmt_traverse                   \
> +         auto_end_imm_use_stmt_traverse                                \
> +          ((((STMT) = first_imm_use_stmt (&(ITER), (SSAVAR))), \
> +            &(ITER)));                                         \
>         !end_imm_use_stmt_p (&(ITER));                          \
>         (void) ((STMT) = next_imm_use_stmt (&(ITER))))
>
> -/* Use this to terminate the FOR_EACH_IMM_USE_STMT loop early.  Failure to
> -   do so will result in leaving a iterator marker node in the immediate
> -   use list, and nothing good will come from that.   */
> +/* These used to be needed to exit FOR_EACH_IMM_USE_STMT early, without leaving
> +   ITER behind in the stmt lists.  This is now taken care of automatically, but
> +   it doesn't hurt to use the macros for documentation purposes.  */
>  #define BREAK_FROM_IMM_USE_STMT(ITER)                          \
>     {                                                           \
>       end_imm_use_stmt_traverse (&(ITER));                      \
>
> --
> Alexandre Oliva, happy hacker  https://FSFLA.org/blogs/lxo/
>    Free Software Activist         GNU Toolchain Engineer
>         Vim, Vi, Voltei pro Emacs -- GNUlius Caesar

  reply	other threads:[~2021-01-04 13:10 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-18 20:28 [Ada,FYI] revamp ada.numerics.aux Alexandre Oliva
2020-10-19  9:46 ` Andreas Schwab
2020-10-19 11:52   ` Alexandre Oliva
2020-10-20  8:26     ` Rainer Orth
2020-10-22  5:15       ` Alexandre Oliva
2020-10-23  7:24       ` Iain Sandoe
2020-10-22  5:13     ` Alexandre Oliva
2020-10-22 18:13       ` Eric Botcazou
2020-10-23  9:33         ` Alexandre Oliva
2021-01-13  6:37     ` Sebastian Huber
2021-01-13 16:45       ` Alexandre Oliva
2021-01-13 17:27         ` Sebastian Huber
2021-01-13 18:40           ` Alexandre Oliva
2021-01-21  5:24             ` Sebastian Huber
2021-01-21  9:57               ` Alexandre Oliva
2020-10-22  5:22 ` Alexandre Oliva
2020-10-22 12:04   ` Alexandre Oliva
2020-10-23 14:23   ` move sincos after pre (was: Re: [Ada,FYI] revamp ada.numerics.aux) Alexandre Oliva
2020-10-23 15:05     ` move sincos after pre (was: Re: [Ada, FYI] " Richard Biener
2020-10-27  5:32       ` move sincos after pre Alexandre Oliva
2020-10-27  8:54         ` Richard Biener
2020-10-28  3:17           ` Alexandre Oliva
2020-10-28 13:01             ` Richard Biener
2020-12-22 22:03               ` make FOR_EACH_IMM_USE_STMT safe for early exits (was: Re: move sincos after pre) Alexandre Oliva
2021-01-04 13:10                 ` Richard Biener [this message]
2021-01-06 11:34                   ` make FOR_EACH_IMM_USE_STMT safe for early exits Alexandre Oliva
2021-01-07  8:41                     ` Richard Biener
2021-01-09 20:33                       ` Alexandre Oliva
2021-01-11  8:42                         ` Richard Biener
2021-01-12 14:29                         ` Andrew MacLeod
2020-10-22  5:27 ` [Ada,FYI] revamp ada.numerics.aux Alexandre Oliva

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFiYyc22_-KzKTWWjTXn8p+7ybNeJ_7pEsQnYpVR_g9YA93VfA@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=oliva@adacore.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).