public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-8631] analyzer: add .fpath.txt dumps to -fdump-analyzer-feasibility
@ 2022-07-27 21:55 David Malcolm
  0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2022-07-27 21:55 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:1321183a13540b5c3503586b94c758198471c7b3

commit r12-8631-g1321183a13540b5c3503586b94c758198471c7b3
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Wed Jul 27 17:38:53 2022 -0400

    analyzer: add .fpath.txt dumps to -fdump-analyzer-feasibility
    
    (cherry picked from r13-6-gd8586b00dd00a1783862da5f0c8811a740400074)
    
    I found this extension to -fdump-analyzer-feasibility very helpful when
    debugging PR analyzer/105285.
    
    gcc/analyzer/ChangeLog:
            * diagnostic-manager.cc (epath_finder::process_worklist_item):
            Call dump_feasible_path when a path that reaches the the target
            enode is found.
            (epath_finder::dump_feasible_path): New.
            * engine.cc (feasibility_state::dump_to_pp): New.
            * exploded-graph.h (feasibility_state::dump_to_pp): New decl.
            * feasible-graph.cc (feasible_graph::dump_feasible_path): New.
            * feasible-graph.h (feasible_graph::dump_feasible_path): New
            decls.
            * program-point.cc (function_point::print): Fix missing trailing
            newlines.
            * program-point.h (program_point::print_source_line): Remove
            unimplemented decl.
    
    gcc/ChangeLog:
            * doc/invoke.texi (-fdump-analyzer-feasibility): Mention the
            fpath.txt output.
    
    Signed-off-by: David Malcolm <dmalcolm@redhat.com>

Diff:
---
 gcc/analyzer/diagnostic-manager.cc | 24 ++++++++++++++
 gcc/analyzer/engine.cc             |  9 ++++++
 gcc/analyzer/exploded-graph.h      |  2 ++
 gcc/analyzer/feasible-graph.cc     | 65 ++++++++++++++++++++++++++++++++++++++
 gcc/analyzer/feasible-graph.h      |  6 ++++
 gcc/analyzer/program-point.cc      |  4 +++
 gcc/analyzer/program-point.h       |  1 -
 gcc/doc/invoke.texi                |  4 +--
 8 files changed, 112 insertions(+), 3 deletions(-)

diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc
index bf7c8fc5147..5bd4cd49cac 100644
--- a/gcc/analyzer/diagnostic-manager.cc
+++ b/gcc/analyzer/diagnostic-manager.cc
@@ -112,6 +112,10 @@ private:
   void dump_feasible_graph (const exploded_node *target_enode,
 			    const char *desc, unsigned diag_idx,
 			    const feasible_graph &fg);
+  void dump_feasible_path (const exploded_node *target_enode,
+			   unsigned diag_idx,
+			   const feasible_graph &fg,
+			   const feasible_node &fnode) const;
 
   const exploded_graph &m_eg;
   shortest_exploded_paths *m_sep;
@@ -510,6 +514,9 @@ epath_finder::process_worklist_item (feasible_worklist *worklist,
 			     target_enode->m_index, diag_idx,
 			     succ_fnode->get_path_length ());
 	      *out_best_path = fg->make_epath (succ_fnode);
+	      if (flag_dump_analyzer_feasibility)
+		dump_feasible_path (target_enode, diag_idx, *fg, *succ_fnode);
+
 	      /* Success: stop the worklist iteration.  */
 	      return false;
 	    }
@@ -608,6 +615,23 @@ epath_finder::dump_feasible_graph (const exploded_node *target_enode,
   free (filename);
 }
 
+/* Dump the path to FNODE to "BASE_NAME.DIAG_IDX.to-enN.fpath.txt".  */
+
+void
+epath_finder::dump_feasible_path (const exploded_node *target_enode,
+				  unsigned diag_idx,
+				  const feasible_graph &fg,
+				  const feasible_node &fnode) const
+{
+  auto_timevar tv (TV_ANALYZER_DUMP);
+  pretty_printer pp;
+  pp_printf (&pp, "%s.%i.to-en%i.fpath.txt",
+	     dump_base_name, diag_idx, target_enode->m_index);
+  char *filename = xstrdup (pp_formatted_text (&pp));
+  fg.dump_feasible_path (fnode, filename);
+  free (filename);
+}
+
 /* class saved_diagnostic.  */
 
 /* saved_diagnostic's ctor.
diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index d8b61955aa6..e43406e3556 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -4605,6 +4605,15 @@ feasibility_state::maybe_update_for_edge (logger *logger,
   return true;
 }
 
+/* Dump this object to PP.  */
+
+void
+feasibility_state::dump_to_pp (pretty_printer *pp,
+			       bool simple, bool multiline) const
+{
+  m_model.dump_to_pp (pp, simple, multiline);
+}
+
 /* A family of cluster subclasses for use when generating .dot output for
    exploded graphs (-fdump-analyzer-exploded-graph), for grouping the
    enodes into hierarchical boxes.
diff --git a/gcc/analyzer/exploded-graph.h b/gcc/analyzer/exploded-graph.h
index af0ab8d42c8..2dcdcc55b2a 100644
--- a/gcc/analyzer/exploded-graph.h
+++ b/gcc/analyzer/exploded-graph.h
@@ -1001,6 +1001,8 @@ public:
   const region_model &get_model () const { return m_model; }
   const auto_sbitmap &get_snodes_visited () const { return m_snodes_visited; }
 
+  void dump_to_pp (pretty_printer *pp, bool simple, bool multiline) const;
+
 private:
   region_model m_model;
   auto_sbitmap m_snodes_visited;
diff --git a/gcc/analyzer/feasible-graph.cc b/gcc/analyzer/feasible-graph.cc
index 0ac8484a7e4..fe7e79fe902 100644
--- a/gcc/analyzer/feasible-graph.cc
+++ b/gcc/analyzer/feasible-graph.cc
@@ -218,6 +218,71 @@ feasible_graph::make_epath (feasible_node *fnode) const
   return epath;
 }
 
+/* Dump the path to DST_FNODE in textual form to PP.  */
+
+void
+feasible_graph::dump_feasible_path (const feasible_node &dst_fnode,
+				    pretty_printer *pp) const
+{
+  const feasible_node *fnode = &dst_fnode;
+
+  auto_vec<const feasible_edge *> fpath;
+
+  /* FG is actually a tree.  Built the path backwards, by walking
+     backwards from FNODE until we reach the origin.  */
+  while (fnode->get_inner_node ()->m_index != 0)
+    {
+      gcc_assert (fnode->m_preds.length () == 1);
+      feasible_edge *pred_fedge
+	= static_cast <feasible_edge *> (fnode->m_preds[0]);
+      fpath.safe_push (pred_fedge);
+      fnode = static_cast <const feasible_node *> (pred_fedge->m_src);
+    }
+
+  /* Now reverse it.  */
+  fpath.reverse ();
+
+  for (unsigned i = 0; i < fpath.length (); i++)
+    {
+      const feasible_edge *fedge = fpath[i];
+      const feasible_node *src_fnode
+	= static_cast <const feasible_node *> (fedge->m_src);
+      const feasible_node *dest_fnode
+	= static_cast <const feasible_node *> (fedge->m_dest);
+
+      pp_printf (pp, "fpath[%i]: FN %i (EN %i) -> FN %i (EN %i)",
+		 i,
+		 src_fnode->get_index (),
+		 src_fnode->get_inner_node ()->m_index,
+		 dest_fnode->get_index (),
+		 dest_fnode->get_inner_node ()->m_index);
+      pp_newline (pp);
+      pp_printf (pp, "  FN %i (EN %i):",
+		 dest_fnode->get_index (),
+		 dest_fnode->get_inner_node ()->m_index);
+      pp_newline (pp);
+      const program_point &point = dest_fnode->get_inner_node ()->get_point ();
+      point.print (pp, format (true));
+      dest_fnode->get_state ().dump_to_pp (pp, true, true);
+      pp_newline (pp);
+    }
+}
+
+/* Dump the path to DST_FNODE in textual form to FILENAME.  */
+
+void
+feasible_graph::dump_feasible_path (const feasible_node &dst_fnode,
+				    const char *filename) const
+{
+  FILE *fp = fopen (filename, "w");
+  pretty_printer pp;
+  pp_format_decoder (&pp) = default_tree_printer;
+  pp.buffer->stream = fp;
+  dump_feasible_path (dst_fnode, &pp);
+  pp_flush (&pp);
+  fclose (fp);
+}
+
 /* Dump stats about this graph to LOGGER.  */
 
 void
diff --git a/gcc/analyzer/feasible-graph.h b/gcc/analyzer/feasible-graph.h
index d10a28d4f90..f1868af3cf8 100644
--- a/gcc/analyzer/feasible-graph.h
+++ b/gcc/analyzer/feasible-graph.h
@@ -197,11 +197,17 @@ class feasible_graph : public digraph <fg_traits>
 
   exploded_path *make_epath (feasible_node *fnode) const;
 
+  void dump_feasible_path (const feasible_node &dst_fnode,
+			   const char *filename) const;
+
   unsigned get_num_infeasible () const { return m_num_infeasible; }
 
   void log_stats (logger *logger) const;
 
 private:
+  void dump_feasible_path (const feasible_node &dst_fnode,
+			   pretty_printer *pp) const;
+
   unsigned m_num_infeasible;
 };
 
diff --git a/gcc/analyzer/program-point.cc b/gcc/analyzer/program-point.cc
index 61cea8a1076..8fa7066fea5 100644
--- a/gcc/analyzer/program-point.cc
+++ b/gcc/analyzer/program-point.cc
@@ -114,6 +114,8 @@ function_point::print (pretty_printer *pp, const format &f) const
 
     case PK_ORIGIN:
       pp_printf (pp, "origin");
+      if (f.m_newlines)
+	pp_newline (pp);
       break;
 
     case PK_BEFORE_SUPERNODE:
@@ -156,6 +158,8 @@ function_point::print (pretty_printer *pp, const format &f) const
 
     case PK_AFTER_SUPERNODE:
       pp_printf (pp, "after SN: %i", m_supernode->m_index);
+      if (f.m_newlines)
+	pp_newline (pp);
       break;
     }
 }
diff --git a/gcc/analyzer/program-point.h b/gcc/analyzer/program-point.h
index 4b1c733d710..6084c9e3004 100644
--- a/gcc/analyzer/program-point.h
+++ b/gcc/analyzer/program-point.h
@@ -179,7 +179,6 @@ public:
   }
 
   void print (pretty_printer *pp, const format &f) const;
-  void print_source_line (pretty_printer *pp) const;
   void dump () const;
 
   json::object *to_json () const;
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index e7f0a94a7cf..ff6c338bedb 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -10198,8 +10198,8 @@ diagnostic to @file{@var{file}.@var{idx}.@var{kind}.epath.txt}.
 @opindex dump-analyzer-feasibility
 Dump internal details about the analyzer's search for feasible paths.
 The details are written in a form suitable for viewing with GraphViz
-to filenames of the form @file{@var{file}.*.fg.dot} and
-@file{@var{file}.*.tg.dot}.
+to filenames of the form @file{@var{file}.*.fg.dot},
+@file{@var{file}.*.tg.dot}, and @file{@var{file}.*.fpath.txt}.
 
 @item -fdump-analyzer-json
 @opindex fdump-analyzer-json


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-27 21:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-27 21:55 [gcc r12-8631] analyzer: add .fpath.txt dumps to -fdump-analyzer-feasibility David Malcolm

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).