public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Andrew Pinski <apinski@marvell.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Dump if a pattern fails after having printed applying it
Date: Wed, 24 May 2023 11:00:02 +0200	[thread overview]
Message-ID: <CAFiYyc3G82Kf=0hUQHJ5J846ohTRv3V4a_yAwTaop2YoVgvVpQ@mail.gmail.com> (raw)
In-Reply-To: <20230523231601.2130715-1-apinski@marvell.com>

On Wed, May 24, 2023 at 1:16 AM Andrew Pinski via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> While trying to understand how to use the ! operand for match
> patterns, I noticed that the debug dumps would print out applying
> a pattern but nothing when it was rejected in the end. This was confusing
> me.
> This adds that by emitting a dump for the failed case.
> Note the patch is little more complex as we don't want to print out
> if debug counter rejected the pattern and then we need to fix up
> when we mark needing a label or not.
>
> OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

Hmm, can we maybe simply move the

                                                if (UNLIKELY
(debug_dump)) fprintf (dump_file, "Applying pattern %s:%d, %s:%d\n",
"match.pd", 1157, __FILE__, __LINE__);

right before the return true; instead?

> gcc/ChangeLog:
>
>         * genmatch.cc (needs_label): New variable
>         (expr::gen_transform): Set needs_label
>         if we use the local_label.
>         (dt_simplify::gen_1): Use `_1` for the debug count label.
>         After the local label, emit debug print for the failure.
>         Emit `_1` label if needed.
> ---
>  gcc/genmatch.cc | 28 ++++++++++++++++++++++++----
>  1 file changed, 24 insertions(+), 4 deletions(-)
>
> diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc
> index 177c13d87cb..2ea80d341a2 100644
> --- a/gcc/genmatch.cc
> +++ b/gcc/genmatch.cc
> @@ -2433,6 +2433,7 @@ capture_info::walk_c_expr (c_expr *e)
>  /* The current label failing the current matched pattern during
>     code generation.  */
>  static char *fail_label;
> +static bool needs_label;
>
>  /* Code generation off the decision tree and the refered AST nodes.  */
>
> @@ -2611,6 +2612,7 @@ expr::gen_transform (FILE *f, int indent, const char *dest, bool gimple,
>        fprintf_indent (f, indent,
>                       "if (!_r%d) goto %s;\n",
>                       depth, fail_label);
> +      needs_label = true;
>        if (*opr == CONVERT_EXPR)
>         {
>           indent -= 4;
> @@ -2640,11 +2642,13 @@ expr::gen_transform (FILE *f, int indent, const char *dest, bool gimple,
>         {
>           fprintf_indent (f, indent, "if (!_r%d)\n", depth);
>           fprintf_indent (f, indent, "  goto %s;\n", fail_label);
> +         needs_label = true;
>         }
>        if (force_leaf)
>         {
>           fprintf_indent (f, indent, "if (EXPR_P (_r%d))\n", depth);
>           fprintf_indent (f, indent, "  goto %s;\n", fail_label);
> +         needs_label = true;
>         }
>        if (*opr == CONVERT_EXPR)
>         {
> @@ -3409,7 +3413,8 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result)
>    char local_fail_label[256];
>    snprintf (local_fail_label, 256, "next_after_fail%u", ++fail_label_cnt);
>    fail_label = local_fail_label;
> -  bool needs_label = false;
> +  needs_label = false;
> +  bool needs_label_1 = false;
>
>    /* Analyze captures and perform early-outs on the incoming arguments
>       that cover cases we cannot handle.  */
> @@ -3484,8 +3489,8 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result)
>
>    if (s->kind == simplify::SIMPLIFY)
>      {
> -      fprintf_indent (f, indent, "if (UNLIKELY (!dbg_cnt (match))) goto %s;\n", fail_label);
> -      needs_label = true;
> +      fprintf_indent (f, indent, "if (UNLIKELY (!dbg_cnt (match))) goto %s_1;\n", fail_label);
> +      needs_label_1 = true;
>      }
>
>    fprintf_indent (f, indent, "if (UNLIKELY (debug_dump)) "
> @@ -3718,7 +3723,22 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result)
>    indent -= 2;
>    fprintf_indent (f, indent, "}\n");
>    if (needs_label)
> -    fprintf (f, "%s:;\n", fail_label);
> +    {
> +      fprintf (f, "%s:;\n", fail_label);
> +      if (s->kind == simplify::SIMPLIFY)
> +       {
> +         fprintf_indent (f, indent, "if (UNLIKELY (debug_dump)) "
> +                         "fprintf (dump_file, \"Pattern failed ");
> +         fprintf (f, "%%s:%%d, %%s:%%d\\n\", ");
> +         output_line_directive (f,
> +                                result ? result->location : s->match->location, true,
> +                                true);
> +         fprintf (f, ", __FILE__, __LINE__);\n");
> +       }
> +    }
> +  if (needs_label_1)
> +    fprintf (f, "%s_1:;\n", fail_label);
> +  needs_label = false;
>    fail_label = NULL;
>  }
>
> --
> 2.31.1
>

  reply	other threads:[~2023-05-24  9:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-23 23:16 Andrew Pinski
2023-05-24  9:00 ` Richard Biener [this message]
2023-05-24 16:42   ` Andrew Pinski

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='CAFiYyc3G82Kf=0hUQHJ5J846ohTRv3V4a_yAwTaop2YoVgvVpQ@mail.gmail.com' \
    --to=richard.guenther@gmail.com \
    --cc=apinski@marvell.com \
    --cc=gcc-patches@gcc.gnu.org \
    /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).