]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Improve jump threading dump output.
authorAldy Hernandez <aldyh@redhat.com>
Tue, 28 Sep 2021 08:19:57 +0000 (10:19 +0200)
committerAldy Hernandez <aldyh@redhat.com>
Tue, 28 Sep 2021 13:55:29 +0000 (15:55 +0200)
In analyzing PR102511, it has become abundantly clear that we need
better debugging aids for the jump threader solver.  Currently
debugging these issues is a nightmare if you're not intimately
familiar with the code.  This patch attempts to improve this.

First, I'm enabling path solver dumps with TDF_THREADING.  None of the
available TDF_* flags are a good match, and using TDF_DETAILS would blow
up the dump file, since both threaders continually call the solver to
try out candidates.  This will allow dumping path solver details without
having to resort to hacking the source.

I am also dumping the current registered_jump_thread dbg counter used
by the registry, in the solver.  That way narrowing down a problematic
thread can then be examined by -fdump-*-threading and looking at the
solver details surrounding the appropriate counter (which the dbgcnt
also dumps to the dump file).

You still need knowledge of the solver to debug these issues, but at
least now it's not entirely opaque.

Tested on x86-64 Linux.

gcc/ChangeLog:

* dbgcnt.c (dbg_cnt_counter): New.
* dbgcnt.h (dbg_cnt_counter): New.
* dumpfile.c (dump_options): Add entry for TDF_THREADING.
* dumpfile.h (enum dump_flag): Add TDF_THREADING.
* gimple-range-path.cc (DEBUG_SOLVER): Use TDF_THREADING.
* tree-ssa-threadupdate.c (dump_jump_thread_path): Dump out
debug counter.

gcc/dbgcnt.c
gcc/dbgcnt.h
gcc/dumpfile.c
gcc/dumpfile.h
gcc/gimple-range-path.cc
gcc/tree-ssa-threadupdate.c

index 934bbe033eeb70215db5b9856883dd1a998ab105..6a7eb34cd3ed2a8d9212ad5e0d87e8219f1eaa04 100644 (file)
@@ -98,6 +98,14 @@ dbg_cnt (enum debug_counter index)
     return false;
 }
 
+/* Return the counter for INDEX.  */
+
+unsigned
+dbg_cnt_counter (enum debug_counter index)
+{
+  return count[index];
+}
+
 /* Compare limit_tuple intervals by first item in descending order.  */
 
 static int
index 17f2091f5a72c336b09742df7b1d489b9f1476ef..3c35dcc3e0a7e0e2e62fff460f86265937e0bac0 100644 (file)
@@ -33,6 +33,7 @@ enum debug_counter {
 
 extern bool dbg_cnt_is_enabled (enum debug_counter index);
 extern bool dbg_cnt (enum debug_counter index);
+extern unsigned dbg_cnt_counter (enum debug_counter index);
 extern void dbg_cnt_process_opt (const char *arg);
 extern void dbg_cnt_list_all_counters (void);
 
index 8169daf7f5964dbdf18cdfb61fdd780aa20ab153..e6ead5debe5603a4ee22a68555e0eac8f6fe22d2 100644 (file)
@@ -145,6 +145,7 @@ static const kv_pair<dump_flags_t> dump_options[] =
   {"missed", MSG_MISSED_OPTIMIZATION},
   {"note", MSG_NOTE},
   {"optall", MSG_ALL_KINDS},
+  {"threading", TDF_THREADING},
   {"all", dump_flags_t (TDF_ALL_VALUES
                        & ~(TDF_RAW | TDF_SLIM | TDF_LINENO | TDF_GRAPH
                            | TDF_STMTADDR | TDF_RHS_ONLY | TDF_NOUID
index 892bfc9ae90bcdb1dc0abbb62942cf822a9ff4b7..6c7758dd2fb6b54cb96eb0a4e72c3ad8c4b14983 100644 (file)
@@ -197,6 +197,9 @@ enum dump_flag
   /* For error.  */
   TDF_ERROR = (1 << 26),
 
+  /* Dumping for range path solver.  */
+  TDF_THREADING = (1 << 27),
+
   /* All values.  */
   TDF_ALL_VALUES = (1 << 29) - 1
 };
index 9da67d2a35be3eb73834e60cfc48b3f40cd081b9..a29d5318ca9b7568b62b509f8149b817e7aa505e 100644 (file)
@@ -34,7 +34,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-iterator.h"
 
 // Internal construct to help facilitate debugging of solver.
-#define DEBUG_SOLVER (0 && dump_file)
+#define DEBUG_SOLVER (dump_file && dump_flags & TDF_THREADING)
 
 path_range_query::path_range_query (gimple_ranger &ranger, bool resolve)
   : m_ranger (ranger)
index 71e602ffa2da7b7d906f1b94fcddbe374e5eca52..dcabfdb30d2c0dfee702463713cb11fcdc3defa3 100644 (file)
@@ -218,10 +218,15 @@ dump_jump_thread_path (FILE *dump_file,
                       const vec<jump_thread_edge *> &path,
                       bool registering)
 {
-  fprintf (dump_file,
-          "  %s jump thread: (%d, %d) incoming edge; ",
-          (registering ? "Registering" : "Cancelling"),
-          path[0]->e->src->index, path[0]->e->dest->index);
+  if (registering)
+    fprintf (dump_file,
+            "  [%u] Registering jump thread: (%d, %d) incoming edge; ",
+            dbg_cnt_counter (registered_jump_thread),
+            path[0]->e->src->index, path[0]->e->dest->index);
+  else
+    fprintf (dump_file,
+            "  Cancelling jump thread: (%d, %d) incoming edge; ",
+            path[0]->e->src->index, path[0]->e->dest->index);
 
   for (unsigned int i = 1; i < path.length (); i++)
     {