OSDN Git Service

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