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]>
---
gcc/callback-info.cc | 54 ++++++++++++++++++++++++++++++++++++++++++++
gcc/callback-info.h | 16 +++++++++++++
2 files changed, 70 insertions(+)
diff --git a/gcc/callback-info.cc b/gcc/callback-info.cc
index ec2291f3338..95357b9c8ff 100644
--- a/gcc/callback-info.cc
+++ b/gcc/callback-info.cc
@@ -147,3 +147,57 @@ 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 (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 (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 to pointing to the outlined body. */
+bool
+callback_ifn_assume_call_with_edge_p (gimple *stmt)
+{
+ /* Fast path for most cases. */
+ if (!callback_ifn_assume_call_p (stmt))
+ return false;
+
+ tree decl = TREE_OPERAND (gimple_call_arg (stmt, 0), 0);
+ cgraph_node *node = cgraph_node::get (decl);
+ gcc_checking_assert (node->assume_function);
+
+ if (!node->callers)
+ return false;
+
+ cgraph_edge *e;
+ for (e = node->callers; e; e = e->next_caller)
+ if (!e->callback)
+ return false;
+
+ return true;
+}
diff --git a/gcc/callback-info.h b/gcc/callback-info.h
index 75894c7a361..87455ab1f76 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 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 (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 (gimple *stmt);
+
+/* Returns TRUE iff STMT is an internal call statement to IFN_ASSUME with a
+ callback edge to pointing to the outlined body. */
+bool callback_ifn_assume_call_with_edge_p (gimple *stmt);
+
#endif /* CALLBACK_INFO_H */
--
2.55.0