This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: C++: inlining issues
- To: martin at MPA-Garching dot MPG dot DE
- Subject: Re: C++: inlining issues
- From: Mark Mitchell <mark at codesourcery dot com>
- Date: Mon, 13 Dec 1999 00:55:27 -0800
- Cc: gcc-bugs at gcc dot gnu dot org
- Organization: CodeSourcery, LLC
- References: <3850E197.1B4642BA@mpa-garching.mpg.de>
Martin --
Fixed with the attached patch.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
1999-12-13 Mark Mitchell <mark@codesourcery.com>
* optimize.c (initialize_inlined_parameters): Take FN to which the
parameters belong as an argument.
(expand_call_inline): Expand calls into the parameter
initializations before pushing the function onto the list of
functions we are presently expanding.
Index: testsuite/g++.old-deja/g++.other/inline2.C
===================================================================
RCS file: inline2.C
diff -N inline2.C
*** /dev/null Tue May 5 13:32:27 1998
--- inline2.C Mon Dec 13 00:23:07 1999
***************
*** 0 ****
--- 1,11 ----
+ // Origin: Martin Reinecke <martin@MPA-Garching.MPG.DE>
+ // Build don't link:
+ // Special g++ Options: -O2 -Winline
+
+ #include <cmath>
+
+ int main()
+ {
+ double foo = 4.5;
+ if (abs (0.5-abs (foo-0.5)) < 1e-10) foo+=1;
+ }
Index: cp/optimize.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/optimize.c,v
retrieving revision 1.5
diff -c -p -r1.5 optimize.c
*** optimize.c 1999/12/11 19:02:10 1.5
--- optimize.c 1999/12/13 08:23:12
*************** typedef struct inline_data
*** 67,73 ****
/* Prototypes. */
! static tree initialize_inlined_parameters PROTO((inline_data *, tree));
static tree declare_return_variable PROTO((inline_data *, tree *));
static tree copy_body_r PROTO((tree *, int *, void *));
static tree copy_body PROTO((inline_data *));
--- 67,73 ----
/* Prototypes. */
! static tree initialize_inlined_parameters PROTO((inline_data *, tree, tree));
static tree declare_return_variable PROTO((inline_data *, tree *));
static tree copy_body_r PROTO((tree *, int *, void *));
static tree copy_body PROTO((inline_data *));
*************** copy_body (id)
*** 342,359 ****
top of the stack in ID from the ARGS (presented as a TREE_LIST). */
static tree
! initialize_inlined_parameters (id, args)
inline_data *id;
tree args;
{
- tree fn;
tree init_stmts;
tree parms;
tree a;
tree p;
/* Figure out what the parameters are. */
- fn = VARRAY_TOP_TREE (id->fns);
parms = DECL_ARGUMENTS (fn);
/* Start with no initializations whatsoever. */
--- 342,358 ----
top of the stack in ID from the ARGS (presented as a TREE_LIST). */
static tree
! initialize_inlined_parameters (id, args, fn)
inline_data *id;
tree args;
+ tree fn;
{
tree init_stmts;
tree parms;
tree a;
tree p;
/* Figure out what the parameters are. */
parms = DECL_ARGUMENTS (fn);
/* Start with no initializations whatsoever. */
*************** expand_call_inline (tp, walk_subtrees, d
*** 517,522 ****
--- 516,522 ----
tree fn;
tree scope_stmt;
tree use_stmt;
+ tree arg_inits;
splay_tree st;
/* See what we've got. */
*************** expand_call_inline (tp, walk_subtrees, d
*** 570,580 ****
if (!inlinable_function_p (fn, id))
return NULL_TREE;
- /* Return statements in the function body will be replaced by jumps
- to the RET_LABEL. */
- id->ret_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
- DECL_CONTEXT (id->ret_label) = VARRAY_TREE (id->fns, 0);
-
/* Build a statement-expression containing code to initialize the
arguments, the actual inline expansion of the body, and a label
for the return statements within the function to jump to. The
--- 570,575 ----
*************** expand_call_inline (tp, walk_subtrees, d
*** 582,591 ****
function call. */
expr = build_min (STMT_EXPR, TREE_TYPE (TREE_TYPE (fn)), NULL_TREE);
- /* Record the function we are about to inline so that we can avoid
- recursing into it. */
- VARRAY_PUSH_TREE (id->fns, fn);
-
/* Local declarations will be replaced by their equivalents in this
map. */
st = id->decl_map;
--- 577,582 ----
*************** expand_call_inline (tp, walk_subtrees, d
*** 593,601 ****
NULL, NULL);
/* Initialize the parameters. */
! STMT_EXPR_STMT (expr)
! = initialize_inlined_parameters (id, TREE_OPERAND (t, 1));
!
/* Create a block to put the parameters in. We have to do this
after the parameters have been remapped because remapping
parameters is different from remapping ordinary variables. */
--- 584,607 ----
NULL, NULL);
/* Initialize the parameters. */
! arg_inits = initialize_inlined_parameters (id, TREE_OPERAND (t, 1), fn);
! /* Expand any inlined calls in the initializers. Do this before we
! push FN on the stack of functions we are inlining; we want to
! inline calls to FN that appear in the initializers for the
! parameters. */
! expand_calls_inline (&arg_inits, id);
! /* And add them to the tree. */
! STMT_EXPR_STMT (expr) = chainon (STMT_EXPR_STMT (expr), arg_inits);
!
! /* Record the function we are about to inline so that we can avoid
! recursing into it. */
! VARRAY_PUSH_TREE (id->fns, fn);
!
! /* Return statements in the function body will be replaced by jumps
! to the RET_LABEL. */
! id->ret_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
! DECL_CONTEXT (id->ret_label) = VARRAY_TREE (id->fns, 0);
!
/* Create a block to put the parameters in. We have to do this
after the parameters have been remapped because remapping
parameters is different from remapping ordinary variables. */