From 9a7ecb49ebb3339e6d49ee0d08584b740710995e Mon Sep 17 00:00:00 2001 From: hubicka Date: Mon, 18 Nov 2002 19:30:34 +0000 Subject: * calls.c (alloca_call_p): New global function. * tree.h (alloca_call_p): New. * tree-inline.c (inlinable_function_p): Do not inline when function calls alloca. (find_alloca_call, find_alloca_call_1): New functions. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@59228 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/tree-inline.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 362ddd18b57..73ba48ae51c 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -122,6 +122,8 @@ static void copy_scope_stmt PARAMS ((tree *, int *, inline_data *)); static tree initialize_inlined_parameters PARAMS ((inline_data *, tree, tree, tree)); static void remap_block PARAMS ((tree *, tree, inline_data *)); static tree add_stmt_to_compound PARAMS ((tree, tree, tree)); +static tree find_alloca_call_1 PARAMS ((tree *, int *, void *)); +static tree find_alloca_call PARAMS ((tree)); #endif /* INLINER_FOR_JAVA */ /* The approximate number of instructions per statement. This number @@ -857,6 +859,27 @@ tree_inlinable_function_p (fn) return inlinable_function_p (fn, NULL); } +/* if *TP is possibly call to alloca, return nonzero. */ +static tree +find_alloca_call_1 (tp, walk_subtrees, data) + tree *tp; + int *walk_subtrees ATTRIBUTE_UNUSED; + void *data ATTRIBUTE_UNUSED; +{ + if (alloca_call_p (*tp)) + return *tp; + return NULL; +} + +/* Return subexpression representing possible alloca call, + if any. */ +static tree +find_alloca_call (exp) + tree exp; +{ + return walk_tree (&exp, find_alloca_call_1, NULL, NULL); +} + /* Returns nonzero if FN is a function that can be inlined into the inlining context ID_. If ID_ is NULL, check whether the function can be inlined at all. */ @@ -897,6 +920,13 @@ inlinable_function_p (fn, id) else if (! (*lang_hooks.tree_inlining.disregard_inline_limits) (fn) && currfn_insns > MAX_INLINE_INSNS_SINGLE) ; + /* Refuse to inline alloca call unless user explicitly forced so as this may + change program's memory overhead drastically when the function using alloca + is called in loop. In GCC present in SPEC2000 inlining into schedule_block + cause it to require 2GB of ram instead of 256MB. */ + else if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)) == NULL + && find_alloca_call (DECL_SAVED_TREE (fn))) + ; /* All is well. We can inline this function. Traditionally, GCC has refused to inline functions using alloca, or functions whose values are returned in a PARALLEL, and a few other such obscure -- cgit v1.2.1