This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++] RFC: fix inlining logic
- To: gcc-patches at gcc dot gnu dot org
- Subject: [C++] RFC: fix inlining logic
- From: Dan Nicolaescu <dann at godzilla dot ICS dot UCI dot EDU>
- Date: Wed, 02 May 2001 13:41:22 -0700
Hi!
g++ from the branch (and probably mainline) would not inline function
foo in the following small example:
void f2 (int);
static void
foo (float xx, int type)
{
f1 (xx);
f2 (type);
}
void
bar (void)
{
foo (3.5, 6);
}
when compiled with g++ -O3
g++ 2.95.2 will inline it just fine.
(BTW this small example crashes the branch and mainline C compiler on
SPARC, see http://gcc.gnu.org/ml/gcc/2001-05/msg00030.html)
The problem is that init_decl_processing in cp/decl.c messes with the
inlining flags and manages to turn off flag_inline_functions
Like this:
if (!flag_no_inline)
{
flag_inline_trees = 1;
flag_no_inline = 1;
}
and later:
if (flag_no_inline)
{
flag_inline_functions = 0;
}
So flag_inline_functions is turned off all the time. Not good.
One way to fix it is shown below. With this the foo function in the
above example is inlined.
I have a few questions concerning inlining:
1. The code always sets flag_no_inline to 1, is that correct?
2. Is this sequence in inlinable_function_p from cp/optimize.c
/* If the function was not declared `inline', then we don't inline
it. */
else if (!DECL_INLINE (fn))
correct? Why not inline functions not declared inline? Is the comment
innacurate? With my patch it inlines the "foo" just fine....
2001-05-02 Dan Nicolaescu <dann@ics.uci.edu>
* decl.c (init_decl_processing): Only reset
flag_inline_functions if flag_no_inline is set.
*** decl.c.~1.747.2.22.~ Tue May 1 23:14:11 2001
--- decl.c Wed May 2 11:10:52 2001
***************
*** 6354,6360 ****
--- 6354,6365 ----
flag_inline_trees = 1;
flag_no_inline = 1;
}
+ else
+ {
+ flag_inline_functions = 0;
+ }
+
/* Initially, C. */
current_lang_name = lang_name_c;
***************
*** 6534,6543 ****
if (flag_exceptions)
init_exception_processing ();
- if (flag_no_inline)
- {
- flag_inline_functions = 0;
- }
if (! supports_one_only ())
flag_weak = 0;
--- 6539,6544 ----