summaryrefslogtreecommitdiff
path: root/gcc/tree-inline.c
diff options
context:
space:
mode:
authorsteven <steven@138bc75d-0d04-0410-961f-82ee72b054a4>2003-08-05 14:11:53 +0000
committersteven <steven@138bc75d-0d04-0410-961f-82ee72b054a4>2003-08-05 14:11:53 +0000
commit746149b7c6ddc67bd15a841ee6e8e50b97945035 (patch)
treef99d1c794a4de2c3fc4751de63ab48b0674a8860 /gcc/tree-inline.c
parentda94567d9ef0be7d5a6dcbf648804da1b5316f73 (diff)
downloadgcc-746149b7c6ddc67bd15a841ee6e8e50b97945035.tar.gz
2003-08-05 Steven Bosscher <steven@gcc.gnu.org>
* tree.h (DID_INLINE_FUNC): Remove macro. (DECL_DECLARED_INLINE_P): Move from c-tree.h and cp/cp-tree.h, add tree check for FUNCTION_DECL. (DECL_ESTIMATED_INSNS): Move from c-common.h and java/java-tree.h. (struct tree_decl): Rename inlined_function_flag to declared_inline_flag. * c-common.h (c_lang_decl): Remove. (DECL_ESTIMATED_INSNS): Remove. * c-tree.h (struct lang_decl): Don't include c_lang_decl. (DECL_DECLARED_INLINE_P): Remove. * c-decl.c (grokdeclarator): Update comment. With -finline-functions, do not reset DECL_DECLARED_INLINE_P. Don't use DID_INLINE_FUNC. (finish_function): Make uninlinable a bool. Fixup call to tree_inlinable_function_p() and fix some code style issues. * cgraph.h (disgread_inline_limits): Fix spelling: `disregard'. * cgraph.c (dump_cgraph): Likewise. * cgraphunit.c (cgraph_decide_inlining): Likewise (cgraph_finalize_compilation_unit): Likewise. Also update call to tree_inlinable_function_p(). (cgraph_default_inline_p): Don't use DID_INLINE_FUNC. Instead look at DECL_DECLARED_INLINE and reverse logic. * print-tree.c (print_node): Likewise. * toplev.c (rest_of_handle_inlining): Don't use DID_INLINE_FUNC. * tree-inline.h (tree_inlinable_function_p): Make a bool. Update prototype. * tree-inline.c (inlinable_function_p): Split up in this function to check for basic inlining inhibiting conditions, and new limits_allow_inlining() function. Warn if inlining is impossible because the inline candidate calls alloca or uses sjlj exceptions. (limits_allow_inlining): this new function to check if the inlining limits are satisfied. Throttle from currfn_max_inline_insns, not from MAX_INLINE_INSNS_SINGLE. The latter only makes sense if MAX_INLINE_INSNS_AUTO and MAX_INLINE_INSNS_SINGLE are equal. Update prototypes. (tree_inlinable_function_p): Make a bool. Update call to inlinable_function_p (expand_call_inline): Use limits_allow_inlining() when not in unit-at-a-time mode to decide on inlining. Don't use DID_INLINE_FUNC, instead see if the function was declared `inline'. cp/ * cp-tree.h (struct lang_decl): Don't include c_lang_decl. (DECL_DECLARED_INLINE_P): Remove. * decl2.c (import_export_decl): Only look at DECL_DECLARED_INLINE_P if decl is a FUNCTION_DECL. This never made sense, but now it is required to avoid a tree check failure. * decl.c (grokfndecl): Don't touch DID_INLINE_FUNC. * optimize.c (maybe_clone_body): Likewise. java/ * java-tree.h (DECL_ESTIMATED_INSNS): Remove. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@70174 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree-inline.c')
-rw-r--r--gcc/tree-inline.c258
1 files changed, 159 insertions, 99 deletions
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index dbf2543b093..07664bdb69b 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -116,7 +116,8 @@ static tree copy_body_r (tree *, int *, void *);
static tree copy_body (inline_data *);
static tree expand_call_inline (tree *, int *, void *);
static void expand_calls_inline (tree *, inline_data *);
-static int inlinable_function_p (tree, inline_data *, int);
+static bool inlinable_function_p (tree);
+static int limits_allow_inlining (tree, inline_data *);
static tree remap_decl (tree, inline_data *);
#ifndef INLINER_FOR_JAVA
static tree initialize_inlined_parameters (inline_data *, tree, tree);
@@ -873,10 +874,10 @@ declare_return_variable (struct inline_data *id, tree return_slot_addr,
/* Returns nonzero if a function can be inlined as a tree. */
-int
-tree_inlinable_function_p (tree fn, int nolimit)
+bool
+tree_inlinable_function_p (tree fn)
{
- return inlinable_function_p (fn, NULL, nolimit);
+ return inlinable_function_p (fn);
}
/* If *TP is possibly call to alloca, return nonzero. */
@@ -927,67 +928,58 @@ find_builtin_longjmp_call (tree exp)
return ret;
}
-/* 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. */
+/* Returns nonzero if FN is a function that does not have any
+ fundamental inline blocking properties. */
-static int
-inlinable_function_p (tree fn, inline_data *id, int nolimit)
+static bool
+inlinable_function_p (tree fn)
{
- int inlinable;
- int currfn_insns = 0;
- int max_inline_insns_single = MAX_INLINE_INSNS_SINGLE;
+ bool inlinable = true;
+ bool calls_builtin_longjmp = false;
+ bool calls_alloca = false;
/* If we've already decided this function shouldn't be inlined,
there's no need to check again. */
if (DECL_UNINLINABLE (fn))
- return 0;
+ return false;
/* See if there is any language-specific reason it cannot be
inlined. (It is important that this hook be called early because
- in C++ it may result in template instantiation.) */
+ in C++ it may result in template instantiation.)
+ If the function is not inlinable for language-specific reasons,
+ it is left up to the langhook to explain why. */
inlinable = !(*lang_hooks.tree_inlining.cannot_inline_tree_fn) (&fn);
- /* If we don't have the function body available, we can't inline
- it. */
- if (! DECL_SAVED_TREE (fn))
- return 0;
-
- /* We may be here either because fn is declared inline or because
- we use -finline-functions. For the second case, we are more
- restrictive. */
- if (DID_INLINE_FUNC (fn))
- max_inline_insns_single = MAX_INLINE_INSNS_AUTO;
+ /* If we don't have the function body available, we can't inline it.
+ However, this should not be recorded since we also get here for
+ forward declared inline functions. Therefore, return at once. */
+ if (!DECL_SAVED_TREE (fn))
+ return false;
+
+ /* If we're not inlining at all, then we cannot inline this function. */
+ else if (!flag_inline_trees)
+ inlinable = false;
+
+ /* Only try to inline functions if DECL_INLINE is set. This should be
+ true for all functions declared `inline', and for all other functions
+ as well with -finline-functions.
+
+ Don't think of disregarding DECL_INLINE when flag_inline_trees == 2;
+ it's the front-end that must set DECL_INLINE in this case, because
+ dwarf2out loses if a function that does not have DECL_INLINE set is
+ inlined anyway. That is why we have both DECL_INLINE and
+ DECL_DECLARED_INLINE_P. */
+ /* FIXME: When flag_inline_trees dies, the check for flag_unit_at_a_time
+ here should be redundant. */
+ else if (!DECL_INLINE (fn) && !flag_unit_at_a_time)
+ inlinable = false;
- /* The number of instructions (estimated) of current function. */
- if (!nolimit && !DECL_ESTIMATED_INSNS (fn))
- DECL_ESTIMATED_INSNS (fn)
- = (*lang_hooks.tree_inlining.estimate_num_insns) (fn);
- currfn_insns = DECL_ESTIMATED_INSNS (fn);
-
- /* If we're not inlining things, then nothing is inlinable. */
- if (! flag_inline_trees)
- inlinable = 0;
- /* If we're not inlining all functions and the function was not
- declared `inline', we don't inline it. Don't think of
- disregarding DECL_INLINE when flag_inline_trees == 2; it's the
- front-end that must set DECL_INLINE in this case, because
- dwarf2out loses if a function is inlined that doesn't have
- DECL_INLINE set. */
- else if (! DECL_INLINE (fn) && !nolimit)
- inlinable = 0;
#ifdef INLINER_FOR_JAVA
/* Synchronized methods can't be inlined. This is a bug. */
else if (METHOD_SYNCHRONIZED (fn))
- inlinable = 0;
+ inlinable = false;
#endif /* INLINER_FOR_JAVA */
- /* We can't inline functions that are too big. Only allow a single
- function to be of MAX_INLINE_INSNS_SINGLE size. Make special
- allowance for extern inline functions, though. */
- else if (!nolimit
- && ! (*lang_hooks.tree_inlining.disregard_inline_limits) (fn)
- && currfn_insns > max_inline_insns_single)
- inlinable = 0;
+
/* We can't inline functions that call __builtin_longjmp at all.
The non-local goto machinery really requires the destination
be in a different function. If we allow the function calling
@@ -995,70 +987,138 @@ inlinable_function_p (tree fn, inline_data *id, int nolimit)
__builtin_setjmp, Things will Go Awry. */
/* ??? Need front end help to identify "regular" non-local goto. */
else if (find_builtin_longjmp_call (DECL_SAVED_TREE (fn)))
- inlinable = 0;
- /* 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. */
+ calls_builtin_longjmp = true;
+
+ /* 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)))
- inlinable = 0;
+ calls_alloca = true;
+
+ if (calls_builtin_longjmp || calls_alloca)
+ {
+ /* See if we should warn about uninlinable functions. Previously,
+ some of these warnings would be issued while trying to expand
+ the function inline, but that would cause multiple warnings
+ about functions that would for example call alloca. But since
+ this a property of the function, just one warning is enough.
+ As a bonus we can now give more details about the reason why a
+ function is not inlinable.
+ We only warn for functions declared `inline' by the user. */
+ bool do_warning = (warn_inline
+ && DECL_INLINE (fn)
+ && DECL_DECLARED_INLINE_P (fn)
+ && !DECL_IN_SYSTEM_HEADER (fn));
+
+ if (do_warning && calls_builtin_longjmp)
+ warning ("%Hfunction '%F' can never be inlined because it uses "
+ "setjmp-longjmp exception handling",
+ &DECL_SOURCE_LOCATION (fn), fn);
+ if (do_warning && calls_alloca)
+ warning ("%Hfunction '%F' can never be inlined because it uses "
+ "setjmp-longjmp exception handling",
+ &DECL_SOURCE_LOCATION (fn), fn);
+
+ inlinable = false;
+ }
/* Squirrel away the result so that we don't have to check again. */
- DECL_UNINLINABLE (fn) = ! inlinable;
+ DECL_UNINLINABLE (fn) = !inlinable;
+
+ return inlinable;
+}
+
+/* We can't inline functions that are too big. Only allow a single
+ function to be of MAX_INLINE_INSNS_SINGLE size. Make special
+ allowance for extern inline functions, though.
- /* In case we don't disregard the inlining limits and we basically
- can inline this function, investigate further. */
- if (! (*lang_hooks.tree_inlining.disregard_inline_limits) (fn)
- && inlinable && !nolimit
- && currfn_insns > MIN_INLINE_INSNS)
+ Return nonzero if the function FN can be inlined into the inlining
+ context ID. */
+
+static int
+limits_allow_inlining (tree fn, inline_data *id)
+{
+ int estimated_insns = 0;
+ size_t i;
+
+ /* Don't even bother if the function is not inlinable. */
+ if (!inlinable_function_p (fn))
+ return 0;
+
+ /* Investigate the size of the function. Return at once
+ if the function body size is too large. */
+ if (!(*lang_hooks.tree_inlining.disregard_inline_limits) (fn))
{
- int sum_insns = (id ? id->inlined_insns : 0) + currfn_insns;
- /* In the extreme case that we have exceeded the recursive inlining
- limit by a huge factor (128), we just say no. Should not happen
- in real life. */
- if (sum_insns > MAX_INLINE_INSNS * 128)
- inlinable = 0;
- /* If we did not hit the extreme limit, we use a linear function
- with slope -1/MAX_INLINE_SLOPE to exceedingly decrease the
- allowable size. We always allow a size of MIN_INLINE_INSNS
- though. */
- else if (sum_insns > MAX_INLINE_INSNS)
+ int currfn_max_inline_insns;
+
+ /* If we haven't already done so, get an estimate of the number of
+ instructions that will be produces when expanding this function. */
+ if (!DECL_ESTIMATED_INSNS (fn))
+ DECL_ESTIMATED_INSNS (fn)
+ = (*lang_hooks.tree_inlining.estimate_num_insns) (fn);
+ estimated_insns = DECL_ESTIMATED_INSNS (fn);
+
+ /* We may be here either because fn is declared inline or because
+ we use -finline-functions. For the second case, we are more
+ restrictive.
+
+ FIXME: -finline-functions should imply -funit-at-a-time, it's
+ about equally expensive but unit-at-a-time produces
+ better code. */
+ currfn_max_inline_insns = DECL_DECLARED_INLINE_P (fn) ?
+ MAX_INLINE_INSNS_SINGLE : MAX_INLINE_INSNS_AUTO;
+
+ /* If the function is too big to be inlined, adieu. */
+ if (estimated_insns > currfn_max_inline_insns)
+ return 0;
+
+ /* We now know that we don't disregard the inlining limits and that
+ we basically should be able to inline this function.
+ We always allow inlining functions if we estimate that they are
+ smaller than MIN_INLINE_INSNS. Otherwise, investigate further. */
+ if (estimated_insns > MIN_INLINE_INSNS)
{
- int max_curr = MAX_INLINE_INSNS_SINGLE
- - (sum_insns - MAX_INLINE_INSNS) / MAX_INLINE_SLOPE;
- if (currfn_insns > max_curr)
- inlinable = 0;
+ int sum_insns = (id ? id->inlined_insns : 0) + estimated_insns;
+
+ /* In the extreme case that we have exceeded the recursive inlining
+ limit by a huge factor (128), we just say no.
+
+ FIXME: Should not happen in real life, but people have reported
+ that it actually does!? */
+ if (sum_insns > MAX_INLINE_INSNS * 128)
+ return 0;
+
+ /* If we did not hit the extreme limit, we use a linear function
+ with slope -1/MAX_INLINE_SLOPE to exceedingly decrease the
+ allowable size. */
+ else if (sum_insns > MAX_INLINE_INSNS)
+ {
+ if (estimated_insns > currfn_max_inline_insns
+ - (sum_insns - MAX_INLINE_INSNS) / MAX_INLINE_SLOPE)
+ return 0;
+ }
}
}
- /* Check again, language hooks may have modified it. */
- if (! inlinable || DECL_UNINLINABLE (fn))
- return 0;
+ /* Don't allow recursive inlining. */
+ for (i = 0; i < VARRAY_ACTIVE_SIZE (id->fns); ++i)
+ if (VARRAY_TREE (id->fns, i) == fn)
+ return 0;
- /* Don't do recursive inlining, either. We don't record this in
- DECL_UNINLINABLE; we may be able to inline this function later. */
- if (id)
+ if (DECL_INLINED_FNS (fn))
{
- size_t i;
+ int j;
+ tree inlined_fns = DECL_INLINED_FNS (fn);
- for (i = 0; i < VARRAY_ACTIVE_SIZE (id->fns); ++i)
- if (VARRAY_TREE (id->fns, i) == fn)
+ for (j = 0; j < TREE_VEC_LENGTH (inlined_fns); ++j)
+ if (TREE_VEC_ELT (inlined_fns, j) == VARRAY_TREE (id->fns, 0))
return 0;
-
- if (DECL_INLINED_FNS (fn))
- {
- int j;
- tree inlined_fns = DECL_INLINED_FNS (fn);
-
- for (j = 0; j < TREE_VEC_LENGTH (inlined_fns); ++j)
- if (TREE_VEC_ELT (inlined_fns, j) == VARRAY_TREE (id->fns, 0))
- return 0;
- }
}
- /* Return the result. */
- return inlinable;
+ /* Go ahead, this function can be inlined. */
+ return 1;
}
/* If *TP is a CALL_EXPR, replace it with its inline expansion. */
@@ -1166,9 +1226,9 @@ expand_call_inline (tree *tp, int *walk_subtrees, void *data)
inlining. */
if ((flag_unit_at_a_time
&& (!DECL_SAVED_TREE (fn) || !cgraph_inline_p (id->current_decl, fn)))
- || (!flag_unit_at_a_time && !inlinable_function_p (fn, id, 0)))
+ || (!flag_unit_at_a_time && !limits_allow_inlining (fn, id)))
{
- if (warn_inline && DECL_INLINE (fn) && !DID_INLINE_FUNC (fn)
+ if (warn_inline && DECL_INLINE (fn) && DECL_DECLARED_INLINE_P (fn)
&& !DECL_IN_SYSTEM_HEADER (fn))
{
warning ("%Hinlining failed in call to '%F'",