From 159e8ef0c6673f73ab33ba86dd13652dfdae342c Mon Sep 17 00:00:00 2001 From: Bernd Edlinger Date: Thu, 21 Jul 2016 19:06:02 +0000 Subject: [PATCH] 016-07-21 Bernd Edlinger PR middle-end/71876 * calls.c (gimple_maybe_alloca_call_p): New function. Return true if STMT may be an alloca call. (gimple_alloca_call_p, alloca_call_p): Return only true for the builtin alloca call. * calls.h (gimple_maybe_alloca_call_p): New function. * tree-inline.c (inline_forbidden_p_stmt): Use gimple_maybe_alloca_call_p here. From-SVN: r238605 --- gcc/ChangeLog | 11 +++++++++++ gcc/calls.c | 42 +++++++++++++++++++++++++++++++++++++----- gcc/calls.h | 1 + gcc/tree-inline.c | 2 +- 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f559e29dc23..b5b24a03127 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2016-07-21 Bernd Edlinger + + PR middle-end/71876 + * calls.c (gimple_maybe_alloca_call_p): New function. Return true + if STMT may be an alloca call. + (gimple_alloca_call_p, alloca_call_p): Return only true for the + builtin alloca call. + * calls.h (gimple_maybe_alloca_call_p): New function. + * tree-inline.c (inline_forbidden_p_stmt): Use + gimple_maybe_alloca_call_p here. + 2016-07-21 David Malcolm * spellcheck-tree.c (best_macro_match::best_macro_match): diff --git a/gcc/calls.c b/gcc/calls.c index 587969fcf01..bb954ef5b09 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -617,10 +617,10 @@ setjmp_call_p (const_tree fndecl) } -/* Return true if STMT is an alloca call. */ +/* Return true if STMT may be an alloca call. */ bool -gimple_alloca_call_p (const gimple *stmt) +gimple_maybe_alloca_call_p (const gimple *stmt) { tree fndecl; @@ -634,7 +634,31 @@ gimple_alloca_call_p (const gimple *stmt) return false; } -/* Return true when exp contains alloca call. */ +/* Return true if STMT is a builtin alloca call. */ + +bool +gimple_alloca_call_p (const gimple *stmt) +{ + tree fndecl; + + if (!is_gimple_call (stmt)) + return false; + + fndecl = gimple_call_fndecl (stmt); + if (fndecl && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL) + switch (DECL_FUNCTION_CODE (fndecl)) + { + case BUILT_IN_ALLOCA: + case BUILT_IN_ALLOCA_WITH_ALIGN: + return true; + default: + break; + } + + return false; +} + +/* Return true when exp contains a builtin alloca call. */ bool alloca_call_p (const_tree exp) @@ -642,8 +666,16 @@ alloca_call_p (const_tree exp) tree fndecl; if (TREE_CODE (exp) == CALL_EXPR && (fndecl = get_callee_fndecl (exp)) - && (special_function_p (fndecl, 0) & ECF_MAY_BE_ALLOCA)) - return true; + && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL) + switch (DECL_FUNCTION_CODE (fndecl)) + { + case BUILT_IN_ALLOCA: + case BUILT_IN_ALLOCA_WITH_ALIGN: + return true; + default: + break; + } + return false; } diff --git a/gcc/calls.h b/gcc/calls.h index c6cca5d7d81..e14415646ca 100644 --- a/gcc/calls.h +++ b/gcc/calls.h @@ -23,6 +23,7 @@ along with GCC; see the file COPYING3. If not see extern int flags_from_decl_or_type (const_tree); extern int call_expr_flags (const_tree); extern int setjmp_call_p (const_tree); +extern bool gimple_maybe_alloca_call_p (const gimple *); extern bool gimple_alloca_call_p (const gimple *); extern bool alloca_call_p (const_tree); extern bool must_pass_in_stack_var_size (machine_mode, const_tree); diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index ef588662ace..f2b44915a3e 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -3577,7 +3577,7 @@ inline_forbidden_p_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p, RAM instead of 256MB. Don't do so for alloca calls emitted for VLA objects as those can't cause unbounded growth (they're always wrapped inside stack_save/stack_restore regions. */ - if (gimple_alloca_call_p (stmt) + if (gimple_maybe_alloca_call_p (stmt) && !gimple_call_alloca_for_var_p (as_a (stmt)) && !lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn))) {