https://gcc.gnu.org/g:21de85de3845dc0e4a53b75d8d436acb9dc51fed

commit r17-5621-g21de85de3845dc0e4a53b75d8d436acb9dc51fed
Author: Josef Melcr <[email protected]>
Date:   Wed Sep 16 16:28:52 2026 +0200

    Add supporting functions for IFN_ASSUME IPA support
    
    This patch adds a few shorthand functions to make further work with the
    new callback edges a little easier.  They are pretty self explanatory.
    Some of them actaully contain some logic, but some of them exist just to
    make some if statements a little shorter.
    
    gcc/ChangeLog:
    
            * callback-info.cc (callback_call_arg_summary): Add
            implementation.
            (callback_call_num_args_summary): Likewise.
            (callback_ifn_assume_call_p): Likewise.
            (callback_ifn_assume_call_with_edge_p): Likewise.
            * callback-info.h (callback_call_arg_summary): New function,
            remaps arguments for callback calls.
            (callback_call_num_args_summary): New function, returns the
            correct number of arguments for callback calls.
            (callback_ifn_assume_call_p): New function, returns TRUE if the
            passed call is a call to IFN_ASSUME.
            (callback_ifn_assume_call_with_edge_p): New function, returns
            TRUE if the passed call is a call to IFN_ASSUME with an attached
            cgraph_edge.
    
    Signed-off-by: Josef Melcr <[email protected]>

Diff:
---
 gcc/callback-info.cc | 44 ++++++++++++++++++++++++++++++++++++++++++++
 gcc/callback-info.h  | 16 ++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git a/gcc/callback-info.cc b/gcc/callback-info.cc
index ec2291f3338c..a75a7d695e5c 100644
--- a/gcc/callback-info.cc
+++ b/gcc/callback-info.cc
@@ -147,3 +147,47 @@ callback_info_sum_t::duplicate (cgraph_edge *, cgraph_edge 
*,
   dst_s->inverted_mapping = src_s->inverted_mapping.copy ();
   dst_s->redirected = src_s->redirected;
 }
+
+/* Return the argument at IDX if CI is null, otherwise use the mapping in CI 
and
+   return the remapped argument.  Presumes that the remapped index is not
+   ARG_MAPPING_UNKNOWN_IDX.  */
+tree
+callback_call_arg_summary (const gimple *stmt, int idx, callback_info *ci)
+{
+  if (ci)
+    idx = ci->arg_mapping[idx];
+  gcc_checking_assert (idx != ARG_MAPPING_UNKNOWN_IDX);
+  return gimple_call_arg (stmt, idx);
+}
+
+/* Return the number of arguments of STMT if CI is null,
+   ci->arg_mapping.length() otherwise.  */
+unsigned
+callback_call_num_args_summary (const gcall *stmt, callback_info *ci)
+{
+  if (ci)
+    return ci->arg_mapping.length ();
+  return gimple_call_num_args (stmt);
+}
+
+/* Returns TRUE iff STMT is an internal call statement to IFN_ASSUME.  */
+bool
+callback_ifn_assume_call_p (const gimple *stmt)
+{
+  return is_gimple_call (stmt) && gimple_call_internal_p (stmt)
+        && (gimple_call_internal_fn (stmt) == IFN_ASSUME);
+}
+
+/* Returns TRUE iff STMT is an internal call statement to IFN_ASSUME with a
+   callback edge pointing to the outlined body.  */
+bool
+callback_ifn_assume_call_with_edge_p (cgraph_node *caller, gimple *stmt)
+{
+  /* Fast path for most cases.  */
+  if (!callback_ifn_assume_call_p (stmt))
+    return false;
+
+  cgraph_edge *cbei = caller->get_edge (stmt);
+
+  return cbei != nullptr;
+}
diff --git a/gcc/callback-info.h b/gcc/callback-info.h
index 96fc1f01d249..bb656a90c889 100644
--- a/gcc/callback-info.h
+++ b/gcc/callback-info.h
@@ -82,4 +82,20 @@ public:
 
 extern callback_info_sum_t *callback_info_sum;
 
+/* Return the argument of STMT at IDX if CI is null, otherwise use the mapping
+   in CI and return the remapped argument.  Presumes that the remapped index is
+   not ARG_MAPPING_UNKNOWN_IDX.  */
+tree callback_call_arg_summary (const gimple *stmt, int idx, callback_info 
*ci);
+
+/* Return the number of arguments of STMT if CI is null,
+   ci->arg_mapping.length() otherwise.  */
+unsigned callback_call_num_args_summary (const gcall *stmt, callback_info *ci);
+
+/* Returns TRUE iff STMT is an internal call statement to IFN_ASSUME.  */
+bool callback_ifn_assume_call_p (const gimple *stmt);
+
+/* Returns TRUE iff STMT is an internal call statement to IFN_ASSUME with a
+   callback edge pointing to the outlined body.  */
+bool callback_ifn_assume_call_with_edge_p (cgraph_node *caller, gimple *stmt);
+
 #endif /* CALLBACK_INFO_H  */

Reply via email to