OSDN Git Service

* gcc.dg/ultrasp5.c: Fix options.
[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 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       copy_tree_r (tp, walk_subtrees, NULL);
550
551       /* The copied TARGET_EXPR has never been expanded, even if the
552          original node was expanded already.  */
553       if (TREE_CODE (*tp) == TARGET_EXPR && TREE_OPERAND (*tp, 3))
554         {
555           TREE_OPERAND (*tp, 1) = TREE_OPERAND (*tp, 3);
556           TREE_OPERAND (*tp, 3) = NULL_TREE;
557         }
558       else if (TREE_CODE (*tp) == MODIFY_EXPR
559                && TREE_OPERAND (*tp, 0) == TREE_OPERAND (*tp, 1)
560                && ((*lang_hooks.tree_inlining.auto_var_in_fn_p)
561                    (TREE_OPERAND (*tp, 0), fn)))
562         {
563           /* Some assignments VAR = VAR; don't generate any rtl code
564              and thus don't count as variable modification.  Avoid
565              keeping bogosities like 0 = 0.  */
566           tree decl = TREE_OPERAND (*tp, 0), value;
567           splay_tree_node n;
568
569           n = splay_tree_lookup (id->decl_map, (splay_tree_key) decl);
570           if (n)
571             {
572               value = (tree) n->value;
573               STRIP_TYPE_NOPS (value);
574               if (TREE_CONSTANT (value) || TREE_READONLY_DECL_P (value))
575                 *tp = value;
576             }
577         }
578     }
579
580   /* Keep iterating.  */
581   return NULL_TREE;
582 }
583
584 /* Make a copy of the body of FN so that it can be inserted inline in
585    another function.  */
586
587 static tree
588 copy_body (id)
589      inline_data *id;
590 {
591   tree body;
592
593   body = DECL_SAVED_TREE (VARRAY_TOP_TREE (id->fns));
594   walk_tree (&body, copy_body_r, id, NULL);
595
596   return body;
597 }
598
599 /* Generate code to initialize the parameters of the function at the
600    top of the stack in ID from the ARGS (presented as a TREE_LIST).  */
601
602 static tree
603 #ifndef INLINER_FOR_JAVA
604 initialize_inlined_parameters (id, args, fn)
605 #else /* INLINER_FOR_JAVA */
606 initialize_inlined_parameters (id, args, fn, block)
607 #endif /* INLINER_FOR_JAVA */
608      inline_data *id;
609      tree args;
610      tree fn;
611 #ifdef INLINER_FOR_JAVA
612      tree block;
613 #endif /* INLINER_FOR_JAVA */
614 {
615   tree init_stmts;
616   tree parms;
617   tree a;
618   tree p;
619 #ifdef INLINER_FOR_JAVA
620   tree vars = NULL_TREE;
621 #endif /* INLINER_FOR_JAVA */
622
623   /* Figure out what the parameters are.  */
624   parms = DECL_ARGUMENTS (fn);
625
626   /* Start with no initializations whatsoever.  */
627   init_stmts = NULL_TREE;
628
629   /* Loop through the parameter declarations, replacing each with an
630      equivalent VAR_DECL, appropriately initialized.  */
631   for (p = parms, a = args; p;
632        a = a ? TREE_CHAIN (a) : a, p = TREE_CHAIN (p))
633     {
634 #ifndef INLINER_FOR_JAVA
635       tree init_stmt;
636       tree cleanup;
637 #endif /* not INLINER_FOR_JAVA */
638       tree var;
639       tree value;
640       tree var_sub;
641
642       /* Find the initializer.  */
643       value = (*lang_hooks.tree_inlining.convert_parm_for_inlining)
644               (p, a ? TREE_VALUE (a) : NULL_TREE, fn);
645
646       /* If the parameter is never assigned to, we may not need to
647          create a new variable here at all.  Instead, we may be able
648          to just use the argument value.  */
649       if (TREE_READONLY (p)
650           && !TREE_ADDRESSABLE (p)
651           && value && !TREE_SIDE_EFFECTS (value))
652         {
653           /* Simplify the value, if possible.  */
654           value = fold (DECL_P (value) ? decl_constant_value (value) : value);
655
656           /* We can't risk substituting complex expressions.  They
657              might contain variables that will be assigned to later.
658              Theoretically, we could check the expression to see if
659              all of the variables that determine its value are
660              read-only, but we don't bother.  */
661           if (TREE_CONSTANT (value) || TREE_READONLY_DECL_P (value))
662             {
663               /* If this is a declaration, wrap it a NOP_EXPR so that
664                  we don't try to put the VALUE on the list of
665                  BLOCK_VARS.  */
666               if (DECL_P (value))
667                 value = build1 (NOP_EXPR, TREE_TYPE (value), value);
668
669               /* If this is a constant, make sure it has the right type.  */
670               else if (TREE_TYPE (value) != TREE_TYPE (p))
671                 value = fold (build1 (NOP_EXPR, TREE_TYPE (p), value));
672
673               splay_tree_insert (id->decl_map,
674                                  (splay_tree_key) p,
675                                  (splay_tree_value) value);
676               continue;
677             }
678         }
679
680       /* Make an equivalent VAR_DECL.  */
681       var = copy_decl_for_inlining (p, fn, VARRAY_TREE (id->fns, 0));
682
683       /* See if the frontend wants to pass this by invisible reference.  If
684          so, our new VAR_DECL will have REFERENCE_TYPE, and we need to
685          replace uses of the PARM_DECL with dereferences.  */
686       if (TREE_TYPE (var) != TREE_TYPE (p)
687           && POINTER_TYPE_P (TREE_TYPE (var))
688           && TREE_TYPE (TREE_TYPE (var)) == TREE_TYPE (p))
689         var_sub = build1 (INDIRECT_REF, TREE_TYPE (p), var);
690       else
691         var_sub = var;
692
693       /* Register the VAR_DECL as the equivalent for the PARM_DECL;
694          that way, when the PARM_DECL is encountered, it will be
695          automatically replaced by the VAR_DECL.  */
696       splay_tree_insert (id->decl_map,
697                          (splay_tree_key) p,
698                          (splay_tree_value) var_sub);
699
700       /* Declare this new variable.  */
701 #ifndef INLINER_FOR_JAVA
702       init_stmt = build_stmt (DECL_STMT, var);
703       TREE_CHAIN (init_stmt) = init_stmts;
704       init_stmts = init_stmt;
705 #else /* INLINER_FOR_JAVA */
706       TREE_CHAIN (var) = vars;
707       vars = var;
708 #endif /* INLINER_FOR_JAVA */
709
710       /* Initialize this VAR_DECL from the equivalent argument.  If
711          the argument is an object, created via a constructor or copy,
712          this will not result in an extra copy: the TARGET_EXPR
713          representing the argument will be bound to VAR, and the
714          object will be constructed in VAR.  */
715       if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (p)))
716 #ifndef INLINER_FOR_JAVA
717         DECL_INITIAL (var) = value;
718       else
719         {
720           /* Even if P was TREE_READONLY, the new VAR should not be.
721              In the original code, we would have constructed a
722              temporary, and then the function body would have never
723              changed the value of P.  However, now, we will be
724              constructing VAR directly.  The constructor body may
725              change its value multiple times as it is being
726              constructed.  Therefore, it must not be TREE_READONLY;
727              the back-end assumes that TREE_READONLY variable is
728              assigned to only once.  */
729           TREE_READONLY (var) = 0;
730
731           /* Build a run-time initialization.  */
732           init_stmt = build_stmt (EXPR_STMT,
733                                   build (INIT_EXPR, TREE_TYPE (p),
734                                          var, value));
735           /* Add this initialization to the list.  Note that we want the
736              declaration *after* the initialization because we are going
737              to reverse all the initialization statements below.  */
738           TREE_CHAIN (init_stmt) = init_stmts;
739           init_stmts = init_stmt;
740         }
741
742       /* See if we need to clean up the declaration.  */
743       cleanup = (*lang_hooks.maybe_build_cleanup) (var);
744       if (cleanup)
745         {
746           tree cleanup_stmt;
747           /* Build the cleanup statement.  */
748           cleanup_stmt = build_stmt (CLEANUP_STMT, var, cleanup);
749           /* Add it to the *front* of the list; the list will be
750              reversed below.  */
751           TREE_CHAIN (cleanup_stmt) = init_stmts;
752           init_stmts = cleanup_stmt;
753         }
754 #else /* INLINER_FOR_JAVA */
755         {
756           tree assignment = build (MODIFY_EXPR, TREE_TYPE (p), var, value);
757           init_stmts = add_stmt_to_compound (init_stmts, TREE_TYPE (p),
758                                              assignment);
759         }
760       else
761         {
762           /* Java objects don't ever need constructing when being
763              passed as arguments because only call by reference is
764              supported.  */
765           abort ();
766         }
767 #endif /* INLINER_FOR_JAVA */
768     }
769
770 #ifndef INLINER_FOR_JAVA
771   /* Evaluate trailing arguments.  */
772   for (; a; a = TREE_CHAIN (a))
773     {
774       tree init_stmt;
775       tree value = TREE_VALUE (a);
776
777       if (! value || ! TREE_SIDE_EFFECTS (value))
778         continue;
779
780       init_stmt = build_stmt (EXPR_STMT, value);
781       TREE_CHAIN (init_stmt) = init_stmts;
782       init_stmts = init_stmt;
783     }
784
785   /* The initialization statements have been built up in reverse
786      order.  Straighten them out now.  */
787   return nreverse (init_stmts);
788 #else /* INLINER_FOR_JAVA */
789   BLOCK_VARS (block) = nreverse (vars);
790   return init_stmts;
791 #endif /* INLINER_FOR_JAVA */
792 }
793
794 /* Declare a return variable to replace the RESULT_DECL for the
795    function we are calling.  An appropriate DECL_STMT is returned.
796    The USE_STMT is filled in to contain a use of the declaration to
797    indicate the return value of the function.  */
798
799 #ifndef INLINER_FOR_JAVA
800 static tree
801 declare_return_variable (id, return_slot_addr, use_stmt)
802      struct inline_data *id;
803      tree return_slot_addr;
804      tree *use_stmt;
805 #else /* INLINER_FOR_JAVA */
806 static tree
807 declare_return_variable (id, return_slot_addr, var)
808      struct inline_data *id;
809      tree return_slot_addr;
810      tree *var;
811 #endif /* INLINER_FOR_JAVA */
812 {
813   tree fn = VARRAY_TOP_TREE (id->fns);
814   tree result = DECL_RESULT (fn);
815 #ifndef INLINER_FOR_JAVA
816   tree var;
817 #endif /* not INLINER_FOR_JAVA */
818   int need_return_decl = 1;
819
820   /* We don't need to do anything for functions that don't return
821      anything.  */
822   if (!result || VOID_TYPE_P (TREE_TYPE (result)))
823     {
824 #ifndef INLINER_FOR_JAVA
825       *use_stmt = NULL_TREE;
826 #else /* INLINER_FOR_JAVA */
827       *var = NULL_TREE;
828 #endif /* INLINER_FOR_JAVA */
829       return NULL_TREE;
830     }
831
832 #ifndef INLINER_FOR_JAVA
833   var = ((*lang_hooks.tree_inlining.copy_res_decl_for_inlining)
834          (result, fn, VARRAY_TREE (id->fns, 0), id->decl_map,
835           &need_return_decl, return_slot_addr));
836
837   /* Register the VAR_DECL as the equivalent for the RESULT_DECL; that
838      way, when the RESULT_DECL is encountered, it will be
839      automatically replaced by the VAR_DECL.  */
840   splay_tree_insert (id->decl_map,
841                      (splay_tree_key) result,
842                      (splay_tree_value) var);
843
844   /* Build the USE_STMT.  If the return type of the function was
845      promoted, convert it back to the expected type.  */
846   if (TREE_TYPE (var) == TREE_TYPE (TREE_TYPE (fn)))
847     *use_stmt = build_stmt (EXPR_STMT, var);
848   else
849     *use_stmt = build_stmt (EXPR_STMT,
850                             build1 (NOP_EXPR, TREE_TYPE (TREE_TYPE (fn)),
851                                     var));
852   TREE_ADDRESSABLE (*use_stmt) = 1;
853
854   /* Build the declaration statement if FN does not return an
855      aggregate.  */
856   if (need_return_decl)
857     return build_stmt (DECL_STMT, var);
858 #else /* INLINER_FOR_JAVA */
859   *var = ((*lang_hooks.tree_inlining.copy_res_decl_for_inlining)
860          (result, fn, VARRAY_TREE (id->fns, 0), id->decl_map,
861           &need_return_decl, return_slot_addr));
862
863   splay_tree_insert (id->decl_map,
864                      (splay_tree_key) result,
865                      (splay_tree_value) *var);
866   DECL_IGNORED_P (*var) = 1;
867   if (need_return_decl)
868     return *var;
869 #endif /* INLINER_FOR_JAVA */
870   /* If FN does return an aggregate, there's no need to declare the
871      return variable; we're using a variable in our caller's frame.  */
872   else
873     return NULL_TREE;
874 }
875
876 /* Returns nonzero if a function can be inlined as a tree.  */
877
878 int
879 tree_inlinable_function_p (fn, nolimit)
880      tree fn;
881      int nolimit;
882 {
883   return inlinable_function_p (fn, NULL, nolimit);
884 }
885
886 /* If *TP is possibly call to alloca, return nonzero.  */
887 static tree
888 find_alloca_call_1 (tp, walk_subtrees, data)
889      tree *tp;
890      int *walk_subtrees ATTRIBUTE_UNUSED;
891      void *data ATTRIBUTE_UNUSED;
892 {
893   if (alloca_call_p (*tp))
894     return *tp;
895   return NULL;
896 }
897
898 /* Return subexpression representing possible alloca call, if any.  */
899 static tree
900 find_alloca_call (exp)
901      tree exp;
902 {
903   int line = lineno;
904   const char *file = input_filename;
905   tree ret = walk_tree (&exp, find_alloca_call_1, NULL, NULL);
906   lineno = line;
907   input_filename = file;
908   return ret;
909 }
910
911 static tree
912 find_builtin_longjmp_call_1 (tp, walk_subtrees, data)
913      tree *tp;
914      int *walk_subtrees ATTRIBUTE_UNUSED;
915      void *data ATTRIBUTE_UNUSED;
916 {
917   tree exp = *tp, decl;
918
919   if (TREE_CODE (exp) == CALL_EXPR
920       && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
921       && (decl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
922           TREE_CODE (decl) == FUNCTION_DECL)
923       && DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
924       && DECL_FUNCTION_CODE (decl) == BUILT_IN_LONGJMP)
925     return decl;
926
927   return NULL;
928 }
929
930 static tree
931 find_builtin_longjmp_call (exp)
932      tree exp;
933 {
934   int line = lineno;
935   const char *file = input_filename;
936   tree ret = walk_tree (&exp, find_builtin_longjmp_call_1, NULL, NULL);
937   lineno = line;
938   input_filename = file;
939   return ret;
940 }
941
942 /* Returns nonzero if FN is a function that can be inlined into the
943    inlining context ID_.  If ID_ is NULL, check whether the function
944    can be inlined at all.  */
945
946 static int
947 inlinable_function_p (fn, id, nolimit)
948      tree fn;
949      inline_data *id;
950      int nolimit;
951 {
952   int inlinable;
953   int currfn_insns;
954   int max_inline_insns_single = MAX_INLINE_INSNS_SINGLE;
955
956   /* If we've already decided this function shouldn't be inlined,
957      there's no need to check again.  */
958   if (DECL_UNINLINABLE (fn))
959     return 0;
960
961   /* Assume it is not inlinable.  */
962   inlinable = 0;
963        
964   /* We may be here either because fn is declared inline or because
965      we use -finline-functions.  For the second case, we are more
966      restrictive.  */
967   if (DID_INLINE_FUNC (fn))
968     max_inline_insns_single = MAX_INLINE_INSNS_AUTO;
969         
970   /* The number of instructions (estimated) of current function.  */
971   currfn_insns = DECL_NUM_STMTS (fn) * INSNS_PER_STMT;
972
973   /* If we're not inlining things, then nothing is inlinable.  */
974   if (! flag_inline_trees)
975     ;
976   /* If we're not inlining all functions and the function was not
977      declared `inline', we don't inline it.  Don't think of
978      disregarding DECL_INLINE when flag_inline_trees == 2; it's the
979      front-end that must set DECL_INLINE in this case, because
980      dwarf2out loses if a function is inlined that doesn't have
981      DECL_INLINE set.  */
982   else if (! DECL_INLINE (fn) && !nolimit)
983     ;
984   /* We can't inline functions that are too big.  Only allow a single
985      function to be of MAX_INLINE_INSNS_SINGLE size.  Make special
986      allowance for extern inline functions, though.  */
987   else if (!nolimit
988            && ! (*lang_hooks.tree_inlining.disregard_inline_limits) (fn)
989            && currfn_insns > max_inline_insns_single)
990     ;
991   /* We can't inline functions that call __builtin_longjmp at all.
992      The non-local goto machenery really requires the destination
993      be in a different function.  If we allow the function calling
994      __builtin_longjmp to be inlined into the function calling
995      __builtin_setjmp, Things will Go Awry.  */
996   /* ??? Need front end help to identify "regular" non-local goto.  */
997   else if (find_builtin_longjmp_call (DECL_SAVED_TREE (fn)))
998     ;
999   /* Refuse to inline alloca call unless user explicitly forced so as this may
1000      change program's memory overhead drastically when the function using alloca
1001      is called in loop.  In GCC present in SPEC2000 inlining into schedule_block
1002      cause it to require 2GB of ram instead of 256MB.  */
1003   else if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)) == NULL
1004            && find_alloca_call (DECL_SAVED_TREE (fn)))
1005     ;
1006   /* All is well.  We can inline this function.  Traditionally, GCC
1007      has refused to inline functions using alloca, or functions whose
1008      values are returned in a PARALLEL, and a few other such obscure
1009      conditions.  We are not equally constrained at the tree level.  */
1010   else
1011     inlinable = 1;
1012
1013   /* Squirrel away the result so that we don't have to check again.  */
1014   DECL_UNINLINABLE (fn) = ! inlinable;
1015
1016   /* In case we don't disregard the inlining limits and we basically
1017      can inline this function, investigate further.  */
1018   if (! (*lang_hooks.tree_inlining.disregard_inline_limits) (fn)
1019       && inlinable && !nolimit)
1020     {
1021       int sum_insns = (id ? id->inlined_stmts : 0) * INSNS_PER_STMT
1022                      + currfn_insns;
1023       /* In the extreme case that we have exceeded the recursive inlining
1024          limit by a huge factor (128), we just say no. Should not happen
1025          in real life.  */
1026       if (sum_insns > MAX_INLINE_INSNS * 128)
1027          inlinable = 0;
1028       /* If we did not hit the extreme limit, we use a linear function
1029          with slope -1/MAX_INLINE_SLOPE to exceedingly decrease the
1030          allowable size. We always allow a size of MIN_INLINE_INSNS
1031          though.  */
1032       else if ((sum_insns > MAX_INLINE_INSNS)
1033                && (currfn_insns > MIN_INLINE_INSNS))
1034         {
1035           int max_curr = MAX_INLINE_INSNS_SINGLE
1036                         - (sum_insns - MAX_INLINE_INSNS) / MAX_INLINE_SLOPE;
1037           if (currfn_insns > max_curr)
1038             inlinable = 0;
1039         }
1040     }
1041
1042   if (inlinable && (*lang_hooks.tree_inlining.cannot_inline_tree_fn) (&fn))
1043     inlinable = 0;
1044
1045   /* If we don't have the function body available, we can't inline
1046      it.  */
1047   if (! DECL_SAVED_TREE (fn))
1048     inlinable = 0;
1049
1050   /* Check again, language hooks may have modified it.  */
1051   if (! inlinable || DECL_UNINLINABLE (fn))
1052     return 0;
1053
1054   /* Don't do recursive inlining, either.  We don't record this in
1055      DECL_UNINLINABLE; we may be able to inline this function later.  */
1056   if (id)
1057     {
1058       size_t i;
1059
1060       for (i = 0; i < VARRAY_ACTIVE_SIZE (id->fns); ++i)
1061         if (VARRAY_TREE (id->fns, i) == fn)
1062           return 0;
1063
1064       if (DECL_INLINED_FNS (fn))
1065         {
1066           int j;
1067           tree inlined_fns = DECL_INLINED_FNS (fn);
1068
1069           for (j = 0; j < TREE_VEC_LENGTH (inlined_fns); ++j)
1070             if (TREE_VEC_ELT (inlined_fns, j) == VARRAY_TREE (id->fns, 0))
1071               return 0;
1072         }
1073     }
1074
1075   /* Return the result.  */
1076   return inlinable;
1077 }
1078
1079 /* If *TP is a CALL_EXPR, replace it with its inline expansion.  */
1080
1081 static tree
1082 expand_call_inline (tp, walk_subtrees, data)
1083      tree *tp;
1084      int *walk_subtrees;
1085      void *data;
1086 {
1087   inline_data *id;
1088   tree t;
1089   tree expr;
1090   tree stmt;
1091 #ifndef INLINER_FOR_JAVA
1092   tree chain;
1093   tree scope_stmt;
1094   tree use_stmt;
1095 #else /* INLINER_FOR_JAVA */
1096   tree retvar;
1097 #endif /* INLINER_FOR_JAVA */
1098   tree fn;
1099   tree arg_inits;
1100   tree *inlined_body;
1101   splay_tree st;
1102   tree args;
1103   tree return_slot_addr;
1104
1105   /* See what we've got.  */
1106   id = (inline_data *) data;
1107   t = *tp;
1108
1109   /* Recurse, but letting recursive invocations know that we are
1110      inside the body of a TARGET_EXPR.  */
1111   if (TREE_CODE (*tp) == TARGET_EXPR)
1112     {
1113 #ifndef INLINER_FOR_JAVA
1114       int i, len = first_rtl_op (TARGET_EXPR);
1115
1116       /* We're walking our own subtrees.  */
1117       *walk_subtrees = 0;
1118
1119       /* Actually walk over them.  This loop is the body of
1120          walk_trees, omitting the case where the TARGET_EXPR
1121          itself is handled.  */
1122       for (i = 0; i < len; ++i)
1123         {
1124           if (i == 2)
1125             ++id->in_target_cleanup_p;
1126           walk_tree (&TREE_OPERAND (*tp, i), expand_call_inline, data,
1127                      id->tree_pruner);
1128           if (i == 2)
1129             --id->in_target_cleanup_p;
1130         }
1131
1132       return NULL_TREE;
1133 #else /* INLINER_FOR_JAVA */
1134       abort ();
1135 #endif /* INLINER_FOR_JAVA */
1136     }
1137
1138   if (TYPE_P (t))
1139     /* Because types were not copied in copy_body, CALL_EXPRs beneath
1140        them should not be expanded.  This can happen if the type is a
1141        dynamic array type, for example.  */
1142     *walk_subtrees = 0;
1143
1144   /* From here on, we're only interested in CALL_EXPRs.  */
1145   if (TREE_CODE (t) != CALL_EXPR)
1146     return NULL_TREE;
1147
1148   /* First, see if we can figure out what function is being called.
1149      If we cannot, then there is no hope of inlining the function.  */
1150   fn = get_callee_fndecl (t);
1151   if (!fn)
1152     return NULL_TREE;
1153
1154   /* If fn is a declaration of a function in a nested scope that was
1155      globally declared inline, we don't set its DECL_INITIAL.
1156      However, we can't blindly follow DECL_ABSTRACT_ORIGIN because the
1157      C++ front-end uses it for cdtors to refer to their internal
1158      declarations, that are not real functions.  Fortunately those
1159      don't have trees to be saved, so we can tell by checking their
1160      DECL_SAVED_TREE.  */
1161   if (! DECL_INITIAL (fn)
1162       && DECL_ABSTRACT_ORIGIN (fn)
1163       && DECL_SAVED_TREE (DECL_ABSTRACT_ORIGIN (fn)))
1164     fn = DECL_ABSTRACT_ORIGIN (fn);
1165
1166   /* Don't try to inline functions that are not well-suited to
1167      inlining.  */
1168   if ((!flag_unit_at_a_time || !DECL_SAVED_TREE (fn)
1169        || !cgraph_global_info (fn)->inline_once)
1170       && !inlinable_function_p (fn, id, 0))
1171     return NULL_TREE;
1172
1173   if (! (*lang_hooks.tree_inlining.start_inlining) (fn))
1174     return NULL_TREE;
1175
1176   /* Set the current filename and line number to the function we are
1177      inlining so that when we create new _STMT nodes here they get
1178      line numbers corresponding to the function we are calling.  We
1179      wrap the whole inlined body in an EXPR_WITH_FILE_AND_LINE as well
1180      because individual statements don't record the filename.  */
1181   push_srcloc (DECL_SOURCE_FILE (fn), DECL_SOURCE_LINE (fn));
1182
1183 #ifndef INLINER_FOR_JAVA
1184   /* Build a statement-expression containing code to initialize the
1185      arguments, the actual inline expansion of the body, and a label
1186      for the return statements within the function to jump to.  The
1187      type of the statement expression is the return type of the
1188      function call.  */
1189   expr = build1 (STMT_EXPR, TREE_TYPE (TREE_TYPE (fn)), make_node (COMPOUND_STMT));
1190   /* There is no scope associated with the statement-expression.  */
1191   STMT_EXPR_NO_SCOPE (expr) = 1;
1192   stmt = STMT_EXPR_STMT (expr);
1193 #else /* INLINER_FOR_JAVA */
1194   /* Build a block containing code to initialize the arguments, the
1195      actual inline expansion of the body, and a label for the return
1196      statements within the function to jump to.  The type of the
1197      statement expression is the return type of the function call.  */
1198   stmt = NULL;
1199   expr = build (BLOCK, TREE_TYPE (TREE_TYPE (fn)), stmt);
1200 #endif /* INLINER_FOR_JAVA */
1201
1202   /* Local declarations will be replaced by their equivalents in this
1203      map.  */
1204   st = id->decl_map;
1205   id->decl_map = splay_tree_new (splay_tree_compare_pointers,
1206                                  NULL, NULL);
1207
1208   /* Initialize the parameters.  */
1209   args = TREE_OPERAND (t, 1);
1210   return_slot_addr = NULL_TREE;
1211   if (CALL_EXPR_HAS_RETURN_SLOT_ADDR (t))
1212     {
1213       return_slot_addr = TREE_VALUE (args);
1214       args = TREE_CHAIN (args);
1215     }
1216
1217 #ifndef INLINER_FOR_JAVA
1218   arg_inits = initialize_inlined_parameters (id, args, fn);
1219   /* Expand any inlined calls in the initializers.  Do this before we
1220      push FN on the stack of functions we are inlining; we want to
1221      inline calls to FN that appear in the initializers for the
1222      parameters.  */
1223   expand_calls_inline (&arg_inits, id);
1224   /* And add them to the tree.  */
1225   COMPOUND_BODY (stmt) = chainon (COMPOUND_BODY (stmt), arg_inits);
1226 #else /* INLINER_FOR_JAVA */
1227   arg_inits = initialize_inlined_parameters (id, args, fn, expr);
1228   if (arg_inits)
1229     {
1230       /* Expand any inlined calls in the initializers.  Do this before we
1231          push FN on the stack of functions we are inlining; we want to
1232          inline calls to FN that appear in the initializers for the
1233          parameters.  */
1234       expand_calls_inline (&arg_inits, id);
1235
1236       /* And add them to the tree.  */
1237       BLOCK_EXPR_BODY (expr) = add_stmt_to_compound (BLOCK_EXPR_BODY (expr),
1238                                                      TREE_TYPE (arg_inits),
1239                                                      arg_inits);
1240     }
1241 #endif /* INLINER_FOR_JAVA */
1242
1243   /* Record the function we are about to inline so that we can avoid
1244      recursing into it.  */
1245   VARRAY_PUSH_TREE (id->fns, fn);
1246
1247   /* Record the function we are about to inline if optimize_function
1248      has not been called on it yet and we don't have it in the list.  */
1249   if (! DECL_INLINED_FNS (fn))
1250     {
1251       int i;
1252
1253       for (i = VARRAY_ACTIVE_SIZE (id->inlined_fns) - 1; i >= 0; i--)
1254         if (VARRAY_TREE (id->inlined_fns, i) == fn)
1255           break;
1256       if (i < 0)
1257         VARRAY_PUSH_TREE (id->inlined_fns, fn);
1258     }
1259
1260   /* Return statements in the function body will be replaced by jumps
1261      to the RET_LABEL.  */
1262   id->ret_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
1263   DECL_CONTEXT (id->ret_label) = VARRAY_TREE (id->fns, 0);
1264
1265   if (! DECL_INITIAL (fn)
1266       || TREE_CODE (DECL_INITIAL (fn)) != BLOCK)
1267     abort ();
1268
1269 #ifndef INLINER_FOR_JAVA
1270   /* Create a block to put the parameters in.  We have to do this
1271      after the parameters have been remapped because remapping
1272      parameters is different from remapping ordinary variables.  */
1273   scope_stmt = build_stmt (SCOPE_STMT, DECL_INITIAL (fn));
1274   SCOPE_BEGIN_P (scope_stmt) = 1;
1275   SCOPE_NO_CLEANUPS_P (scope_stmt) = 1;
1276   remap_block (scope_stmt, DECL_ARGUMENTS (fn), id);
1277   TREE_CHAIN (scope_stmt) = COMPOUND_BODY (stmt);
1278   COMPOUND_BODY (stmt) = scope_stmt;
1279
1280   /* Tell the debugging backends that this block represents the
1281      outermost scope of the inlined function.  */
1282   if (SCOPE_STMT_BLOCK (scope_stmt))
1283     BLOCK_ABSTRACT_ORIGIN (SCOPE_STMT_BLOCK (scope_stmt)) = DECL_ORIGIN (fn);
1284
1285   /* Declare the return variable for the function.  */
1286   COMPOUND_BODY (stmt)
1287     = chainon (COMPOUND_BODY (stmt),
1288                declare_return_variable (id, return_slot_addr, &use_stmt));
1289 #else /* INLINER_FOR_JAVA */
1290   {
1291     /* Declare the return variable for the function.  */
1292     tree decl = declare_return_variable (id, return_slot_addr, &retvar);
1293     if (retvar)
1294       {
1295         tree *next = &BLOCK_VARS (expr);
1296         while (*next)
1297           next = &TREE_CHAIN (*next);
1298         *next = decl;
1299       }
1300   }
1301 #endif /* INLINER_FOR_JAVA */
1302
1303   /* After we've initialized the parameters, we insert the body of the
1304      function itself.  */
1305 #ifndef INLINER_FOR_JAVA
1306   inlined_body = &COMPOUND_BODY (stmt);
1307   while (*inlined_body)
1308     inlined_body = &TREE_CHAIN (*inlined_body);
1309   *inlined_body = copy_body (id);
1310 #else /* INLINER_FOR_JAVA */
1311   {
1312     tree new_body;
1313     java_inlining_map_static_initializers (fn, id->decl_map);
1314     new_body = copy_body (id);
1315     TREE_TYPE (new_body) = TREE_TYPE (TREE_TYPE (fn));
1316     BLOCK_EXPR_BODY (expr)
1317       = add_stmt_to_compound (BLOCK_EXPR_BODY (expr),
1318                               TREE_TYPE (new_body), new_body);
1319     inlined_body = &BLOCK_EXPR_BODY (expr);
1320   }
1321 #endif /* INLINER_FOR_JAVA */
1322
1323   /* After the body of the function comes the RET_LABEL.  This must come
1324      before we evaluate the returned value below, because that evaluation
1325      may cause RTL to be generated.  */
1326 #ifndef INLINER_FOR_JAVA
1327   COMPOUND_BODY (stmt)
1328     = chainon (COMPOUND_BODY (stmt),
1329                build_stmt (LABEL_STMT, id->ret_label));
1330 #else /* INLINER_FOR_JAVA */
1331   {
1332     tree label = build1 (LABEL_EXPR, void_type_node, id->ret_label);
1333     BLOCK_EXPR_BODY (expr)
1334       = add_stmt_to_compound (BLOCK_EXPR_BODY (expr), void_type_node, label);
1335     TREE_SIDE_EFFECTS (label) = TREE_SIDE_EFFECTS (t);
1336   }
1337 #endif /* INLINER_FOR_JAVA */
1338
1339   /* Finally, mention the returned value so that the value of the
1340      statement-expression is the returned value of the function.  */
1341 #ifndef INLINER_FOR_JAVA
1342   COMPOUND_BODY (stmt) = chainon (COMPOUND_BODY (stmt), use_stmt);
1343
1344   /* Close the block for the parameters.  */
1345   scope_stmt = build_stmt (SCOPE_STMT, DECL_INITIAL (fn));
1346   SCOPE_NO_CLEANUPS_P (scope_stmt) = 1;
1347   remap_block (scope_stmt, NULL_TREE, id);
1348   COMPOUND_BODY (stmt)
1349     = chainon (COMPOUND_BODY (stmt), scope_stmt);
1350 #else /* INLINER_FOR_JAVA */
1351   if (retvar)
1352     {
1353       /* Mention the retvar.  If the return type of the function was
1354          promoted, convert it back to the expected type.  */
1355       if (TREE_TYPE (TREE_TYPE (fn)) != TREE_TYPE (retvar))
1356         retvar = build1 (NOP_EXPR, TREE_TYPE (TREE_TYPE (fn)), retvar);
1357       BLOCK_EXPR_BODY (expr)
1358         = add_stmt_to_compound (BLOCK_EXPR_BODY (expr),
1359                                 TREE_TYPE (retvar), retvar);
1360     }
1361
1362   java_inlining_merge_static_initializers (fn, id->decl_map);
1363 #endif /* INLINER_FOR_JAVA */
1364
1365   /* Clean up.  */
1366   splay_tree_delete (id->decl_map);
1367   id->decl_map = st;
1368
1369   /* The new expression has side-effects if the old one did.  */
1370   TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (t);
1371
1372   /* Replace the call by the inlined body.  Wrap it in an
1373      EXPR_WITH_FILE_LOCATION so that we'll get debugging line notes
1374      pointing to the right place.  */
1375 #ifndef INLINER_FOR_JAVA
1376   chain = TREE_CHAIN (*tp);
1377   *tp = build_expr_wfl (expr, DECL_SOURCE_FILE (fn), DECL_SOURCE_LINE (fn),
1378                         /*col=*/0);
1379 #else /* INLINER_FOR_JAVA */
1380   *tp = build_expr_wfl (expr, DECL_SOURCE_FILE (fn),
1381                         DECL_SOURCE_LINE_FIRST(fn),
1382                         /*col=*/0);
1383 #endif /* INLINER_FOR_JAVA */
1384   EXPR_WFL_EMIT_LINE_NOTE (*tp) = 1;
1385 #ifndef INLINER_FOR_JAVA
1386   TREE_CHAIN (*tp) = chain;
1387 #endif /* not INLINER_FOR_JAVA */
1388   pop_srcloc ();
1389
1390   /* If the value of the new expression is ignored, that's OK.  We
1391      don't warn about this for CALL_EXPRs, so we shouldn't warn about
1392      the equivalent inlined version either.  */
1393   TREE_USED (*tp) = 1;
1394
1395   /* Our function now has more statements than it did before.  */
1396   DECL_NUM_STMTS (VARRAY_TREE (id->fns, 0)) += DECL_NUM_STMTS (fn);
1397   /* For accounting, subtract one for the saved call/ret.  */
1398   id->inlined_stmts += DECL_NUM_STMTS (fn) - 1;
1399
1400   /* Update callgraph if needed.  */
1401   if (id->decl && flag_unit_at_a_time)
1402     {
1403       cgraph_remove_call (id->decl, fn);
1404       cgraph_create_edges (id->decl, *inlined_body);
1405     }
1406
1407   /* Recurse into the body of the just inlined function.  */
1408   expand_calls_inline (inlined_body, id);
1409   VARRAY_POP (id->fns);
1410
1411   /* If we've returned to the top level, clear out the record of how
1412      much inlining has been done.  */
1413   if (VARRAY_ACTIVE_SIZE (id->fns) == id->first_inlined_fn)
1414     id->inlined_stmts = 0;
1415
1416   /* Don't walk into subtrees.  We've already handled them above.  */
1417   *walk_subtrees = 0;
1418
1419   (*lang_hooks.tree_inlining.end_inlining) (fn);
1420
1421   /* Keep iterating.  */
1422   return NULL_TREE;
1423 }
1424 /* Walk over the entire tree *TP, replacing CALL_EXPRs with inline
1425    expansions as appropriate.  */
1426
1427 static void
1428 expand_calls_inline (tp, id)
1429      tree *tp;
1430      inline_data *id;
1431 {
1432   /* Search through *TP, replacing all calls to inline functions by
1433      appropriate equivalents.  Use walk_tree in no-duplicates mode
1434      to avoid exponential time complexity.  (We can't just use
1435      walk_tree_without_duplicates, because of the special TARGET_EXPR
1436      handling in expand_calls.  The hash table is set up in
1437      optimize_function.  */
1438   walk_tree (tp, expand_call_inline, id, id->tree_pruner);
1439 }
1440
1441 /* Expand calls to inline functions in the body of FN.  */
1442
1443 void
1444 optimize_inline_calls (fn)
1445      tree fn;
1446 {
1447   inline_data id;
1448   tree prev_fn;
1449
1450   /* Clear out ID.  */
1451   memset (&id, 0, sizeof (id));
1452
1453   id.decl = fn;
1454   /* Don't allow recursion into FN.  */
1455   VARRAY_TREE_INIT (id.fns, 32, "fns");
1456   VARRAY_PUSH_TREE (id.fns, fn);
1457   /* Or any functions that aren't finished yet.  */
1458   prev_fn = NULL_TREE;
1459   if (current_function_decl)
1460     {
1461       VARRAY_PUSH_TREE (id.fns, current_function_decl);
1462       prev_fn = current_function_decl;
1463     }
1464
1465   prev_fn = ((*lang_hooks.tree_inlining.add_pending_fn_decls)
1466              (&id.fns, prev_fn));
1467
1468   /* Create the list of functions this call will inline.  */
1469   VARRAY_TREE_INIT (id.inlined_fns, 32, "inlined_fns");
1470
1471   /* Keep track of the low-water mark, i.e., the point where the first
1472      real inlining is represented in ID.FNS.  */
1473   id.first_inlined_fn = VARRAY_ACTIVE_SIZE (id.fns);
1474
1475   /* Replace all calls to inline functions with the bodies of those
1476      functions.  */
1477   id.tree_pruner = htab_create (37, htab_hash_pointer,
1478                                 htab_eq_pointer, NULL);
1479   expand_calls_inline (&DECL_SAVED_TREE (fn), &id);
1480
1481   /* Clean up.  */
1482   htab_delete (id.tree_pruner);
1483   if (DECL_LANG_SPECIFIC (fn))
1484     {
1485       tree ifn = make_tree_vec (VARRAY_ACTIVE_SIZE (id.inlined_fns));
1486
1487       if (VARRAY_ACTIVE_SIZE (id.inlined_fns))
1488         memcpy (&TREE_VEC_ELT (ifn, 0), &VARRAY_TREE (id.inlined_fns, 0),
1489                 VARRAY_ACTIVE_SIZE (id.inlined_fns) * sizeof (tree));
1490       DECL_INLINED_FNS (fn) = ifn;
1491     }
1492 }
1493
1494 /* FN is a function that has a complete body, and CLONE is a function
1495    whose body is to be set to a copy of FN, mapping argument
1496    declarations according to the ARG_MAP splay_tree.  */
1497
1498 void
1499 clone_body (clone, fn, arg_map)
1500      tree clone, fn;
1501      void *arg_map;
1502 {
1503   inline_data id;
1504
1505   /* Clone the body, as if we were making an inline call.  But, remap
1506      the parameters in the callee to the parameters of caller.  If
1507      there's an in-charge parameter, map it to an appropriate
1508      constant.  */
1509   memset (&id, 0, sizeof (id));
1510   VARRAY_TREE_INIT (id.fns, 2, "fns");
1511   VARRAY_PUSH_TREE (id.fns, clone);
1512   VARRAY_PUSH_TREE (id.fns, fn);
1513   id.decl_map = (splay_tree)arg_map;
1514
1515   /* Cloning is treated slightly differently from inlining.  Set
1516      CLONING_P so that it's clear which operation we're performing.  */
1517   id.cloning_p = true;
1518
1519   /* Actually copy the body.  */
1520   TREE_CHAIN (DECL_SAVED_TREE (clone)) = copy_body (&id);
1521 }
1522
1523 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal.
1524    FUNC is called with the DATA and the address of each sub-tree.  If
1525    FUNC returns a non-NULL value, the traversal is aborted, and the
1526    value returned by FUNC is returned.  If HTAB is non-NULL it is used
1527    to record the nodes visited, and to avoid visiting a node more than
1528    once.  */
1529
1530 tree
1531 walk_tree (tp, func, data, htab_)
1532      tree *tp;
1533      walk_tree_fn func;
1534      void *data;
1535      void *htab_;
1536 {
1537   htab_t htab = (htab_t) htab_;
1538   enum tree_code code;
1539   int walk_subtrees;
1540   tree result;
1541
1542 #define WALK_SUBTREE(NODE)                              \
1543   do                                                    \
1544     {                                                   \
1545       result = walk_tree (&(NODE), func, data, htab);   \
1546       if (result)                                       \
1547         return result;                                  \
1548     }                                                   \
1549   while (0)
1550
1551 #define WALK_SUBTREE_TAIL(NODE)                         \
1552   do                                                    \
1553     {                                                   \
1554        tp = & (NODE);                                   \
1555        goto tail_recurse;                               \
1556     }                                                   \
1557   while (0)
1558
1559  tail_recurse:
1560   /* Skip empty subtrees.  */
1561   if (!*tp)
1562     return NULL_TREE;
1563
1564   if (htab)
1565     {
1566       void **slot;
1567
1568       /* Don't walk the same tree twice, if the user has requested
1569          that we avoid doing so.  */
1570       slot = htab_find_slot (htab, *tp, INSERT);
1571       if (*slot)
1572         return NULL_TREE;
1573       *slot = *tp;
1574     }
1575
1576   /* Call the function.  */
1577   walk_subtrees = 1;
1578   result = (*func) (tp, &walk_subtrees, data);
1579
1580   /* If we found something, return it.  */
1581   if (result)
1582     return result;
1583
1584   code = TREE_CODE (*tp);
1585
1586 #ifndef INLINER_FOR_JAVA
1587   /* Even if we didn't, FUNC may have decided that there was nothing
1588      interesting below this point in the tree.  */
1589   if (!walk_subtrees)
1590     {
1591       if (statement_code_p (code) || code == TREE_LIST
1592           || (*lang_hooks.tree_inlining.tree_chain_matters_p) (*tp))
1593         /* But we still need to check our siblings.  */
1594         WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
1595       else
1596         return NULL_TREE;
1597     }
1598
1599   /* Handle common cases up front.  */
1600   if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code))
1601       || TREE_CODE_CLASS (code) == 'r'
1602       || TREE_CODE_CLASS (code) == 's')
1603 #else /* INLINER_FOR_JAVA */
1604   if (code != EXIT_BLOCK_EXPR
1605       && code != SAVE_EXPR
1606       && (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code))
1607           || TREE_CODE_CLASS (code) == 'r'
1608           || TREE_CODE_CLASS (code) == 's'))
1609 #endif /* INLINER_FOR_JAVA */
1610     {
1611       int i, len;
1612
1613 #ifndef INLINER_FOR_JAVA
1614       /* Set lineno here so we get the right instantiation context
1615          if we call instantiate_decl from inlinable_function_p.  */
1616       if (statement_code_p (code) && !STMT_LINENO_FOR_FN_P (*tp))
1617         lineno = STMT_LINENO (*tp);
1618 #endif /* not INLINER_FOR_JAVA */
1619
1620       /* Walk over all the sub-trees of this operand.  */
1621       len = first_rtl_op (code);
1622       /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
1623          But, we only want to walk once.  */
1624       if (code == TARGET_EXPR
1625           && TREE_OPERAND (*tp, 3) == TREE_OPERAND (*tp, 1))
1626         --len;
1627       /* Go through the subtrees.  We need to do this in forward order so
1628          that the scope of a FOR_EXPR is handled properly.  */
1629       for (i = 0; i < len; ++i)
1630         WALK_SUBTREE (TREE_OPERAND (*tp, i));
1631
1632 #ifndef INLINER_FOR_JAVA
1633       /* For statements, we also walk the chain so that we cover the
1634          entire statement tree.  */
1635       if (statement_code_p (code))
1636         {
1637           if (code == DECL_STMT
1638               && DECL_STMT_DECL (*tp)
1639               && DECL_P (DECL_STMT_DECL (*tp)))
1640             {
1641               /* Walk the DECL_INITIAL and DECL_SIZE.  We don't want to walk
1642                  into declarations that are just mentioned, rather than
1643                  declared; they don't really belong to this part of the tree.
1644                  And, we can see cycles: the initializer for a declaration can
1645                  refer to the declaration itself.  */
1646               WALK_SUBTREE (DECL_INITIAL (DECL_STMT_DECL (*tp)));
1647               WALK_SUBTREE (DECL_SIZE (DECL_STMT_DECL (*tp)));
1648               WALK_SUBTREE (DECL_SIZE_UNIT (DECL_STMT_DECL (*tp)));
1649             }
1650
1651           /* This can be tail-recursion optimized if we write it this way.  */
1652           WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
1653         }
1654
1655 #endif /* not INLINER_FOR_JAVA */
1656       /* We didn't find what we were looking for.  */
1657       return NULL_TREE;
1658     }
1659   else if (TREE_CODE_CLASS (code) == 'd')
1660     {
1661       WALK_SUBTREE_TAIL (TREE_TYPE (*tp));
1662     }
1663   else if (TREE_CODE_CLASS (code) == 't')
1664     {
1665       WALK_SUBTREE (TYPE_SIZE (*tp));
1666       WALK_SUBTREE (TYPE_SIZE_UNIT (*tp));
1667       /* Also examine various special fields, below.  */
1668     }
1669
1670   result = (*lang_hooks.tree_inlining.walk_subtrees) (tp, &walk_subtrees, func,
1671                                                       data, htab);
1672   if (result || ! walk_subtrees)
1673     return result;
1674
1675   /* Not one of the easy cases.  We must explicitly go through the
1676      children.  */
1677   switch (code)
1678     {
1679     case ERROR_MARK:
1680     case IDENTIFIER_NODE:
1681     case INTEGER_CST:
1682     case REAL_CST:
1683     case VECTOR_CST:
1684     case STRING_CST:
1685     case REAL_TYPE:
1686     case COMPLEX_TYPE:
1687     case VECTOR_TYPE:
1688     case VOID_TYPE:
1689     case BOOLEAN_TYPE:
1690     case UNION_TYPE:
1691     case ENUMERAL_TYPE:
1692     case BLOCK:
1693     case RECORD_TYPE:
1694     case CHAR_TYPE:
1695       /* None of thse have subtrees other than those already walked
1696          above.  */
1697       break;
1698
1699     case POINTER_TYPE:
1700     case REFERENCE_TYPE:
1701       WALK_SUBTREE_TAIL (TREE_TYPE (*tp));
1702       break;
1703
1704     case TREE_LIST:
1705       WALK_SUBTREE (TREE_VALUE (*tp));
1706       WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
1707       break;
1708
1709     case TREE_VEC:
1710       {
1711         int len = TREE_VEC_LENGTH (*tp);
1712
1713         if (len == 0)
1714           break;
1715
1716         /* Walk all elements but the first.  */
1717         while (--len)
1718           WALK_SUBTREE (TREE_VEC_ELT (*tp, len));
1719
1720         /* Now walk the first one as a tail call.  */
1721         WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp, 0));
1722       }
1723
1724     case COMPLEX_CST:
1725       WALK_SUBTREE (TREE_REALPART (*tp));
1726       WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp));
1727
1728     case CONSTRUCTOR:
1729       WALK_SUBTREE_TAIL (CONSTRUCTOR_ELTS (*tp));
1730
1731     case METHOD_TYPE:
1732       WALK_SUBTREE (TYPE_METHOD_BASETYPE (*tp));
1733       /* Fall through.  */
1734
1735     case FUNCTION_TYPE:
1736       WALK_SUBTREE (TREE_TYPE (*tp));
1737       {
1738         tree arg = TYPE_ARG_TYPES (*tp);
1739
1740         /* We never want to walk into default arguments.  */
1741         for (; arg; arg = TREE_CHAIN (arg))
1742           WALK_SUBTREE (TREE_VALUE (arg));
1743       }
1744       break;
1745
1746     case ARRAY_TYPE:
1747       WALK_SUBTREE (TREE_TYPE (*tp));
1748       WALK_SUBTREE_TAIL (TYPE_DOMAIN (*tp));
1749
1750     case INTEGER_TYPE:
1751       WALK_SUBTREE (TYPE_MIN_VALUE (*tp));
1752       WALK_SUBTREE_TAIL (TYPE_MAX_VALUE (*tp));
1753
1754     case OFFSET_TYPE:
1755       WALK_SUBTREE (TREE_TYPE (*tp));
1756       WALK_SUBTREE_TAIL (TYPE_OFFSET_BASETYPE (*tp));
1757
1758 #ifdef INLINER_FOR_JAVA
1759     case EXIT_BLOCK_EXPR:
1760       WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, 1));
1761
1762     case SAVE_EXPR:
1763       WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, 0));
1764 #endif /* INLINER_FOR_JAVA */
1765
1766     default:
1767       abort ();
1768     }
1769
1770   /* We didn't find what we were looking for.  */
1771   return NULL_TREE;
1772
1773 #undef WALK_SUBTREE
1774 #undef WALK_SUBTREE_TAIL
1775 }
1776
1777 /* Like walk_tree, but does not walk duplicate nodes more than
1778    once.  */
1779
1780 tree
1781 walk_tree_without_duplicates (tp, func, data)
1782      tree *tp;
1783      walk_tree_fn func;
1784      void *data;
1785 {
1786   tree result;
1787   htab_t htab;
1788
1789   htab = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
1790   result = walk_tree (tp, func, data, htab);
1791   htab_delete (htab);
1792   return result;
1793 }
1794
1795 /* Passed to walk_tree.  Copies the node pointed to, if appropriate.  */
1796
1797 tree
1798 copy_tree_r (tp, walk_subtrees, data)
1799      tree *tp;
1800      int *walk_subtrees;
1801      void *data ATTRIBUTE_UNUSED;
1802 {
1803   enum tree_code code = TREE_CODE (*tp);
1804
1805   /* We make copies of most nodes.  */
1806   if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code))
1807       || TREE_CODE_CLASS (code) == 'r'
1808       || TREE_CODE_CLASS (code) == 'c'
1809       || TREE_CODE_CLASS (code) == 's'
1810       || code == TREE_LIST
1811       || code == TREE_VEC
1812       || (*lang_hooks.tree_inlining.tree_chain_matters_p) (*tp))
1813     {
1814       /* Because the chain gets clobbered when we make a copy, we save it
1815          here.  */
1816       tree chain = TREE_CHAIN (*tp);
1817
1818       /* Copy the node.  */
1819       *tp = copy_node (*tp);
1820
1821       /* Now, restore the chain, if appropriate.  That will cause
1822          walk_tree to walk into the chain as well.  */
1823       if (code == PARM_DECL || code == TREE_LIST
1824 #ifndef INLINER_FOR_JAVA
1825           || (*lang_hooks.tree_inlining.tree_chain_matters_p) (*tp)
1826           || statement_code_p (code))
1827         TREE_CHAIN (*tp) = chain;
1828
1829       /* For now, we don't update BLOCKs when we make copies.  So, we
1830          have to nullify all scope-statements.  */
1831       if (TREE_CODE (*tp) == SCOPE_STMT)
1832         SCOPE_STMT_BLOCK (*tp) = NULL_TREE;
1833 #else /* INLINER_FOR_JAVA */
1834           || (*lang_hooks.tree_inlining.tree_chain_matters_p) (*tp))
1835         TREE_CHAIN (*tp) = chain;
1836 #endif /* INLINER_FOR_JAVA */
1837     }
1838   else if (TREE_CODE_CLASS (code) == 't' && !variably_modified_type_p (*tp))
1839     /* Types only need to be copied if they are variably modified.  */
1840     *walk_subtrees = 0;
1841
1842   return NULL_TREE;
1843 }
1844
1845 /* The SAVE_EXPR pointed to by TP is being copied.  If ST contains
1846    information indicating to what new SAVE_EXPR this one should be
1847    mapped, use that one.  Otherwise, create a new node and enter it in
1848    ST.  FN is the function into which the copy will be placed.  */
1849
1850 void
1851 remap_save_expr (tp, st_, fn, walk_subtrees)
1852      tree *tp;
1853      void *st_;
1854      tree fn;
1855      int *walk_subtrees;
1856 {
1857   splay_tree st = (splay_tree) st_;
1858   splay_tree_node n;
1859
1860   /* See if we already encountered this SAVE_EXPR.  */
1861   n = splay_tree_lookup (st, (splay_tree_key) *tp);
1862
1863   /* If we didn't already remap this SAVE_EXPR, do so now.  */
1864   if (!n)
1865     {
1866       tree t = copy_node (*tp);
1867
1868       /* The SAVE_EXPR is now part of the function into which we
1869          are inlining this body.  */
1870       SAVE_EXPR_CONTEXT (t) = fn;
1871       /* And we haven't evaluated it yet.  */
1872       SAVE_EXPR_RTL (t) = NULL_RTX;
1873       /* Remember this SAVE_EXPR.  */
1874       n = splay_tree_insert (st,
1875                              (splay_tree_key) *tp,
1876                              (splay_tree_value) t);
1877       /* Make sure we don't remap an already-remapped SAVE_EXPR.  */
1878       splay_tree_insert (st, (splay_tree_key) t,
1879                          (splay_tree_value) error_mark_node);
1880     }
1881   else
1882     /* We've already walked into this SAVE_EXPR, so we needn't do it
1883        again.  */
1884     *walk_subtrees = 0;
1885
1886   /* Replace this SAVE_EXPR with the copy.  */
1887   *tp = (tree) n->value;
1888 }
1889
1890 #ifdef INLINER_FOR_JAVA
1891 /* Add STMT to EXISTING if possible, otherwise create a new
1892    COMPOUND_EXPR and add STMT to it.  */
1893
1894 static tree
1895 add_stmt_to_compound (existing, type, stmt)
1896      tree existing, type, stmt;
1897 {
1898   if (!stmt)
1899     return existing;
1900   else if (existing)
1901     return build (COMPOUND_EXPR, type, existing, stmt);
1902   else
1903     return stmt;
1904 }
1905
1906 #endif /* INLINER_FOR_JAVA */