aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAndrew Pinski <apinski@marvell.com>2023-05-25 22:08:24 +0000
committerAndrew Pinski <apinski@marvell.com>2023-05-26 15:01:46 +0000
commit497e8e2420e3fc0209ae240f61050d0257023d6b (patch)
tree7a296869a3afd409ee78305d1744e44591606bf2 /gcc
parent1a1abec1d618cde709c585fcce89330bb33b07ac (diff)
downloadgcc-497e8e2420e3fc0209ae240f61050d0257023d6b.zip
gcc-497e8e2420e3fc0209ae240f61050d0257023d6b.tar.gz
gcc-497e8e2420e3fc0209ae240f61050d0257023d6b.tar.bz2
genmatch: Emit debug message right before "return x" instead of earlier
This is based on the review of https://gcc.gnu.org/pipermail/gcc-patches/2023-May/619342.html . Instead of emitting debug message even if we don't apply a pattern, this fixes the issue by only emitting it if it the pattern finally succeeded. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * genmatch.cc (emit_debug_printf): New function. (dt_simplify::gen_1): Emit printf into the code before the `return true` or returning the folded result instead of emitting it always.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/genmatch.cc33
1 files changed, 22 insertions, 11 deletions
diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc
index 177c13d..bd6ce3a 100644
--- a/gcc/genmatch.cc
+++ b/gcc/genmatch.cc
@@ -3359,6 +3359,21 @@ dt_operand::gen (FILE *f, int indent, bool gimple, int depth)
}
}
+/* Emit a fprintf to the debug file to the file F, with the INDENT from
+ either the RESULT location or the S's match location if RESULT is null. */
+static void
+emit_debug_printf (FILE *f, int indent, class simplify *s, operand *result)
+{
+ fprintf_indent (f, indent, "if (UNLIKELY (debug_dump)) "
+ "fprintf (dump_file, \"%s ",
+ s->kind == simplify::SIMPLIFY
+ ? "Applying pattern" : "Matching expression");
+ fprintf (f, "%%s:%%d, %%s:%%d\\n\", ");
+ output_line_directive (f,
+ result ? result->location : s->match->location, true,
+ true);
+ fprintf (f, ", __FILE__, __LINE__);\n");
+}
/* Generate code for the '(if ...)', '(with ..)' and actual transform
step of a '(simplify ...)' or '(match ...)'. This handles everything
@@ -3488,21 +3503,12 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result)
needs_label = true;
}
- fprintf_indent (f, indent, "if (UNLIKELY (debug_dump)) "
- "fprintf (dump_file, \"%s ",
- s->kind == simplify::SIMPLIFY
- ? "Applying pattern" : "Matching expression");
- fprintf (f, "%%s:%%d, %%s:%%d\\n\", ");
- output_line_directive (f,
- result ? result->location : s->match->location, true,
- true);
- fprintf (f, ", __FILE__, __LINE__);\n");
-
fprintf_indent (f, indent, "{\n");
indent += 2;
if (!result)
{
/* If there is no result then this is a predicate implementation. */
+ emit_debug_printf (f, indent, s, result);
fprintf_indent (f, indent, "return true;\n");
}
else if (gimple)
@@ -3593,6 +3599,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result)
}
else
gcc_unreachable ();
+ emit_debug_printf (f, indent, s, result);
fprintf_indent (f, indent, "return true;\n");
}
else /* GENERIC */
@@ -3646,7 +3653,10 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result)
&cinfo, indexes);
}
if (is_predicate)
- fprintf_indent (f, indent, "return true;\n");
+ {
+ emit_debug_printf (f, indent, s, result);
+ fprintf_indent (f, indent, "return true;\n");
+ }
else
{
fprintf_indent (f, indent, "tree _r;\n");
@@ -3712,6 +3722,7 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result)
i);
}
}
+ emit_debug_printf (f, indent, s, result);
fprintf_indent (f, indent, "return _r;\n");
}
}