From b9a32c5d747a3990f38555a4a72d4863b5cfbc56 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Fri, 17 Jul 2020 15:41:43 -0400
Subject: [PATCH 312/315] FIXME: tweak egraph .dot output to focus on enodes
 where state exploded

---
 gcc/analyzer/engine.cc        | 74 +++++++++++++++++++++++++++--------
 gcc/analyzer/exploded-graph.h |  5 +++
 2 files changed, 62 insertions(+), 17 deletions(-)

diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index 72897cad8c2..bc7821bd161 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -1318,6 +1318,28 @@ print_enode_indices (pretty_printer *pp,
     }
 }
 
+/* struct eg_traits::dump_args_t.  */
+
+/* Return true if ENODE should be shown in detail in .dot output.
+   Return false if no detail should be shown for ENODE.  */
+
+bool
+eg_traits::dump_args_t::show_enode_details_p (const exploded_node &enode) const
+{
+#if 0
+  // FIXME:
+  const int id_of_interest = 1179;
+  const exploded_node *enode_of_interest = m_eg.m_nodes[id_of_interest];
+  gcc_assert (enode_of_interest->m_index == id_of_interest);
+  const program_point &point_of_interest = enode_of_interest->get_point ();
+#endif
+  /* Expand enodes at program points where we hit the per-enode limit, so we
+     can investigate what exploded.  */
+  const per_program_point_data *per_point_data
+    = m_eg.get_per_program_point_data (enode.get_point ());
+  return per_point_data->m_excess_enodes > 0;
+}
+
 /* class exploded_node : public dnode<eg_traits>.  */
 
 /* exploded_node's ctor.  */
@@ -1375,7 +1397,9 @@ exploded_node::get_dot_fillcolor () const
     {
       /* An arbitrarily-picked collection of light colors.  */
       const char * const colors[]
-	= {"azure", "coral", "cornsilk", "lightblue", "yellow"};
+	= {"azure", "coral", "cornsilk", "lightblue", "yellow",
+	   "honeydew", "lightpink", "lightsalmon", "palegreen1",
+	   "wheat", "seashell"};
       const int num_colors = sizeof (colors) / sizeof (colors[0]);
       return colors[total_sm_state % num_colors];
     }
@@ -1401,28 +1425,31 @@ exploded_node::dump_dot (graphviz_out *gv, const dump_args_t &args) const
     pp_string (pp, " (merger)");
   pp_newline (pp);
 
-  format f (true);
-  m_ps.get_point ().print (pp, f);
-  pp_newline (pp);
+  if (args.show_enode_details_p (*this))
+    {
+      format f (true);
+      m_ps.get_point ().print (pp, f);
+      pp_newline (pp);
 
-  const extrinsic_state &ext_state = args.m_eg.get_ext_state ();
-  const program_state &state = m_ps.get_state ();
-  state.dump_to_pp (ext_state, true, true, pp);
-  pp_newline (pp);
+      const extrinsic_state &ext_state = args.m_eg.get_ext_state ();
+      const program_state &state = m_ps.get_state ();
+      state.dump_to_pp (ext_state, false, true, pp);
+      pp_newline (pp);
 
-  {
-    int i;
-    sm_state_map *smap;
-    FOR_EACH_VEC_ELT (state.m_checker_states, i, smap)
       {
-	if (!smap->is_empty_p ())
+	int i;
+	sm_state_map *smap;
+	FOR_EACH_VEC_ELT (state.m_checker_states, i, smap)
 	  {
-	    pp_printf (pp, "%s: ", ext_state.get_name (i));
-	    smap->print (ext_state.get_sm (i), state.m_region_model, pp);
-	    pp_newline (pp);
+	    if (!smap->is_empty_p ())
+	      {
+		pp_printf (pp, "%s: ", ext_state.get_name (i));
+		smap->print (ext_state.get_sm (i), state.m_region_model, pp);
+		pp_newline (pp);
+	      }
 	  }
       }
-  }
+    }
 
   /* Dump any saved_diagnostics at this enode.  */
   {
@@ -2958,6 +2985,19 @@ get_or_create_per_program_point_data (const program_point &point)
   return per_point_data;
 }
 
+/* Get this graph's per-program-point-data for POINT if there is any,
+   otherwise NULL.  */
+
+per_program_point_data *
+exploded_graph::get_per_program_point_data (const program_point &point) const
+{
+  if (per_program_point_data **slot
+      = const_cast <point_map_t &> (m_per_point_data).get (&point))
+    return *slot;
+
+  return NULL;
+}
+
 /* Ensure that this graph has per-call_string-data for CS;
    borrow a pointer to it.  */
 
diff --git a/gcc/analyzer/exploded-graph.h b/gcc/analyzer/exploded-graph.h
index 6eea887a6a0..bea6c42e4b5 100644
--- a/gcc/analyzer/exploded-graph.h
+++ b/gcc/analyzer/exploded-graph.h
@@ -204,6 +204,9 @@ struct eg_traits
   struct dump_args_t
   {
     dump_args_t (const exploded_graph &eg) : m_eg (eg) {}
+
+    bool show_enode_details_p (const exploded_node &enode) const;
+
     const exploded_graph &m_eg;
   };
   typedef exploded_cluster cluster_t;
@@ -830,6 +833,8 @@ public:
 
   per_program_point_data *
   get_or_create_per_program_point_data (const program_point &);
+  per_program_point_data *
+  get_per_program_point_data (const program_point &) const;
 
   per_call_string_data *
   get_or_create_per_call_string_data (const call_string &);
-- 
2.26.2

