OSDN Git Service

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