public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/arsenic/heads/call_string_update)] gcc/analyzer/call-string.h: refactor callstring to work with pairs of supernodes
@ 2021-07-03  5:55 Ankur saini
  0 siblings, 0 replies; only message in thread
From: Ankur saini @ 2021-07-03  5:55 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:95033fee8202d9678533e789213a5cc46566a825

commit 95033fee8202d9678533e789213a5cc46566a825
Author: Ankur Saini <arsenic@sourceware.org>
Date:   Sat Jul 3 11:10:39 2021 +0530

    gcc/analyzer/call-string.h: refactor callstring to work with pairs of supernodes
    
    2021-07-3  Ankur Saini  <arsenic@sourceware.org>
    
            * gcc/analyzer/call-string.cc: refactor callstring to work with pair of supernodes instead of super superedges
            * gcc/analyzer/call-string.h: make callstring work with pairs of supernodes
            * gcc/analyzer/program-point.cc: refactor program point to work with new call-string format

Diff:
---
 gcc/analyzer/call-string.cc   | 76 +++++++++++++++++++++++--------------------
 gcc/analyzer/call-string.h    | 16 +++++----
 gcc/analyzer/program-point.cc | 12 ++++---
 3 files changed, 57 insertions(+), 47 deletions(-)

diff --git a/gcc/analyzer/call-string.cc b/gcc/analyzer/call-string.cc
index 9f4f77ab3a9..d2e8ed46897 100644
--- a/gcc/analyzer/call-string.cc
+++ b/gcc/analyzer/call-string.cc
@@ -48,10 +48,10 @@ along with GCC; see the file COPYING3.  If not see
 /* call_string's copy ctor.  */
 
 call_string::call_string (const call_string &other)
-: m_return_edges (other.m_return_edges.length ())
+: m_supernodes (other.m_supernodes.length ())
 {
-  for (const return_superedge *e : other.m_return_edges)
-    m_return_edges.quick_push (e);
+  for (const std::pair<supernode *,supernode *> *e : other.m_supernodes)
+    m_supernodes.quick_push (e);
 }
 
 /* call_string's assignment operator.  */
@@ -60,12 +60,12 @@ call_string&
 call_string::operator= (const call_string &other)
 {
   // would be much simpler if we could rely on vec<> assignment op
-  m_return_edges.truncate (0);
-  m_return_edges.reserve (other.m_return_edges.length (), true);
-  const return_superedge *e;
+  m_supernodes.truncate (0);
+  m_supernodes.reserve (other.m_supernodes.length (), true);
+  const std::pair<supernode *,supernode *> *e;
   int i;
-  FOR_EACH_VEC_ELT (other.m_return_edges, i, e)
-    m_return_edges.quick_push (e);
+  FOR_EACH_VEC_ELT (other.m_supernodes, i, e)
+    m_supernodes.quick_push (e);
   return *this;
 }
 
@@ -74,12 +74,12 @@ call_string::operator= (const call_string &other)
 bool
 call_string::operator== (const call_string &other) const
 {
-  if (m_return_edges.length () != other.m_return_edges.length ())
+  if (m_supernodes.length () != other.m_supernodes.length ())
     return false;
-  const return_superedge *e;
+  const std::pair<supernode *,supernode *> *e;
   int i;
-  FOR_EACH_VEC_ELT (m_return_edges, i, e)
-    if (e != other.m_return_edges[i])
+  FOR_EACH_VEC_ELT (m_supernodes, i, e)
+    if (e != other.m_supernodes[i])
       return false;
   return true;
 }
@@ -91,15 +91,15 @@ call_string::print (pretty_printer *pp) const
 {
   pp_string (pp, "[");
 
-  const return_superedge *e;
+  const std::pair<supernode *,supernode *> *e;
   int i;
-  FOR_EACH_VEC_ELT (m_return_edges, i, e)
+  FOR_EACH_VEC_ELT (m_supernodes, i, e)
     {
       if (i > 0)
 	pp_string (pp, ", ");
       pp_printf (pp, "(SN: %i -> SN: %i in %s)",
-		 e->m_src->m_index, e->m_dest->m_index,
-		 function_name (e->m_dest->m_fun));
+		 e->first->m_index, e->second->m_index,
+		 function_name (e->second->m_fun));
     }
 
   pp_string (pp, "]");
@@ -109,22 +109,22 @@ call_string::print (pretty_printer *pp) const
    [{"src_snode_idx" : int,
      "dst_snode_idx" : int,
      "funcname" : str},
-     ...for each return_superedge in the callstring].  */
+     ...for each std::pair<supernode *,supernode *> in the callstring].  */
 
 json::value *
 call_string::to_json () const
 {
   json::array *arr = new json::array ();
 
-  for (const return_superedge *e : m_return_edges)
+  for (const std::pair<supernode *,supernode *> *e : m_supernodes)
     {
       json::object *e_obj = new json::object ();
       e_obj->set ("src_snode_idx",
-		  new json::integer_number (e->m_src->m_index));
+		  new json::integer_number (e->first->m_index));
       e_obj->set ("dst_snode_idx",
-		  new json::integer_number (e->m_dest->m_index));
+		  new json::integer_number (e->second->m_index));
       e_obj->set ("funcname",
-		  new json::string (function_name (e->m_dest->m_fun)));
+		  new json::string (function_name (e->second->m_fun)));
       arr->append (e_obj);
     }
 
@@ -137,7 +137,7 @@ hashval_t
 call_string::hash () const
 {
   inchash::hash hstate;
-  for (const return_superedge *e : m_return_edges)
+  for (const std::pair<supernode *,supernode *> *e : m_supernodes)
     hstate.add_ptr (e);
   return hstate.end ();
 }
@@ -152,7 +152,10 @@ call_string::push_call (const supergraph &sg,
   gcc_assert (call_sedge);
   const return_superedge *return_sedge = call_sedge->get_edge_for_return (sg);
   gcc_assert (return_sedge);
-  m_return_edges.safe_push (return_sedge);
+  std::pair<supernode *,supernode *> *e;
+  e->first =  return_sedge->m_src;
+  e->second = return_sedge->m_dest;
+  m_supernodes.safe_push (e);
 }
 
 /* Count the number of times the top-most call site appears in the
@@ -161,13 +164,13 @@ call_string::push_call (const supergraph &sg,
 int
 call_string::calc_recursion_depth () const
 {
-  if (m_return_edges.is_empty ())
+  if (m_supernodes.is_empty ())
     return 0;
-  const return_superedge *top_return_sedge
-    = m_return_edges[m_return_edges.length () - 1];
+  const std::pair<supernode *,supernode *> *top_return_sedge
+    = m_supernodes[m_supernodes.length () - 1];
 
   int result = 0;
-  for (const return_superedge *e : m_return_edges)
+  for (const std::pair<supernode *,supernode *> *e : m_supernodes)
     if (e == top_return_sedge)
       ++result;
   return result;
@@ -201,13 +204,13 @@ call_string::cmp (const call_string &a,
       if (i >= len_b)
 	return -1;
 
-      /* Otherwise, compare the edges.  */
-      const return_superedge *edge_a = a[i];
-      const return_superedge *edge_b = b[i];
-      int src_cmp = edge_a->m_src->m_index - edge_b->m_src->m_index;
+      /* Otherwise, compare the node pairs.  */
+      const std::pair<supernode *,supernode *> *a_node_pair = a[i];
+      const std::pair<supernode *,supernode *> *b_node_pair = b[i];
+      int src_cmp = a_node_pair->first->m_index - b_node_pair->first->m_index;
       if (src_cmp)
 	return src_cmp;
-      int dest_cmp = edge_a->m_dest->m_index - edge_b->m_dest->m_index;
+      int dest_cmp = a_node_pair->second->m_index - b_node_pair->second->m_index;
       if (dest_cmp)
 	return dest_cmp;
       i++;
@@ -226,12 +229,13 @@ call_string::validate () const
 #endif
 
   /* Each entry's "caller" should be the "callee" of the previous entry.  */
-  const return_superedge *e;
+  const std::pair<supernode *,supernode *> *e;
   int i;
-  FOR_EACH_VEC_ELT (m_return_edges, i, e)
+  FOR_EACH_VEC_ELT (m_supernodes, i, e)
     if (i > 0)
-      gcc_assert (e->get_caller_function ()
-		  == m_return_edges[i - 1]->get_callee_function ());
+    {
+      gcc_assert (e->second->get_function () == m_supernodes[i - 1]->second->get_function());
+    }
 }
 
 #endif /* #if ENABLE_ANALYZER */
diff --git a/gcc/analyzer/call-string.h b/gcc/analyzer/call-string.h
index 7721571ed60..be3b486157a 100644
--- a/gcc/analyzer/call-string.h
+++ b/gcc/analyzer/call-string.h
@@ -24,6 +24,7 @@ along with GCC; see the file COPYING3.  If not see
 namespace ana {
 
 class supergraph;
+class supernode;
 class call_superedge;
 class return_superedge;
 
@@ -39,7 +40,7 @@ class return_superedge;
 class call_string
 {
 public:
-  call_string () : m_return_edges () {}
+  call_string () : m_supernodes () {}
   call_string (const call_string &other);
   call_string& operator= (const call_string &other);
 
@@ -51,27 +52,28 @@ public:
 
   hashval_t hash () const;
 
-  bool empty_p () const { return m_return_edges.is_empty (); }
+  bool empty_p () const { return m_supernodes.is_empty (); }
 
   void push_call (const supergraph &sg,
 		  const call_superedge *sedge);
-  const return_superedge *pop () { return m_return_edges.pop (); }
+  const std::pair<supernode *,supernode *> *pop () { return m_supernodes.pop (); }
 
   int calc_recursion_depth () const;
 
   static int cmp (const call_string &a,
 		  const call_string &b);
 
-  unsigned length () const { return m_return_edges.length (); }
-  const return_superedge *operator[] (unsigned idx) const
+  unsigned length () const { return m_supernodes.length (); }
+  const std::pair<supernode *,supernode *> *operator[] (unsigned idx) const
   {
-    return m_return_edges[idx];
+    return m_supernodes[idx];
   }
 
   void validate () const;
 
 private:
-  auto_vec<const return_superedge *> m_return_edges;
+  //auto_vec<const return_superedge *> m_return_edges;
+  auto_vec<const std::pair<supernode *,supernode *>*> m_supernodes;
 };
 
 } // namespace ana
diff --git a/gcc/analyzer/program-point.cc b/gcc/analyzer/program-point.cc
index d8cfc61975e..b08306b20d5 100644
--- a/gcc/analyzer/program-point.cc
+++ b/gcc/analyzer/program-point.cc
@@ -343,7 +343,7 @@ program_point::get_function_at_depth (unsigned depth) const
   if (depth == m_call_string.length ())
     return m_function_point.get_function ();
   else
-    return m_call_string[depth]->get_caller_function ();
+    return m_call_string[depth]->first->get_function ();
 }
 
 /* Assert that this object is sane.  */
@@ -360,7 +360,7 @@ program_point::validate () const
   /* The "callee" of the final entry in the callstring should be the
      function of the m_function_point.  */
   if (m_call_string.length () > 0)
-    gcc_assert (m_call_string[m_call_string.length () - 1]->get_callee_function ()
+    gcc_assert (m_call_string[m_call_string.length () - 1]->second->get_function ()
 		== get_function ());
 }
 
@@ -431,8 +431,12 @@ program_point::on_edge (exploded_graph &eg,
 	      logger->log ("rejecting return edge: empty call string");
 	    return false;
 	  }
-	const return_superedge *top_of_stack = m_call_string.pop ();
-	if (top_of_stack != succ)
+	const std::pair<supernode *,supernode *> *top_of_stack = m_call_string.pop ();
+  std::pair<supernode *,supernode *> *current_sedge_node_pair = NULL;
+  current_sedge_node_pair->first = succ->m_src;
+  current_sedge_node_pair->second = succ->m_dest;
+
+	if (top_of_stack != current_sedge_node_pair)
 	  {
 	    if (logger)
 	      logger->log ("rejecting return edge: return to wrong callsite");


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

only message in thread, other threads:[~2021-07-03  5:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-03  5:55 [gcc(refs/users/arsenic/heads/call_string_update)] gcc/analyzer/call-string.h: refactor callstring to work with pairs of supernodes Ankur saini

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