* configure.in: Add ${libgcj} to noconfigdirs for xtensa-*-* targets.
[official-gcc.git] / gcc / tree-inline.c
blob3e68983fe3fa3851204ab50c772bf405f7a02e17
1 /* Control and data flow functions for trees.
2 Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
3 Contributed by Alexandre Oliva <aoliva@redhat.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "toplev.h"
27 #include "tree.h"
28 #include "tree-inline.h"
29 #include "rtl.h"
30 #include "expr.h"
31 #include "flags.h"
32 #include "params.h"
33 #include "input.h"
34 #include "insn-config.h"
35 #include "integrate.h"
36 #include "varray.h"
37 #include "hashtab.h"
38 #include "splay-tree.h"
39 #include "langhooks.h"
40 #include "cgraph.h"
42 /* This should be eventually be generalized to other languages, but
43 this would require a shared function-as-trees infrastructure. */
44 #ifndef INLINER_FOR_JAVA
45 #include "c-common.h"
46 #else /* INLINER_FOR_JAVA */
47 #include "parse.h"
48 #include "java-tree.h"
49 #endif /* INLINER_FOR_JAVA */
51 /* 0 if we should not perform inlining.
52 1 if we should expand functions calls inline at the tree level.
53 2 if we should consider *all* functions to be inline
54 candidates. */
56 int flag_inline_trees = 0;
58 /* To Do:
60 o In order to make inlining-on-trees work, we pessimized
61 function-local static constants. In particular, they are now
62 always output, even when not addressed. Fix this by treating
63 function-local static constants just like global static
64 constants; the back-end already knows not to output them if they
65 are not needed.
67 o Provide heuristics to clamp inlining of recursive template
68 calls? */
70 /* Data required for function inlining. */
72 typedef struct inline_data
74 /* A stack of the functions we are inlining. For example, if we are
75 compiling `f', which calls `g', which calls `h', and we are
76 inlining the body of `h', the stack will contain, `h', followed
77 by `g', followed by `f'. The first few elements of the stack may
78 contain other functions that we know we should not recurse into,
79 even though they are not directly being inlined. */
80 varray_type fns;
81 /* The index of the first element of FNS that really represents an
82 inlined function. */
83 unsigned first_inlined_fn;
84 /* The label to jump to when a return statement is encountered. If
85 this value is NULL, then return statements will simply be
86 remapped as return statements, rather than as jumps. */
87 tree ret_label;
88 /* The map from local declarations in the inlined function to
89 equivalents in the function into which it is being inlined. */
90 splay_tree decl_map;
91 /* Nonzero if we are currently within the cleanup for a
92 TARGET_EXPR. */
93 int in_target_cleanup_p;
94 /* A list of the functions current function has inlined. */
95 varray_type inlined_fns;
96 /* The approximate number of instructions we have inlined in the
97 current call stack. */
98 int inlined_insns;
99 /* We use the same mechanism to build clones that we do to perform
100 inlining. However, there are a few places where we need to
101 distinguish between those two situations. This flag is true if
102 we are cloning, rather than inlining. */
103 bool cloning_p;
104 /* Hash table used to prevent walk_tree from visiting the same node
105 umpteen million times. */
106 htab_t tree_pruner;
107 /* Decl of function we are inlining into. */
108 tree decl;
109 } inline_data;
111 /* Prototypes. */
113 static tree declare_return_variable (inline_data *, tree, tree *);
114 static tree copy_body_r (tree *, int *, void *);
115 static tree copy_body (inline_data *);
116 static tree expand_call_inline (tree *, int *, void *);
117 static void expand_calls_inline (tree *, inline_data *);
118 static int inlinable_function_p (tree, inline_data *, int);
119 static tree remap_decl (tree, inline_data *);
120 #ifndef INLINER_FOR_JAVA
121 static tree initialize_inlined_parameters (inline_data *, tree, tree);
122 static void remap_block (tree, tree, inline_data *);
123 static void copy_scope_stmt (tree *, int *, inline_data *);
124 #else /* INLINER_FOR_JAVA */
125 static tree initialize_inlined_parameters (inline_data *, tree, tree, tree);
126 static void remap_block (tree *, tree, inline_data *);
127 static tree add_stmt_to_compound (tree, tree, tree);
128 #endif /* INLINER_FOR_JAVA */
129 static tree find_alloca_call_1 (tree *, int *, void *);
130 static tree find_alloca_call (tree);
131 static tree find_builtin_longjmp_call_1 (tree *, int *, void *);
132 static tree find_builtin_longjmp_call (tree);
134 /* Remap DECL during the copying of the BLOCK tree for the function. */
136 static tree
137 remap_decl (tree decl, inline_data *id)
139 splay_tree_node n;
140 tree fn;
142 /* We only remap local variables in the current function. */
143 fn = VARRAY_TOP_TREE (id->fns);
144 if (! (*lang_hooks.tree_inlining.auto_var_in_fn_p) (decl, fn))
145 return NULL_TREE;
147 /* See if we have remapped this declaration. */
148 n = splay_tree_lookup (id->decl_map, (splay_tree_key) decl);
149 /* If we didn't already have an equivalent for this declaration,
150 create one now. */
151 if (!n)
153 tree t;
155 /* Make a copy of the variable or label. */
156 t = copy_decl_for_inlining (decl, fn,
157 VARRAY_TREE (id->fns, 0));
159 /* The decl T could be a dynamic array or other variable size type,
160 in which case some fields need to be remapped because they may
161 contain SAVE_EXPRs. */
162 if (TREE_TYPE (t) && TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
163 && TYPE_DOMAIN (TREE_TYPE (t)))
165 TREE_TYPE (t) = copy_node (TREE_TYPE (t));
166 TYPE_DOMAIN (TREE_TYPE (t))
167 = copy_node (TYPE_DOMAIN (TREE_TYPE (t)));
168 walk_tree (&TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (t))),
169 copy_body_r, id, NULL);
172 #ifndef INLINER_FOR_JAVA
173 if (! DECL_NAME (t) && TREE_TYPE (t)
174 && (*lang_hooks.tree_inlining.anon_aggr_type_p) (TREE_TYPE (t)))
176 /* For a VAR_DECL of anonymous type, we must also copy the
177 member VAR_DECLS here and rechain the
178 DECL_ANON_UNION_ELEMS. */
179 tree members = NULL;
180 tree src;
182 for (src = DECL_ANON_UNION_ELEMS (t); src;
183 src = TREE_CHAIN (src))
185 tree member = remap_decl (TREE_VALUE (src), id);
187 if (TREE_PURPOSE (src))
188 abort ();
189 members = tree_cons (NULL, member, members);
191 DECL_ANON_UNION_ELEMS (t) = nreverse (members);
193 #endif /* not INLINER_FOR_JAVA */
195 /* Remember it, so that if we encounter this local entity
196 again we can reuse this copy. */
197 n = splay_tree_insert (id->decl_map,
198 (splay_tree_key) decl,
199 (splay_tree_value) t);
202 return (tree) n->value;
205 #ifndef INLINER_FOR_JAVA
206 /* Copy the SCOPE_STMT_BLOCK associated with SCOPE_STMT to contain
207 remapped versions of the variables therein. And hook the new block
208 into the block-tree. If non-NULL, the DECLS are declarations to
209 add to use instead of the BLOCK_VARS in the old block. */
210 #else /* INLINER_FOR_JAVA */
211 /* Copy the BLOCK to contain remapped versions of the variables
212 therein. And hook the new block into the block-tree. */
213 #endif /* INLINER_FOR_JAVA */
215 static void
216 #ifndef INLINER_FOR_JAVA
217 remap_block (tree scope_stmt, tree decls, inline_data *id)
218 #else /* INLINER_FOR_JAVA */
219 remap_block (tree *block, tree decls, inline_data *id)
220 #endif /* INLINER_FOR_JAVA */
222 #ifndef INLINER_FOR_JAVA
223 /* We cannot do this in the cleanup for a TARGET_EXPR since we do
224 not know whether or not expand_expr will actually write out the
225 code we put there. If it does not, then we'll have more BLOCKs
226 than block-notes, and things will go awry. At some point, we
227 should make the back-end handle BLOCK notes in a tidier way,
228 without requiring a strict correspondence to the block-tree; then
229 this check can go. */
230 if (id->in_target_cleanup_p)
232 SCOPE_STMT_BLOCK (scope_stmt) = NULL_TREE;
233 return;
236 /* If this is the beginning of a scope, remap the associated BLOCK. */
237 if (SCOPE_BEGIN_P (scope_stmt) && SCOPE_STMT_BLOCK (scope_stmt))
239 tree old_block;
240 tree new_block;
241 tree old_var;
242 tree fn;
244 /* Make the new block. */
245 old_block = SCOPE_STMT_BLOCK (scope_stmt);
246 new_block = make_node (BLOCK);
247 TREE_USED (new_block) = TREE_USED (old_block);
248 BLOCK_ABSTRACT_ORIGIN (new_block) = old_block;
249 SCOPE_STMT_BLOCK (scope_stmt) = new_block;
251 /* Remap its variables. */
252 for (old_var = decls ? decls : BLOCK_VARS (old_block);
253 old_var;
254 old_var = TREE_CHAIN (old_var))
256 tree new_var;
258 /* Remap the variable. */
259 new_var = remap_decl (old_var, id);
260 /* If we didn't remap this variable, so we can't mess with
261 its TREE_CHAIN. If we remapped this variable to
262 something other than a declaration (say, if we mapped it
263 to a constant), then we must similarly omit any mention
264 of it here. */
265 if (!new_var || !DECL_P (new_var))
267 else
269 TREE_CHAIN (new_var) = BLOCK_VARS (new_block);
270 BLOCK_VARS (new_block) = new_var;
273 /* We put the BLOCK_VARS in reverse order; fix that now. */
274 BLOCK_VARS (new_block) = nreverse (BLOCK_VARS (new_block));
275 fn = VARRAY_TREE (id->fns, 0);
276 if (id->cloning_p)
277 /* We're building a clone; DECL_INITIAL is still
278 error_mark_node, and current_binding_level is the parm
279 binding level. */
280 (*lang_hooks.decls.insert_block) (new_block);
281 else
283 /* Attach this new block after the DECL_INITIAL block for the
284 function into which this block is being inlined. In
285 rest_of_compilation we will straighten out the BLOCK tree. */
286 tree *first_block;
287 if (DECL_INITIAL (fn))
288 first_block = &BLOCK_CHAIN (DECL_INITIAL (fn));
289 else
290 first_block = &DECL_INITIAL (fn);
291 BLOCK_CHAIN (new_block) = *first_block;
292 *first_block = new_block;
294 /* Remember the remapped block. */
295 splay_tree_insert (id->decl_map,
296 (splay_tree_key) old_block,
297 (splay_tree_value) new_block);
299 /* If this is the end of a scope, set the SCOPE_STMT_BLOCK to be the
300 remapped block. */
301 else if (SCOPE_END_P (scope_stmt) && SCOPE_STMT_BLOCK (scope_stmt))
303 splay_tree_node n;
305 /* Find this block in the table of remapped things. */
306 n = splay_tree_lookup (id->decl_map,
307 (splay_tree_key) SCOPE_STMT_BLOCK (scope_stmt));
308 if (! n)
309 abort ();
310 SCOPE_STMT_BLOCK (scope_stmt) = (tree) n->value;
312 #else /* INLINER_FOR_JAVA */
313 tree old_block;
314 tree new_block;
315 tree old_var;
316 tree fn;
318 /* Make the new block. */
319 old_block = *block;
320 new_block = make_node (BLOCK);
321 TREE_USED (new_block) = TREE_USED (old_block);
322 BLOCK_ABSTRACT_ORIGIN (new_block) = old_block;
323 BLOCK_SUBBLOCKS (new_block) = BLOCK_SUBBLOCKS (old_block);
324 TREE_SIDE_EFFECTS (new_block) = TREE_SIDE_EFFECTS (old_block);
325 TREE_TYPE (new_block) = TREE_TYPE (old_block);
326 *block = new_block;
328 /* Remap its variables. */
329 for (old_var = decls ? decls : BLOCK_VARS (old_block);
330 old_var;
331 old_var = TREE_CHAIN (old_var))
333 tree new_var;
335 /* All local class initialization flags go in the outermost
336 scope. */
337 if (LOCAL_CLASS_INITIALIZATION_FLAG_P (old_var))
339 /* We may already have one. */
340 if (! splay_tree_lookup (id->decl_map, (splay_tree_key) old_var))
342 tree outermost_block;
343 new_var = remap_decl (old_var, id);
344 DECL_ABSTRACT_ORIGIN (new_var) = NULL;
345 outermost_block = DECL_SAVED_TREE (current_function_decl);
346 TREE_CHAIN (new_var) = BLOCK_VARS (outermost_block);
347 BLOCK_VARS (outermost_block) = new_var;
349 continue;
352 /* Remap the variable. */
353 new_var = remap_decl (old_var, id);
354 /* If we didn't remap this variable, so we can't mess with
355 its TREE_CHAIN. If we remapped this variable to
356 something other than a declaration (say, if we mapped it
357 to a constant), then we must similarly omit any mention
358 of it here. */
359 if (!new_var || !DECL_P (new_var))
361 else
363 TREE_CHAIN (new_var) = BLOCK_VARS (new_block);
364 BLOCK_VARS (new_block) = new_var;
367 /* We put the BLOCK_VARS in reverse order; fix that now. */
368 BLOCK_VARS (new_block) = nreverse (BLOCK_VARS (new_block));
369 fn = VARRAY_TREE (id->fns, 0);
370 /* Remember the remapped block. */
371 splay_tree_insert (id->decl_map,
372 (splay_tree_key) old_block,
373 (splay_tree_value) new_block);
374 #endif /* INLINER_FOR_JAVA */
377 #ifndef INLINER_FOR_JAVA
378 /* Copy the SCOPE_STMT pointed to by TP. */
380 static void
381 copy_scope_stmt (tree *tp, int *walk_subtrees, inline_data *id)
383 tree block;
385 /* Remember whether or not this statement was nullified. When
386 making a copy, copy_tree_r always sets SCOPE_NULLIFIED_P (and
387 doesn't copy the SCOPE_STMT_BLOCK) to free callers from having to
388 deal with copying BLOCKs if they do not wish to do so. */
389 block = SCOPE_STMT_BLOCK (*tp);
390 /* Copy (and replace) the statement. */
391 copy_tree_r (tp, walk_subtrees, NULL);
392 /* Restore the SCOPE_STMT_BLOCK. */
393 SCOPE_STMT_BLOCK (*tp) = block;
395 /* Remap the associated block. */
396 remap_block (*tp, NULL_TREE, id);
398 #endif /* not INLINER_FOR_JAVA */
400 /* Called from copy_body via walk_tree. DATA is really an
401 `inline_data *'. */
402 static tree
403 copy_body_r (tree *tp, int *walk_subtrees, void *data)
405 inline_data* id;
406 tree fn;
408 /* Set up. */
409 id = (inline_data *) data;
410 fn = VARRAY_TOP_TREE (id->fns);
412 #if 0
413 /* All automatic variables should have a DECL_CONTEXT indicating
414 what function they come from. */
415 if ((TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == LABEL_DECL)
416 && DECL_NAMESPACE_SCOPE_P (*tp))
417 if (! DECL_EXTERNAL (*tp) && ! TREE_STATIC (*tp))
418 abort ();
419 #endif
421 #ifdef INLINER_FOR_JAVA
422 if (TREE_CODE (*tp) == BLOCK)
423 remap_block (tp, NULL_TREE, id);
424 #endif
426 /* If this is a RETURN_STMT, change it into an EXPR_STMT and a
427 GOTO_STMT with the RET_LABEL as its target. */
428 #ifndef INLINER_FOR_JAVA
429 if (TREE_CODE (*tp) == RETURN_STMT && id->ret_label)
430 #else /* INLINER_FOR_JAVA */
431 if (TREE_CODE (*tp) == RETURN_EXPR && id->ret_label)
432 #endif /* INLINER_FOR_JAVA */
434 tree return_stmt = *tp;
435 tree goto_stmt;
437 /* Build the GOTO_STMT. */
438 #ifndef INLINER_FOR_JAVA
439 goto_stmt = build_stmt (GOTO_STMT, id->ret_label);
440 TREE_CHAIN (goto_stmt) = TREE_CHAIN (return_stmt);
441 GOTO_FAKE_P (goto_stmt) = 1;
442 #else /* INLINER_FOR_JAVA */
443 tree assignment = TREE_OPERAND (return_stmt, 0);
444 goto_stmt = build1 (GOTO_EXPR, void_type_node, id->ret_label);
445 TREE_SIDE_EFFECTS (goto_stmt) = 1;
446 #endif /* INLINER_FOR_JAVA */
448 /* If we're returning something, just turn that into an
449 assignment into the equivalent of the original
450 RESULT_DECL. */
451 #ifndef INLINER_FOR_JAVA
452 if (RETURN_STMT_EXPR (return_stmt))
454 *tp = build_stmt (EXPR_STMT,
455 RETURN_STMT_EXPR (return_stmt));
456 STMT_IS_FULL_EXPR_P (*tp) = 1;
457 /* And then jump to the end of the function. */
458 TREE_CHAIN (*tp) = goto_stmt;
460 #else /* INLINER_FOR_JAVA */
461 if (assignment)
463 copy_body_r (&assignment, walk_subtrees, data);
464 *tp = build (COMPOUND_EXPR, void_type_node, assignment, goto_stmt);
465 TREE_SIDE_EFFECTS (*tp) = 1;
467 #endif /* INLINER_FOR_JAVA */
468 /* If we're not returning anything just do the jump. */
469 else
470 *tp = goto_stmt;
472 /* Local variables and labels need to be replaced by equivalent
473 variables. We don't want to copy static variables; there's only
474 one of those, no matter how many times we inline the containing
475 function. */
476 else if ((*lang_hooks.tree_inlining.auto_var_in_fn_p) (*tp, fn))
478 tree new_decl;
480 /* Remap the declaration. */
481 new_decl = remap_decl (*tp, id);
482 if (! new_decl)
483 abort ();
484 /* Replace this variable with the copy. */
485 STRIP_TYPE_NOPS (new_decl);
486 *tp = new_decl;
488 #if 0
489 else if (nonstatic_local_decl_p (*tp)
490 && DECL_CONTEXT (*tp) != VARRAY_TREE (id->fns, 0))
491 abort ();
492 #endif
493 else if (TREE_CODE (*tp) == SAVE_EXPR)
494 remap_save_expr (tp, id->decl_map, VARRAY_TREE (id->fns, 0),
495 walk_subtrees);
496 else if (TREE_CODE (*tp) == UNSAVE_EXPR)
497 /* UNSAVE_EXPRs should not be generated until expansion time. */
498 abort ();
499 #ifndef INLINER_FOR_JAVA
500 /* For a SCOPE_STMT, we must copy the associated block so that we
501 can write out debugging information for the inlined variables. */
502 else if (TREE_CODE (*tp) == SCOPE_STMT && !id->in_target_cleanup_p)
503 copy_scope_stmt (tp, walk_subtrees, id);
504 #else /* INLINER_FOR_JAVA */
505 else if (TREE_CODE (*tp) == LABELED_BLOCK_EXPR)
507 /* We need a new copy of this labeled block; the EXIT_BLOCK_EXPR
508 will refer to it, so save a copy ready for remapping. We
509 save it in the decl_map, although it isn't a decl. */
510 tree new_block = copy_node (*tp);
511 splay_tree_insert (id->decl_map,
512 (splay_tree_key) *tp,
513 (splay_tree_value) new_block);
514 *tp = new_block;
516 else if (TREE_CODE (*tp) == EXIT_BLOCK_EXPR)
518 splay_tree_node n
519 = splay_tree_lookup (id->decl_map,
520 (splay_tree_key) TREE_OPERAND (*tp, 0));
521 /* We _must_ have seen the enclosing LABELED_BLOCK_EXPR. */
522 if (! n)
523 abort ();
524 *tp = copy_node (*tp);
525 TREE_OPERAND (*tp, 0) = (tree) n->value;
527 #endif /* INLINER_FOR_JAVA */
528 /* Otherwise, just copy the node. Note that copy_tree_r already
529 knows not to copy VAR_DECLs, etc., so this is safe. */
530 else
532 if (TREE_CODE (*tp) == MODIFY_EXPR
533 && TREE_OPERAND (*tp, 0) == TREE_OPERAND (*tp, 1)
534 && ((*lang_hooks.tree_inlining.auto_var_in_fn_p)
535 (TREE_OPERAND (*tp, 0), fn)))
537 /* Some assignments VAR = VAR; don't generate any rtl code
538 and thus don't count as variable modification. Avoid
539 keeping bogosities like 0 = 0. */
540 tree decl = TREE_OPERAND (*tp, 0), value;
541 splay_tree_node n;
543 n = splay_tree_lookup (id->decl_map, (splay_tree_key) decl);
544 if (n)
546 value = (tree) n->value;
547 STRIP_TYPE_NOPS (value);
548 if (TREE_CONSTANT (value) || TREE_READONLY_DECL_P (value))
550 *tp = value;
551 return copy_body_r (tp, walk_subtrees, data);
555 else if (TREE_CODE (*tp) == ADDR_EXPR
556 && ((*lang_hooks.tree_inlining.auto_var_in_fn_p)
557 (TREE_OPERAND (*tp, 0), fn)))
559 /* Get rid of &* from inline substitutions. It can occur when
560 someone takes the address of a parm or return slot passed by
561 invisible reference. */
562 tree decl = TREE_OPERAND (*tp, 0), value;
563 splay_tree_node n;
565 n = splay_tree_lookup (id->decl_map, (splay_tree_key) decl);
566 if (n)
568 value = (tree) n->value;
569 if (TREE_CODE (value) == INDIRECT_REF)
571 *tp = convert (TREE_TYPE (*tp), TREE_OPERAND (value, 0));
572 return copy_body_r (tp, walk_subtrees, data);
577 copy_tree_r (tp, walk_subtrees, NULL);
579 /* The copied TARGET_EXPR has never been expanded, even if the
580 original node was expanded already. */
581 if (TREE_CODE (*tp) == TARGET_EXPR && TREE_OPERAND (*tp, 3))
583 TREE_OPERAND (*tp, 1) = TREE_OPERAND (*tp, 3);
584 TREE_OPERAND (*tp, 3) = NULL_TREE;
588 /* Keep iterating. */
589 return NULL_TREE;
592 /* Make a copy of the body of FN so that it can be inserted inline in
593 another function. */
595 static tree
596 copy_body (inline_data *id)
598 tree body;
600 body = DECL_SAVED_TREE (VARRAY_TOP_TREE (id->fns));
601 walk_tree (&body, copy_body_r, id, NULL);
603 return body;
606 /* Generate code to initialize the parameters of the function at the
607 top of the stack in ID from the ARGS (presented as a TREE_LIST). */
609 static tree
610 #ifndef INLINER_FOR_JAVA
611 initialize_inlined_parameters (inline_data *id, tree args, tree fn)
612 #else /* INLINER_FOR_JAVA */
613 initialize_inlined_parameters (inline_data *id, tree args, tree fn, tree block)
614 #endif /* INLINER_FOR_JAVA */
616 tree init_stmts;
617 tree parms;
618 tree a;
619 tree p;
620 #ifdef INLINER_FOR_JAVA
621 tree vars = NULL_TREE;
622 #endif /* INLINER_FOR_JAVA */
624 /* Figure out what the parameters are. */
625 parms = DECL_ARGUMENTS (fn);
627 /* Start with no initializations whatsoever. */
628 init_stmts = NULL_TREE;
630 /* Loop through the parameter declarations, replacing each with an
631 equivalent VAR_DECL, appropriately initialized. */
632 for (p = parms, a = args; p;
633 a = a ? TREE_CHAIN (a) : a, p = TREE_CHAIN (p))
635 #ifndef INLINER_FOR_JAVA
636 tree init_stmt;
637 tree cleanup;
638 #endif /* not INLINER_FOR_JAVA */
639 tree var;
640 tree value;
641 tree var_sub;
643 /* Find the initializer. */
644 value = (*lang_hooks.tree_inlining.convert_parm_for_inlining)
645 (p, a ? TREE_VALUE (a) : NULL_TREE, fn);
647 /* If the parameter is never assigned to, we may not need to
648 create a new variable here at all. Instead, we may be able
649 to just use the argument value. */
650 if (TREE_READONLY (p)
651 && !TREE_ADDRESSABLE (p)
652 && value && !TREE_SIDE_EFFECTS (value))
654 /* Simplify the value, if possible. */
655 value = fold (DECL_P (value) ? decl_constant_value (value) : value);
657 /* We can't risk substituting complex expressions. They
658 might contain variables that will be assigned to later.
659 Theoretically, we could check the expression to see if
660 all of the variables that determine its value are
661 read-only, but we don't bother. */
662 if (TREE_CONSTANT (value) || TREE_READONLY_DECL_P (value))
664 /* If this is a declaration, wrap it a NOP_EXPR so that
665 we don't try to put the VALUE on the list of
666 BLOCK_VARS. */
667 if (DECL_P (value))
668 value = build1 (NOP_EXPR, TREE_TYPE (value), value);
670 /* If this is a constant, make sure it has the right type. */
671 else if (TREE_TYPE (value) != TREE_TYPE (p))
672 value = fold (build1 (NOP_EXPR, TREE_TYPE (p), value));
674 splay_tree_insert (id->decl_map,
675 (splay_tree_key) p,
676 (splay_tree_value) value);
677 continue;
681 /* Make an equivalent VAR_DECL. */
682 var = copy_decl_for_inlining (p, fn, VARRAY_TREE (id->fns, 0));
684 /* See if the frontend wants to pass this by invisible reference. If
685 so, our new VAR_DECL will have REFERENCE_TYPE, and we need to
686 replace uses of the PARM_DECL with dereferences. */
687 if (TREE_TYPE (var) != TREE_TYPE (p)
688 && POINTER_TYPE_P (TREE_TYPE (var))
689 && TREE_TYPE (TREE_TYPE (var)) == TREE_TYPE (p))
690 var_sub = build1 (INDIRECT_REF, TREE_TYPE (p), var);
691 else
692 var_sub = var;
694 /* Register the VAR_DECL as the equivalent for the PARM_DECL;
695 that way, when the PARM_DECL is encountered, it will be
696 automatically replaced by the VAR_DECL. */
697 splay_tree_insert (id->decl_map,
698 (splay_tree_key) p,
699 (splay_tree_value) var_sub);
701 /* Declare this new variable. */
702 #ifndef INLINER_FOR_JAVA
703 init_stmt = build_stmt (DECL_STMT, var);
704 TREE_CHAIN (init_stmt) = init_stmts;
705 init_stmts = init_stmt;
706 #else /* INLINER_FOR_JAVA */
707 TREE_CHAIN (var) = vars;
708 vars = var;
709 #endif /* INLINER_FOR_JAVA */
711 /* Initialize this VAR_DECL from the equivalent argument. If
712 the argument is an object, created via a constructor or copy,
713 this will not result in an extra copy: the TARGET_EXPR
714 representing the argument will be bound to VAR, and the
715 object will be constructed in VAR. */
716 if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (p)))
717 #ifndef INLINER_FOR_JAVA
718 DECL_INITIAL (var) = value;
719 else
721 /* Even if P was TREE_READONLY, the new VAR should not be.
722 In the original code, we would have constructed a
723 temporary, and then the function body would have never
724 changed the value of P. However, now, we will be
725 constructing VAR directly. The constructor body may
726 change its value multiple times as it is being
727 constructed. Therefore, it must not be TREE_READONLY;
728 the back-end assumes that TREE_READONLY variable is
729 assigned to only once. */
730 TREE_READONLY (var) = 0;
732 /* Build a run-time initialization. */
733 init_stmt = build_stmt (EXPR_STMT,
734 build (INIT_EXPR, TREE_TYPE (p),
735 var, value));
736 /* Add this initialization to the list. Note that we want the
737 declaration *after* the initialization because we are going
738 to reverse all the initialization statements below. */
739 TREE_CHAIN (init_stmt) = init_stmts;
740 init_stmts = init_stmt;
743 /* See if we need to clean up the declaration. */
744 cleanup = (*lang_hooks.maybe_build_cleanup) (var);
745 if (cleanup)
747 tree cleanup_stmt;
748 /* Build the cleanup statement. */
749 cleanup_stmt = build_stmt (CLEANUP_STMT, var, cleanup);
750 /* Add it to the *front* of the list; the list will be
751 reversed below. */
752 TREE_CHAIN (cleanup_stmt) = init_stmts;
753 init_stmts = cleanup_stmt;
755 #else /* INLINER_FOR_JAVA */
757 tree assignment = build (MODIFY_EXPR, TREE_TYPE (p), var, value);
758 init_stmts = add_stmt_to_compound (init_stmts, TREE_TYPE (p),
759 assignment);
761 else
763 /* Java objects don't ever need constructing when being
764 passed as arguments because only call by reference is
765 supported. */
766 abort ();
768 #endif /* INLINER_FOR_JAVA */
771 #ifndef INLINER_FOR_JAVA
772 /* Evaluate trailing arguments. */
773 for (; a; a = TREE_CHAIN (a))
775 tree init_stmt;
776 tree value = TREE_VALUE (a);
778 if (! value || ! TREE_SIDE_EFFECTS (value))
779 continue;
781 init_stmt = build_stmt (EXPR_STMT, value);
782 TREE_CHAIN (init_stmt) = init_stmts;
783 init_stmts = init_stmt;
786 /* The initialization statements have been built up in reverse
787 order. Straighten them out now. */
788 return nreverse (init_stmts);
789 #else /* INLINER_FOR_JAVA */
790 BLOCK_VARS (block) = nreverse (vars);
791 return init_stmts;
792 #endif /* INLINER_FOR_JAVA */
795 /* Declare a return variable to replace the RESULT_DECL for the
796 function we are calling. An appropriate DECL_STMT is returned.
797 The USE_STMT is filled in to contain a use of the declaration to
798 indicate the return value of the function. */
800 #ifndef INLINER_FOR_JAVA
801 static tree
802 declare_return_variable (struct inline_data *id, tree return_slot_addr,
803 tree *use_stmt)
804 #else /* INLINER_FOR_JAVA */
805 static tree
806 declare_return_variable (struct inline_data *id, tree return_slot_addr,
807 tree *var)
808 #endif /* INLINER_FOR_JAVA */
810 tree fn = VARRAY_TOP_TREE (id->fns);
811 tree result = DECL_RESULT (fn);
812 #ifndef INLINER_FOR_JAVA
813 tree var;
814 #endif /* not INLINER_FOR_JAVA */
815 int need_return_decl = 1;
817 /* We don't need to do anything for functions that don't return
818 anything. */
819 if (!result || VOID_TYPE_P (TREE_TYPE (result)))
821 #ifndef INLINER_FOR_JAVA
822 *use_stmt = NULL_TREE;
823 #else /* INLINER_FOR_JAVA */
824 *var = NULL_TREE;
825 #endif /* INLINER_FOR_JAVA */
826 return NULL_TREE;
829 #ifndef INLINER_FOR_JAVA
830 var = ((*lang_hooks.tree_inlining.copy_res_decl_for_inlining)
831 (result, fn, VARRAY_TREE (id->fns, 0), id->decl_map,
832 &need_return_decl, return_slot_addr));
834 /* Register the VAR_DECL as the equivalent for the RESULT_DECL; that
835 way, when the RESULT_DECL is encountered, it will be
836 automatically replaced by the VAR_DECL. */
837 splay_tree_insert (id->decl_map,
838 (splay_tree_key) result,
839 (splay_tree_value) var);
841 /* Build the USE_STMT. If the return type of the function was
842 promoted, convert it back to the expected type. */
843 if (TREE_TYPE (var) == TREE_TYPE (TREE_TYPE (fn)))
844 *use_stmt = build_stmt (EXPR_STMT, var);
845 else
846 *use_stmt = build_stmt (EXPR_STMT,
847 build1 (NOP_EXPR, TREE_TYPE (TREE_TYPE (fn)),
848 var));
849 TREE_ADDRESSABLE (*use_stmt) = 1;
851 /* Build the declaration statement if FN does not return an
852 aggregate. */
853 if (need_return_decl)
854 return build_stmt (DECL_STMT, var);
855 #else /* INLINER_FOR_JAVA */
856 *var = ((*lang_hooks.tree_inlining.copy_res_decl_for_inlining)
857 (result, fn, VARRAY_TREE (id->fns, 0), id->decl_map,
858 &need_return_decl, return_slot_addr));
860 splay_tree_insert (id->decl_map,
861 (splay_tree_key) result,
862 (splay_tree_value) *var);
863 DECL_IGNORED_P (*var) = 1;
864 if (need_return_decl)
865 return *var;
866 #endif /* INLINER_FOR_JAVA */
867 /* If FN does return an aggregate, there's no need to declare the
868 return variable; we're using a variable in our caller's frame. */
869 else
870 return NULL_TREE;
873 /* Returns nonzero if a function can be inlined as a tree. */
876 tree_inlinable_function_p (tree fn, int nolimit)
878 return inlinable_function_p (fn, NULL, nolimit);
881 /* If *TP is possibly call to alloca, return nonzero. */
882 static tree
883 find_alloca_call_1 (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
884 void *data ATTRIBUTE_UNUSED)
886 if (alloca_call_p (*tp))
887 return *tp;
888 return NULL;
891 /* Return subexpression representing possible alloca call, if any. */
892 static tree
893 find_alloca_call (tree exp)
895 location_t saved_loc = input_location;
896 tree ret = walk_tree_without_duplicates
897 (&exp, find_alloca_call_1, NULL);
898 input_location = saved_loc;
899 return ret;
902 static tree
903 find_builtin_longjmp_call_1 (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
904 void *data ATTRIBUTE_UNUSED)
906 tree exp = *tp, decl;
908 if (TREE_CODE (exp) == CALL_EXPR
909 && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
910 && (decl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
911 TREE_CODE (decl) == FUNCTION_DECL)
912 && DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
913 && DECL_FUNCTION_CODE (decl) == BUILT_IN_LONGJMP)
914 return decl;
916 return NULL;
919 static tree
920 find_builtin_longjmp_call (tree exp)
922 location_t saved_loc = input_location;
923 tree ret = walk_tree_without_duplicates
924 (&exp, find_builtin_longjmp_call_1, NULL);
925 input_location = saved_loc;
926 return ret;
929 /* Returns nonzero if FN is a function that can be inlined into the
930 inlining context ID_. If ID_ is NULL, check whether the function
931 can be inlined at all. */
933 static int
934 inlinable_function_p (tree fn, inline_data *id, int nolimit)
936 int inlinable;
937 int currfn_insns = 0;
938 int max_inline_insns_single = MAX_INLINE_INSNS_SINGLE;
940 /* If we've already decided this function shouldn't be inlined,
941 there's no need to check again. */
942 if (DECL_UNINLINABLE (fn))
943 return 0;
945 /* See if there is any language-specific reason it cannot be
946 inlined. (It is important that this hook be called early because
947 in C++ it may result in template instantiation.) */
948 inlinable = !(*lang_hooks.tree_inlining.cannot_inline_tree_fn) (&fn);
950 /* We may be here either because fn is declared inline or because
951 we use -finline-functions. For the second case, we are more
952 restrictive. */
953 if (DID_INLINE_FUNC (fn))
954 max_inline_insns_single = MAX_INLINE_INSNS_AUTO;
956 /* The number of instructions (estimated) of current function. */
957 if (!nolimit && !DECL_ESTIMATED_INSNS (fn))
958 DECL_ESTIMATED_INSNS (fn)
959 = (*lang_hooks.tree_inlining.estimate_num_insns) (fn);
960 currfn_insns = DECL_ESTIMATED_INSNS (fn);
962 /* If we're not inlining things, then nothing is inlinable. */
963 if (! flag_inline_trees)
964 inlinable = 0;
965 /* If we're not inlining all functions and the function was not
966 declared `inline', we don't inline it. Don't think of
967 disregarding DECL_INLINE when flag_inline_trees == 2; it's the
968 front-end that must set DECL_INLINE in this case, because
969 dwarf2out loses if a function is inlined that doesn't have
970 DECL_INLINE set. */
971 else if (! DECL_INLINE (fn) && !nolimit)
972 inlinable = 0;
973 #ifdef INLINER_FOR_JAVA
974 /* Synchronized methods can't be inlined. This is a bug. */
975 else if (METHOD_SYNCHRONIZED (fn))
976 inlinable = 0;
977 #endif /* INLINER_FOR_JAVA */
978 /* We can't inline functions that are too big. Only allow a single
979 function to be of MAX_INLINE_INSNS_SINGLE size. Make special
980 allowance for extern inline functions, though. */
981 else if (!nolimit
982 && ! (*lang_hooks.tree_inlining.disregard_inline_limits) (fn)
983 && currfn_insns > max_inline_insns_single)
984 inlinable = 0;
985 /* We can't inline functions that call __builtin_longjmp at all.
986 The non-local goto machinery really requires the destination
987 be in a different function. If we allow the function calling
988 __builtin_longjmp to be inlined into the function calling
989 __builtin_setjmp, Things will Go Awry. */
990 /* ??? Need front end help to identify "regular" non-local goto. */
991 else if (find_builtin_longjmp_call (DECL_SAVED_TREE (fn)))
992 inlinable = 0;
993 /* Refuse to inline alloca call unless user explicitly forced so as this may
994 change program's memory overhead drastically when the function using alloca
995 is called in loop. In GCC present in SPEC2000 inlining into schedule_block
996 cause it to require 2GB of ram instead of 256MB. */
997 else if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)) == NULL
998 && find_alloca_call (DECL_SAVED_TREE (fn)))
999 inlinable = 0;
1001 /* Squirrel away the result so that we don't have to check again. */
1002 DECL_UNINLINABLE (fn) = ! inlinable;
1004 /* In case we don't disregard the inlining limits and we basically
1005 can inline this function, investigate further. */
1006 if (! (*lang_hooks.tree_inlining.disregard_inline_limits) (fn)
1007 && inlinable && !nolimit)
1009 int sum_insns = (id ? id->inlined_insns : 0) + currfn_insns;
1010 /* In the extreme case that we have exceeded the recursive inlining
1011 limit by a huge factor (128), we just say no. Should not happen
1012 in real life. */
1013 if (sum_insns > MAX_INLINE_INSNS * 128)
1014 inlinable = 0;
1015 /* If we did not hit the extreme limit, we use a linear function
1016 with slope -1/MAX_INLINE_SLOPE to exceedingly decrease the
1017 allowable size. We always allow a size of MIN_INLINE_INSNS
1018 though. */
1019 else if ((sum_insns > MAX_INLINE_INSNS)
1020 && (currfn_insns > MIN_INLINE_INSNS))
1022 int max_curr = MAX_INLINE_INSNS_SINGLE
1023 - (sum_insns - MAX_INLINE_INSNS) / MAX_INLINE_SLOPE;
1024 if (currfn_insns > max_curr)
1025 inlinable = 0;
1029 /* If we don't have the function body available, we can't inline
1030 it. */
1031 if (! DECL_SAVED_TREE (fn))
1032 inlinable = 0;
1034 /* Check again, language hooks may have modified it. */
1035 if (! inlinable || DECL_UNINLINABLE (fn))
1036 return 0;
1038 /* Don't do recursive inlining, either. We don't record this in
1039 DECL_UNINLINABLE; we may be able to inline this function later. */
1040 if (id)
1042 size_t i;
1044 for (i = 0; i < VARRAY_ACTIVE_SIZE (id->fns); ++i)
1045 if (VARRAY_TREE (id->fns, i) == fn)
1046 return 0;
1048 if (DECL_INLINED_FNS (fn))
1050 int j;
1051 tree inlined_fns = DECL_INLINED_FNS (fn);
1053 for (j = 0; j < TREE_VEC_LENGTH (inlined_fns); ++j)
1054 if (TREE_VEC_ELT (inlined_fns, j) == VARRAY_TREE (id->fns, 0))
1055 return 0;
1059 /* Return the result. */
1060 return inlinable;
1063 /* If *TP is a CALL_EXPR, replace it with its inline expansion. */
1065 static tree
1066 expand_call_inline (tree *tp, int *walk_subtrees, void *data)
1068 inline_data *id;
1069 tree t;
1070 tree expr;
1071 tree stmt;
1072 #ifndef INLINER_FOR_JAVA
1073 tree chain;
1074 tree scope_stmt;
1075 tree use_stmt;
1076 #else /* INLINER_FOR_JAVA */
1077 tree retvar;
1078 #endif /* INLINER_FOR_JAVA */
1079 tree fn;
1080 tree arg_inits;
1081 tree *inlined_body;
1082 splay_tree st;
1083 tree args;
1084 tree return_slot_addr;
1086 /* See what we've got. */
1087 id = (inline_data *) data;
1088 t = *tp;
1090 /* Recurse, but letting recursive invocations know that we are
1091 inside the body of a TARGET_EXPR. */
1092 if (TREE_CODE (*tp) == TARGET_EXPR)
1094 #ifndef INLINER_FOR_JAVA
1095 int i, len = first_rtl_op (TARGET_EXPR);
1097 /* We're walking our own subtrees. */
1098 *walk_subtrees = 0;
1100 /* Actually walk over them. This loop is the body of
1101 walk_trees, omitting the case where the TARGET_EXPR
1102 itself is handled. */
1103 for (i = 0; i < len; ++i)
1105 if (i == 2)
1106 ++id->in_target_cleanup_p;
1107 walk_tree (&TREE_OPERAND (*tp, i), expand_call_inline, data,
1108 id->tree_pruner);
1109 if (i == 2)
1110 --id->in_target_cleanup_p;
1113 return NULL_TREE;
1114 #else /* INLINER_FOR_JAVA */
1115 abort ();
1116 #endif /* INLINER_FOR_JAVA */
1118 else if (TREE_CODE (t) == EXPR_WITH_FILE_LOCATION)
1120 /* We're walking the subtree directly. */
1121 *walk_subtrees = 0;
1122 /* Update the source position. */
1123 push_srcloc (EXPR_WFL_FILENAME (t), EXPR_WFL_LINENO (t));
1124 walk_tree (&EXPR_WFL_NODE (t), expand_call_inline, data,
1125 id->tree_pruner);
1126 /* Restore the original source position. */
1127 pop_srcloc ();
1129 return NULL_TREE;
1132 if (TYPE_P (t))
1133 /* Because types were not copied in copy_body, CALL_EXPRs beneath
1134 them should not be expanded. This can happen if the type is a
1135 dynamic array type, for example. */
1136 *walk_subtrees = 0;
1138 /* From here on, we're only interested in CALL_EXPRs. */
1139 if (TREE_CODE (t) != CALL_EXPR)
1140 return NULL_TREE;
1142 /* First, see if we can figure out what function is being called.
1143 If we cannot, then there is no hope of inlining the function. */
1144 fn = get_callee_fndecl (t);
1145 if (!fn)
1146 return NULL_TREE;
1148 /* If fn is a declaration of a function in a nested scope that was
1149 globally declared inline, we don't set its DECL_INITIAL.
1150 However, we can't blindly follow DECL_ABSTRACT_ORIGIN because the
1151 C++ front-end uses it for cdtors to refer to their internal
1152 declarations, that are not real functions. Fortunately those
1153 don't have trees to be saved, so we can tell by checking their
1154 DECL_SAVED_TREE. */
1155 if (! DECL_INITIAL (fn)
1156 && DECL_ABSTRACT_ORIGIN (fn)
1157 && DECL_SAVED_TREE (DECL_ABSTRACT_ORIGIN (fn)))
1158 fn = DECL_ABSTRACT_ORIGIN (fn);
1160 /* Don't try to inline functions that are not well-suited to
1161 inlining. */
1162 if ((!flag_unit_at_a_time || !DECL_SAVED_TREE (fn)
1163 || !cgraph_global_info (fn)->inline_once)
1164 && !inlinable_function_p (fn, id, 0))
1166 if (warn_inline && DECL_INLINE (fn) && !DID_INLINE_FUNC (fn)
1167 && !DECL_IN_SYSTEM_HEADER (fn))
1169 warning_with_decl (fn, "inlining failed in call to `%s'");
1170 warning ("called from here");
1172 return NULL_TREE;
1175 if (! (*lang_hooks.tree_inlining.start_inlining) (fn))
1176 return NULL_TREE;
1178 /* Set the current filename and line number to the function we are
1179 inlining so that when we create new _STMT nodes here they get
1180 line numbers corresponding to the function we are calling. We
1181 wrap the whole inlined body in an EXPR_WITH_FILE_AND_LINE as well
1182 because individual statements don't record the filename. */
1183 push_srcloc (DECL_SOURCE_FILE (fn), DECL_SOURCE_LINE (fn));
1185 #ifndef INLINER_FOR_JAVA
1186 /* Build a statement-expression containing code to initialize the
1187 arguments, the actual inline expansion of the body, and a label
1188 for the return statements within the function to jump to. The
1189 type of the statement expression is the return type of the
1190 function call. */
1191 expr = build1 (STMT_EXPR, TREE_TYPE (TREE_TYPE (fn)), make_node (COMPOUND_STMT));
1192 /* There is no scope associated with the statement-expression. */
1193 STMT_EXPR_NO_SCOPE (expr) = 1;
1194 stmt = STMT_EXPR_STMT (expr);
1195 #else /* INLINER_FOR_JAVA */
1196 /* Build a block containing code to initialize the arguments, the
1197 actual inline expansion of the body, and a label for the return
1198 statements within the function to jump to. The type of the
1199 statement expression is the return type of the function call. */
1200 stmt = NULL;
1201 expr = build (BLOCK, TREE_TYPE (TREE_TYPE (fn)), stmt);
1202 #endif /* INLINER_FOR_JAVA */
1204 /* Local declarations will be replaced by their equivalents in this
1205 map. */
1206 st = id->decl_map;
1207 id->decl_map = splay_tree_new (splay_tree_compare_pointers,
1208 NULL, NULL);
1210 /* Initialize the parameters. */
1211 args = TREE_OPERAND (t, 1);
1212 return_slot_addr = NULL_TREE;
1213 if (CALL_EXPR_HAS_RETURN_SLOT_ADDR (t))
1215 return_slot_addr = TREE_VALUE (args);
1216 args = TREE_CHAIN (args);
1219 #ifndef INLINER_FOR_JAVA
1220 arg_inits = initialize_inlined_parameters (id, args, fn);
1221 /* Expand any inlined calls in the initializers. Do this before we
1222 push FN on the stack of functions we are inlining; we want to
1223 inline calls to FN that appear in the initializers for the
1224 parameters. */
1225 expand_calls_inline (&arg_inits, id);
1226 /* And add them to the tree. */
1227 COMPOUND_BODY (stmt) = chainon (COMPOUND_BODY (stmt), arg_inits);
1228 #else /* INLINER_FOR_JAVA */
1229 arg_inits = initialize_inlined_parameters (id, args, fn, expr);
1230 if (arg_inits)
1232 /* Expand any inlined calls in the initializers. Do this before we
1233 push FN on the stack of functions we are inlining; we want to
1234 inline calls to FN that appear in the initializers for the
1235 parameters. */
1236 expand_calls_inline (&arg_inits, id);
1238 /* And add them to the tree. */
1239 BLOCK_EXPR_BODY (expr) = add_stmt_to_compound (BLOCK_EXPR_BODY (expr),
1240 TREE_TYPE (arg_inits),
1241 arg_inits);
1243 #endif /* INLINER_FOR_JAVA */
1245 /* Record the function we are about to inline so that we can avoid
1246 recursing into it. */
1247 VARRAY_PUSH_TREE (id->fns, fn);
1249 /* Record the function we are about to inline if optimize_function
1250 has not been called on it yet and we don't have it in the list. */
1251 if (! DECL_INLINED_FNS (fn))
1253 int i;
1255 for (i = VARRAY_ACTIVE_SIZE (id->inlined_fns) - 1; i >= 0; i--)
1256 if (VARRAY_TREE (id->inlined_fns, i) == fn)
1257 break;
1258 if (i < 0)
1259 VARRAY_PUSH_TREE (id->inlined_fns, fn);
1262 /* Return statements in the function body will be replaced by jumps
1263 to the RET_LABEL. */
1264 id->ret_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1265 DECL_CONTEXT (id->ret_label) = VARRAY_TREE (id->fns, 0);
1267 if (! DECL_INITIAL (fn)
1268 || TREE_CODE (DECL_INITIAL (fn)) != BLOCK)
1269 abort ();
1271 #ifndef INLINER_FOR_JAVA
1272 /* Create a block to put the parameters in. We have to do this
1273 after the parameters have been remapped because remapping
1274 parameters is different from remapping ordinary variables. */
1275 scope_stmt = build_stmt (SCOPE_STMT, DECL_INITIAL (fn));
1276 SCOPE_BEGIN_P (scope_stmt) = 1;
1277 SCOPE_NO_CLEANUPS_P (scope_stmt) = 1;
1278 remap_block (scope_stmt, DECL_ARGUMENTS (fn), id);
1279 TREE_CHAIN (scope_stmt) = COMPOUND_BODY (stmt);
1280 COMPOUND_BODY (stmt) = scope_stmt;
1282 /* Tell the debugging backends that this block represents the
1283 outermost scope of the inlined function. */
1284 if (SCOPE_STMT_BLOCK (scope_stmt))
1285 BLOCK_ABSTRACT_ORIGIN (SCOPE_STMT_BLOCK (scope_stmt)) = DECL_ORIGIN (fn);
1287 /* Declare the return variable for the function. */
1288 COMPOUND_BODY (stmt)
1289 = chainon (COMPOUND_BODY (stmt),
1290 declare_return_variable (id, return_slot_addr, &use_stmt));
1291 #else /* INLINER_FOR_JAVA */
1293 /* Declare the return variable for the function. */
1294 tree decl = declare_return_variable (id, return_slot_addr, &retvar);
1295 if (retvar)
1297 tree *next = &BLOCK_VARS (expr);
1298 while (*next)
1299 next = &TREE_CHAIN (*next);
1300 *next = decl;
1303 #endif /* INLINER_FOR_JAVA */
1305 /* After we've initialized the parameters, we insert the body of the
1306 function itself. */
1307 #ifndef INLINER_FOR_JAVA
1308 inlined_body = &COMPOUND_BODY (stmt);
1309 while (*inlined_body)
1310 inlined_body = &TREE_CHAIN (*inlined_body);
1311 *inlined_body = copy_body (id);
1312 #else /* INLINER_FOR_JAVA */
1314 tree new_body;
1315 java_inlining_map_static_initializers (fn, id->decl_map);
1316 new_body = copy_body (id);
1317 TREE_TYPE (new_body) = TREE_TYPE (TREE_TYPE (fn));
1318 BLOCK_EXPR_BODY (expr)
1319 = add_stmt_to_compound (BLOCK_EXPR_BODY (expr),
1320 TREE_TYPE (new_body), new_body);
1321 inlined_body = &BLOCK_EXPR_BODY (expr);
1323 #endif /* INLINER_FOR_JAVA */
1325 /* After the body of the function comes the RET_LABEL. This must come
1326 before we evaluate the returned value below, because that evaluation
1327 may cause RTL to be generated. */
1328 #ifndef INLINER_FOR_JAVA
1329 COMPOUND_BODY (stmt)
1330 = chainon (COMPOUND_BODY (stmt),
1331 build_stmt (LABEL_STMT, id->ret_label));
1332 #else /* INLINER_FOR_JAVA */
1334 tree label = build1 (LABEL_EXPR, void_type_node, id->ret_label);
1335 BLOCK_EXPR_BODY (expr)
1336 = add_stmt_to_compound (BLOCK_EXPR_BODY (expr), void_type_node, label);
1337 TREE_SIDE_EFFECTS (label) = TREE_SIDE_EFFECTS (t);
1339 #endif /* INLINER_FOR_JAVA */
1341 /* Finally, mention the returned value so that the value of the
1342 statement-expression is the returned value of the function. */
1343 #ifndef INLINER_FOR_JAVA
1344 COMPOUND_BODY (stmt) = chainon (COMPOUND_BODY (stmt), use_stmt);
1346 /* Close the block for the parameters. */
1347 scope_stmt = build_stmt (SCOPE_STMT, DECL_INITIAL (fn));
1348 SCOPE_NO_CLEANUPS_P (scope_stmt) = 1;
1349 remap_block (scope_stmt, NULL_TREE, id);
1350 COMPOUND_BODY (stmt)
1351 = chainon (COMPOUND_BODY (stmt), scope_stmt);
1352 #else /* INLINER_FOR_JAVA */
1353 if (retvar)
1355 /* Mention the retvar. If the return type of the function was
1356 promoted, convert it back to the expected type. */
1357 if (TREE_TYPE (TREE_TYPE (fn)) != TREE_TYPE (retvar))
1358 retvar = build1 (NOP_EXPR, TREE_TYPE (TREE_TYPE (fn)), retvar);
1359 BLOCK_EXPR_BODY (expr)
1360 = add_stmt_to_compound (BLOCK_EXPR_BODY (expr),
1361 TREE_TYPE (retvar), retvar);
1364 java_inlining_merge_static_initializers (fn, id->decl_map);
1365 #endif /* INLINER_FOR_JAVA */
1367 /* Clean up. */
1368 splay_tree_delete (id->decl_map);
1369 id->decl_map = st;
1371 /* The new expression has side-effects if the old one did. */
1372 TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (t);
1374 /* Replace the call by the inlined body. Wrap it in an
1375 EXPR_WITH_FILE_LOCATION so that we'll get debugging line notes
1376 pointing to the right place. */
1377 #ifndef INLINER_FOR_JAVA
1378 chain = TREE_CHAIN (*tp);
1379 #endif /* INLINER_FOR_JAVA */
1380 *tp = build_expr_wfl (expr, DECL_SOURCE_FILE (fn), DECL_SOURCE_LINE (fn),
1381 /*col=*/0);
1382 EXPR_WFL_EMIT_LINE_NOTE (*tp) = 1;
1383 #ifndef INLINER_FOR_JAVA
1384 TREE_CHAIN (*tp) = chain;
1385 #endif /* not INLINER_FOR_JAVA */
1386 pop_srcloc ();
1388 /* If the value of the new expression is ignored, that's OK. We
1389 don't warn about this for CALL_EXPRs, so we shouldn't warn about
1390 the equivalent inlined version either. */
1391 TREE_USED (*tp) = 1;
1393 /* Our function now has more statements than it did before. */
1394 DECL_ESTIMATED_INSNS (VARRAY_TREE (id->fns, 0)) += DECL_ESTIMATED_INSNS (fn);
1395 /* For accounting, subtract one for the saved call/ret. */
1396 id->inlined_insns += DECL_ESTIMATED_INSNS (fn) - 1;
1398 /* Update callgraph if needed. */
1399 if (id->decl && flag_unit_at_a_time)
1401 cgraph_remove_call (id->decl, fn);
1402 cgraph_create_edges (id->decl, *inlined_body);
1405 /* Recurse into the body of the just inlined function. */
1406 expand_calls_inline (inlined_body, id);
1407 VARRAY_POP (id->fns);
1409 /* If we've returned to the top level, clear out the record of how
1410 much inlining has been done. */
1411 if (VARRAY_ACTIVE_SIZE (id->fns) == id->first_inlined_fn)
1412 id->inlined_insns = 0;
1414 /* Don't walk into subtrees. We've already handled them above. */
1415 *walk_subtrees = 0;
1417 (*lang_hooks.tree_inlining.end_inlining) (fn);
1419 /* Keep iterating. */
1420 return NULL_TREE;
1422 /* Walk over the entire tree *TP, replacing CALL_EXPRs with inline
1423 expansions as appropriate. */
1425 static void
1426 expand_calls_inline (tree *tp, inline_data *id)
1428 /* Search through *TP, replacing all calls to inline functions by
1429 appropriate equivalents. Use walk_tree in no-duplicates mode
1430 to avoid exponential time complexity. (We can't just use
1431 walk_tree_without_duplicates, because of the special TARGET_EXPR
1432 handling in expand_calls. The hash table is set up in
1433 optimize_function. */
1434 walk_tree (tp, expand_call_inline, id, id->tree_pruner);
1437 /* Expand calls to inline functions in the body of FN. */
1439 void
1440 optimize_inline_calls (tree fn)
1442 inline_data id;
1443 tree prev_fn;
1445 /* Clear out ID. */
1446 memset (&id, 0, sizeof (id));
1448 id.decl = fn;
1449 /* Don't allow recursion into FN. */
1450 VARRAY_TREE_INIT (id.fns, 32, "fns");
1451 VARRAY_PUSH_TREE (id.fns, fn);
1452 if (!DECL_ESTIMATED_INSNS (fn))
1453 DECL_ESTIMATED_INSNS (fn)
1454 = (*lang_hooks.tree_inlining.estimate_num_insns) (fn);
1455 /* Or any functions that aren't finished yet. */
1456 prev_fn = NULL_TREE;
1457 if (current_function_decl)
1459 VARRAY_PUSH_TREE (id.fns, current_function_decl);
1460 prev_fn = current_function_decl;
1463 prev_fn = ((*lang_hooks.tree_inlining.add_pending_fn_decls)
1464 (&id.fns, prev_fn));
1466 /* Create the list of functions this call will inline. */
1467 VARRAY_TREE_INIT (id.inlined_fns, 32, "inlined_fns");
1469 /* Keep track of the low-water mark, i.e., the point where the first
1470 real inlining is represented in ID.FNS. */
1471 id.first_inlined_fn = VARRAY_ACTIVE_SIZE (id.fns);
1473 /* Replace all calls to inline functions with the bodies of those
1474 functions. */
1475 id.tree_pruner = htab_create (37, htab_hash_pointer,
1476 htab_eq_pointer, NULL);
1477 expand_calls_inline (&DECL_SAVED_TREE (fn), &id);
1479 /* Clean up. */
1480 htab_delete (id.tree_pruner);
1481 if (DECL_LANG_SPECIFIC (fn))
1483 tree ifn = make_tree_vec (VARRAY_ACTIVE_SIZE (id.inlined_fns));
1485 if (VARRAY_ACTIVE_SIZE (id.inlined_fns))
1486 memcpy (&TREE_VEC_ELT (ifn, 0), &VARRAY_TREE (id.inlined_fns, 0),
1487 VARRAY_ACTIVE_SIZE (id.inlined_fns) * sizeof (tree));
1488 DECL_INLINED_FNS (fn) = ifn;
1492 /* FN is a function that has a complete body, and CLONE is a function
1493 whose body is to be set to a copy of FN, mapping argument
1494 declarations according to the ARG_MAP splay_tree. */
1496 void
1497 clone_body (tree clone, tree fn, void *arg_map)
1499 inline_data id;
1501 /* Clone the body, as if we were making an inline call. But, remap
1502 the parameters in the callee to the parameters of caller. If
1503 there's an in-charge parameter, map it to an appropriate
1504 constant. */
1505 memset (&id, 0, sizeof (id));
1506 VARRAY_TREE_INIT (id.fns, 2, "fns");
1507 VARRAY_PUSH_TREE (id.fns, clone);
1508 VARRAY_PUSH_TREE (id.fns, fn);
1509 id.decl_map = (splay_tree)arg_map;
1511 /* Cloning is treated slightly differently from inlining. Set
1512 CLONING_P so that it's clear which operation we're performing. */
1513 id.cloning_p = true;
1515 /* Actually copy the body. */
1516 TREE_CHAIN (DECL_SAVED_TREE (clone)) = copy_body (&id);
1519 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal.
1520 FUNC is called with the DATA and the address of each sub-tree. If
1521 FUNC returns a non-NULL value, the traversal is aborted, and the
1522 value returned by FUNC is returned. If HTAB is non-NULL it is used
1523 to record the nodes visited, and to avoid visiting a node more than
1524 once. */
1526 tree
1527 walk_tree (tree *tp, walk_tree_fn func, void *data, void *htab_)
1529 htab_t htab = (htab_t) htab_;
1530 enum tree_code code;
1531 int walk_subtrees;
1532 tree result;
1534 #define WALK_SUBTREE(NODE) \
1535 do \
1537 result = walk_tree (&(NODE), func, data, htab); \
1538 if (result) \
1539 return result; \
1541 while (0)
1543 #define WALK_SUBTREE_TAIL(NODE) \
1544 do \
1546 tp = & (NODE); \
1547 goto tail_recurse; \
1549 while (0)
1551 tail_recurse:
1552 /* Skip empty subtrees. */
1553 if (!*tp)
1554 return NULL_TREE;
1556 if (htab)
1558 void **slot;
1560 /* Don't walk the same tree twice, if the user has requested
1561 that we avoid doing so. */
1562 slot = htab_find_slot (htab, *tp, INSERT);
1563 if (*slot)
1564 return NULL_TREE;
1565 *slot = *tp;
1568 /* Call the function. */
1569 walk_subtrees = 1;
1570 result = (*func) (tp, &walk_subtrees, data);
1572 /* If we found something, return it. */
1573 if (result)
1574 return result;
1576 code = TREE_CODE (*tp);
1578 #ifndef INLINER_FOR_JAVA
1579 /* Even if we didn't, FUNC may have decided that there was nothing
1580 interesting below this point in the tree. */
1581 if (!walk_subtrees)
1583 if (STATEMENT_CODE_P (code) || code == TREE_LIST
1584 || (*lang_hooks.tree_inlining.tree_chain_matters_p) (*tp))
1585 /* But we still need to check our siblings. */
1586 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
1587 else
1588 return NULL_TREE;
1591 /* Handle common cases up front. */
1592 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code))
1593 || TREE_CODE_CLASS (code) == 'r'
1594 || TREE_CODE_CLASS (code) == 's')
1595 #else /* INLINER_FOR_JAVA */
1596 if (code != EXIT_BLOCK_EXPR
1597 && code != SAVE_EXPR
1598 && (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code))
1599 || TREE_CODE_CLASS (code) == 'r'
1600 || TREE_CODE_CLASS (code) == 's'))
1601 #endif /* INLINER_FOR_JAVA */
1603 int i, len;
1605 #ifndef INLINER_FOR_JAVA
1606 /* Set lineno here so we get the right instantiation context
1607 if we call instantiate_decl from inlinable_function_p. */
1608 if (STATEMENT_CODE_P (code) && !STMT_LINENO_FOR_FN_P (*tp))
1609 input_line = STMT_LINENO (*tp);
1610 #endif /* not INLINER_FOR_JAVA */
1612 /* Walk over all the sub-trees of this operand. */
1613 len = first_rtl_op (code);
1614 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
1615 But, we only want to walk once. */
1616 if (code == TARGET_EXPR
1617 && TREE_OPERAND (*tp, 3) == TREE_OPERAND (*tp, 1))
1618 --len;
1619 /* Go through the subtrees. We need to do this in forward order so
1620 that the scope of a FOR_EXPR is handled properly. */
1621 for (i = 0; i < len; ++i)
1622 WALK_SUBTREE (TREE_OPERAND (*tp, i));
1624 #ifndef INLINER_FOR_JAVA
1625 /* For statements, we also walk the chain so that we cover the
1626 entire statement tree. */
1627 if (STATEMENT_CODE_P (code))
1629 if (code == DECL_STMT
1630 && DECL_STMT_DECL (*tp)
1631 && DECL_P (DECL_STMT_DECL (*tp)))
1633 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
1634 into declarations that are just mentioned, rather than
1635 declared; they don't really belong to this part of the tree.
1636 And, we can see cycles: the initializer for a declaration can
1637 refer to the declaration itself. */
1638 WALK_SUBTREE (DECL_INITIAL (DECL_STMT_DECL (*tp)));
1639 WALK_SUBTREE (DECL_SIZE (DECL_STMT_DECL (*tp)));
1640 WALK_SUBTREE (DECL_SIZE_UNIT (DECL_STMT_DECL (*tp)));
1643 /* This can be tail-recursion optimized if we write it this way. */
1644 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
1647 #endif /* not INLINER_FOR_JAVA */
1648 /* We didn't find what we were looking for. */
1649 return NULL_TREE;
1651 else if (TREE_CODE_CLASS (code) == 'd')
1653 WALK_SUBTREE_TAIL (TREE_TYPE (*tp));
1655 else if (TREE_CODE_CLASS (code) == 't')
1657 WALK_SUBTREE (TYPE_SIZE (*tp));
1658 WALK_SUBTREE (TYPE_SIZE_UNIT (*tp));
1659 /* Also examine various special fields, below. */
1662 result = (*lang_hooks.tree_inlining.walk_subtrees) (tp, &walk_subtrees, func,
1663 data, htab);
1664 if (result || ! walk_subtrees)
1665 return result;
1667 /* Not one of the easy cases. We must explicitly go through the
1668 children. */
1669 switch (code)
1671 case ERROR_MARK:
1672 case IDENTIFIER_NODE:
1673 case INTEGER_CST:
1674 case REAL_CST:
1675 case VECTOR_CST:
1676 case STRING_CST:
1677 case REAL_TYPE:
1678 case COMPLEX_TYPE:
1679 case VECTOR_TYPE:
1680 case VOID_TYPE:
1681 case BOOLEAN_TYPE:
1682 case UNION_TYPE:
1683 case ENUMERAL_TYPE:
1684 case BLOCK:
1685 case RECORD_TYPE:
1686 case CHAR_TYPE:
1687 /* None of thse have subtrees other than those already walked
1688 above. */
1689 break;
1691 case POINTER_TYPE:
1692 case REFERENCE_TYPE:
1693 WALK_SUBTREE_TAIL (TREE_TYPE (*tp));
1694 break;
1696 case TREE_LIST:
1697 WALK_SUBTREE (TREE_VALUE (*tp));
1698 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
1699 break;
1701 case TREE_VEC:
1703 int len = TREE_VEC_LENGTH (*tp);
1705 if (len == 0)
1706 break;
1708 /* Walk all elements but the first. */
1709 while (--len)
1710 WALK_SUBTREE (TREE_VEC_ELT (*tp, len));
1712 /* Now walk the first one as a tail call. */
1713 WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp, 0));
1716 case COMPLEX_CST:
1717 WALK_SUBTREE (TREE_REALPART (*tp));
1718 WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp));
1720 case CONSTRUCTOR:
1721 WALK_SUBTREE_TAIL (CONSTRUCTOR_ELTS (*tp));
1723 case METHOD_TYPE:
1724 WALK_SUBTREE (TYPE_METHOD_BASETYPE (*tp));
1725 /* Fall through. */
1727 case FUNCTION_TYPE:
1728 WALK_SUBTREE (TREE_TYPE (*tp));
1730 tree arg = TYPE_ARG_TYPES (*tp);
1732 /* We never want to walk into default arguments. */
1733 for (; arg; arg = TREE_CHAIN (arg))
1734 WALK_SUBTREE (TREE_VALUE (arg));
1736 break;
1738 case ARRAY_TYPE:
1739 WALK_SUBTREE (TREE_TYPE (*tp));
1740 WALK_SUBTREE_TAIL (TYPE_DOMAIN (*tp));
1742 case INTEGER_TYPE:
1743 WALK_SUBTREE (TYPE_MIN_VALUE (*tp));
1744 WALK_SUBTREE_TAIL (TYPE_MAX_VALUE (*tp));
1746 case OFFSET_TYPE:
1747 WALK_SUBTREE (TREE_TYPE (*tp));
1748 WALK_SUBTREE_TAIL (TYPE_OFFSET_BASETYPE (*tp));
1750 #ifdef INLINER_FOR_JAVA
1751 case EXIT_BLOCK_EXPR:
1752 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, 1));
1754 case SAVE_EXPR:
1755 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, 0));
1756 #endif /* INLINER_FOR_JAVA */
1758 default:
1759 abort ();
1762 /* We didn't find what we were looking for. */
1763 return NULL_TREE;
1765 #undef WALK_SUBTREE
1766 #undef WALK_SUBTREE_TAIL
1769 /* Like walk_tree, but does not walk duplicate nodes more than
1770 once. */
1772 tree
1773 walk_tree_without_duplicates (tree *tp, walk_tree_fn func, void *data)
1775 tree result;
1776 htab_t htab;
1778 htab = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
1779 result = walk_tree (tp, func, data, htab);
1780 htab_delete (htab);
1781 return result;
1784 /* Passed to walk_tree. Copies the node pointed to, if appropriate. */
1786 tree
1787 copy_tree_r (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
1789 enum tree_code code = TREE_CODE (*tp);
1791 /* We make copies of most nodes. */
1792 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code))
1793 || TREE_CODE_CLASS (code) == 'r'
1794 || TREE_CODE_CLASS (code) == 'c'
1795 || TREE_CODE_CLASS (code) == 's'
1796 || code == TREE_LIST
1797 || code == TREE_VEC
1798 || (*lang_hooks.tree_inlining.tree_chain_matters_p) (*tp))
1800 /* Because the chain gets clobbered when we make a copy, we save it
1801 here. */
1802 tree chain = TREE_CHAIN (*tp);
1804 /* Copy the node. */
1805 *tp = copy_node (*tp);
1807 /* Now, restore the chain, if appropriate. That will cause
1808 walk_tree to walk into the chain as well. */
1809 if (code == PARM_DECL || code == TREE_LIST
1810 #ifndef INLINER_FOR_JAVA
1811 || (*lang_hooks.tree_inlining.tree_chain_matters_p) (*tp)
1812 || STATEMENT_CODE_P (code))
1813 TREE_CHAIN (*tp) = chain;
1815 /* For now, we don't update BLOCKs when we make copies. So, we
1816 have to nullify all scope-statements. */
1817 if (TREE_CODE (*tp) == SCOPE_STMT)
1818 SCOPE_STMT_BLOCK (*tp) = NULL_TREE;
1819 #else /* INLINER_FOR_JAVA */
1820 || (*lang_hooks.tree_inlining.tree_chain_matters_p) (*tp))
1821 TREE_CHAIN (*tp) = chain;
1822 #endif /* INLINER_FOR_JAVA */
1824 else if (TREE_CODE_CLASS (code) == 't' && !variably_modified_type_p (*tp))
1825 /* Types only need to be copied if they are variably modified. */
1826 *walk_subtrees = 0;
1828 return NULL_TREE;
1831 /* The SAVE_EXPR pointed to by TP is being copied. If ST contains
1832 information indicating to what new SAVE_EXPR this one should be
1833 mapped, use that one. Otherwise, create a new node and enter it in
1834 ST. FN is the function into which the copy will be placed. */
1836 void
1837 remap_save_expr (tree *tp, void *st_, tree fn, int *walk_subtrees)
1839 splay_tree st = (splay_tree) st_;
1840 splay_tree_node n;
1842 /* See if we already encountered this SAVE_EXPR. */
1843 n = splay_tree_lookup (st, (splay_tree_key) *tp);
1845 /* If we didn't already remap this SAVE_EXPR, do so now. */
1846 if (!n)
1848 tree t = copy_node (*tp);
1850 /* The SAVE_EXPR is now part of the function into which we
1851 are inlining this body. */
1852 SAVE_EXPR_CONTEXT (t) = fn;
1853 /* And we haven't evaluated it yet. */
1854 SAVE_EXPR_RTL (t) = NULL_RTX;
1855 /* Remember this SAVE_EXPR. */
1856 n = splay_tree_insert (st,
1857 (splay_tree_key) *tp,
1858 (splay_tree_value) t);
1859 /* Make sure we don't remap an already-remapped SAVE_EXPR. */
1860 splay_tree_insert (st, (splay_tree_key) t,
1861 (splay_tree_value) error_mark_node);
1863 else
1864 /* We've already walked into this SAVE_EXPR, so we needn't do it
1865 again. */
1866 *walk_subtrees = 0;
1868 /* Replace this SAVE_EXPR with the copy. */
1869 *tp = (tree) n->value;
1872 #ifdef INLINER_FOR_JAVA
1873 /* Add STMT to EXISTING if possible, otherwise create a new
1874 COMPOUND_EXPR and add STMT to it. */
1876 static tree
1877 add_stmt_to_compound (tree existing, tree type, tree stmt)
1879 if (!stmt)
1880 return existing;
1881 else if (existing)
1882 return build (COMPOUND_EXPR, type, existing, stmt);
1883 else
1884 return stmt;
1887 #endif /* INLINER_FOR_JAVA */