This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Some cleanups for the tree inliner.
- From: Steven Bosscher <s dot bosscher at student dot tudelft dot nl>
- To: gcc-patches at gcc dot gnu dot org
- Date: 31 Jul 2003 19:38:43 +0200
- Subject: Some cleanups for the tree inliner.
Hi,
This is an attempt to cleanup the tree inliner a bit, and to get more
useful warnings out of -Winline.
The first things it does, is move around some macros. DID_INLINE_FUNC
was used to mark functions that were inlinable because of
-finline-functions. So DID_INLINE_FUNC(fn) should be equivalent to
!DECL_DECLARED_INLINE (fn). The latter was defined in cp-tree.h and
c-tree.h and used an extra bit in an extra struct c_lang_decl. Cleaned
up by moving DECL_DECLARED_INLINE to tree.h.
DECL_ESTIMATED_INSNS came in with Jan's new function body size
estimates. On the tree-ssa branch, this macro is in tree.h, but on
mainline it was in c-common.h and java-tree.h, this patch changes that.
Finally, the nolimit argument to inlinable_function_p() was annoying.
This patch splits up this function in two: inlinable_function_p() which
checks if there are any show-stoppers for inlining in the function body,
and limits_allow_inlining() to control function growth.
This patch modifies the behavior of the compiler in two different ways:
- It adds warnings to tell the user that functions calling alloca
or __builtin_longjmp (ie. using sjlj exceptions) cannot be inlined.
This means that the user now first gets a warning about this, and
then another warning for each place where inlining failed.
- It fixes the throttle to take into account the difference between
MAX_INLINE_INSNS_SINGLE and MAX_INLINE_INSNS_AUTO. This is a bug
in the current inliner that allows auto-inlining functions larger
than MAX_INLINE_INSNS_AUTO when throttling.
Bootstrapped c,objc,c++,java on i686-pc-linux-gnu with tree-checking
enabled (I already bumped into a C++ bug, now that DECL_DECLARED_INLINE
is now with a tree check). Testing in progress. OK if it passes?
Gr.
Steven
2003-07-31 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.
Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.197
diff -c -3 -p -r1.197 c-common.h
*** c-common.h 30 Jul 2003 17:27:04 -0000 1.197
--- c-common.h 31 Jul 2003 15:30:21 -0000
*************** extern void shadow_warning (enum sw_kind
*** 347,368 ****
extern int field_decl_cmp (const void *, const void *);
extern void resort_sorted_fields (void *, void *, gt_pointer_operator,
void *);
-
- /* Extra information associated with a DECL. Other C dialects extend
- this structure in various ways. The C front-end only uses this
- structure for FUNCTION_DECLs; all other DECLs have a NULL
- DECL_LANG_SPECIFIC field. */
-
- struct c_lang_decl GTY(()) {
- unsigned declared_inline : 1;
- };
-
- /* In a FUNCTION_DECL for which DECL_BUILT_IN does not hold, this is
- the approximate number of statements in this function. There is
- no need for this number to be exact; it is only used in various
- heuristics regarding optimization. */
- #define DECL_ESTIMATED_INSNS(NODE) \
- (FUNCTION_DECL_CHECK (NODE)->decl.u1.i)
/* Switches common to the C front ends. */
--- 347,352 ----
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.424
diff -c -3 -p -r1.424 c-decl.c
*** c-decl.c 29 Jul 2003 23:58:07 -0000 1.424
--- c-decl.c 31 Jul 2003 15:30:34 -0000
*************** grokdeclarator (tree declarator, tree de
*** 4366,4372 ****
}
else if (inlinep)
{
! /* Assume that otherwise the function can be inlined. */
DECL_DECLARED_INLINE_P (decl) = 1;
/* Do not mark bare declarations as DECL_INLINE. Doing so
--- 4366,4372 ----
}
else if (inlinep)
{
! /* Record that the function is declared `inline'. */
DECL_DECLARED_INLINE_P (decl) = 1;
/* Do not mark bare declarations as DECL_INLINE. Doing so
*************** grokdeclarator (tree declarator, tree de
*** 4384,4395 ****
two things: let the function be deferred until it is actually
needed, and let dwarf2 know that the function is inlinable. */
else if (flag_inline_trees == 2 && initialized)
! {
! if (!DECL_INLINE (decl))
! DID_INLINE_FUNC (decl) = 1;
! DECL_INLINE (decl) = 1;
! DECL_DECLARED_INLINE_P (decl) = 0;
! }
}
else
{
--- 4384,4390 ----
two things: let the function be deferred until it is actually
needed, and let dwarf2 know that the function is inlinable. */
else if (flag_inline_trees == 2 && initialized)
! DECL_INLINE (decl) = 1;
}
else
{
*************** finish_function (int nested, int can_def
*** 6202,6208 ****
/* Function is parsed.
Generate RTL for the body of this function or defer
it for later expansion. */
! int uninlinable = 1;
/* There's no reason to do any of the work here if we're only doing
semantic analysis; this code just generates RTL. */
--- 6197,6203 ----
/* Function is parsed.
Generate RTL for the body of this function or defer
it for later expansion. */
! bool uninlinable = true;
/* There's no reason to do any of the work here if we're only doing
semantic analysis; this code just generates RTL. */
*************** finish_function (int nested, int can_def
*** 6219,6232 ****
predicates depend on cfun and current_function_decl to
function completely. */
timevar_push (TV_INTEGRATION);
! uninlinable = ! tree_inlinable_function_p (fndecl, 0);
if (can_defer_p
/* We defer functions marked inline *even if* the function
itself is not inlinable. This is because we don't yet
know if the function will actually be used; we may be
able to avoid emitting it entirely. */
! && (! uninlinable || DECL_DECLARED_INLINE_P (fndecl))
/* Save function tree for inlining. Should return 0 if the
language does not support function deferring or the
function could not be deferred. */
--- 6214,6227 ----
predicates depend on cfun and current_function_decl to
function completely. */
timevar_push (TV_INTEGRATION);
! uninlinable = !tree_inlinable_function_p (fndecl);
if (can_defer_p
/* We defer functions marked inline *even if* the function
itself is not inlinable. This is because we don't yet
know if the function will actually be used; we may be
able to avoid emitting it entirely. */
! && (!uninlinable || DECL_DECLARED_INLINE_P (fndecl))
/* Save function tree for inlining. Should return 0 if the
language does not support function deferring or the
function could not be deferred. */
Index: c-objc-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-objc-common.c,v
retrieving revision 1.30
Index: c-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-tree.h,v
retrieving revision 1.126
diff -c -3 -p -r1.126 c-tree.h
*** c-tree.h 29 Jul 2003 23:58:07 -0000 1.126
--- c-tree.h 31 Jul 2003 15:30:38 -0000
*************** union lang_tree_node
*** 58,64 ****
struct lang_decl GTY(())
{
- struct c_lang_decl base;
/* The return types and parameter types may have variable size.
This is a list of any SAVE_EXPRs that need to be evaluated to
compute those sizes. */
--- 58,63 ----
*************** struct lang_decl GTY(())
*** 99,110 ****
keyword. C_RID_CODE (node) is then the RID_* value of the keyword,
and C_RID_YYCODE is the token number wanted by Yacc. */
#define C_IS_RESERVED_WORD(ID) TREE_LANG_FLAG_0 (ID)
-
- /* This function was declared inline. This flag controls the linkage
- semantics of 'inline'; whether or not the function is inlined is
- controlled by DECL_INLINE. */
- #define DECL_DECLARED_INLINE_P(NODE) \
- (DECL_LANG_SPECIFIC (NODE)->base.declared_inline)
/* In a RECORD_TYPE, a sorted array of the fields of the type. */
struct lang_type GTY(())
--- 98,103 ----
Index: cgraph.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cgraph.c,v
retrieving revision 1.21
diff -c -3 -p -r1.21 cgraph.c
*** cgraph.c 18 Jul 2003 15:13:35 -0000 1.21
--- cgraph.c 31 Jul 2003 15:30:38 -0000
*************** dump_cgraph (FILE *f)
*** 353,359 ****
if (DECL_SAVED_TREE (node->decl))
fprintf (f, " tree");
! if (node->local.disgread_inline_limits)
fprintf (f, " always_inline");
else if (node->local.inlinable)
fprintf (f, " inlinable");
--- 353,359 ----
if (DECL_SAVED_TREE (node->decl))
fprintf (f, " tree");
! if (node->local.disregard_inline_limits)
fprintf (f, " always_inline");
else if (node->local.inlinable)
fprintf (f, " inlinable");
Index: cgraph.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cgraph.h,v
retrieving revision 1.14
diff -c -3 -p -r1.14 cgraph.h
*** cgraph.h 12 Jul 2003 11:29:18 -0000 1.14
--- cgraph.h 31 Jul 2003 15:30:38 -0000
*************** struct cgraph_local_info GTY(())
*** 33,42 ****
/* Set once it has been finalized so we consider it to be output. */
bool finalized;
! /* False when there is something making inlining impossible (such as va_arg) */
bool inlinable;
/* True when function should be inlined independently on it's size. */
! bool disgread_inline_limits;
/* Size of the function before inlining. */
int self_insns;
};
--- 33,42 ----
/* Set once it has been finalized so we consider it to be output. */
bool finalized;
! /* False when there something makes inlining impossible (such as va_arg). */
bool inlinable;
/* True when function should be inlined independently on it's size. */
! bool disregard_inline_limits;
/* Size of the function before inlining. */
int self_insns;
};
Index: cgraphunit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cgraphunit.c,v
retrieving revision 1.17
diff -c -3 -p -r1.17 cgraphunit.c
*** cgraphunit.c 21 Jul 2003 22:46:47 -0000 1.17
--- cgraphunit.c 31 Jul 2003 15:30:40 -0000
*************** cgraph_finalize_compilation_unit (void)
*** 189,200 ****
/* First kill forward declaration so reverse inlining works properly. */
cgraph_create_edges (decl, DECL_SAVED_TREE (decl));
! node->local.inlinable = tree_inlinable_function_p (decl, 1);
DECL_ESTIMATED_INSNS (decl)
= (*lang_hooks.tree_inlining.estimate_num_insns) (decl);
node->local.self_insns = DECL_ESTIMATED_INSNS (decl);
if (node->local.inlinable)
! node->local.disgread_inline_limits
= (*lang_hooks.tree_inlining.disregard_inline_limits) (decl);
for (edge = node->callees; edge; edge = edge->next_callee)
--- 189,200 ----
/* First kill forward declaration so reverse inlining works properly. */
cgraph_create_edges (decl, DECL_SAVED_TREE (decl));
! node->local.inlinable = tree_inlinable_function_p (decl);
DECL_ESTIMATED_INSNS (decl)
= (*lang_hooks.tree_inlining.estimate_num_insns) (decl);
node->local.self_insns = DECL_ESTIMATED_INSNS (decl);
if (node->local.inlinable)
! node->local.disregard_inline_limits
= (*lang_hooks.tree_inlining.disregard_inline_limits) (decl);
for (edge = node->callees; edge; edge = edge->next_callee)
*************** cgraph_default_inline_p (struct cgraph_n
*** 735,744 ****
{
if (!DECL_INLINE (n->decl) || !DECL_SAVED_TREE (n->decl))
return false;
! if (DID_INLINE_FUNC (n->decl))
! return n->global.insns < MAX_INLINE_INSNS_AUTO;
! else
return n->global.insns < MAX_INLINE_INSNS_SINGLE;
}
/* We use greedy algorithm for inlining of small functions:
--- 735,744 ----
{
if (!DECL_INLINE (n->decl) || !DECL_SAVED_TREE (n->decl))
return false;
! if (DECL_DECLARED_INLINE_P (n->decl))
return n->global.insns < MAX_INLINE_INSNS_SINGLE;
+ else
+ return n->global.insns < MAX_INLINE_INSNS_AUTO;
}
/* We use greedy algorithm for inlining of small functions:
*************** cgraph_decide_inlining (void)
*** 917,923 ****
node = order[i];
for (e = node->callees; e; e = e->next_callee)
! if (e->callee->local.disgread_inline_limits)
break;
if (!e)
continue;
--- 917,923 ----
node = order[i];
for (e = node->callees; e; e = e->next_callee)
! if (e->callee->local.disregard_inline_limits)
break;
if (!e)
continue;
*************** cgraph_decide_inlining (void)
*** 928,934 ****
ninlined = cgraph_inlined_into (order[i], inlined);
for (; e; e = e->next_callee)
{
! if (e->inline_call || !e->callee->local.disgread_inline_limits)
continue;
if (e->callee->output || e->callee == node)
continue;
--- 928,934 ----
ninlined = cgraph_inlined_into (order[i], inlined);
for (; e; e = e->next_callee)
{
! if (e->inline_call || !e->callee->local.disregard_inline_limits)
continue;
if (e->callee->output || e->callee == node)
continue;
Index: print-tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/print-tree.c,v
retrieving revision 1.76
diff -c -3 -p -r1.76 print-tree.c
*** print-tree.c 19 Jul 2003 14:47:07 -0000 1.76
--- print-tree.c 31 Jul 2003 15:30:42 -0000
*************** print_node (FILE *file, const char *pref
*** 317,326 ****
if (TREE_CODE (node) == TYPE_DECL && TYPE_DECL_SUPPRESS_DEBUG (node))
fputs (" suppress-debug", file);
! if (TREE_CODE (node) == FUNCTION_DECL && DID_INLINE_FUNC (node))
! fputs (" autoinline", file);
! else if (TREE_CODE (node) == FUNCTION_DECL && DECL_INLINE (node))
! fputs (" inline", file);
if (TREE_CODE (node) == FUNCTION_DECL && DECL_BUILT_IN (node))
fputs (" built-in", file);
if (TREE_CODE (node) == FUNCTION_DECL && DECL_NO_STATIC_CHAIN (node))
--- 317,324 ----
if (TREE_CODE (node) == TYPE_DECL && TYPE_DECL_SUPPRESS_DEBUG (node))
fputs (" suppress-debug", file);
! if (TREE_CODE (node) == FUNCTION_DECL && DECL_INLINE (node))
! fputs (DECL_DECLARED_INLINE_P (node) ? " inline" : " autoinline", file);
if (TREE_CODE (node) == FUNCTION_DECL && DECL_BUILT_IN (node))
fputs (" built-in", file);
if (TREE_CODE (node) == FUNCTION_DECL && DECL_NO_STATIC_CHAIN (node))
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.c,v
retrieving revision 1.814
diff -c -3 -p -r1.814 toplev.c
*** toplev.c 25 Jul 2003 09:52:26 -0000 1.814
--- toplev.c 31 Jul 2003 17:15:18 -0000
*************** rest_of_handle_inlining (tree decl)
*** 2532,2547 ****
return true;
}
}
! else {
! /* ??? Note that we used to just make it look like if
! the "inline" keyword was specified when we decide
! to inline it (because of -finline-functions).
! garloff@suse.de, 2002-04-24: Add another flag to
! actually record this piece of information. */
! if (!DECL_INLINE (decl))
! DID_INLINE_FUNC (decl) = 1;
inlinable = DECL_INLINE (decl) = 1;
- }
}
insns = get_insns ();
--- 2532,2539 ----
return true;
}
}
! else
inlinable = DECL_INLINE (decl) = 1;
}
insns = get_insns ();
Index: tree-inline.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-inline.c,v
retrieving revision 1.72
diff -c -3 -p -r1.72 tree-inline.c
*** tree-inline.c 30 Jul 2003 17:27:07 -0000 1.72
--- tree-inline.c 31 Jul 2003 15:30:54 -0000
*************** static tree copy_body_r (tree *, int *,
*** 116,122 ****
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 tree remap_decl (tree, inline_data *);
#ifndef INLINER_FOR_JAVA
static tree initialize_inlined_parameters (inline_data *, tree, tree);
--- 116,123 ----
static tree copy_body (inline_data *);
static tree expand_call_inline (tree *, int *, void *);
static void expand_calls_inline (tree *, inline_data *);
! 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);
*************** declare_return_variable (struct inline_d
*** 873,882 ****
/* Returns nonzero if a function can be inlined as a tree. */
! int
! tree_inlinable_function_p (tree fn, int nolimit)
{
! return inlinable_function_p (fn, NULL, nolimit);
}
/* If *TP is possibly call to alloca, return nonzero. */
--- 874,883 ----
/* Returns nonzero if a function can be inlined as a tree. */
! bool
! tree_inlinable_function_p (tree fn)
{
! return inlinable_function_p (fn);
}
/* If *TP is possibly call to alloca, return nonzero. */
*************** find_builtin_longjmp_call (tree exp)
*** 927,993 ****
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. */
! static int
! inlinable_function_p (tree fn, inline_data *id, int nolimit)
{
! int inlinable;
! int currfn_insns = 0;
! int max_inline_insns_single = MAX_INLINE_INSNS_SINGLE;
/* If we've already decided this function shouldn't be inlined,
there's no need to check again. */
if (DECL_UNINLINABLE (fn))
! return 0;
/* 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.) */
! 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;
-
- /* 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;
#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
--- 928,979 ----
return ret;
}
! /* Returns nonzero if FN is a function that does not have any
! fundamental inline blocking properties. */
! static bool
! inlinable_function_p (tree fn)
{
! 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 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.)
! If the function is not inlinable for language-specific reasons,
! it is left up to the langhook to explain why. */
! if ((*lang_hooks.tree_inlining.cannot_inline_tree_fn) (&fn))
! inlinable = false;
!
! /* If we're not inlining at all, or if we don't have the function
! body available, we can't inline this function. */
! else if (!flag_inline_trees || !DECL_SAVED_TREE (fn))
! 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. */
! else if (!DECL_INLINE (fn))
! inlinable = false;
#ifdef INLINER_FOR_JAVA
/* Synchronized methods can't be inlined. This is a bug. */
else if (METHOD_SYNCHRONIZED (fn))
! inlinable = false;
#endif /* INLINER_FOR_JAVA */
!
/* 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
*************** inlinable_function_p (tree fn, inline_da
*** 995,1064 ****
__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. */
else if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)) == NULL
&& find_alloca_call (DECL_SAVED_TREE (fn)))
! inlinable = 0;
/* Squirrel away the result so that we don't have to check again. */
! DECL_UNINLINABLE (fn) = ! inlinable;
! /* 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)
{
! 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 max_curr = MAX_INLINE_INSNS_SINGLE
! - (sum_insns - MAX_INLINE_INSNS) / MAX_INLINE_SLOPE;
! if (currfn_insns > max_curr)
! inlinable = 0;
}
}
! /* Check again, language hooks may have modified it. */
! if (! inlinable || DECL_UNINLINABLE (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)
{
! size_t i;
! for (i = 0; i < VARRAY_ACTIVE_SIZE (id->fns); ++i)
! if (VARRAY_TREE (id->fns, i) == fn)
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;
}
/* If *TP is a CALL_EXPR, replace it with its inline expansion. */
--- 981,1118 ----
__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)))
! 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)))
! 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;
!
! 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.
! 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 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 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;
! }
}
}
! /* Don't allow recursive inlining. */
! for (i = 0; i < VARRAY_ACTIVE_SIZE (id->fns); ++i)
! if (VARRAY_TREE (id->fns, i) == fn)
! 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;
}
! /* Go ahead, this function can be inlined. */
! return 1;
}
/* If *TP is a CALL_EXPR, replace it with its inline expansion. */
*************** expand_call_inline (tree *tp, int *walk_
*** 1166,1174 ****
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)))
{
! if (warn_inline && DECL_INLINE (fn) && !DID_INLINE_FUNC (fn)
&& !DECL_IN_SYSTEM_HEADER (fn))
{
warning ("%Hinlining failed in call to '%F'",
--- 1220,1228 ----
inlining. */
if ((flag_unit_at_a_time
&& (!DECL_SAVED_TREE (fn) || !cgraph_inline_p (id->current_decl, fn)))
! || (!flag_unit_at_a_time && !limits_allow_inlining (fn, id)))
{
! if (warn_inline && DECL_INLINE (fn) && DECL_DECLARED_INLINE_P (fn)
&& !DECL_IN_SYSTEM_HEADER (fn))
{
warning ("%Hinlining failed in call to '%F'",
Index: tree-inline.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-inline.h,v
retrieving revision 1.7
diff -c -3 -p -r1.7 tree-inline.h
*** tree-inline.h 6 Jul 2003 12:35:55 -0000 1.7
--- tree-inline.h 31 Jul 2003 15:30:54 -0000
*************** Boston, MA 02111-1307, USA. */
*** 25,31 ****
/* Function prototypes. */
void optimize_inline_calls (tree);
! int tree_inlinable_function_p (tree, int);
tree walk_tree (tree*, walk_tree_fn, void*, void*);
tree walk_tree_without_duplicates (tree*, walk_tree_fn, void*);
tree copy_tree_r (tree*, int*, void*);
--- 25,31 ----
/* Function prototypes. */
void optimize_inline_calls (tree);
! bool tree_inlinable_function_p (tree);
tree walk_tree (tree*, walk_tree_fn, void*, void*);
tree walk_tree_without_duplicates (tree*, walk_tree_fn, void*);
tree copy_tree_r (tree*, int*, void*);
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.431
diff -c -3 -p -r1.431 tree.h
*** tree.h 29 Jul 2003 01:14:19 -0000 1.431
--- tree.h 31 Jul 2003 15:31:00 -0000
*************** struct tree_type GTY(())
*** 1473,1482 ****
where it is called. */
#define DECL_INLINE(NODE) (FUNCTION_DECL_CHECK (NODE)->decl.inline_flag)
! /* Nonzero in a FUNCTION_DECL means this function has been found inlinable
! only by virtue of -finline-functions */
! #define DID_INLINE_FUNC(NODE) \
! (FUNCTION_DECL_CHECK (NODE)->decl.inlined_function_flag)
/* In a FUNCTION_DECL, nonzero if the function cannot be inlined. */
#define DECL_UNINLINABLE(NODE) (FUNCTION_DECL_CHECK (NODE)->decl.uninlinable)
--- 1473,1484 ----
where it is called. */
#define DECL_INLINE(NODE) (FUNCTION_DECL_CHECK (NODE)->decl.inline_flag)
! /* Nonzero in a FUNCTION_DECL means that this function was declared inline,
! such as via the `inline' keyword in C/C++. This flag controls the linkage
! semantics of 'inline'; whether or not the function is inlined is
! controlled by DECL_INLINE. */
! #define DECL_DECLARED_INLINE_P(NODE) \
! (FUNCTION_DECL_CHECK (NODE)->decl.declared_inline_flag)
/* In a FUNCTION_DECL, nonzero if the function cannot be inlined. */
#define DECL_UNINLINABLE(NODE) (FUNCTION_DECL_CHECK (NODE)->decl.uninlinable)
*************** struct tree_type GTY(())
*** 1606,1611 ****
--- 1608,1620 ----
#define DECL_POINTER_ALIAS_SET_KNOWN_P(NODE) \
(DECL_POINTER_ALIAS_SET (NODE) != - 1)
+ /* In a FUNCTION_DECL for which DECL_BUILT_IN does not hold, this is
+ the approximate number of statements in this function. There is
+ no need for this number to be exact; it is only used in various
+ heuristics regarding optimization. */
+ #define DECL_ESTIMATED_INSNS(NODE) \
+ (FUNCTION_DECL_CHECK (NODE)->decl.u1.i)
+
struct function;
struct tree_decl GTY(())
*************** struct tree_decl GTY(())
*** 1646,1652 ****
unsigned user_align : 1;
unsigned uninlinable : 1;
unsigned thread_local_flag : 1;
! unsigned inlined_function_flag : 1;
unsigned unused : 3;
/* three unused bits. */
--- 1655,1661 ----
unsigned user_align : 1;
unsigned uninlinable : 1;
unsigned thread_local_flag : 1;
! unsigned declared_inline_flag : 1;
unsigned unused : 3;
/* three unused bits. */
Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.893
diff -c -3 -p -r1.893 cp-tree.h
*** cp/cp-tree.h 30 Jul 2003 17:27:13 -0000 1.893
--- cp/cp-tree.h 31 Jul 2003 15:31:47 -0000
*************** struct lang_type GTY(())
*** 1637,1644 ****
struct lang_decl_flags GTY(())
{
- struct c_lang_decl base;
-
ENUM_BITFIELD(languages) language : 8;
unsigned operator_attr : 1;
--- 1637,1642 ----
*************** struct lang_decl GTY(())
*** 2848,2859 ****
/* We know what we're doing with this decl now. */
#define DECL_INTERFACE_KNOWN(NODE) DECL_LANG_FLAG_5 (NODE)
-
- /* This function was declared inline. This flag controls the linkage
- semantics of 'inline'; whether or not the function is inlined is
- controlled by DECL_INLINE. */
- #define DECL_DECLARED_INLINE_P(NODE) \
- (DECL_LANG_SPECIFIC (NODE)->decl_flags.base.declared_inline)
/* DECL_EXTERNAL must be set on a decl until the decl is actually emitted,
so that assemble_external will work properly. So we have this flag to
--- 2846,2851 ----
Index: cp/decl2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl2.c,v
retrieving revision 1.653
diff -c -3 -p -r1.653 decl2.c
*** cp/decl2.c 30 Jul 2003 23:47:59 -0000 1.653
--- cp/decl2.c 31 Jul 2003 15:31:51 -0000
*************** import_export_decl (tree decl)
*** 1743,1749 ****
if ((DECL_IMPLICIT_INSTANTIATION (decl)
|| DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl))
&& (flag_implicit_templates
! || (flag_implicit_inline_templates
&& DECL_DECLARED_INLINE_P (decl))))
{
if (!TREE_PUBLIC (decl))
--- 1743,1750 ----
if ((DECL_IMPLICIT_INSTANTIATION (decl)
|| DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl))
&& (flag_implicit_templates
! || (flag_implicit_inline_templates
! && TREE_CODE (decl) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (decl))))
{
if (!TREE_PUBLIC (decl))
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1105
diff -c -3 -p -r1.1105 decl.c
*** cp/decl.c 29 Jul 2003 22:15:28 -0000 1.1105
--- cp/decl.c 31 Jul 2003 15:32:17 -0000
*************** grokfndecl (tree ctype,
*** 8896,8914 ****
DECL_NOT_REALLY_EXTERN (decl) = 1;
}
- DID_INLINE_FUNC (decl) = 0;
/* If the declaration was declared inline, mark it as such. */
if (inlinep)
DECL_DECLARED_INLINE_P (decl) = 1;
/* We inline functions that are explicitly declared inline, or, when
the user explicitly asks us to, all functions. */
! if (DECL_DECLARED_INLINE_P (decl))
DECL_INLINE (decl) = 1;
- if (flag_inline_trees == 2 && !DECL_INLINE (decl) && funcdef_flag)
- {
- DID_INLINE_FUNC (decl) = 1;
- DECL_INLINE (decl) = 1;
- }
DECL_EXTERNAL (decl) = 1;
if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE)
--- 8896,8909 ----
DECL_NOT_REALLY_EXTERN (decl) = 1;
}
/* If the declaration was declared inline, mark it as such. */
if (inlinep)
DECL_DECLARED_INLINE_P (decl) = 1;
/* We inline functions that are explicitly declared inline, or, when
the user explicitly asks us to, all functions. */
! if (DECL_DECLARED_INLINE_P (decl)
! || (flag_inline_trees == 2 && !DECL_INLINE (decl) && funcdef_flag))
DECL_INLINE (decl) = 1;
DECL_EXTERNAL (decl) = 1;
if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE)
*************** start_method (tree declspecs, tree decla
*** 14267,14274 ****
check_template_shadow (fndecl);
DECL_DECLARED_INLINE_P (fndecl) = 1;
-
- DID_INLINE_FUNC (fndecl) = 0;
if (flag_default_inline)
DECL_INLINE (fndecl) = 1;
--- 14262,14267 ----
Index: cp/optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/optimize.c,v
retrieving revision 1.93
diff -c -3 -p -r1.93 optimize.c
*** cp/optimize.c 9 Jul 2003 00:31:15 -0000 1.93
--- cp/optimize.c 31 Jul 2003 15:32:20 -0000
*************** maybe_clone_body (tree fn)
*** 159,165 ****
/* Update CLONE's source position information to match FN's. */
DECL_SOURCE_LOCATION (clone) = DECL_SOURCE_LOCATION (fn);
DECL_INLINE (clone) = DECL_INLINE (fn);
- DID_INLINE_FUNC (clone) = DID_INLINE_FUNC (fn);
DECL_DECLARED_INLINE_P (clone) = DECL_DECLARED_INLINE_P (fn);
DECL_COMDAT (clone) = DECL_COMDAT (fn);
DECL_WEAK (clone) = DECL_WEAK (fn);
--- 159,164 ----
Index: cp/tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/tree.c,v
retrieving revision 1.339
Index: java/java-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/java-tree.h,v
retrieving revision 1.179
diff -c -3 -p -r1.179 java-tree.h
*** java/java-tree.h 24 Jul 2003 20:48:13 -0000 1.179
--- java/java-tree.h 31 Jul 2003 15:33:17 -0000
*************** union lang_tree_node
*** 907,918 ****
/* The original WFL of a final variable. */
#define DECL_FIELD_FINAL_WFL(NODE) \
(DECL_LANG_SPECIFIC(NODE)->u.v.wfl)
- /* In a FUNCTION_DECL for which DECL_BUILT_IN does not hold, this is
- the approximate number of instructions in this function. There is
- no need for this number to be exact; it is only used in various
- heuristics regarding optimization. */
- #define DECL_ESTIMATED_INSNS(NODE) \
- (FUNCTION_DECL_CHECK (NODE)->decl.u1.i)
/* True if NODE is a local variable final. */
#define LOCAL_FINAL_P(NODE) (DECL_LANG_SPECIFIC (NODE) && DECL_FINAL (NODE))
/* True if NODE is a final field. */
--- 907,912 ----