public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-109] tree: Add 3+ argument fndecl_built_in_p
@ 2023-04-20 11:05 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2023-04-20 11:05 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:1edcb2ea0eb29f1a85cd9ba7bb933c4a260cba44
commit r14-109-g1edcb2ea0eb29f1a85cd9ba7bb933c4a260cba44
Author: Jakub Jelinek <jakub@redhat.com>
Date: Thu Apr 20 13:02:52 2023 +0200
tree: Add 3+ argument fndecl_built_in_p
On Wed, Feb 22, 2023 at 09:52:06AM +0000, Richard Biener wrote:
> > The following testcase ICEs because we still have some spots that
> > treat BUILT_IN_UNREACHABLE specially but not BUILT_IN_UNREACHABLE_TRAP
> > the same.
This patch uses (fndecl_built_in_p (node, BUILT_IN_UNREACHABLE)
|| fndecl_built_in_p (node, BUILT_IN_UNREACHABLE_TRAP))
a lot and from grepping around, we do something like that in lots of
other places, or in some spots instead as
(fndecl_built_in_p (node, BUILT_IN_NORMAL)
&& (DECL_FUNCTION_CODE (node) == BUILT_IN_WHATEVER1
|| DECL_FUNCTION_CODE (node) == BUILT_IN_WHATEVER2))
The following patch adds an overload for this case, so we can write
it in a shorter way, using C++11 argument packs so that it supports
as many codes as one needs.
2023-04-20 Jakub Jelinek <jakub@redhat.com>
Jonathan Wakely <jwakely@redhat.com>
* tree.h (built_in_function_equal_p): New helper function.
(fndecl_built_in_p): Turn into variadic template to support
1 or more built_in_function arguments.
* builtins.cc (fold_builtin_expect): Use 3 argument fndecl_built_in_p.
* gimplify.cc (goa_stabilize_expr): Likewise.
* cgraphclones.cc (cgraph_node::create_clone): Likewise.
* ipa-fnsummary.cc (compute_fn_summary): Likewise.
* omp-low.cc (setjmp_or_longjmp_p): Likewise.
* cgraph.cc (cgraph_edge::redirect_call_stmt_to_callee,
cgraph_update_edges_for_call_stmt_node,
cgraph_edge::verify_corresponds_to_fndecl,
cgraph_node::verify_node): Likewise.
* tree-stdarg.cc (optimize_va_list_gpr_fpr_size): Likewise.
* gimple-ssa-warn-access.cc (matching_alloc_calls_p): Likewise.
* ipa-prop.cc (try_make_edge_direct_virtual_call): Likewise.
Diff:
---
gcc/builtins.cc | 4 ++--
gcc/cgraph.cc | 19 ++++++++-----------
gcc/cgraphclones.cc | 5 ++---
gcc/gimple-ssa-warn-access.cc | 7 +++----
gcc/gimplify.cc | 4 ++--
gcc/ipa-fnsummary.cc | 4 ++--
gcc/ipa-prop.cc | 4 ++--
gcc/omp-low.cc | 3 +--
gcc/tree-stdarg.cc | 4 ++--
gcc/tree.h | 27 ++++++++++++++++++++++++---
10 files changed, 48 insertions(+), 33 deletions(-)
diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index 80b8b89d98b..0e06fa5b2e0 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -8645,8 +8645,8 @@ fold_builtin_expect (location_t loc, tree arg0, tree arg1, tree arg2,
if (TREE_CODE (inner) == CALL_EXPR
&& (fndecl = get_callee_fndecl (inner))
- && (fndecl_built_in_p (fndecl, BUILT_IN_EXPECT)
- || fndecl_built_in_p (fndecl, BUILT_IN_EXPECT_WITH_PROBABILITY)))
+ && fndecl_built_in_p (fndecl, BUILT_IN_EXPECT,
+ BUILT_IN_EXPECT_WITH_PROBABILITY))
return arg0;
inner = inner_arg0;
diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index ec663d23385..e8f9bec8227 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -1548,8 +1548,8 @@ cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge *e)
else
{
if (flag_checking
- && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
- && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE_TRAP))
+ && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
+ BUILT_IN_UNREACHABLE_TRAP))
ipa_verify_edge_has_no_modifications (e);
new_stmt = e->call_stmt;
gimple_call_set_fndecl (new_stmt, e->callee->decl);
@@ -1635,9 +1635,8 @@ cgraph_update_edges_for_call_stmt_node (cgraph_node *node,
{
/* Keep calls marked as dead dead. */
if (new_stmt && is_gimple_call (new_stmt) && e->callee
- && (fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
- || fndecl_built_in_p (e->callee->decl,
- BUILT_IN_UNREACHABLE_TRAP)))
+ && fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
+ BUILT_IN_UNREACHABLE_TRAP))
{
cgraph_edge::set_call_stmt (node->get_edge (old_stmt),
as_a <gcall *> (new_stmt));
@@ -3259,9 +3258,8 @@ cgraph_edge::verify_corresponds_to_fndecl (tree decl)
/* Optimizers can redirect unreachable calls or calls triggering undefined
behavior to __builtin_unreachable or __builtin_unreachable trap. */
- if (fndecl_built_in_p (callee->decl, BUILT_IN_NORMAL)
- && (DECL_FUNCTION_CODE (callee->decl) == BUILT_IN_UNREACHABLE
- || DECL_FUNCTION_CODE (callee->decl) == BUILT_IN_UNREACHABLE_TRAP))
+ if (fndecl_built_in_p (callee->decl, BUILT_IN_UNREACHABLE,
+ BUILT_IN_UNREACHABLE_TRAP))
return false;
if (callee->former_clone_of != node->decl
@@ -3601,9 +3599,8 @@ cgraph_node::verify_node (void)
/* Optimized out calls are redirected to __builtin_unreachable. */
&& (e->count.nonzero_p ()
|| ! e->callee->decl
- || !(fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
- || fndecl_built_in_p (e->callee->decl,
- BUILT_IN_UNREACHABLE_TRAP)))
+ || !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
+ BUILT_IN_UNREACHABLE_TRAP))
&& count
== ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (decl))->count
&& (!e->count.ipa_p ()
diff --git a/gcc/cgraphclones.cc b/gcc/cgraphclones.cc
index 7c5d3b2842c..29d28ef895a 100644
--- a/gcc/cgraphclones.cc
+++ b/gcc/cgraphclones.cc
@@ -435,9 +435,8 @@ cgraph_node::create_clone (tree new_decl, profile_count prof_count,
version. The only exception is when the edge was proved to
be unreachable during the cloning procedure. */
if (!e->callee
- || !(fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
- || fndecl_built_in_p (e->callee->decl,
- BUILT_IN_UNREACHABLE_TRAP)))
+ || !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
+ BUILT_IN_UNREACHABLE_TRAP))
e->redirect_callee_duplicating_thunks (new_node);
}
new_node->expand_all_artificial_thunks ();
diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index 48e85e9cab5..33bc4a84a7e 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -1787,8 +1787,7 @@ matching_alloc_calls_p (tree alloc_decl, tree dealloc_decl)
/* Return false for deallocation functions that are known not
to match. */
- if (fndecl_built_in_p (dealloc_decl, BUILT_IN_FREE)
- || fndecl_built_in_p (dealloc_decl, BUILT_IN_REALLOC))
+ if (fndecl_built_in_p (dealloc_decl, BUILT_IN_FREE, BUILT_IN_REALLOC))
return false;
/* Otherwise proceed below to check the deallocation function's
"*dealloc" attributes to look for one that mentions this operator
@@ -1812,8 +1811,8 @@ matching_alloc_calls_p (tree alloc_decl, tree dealloc_decl)
if (DECL_IS_OPERATOR_DELETE_P (dealloc_decl))
return false;
- if (fndecl_built_in_p (dealloc_decl, BUILT_IN_FREE)
- || fndecl_built_in_p (dealloc_decl, BUILT_IN_REALLOC))
+ if (fndecl_built_in_p (dealloc_decl, BUILT_IN_FREE,
+ BUILT_IN_REALLOC))
return true;
alloc_dealloc_kind = alloc_kind_t::builtin;
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index ade6e335da7..5a8340504d0 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -15830,8 +15830,8 @@ goa_stabilize_expr (tree *expr_p, gimple_seq *pre_p, tree lhs_addr,
if (TREE_CODE (expr) == CALL_EXPR)
{
if (tree fndecl = get_callee_fndecl (expr))
- if (fndecl_built_in_p (fndecl, BUILT_IN_CLEAR_PADDING)
- || fndecl_built_in_p (fndecl, BUILT_IN_MEMCMP))
+ if (fndecl_built_in_p (fndecl, BUILT_IN_CLEAR_PADDING,
+ BUILT_IN_MEMCMP))
{
int nargs = call_expr_nargs (expr);
for (int i = 0; i < nargs; i++)
diff --git a/gcc/ipa-fnsummary.cc b/gcc/ipa-fnsummary.cc
index 63bd525b4c5..8217039b548 100644
--- a/gcc/ipa-fnsummary.cc
+++ b/gcc/ipa-fnsummary.cc
@@ -3180,8 +3180,8 @@ compute_fn_summary (struct cgraph_node *node, bool early)
for (e = node->callees; e; e = e->next_callee)
{
tree cdecl = e->callee->decl;
- if (fndecl_built_in_p (cdecl, BUILT_IN_APPLY_ARGS)
- || fndecl_built_in_p (cdecl, BUILT_IN_VA_START))
+ if (fndecl_built_in_p (cdecl, BUILT_IN_APPLY_ARGS,
+ BUILT_IN_VA_START))
break;
}
node->can_change_signature = !e;
diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index 0d816749534..c0143e90cd3 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -3865,8 +3865,8 @@ try_make_edge_direct_virtual_call (struct cgraph_edge *ie,
if (can_refer)
{
if (!t
- || fndecl_built_in_p (t, BUILT_IN_UNREACHABLE)
- || fndecl_built_in_p (t, BUILT_IN_UNREACHABLE_TRAP)
+ || fndecl_built_in_p (t, BUILT_IN_UNREACHABLE,
+ BUILT_IN_UNREACHABLE_TRAP)
|| !possible_polymorphic_call_target_p
(ie, cgraph_node::get (t)))
{
diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index 1818132830f..dddf5b59d8f 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -3992,8 +3992,7 @@ scan_omp_1_op (tree *tp, int *walk_subtrees, void *data)
static bool
setjmp_or_longjmp_p (const_tree fndecl)
{
- if (fndecl_built_in_p (fndecl, BUILT_IN_SETJMP)
- || fndecl_built_in_p (fndecl, BUILT_IN_LONGJMP))
+ if (fndecl_built_in_p (fndecl, BUILT_IN_SETJMP, BUILT_IN_LONGJMP))
return true;
tree declname = DECL_NAME (fndecl);
diff --git a/gcc/tree-stdarg.cc b/gcc/tree-stdarg.cc
index 37c3981316a..f522181248d 100644
--- a/gcc/tree-stdarg.cc
+++ b/gcc/tree-stdarg.cc
@@ -867,8 +867,8 @@ optimize_va_list_gpr_fpr_size (function *fun)
tree callee = gimple_call_fndecl (stmt);
if (callee
- && (fndecl_built_in_p (callee, BUILT_IN_VA_START)
- || fndecl_built_in_p (callee, BUILT_IN_VA_END)))
+ && fndecl_built_in_p (callee, BUILT_IN_VA_START,
+ BUILT_IN_VA_END))
continue;
}
diff --git a/gcc/tree.h b/gcc/tree.h
index abcdb5638d4..8e67e7078d1 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -6585,6 +6585,24 @@ type_has_mode_precision_p (const_tree t)
return known_eq (TYPE_PRECISION (t), GET_MODE_PRECISION (TYPE_MODE (t)));
}
+/* Helper functions for fndecl_built_in_p. */
+
+inline bool
+built_in_function_equal_p (built_in_function name0, built_in_function name1)
+{
+ return name0 == name1;
+}
+
+/* Recursive case for two or more names. */
+
+template <typename... F>
+inline bool
+built_in_function_equal_p (built_in_function name0, built_in_function name1,
+ built_in_function name2, F... names)
+{
+ return name0 == name1 || built_in_function_equal_p (name0, name2, names...);
+}
+
/* Return true if a FUNCTION_DECL NODE is a GCC built-in function.
Note that it is different from the DECL_IS_UNDECLARED_BUILTIN
@@ -6616,13 +6634,16 @@ fndecl_built_in_p (const_tree node, unsigned int name, built_in_class klass)
}
/* Return true if a FUNCTION_DECL NODE is a GCC built-in function
- of BUILT_IN_NORMAL class with name equal to NAME. */
+ of BUILT_IN_NORMAL class with name equal to NAME1 (or other mentioned
+ NAMES). */
+template <typename... F>
inline bool
-fndecl_built_in_p (const_tree node, built_in_function name)
+fndecl_built_in_p (const_tree node, built_in_function name1, F... names)
{
return (fndecl_built_in_p (node, BUILT_IN_NORMAL)
- && DECL_FUNCTION_CODE (node) == name);
+ && built_in_function_equal_p (DECL_FUNCTION_CODE (node),
+ name1, names...));
}
/* A struct for encapsulating location information about an operator
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-04-20 11:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-20 11:05 [gcc r14-109] tree: Add 3+ argument fndecl_built_in_p Jakub Jelinek
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).