From 4a4732a6f48d5ba88bde1e97ec3abcf513ee2346 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 9 May 2019 15:46:13 -0400
Subject: [PATCH 28/46] FIXME: track the number of pathvars purged

---
 gcc/analyzer/constraints.cc | 18 +++++++++++++-----
 gcc/analyzer/constraints.h  |  2 +-
 gcc/analyzer/impl-4.cc      | 19 +++++++++++++++----
 3 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/gcc/analyzer/constraints.cc b/gcc/analyzer/constraints.cc
index b2a8e32..70f91ba 100644
--- a/gcc/analyzer/constraints.cc
+++ b/gcc/analyzer/constraints.cc
@@ -1219,11 +1219,14 @@ path_state::calc_escaped_p (path_var pv)
 
 /* Delete any information about path_var instances identified by P.
    Such instances are removed from equivalence classes, and any
-   redundant ECs and constraints are also removed.  */
+   redundant ECs and constraints are also removed.
+   Return the number of path_vars that are purged.  */
 
-void
+int
 path_state::purge (const purge_criteria &p)
 {
+  int num_purged = 0;
+
   /* Delete any path_vars identified by P within the various equivalence
      classes.  */
   for (unsigned ec_idx = 0; ec_idx < m_equiv_classes.length (); )
@@ -1236,9 +1239,12 @@ path_state::purge (const purge_criteria &p)
       FOR_EACH_VEC_ELT (ec->m_vars, i, pv)
 	{
 	  if (p.should_purge_p (*pv))
-	    if (ec->del (*pv))
-	      if (!ec->m_constant)
-		delete_ec = true;
+	    {
+	      num_purged++;
+	      if (ec->del (*pv))
+		if (!ec->m_constant)
+		  delete_ec = true;
+	    }
 	}
 
       if (delete_ec)
@@ -1325,6 +1331,8 @@ path_state::purge (const purge_criteria &p)
     }
 
   validate ();
+
+  return num_purged;
 }
 
 /* FIXME.  */
diff --git a/gcc/analyzer/constraints.h b/gcc/analyzer/constraints.h
index d6abfd8..eb8f4ec 100644
--- a/gcc/analyzer/constraints.h
+++ b/gcc/analyzer/constraints.h
@@ -274,7 +274,7 @@ public:
   void recursively_mark_as_escaping (equiv_class_id ec_id);
   bool calc_escaped_p (path_var pv);
 
-  void purge (const purge_criteria &p);
+  int purge (const purge_criteria &p);
 
   void validate () const;
 
diff --git a/gcc/analyzer/impl-4.cc b/gcc/analyzer/impl-4.cc
index 37e4658..1ab9c45 100644
--- a/gcc/analyzer/impl-4.cc
+++ b/gcc/analyzer/impl-4.cc
@@ -671,7 +671,7 @@ public:
     return ec_id.get_obj (m_path_state);
   }
 
-  program_state prune_for_point (const exploded_graph &eg,
+  program_state prune_for_point (exploded_graph &eg,
 				 const program_point &point) const;
 
   bool on_edge (const exploded_graph &eg,
@@ -856,6 +856,7 @@ struct stats
 
   int m_num_nodes[NUM_POINT_KINDS];
   int m_node_reuse_count;
+  int m_path_vars_purged;
 };
 
 /* An exploded_graph is a directed graph of unique <point, state> pairs.
@@ -896,6 +897,7 @@ public:
 		   const state_machine &sm,
 		   tree var, state_machine::state_t state) const;
 
+  stats *get_global_stats () { return &m_global_stats; }
   stats *get_or_create_function_stats (function *fn);
   void log_stats () const;
 
@@ -2178,7 +2180,7 @@ private:
    irrelevant state (e.g. at the end of functions).  */
 
 program_state
-program_state::prune_for_point (const exploded_graph &eg,
+program_state::prune_for_point (exploded_graph &eg,
 				const program_point &point) const
 {
   function *fun = point.get_function ();
@@ -2194,7 +2196,13 @@ program_state::prune_for_point (const exploded_graph &eg,
 
   purge_at_point_criteria criteria (point, eg.get_purge_map (),
 				    *this);
-  new_state.m_path_state.purge (criteria);
+  int num_purged = new_state.m_path_state.purge (criteria);
+  eg.log ("path_vars purged: %i", num_purged);
+
+  eg.get_global_stats ()->m_path_vars_purged++;
+  stats *per_fn_stats = eg.get_or_create_function_stats (point.get_function ());
+  per_fn_stats->m_path_vars_purged++;
+
 
 #if 0
   // FIXME: state maps also
@@ -3052,7 +3060,9 @@ exploded_edge::dump_dot (graphviz_out *gv) const
 
 /* FIXME.  */
 
-stats::stats () : m_node_reuse_count (0)
+ stats::stats ()
+: m_node_reuse_count (0),
+  m_path_vars_purged (0)
 {
   for (int i = 0; i < NUM_POINT_KINDS; i++)
     m_num_nodes[i] = 0;
@@ -3069,6 +3079,7 @@ stats::log (logger *logger) const
 		 point_kind_to_string (static_cast <enum point_kind> (i)),
 		 m_num_nodes[i]);
   logger->log ("m_node_reuse_count: %i", m_node_reuse_count);
+  logger->log ("m_path_vars_purged: %i", m_path_vars_purged);
 }
 
 ////////////////////////////////////////////////////////////////////////////
-- 
1.8.5.3

