2003-07-08 Steven Bosscher <steven@gcc.gnu.org>
[official-gcc.git] / gcc / tree-inline.c
blobc41ccea5e832f573ef33d732ac6739072c49600b
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 statements we have inlined in the
97 current call stack. */
98 int inlined_stmts;
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 /* The approximate number of instructions per statement. This number
135 need not be particularly accurate; it is used only to make
136 decisions about when a function is too big to inline. */
137 #define INSNS_PER_STMT (10)
139 /* Remap DECL during the copying of the BLOCK tree for the function. */
141 static tree
142 remap_decl (tree decl, inline_data *id)
144 splay_tree_node n;
145 tree fn;
147 /* We only remap local variables in the current function. */
148 fn = VARRAY_TOP_TREE (id->fns);
149 if (! (*lang_hooks.tree_inlining.auto_var_in_fn_p) (decl, fn))
150 return NULL_TREE;
152 /* See if we have remapped this declaration. */
153 n = splay_tree_lookup (id->decl_map, (splay_tree_key) decl);
154 /* If we didn't already have an equivalent for this declaration,
155 create one now. */
156 if (!n)
158 tree t;
160 /* Make a copy of the variable or label. */
161 t = copy_decl_for_inlining (decl, fn,
162 VARRAY_TREE (id->fns, 0));
164 /* The decl T could be a dynamic array or other variable size type,
165 in which case some fields need to be remapped because they may
166 contain SAVE_EXPRs. */
167 if (TREE_TYPE (t) && TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
168 && TYPE_DOMAIN (TREE_TYPE (t)))
170 TREE_TYPE (t) = copy_node (TREE_TYPE (t));
171 TYPE_DOMAIN (TREE_TYPE (t))
172 = copy_node (TYPE_DOMAIN (TREE_TYPE (t)));
173 walk_tree (&TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (t))),
174 copy_body_r, id, NULL);
177 #ifndef INLINER_FOR_JAVA
178 if (! DECL_NAME (t) && TREE_TYPE (t)
179 && (*lang_hooks.tree_inlining.anon_aggr_type_p) (TREE_TYPE (t)))
181 /* For a VAR_DECL of anonymous type, we must also copy the
182 member VAR_DECLS here and rechain the
183 DECL_ANON_UNION_ELEMS. */
184 tree members = NULL;
185 tree src;
187 for (src = DECL_ANON_UNION_ELEMS (t); src;
188 src = TREE_CHAIN (src))
190 tree member = remap_decl (TREE_VALUE (src), id);
192 if (TREE_PURPOSE (src))
193 abort ();
194 members = tree_cons (NULL, member, members);
196 DECL_ANON_UNION_ELEMS (t) = nreverse (members);
198 #endif /* not INLINER_FOR_JAVA */
200 /* Remember it, so that if we encounter this local entity
201 again we can reuse this copy. */
202 n = splay_tree_insert (id->decl_map,
203 (splay_tree_key) decl,
204 (splay_tree_value) t);
207 return (tree) n->value;
210 #ifndef INLINER_FOR_JAVA
211 /* Copy the SCOPE_STMT_BLOCK associated with SCOPE_STMT to contain
212 remapped versions of the variables therein. And hook the new block
213 into the block-tree. If non-NULL, the DECLS are declarations to
214 add to use instead of the BLOCK_VARS in the old block. */
215 #else /* INLINER_FOR_JAVA */
216 /* Copy the BLOCK to contain remapped versions of the variables
217 therein. And hook the new block into the block-tree. */
218 #endif /* INLINER_FOR_JAVA */
220 static void
221 #ifndef INLINER_FOR_JAVA
222 remap_block (tree scope_stmt, tree decls, inline_data *id)
223 #else /* INLINER_FOR_JAVA */
224 remap_block (tree *block, tree decls, inline_data *id)
225 #endif /* INLINER_FOR_JAVA */
227 #ifndef INLINER_FOR_JAVA
228 /* We cannot do this in the cleanup for a TARGET_EXPR since we do
229 not know whether or not expand_expr will actually write out the
230 code we put there. If it does not, then we'll have more BLOCKs
231 than block-notes, and things will go awry. At some point, we
232 should make the back-end handle BLOCK notes in a tidier way,
233 without requiring a strict correspondence to the block-tree; then
234 this check can go. */
235 if (id->in_target_cleanup_p)
237 SCOPE_STMT_BLOCK (scope_stmt) = NULL_TREE;
238 return;
241 /* If this is the beginning of a scope, remap the associated BLOCK. */
242 if (SCOPE_BEGIN_P (scope_stmt) && SCOPE_STMT_BLOCK (scope_stmt))
244 tree old_block;
245 tree new_block;
246 tree old_var;
247 tree fn;
249 /* Make the new block. */
250 old_block = SCOPE_STMT_BLOCK (scope_stmt);
251 new_block = make_node (BLOCK);
252 TREE_USED (new_block) = TREE_USED (old_block);
253 BLOCK_ABSTRACT_ORIGIN (new_block) = old_block;
254 SCOPE_STMT_BLOCK (scope_stmt) = new_block;
256 /* Remap its variables. */
257 for (old_var = decls ? decls : BLOCK_VARS (old_block);
258 old_var;
259 old_var = TREE_CHAIN (old_var))
261 tree new_var;
263 /* Remap the variable. */
264 new_var = remap_decl (old_var, id);
265 /* If we didn't remap this variable, so we can't mess with
266 its TREE_CHAIN. If we remapped this variable to
267 something other than a declaration (say, if we mapped it
268 to a constant), then we must similarly omit any mention
269 of it here. */
270 if (!new_var || !DECL_P (new_var))
272 else
274 TREE_CHAIN (new_var) = BLOCK_VARS (new_block);
275 BLOCK_VARS (new_block) = new_var;
278 /* We put the BLOCK_VARS in reverse order; fix that now. */
279 BLOCK_VARS (new_block) = nreverse (BLOCK_VARS (new_block));
280 fn = VARRAY_TREE (id->fns, 0);
281 if (id->cloning_p)
282 /* We're building a clone; DECL_INITIAL is still
283 error_mark_node, and current_binding_level is the parm
284 binding level. */
285 (*lang_hooks.decls.insert_block) (new_block);
286 else
288 /* Attach this new block after the DECL_INITIAL block for the
289 function into which this block is being inlined. In
290 rest_of_compilation we will straighten out the BLOCK tree. */
291 tree *first_block;
292 if (DECL_INITIAL (fn))
293 first_block = &BLOCK_CHAIN (DECL_INITIAL (fn));
294 else
295 first_block = &DECL_INITIAL (fn);
296 BLOCK_CHAIN (new_block) = *first_block;
297 *first_block = new_block;
299 /* Remember the remapped block. */
300 splay_tree_insert (id->decl_map,
301 (splay_tree_key) old_block,
302 (splay_tree_value) new_block);
304 /* If this is the end of a scope, set the SCOPE_STMT_BLOCK to be the
305 remapped block. */
306 else if (SCOPE_END_P (scope_stmt) && SCOPE_STMT_BLOCK (scope_stmt))
308 splay_tree_node n;
310 /* Find this block in the table of remapped things. */
311 n = splay_tree_lookup (id->decl_map,
312 (splay_tree_key) SCOPE_STMT_BLOCK (scope_stmt));
313 if (! n)
314 abort ();
315 SCOPE_STMT_BLOCK (scope_stmt) = (tree) n->value;
317 #else /* INLINER_FOR_JAVA */
318 tree old_block;
319 tree new_block;
320 tree old_var;
321 tree fn;
323 /* Make the new block. */
324 old_block = *block;
325 new_block = make_node (BLOCK);
326 TREE_USED (new_block) = TREE_USED (old_block);
327 BLOCK_ABSTRACT_ORIGIN (new_block) = old_block;
328 BLOCK_SUBBLOCKS (new_block) = BLOCK_SUBBLOCKS (old_block);
329 TREE_SIDE_EFFECTS (new_block) = TREE_SIDE_EFFECTS (old_block);
330 TREE_TYPE (new_block) = TREE_TYPE (old_block);
331 *block = new_block;
333 /* Remap its variables. */
334 for (old_var = decls ? decls : BLOCK_VARS (old_block);
335 old_var;
336 old_var = TREE_CHAIN (old_var))
338 tree new_var;
340 /* All local class initialization flags go in the outermost
341 scope. */
342 if (LOCAL_CLASS_INITIALIZATION_FLAG_P (old_var))
344 /* We may already have one. */
345 if (! splay_tree_lookup (id->decl_map, (splay_tree_key) old_var))
347 tree outermost_block;
348 new_var = remap_decl (old_var, id);
349 DECL_ABSTRACT_ORIGIN (new_var) = NULL;
350 outermost_block = DECL_SAVED_TREE (current_function_decl);
351 TREE_CHAIN (new_var) = BLOCK_VARS (outermost_block);
352 BLOCK_VARS (outermost_block) = new_var;
354 continue;
357 /* Remap the variable. */
358 new_var = remap_decl (old_var, id);
359 /* If we didn't remap this variable, so we can't mess with
360 its TREE_CHAIN. If we remapped this variable to
361 something other than a declaration (say, if we mapped it
362 to a constant), then we must similarly omit any mention
363 of it here. */
364 if (!new_var || !DECL_P (new_var))
366 else
368 TREE_CHAIN (new_var) = BLOCK_VARS (new_block);
369 BLOCK_VARS (new_block) = new_var;
372 /* We put the BLOCK_VARS in reverse order; fix that now. */
373 BLOCK_VARS (new_block) = nreverse (BLOCK_VARS (new_block));
374 fn = VARRAY_TREE (id->fns, 0);
375 /* Remember the remapped block. */
376 splay_tree_insert (id->decl_map,
377 (splay_tree_key) old_block,
378 (splay_tree_value) new_block);
379 #endif /* INLINER_FOR_JAVA */
382 #ifndef INLINER_FOR_JAVA
383 /* Copy the SCOPE_STMT pointed to by TP. */
385 static void
386 copy_scope_stmt (tree *tp, int *walk_subtrees, inline_data *id)
388 tree block;
390 /* Remember whether or not this statement was nullified. When
391 making a copy, copy_tree_r always sets SCOPE_NULLIFIED_P (and
392 doesn't copy the SCOPE_STMT_BLOCK) to free callers from having to
393 deal with copying BLOCKs if they do not wish to do so. */
394 block = SCOPE_STMT_BLOCK (*tp);
395 /* Copy (and replace) the statement. */
396 copy_tree_r (tp, walk_subtrees, NULL);
397 /* Restore the SCOPE_STMT_BLOCK. */
398 SCOPE_STMT_BLOCK (*tp) = block;
400 /* Remap the associated block. */
401 remap_block (*tp, NULL_TREE, id);
403 #endif /* not INLINER_FOR_JAVA */
405 /* Called from copy_body via walk_tree. DATA is really an
406 `inline_data *'. */
407 static tree
408 copy_body_r (tree *tp, int *walk_subtrees, void *data)
410 inline_data* id;
411 tree fn;
413 /* Set up. */
414 id = (inline_data *) data;
415 fn = VARRAY_TOP_TREE (id->fns);
417 #if 0
418 /* All automatic variables should have a DECL_CONTEXT indicating
419 what function they come from. */
420 if ((TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == LABEL_DECL)
421 && DECL_NAMESPACE_SCOPE_P (*tp))
422 if (! DECL_EXTERNAL (*tp) && ! TREE_STATIC (*tp))
423 abort ();
424 #endif
426 #ifdef INLINER_FOR_JAVA
427 if (TREE_CODE (*tp) == BLOCK)
428 remap_block (tp, NULL_TREE, id);
429 #endif
431 /* If this is a RETURN_STMT, change it into an EXPR_STMT and a
432 GOTO_STMT with the RET_LABEL as its target. */
433 #ifndef INLINER_FOR_JAVA
434 if (TREE_CODE (*tp) == RETURN_STMT && id->ret_label)
435 #else /* INLINER_FOR_JAVA */
436 if (TREE_CODE (*tp) == RETURN_EXPR && id->ret_label)
437 #endif /* INLINER_FOR_JAVA */
439 tree return_stmt = *tp;
440 tree goto_stmt;
442 /* Build the GOTO_STMT. */
443 #ifndef INLINER_FOR_JAVA
444 goto_stmt = build_stmt (GOTO_STMT, id->ret_label);
445 TREE_CHAIN (goto_stmt) = TREE_CHAIN (return_stmt);
446 GOTO_FAKE_P (goto_stmt) = 1;
447 #else /* INLINER_FOR_JAVA */
448 tree assignment = TREE_OPERAND (return_stmt, 0);
449 goto_stmt = build1 (GOTO_EXPR, void_type_node, id->ret_label);
450 TREE_SIDE_EFFECTS (goto_stmt) = 1;
451 #endif /* INLINER_FOR_JAVA */
453 /* If we're returning something, just turn that into an
454 assignment into the equivalent of the original
455 RESULT_DECL. */
456 #ifndef INLINER_FOR_JAVA
457 if (RETURN_STMT_EXPR (return_stmt))
459 *tp = build_stmt (EXPR_STMT,
460 RETURN_STMT_EXPR (return_stmt));
461 STMT_IS_FULL_EXPR_P (*tp) = 1;
462 /* And then jump to the end of the function. */
463 TREE_CHAIN (*tp) = goto_stmt;
465 #else /* INLINER_FOR_JAVA */
466 if (assignment)
468 copy_body_r (&assignment, walk_subtrees, data);
469 *tp = build (COMPOUND_EXPR, void_type_node, assignment, goto_stmt);
470 TREE_SIDE_EFFECTS (*tp) = 1;
472 #endif /* INLINER_FOR_JAVA */
473 /* If we're not returning anything just do the jump. */
474 else
475 *tp = goto_stmt;
477 /* Local variables and labels need to be replaced by equivalent
478 variables. We don't want to copy static variables; there's only
479 one of those, no matter how many times we inline the containing
480 function. */
481 else if ((*lang_hooks.tree_inlining.auto_var_in_fn_p) (*tp, fn))
483 tree new_decl;
485 /* Remap the declaration. */
486 new_decl = remap_decl (*tp, id);
487 if (! new_decl)
488 abort ();
489 /* Replace this variable with the copy. */
490 STRIP_TYPE_NOPS (new_decl);
491 *tp = new_decl;
493 #if 0
494 else if (nonstatic_local_decl_p (*tp)
495 && DECL_CONTEXT (*tp) != VARRAY_TREE (id->fns, 0))
496 abort ();
497 #endif
498 else if (TREE_CODE (*tp) == SAVE_EXPR)
499 remap_save_expr (tp, id->decl_map, VARRAY_TREE (id->fns, 0),
500 walk_subtrees);
501 else if (TREE_CODE (*tp) == UNSAVE_EXPR)
502 /* UNSAVE_EXPRs should not be generated until expansion time. */
503 abort ();
504 #ifndef INLINER_FOR_JAVA
505 /* For a SCOPE_STMT, we must copy the associated block so that we
506 can write out debugging information for the inlined variables. */
507 else if (TREE_CODE (*tp) == SCOPE_STMT && !id->in_target_cleanup_p)
508 copy_scope_stmt (tp, walk_subtrees, id);
509 #else /* INLINER_FOR_JAVA */
510 else if (TREE_CODE (*tp) == LABELED_BLOCK_EXPR)
512 /* We need a new copy of this labeled block; the EXIT_BLOCK_EXPR
513 will refer to it, so save a copy ready for remapping. We
514 save it in the decl_map, although it isn't a decl. */
515 tree new_block = copy_node (*tp);
516 splay_tree_insert (id->decl_map,
517 (splay_tree_key) *tp,
518 (splay_tree_value) new_block);
519 *tp = new_block;
521 else if (TREE_CODE (*tp) == EXIT_BLOCK_EXPR)
523 splay_tree_node n
524 = splay_tree_lookup (id->decl_map,
525 (splay_tree_key) TREE_OPERAND (*tp, 0));
526 /* We _must_ have seen the enclosing LABELED_BLOCK_EXPR. */
527 if (! n)
528 abort ();
529 *tp = copy_node (*tp);
530 TREE_OPERAND (*tp, 0) = (tree) n->value;
532 #endif /* INLINER_FOR_JAVA */
533 /* Otherwise, just copy the node. Note that copy_tree_r already
534 knows not to copy VAR_DECLs, etc., so this is safe. */
535 else
537 if (TREE_CODE (*tp) == MODIFY_EXPR
538 && TREE_OPERAND (*tp, 0) == TREE_OPERAND (*tp, 1)
539 && ((*lang_hooks.tree_inlining.auto_var_in_fn_p)
540 (TREE_OPERAND (*tp, 0), fn)))
542 /* Some assignments VAR = VAR; don't generate any rtl code
543 and thus don't count as variable modification. Avoid
544 keeping bogosities like 0 = 0. */
545 tree decl = TREE_OPERAND (*tp, 0), value;
546 splay_tree_node n;
548 n = splay_tree_lookup (id->decl_map, (splay_tree_key) decl);
549 if (n)
551 value = (tree) n->value;
552 STRIP_TYPE_NOPS (value);
553 if (TREE_CONSTANT (value) || TREE_READONLY_DECL_P (value))
555 *tp = value;
556 return copy_body_r (tp, walk_subtrees, data);
560 else if (TREE_CODE (*tp) == ADDR_EXPR
561 && ((*lang_hooks.tree_inlining.auto_var_in_fn_p)
562 (TREE_OPERAND (*tp, 0), fn)))
564 /* Get rid of &* from inline substitutions. It can occur when
565 someone takes the address of a parm or return slot passed by
566 invisible reference. */
567 tree decl = TREE_OPERAND (*tp, 0), value;
568 splay_tree_node n;
570 n = splay_tree_lookup (id->decl_map, (splay_tree_key) decl);
571 if (n)
573 value = (tree) n->value;
574 if (TREE_CODE (value) == INDIRECT_REF)
576 *tp = convert (TREE_TYPE (*tp), TREE_OPERAND (value, 0));
577 return copy_body_r (tp, walk_subtrees, data);
582 copy_tree_r (tp, walk_subtrees, NULL);
584 /* The copied TARGET_EXPR has never been expanded, even if the
585 original node was expanded already. */
586 if (TREE_CODE (*tp) == TARGET_EXPR && TREE_OPERAND (*tp, 3))
588 TREE_OPERAND (*tp, 1) = TREE_OPERAND (*tp, 3);
589 TREE_OPERAND (*tp, 3) = NULL_TREE;
593 /* Keep iterating. */
594 return NULL_TREE;
597 /* Make a copy of the body of FN so that it can be inserted inline in
598 another function. */
600 static tree
601 copy_body (inline_data *id)
603 tree body;
605 body = DECL_SAVED_TREE (VARRAY_TOP_TREE (id->fns));
606 walk_tree (&body, copy_body_r, id, NULL);
608 return body;
611 /* Generate code to initialize the parameters of the function at the
612 top of the stack in ID from the ARGS (presented as a TREE_LIST). */
614 static tree
615 #ifndef INLINER_FOR_JAVA
616 initialize_inlined_parameters (inline_data *id, tree args, tree fn)
617 #else /* INLINER_FOR_JAVA */
618 initialize_inlined_parameters (inline_data *id, tree args, tree fn, tree block)
619 #endif /* INLINER_FOR_JAVA */
621 tree init_stmts;
622 tree parms;
623 tree a;
624 tree p;
625 #ifdef INLINER_FOR_JAVA
626 tree vars = NULL_TREE;
627 #endif /* INLINER_FOR_JAVA */
629 /* Figure out what the parameters are. */
630 parms = DECL_ARGUMENTS (fn);
632 /* Start with no initializations whatsoever. */
633 init_stmts = NULL_TREE;
635 /* Loop through the parameter declarations, replacing each with an
636 equivalent VAR_DECL, appropriately initialized. */
637 for (p = parms, a = args; p;
638 a = a ? TREE_CHAIN (a) : a, p = TREE_CHAIN (p))
640 #ifndef INLINER_FOR_JAVA
641 tree init_stmt;
642 tree cleanup;
643 #endif /* not INLINER_FOR_JAVA */
644 tree var;
645 tree value;
646 tree var_sub;
648 /* Find the initializer. */
649 value = (*lang_hooks.tree_inlining.convert_parm_for_inlining)
650 (p, a ? TREE_VALUE (a) : NULL_TREE, fn);
652 /* If the parameter is never assigned to, we may not need to
653 create a new variable here at all. Instead, we may be able
654 to just use the argument value. */
655 if (TREE_READONLY (p)
656 && !TREE_ADDRESSABLE (p)
657 && value && !TREE_SIDE_EFFECTS (value))
659 /* Simplify the value, if possible. */
660 value = fold (DECL_P (value) ? decl_constant_value (value) : value);
662 /* We can't risk substituting complex expressions. They
663 might contain variables that will be assigned to later.
664 Theoretically, we could check the expression to see if
665 all of the variables that determine its value are
666 read-only, but we don't bother. */
667 if (TREE_CONSTANT (value) || TREE_READONLY_DECL_P (value))
669 /* If this is a declaration, wrap it a NOP_EXPR so that
670 we don't try to put the VALUE on the list of
671 BLOCK_VARS. */
672 if (DECL_P (value))
673 value = build1 (NOP_EXPR, TREE_TYPE (value), value);
675 /* If this is a constant, make sure it has the right type. */
676 else if (TREE_TYPE (value) != TREE_TYPE (p))
677 value = fold (build1 (NOP_EXPR, TREE_TYPE (p), value));
679 splay_tree_insert (id->decl_map,
680 (splay_tree_key) p,
681 (splay_tree_value) value);
682 continue;
686 /* Make an equivalent VAR_DECL. */
687 var = copy_decl_for_inlining (p, fn, VARRAY_TREE (id->fns, 0));
689 /* See if the frontend wants to pass this by invisible reference. If
690 so, our new VAR_DECL will have REFERENCE_TYPE, and we need to
691 replace uses of the PARM_DECL with dereferences. */
692 if (TREE_TYPE (var) != TREE_TYPE (p)
693 && POINTER_TYPE_P (TREE_TYPE (var))
694 && TREE_TYPE (TREE_TYPE (var)) == TREE_TYPE (p))
695 var_sub = build1 (INDIRECT_REF, TREE_TYPE (p), var);
696 else
697 var_sub = var;
699 /* Register the VAR_DECL as the equivalent for the PARM_DECL;
700 that way, when the PARM_DECL is encountered, it will be
701 automatically replaced by the VAR_DECL. */
702 splay_tree_insert (id->decl_map,
703 (splay_tree_key) p,
704 (splay_tree_value) var_sub);
706 /* Declare this new variable. */
707 #ifndef INLINER_FOR_JAVA
708 init_stmt = build_stmt (DECL_STMT, var);
709 TREE_CHAIN (init_stmt) = init_stmts;
710 init_stmts = init_stmt;
711 #else /* INLINER_FOR_JAVA */
712 TREE_CHAIN (var) = vars;
713 vars = var;
714 #endif /* INLINER_FOR_JAVA */
716 /* Initialize this VAR_DECL from the equivalent argument. If
717 the argument is an object, created via a constructor or copy,
718 this will not result in an extra copy: the TARGET_EXPR
719 representing the argument will be bound to VAR, and the
720 object will be constructed in VAR. */
721 if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (p)))
722 #ifndef INLINER_FOR_JAVA
723 DECL_INITIAL (var) = value;
724 else
726 /* Even if P was TREE_READONLY, the new VAR should not be.
727 In the original code, we would have constructed a
728 temporary, and then the function body would have never
729 changed the value of P. However, now, we will be
730 constructing VAR directly. The constructor body may
731 change its value multiple times as it is being
732 constructed. Therefore, it must not be TREE_READONLY;
733 the back-end assumes that TREE_READONLY variable is
734 assigned to only once. */
735 TREE_READONLY (var) = 0;
737 /* Build a run-time initialization. */
738 init_stmt = build_stmt (EXPR_STMT,
739 build (INIT_EXPR, TREE_TYPE (p),
740 var, value));
741 /* Add this initialization to the list. Note that we want the
742 declaration *after* the initialization because we are going
743 to reverse all the initialization statements below. */
744 TREE_CHAIN (init_stmt) = init_stmts;
745 init_stmts = init_stmt;
748 /* See if we need to clean up the declaration. */
749 cleanup = (*lang_hooks.maybe_build_cleanup) (var);
750 if (cleanup)
752 tree cleanup_stmt;
753 /* Build the cleanup statement. */
754 cleanup_stmt = build_stmt (CLEANUP_STMT, var, cleanup);
755 /* Add it to the *front* of the list; the list will be
756 reversed below. */
757 TREE_CHAIN (cleanup_stmt) = init_stmts;
758 init_stmts = cleanup_stmt;
760 #else /* INLINER_FOR_JAVA */
762 tree assignment = build (MODIFY_EXPR, TREE_TYPE (p), var, value);
763 init_stmts = add_stmt_to_compound (init_stmts, TREE_TYPE (p),
764 assignment);
766 else
768 /* Java objects don't ever need constructing when being
769 passed as arguments because only call by reference is
770 supported. */
771 abort ();
773 #endif /* INLINER_FOR_JAVA */
776 #ifndef INLINER_FOR_JAVA
777 /* Evaluate trailing arguments. */
778 for (; a; a = TREE_CHAIN (a))
780 tree init_stmt;
781 tree value = TREE_VALUE (a);
783 if (! value || ! TREE_SIDE_EFFECTS (value))
784 continue;
786 init_stmt = build_stmt (EXPR_STMT, value);
787 TREE_CHAIN (init_stmt) = init_stmts;
788 init_stmts = init_stmt;
791 /* The initialization statements have been built up in reverse
792 order. Straighten them out now. */
793 return nreverse (init_stmts);
794 #else /* INLINER_FOR_JAVA */
795 BLOCK_VARS (block) = nreverse (vars);
796 return init_stmts;
797 #endif /* INLINER_FOR_JAVA */
800 /* Declare a return variable to replace the RESULT_DECL for the
801 function we are calling. An appropriate DECL_STMT is returned.
802 The USE_STMT is filled in to contain a use of the declaration to
803 indicate the return value of the function. */
805 #ifndef INLINER_FOR_JAVA
806 static tree
807 declare_return_variable (struct inline_data *id, tree return_slot_addr,
808 tree *use_stmt)
809 #else /* INLINER_FOR_JAVA */
810 static tree
811 declare_return_variable (struct inline_data *id, tree return_slot_addr,
812 tree *var)
813 #endif /* INLINER_FOR_JAVA */
815 tree fn = VARRAY_TOP_TREE (id->fns);
816 tree result = DECL_RESULT (fn);
817 #ifndef INLINER_FOR_JAVA
818 tree var;
819 #endif /* not INLINER_FOR_JAVA */
820 int need_return_decl = 1;
822 /* We don't need to do anything for functions that don't return
823 anything. */
824 if (!result || VOID_TYPE_P (TREE_TYPE (result)))
826 #ifndef INLINER_FOR_JAVA
827 *use_stmt = NULL_TREE;
828 #else /* INLINER_FOR_JAVA */
829 *var = NULL_TREE;
830 #endif /* INLINER_FOR_JAVA */
831 return NULL_TREE;
834 #ifndef INLINER_FOR_JAVA
835 var = ((*lang_hooks.tree_inlining.copy_res_decl_for_inlining)
836 (result, fn, VARRAY_TREE (id->fns, 0), id->decl_map,
837 &need_return_decl, return_slot_addr));
839 /* Register the VAR_DECL as the equivalent for the RESULT_DECL; that
840 way, when the RESULT_DECL is encountered, it will be
841 automatically replaced by the VAR_DECL. */
842 splay_tree_insert (id->decl_map,
843 (splay_tree_key) result,
844 (splay_tree_value) var);
846 /* Build the USE_STMT. If the return type of the function was
847 promoted, convert it back to the expected type. */
848 if (TREE_TYPE (var) == TREE_TYPE (TREE_TYPE (fn)))
849 *use_stmt = build_stmt (EXPR_STMT, var);
850 else
851 *use_stmt = build_stmt (EXPR_STMT,
852 build1 (NOP_EXPR, TREE_TYPE (TREE_TYPE (fn)),
853 var));
854 TREE_ADDRESSABLE (*use_stmt) = 1;
856 /* Build the declaration statement if FN does not return an
857 aggregate. */
858 if (need_return_decl)
859 return build_stmt (DECL_STMT, var);
860 #else /* INLINER_FOR_JAVA */
861 *var = ((*lang_hooks.tree_inlining.copy_res_decl_for_inlining)
862 (result, fn, VARRAY_TREE (id->fns, 0), id->decl_map,
863 &need_return_decl, return_slot_addr));
865 splay_tree_insert (id->decl_map,
866 (splay_tree_key) result,
867 (splay_tree_value) *var);
868 DECL_IGNORED_P (*var) = 1;
869 if (need_return_decl)
870 return *var;
871 #endif /* INLINER_FOR_JAVA */
872 /* If FN does return an aggregate, there's no need to declare the
873 return variable; we're using a variable in our caller's frame. */
874 else
875 return NULL_TREE;
878 /* Returns nonzero if a function can be inlined as a tree. */
881 tree_inlinable_function_p (tree fn, int nolimit)
883 return inlinable_function_p (fn, NULL, nolimit);
886 /* If *TP is possibly call to alloca, return nonzero. */
887 static tree
888 find_alloca_call_1 (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
889 void *data ATTRIBUTE_UNUSED)
891 if (alloca_call_p (*tp))
892 return *tp;
893 return NULL;
896 /* Return subexpression representing possible alloca call, if any. */
897 static tree
898 find_alloca_call (tree exp)
900 location_t saved_loc = input_location;
901 tree ret = walk_tree_without_duplicates
902 (&exp, find_alloca_call_1, NULL);
903 input_location = saved_loc;
904 return ret;
907 static tree
908 find_builtin_longjmp_call_1 (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
909 void *data ATTRIBUTE_UNUSED)
911 tree exp = *tp, decl;
913 if (TREE_CODE (exp) == CALL_EXPR
914 && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
915 && (decl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
916 TREE_CODE (decl) == FUNCTION_DECL)
917 && DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
918 && DECL_FUNCTION_CODE (decl) == BUILT_IN_LONGJMP)
919 return decl;
921 return NULL;
924 static tree
925 find_builtin_longjmp_call (tree exp)
927 location_t saved_loc = input_location;
928 tree ret = walk_tree_without_duplicates
929 (&exp, find_builtin_longjmp_call_1, NULL);
930 input_location = saved_loc;
931 return ret;
934 /* Returns nonzero if FN is a function that can be inlined into the
935 inlining context ID_. If ID_ is NULL, check whether the function
936 can be inlined at all. */
938 static int
939 inlinable_function_p (tree fn, inline_data *id, int nolimit)
941 int inlinable;
942 int currfn_insns;
943 int max_inline_insns_single = MAX_INLINE_INSNS_SINGLE;
945 /* If we've already decided this function shouldn't be inlined,
946 there's no need to check again. */
947 if (DECL_UNINLINABLE (fn))
948 return 0;
950 /* See if there is any language-specific reason it cannot be
951 inlined. (It is important that this hook be called early because
952 in C++ it may result in template instantiation.) */
953 inlinable = !(*lang_hooks.tree_inlining.cannot_inline_tree_fn) (&fn);
955 /* We may be here either because fn is declared inline or because
956 we use -finline-functions. For the second case, we are more
957 restrictive. */
958 if (DID_INLINE_FUNC (fn))
959 max_inline_insns_single = MAX_INLINE_INSNS_AUTO;
961 /* The number of instructions (estimated) of current function. */
962 currfn_insns = DECL_NUM_STMTS (fn) * INSNS_PER_STMT;
964 /* If we're not inlining things, then nothing is inlinable. */
965 if (! flag_inline_trees)
966 inlinable = 0;
967 /* If we're not inlining all functions and the function was not
968 declared `inline', we don't inline it. Don't think of
969 disregarding DECL_INLINE when flag_inline_trees == 2; it's the
970 front-end that must set DECL_INLINE in this case, because
971 dwarf2out loses if a function is inlined that doesn't have
972 DECL_INLINE set. */
973 else if (! DECL_INLINE (fn) && !nolimit)
974 inlinable = 0;
975 #ifdef INLINER_FOR_JAVA
976 /* Synchronized methods can't be inlined. This is a bug. */
977 else if (METHOD_SYNCHRONIZED (fn))
978 inlinable = 0;
979 #endif /* INLINER_FOR_JAVA */
980 /* We can't inline functions that are too big. Only allow a single
981 function to be of MAX_INLINE_INSNS_SINGLE size. Make special
982 allowance for extern inline functions, though. */
983 else if (!nolimit
984 && ! (*lang_hooks.tree_inlining.disregard_inline_limits) (fn)
985 && currfn_insns > max_inline_insns_single)
986 inlinable = 0;
987 /* We can't inline functions that call __builtin_longjmp at all.
988 The non-local goto machinery really requires the destination
989 be in a different function. If we allow the function calling
990 __builtin_longjmp to be inlined into the function calling
991 __builtin_setjmp, Things will Go Awry. */
992 /* ??? Need front end help to identify "regular" non-local goto. */
993 else if (find_builtin_longjmp_call (DECL_SAVED_TREE (fn)))
994 inlinable = 0;
995 /* Refuse to inline alloca call unless user explicitly forced so as this may
996 change program's memory overhead drastically when the function using alloca
997 is called in loop. In GCC present in SPEC2000 inlining into schedule_block
998 cause it to require 2GB of ram instead of 256MB. */
999 else if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)) == NULL
1000 && find_alloca_call (DECL_SAVED_TREE (fn)))
1001 inlinable = 0;
1003 /* Squirrel away the result so that we don't have to check again. */
1004 DECL_UNINLINABLE (fn) = ! inlinable;
1006 /* In case we don't disregard the inlining limits and we basically
1007 can inline this function, investigate further. */
1008 if (! (*lang_hooks.tree_inlining.disregard_inline_limits) (fn)
1009 && inlinable && !nolimit)
1011 int sum_insns = (id ? id->inlined_stmts : 0) * INSNS_PER_STMT
1012 + currfn_insns;
1013 /* In the extreme case that we have exceeded the recursive inlining
1014 limit by a huge factor (128), we just say no. Should not happen
1015 in real life. */
1016 if (sum_insns > MAX_INLINE_INSNS * 128)
1017 inlinable = 0;
1018 /* If we did not hit the extreme limit, we use a linear function
1019 with slope -1/MAX_INLINE_SLOPE to exceedingly decrease the
1020 allowable size. We always allow a size of MIN_INLINE_INSNS
1021 though. */
1022 else if ((sum_insns > MAX_INLINE_INSNS)
1023 && (currfn_insns > MIN_INLINE_INSNS))
1025 int max_curr = MAX_INLINE_INSNS_SINGLE
1026 - (sum_insns - MAX_INLINE_INSNS) / MAX_INLINE_SLOPE;
1027 if (currfn_insns > max_curr)
1028 inlinable = 0;
1032 /* If we don't have the function body available, we can't inline
1033 it. */
1034 if (! DECL_SAVED_TREE (fn))
1035 inlinable = 0;
1037 /* Check again, language hooks may have modified it. */
1038 if (! inlinable || DECL_UNINLINABLE (fn))
1039 return 0;
1041 /* Don't do recursive inlining, either. We don't record this in
1042 DECL_UNINLINABLE; we may be able to inline this function later. */
1043 if (id)
1045 size_t i;
1047 for (i = 0; i < VARRAY_ACTIVE_SIZE (id->fns); ++i)
1048 if (VARRAY_TREE (id->fns, i) == fn)
1049 return 0;
1051 if (DECL_INLINED_FNS (fn))
1053 int j;
1054 tree inlined_fns = DECL_INLINED_FNS (fn);
1056 for (j = 0; j < TREE_VEC_LENGTH (inlined_fns); ++j)
1057 if (TREE_VEC_ELT (inlined_fns, j) == VARRAY_TREE (id->fns, 0))
1058 return 0;
1062 /* Return the result. */
1063 return inlinable;
1066 /* If *TP is a CALL_EXPR, replace it with its inline expansion. */
1068 static tree
1069 expand_call_inline (tree *tp, int *walk_subtrees, void *data)
1071 inline_data *id;
1072 tree t;
1073 tree expr;
1074 tree stmt;
1075 #ifndef INLINER_FOR_JAVA
1076 tree chain;
1077 tree scope_stmt;
1078 tree use_stmt;
1079 #else /* INLINER_FOR_JAVA */
1080 tree retvar;
1081 #endif /* INLINER_FOR_JAVA */
1082 tree fn;
1083 tree arg_inits;
1084 tree *inlined_body;
1085 splay_tree st;
1086 tree args;
1087 tree return_slot_addr;
1089 /* See what we've got. */
1090 id = (inline_data *) data;
1091 t = *tp;
1093 /* Recurse, but letting recursive invocations know that we are
1094 inside the body of a TARGET_EXPR. */
1095 if (TREE_CODE (*tp) == TARGET_EXPR)
1097 #ifndef INLINER_FOR_JAVA
1098 int i, len = first_rtl_op (TARGET_EXPR);
1100 /* We're walking our own subtrees. */
1101 *walk_subtrees = 0;
1103 /* Actually walk over them. This loop is the body of
1104 walk_trees, omitting the case where the TARGET_EXPR
1105 itself is handled. */
1106 for (i = 0; i < len; ++i)
1108 if (i == 2)
1109 ++id->in_target_cleanup_p;
1110 walk_tree (&TREE_OPERAND (*tp, i), expand_call_inline, data,
1111 id->tree_pruner);
1112 if (i == 2)
1113 --id->in_target_cleanup_p;
1116 return NULL_TREE;
1117 #else /* INLINER_FOR_JAVA */
1118 abort ();
1119 #endif /* INLINER_FOR_JAVA */
1121 else if (TREE_CODE (t) == EXPR_WITH_FILE_LOCATION)
1123 /* We're walking the subtree directly. */
1124 *walk_subtrees = 0;
1125 /* Update the source position. */
1126 push_srcloc (EXPR_WFL_FILENAME (t), EXPR_WFL_LINENO (t));
1127 walk_tree (&EXPR_WFL_NODE (t), expand_call_inline, data,
1128 id->tree_pruner);
1129 /* Restore the original source position. */
1130 pop_srcloc ();
1132 return NULL_TREE;
1135 if (TYPE_P (t))
1136 /* Because types were not copied in copy_body, CALL_EXPRs beneath
1137 them should not be expanded. This can happen if the type is a
1138 dynamic array type, for example. */
1139 *walk_subtrees = 0;
1141 /* From here on, we're only interested in CALL_EXPRs. */
1142 if (TREE_CODE (t) != CALL_EXPR)
1143 return NULL_TREE;
1145 /* First, see if we can figure out what function is being called.
1146 If we cannot, then there is no hope of inlining the function. */
1147 fn = get_callee_fndecl (t);
1148 if (!fn)
1149 return NULL_TREE;
1151 /* If fn is a declaration of a function in a nested scope that was
1152 globally declared inline, we don't set its DECL_INITIAL.
1153 However, we can't blindly follow DECL_ABSTRACT_ORIGIN because the
1154 C++ front-end uses it for cdtors to refer to their internal
1155 declarations, that are not real functions. Fortunately those
1156 don't have trees to be saved, so we can tell by checking their
1157 DECL_SAVED_TREE. */
1158 if (! DECL_INITIAL (fn)
1159 && DECL_ABSTRACT_ORIGIN (fn)
1160 && DECL_SAVED_TREE (DECL_ABSTRACT_ORIGIN (fn)))
1161 fn = DECL_ABSTRACT_ORIGIN (fn);
1163 /* Don't try to inline functions that are not well-suited to
1164 inlining. */
1165 if ((!flag_unit_at_a_time || !DECL_SAVED_TREE (fn)
1166 || !cgraph_global_info (fn)->inline_once)
1167 && !inlinable_function_p (fn, id, 0))
1169 if (warn_inline && DECL_INLINE (fn) && !DID_INLINE_FUNC (fn)
1170 && !DECL_IN_SYSTEM_HEADER (fn))
1172 warning_with_decl (fn, "inlining failed in call to `%s'");
1173 warning ("called from here");
1175 return NULL_TREE;
1178 if (! (*lang_hooks.tree_inlining.start_inlining) (fn))
1179 return NULL_TREE;
1181 /* Set the current filename and line number to the function we are
1182 inlining so that when we create new _STMT nodes here they get
1183 line numbers corresponding to the function we are calling. We
1184 wrap the whole inlined body in an EXPR_WITH_FILE_AND_LINE as well
1185 because individual statements don't record the filename. */
1186 push_srcloc (DECL_SOURCE_FILE (fn), DECL_SOURCE_LINE (fn));
1188 #ifndef INLINER_FOR_JAVA
1189 /* Build a statement-expression containing code to initialize the
1190 arguments, the actual inline expansion of the body, and a label
1191 for the return statements within the function to jump to. The
1192 type of the statement expression is the return type of the
1193 function call. */
1194 expr = build1 (STMT_EXPR, TREE_TYPE (TREE_TYPE (fn)), make_node (COMPOUND_STMT));
1195 /* There is no scope associated with the statement-expression. */
1196 STMT_EXPR_NO_SCOPE (expr) = 1;
1197 stmt = STMT_EXPR_STMT (expr);
1198 #else /* INLINER_FOR_JAVA */
1199 /* Build a block containing code to initialize the arguments, the
1200 actual inline expansion of the body, and a label for the return
1201 statements within the function to jump to. The type of the
1202 statement expression is the return type of the function call. */
1203 stmt = NULL;
1204 expr = build (BLOCK, TREE_TYPE (TREE_TYPE (fn)), stmt);
1205 #endif /* INLINER_FOR_JAVA */
1207 /* Local declarations will be replaced by their equivalents in this
1208 map. */
1209 st = id->decl_map;
1210 id->decl_map = splay_tree_new (splay_tree_compare_pointers,
1211 NULL, NULL);
1213 /* Initialize the parameters. */
1214 args = TREE_OPERAND (t, 1);
1215 return_slot_addr = NULL_TREE;
1216 if (CALL_EXPR_HAS_RETURN_SLOT_ADDR (t))
1218 return_slot_addr = TREE_VALUE (args);
1219 args = TREE_CHAIN (args);
1222 #ifndef INLINER_FOR_JAVA
1223 arg_inits = initialize_inlined_parameters (id, args, fn);
1224 /* Expand any inlined calls in the initializers. Do this before we
1225 push FN on the stack of functions we are inlining; we want to
1226 inline calls to FN that appear in the initializers for the
1227 parameters. */
1228 expand_calls_inline (&arg_inits, id);
1229 /* And add them to the tree. */
1230 COMPOUND_BODY (stmt) = chainon (COMPOUND_BODY (stmt), arg_inits);
1231 #else /* INLINER_FOR_JAVA */
1232 arg_inits = initialize_inlined_parameters (id, args, fn, expr);
1233 if (arg_inits)
1235 /* Expand any inlined calls in the initializers. Do this before we
1236 push FN on the stack of functions we are inlining; we want to
1237 inline calls to FN that appear in the initializers for the
1238 parameters. */
1239 expand_calls_inline (&arg_inits, id);
1241 /* And add them to the tree. */
1242 BLOCK_EXPR_BODY (expr) = add_stmt_to_compound (BLOCK_EXPR_BODY (expr),
1243 TREE_TYPE (arg_inits),
1244 arg_inits);
1246 #endif /* INLINER_FOR_JAVA */
1248 /* Record the function we are about to inline so that we can avoid
1249 recursing into it. */
1250 VARRAY_PUSH_TREE (id->fns, fn);
1252 /* Record the function we are about to inline if optimize_function
1253 has not been called on it yet and we don't have it in the list. */
1254 if (! DECL_INLINED_FNS (fn))
1256 int i;
1258 for (i = VARRAY_ACTIVE_SIZE (id->inlined_fns) - 1; i >= 0; i--)
1259 if (VARRAY_TREE (id->inlined_fns, i) == fn)
1260 break;
1261 if (i < 0)
1262 VARRAY_PUSH_TREE (id->inlined_fns, fn);
1265 /* Return statements in the function body will be replaced by jumps
1266 to the RET_LABEL. */
1267 id->ret_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1268 DECL_CONTEXT (id->ret_label) = VARRAY_TREE (id->fns, 0);
1270 if (! DECL_INITIAL (fn)
1271 || TREE_CODE (DECL_INITIAL (fn)) != BLOCK)
1272 abort ();
1274 #ifndef INLINER_FOR_JAVA
1275 /* Create a block to put the parameters in. We have to do this
1276 after the parameters have been remapped because remapping
1277 parameters is different from remapping ordinary variables. */
1278 scope_stmt = build_stmt (SCOPE_STMT, DECL_INITIAL (fn));
1279 SCOPE_BEGIN_P (scope_stmt) = 1;
1280 SCOPE_NO_CLEANUPS_P (scope_stmt) = 1;
1281 remap_block (scope_stmt, DECL_ARGUMENTS (fn), id);
1282 TREE_CHAIN (scope_stmt) = COMPOUND_BODY (stmt);
1283 COMPOUND_BODY (stmt) = scope_stmt;
1285 /* Tell the debugging backends that this block represents the
1286 outermost scope of the inlined function. */
1287 if (SCOPE_STMT_BLOCK (scope_stmt))
1288 BLOCK_ABSTRACT_ORIGIN (SCOPE_STMT_BLOCK (scope_stmt)) = DECL_ORIGIN (fn);
1290 /* Declare the return variable for the function. */
1291 COMPOUND_BODY (stmt)
1292 = chainon (COMPOUND_BODY (stmt),
1293 declare_return_variable (id, return_slot_addr, &use_stmt));
1294 #else /* INLINER_FOR_JAVA */
1296 /* Declare the return variable for the function. */
1297 tree decl = declare_return_variable (id, return_slot_addr, &retvar);
1298 if (retvar)
1300 tree *next = &BLOCK_VARS (expr);
1301 while (*next)
1302 next = &TREE_CHAIN (*next);
1303 *next = decl;
1306 #endif /* INLINER_FOR_JAVA */
1308 /* After we've initialized the parameters, we insert the body of the
1309 function itself. */
1310 #ifndef INLINER_FOR_JAVA
1311 inlined_body = &COMPOUND_BODY (stmt);
1312 while (*inlined_body)
1313 inlined_body = &TREE_CHAIN (*inlined_body);
1314 *inlined_body = copy_body (id);
1315 #else /* INLINER_FOR_JAVA */
1317 tree new_body;
1318 java_inlining_map_static_initializers (fn, id->decl_map);
1319 new_body = copy_body (id);
1320 TREE_TYPE (new_body) = TREE_TYPE (TREE_TYPE (fn));
1321 BLOCK_EXPR_BODY (expr)
1322 = add_stmt_to_compound (BLOCK_EXPR_BODY (expr),
1323 TREE_TYPE (new_body), new_body);
1324 inlined_body = &BLOCK_EXPR_BODY (expr);
1326 #endif /* INLINER_FOR_JAVA */
1328 /* After the body of the function comes the RET_LABEL. This must come
1329 before we evaluate the returned value below, because that evaluation
1330 may cause RTL to be generated. */
1331 #ifndef INLINER_FOR_JAVA
1332 COMPOUND_BODY (stmt)
1333 = chainon (COMPOUND_BODY (stmt),
1334 build_stmt (LABEL_STMT, id->ret_label));
1335 #else /* INLINER_FOR_JAVA */
1337 tree label = build1 (LABEL_EXPR, void_type_node, id->ret_label);
1338 BLOCK_EXPR_BODY (expr)
1339 = add_stmt_to_compound (BLOCK_EXPR_BODY (expr), void_type_node, label);
1340 TREE_SIDE_EFFECTS (label) = TREE_SIDE_EFFECTS (t);
1342 #endif /* INLINER_FOR_JAVA */
1344 /* Finally, mention the returned value so that the value of the
1345 statement-expression is the returned value of the function. */
1346 #ifndef INLINER_FOR_JAVA
1347 COMPOUND_BODY (stmt) = chainon (COMPOUND_BODY (stmt), use_stmt);
1349 /* Close the block for the parameters. */
1350 scope_stmt = build_stmt (SCOPE_STMT, DECL_INITIAL (fn));
1351 SCOPE_NO_CLEANUPS_P (scope_stmt) = 1;
1352 remap_block (scope_stmt, NULL_TREE, id);
1353 COMPOUND_BODY (stmt)
1354 = chainon (COMPOUND_BODY (stmt), scope_stmt);
1355 #else /* INLINER_FOR_JAVA */
1356 if (retvar)
1358 /* Mention the retvar. If the return type of the function was
1359 promoted, convert it back to the expected type. */
1360 if (TREE_TYPE (TREE_TYPE (fn)) != TREE_TYPE (retvar))
1361 retvar = build1 (NOP_EXPR, TREE_TYPE (TREE_TYPE (fn)), retvar);
1362 BLOCK_EXPR_BODY (expr)
1363 = add_stmt_to_compound (BLOCK_EXPR_BODY (expr),
1364 TREE_TYPE (retvar), retvar);
1367 java_inlining_merge_static_initializers (fn, id->decl_map);
1368 #endif /* INLINER_FOR_JAVA */
1370 /* Clean up. */
1371 splay_tree_delete (id->decl_map);
1372 id->decl_map = st;
1374 /* The new expression has side-effects if the old one did. */
1375 TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (t);
1377 /* Replace the call by the inlined body. Wrap it in an
1378 EXPR_WITH_FILE_LOCATION so that we'll get debugging line notes
1379 pointing to the right place. */
1380 #ifndef INLINER_FOR_JAVA
1381 chain = TREE_CHAIN (*tp);
1382 #endif /* INLINER_FOR_JAVA */
1383 *tp = build_expr_wfl (expr, DECL_SOURCE_FILE (fn), DECL_SOURCE_LINE (fn),
1384 /*col=*/0);
1385 EXPR_WFL_EMIT_LINE_NOTE (*tp) = 1;
1386 #ifndef INLINER_FOR_JAVA
1387 TREE_CHAIN (*tp) = chain;
1388 #endif /* not INLINER_FOR_JAVA */
1389 pop_srcloc ();
1391 /* If the value of the new expression is ignored, that's OK. We
1392 don't warn about this for CALL_EXPRs, so we shouldn't warn about
1393 the equivalent inlined version either. */
1394 TREE_USED (*tp) = 1;
1396 /* Our function now has more statements than it did before. */
1397 DECL_NUM_STMTS (VARRAY_TREE (id->fns, 0)) += DECL_NUM_STMTS (fn);
1398 /* For accounting, subtract one for the saved call/ret. */
1399 id->inlined_stmts += DECL_NUM_STMTS (fn) - 1;
1401 /* Update callgraph if needed. */
1402 if (id->decl && flag_unit_at_a_time)
1404 cgraph_remove_call (id->decl, fn);
1405 cgraph_create_edges (id->decl, *inlined_body);
1408 /* Recurse into the body of the just inlined function. */
1409 expand_calls_inline (inlined_body, id);
1410 VARRAY_POP (id->fns);
1412 /* If we've returned to the top level, clear out the record of how
1413 much inlining has been done. */
1414 if (VARRAY_ACTIVE_SIZE (id->fns) == id->first_inlined_fn)
1415 id->inlined_stmts = 0;
1417 /* Don't walk into subtrees. We've already handled them above. */
1418 *walk_subtrees = 0;
1420 (*lang_hooks.tree_inlining.end_inlining) (fn);
1422 /* Keep iterating. */
1423 return NULL_TREE;
1425 /* Walk over the entire tree *TP, replacing CALL_EXPRs with inline
1426 expansions as appropriate. */
1428 static void
1429 expand_calls_inline (tree *tp, inline_data *id)
1431 /* Search through *TP, replacing all calls to inline functions by
1432 appropriate equivalents. Use walk_tree in no-duplicates mode
1433 to avoid exponential time complexity. (We can't just use
1434 walk_tree_without_duplicates, because of the special TARGET_EXPR
1435 handling in expand_calls. The hash table is set up in
1436 optimize_function. */
1437 walk_tree (tp, expand_call_inline, id, id->tree_pruner);
1440 /* Expand calls to inline functions in the body of FN. */
1442 void
1443 optimize_inline_calls (tree fn)
1445 inline_data id;
1446 tree prev_fn;
1448 /* Clear out ID. */
1449 memset (&id, 0, sizeof (id));
1451 id.decl = fn;
1452 /* Don't allow recursion into FN. */
1453 VARRAY_TREE_INIT (id.fns, 32, "fns");
1454 VARRAY_PUSH_TREE (id.fns, 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 */