This patch adds a new predicate called callback_with_carrying_edge_p,
which returns true if a callback edge *should* have a carrying edge
bound to it.  This predicate was suggested by Martin, to hide the
somewhat confusing checking of assume_function and to capture the
meaning of the check in more detail.

gcc/ChangeLog:

        * cgraph.cc (cgraph_node::get_edge): Use callback_with_carrying_edge_p.
        (cgraph_edge::set_call_stmt): Likewise.
        (cgraph_edge::callback_with_carrying_edge_p): Add implementation.
        (cgraph_edge::redirect_call_stmt_to_callee): Use
        callback_with_carrying_edge_p.
        * cgraph.h: Add method callback_with_carrying_edge_p, returns
        TRUE if THIS is a callback edge with an existing
        callback-carrying edge.

Signed-off-by: Josef Melcr <[email protected]>
---
 gcc/cgraph.cc | 15 ++++++++++++---
 gcc/cgraph.h  |  3 +++
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index 184b741b1be..e87b7998e00 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -934,7 +934,7 @@ cgraph_node::get_edge (gimple *call_stmt)
      comes to callback edges, a call statement might have multiple callback
      edges attached to it.  These can be easily obtained from the carrying edge
      instead.  */
-  if (e && e->callback)
+  if (e && e->callback_with_carrying_edge_p ())
     e = e->get_callback_carrying_edge ();
 
   if (n > 100)
@@ -1012,7 +1012,8 @@ cgraph_edge::set_call_stmt (cgraph_edge *e, gcall 
*new_stmt,
 
   /* When updating a callback or a callback-carrying edge, update every edge
      involved.  */
-  if (update_derived_edges && (e->callback || e->has_callback))
+  if (update_derived_edges
+      && (e->callback_with_carrying_edge_p () || e->has_callback))
     {
       cgraph_edge *current, *next, *carrying;
       carrying = e->has_callback ? e : e->get_callback_carrying_edge ();
@@ -1406,6 +1407,14 @@ cgraph_edge::get_callback_carrying_edge ()
   return e;
 }
 
+/* Returns TRUE iff THIS is a callback edge with a carrying edge.  */
+bool
+cgraph_edge::callback_with_carrying_edge_p () const
+{
+  /* Callback edges are always direct, i.e. callee != NULL.  */
+  return callback && !callee->assume_function;
+}
+
 /* Returns the first callback edge in the list of callees of the caller node.
    Note that the edges might be in arbitrary order.  Must be called on a
    callback or callback-carrying edge.  */
@@ -1851,7 +1860,7 @@ cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge *e,
   /* When redirecting a callback edge, all we need to do is replace
      the original address with the address of the function we are
      redirecting to.  */
-  if (e->callback)
+  if (e->callback_with_carrying_edge_p ())
     {
       cgraph_edge *carrying = e->get_callback_carrying_edge ();
       if (!callback_is_special_cased (carrying->callee->decl, e->call_stmt)
diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index 5f8e4235184..0f05b5024e9 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -1938,6 +1938,9 @@ public:
      this method is caled on.  */
   cgraph_edge *get_callback_carrying_edge ();
 
+  /* Returns TRUE iff THIS is a callback edge with a carrying edge.  */
+  bool callback_with_carrying_edge_p () const;
+
   /* Returns the first callback edge in the list of callees of the caller node.
      Note that the edges might be in arbitrary order.  Must be called on a
      callback or callback-carrying edge.  */
-- 
2.55.0

Reply via email to