@@ -522,6 +522,7 @@ parse_dump_option (const char *, const char **);
extern FILE *dump_file;
extern dump_flags_t dump_flags;
extern const char *dump_file_name;
+extern bool dump_folding_p;
extern bool dumps_are_enabled;
@@ -63,6 +63,7 @@ FILE *dump_file = NULL;
const char *dump_file_name;
dump_flags_t dump_flags;
bool dumps_are_enabled = false;
+bool dump_folding_p = false;
/* Set global "dump_file" to NEW_DUMP_FILE, refreshing the "dumps_are_enabled"
@@ -73,6 +74,7 @@ set_dump_file (FILE *new_dump_file)
{
dumpfile_ensure_any_optinfo_are_flushed ();
dump_file = new_dump_file;
+ dump_folding_p = dump_file && (dump_flags & TDF_FOLDING);
dump_context::get ().refresh_dumps_are_enabled ();
}
@@ -102,3 +102,17 @@ optimize_successive_divisions_p (tree, tree)
{
return false;
}
+
+/* Helper method for debug printing to reducing string parsing overhead. Keep
+ in sync with version in gimple-match-head.cc. */
+
+static
+void dump_debug (bool simplify, int loc, const char *file, int lineno)
+{
+ if (simplify)
+ fprintf (dump_file, "Applying pattern %s:%d, %s:%d\n", "match.pd", loc,
+ file, lineno);
+ else
+ fprintf (dump_file, "Matching expression %s:%d, %s:%d\n", "match.pd", loc,
+ file, lineno);
+}
\ No newline at end of file
@@ -185,7 +185,8 @@ fprintf_indent (FILE *f, unsigned int indent, const char *format, ...)
static void
output_line_directive (FILE *f, location_t location,
- bool dumpfile = false, bool fnargs = false)
+ bool dumpfile = false, bool fnargs = false,
+ bool loc_only = false)
{
const line_map_ordinary *map;
linemap_resolve_location (line_table, location, LRK_SPELLING_LOCATION, &map);
@@ -204,7 +205,9 @@ output_line_directive (FILE *f, location_t location,
else
++file;
- if (fnargs)
+ if (loc_only)
+ fprintf (f, "%d", loc.line);
+ else if (fnargs)
fprintf (f, "\"%s\", %d", file, loc.line);
else
fprintf (f, "%s:%d", file, loc.line);
@@ -3431,14 +3434,11 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result)
needs_label = true;
}
- fprintf_indent (f, indent, "if (UNLIKELY (dump_file && (dump_flags & TDF_FOLDING))) "
- "fprintf (dump_file, \"%s ",
- s->kind == simplify::SIMPLIFY
- ? "Applying pattern" : "Matching expression");
- fprintf (f, "%%s:%%d, %%s:%%d\\n\", ");
+ fprintf_indent (f, indent, "if (UNLIKELY (dump_folding_p)) "
+ "dump_debug (%s, ", s->kind == simplify::SIMPLIFY ? "true" : "false");
output_line_directive (f,
result ? result->location : s->match->location, true,
- true);
+ true, true);
fprintf (f, ", __FILE__, __LINE__);\n");
fprintf_indent (f, indent, "{\n");
@@ -1412,3 +1412,17 @@ get_conditional_internal_fn (code_helper code, tree type)
auto cfn = combined_fn (code);
return get_conditional_internal_fn (associated_internal_fn (cfn, type));
}
+
+/* Helper method for debug printing to reducing string parsing overhead. Keep
+ in sync with version in generic-match-head.cc. */
+
+static
+void dump_debug (bool simplify, int loc, const char *file, int lineno)
+{
+ if (simplify)
+ fprintf (dump_file, "Applying pattern %s:%d, %s:%d\n", "match.pd", loc,
+ file, lineno);
+ else
+ fprintf (dump_file, "Matching expression %s:%d, %s:%d\n", "match.pd", loc,
+ file, lineno);
+}
\ No newline at end of file