OSDN Git Service

ed21858659e266cbfeb8936b71795b7860ebbbbd
[pf3gnuchains/gcc-fork.git] / gcc / integrate.c
1 /* Procedure integration for GNU CC.
2    Copyright (C) 1988, 1991, 1993, 1994 Free Software Foundation, Inc.
3    Contributed by Michael Tiemann (tiemann@cygnus.com)
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
20
21
22 #include <stdio.h>
23
24 #include "config.h"
25 #include "rtl.h"
26 #include "tree.h"
27 #include "flags.h"
28 #include "insn-config.h"
29 #include "insn-flags.h"
30 #include "expr.h"
31 #include "output.h"
32 #include "integrate.h"
33 #include "real.h"
34 #include "function.h"
35 #include "bytecode.h"
36
37 #include "obstack.h"
38 #define obstack_chunk_alloc     xmalloc
39 #define obstack_chunk_free      free
40
41 extern struct obstack *function_maybepermanent_obstack;
42
43 extern tree pushdecl ();
44 extern tree poplevel ();
45
46 /* Similar, but round to the next highest integer that meets the
47    alignment.  */
48 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
49
50 /* Default max number of insns a function can have and still be inline.
51    This is overridden on RISC machines.  */
52 #ifndef INTEGRATE_THRESHOLD
53 #define INTEGRATE_THRESHOLD(DECL) \
54   (8 * (8 + list_length (DECL_ARGUMENTS (DECL))))
55 #endif
56 \f
57 static rtx initialize_for_inline PROTO((tree, int, int, int, int));
58 static void finish_inline       PROTO((tree, rtx));
59 static void adjust_copied_decl_tree PROTO((tree));
60 static tree copy_decl_list      PROTO((tree));
61 static tree copy_decl_tree      PROTO((tree));
62 static void copy_decl_rtls      PROTO((tree));
63 static void save_constants      PROTO((rtx *));
64 static void note_modified_parmregs PROTO((rtx, rtx));
65 static rtx copy_for_inline      PROTO((rtx));
66 static void integrate_parm_decls PROTO((tree, struct inline_remap *, rtvec));
67 static void integrate_decl_tree PROTO((tree, int, struct inline_remap *));
68 static void subst_constants     PROTO((rtx *, rtx, struct inline_remap *));
69 static void restore_constants   PROTO((rtx *));
70 static void set_block_origin_self PROTO((tree));
71 static void set_decl_origin_self PROTO((tree));
72 static void set_block_abstract_flags PROTO((tree, int));
73
74 void set_decl_abstract_flags    PROTO((tree, int));
75 \f
76 /* Zero if the current function (whose FUNCTION_DECL is FNDECL)
77    is safe and reasonable to integrate into other functions.
78    Nonzero means value is a warning message with a single %s
79    for the function's name.  */
80
81 char *
82 function_cannot_inline_p (fndecl)
83      register tree fndecl;
84 {
85   register rtx insn;
86   tree last = tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
87   int max_insns = INTEGRATE_THRESHOLD (fndecl);
88   register int ninsns = 0;
89   register tree parms;
90
91   /* No inlines with varargs.  `grokdeclarator' gives a warning
92      message about that if `inline' is specified.  This code
93      it put in to catch the volunteers.  */
94   if ((last && TREE_VALUE (last) != void_type_node)
95       || current_function_varargs)
96     return "varargs function cannot be inline";
97
98   if (current_function_calls_alloca)
99     return "function using alloca cannot be inline";
100
101   if (current_function_contains_functions)
102     return "function with nested functions cannot be inline";
103
104   /* If its not even close, don't even look.  */
105   if (!DECL_INLINE (fndecl) && get_max_uid () > 3 * max_insns)
106     return "function too large to be inline";
107
108 #if 0
109   /* Large stacks are OK now that inlined functions can share them.  */
110   /* Don't inline functions with large stack usage,
111      since they can make other recursive functions burn up stack.  */
112   if (!DECL_INLINE (fndecl) && get_frame_size () > 100)
113     return "function stack frame for inlining";
114 #endif
115
116 #if 0
117   /* Don't inline functions which do not specify a function prototype and
118      have BLKmode argument or take the address of a parameter.  */
119   for (parms = DECL_ARGUMENTS (fndecl); parms; parms = TREE_CHAIN (parms))
120     {
121       if (TYPE_MODE (TREE_TYPE (parms)) == BLKmode)
122         TREE_ADDRESSABLE (parms) = 1;
123       if (last == NULL_TREE && TREE_ADDRESSABLE (parms))
124         return "no prototype, and parameter address used; cannot be inline";
125     }
126 #endif
127
128   /* We can't inline functions that return structures
129      the old-fashioned PCC way, copying into a static block.  */
130   if (current_function_returns_pcc_struct)
131     return "inline functions not supported for this return value type";
132
133   /* We can't inline functions that return BLKmode structures in registers.  */
134   if (TYPE_MODE (TREE_TYPE (TREE_TYPE (fndecl))) == BLKmode
135       && ! aggregate_value_p (TREE_TYPE (TREE_TYPE (fndecl))))
136     return "inline functions not supported for this return value type";
137
138   /* We can't inline functions that return structures of varying size.  */
139   if (int_size_in_bytes (TREE_TYPE (TREE_TYPE (fndecl))) < 0)
140     return "function with varying-size return value cannot be inline";
141
142   /* Cannot inline a function with a varying size argument or one that
143      receives a transparent union.  */
144   for (parms = DECL_ARGUMENTS (fndecl); parms; parms = TREE_CHAIN (parms))
145     {
146       if (int_size_in_bytes (TREE_TYPE (parms)) < 0)
147         return "function with varying-size parameter cannot be inline";
148       else if (TYPE_TRANSPARENT_UNION (TREE_TYPE (parms)))
149         return "function with transparent unit parameter cannot be inline";
150     }
151
152   if (!DECL_INLINE (fndecl) && get_max_uid () > max_insns)
153     {
154       for (ninsns = 0, insn = get_first_nonparm_insn (); insn && ninsns < max_insns;
155            insn = NEXT_INSN (insn))
156         {
157           if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
158             ninsns++;
159         }
160
161       if (ninsns >= max_insns)
162         return "function too large to be inline";
163     }
164
165   /* We cannot inline this function if forced_labels is non-zero.  This
166      implies that a label in this function was used as an initializer.
167      Because labels can not be duplicated, all labels in the function
168      will be renamed when it is inlined.  However, there is no way to find
169      and fix all variables initialized with addresses of labels in this
170      function, hence inlining is impossible.  */
171
172   if (forced_labels)
173     return "function with label addresses used in initializers cannot inline";
174
175   /* We cannot inline a nested function that jumps to a nonlocal label.  */
176   if (current_function_has_nonlocal_goto)
177     return "function with nonlocal goto cannot be inline";
178
179   return 0;
180 }
181 \f
182 /* Variables used within save_for_inline.  */
183
184 /* Mapping from old pseudo-register to new pseudo-registers.
185    The first element of this map is reg_map[FIRST_PSEUDO_REGISTER].
186    It is allocated in `save_for_inline' and `expand_inline_function',
187    and deallocated on exit from each of those routines.  */
188 static rtx *reg_map;
189
190 /* Mapping from old code-labels to new code-labels.
191    The first element of this map is label_map[min_labelno].
192    It is allocated in `save_for_inline' and `expand_inline_function',
193    and deallocated on exit from each of those routines.  */
194 static rtx *label_map;
195
196 /* Mapping from old insn uid's to copied insns.
197    It is allocated in `save_for_inline' and `expand_inline_function',
198    and deallocated on exit from each of those routines.  */
199 static rtx *insn_map;
200
201 /* Map pseudo reg number into the PARM_DECL for the parm living in the reg.
202    Zero for a reg that isn't a parm's home.
203    Only reg numbers less than max_parm_reg are mapped here.  */
204 static tree *parmdecl_map;
205
206 /* Keep track of first pseudo-register beyond those that are parms.  */
207 static int max_parm_reg;
208
209 /* When an insn is being copied by copy_for_inline,
210    this is nonzero if we have copied an ASM_OPERANDS.
211    In that case, it is the original input-operand vector.  */
212 static rtvec orig_asm_operands_vector;
213
214 /* When an insn is being copied by copy_for_inline,
215    this is nonzero if we have copied an ASM_OPERANDS.
216    In that case, it is the copied input-operand vector.  */
217 static rtvec copy_asm_operands_vector;
218
219 /* Likewise, this is the copied constraints vector.  */
220 static rtvec copy_asm_constraints_vector;
221
222 /* In save_for_inline, nonzero if past the parm-initialization insns.  */
223 static int in_nonparm_insns;
224 \f
225 /* Subroutine for `save_for_inline{copying,nocopy}'.  Performs initialization
226    needed to save FNDECL's insns and info for future inline expansion.  */
227    
228 static rtx
229 initialize_for_inline (fndecl, min_labelno, max_labelno, max_reg, copy)
230      tree fndecl;
231      int min_labelno;
232      int max_labelno;
233      int max_reg;
234      int copy;
235 {
236   int function_flags, i;
237   rtvec arg_vector;
238   tree parms;
239
240   /* Compute the values of any flags we must restore when inlining this.  */
241
242   function_flags
243     = (current_function_calls_alloca * FUNCTION_FLAGS_CALLS_ALLOCA
244        + current_function_calls_setjmp * FUNCTION_FLAGS_CALLS_SETJMP
245        + current_function_calls_longjmp * FUNCTION_FLAGS_CALLS_LONGJMP
246        + current_function_returns_struct * FUNCTION_FLAGS_RETURNS_STRUCT
247        + current_function_returns_pcc_struct * FUNCTION_FLAGS_RETURNS_PCC_STRUCT
248        + current_function_needs_context * FUNCTION_FLAGS_NEEDS_CONTEXT
249        + current_function_has_nonlocal_label * FUNCTION_FLAGS_HAS_NONLOCAL_LABEL
250        + current_function_returns_pointer * FUNCTION_FLAGS_RETURNS_POINTER
251        + current_function_uses_const_pool * FUNCTION_FLAGS_USES_CONST_POOL
252        + current_function_uses_pic_offset_table * FUNCTION_FLAGS_USES_PIC_OFFSET_TABLE);
253
254   /* Clear out PARMDECL_MAP.  It was allocated in the caller's frame.  */
255   bzero ((char *) parmdecl_map, max_parm_reg * sizeof (tree));
256   arg_vector = rtvec_alloc (list_length (DECL_ARGUMENTS (fndecl)));
257
258   for (parms = DECL_ARGUMENTS (fndecl), i = 0;
259        parms;
260        parms = TREE_CHAIN (parms), i++)
261     {
262       rtx p = DECL_RTL (parms);
263
264       if (GET_CODE (p) == MEM && copy)
265         {
266           /* Copy the rtl so that modifications of the addresses
267              later in compilation won't affect this arg_vector.
268              Virtual register instantiation can screw the address
269              of the rtl.  */
270           rtx new = copy_rtx (p);
271
272           /* Don't leave the old copy anywhere in this decl.  */
273           if (DECL_RTL (parms) == DECL_INCOMING_RTL (parms)
274               || (GET_CODE (DECL_RTL (parms)) == MEM
275                   && GET_CODE (DECL_INCOMING_RTL (parms)) == MEM
276                   && (XEXP (DECL_RTL (parms), 0)
277                       == XEXP (DECL_INCOMING_RTL (parms), 0))))
278             DECL_INCOMING_RTL (parms) = new;
279           DECL_RTL (parms) = new;
280         }
281
282       RTVEC_ELT (arg_vector, i) = p;
283
284       if (GET_CODE (p) == REG)
285         parmdecl_map[REGNO (p)] = parms;
286       else if (GET_CODE (p) == CONCAT)
287         {
288           rtx preal = gen_realpart (GET_MODE (XEXP (p, 0)), p);
289           rtx pimag = gen_imagpart (GET_MODE (preal), p);
290
291           if (GET_CODE (preal) == REG)
292             parmdecl_map[REGNO (preal)] = parms;
293           if (GET_CODE (pimag) == REG)
294             parmdecl_map[REGNO (pimag)] = parms;
295         }
296
297       /* This flag is cleared later
298          if the function ever modifies the value of the parm.  */
299       TREE_READONLY (parms) = 1;
300     }
301
302   /* Assume we start out in the insns that set up the parameters.  */
303   in_nonparm_insns = 0;
304
305   /* The list of DECL_SAVED_INSNS, starts off with a header which
306      contains the following information:
307
308      the first insn of the function (not including the insns that copy
309      parameters into registers).
310      the first parameter insn of the function,
311      the first label used by that function,
312      the last label used by that function,
313      the highest register number used for parameters,
314      the total number of registers used,
315      the size of the incoming stack area for parameters,
316      the number of bytes popped on return,
317      the stack slot list,
318      some flags that are used to restore compiler globals,
319      the value of current_function_outgoing_args_size,
320      the original argument vector,
321      and the original DECL_INITIAL.  */
322
323   return gen_inline_header_rtx (NULL_RTX, NULL_RTX, min_labelno, max_labelno,
324                                 max_parm_reg, max_reg,
325                                 current_function_args_size,
326                                 current_function_pops_args,
327                                 stack_slot_list, function_flags,
328                                 current_function_outgoing_args_size,
329                                 arg_vector, (rtx) DECL_INITIAL (fndecl));
330 }
331
332 /* Subroutine for `save_for_inline{copying,nocopy}'.  Finishes up the
333    things that must be done to make FNDECL expandable as an inline function.
334    HEAD contains the chain of insns to which FNDECL will expand.  */
335    
336 static void
337 finish_inline (fndecl, head)
338      tree fndecl;
339      rtx head;
340 {
341   NEXT_INSN (head) = get_first_nonparm_insn ();
342   FIRST_PARM_INSN (head) = get_insns ();
343   DECL_SAVED_INSNS (fndecl) = head;
344   DECL_FRAME_SIZE (fndecl) = get_frame_size ();
345   DECL_INLINE (fndecl) = 1;
346 }
347
348 /* Adjust the BLOCK_END_NOTE pointers in a given copied DECL tree so that
349    they all point to the new (copied) rtxs.  */
350
351 static void
352 adjust_copied_decl_tree (block)
353      register tree block;
354 {
355   register tree subblock;
356   register rtx original_end;
357
358   original_end = BLOCK_END_NOTE (block);
359   if (original_end)
360     {
361       BLOCK_END_NOTE (block) = (rtx) NOTE_SOURCE_FILE (original_end);
362       NOTE_SOURCE_FILE (original_end) = 0;
363     }
364
365   /* Process all subblocks.  */
366   for (subblock = BLOCK_SUBBLOCKS (block);
367        subblock;
368        subblock = TREE_CHAIN (subblock))
369     adjust_copied_decl_tree (subblock);
370 }
371
372 /* Make the insns and PARM_DECLs of the current function permanent
373    and record other information in DECL_SAVED_INSNS to allow inlining
374    of this function in subsequent calls.
375
376    This function is called when we are going to immediately compile
377    the insns for FNDECL.  The insns in maybepermanent_obstack cannot be
378    modified by the compilation process, so we copy all of them to
379    new storage and consider the new insns to be the insn chain to be
380    compiled.  Our caller (rest_of_compilation) saves the original
381    DECL_INITIAL and DECL_ARGUMENTS; here we copy them.  */
382
383 void
384 save_for_inline_copying (fndecl)
385      tree fndecl;
386 {
387   rtx first_insn, last_insn, insn;
388   rtx head, copy;
389   int max_labelno, min_labelno, i, len;
390   int max_reg;
391   int max_uid;
392   rtx first_nonparm_insn;
393
394   /* Make and emit a return-label if we have not already done so. 
395      Do this before recording the bounds on label numbers. */
396
397   if (return_label == 0)
398     {
399       return_label = gen_label_rtx ();
400       emit_label (return_label);
401     }
402
403   /* Get some bounds on the labels and registers used.  */
404
405   max_labelno = max_label_num ();
406   min_labelno = get_first_label_num ();
407   max_reg = max_reg_num ();
408
409   /* Set up PARMDECL_MAP which maps pseudo-reg number to its PARM_DECL.
410      Later we set TREE_READONLY to 0 if the parm is modified inside the fn.
411      Also set up ARG_VECTOR, which holds the unmodified DECL_RTX values
412      for the parms, prior to elimination of virtual registers.
413      These values are needed for substituting parms properly.  */
414
415   max_parm_reg = max_parm_reg_num ();
416   parmdecl_map = (tree *) alloca (max_parm_reg * sizeof (tree));
417
418   head = initialize_for_inline (fndecl, min_labelno, max_labelno, max_reg, 1);
419
420   if (current_function_uses_const_pool)
421     {
422       /* Replace any constant pool references with the actual constant.  We
423          will put the constants back in the copy made below.  */
424       for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
425         if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
426           {
427             save_constants (&PATTERN (insn));
428             if (REG_NOTES (insn))
429               save_constants (&REG_NOTES (insn));
430           }
431
432       /* Clear out the constant pool so that we can recreate it with the
433          copied constants below.  */
434       init_const_rtx_hash_table ();
435       clear_const_double_mem ();
436     }
437
438   max_uid = INSN_UID (head);
439
440   /* We have now allocated all that needs to be allocated permanently
441      on the rtx obstack.  Set our high-water mark, so that we
442      can free the rest of this when the time comes.  */
443
444   preserve_data ();
445
446   /* Copy the chain insns of this function.
447      Install the copied chain as the insns of this function,
448      for continued compilation;
449      the original chain is recorded as the DECL_SAVED_INSNS
450      for inlining future calls.  */
451
452   /* If there are insns that copy parms from the stack into pseudo registers,
453      those insns are not copied.  `expand_inline_function' must
454      emit the correct code to handle such things.  */
455
456   insn = get_insns ();
457   if (GET_CODE (insn) != NOTE)
458     abort ();
459   first_insn = rtx_alloc (NOTE);
460   NOTE_SOURCE_FILE (first_insn) = NOTE_SOURCE_FILE (insn);
461   NOTE_LINE_NUMBER (first_insn) = NOTE_LINE_NUMBER (insn);
462   INSN_UID (first_insn) = INSN_UID (insn);
463   PREV_INSN (first_insn) = NULL;
464   NEXT_INSN (first_insn) = NULL;
465   last_insn = first_insn;
466
467   /* Each pseudo-reg in the old insn chain must have a unique rtx in the copy.
468      Make these new rtx's now, and install them in regno_reg_rtx, so they
469      will be the official pseudo-reg rtx's for the rest of compilation.  */
470
471   reg_map = (rtx *) alloca ((max_reg + 1) * sizeof (rtx));
472
473   len = sizeof (struct rtx_def) + (GET_RTX_LENGTH (REG) - 1) * sizeof (rtunion);
474   for (i = max_reg - 1; i > LAST_VIRTUAL_REGISTER; i--)
475     reg_map[i] = (rtx)obstack_copy (function_maybepermanent_obstack,
476                                     regno_reg_rtx[i], len);
477
478   bcopy ((char *) (reg_map + LAST_VIRTUAL_REGISTER + 1),
479          (char *) (regno_reg_rtx + LAST_VIRTUAL_REGISTER + 1),
480          (max_reg - (LAST_VIRTUAL_REGISTER + 1)) * sizeof (rtx));
481
482   /* Likewise each label rtx must have a unique rtx as its copy.  */
483
484   label_map = (rtx *)alloca ((max_labelno - min_labelno) * sizeof (rtx));
485   label_map -= min_labelno;
486
487   for (i = min_labelno; i < max_labelno; i++)
488     label_map[i] = gen_label_rtx ();
489
490   /* Record the mapping of old insns to copied insns.  */
491
492   insn_map = (rtx *) alloca (max_uid * sizeof (rtx));
493   bzero ((char *) insn_map, max_uid * sizeof (rtx));
494
495   /* Get the insn which signals the end of parameter setup code.  */
496   first_nonparm_insn = get_first_nonparm_insn ();
497
498   /* Copy any entries in regno_reg_rtx or DECL_RTLs that reference MEM
499      (the former occurs when a variable has its address taken)
500      since these may be shared and can be changed by virtual
501      register instantiation.  DECL_RTL values for our arguments
502      have already been copied by initialize_for_inline.  */
503   for (i = LAST_VIRTUAL_REGISTER + 1; i < max_reg; i++)
504     if (GET_CODE (regno_reg_rtx[i]) == MEM)
505       XEXP (regno_reg_rtx[i], 0)
506         = copy_for_inline (XEXP (regno_reg_rtx[i], 0));
507
508   /* Copy the tree of subblocks of the function, and the decls in them.
509      We will use the copy for compiling this function, then restore the original
510      subblocks and decls for use when inlining this function.
511
512      Several parts of the compiler modify BLOCK trees.  In particular,
513      instantiate_virtual_regs will instantiate any virtual regs
514      mentioned in the DECL_RTLs of the decls, and loop
515      unrolling will replicate any BLOCK trees inside an unrolled loop.
516
517      The modified subblocks or DECL_RTLs would be incorrect for the original rtl
518      which we will use for inlining.  The rtl might even contain pseudoregs
519      whose space has been freed.  */
520
521   DECL_INITIAL (fndecl) = copy_decl_tree (DECL_INITIAL (fndecl));
522   DECL_ARGUMENTS (fndecl) = copy_decl_list (DECL_ARGUMENTS (fndecl));
523
524   /* Now copy each DECL_RTL which is a MEM,
525      so it is safe to modify their addresses.  */
526   copy_decl_rtls (DECL_INITIAL (fndecl));
527
528   /* The fndecl node acts as its own progenitor, so mark it as such.  */
529   DECL_ABSTRACT_ORIGIN (fndecl) = fndecl;
530
531   /* Now copy the chain of insns.  Do this twice.  The first copy the insn
532      itself and its body.  The second time copy of REG_NOTES.  This is because
533      a REG_NOTE may have a forward pointer to another insn.  */
534
535   for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
536     {
537       orig_asm_operands_vector = 0;
538
539       if (insn == first_nonparm_insn)
540         in_nonparm_insns = 1;
541
542       switch (GET_CODE (insn))
543         {
544         case NOTE:
545           /* No need to keep these.  */
546           if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
547             continue;
548
549           copy = rtx_alloc (NOTE);
550           NOTE_LINE_NUMBER (copy) = NOTE_LINE_NUMBER (insn);
551           if (NOTE_LINE_NUMBER (insn) != NOTE_INSN_BLOCK_END)
552             NOTE_SOURCE_FILE (copy) = NOTE_SOURCE_FILE (insn);
553           else
554             {
555               NOTE_SOURCE_FILE (insn) = (char *) copy;
556               NOTE_SOURCE_FILE (copy) = 0;
557             }
558           break;
559
560         case INSN:
561         case JUMP_INSN:
562         case CALL_INSN:
563           copy = rtx_alloc (GET_CODE (insn));
564
565           if (GET_CODE (insn) == CALL_INSN)
566             CALL_INSN_FUNCTION_USAGE (copy) =
567                    copy_for_inline (CALL_INSN_FUNCTION_USAGE (insn));
568
569           PATTERN (copy) = copy_for_inline (PATTERN (insn));
570           INSN_CODE (copy) = -1;
571           LOG_LINKS (copy) = NULL_RTX;
572           RTX_INTEGRATED_P (copy) = RTX_INTEGRATED_P (insn);
573           break;
574
575         case CODE_LABEL:
576           copy = label_map[CODE_LABEL_NUMBER (insn)];
577           LABEL_NAME (copy) = LABEL_NAME (insn);
578           break;
579
580         case BARRIER:
581           copy = rtx_alloc (BARRIER);
582           break;
583
584         default:
585           abort ();
586         }
587       INSN_UID (copy) = INSN_UID (insn);
588       insn_map[INSN_UID (insn)] = copy;
589       NEXT_INSN (last_insn) = copy;
590       PREV_INSN (copy) = last_insn;
591       last_insn = copy;
592     }
593
594   adjust_copied_decl_tree (DECL_INITIAL (fndecl));
595
596   /* Now copy the REG_NOTES.  */
597   for (insn = NEXT_INSN (get_insns ()); insn; insn = NEXT_INSN (insn))
598     if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
599         && insn_map[INSN_UID(insn)])
600       REG_NOTES (insn_map[INSN_UID (insn)])
601         = copy_for_inline (REG_NOTES (insn));
602
603   NEXT_INSN (last_insn) = NULL;
604
605   finish_inline (fndecl, head);
606
607   set_new_first_and_last_insn (first_insn, last_insn);
608 }
609
610 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
611    For example, this can copy a list made of TREE_LIST nodes.  While copying,
612    for each node copied which doesn't already have is DECL_ABSTRACT_ORIGIN
613    set to some non-zero value, set the DECL_ABSTRACT_ORIGIN of the copy to
614    point to the corresponding (abstract) original node.  */
615
616 static tree
617 copy_decl_list (list)
618      tree list;
619 {
620   tree head;
621   register tree prev, next;
622
623   if (list == 0)
624     return 0;
625
626   head = prev = copy_node (list);
627   if (DECL_ABSTRACT_ORIGIN (head) == NULL_TREE)
628     DECL_ABSTRACT_ORIGIN (head) = list;
629   next = TREE_CHAIN (list);
630   while (next)
631     {
632       register tree copy;
633
634       copy = copy_node (next);
635       if (DECL_ABSTRACT_ORIGIN (copy) == NULL_TREE)
636         DECL_ABSTRACT_ORIGIN (copy) = next;
637       TREE_CHAIN (prev) = copy;
638       prev = copy;
639       next = TREE_CHAIN (next);
640     }
641   return head;
642 }
643
644 /* Make a copy of the entire tree of blocks BLOCK, and return it.  */
645
646 static tree
647 copy_decl_tree (block)
648      tree block;
649 {
650   tree t, vars, subblocks;
651
652   vars = copy_decl_list (BLOCK_VARS (block));
653   subblocks = 0;
654
655   /* Process all subblocks.  */
656   for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t))
657     {
658       tree copy = copy_decl_tree (t);
659       TREE_CHAIN (copy) = subblocks;
660       subblocks = copy;
661     }
662
663   t = copy_node (block);
664   BLOCK_VARS (t) = vars;
665   BLOCK_SUBBLOCKS (t) = nreverse (subblocks);
666   /* If the BLOCK being cloned is already marked as having been instantiated
667      from something else, then leave that `origin' marking alone.  Elsewise,
668      mark the clone as having originated from the BLOCK we are cloning.  */
669   if (BLOCK_ABSTRACT_ORIGIN (t) == NULL_TREE)
670     BLOCK_ABSTRACT_ORIGIN (t) = block;
671   return t;
672 }
673
674 /* Copy DECL_RTLs in all decls in the given BLOCK node.  */
675
676 static void
677 copy_decl_rtls (block)
678      tree block;
679 {
680   tree t;
681
682   for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
683     if (DECL_RTL (t) && GET_CODE (DECL_RTL (t)) == MEM)
684       DECL_RTL (t) = copy_for_inline (DECL_RTL (t));
685
686   /* Process all subblocks.  */
687   for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t))
688     copy_decl_rtls (t);
689 }
690
691 /* Make the insns and PARM_DECLs of the current function permanent
692    and record other information in DECL_SAVED_INSNS to allow inlining
693    of this function in subsequent calls.
694
695    This routine need not copy any insns because we are not going
696    to immediately compile the insns in the insn chain.  There
697    are two cases when we would compile the insns for FNDECL:
698    (1) when FNDECL is expanded inline, and (2) when FNDECL needs to
699    be output at the end of other compilation, because somebody took
700    its address.  In the first case, the insns of FNDECL are copied
701    as it is expanded inline, so FNDECL's saved insns are not
702    modified.  In the second case, FNDECL is used for the last time,
703    so modifying the rtl is not a problem.
704
705    ??? Actually, we do not verify that FNDECL is not inline expanded
706    by other functions which must also be written down at the end
707    of compilation.  We could set flag_no_inline to nonzero when
708    the time comes to write down such functions.  */
709
710 void
711 save_for_inline_nocopy (fndecl)
712      tree fndecl;
713 {
714   rtx insn;
715   rtx head;
716   rtx first_nonparm_insn;
717
718   /* Set up PARMDECL_MAP which maps pseudo-reg number to its PARM_DECL.
719      Later we set TREE_READONLY to 0 if the parm is modified inside the fn.
720      Also set up ARG_VECTOR, which holds the unmodified DECL_RTX values
721      for the parms, prior to elimination of virtual registers.
722      These values are needed for substituting parms properly.  */
723
724   max_parm_reg = max_parm_reg_num ();
725   parmdecl_map = (tree *) alloca (max_parm_reg * sizeof (tree));
726
727   /* Make and emit a return-label if we have not already done so.  */
728
729   if (return_label == 0)
730     {
731       return_label = gen_label_rtx ();
732       emit_label (return_label);
733     }
734
735   head = initialize_for_inline (fndecl, get_first_label_num (),
736                                 max_label_num (), max_reg_num (), 0);
737
738   /* If there are insns that copy parms from the stack into pseudo registers,
739      those insns are not copied.  `expand_inline_function' must
740      emit the correct code to handle such things.  */
741
742   insn = get_insns ();
743   if (GET_CODE (insn) != NOTE)
744     abort ();
745
746   /* Get the insn which signals the end of parameter setup code.  */
747   first_nonparm_insn = get_first_nonparm_insn ();
748
749   /* Now just scan the chain of insns to see what happens to our
750      PARM_DECLs.  If a PARM_DECL is used but never modified, we
751      can substitute its rtl directly when expanding inline (and
752      perform constant folding when its incoming value is constant).
753      Otherwise, we have to copy its value into a new register and track
754      the new register's life.  */
755
756   for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
757     {
758       if (insn == first_nonparm_insn)
759         in_nonparm_insns = 1;
760
761       if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
762         {
763           if (current_function_uses_const_pool)
764             {
765               /* Replace any constant pool references with the actual constant.
766                  We will put the constant back if we need to write the
767                  function out after all.  */
768               save_constants (&PATTERN (insn));
769               if (REG_NOTES (insn))
770                 save_constants (&REG_NOTES (insn));
771             }
772
773           /* Record what interesting things happen to our parameters.  */
774           note_stores (PATTERN (insn), note_modified_parmregs);
775         }
776     }
777
778   /* We have now allocated all that needs to be allocated permanently
779      on the rtx obstack.  Set our high-water mark, so that we
780      can free the rest of this when the time comes.  */
781
782   preserve_data ();
783
784   finish_inline (fndecl, head);
785 }
786 \f
787 /* Given PX, a pointer into an insn, search for references to the constant
788    pool.  Replace each with a CONST that has the mode of the original
789    constant, contains the constant, and has RTX_INTEGRATED_P set.
790    Similarly, constant pool addresses not enclosed in a MEM are replaced
791    with an ADDRESS rtx which also gives the constant, mode, and has
792    RTX_INTEGRATED_P set.  */
793
794 static void
795 save_constants (px)
796      rtx *px;
797 {
798   rtx x;
799   int i, j;
800
801  again:
802   x = *px;
803
804   /* If this is a CONST_DOUBLE, don't try to fix things up in 
805      CONST_DOUBLE_MEM, because this is an infinite recursion.  */
806   if (GET_CODE (x) == CONST_DOUBLE)
807     return;
808   else if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
809            && CONSTANT_POOL_ADDRESS_P (XEXP (x,0)))
810     {
811       enum machine_mode const_mode = get_pool_mode (XEXP (x, 0));
812       rtx new = gen_rtx (CONST, const_mode, get_pool_constant (XEXP (x, 0)));
813       RTX_INTEGRATED_P (new) = 1;
814
815       /* If the MEM was in a different mode than the constant (perhaps we
816          were only looking at the low-order part), surround it with a 
817          SUBREG so we can save both modes.  */
818
819       if (GET_MODE (x) != const_mode)
820         {
821           new = gen_rtx (SUBREG, GET_MODE (x), new, 0);
822           RTX_INTEGRATED_P (new) = 1;
823         }
824
825       *px = new;
826       save_constants (&XEXP (*px, 0));
827     }
828   else if (GET_CODE (x) == SYMBOL_REF
829            && CONSTANT_POOL_ADDRESS_P (x))
830     {
831       *px = gen_rtx (ADDRESS, get_pool_mode (x), get_pool_constant (x));
832       save_constants (&XEXP (*px, 0));
833       RTX_INTEGRATED_P (*px) = 1;
834     }
835
836   else
837     {
838       char *fmt = GET_RTX_FORMAT (GET_CODE (x));
839       int len = GET_RTX_LENGTH (GET_CODE (x));
840
841       for (i = len-1; i >= 0; i--)
842         {
843           switch (fmt[i])
844             {
845             case 'E':
846               for (j = 0; j < XVECLEN (x, i); j++)
847                 save_constants (&XVECEXP (x, i, j));
848               break;
849
850             case 'e':
851               if (XEXP (x, i) == 0)
852                 continue;
853               if (i == 0)
854                 {
855                   /* Hack tail-recursion here.  */
856                   px = &XEXP (x, 0);
857                   goto again;
858                 }
859               save_constants (&XEXP (x, i));
860               break;
861             }
862         }
863     }
864 }
865 \f
866 /* Note whether a parameter is modified or not.  */
867
868 static void
869 note_modified_parmregs (reg, x)
870      rtx reg;
871      rtx x;
872 {
873   if (GET_CODE (reg) == REG && in_nonparm_insns
874       && REGNO (reg) < max_parm_reg
875       && REGNO (reg) >= FIRST_PSEUDO_REGISTER
876       && parmdecl_map[REGNO (reg)] != 0)
877     TREE_READONLY (parmdecl_map[REGNO (reg)]) = 0;
878 }
879
880 /* Copy the rtx ORIG recursively, replacing pseudo-regs and labels
881    according to `reg_map' and `label_map'.  The original rtl insns
882    will be saved for inlining; this is used to make a copy
883    which is used to finish compiling the inline function itself.
884
885    If we find a "saved" constant pool entry, one which was replaced with
886    the value of the constant, convert it back to a constant pool entry.
887    Since the pool wasn't touched, this should simply restore the old
888    address.
889
890    All other kinds of rtx are copied except those that can never be
891    changed during compilation.  */
892
893 static rtx
894 copy_for_inline (orig)
895      rtx orig;
896 {
897   register rtx x = orig;
898   register int i;
899   register enum rtx_code code;
900   register char *format_ptr;
901
902   if (x == 0)
903     return x;
904
905   code = GET_CODE (x);
906
907   /* These types may be freely shared.  */
908
909   switch (code)
910     {
911     case QUEUED:
912     case CONST_INT:
913     case SYMBOL_REF:
914     case PC:
915     case CC0:
916       return x;
917
918     case CONST_DOUBLE:
919       /* We have to make a new CONST_DOUBLE to ensure that we account for
920          it correctly.  Using the old CONST_DOUBLE_MEM data is wrong.  */
921       if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
922         {
923           REAL_VALUE_TYPE d;
924
925           REAL_VALUE_FROM_CONST_DOUBLE (d, x);
926           return CONST_DOUBLE_FROM_REAL_VALUE (d, GET_MODE (x));
927         }
928       else
929         return immed_double_const (CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x),
930                                    VOIDmode);
931
932     case CONST:
933       /* Get constant pool entry for constant in the pool.  */
934       if (RTX_INTEGRATED_P (x))
935         return validize_mem (force_const_mem (GET_MODE (x),
936                                               copy_for_inline (XEXP (x, 0))));
937       break;
938
939     case SUBREG:
940       /* Get constant pool entry, but access in different mode.  */
941       if (RTX_INTEGRATED_P (x))
942         {
943           rtx new
944             = force_const_mem (GET_MODE (SUBREG_REG (x)),
945                                copy_for_inline (XEXP (SUBREG_REG (x), 0)));
946
947           PUT_MODE (new, GET_MODE (x));
948           return validize_mem (new);
949         }
950       break;
951
952     case ADDRESS:
953       /* If not special for constant pool error.  Else get constant pool
954          address.  */
955       if (! RTX_INTEGRATED_P (x))
956         abort ();
957
958       return XEXP (force_const_mem (GET_MODE (x),
959                                     copy_for_inline (XEXP (x, 0))), 0);
960
961     case ASM_OPERANDS:
962       /* If a single asm insn contains multiple output operands
963          then it contains multiple ASM_OPERANDS rtx's that share operand 3.
964          We must make sure that the copied insn continues to share it.  */
965       if (orig_asm_operands_vector == XVEC (orig, 3))
966         {
967           x = rtx_alloc (ASM_OPERANDS);
968           x->volatil = orig->volatil;
969           XSTR (x, 0) = XSTR (orig, 0);
970           XSTR (x, 1) = XSTR (orig, 1);
971           XINT (x, 2) = XINT (orig, 2);
972           XVEC (x, 3) = copy_asm_operands_vector;
973           XVEC (x, 4) = copy_asm_constraints_vector;
974           XSTR (x, 5) = XSTR (orig, 5);
975           XINT (x, 6) = XINT (orig, 6);
976           return x;
977         }
978       break;
979
980     case MEM:
981       /* A MEM is usually allowed to be shared if its address is constant
982          or is a constant plus one of the special registers.
983
984          We do not allow sharing of addresses that are either a special
985          register or the sum of a constant and a special register because
986          it is possible for unshare_all_rtl to copy the address, into memory
987          that won't be saved.  Although the MEM can safely be shared, and
988          won't be copied there, the address itself cannot be shared, and may
989          need to be copied. 
990
991          There are also two exceptions with constants: The first is if the
992          constant is a LABEL_REF or the sum of the LABEL_REF
993          and an integer.  This case can happen if we have an inline
994          function that supplies a constant operand to the call of another
995          inline function that uses it in a switch statement.  In this case,
996          we will be replacing the LABEL_REF, so we have to replace this MEM
997          as well.
998
999          The second case is if we have a (const (plus (address ..) ...)).
1000          In that case we need to put back the address of the constant pool
1001          entry.  */
1002
1003       if (CONSTANT_ADDRESS_P (XEXP (x, 0))
1004           && GET_CODE (XEXP (x, 0)) != LABEL_REF
1005           && ! (GET_CODE (XEXP (x, 0)) == CONST
1006                 && (GET_CODE (XEXP (XEXP (x, 0), 0)) == PLUS
1007                     && ((GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0))
1008                         == LABEL_REF)
1009                         || (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0))
1010                             == ADDRESS)))))
1011         return x;
1012       break;
1013
1014     case LABEL_REF:
1015       /* If this is a non-local label, just make a new LABEL_REF.
1016          Otherwise, use the new label as well.  */
1017       x = gen_rtx (LABEL_REF, GET_MODE (orig),
1018                    LABEL_REF_NONLOCAL_P (orig) ? XEXP (orig, 0)
1019                    : label_map[CODE_LABEL_NUMBER (XEXP (orig, 0))]);
1020       LABEL_REF_NONLOCAL_P (x) = LABEL_REF_NONLOCAL_P (orig);
1021       LABEL_OUTSIDE_LOOP_P (x) = LABEL_OUTSIDE_LOOP_P (orig);
1022       return x;
1023
1024     case REG:
1025       if (REGNO (x) > LAST_VIRTUAL_REGISTER)
1026         return reg_map [REGNO (x)];
1027       else
1028         return x;
1029
1030     case SET:
1031       /* If a parm that gets modified lives in a pseudo-reg,
1032          clear its TREE_READONLY to prevent certain optimizations.  */
1033       {
1034         rtx dest = SET_DEST (x);
1035
1036         while (GET_CODE (dest) == STRICT_LOW_PART
1037                || GET_CODE (dest) == ZERO_EXTRACT
1038                || GET_CODE (dest) == SUBREG)
1039           dest = XEXP (dest, 0);
1040
1041         if (GET_CODE (dest) == REG
1042             && REGNO (dest) < max_parm_reg
1043             && REGNO (dest) >= FIRST_PSEUDO_REGISTER
1044             && parmdecl_map[REGNO (dest)] != 0
1045             /* The insn to load an arg pseudo from a stack slot
1046                does not count as modifying it.  */
1047             && in_nonparm_insns)
1048           TREE_READONLY (parmdecl_map[REGNO (dest)]) = 0;
1049       }
1050       break;
1051
1052 #if 0 /* This is a good idea, but here is the wrong place for it.  */
1053       /* Arrange that CONST_INTs always appear as the second operand
1054          if they appear, and that `frame_pointer_rtx' or `arg_pointer_rtx'
1055          always appear as the first.  */
1056     case PLUS:
1057       if (GET_CODE (XEXP (x, 0)) == CONST_INT
1058           || (XEXP (x, 1) == frame_pointer_rtx
1059               || (ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
1060                   && XEXP (x, 1) == arg_pointer_rtx)))
1061         {
1062           rtx t = XEXP (x, 0);
1063           XEXP (x, 0) = XEXP (x, 1);
1064           XEXP (x, 1) = t;
1065         }
1066       break;
1067 #endif
1068     }
1069
1070   /* Replace this rtx with a copy of itself.  */
1071
1072   x = rtx_alloc (code);
1073   bcopy ((char *) orig, (char *) x,
1074          (sizeof (*x) - sizeof (x->fld)
1075           + sizeof (x->fld[0]) * GET_RTX_LENGTH (code)));
1076
1077   /* Now scan the subexpressions recursively.
1078      We can store any replaced subexpressions directly into X
1079      since we know X is not shared!  Any vectors in X
1080      must be copied if X was copied.  */
1081
1082   format_ptr = GET_RTX_FORMAT (code);
1083
1084   for (i = 0; i < GET_RTX_LENGTH (code); i++)
1085     {
1086       switch (*format_ptr++)
1087         {
1088         case 'e':
1089           XEXP (x, i) = copy_for_inline (XEXP (x, i));
1090           break;
1091
1092         case 'u':
1093           /* Change any references to old-insns to point to the
1094              corresponding copied insns.  */
1095           XEXP (x, i) = insn_map[INSN_UID (XEXP (x, i))];
1096           break;
1097
1098         case 'E':
1099           if (XVEC (x, i) != NULL && XVECLEN (x, i) != 0)
1100             {
1101               register int j;
1102
1103               XVEC (x, i) = gen_rtvec_v (XVECLEN (x, i), &XVECEXP (x, i, 0));
1104               for (j = 0; j < XVECLEN (x, i); j++)
1105                 XVECEXP (x, i, j)
1106                   = copy_for_inline (XVECEXP (x, i, j));
1107             }
1108           break;
1109         }
1110     }
1111
1112   if (code == ASM_OPERANDS && orig_asm_operands_vector == 0)
1113     {
1114       orig_asm_operands_vector = XVEC (orig, 3);
1115       copy_asm_operands_vector = XVEC (x, 3);
1116       copy_asm_constraints_vector = XVEC (x, 4);
1117     }
1118
1119   return x;
1120 }
1121
1122 /* Unfortunately, we need a global copy of const_equiv map for communication
1123    with a function called from note_stores.  Be *very* careful that this
1124    is used properly in the presence of recursion.  */
1125
1126 rtx *global_const_equiv_map;
1127 int global_const_equiv_map_size;
1128 \f
1129 #define FIXED_BASE_PLUS_P(X) \
1130   (GET_CODE (X) == PLUS && GET_CODE (XEXP (X, 1)) == CONST_INT  \
1131    && GET_CODE (XEXP (X, 0)) == REG                             \
1132    && REGNO (XEXP (X, 0)) >= FIRST_VIRTUAL_REGISTER             \
1133    && REGNO (XEXP (X, 0)) <= LAST_VIRTUAL_REGISTER)
1134
1135 /* Integrate the procedure defined by FNDECL.  Note that this function
1136    may wind up calling itself.  Since the static variables are not
1137    reentrant, we do not assign them until after the possibility
1138    of recursion is eliminated.
1139
1140    If IGNORE is nonzero, do not produce a value.
1141    Otherwise store the value in TARGET if it is nonzero and that is convenient.
1142
1143    Value is:
1144    (rtx)-1 if we could not substitute the function
1145    0 if we substituted it and it does not produce a value
1146    else an rtx for where the value is stored.  */
1147
1148 rtx
1149 expand_inline_function (fndecl, parms, target, ignore, type, structure_value_addr)
1150      tree fndecl, parms;
1151      rtx target;
1152      int ignore;
1153      tree type;
1154      rtx structure_value_addr;
1155 {
1156   tree formal, actual, block;
1157   rtx header = DECL_SAVED_INSNS (fndecl);
1158   rtx insns = FIRST_FUNCTION_INSN (header);
1159   rtx parm_insns = FIRST_PARM_INSN (header);
1160   tree *arg_trees;
1161   rtx *arg_vals;
1162   rtx insn;
1163   int max_regno;
1164   register int i;
1165   int min_labelno = FIRST_LABELNO (header);
1166   int max_labelno = LAST_LABELNO (header);
1167   int nargs;
1168   rtx local_return_label = 0;
1169   rtx loc;
1170   rtx stack_save = 0;
1171   rtx temp;
1172   struct inline_remap *map;
1173   rtx cc0_insn = 0;
1174   rtvec arg_vector = ORIGINAL_ARG_VECTOR (header);
1175   rtx static_chain_value = 0;
1176
1177   /* Allow for equivalences of the pseudos we make for virtual fp and ap.  */
1178   max_regno = MAX_REGNUM (header) + 3;
1179   if (max_regno < FIRST_PSEUDO_REGISTER)
1180     abort ();
1181
1182   nargs = list_length (DECL_ARGUMENTS (fndecl));
1183
1184   /* Check that the parms type match and that sufficient arguments were
1185      passed.  Since the appropriate conversions or default promotions have
1186      already been applied, the machine modes should match exactly.  */
1187
1188   for (formal = DECL_ARGUMENTS (fndecl),
1189        actual = parms;
1190        formal;
1191        formal = TREE_CHAIN (formal),
1192        actual = TREE_CHAIN (actual))
1193     {
1194       tree arg;
1195       enum machine_mode mode;
1196
1197       if (actual == 0)
1198         return (rtx) (HOST_WIDE_INT) -1;
1199
1200       arg = TREE_VALUE (actual);
1201       mode= TYPE_MODE (DECL_ARG_TYPE (formal));
1202
1203       if (mode != TYPE_MODE (TREE_TYPE (arg))
1204           /* If they are block mode, the types should match exactly.
1205              They don't match exactly if TREE_TYPE (FORMAL) == ERROR_MARK_NODE,
1206              which could happen if the parameter has incomplete type.  */
1207           || (mode == BLKmode && TREE_TYPE (arg) != TREE_TYPE (formal)))
1208         return (rtx) (HOST_WIDE_INT) -1;
1209     }
1210
1211   /* Extra arguments are valid, but will be ignored below, so we must
1212      evaluate them here for side-effects.  */
1213   for (; actual; actual = TREE_CHAIN (actual))
1214     expand_expr (TREE_VALUE (actual), const0_rtx,
1215                  TYPE_MODE (TREE_TYPE (TREE_VALUE (actual))), 0);
1216
1217   /* Make a binding contour to keep inline cleanups called at
1218      outer function-scope level from looking like they are shadowing
1219      parameter declarations.  */
1220   pushlevel (0);
1221
1222   /* Make a fresh binding contour that we can easily remove.  */
1223   pushlevel (0);
1224   expand_start_bindings (0);
1225   if (GET_CODE (parm_insns) == NOTE
1226       && NOTE_LINE_NUMBER (parm_insns) > 0)
1227     {
1228       rtx note = emit_note (NOTE_SOURCE_FILE (parm_insns),
1229                             NOTE_LINE_NUMBER (parm_insns));
1230       if (note)
1231         RTX_INTEGRATED_P (note) = 1;
1232     }
1233
1234   /* Expand the function arguments.  Do this first so that any
1235      new registers get created before we allocate the maps.  */
1236
1237   arg_vals = (rtx *) alloca (nargs * sizeof (rtx));
1238   arg_trees = (tree *) alloca (nargs * sizeof (tree));
1239
1240   for (formal = DECL_ARGUMENTS (fndecl), actual = parms, i = 0;
1241        formal;
1242        formal = TREE_CHAIN (formal), actual = TREE_CHAIN (actual), i++)
1243     {
1244       /* Actual parameter, converted to the type of the argument within the
1245          function.  */
1246       tree arg = convert (TREE_TYPE (formal), TREE_VALUE (actual));
1247       /* Mode of the variable used within the function.  */
1248       enum machine_mode mode = TYPE_MODE (TREE_TYPE (formal));
1249       int invisiref = 0;
1250
1251       /* Make sure this formal has some correspondence in the users code
1252        * before emitting any line notes for it.  */
1253       if (DECL_SOURCE_LINE (formal))
1254         {
1255           rtx note = emit_note (DECL_SOURCE_FILE (formal),
1256                                 DECL_SOURCE_LINE (formal));
1257           if (note)
1258             RTX_INTEGRATED_P (note) = 1;
1259         }
1260
1261       arg_trees[i] = arg;
1262       loc = RTVEC_ELT (arg_vector, i);
1263
1264       /* If this is an object passed by invisible reference, we copy the
1265          object into a stack slot and save its address.  If this will go
1266          into memory, we do nothing now.  Otherwise, we just expand the
1267          argument.  */
1268       if (GET_CODE (loc) == MEM && GET_CODE (XEXP (loc, 0)) == REG
1269           && REGNO (XEXP (loc, 0)) > LAST_VIRTUAL_REGISTER)
1270         {
1271           rtx stack_slot
1272             = assign_stack_temp (TYPE_MODE (TREE_TYPE (arg)),
1273                                  int_size_in_bytes (TREE_TYPE (arg)), 1);
1274           MEM_IN_STRUCT_P (stack_slot) = AGGREGATE_TYPE_P (TREE_TYPE (arg));
1275
1276           store_expr (arg, stack_slot, 0);
1277
1278           arg_vals[i] = XEXP (stack_slot, 0);
1279           invisiref = 1;
1280         }
1281       else if (GET_CODE (loc) != MEM)
1282         {
1283           if (GET_MODE (loc) != TYPE_MODE (TREE_TYPE (arg)))
1284             /* The mode if LOC and ARG can differ if LOC was a variable
1285                that had its mode promoted via PROMOTED_MODE.  */
1286             arg_vals[i] = convert_modes (GET_MODE (loc),
1287                                          TYPE_MODE (TREE_TYPE (arg)),
1288                                          expand_expr (arg, NULL_RTX, mode,
1289                                                       EXPAND_SUM),
1290                                          TREE_UNSIGNED (TREE_TYPE (formal)));
1291           else
1292             arg_vals[i] = expand_expr (arg, NULL_RTX, mode, EXPAND_SUM);
1293         }
1294       else
1295         arg_vals[i] = 0;
1296
1297       if (arg_vals[i] != 0
1298           && (! TREE_READONLY (formal)
1299               /* If the parameter is not read-only, copy our argument through
1300                  a register.  Also, we cannot use ARG_VALS[I] if it overlaps
1301                  TARGET in any way.  In the inline function, they will likely
1302                  be two different pseudos, and `safe_from_p' will make all
1303                  sorts of smart assumptions about their not conflicting.
1304                  But if ARG_VALS[I] overlaps TARGET, these assumptions are
1305                  wrong, so put ARG_VALS[I] into a fresh register.
1306                  Don't worry about invisible references, since their stack
1307                  temps will never overlap the target.  */
1308               || (target != 0
1309                   && ! invisiref
1310                   && (GET_CODE (arg_vals[i]) == REG
1311                       || GET_CODE (arg_vals[i]) == SUBREG
1312                       || GET_CODE (arg_vals[i]) == MEM)
1313                   && reg_overlap_mentioned_p (arg_vals[i], target))
1314               /* ??? We must always copy a SUBREG into a REG, because it might
1315                  get substituted into an address, and not all ports correctly
1316                  handle SUBREGs in addresses.  */
1317               || (GET_CODE (arg_vals[i]) == SUBREG)))
1318         arg_vals[i] = copy_to_mode_reg (GET_MODE (loc), arg_vals[i]);
1319     }
1320         
1321   /* Allocate the structures we use to remap things.  */
1322
1323   map = (struct inline_remap *) alloca (sizeof (struct inline_remap));
1324   map->fndecl = fndecl;
1325
1326   map->reg_map = (rtx *) alloca (max_regno * sizeof (rtx));
1327   bzero ((char *) map->reg_map, max_regno * sizeof (rtx));
1328
1329   map->label_map = (rtx *)alloca ((max_labelno - min_labelno) * sizeof (rtx));
1330   map->label_map -= min_labelno;
1331
1332   map->insn_map = (rtx *) alloca (INSN_UID (header) * sizeof (rtx));
1333   bzero ((char *) map->insn_map, INSN_UID (header) * sizeof (rtx));
1334   map->min_insnno = 0;
1335   map->max_insnno = INSN_UID (header);
1336
1337   map->integrating = 1;
1338
1339   /* const_equiv_map maps pseudos in our routine to constants, so it needs to
1340      be large enough for all our pseudos.  This is the number we are currently
1341      using plus the number in the called routine, plus 15 for each arg,
1342      five to compute the virtual frame pointer, and five for the return value.
1343      This should be enough for most cases.  We do not reference entries
1344      outside the range of the map.
1345
1346      ??? These numbers are quite arbitrary and were obtained by
1347      experimentation.  At some point, we should try to allocate the
1348      table after all the parameters are set up so we an more accurately
1349      estimate the number of pseudos we will need.  */
1350
1351   map->const_equiv_map_size
1352     = max_reg_num () + (max_regno - FIRST_PSEUDO_REGISTER) + 15 * nargs + 10;
1353
1354   map->const_equiv_map
1355     = (rtx *)alloca (map->const_equiv_map_size * sizeof (rtx));
1356   bzero ((char *) map->const_equiv_map,
1357          map->const_equiv_map_size * sizeof (rtx));
1358
1359   map->const_age_map
1360     = (unsigned *)alloca (map->const_equiv_map_size * sizeof (unsigned));
1361   bzero ((char *) map->const_age_map,
1362          map->const_equiv_map_size * sizeof (unsigned));
1363   map->const_age = 0;
1364
1365   /* Record the current insn in case we have to set up pointers to frame
1366      and argument memory blocks.  */
1367   map->insns_at_start = get_last_insn ();
1368
1369   /* Update the outgoing argument size to allow for those in the inlined
1370      function.  */
1371   if (OUTGOING_ARGS_SIZE (header) > current_function_outgoing_args_size)
1372     current_function_outgoing_args_size = OUTGOING_ARGS_SIZE (header);
1373
1374   /* If the inline function needs to make PIC references, that means
1375      that this function's PIC offset table must be used.  */
1376   if (FUNCTION_FLAGS (header) & FUNCTION_FLAGS_USES_PIC_OFFSET_TABLE)
1377     current_function_uses_pic_offset_table = 1;
1378
1379   /* If this function needs a context, set it up.  */
1380   if (FUNCTION_FLAGS (header) & FUNCTION_FLAGS_NEEDS_CONTEXT)
1381     static_chain_value = lookup_static_chain (fndecl);
1382
1383   /* Process each argument.  For each, set up things so that the function's
1384      reference to the argument will refer to the argument being passed.
1385      We only replace REG with REG here.  Any simplifications are done
1386      via const_equiv_map.
1387
1388      We make two passes:  In the first, we deal with parameters that will
1389      be placed into registers, since we need to ensure that the allocated
1390      register number fits in const_equiv_map.  Then we store all non-register
1391      parameters into their memory location.  */
1392
1393   /* Don't try to free temp stack slots here, because we may put one of the
1394      parameters into a temp stack slot.  */
1395
1396   for (i = 0; i < nargs; i++)
1397     {
1398       rtx copy = arg_vals[i];
1399
1400       loc = RTVEC_ELT (arg_vector, i);
1401
1402       /* There are three cases, each handled separately.  */
1403       if (GET_CODE (loc) == MEM && GET_CODE (XEXP (loc, 0)) == REG
1404           && REGNO (XEXP (loc, 0)) > LAST_VIRTUAL_REGISTER)
1405         {
1406           /* This must be an object passed by invisible reference (it could
1407              also be a variable-sized object, but we forbid inlining functions
1408              with variable-sized arguments).  COPY is the address of the
1409              actual value (this computation will cause it to be copied).  We
1410              map that address for the register, noting the actual address as
1411              an equivalent in case it can be substituted into the insns.  */
1412
1413           if (GET_CODE (copy) != REG)
1414             {
1415               temp = copy_addr_to_reg (copy);
1416               if ((CONSTANT_P (copy) || FIXED_BASE_PLUS_P (copy))
1417                   && REGNO (temp) < map->const_equiv_map_size)
1418                 {
1419                   map->const_equiv_map[REGNO (temp)] = copy;
1420                   map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
1421                 }
1422               copy = temp;
1423             }
1424           map->reg_map[REGNO (XEXP (loc, 0))] = copy;
1425         }
1426       else if (GET_CODE (loc) == MEM)
1427         {
1428           /* This is the case of a parameter that lives in memory.
1429              It will live in the block we allocate in the called routine's
1430              frame that simulates the incoming argument area.  Do nothing
1431              now; we will call store_expr later.  */
1432           ;
1433         }
1434       else if (GET_CODE (loc) == REG)
1435         {
1436           /* This is the good case where the parameter is in a register.
1437              If it is read-only and our argument is a constant, set up the
1438              constant equivalence.
1439
1440              If LOC is REG_USERVAR_P, the usual case, COPY must also have
1441              that flag set if it is a register.
1442
1443              Also, don't allow hard registers here; they might not be valid
1444              when substituted into insns. */
1445
1446           if ((GET_CODE (copy) != REG && GET_CODE (copy) != SUBREG)
1447               || (GET_CODE (copy) == REG && REG_USERVAR_P (loc)
1448                   && ! REG_USERVAR_P (copy))
1449               || (GET_CODE (copy) == REG
1450                   && REGNO (copy) < FIRST_PSEUDO_REGISTER))
1451             {
1452               temp = copy_to_mode_reg (GET_MODE (loc), copy);
1453               REG_USERVAR_P (temp) = REG_USERVAR_P (loc);
1454               if ((CONSTANT_P (copy) || FIXED_BASE_PLUS_P (copy))
1455                   && REGNO (temp) < map->const_equiv_map_size)
1456                 {
1457                   map->const_equiv_map[REGNO (temp)] = copy;
1458                   map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
1459                 }
1460               copy = temp;
1461             }
1462           map->reg_map[REGNO (loc)] = copy;
1463         }
1464       else if (GET_CODE (loc) == CONCAT)
1465         {
1466           /* This is the good case where the parameter is in a
1467              pair of separate pseudos.
1468              If it is read-only and our argument is a constant, set up the
1469              constant equivalence.
1470
1471              If LOC is REG_USERVAR_P, the usual case, COPY must also have
1472              that flag set if it is a register.
1473
1474              Also, don't allow hard registers here; they might not be valid
1475              when substituted into insns. */
1476           rtx locreal = gen_realpart (GET_MODE (XEXP (loc, 0)), loc);
1477           rtx locimag = gen_imagpart (GET_MODE (XEXP (loc, 0)), loc);
1478           rtx copyreal = gen_realpart (GET_MODE (locreal), copy);
1479           rtx copyimag = gen_imagpart (GET_MODE (locimag), copy);
1480
1481           if ((GET_CODE (copyreal) != REG && GET_CODE (copyreal) != SUBREG)
1482               || (GET_CODE (copyreal) == REG && REG_USERVAR_P (locreal)
1483                   && ! REG_USERVAR_P (copyreal))
1484               || (GET_CODE (copyreal) == REG
1485                   && REGNO (copyreal) < FIRST_PSEUDO_REGISTER))
1486             {
1487               temp = copy_to_mode_reg (GET_MODE (locreal), copyreal);
1488               REG_USERVAR_P (temp) = REG_USERVAR_P (locreal);
1489               if ((CONSTANT_P (copyreal) || FIXED_BASE_PLUS_P (copyreal))
1490                   && REGNO (temp) < map->const_equiv_map_size)
1491                 {
1492                   map->const_equiv_map[REGNO (temp)] = copyreal;
1493                   map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
1494                 }
1495               copyreal = temp;
1496             }
1497           map->reg_map[REGNO (locreal)] = copyreal;
1498
1499           if ((GET_CODE (copyimag) != REG && GET_CODE (copyimag) != SUBREG)
1500               || (GET_CODE (copyimag) == REG && REG_USERVAR_P (locimag)
1501                   && ! REG_USERVAR_P (copyimag))
1502               || (GET_CODE (copyimag) == REG
1503                   && REGNO (copyimag) < FIRST_PSEUDO_REGISTER))
1504             {
1505               temp = copy_to_mode_reg (GET_MODE (locimag), copyimag);
1506               REG_USERVAR_P (temp) = REG_USERVAR_P (locimag);
1507               if ((CONSTANT_P (copyimag) || FIXED_BASE_PLUS_P (copyimag))
1508                   && REGNO (temp) < map->const_equiv_map_size)
1509                 {
1510                   map->const_equiv_map[REGNO (temp)] = copyimag;
1511                   map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
1512                 }
1513               copyimag = temp;
1514             }
1515           map->reg_map[REGNO (locimag)] = copyimag;
1516         }
1517       else
1518         abort ();
1519     }
1520
1521   /* Now do the parameters that will be placed in memory.  */
1522
1523   for (formal = DECL_ARGUMENTS (fndecl), i = 0;
1524        formal; formal = TREE_CHAIN (formal), i++)
1525     {
1526       loc = RTVEC_ELT (arg_vector, i);
1527
1528       if (GET_CODE (loc) == MEM
1529           /* Exclude case handled above.  */
1530           && ! (GET_CODE (XEXP (loc, 0)) == REG
1531                 && REGNO (XEXP (loc, 0)) > LAST_VIRTUAL_REGISTER))
1532         {
1533           rtx note = emit_note (DECL_SOURCE_FILE (formal),
1534                                 DECL_SOURCE_LINE (formal));
1535           if (note)
1536             RTX_INTEGRATED_P (note) = 1;
1537
1538           /* Compute the address in the area we reserved and store the
1539              value there.  */
1540           temp = copy_rtx_and_substitute (loc, map);
1541           subst_constants (&temp, NULL_RTX, map);
1542           apply_change_group ();
1543           if (! memory_address_p (GET_MODE (temp), XEXP (temp, 0)))
1544             temp = change_address (temp, VOIDmode, XEXP (temp, 0));
1545           store_expr (arg_trees[i], temp, 0);
1546         }
1547     }
1548
1549   /* Deal with the places that the function puts its result.
1550      We are driven by what is placed into DECL_RESULT.
1551
1552      Initially, we assume that we don't have anything special handling for
1553      REG_FUNCTION_RETURN_VALUE_P.  */
1554
1555   map->inline_target = 0;
1556   loc = DECL_RTL (DECL_RESULT (fndecl));
1557   if (TYPE_MODE (type) == VOIDmode)
1558     /* There is no return value to worry about.  */
1559     ;
1560   else if (GET_CODE (loc) == MEM)
1561     {
1562       if (! structure_value_addr || ! aggregate_value_p (DECL_RESULT (fndecl)))
1563         abort ();
1564   
1565       /* Pass the function the address in which to return a structure value.
1566          Note that a constructor can cause someone to call us with
1567          STRUCTURE_VALUE_ADDR, but the initialization takes place
1568          via the first parameter, rather than the struct return address.
1569
1570          We have two cases:  If the address is a simple register indirect,
1571          use the mapping mechanism to point that register to our structure
1572          return address.  Otherwise, store the structure return value into
1573          the place that it will be referenced from.  */
1574
1575       if (GET_CODE (XEXP (loc, 0)) == REG)
1576         {
1577           temp = force_reg (Pmode, structure_value_addr);
1578           map->reg_map[REGNO (XEXP (loc, 0))] = temp;
1579           if ((CONSTANT_P (structure_value_addr)
1580                || (GET_CODE (structure_value_addr) == PLUS
1581                    && XEXP (structure_value_addr, 0) == virtual_stack_vars_rtx
1582                    && GET_CODE (XEXP (structure_value_addr, 1)) == CONST_INT))
1583               && REGNO (temp) < map->const_equiv_map_size)
1584             {
1585               map->const_equiv_map[REGNO (temp)] = structure_value_addr;
1586               map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
1587             }
1588         }
1589       else
1590         {
1591           temp = copy_rtx_and_substitute (loc, map);
1592           subst_constants (&temp, NULL_RTX, map);
1593           apply_change_group ();
1594           emit_move_insn (temp, structure_value_addr);
1595         }
1596     }
1597   else if (ignore)
1598     /* We will ignore the result value, so don't look at its structure.
1599        Note that preparations for an aggregate return value
1600        do need to be made (above) even if it will be ignored.  */
1601     ;
1602   else if (GET_CODE (loc) == REG)
1603     {
1604       /* The function returns an object in a register and we use the return
1605          value.  Set up our target for remapping.  */
1606
1607       /* Machine mode function was declared to return.   */
1608       enum machine_mode departing_mode = TYPE_MODE (type);
1609       /* (Possibly wider) machine mode it actually computes
1610          (for the sake of callers that fail to declare it right).  */
1611       enum machine_mode arriving_mode
1612         = TYPE_MODE (TREE_TYPE (DECL_RESULT (fndecl)));
1613       rtx reg_to_map;
1614
1615       /* Don't use MEMs as direct targets because on some machines
1616          substituting a MEM for a REG makes invalid insns.
1617          Let the combiner substitute the MEM if that is valid.  */
1618       if (target == 0 || GET_CODE (target) != REG
1619           || GET_MODE (target) != departing_mode)
1620         target = gen_reg_rtx (departing_mode);
1621
1622       /* If function's value was promoted before return,
1623          avoid machine mode mismatch when we substitute INLINE_TARGET.
1624          But TARGET is what we will return to the caller.  */
1625       if (arriving_mode != departing_mode)
1626         reg_to_map = gen_rtx (SUBREG, arriving_mode, target, 0);
1627       else
1628         reg_to_map = target;
1629
1630       /* Usually, the result value is the machine's return register.
1631          Sometimes it may be a pseudo. Handle both cases.  */
1632       if (REG_FUNCTION_VALUE_P (loc))
1633         map->inline_target = reg_to_map;
1634       else
1635         map->reg_map[REGNO (loc)] = reg_to_map;
1636     }
1637
1638   /* Make new label equivalences for the labels in the called function.  */
1639   for (i = min_labelno; i < max_labelno; i++)
1640     map->label_map[i] = gen_label_rtx ();
1641
1642   /* Perform postincrements before actually calling the function.  */
1643   emit_queue ();
1644
1645   /* Clean up stack so that variables might have smaller offsets.  */
1646   do_pending_stack_adjust ();
1647
1648   /* Save a copy of the location of const_equiv_map for mark_stores, called
1649      via note_stores.  */
1650   global_const_equiv_map = map->const_equiv_map;
1651   global_const_equiv_map_size = map->const_equiv_map_size;
1652
1653   /* If the called function does an alloca, save and restore the
1654      stack pointer around the call.  This saves stack space, but
1655      also is required if this inline is being done between two
1656      pushes.  */
1657   if (FUNCTION_FLAGS (header) & FUNCTION_FLAGS_CALLS_ALLOCA)
1658     emit_stack_save (SAVE_BLOCK, &stack_save, NULL_RTX);
1659
1660   /* Now copy the insns one by one.  Do this in two passes, first the insns and
1661      then their REG_NOTES, just like save_for_inline.  */
1662
1663   /* This loop is very similar to the loop in copy_loop_body in unroll.c.  */
1664
1665   for (insn = insns; insn; insn = NEXT_INSN (insn))
1666     {
1667       rtx copy, pattern, set;
1668
1669       map->orig_asm_operands_vector = 0;
1670
1671       switch (GET_CODE (insn))
1672         {
1673         case INSN:
1674           pattern = PATTERN (insn);
1675           set = single_set (insn);
1676           copy = 0;
1677           if (GET_CODE (pattern) == USE
1678               && GET_CODE (XEXP (pattern, 0)) == REG
1679               && REG_FUNCTION_VALUE_P (XEXP (pattern, 0)))
1680             /* The (USE (REG n)) at return from the function should
1681                be ignored since we are changing (REG n) into
1682                inline_target.  */
1683             break;
1684
1685           /* Ignore setting a function value that we don't want to use.  */
1686           if (map->inline_target == 0
1687               && set != 0
1688               && GET_CODE (SET_DEST (set)) == REG
1689               && REG_FUNCTION_VALUE_P (SET_DEST (set)))
1690             {
1691               if (volatile_refs_p (SET_SRC (set)))
1692                 {
1693                   rtx new_set;
1694
1695                   /* If we must not delete the source,
1696                      load it into a new temporary.  */
1697                   copy = emit_insn (copy_rtx_and_substitute (pattern, map));
1698
1699                   new_set = single_set (copy);
1700                   if (new_set == 0)
1701                     abort ();
1702
1703                   SET_DEST (new_set)
1704                     = gen_reg_rtx (GET_MODE (SET_DEST (new_set)));
1705                 }
1706               else
1707                 break;
1708             }
1709
1710           /* If this is setting the static chain rtx, omit it.  */
1711           else if (static_chain_value != 0
1712                    && set != 0
1713                    && GET_CODE (SET_DEST (set)) == REG
1714                    && rtx_equal_p (SET_DEST (set),
1715                                    static_chain_incoming_rtx))
1716             break;
1717
1718           /* If this is setting the static chain pseudo, set it from
1719              the value we want to give it instead.  */
1720           else if (static_chain_value != 0
1721                    && set != 0
1722                    && rtx_equal_p (SET_SRC (set),
1723                                    static_chain_incoming_rtx))
1724             {
1725               rtx newdest = copy_rtx_and_substitute (SET_DEST (set), map);
1726
1727               copy = emit_move_insn (newdest, static_chain_value);
1728               static_chain_value = 0;
1729             }
1730           else
1731             copy = emit_insn (copy_rtx_and_substitute (pattern, map));
1732           /* REG_NOTES will be copied later.  */
1733
1734 #ifdef HAVE_cc0
1735           /* If this insn is setting CC0, it may need to look at
1736              the insn that uses CC0 to see what type of insn it is.
1737              In that case, the call to recog via validate_change will
1738              fail.  So don't substitute constants here.  Instead,
1739              do it when we emit the following insn.
1740
1741              For example, see the pyr.md file.  That machine has signed and
1742              unsigned compares.  The compare patterns must check the
1743              following branch insn to see which what kind of compare to
1744              emit.
1745
1746              If the previous insn set CC0, substitute constants on it as
1747              well.  */
1748           if (sets_cc0_p (PATTERN (copy)) != 0)
1749             cc0_insn = copy;
1750           else
1751             {
1752               if (cc0_insn)
1753                 try_constants (cc0_insn, map);
1754               cc0_insn = 0;
1755               try_constants (copy, map);
1756             }
1757 #else
1758           try_constants (copy, map);
1759 #endif
1760           break;
1761
1762         case JUMP_INSN:
1763           if (GET_CODE (PATTERN (insn)) == RETURN)
1764             {
1765               if (local_return_label == 0)
1766                 local_return_label = gen_label_rtx ();
1767               pattern = gen_jump (local_return_label);
1768             }
1769           else
1770             pattern = copy_rtx_and_substitute (PATTERN (insn), map);
1771
1772           copy = emit_jump_insn (pattern);
1773
1774 #ifdef HAVE_cc0
1775           if (cc0_insn)
1776             try_constants (cc0_insn, map);
1777           cc0_insn = 0;
1778 #endif
1779           try_constants (copy, map);
1780
1781           /* If this used to be a conditional jump insn but whose branch
1782              direction is now know, we must do something special.  */
1783           if (condjump_p (insn) && ! simplejump_p (insn) && map->last_pc_value)
1784             {
1785 #ifdef HAVE_cc0
1786               /* The previous insn set cc0 for us.  So delete it.  */
1787               delete_insn (PREV_INSN (copy));
1788 #endif
1789
1790               /* If this is now a no-op, delete it.  */
1791               if (map->last_pc_value == pc_rtx)
1792                 {
1793                   delete_insn (copy);
1794                   copy = 0;
1795                 }
1796               else
1797                 /* Otherwise, this is unconditional jump so we must put a
1798                    BARRIER after it.  We could do some dead code elimination
1799                    here, but jump.c will do it just as well.  */
1800                 emit_barrier ();
1801             }
1802           break;
1803
1804         case CALL_INSN:
1805           pattern = copy_rtx_and_substitute (PATTERN (insn), map);
1806           copy = emit_call_insn (pattern);
1807
1808           /* Because the USAGE information potentially contains objects other
1809              than hard registers, we need to copy it.  */
1810           CALL_INSN_FUNCTION_USAGE (copy) =
1811              copy_rtx_and_substitute (CALL_INSN_FUNCTION_USAGE (insn), map);
1812
1813 #ifdef HAVE_cc0
1814           if (cc0_insn)
1815             try_constants (cc0_insn, map);
1816           cc0_insn = 0;
1817 #endif
1818           try_constants (copy, map);
1819
1820           /* Be lazy and assume CALL_INSNs clobber all hard registers.  */
1821           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1822             map->const_equiv_map[i] = 0;
1823           break;
1824
1825         case CODE_LABEL:
1826           copy = emit_label (map->label_map[CODE_LABEL_NUMBER (insn)]);
1827           LABEL_NAME (copy) = LABEL_NAME (insn);
1828           map->const_age++;
1829           break;
1830
1831         case BARRIER:
1832           copy = emit_barrier ();
1833           break;
1834
1835         case NOTE:
1836           /* It is important to discard function-end and function-beg notes,
1837              so we have only one of each in the current function.
1838              Also, NOTE_INSN_DELETED notes aren't useful (save_for_inline
1839              deleted these in the copy used for continuing compilation,
1840              not the copy used for inlining).  */
1841           if (NOTE_LINE_NUMBER (insn) != NOTE_INSN_FUNCTION_END
1842               && NOTE_LINE_NUMBER (insn) != NOTE_INSN_FUNCTION_BEG
1843               && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED)
1844             copy = emit_note (NOTE_SOURCE_FILE (insn), NOTE_LINE_NUMBER (insn));
1845           else
1846             copy = 0;
1847           break;
1848
1849         default:
1850           abort ();
1851           break;
1852         }
1853
1854       if (copy)
1855         RTX_INTEGRATED_P (copy) = 1;
1856
1857       map->insn_map[INSN_UID (insn)] = copy;
1858     }
1859
1860   /* Now copy the REG_NOTES.  Increment const_age, so that only constants
1861      from parameters can be substituted in.  These are the only ones that
1862      are valid across the entire function.  */
1863   map->const_age++;
1864   for (insn = insns; insn; insn = NEXT_INSN (insn))
1865     if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
1866         && map->insn_map[INSN_UID (insn)]
1867         && REG_NOTES (insn))
1868       {
1869         rtx tem = copy_rtx_and_substitute (REG_NOTES (insn), map);
1870         /* We must also do subst_constants, in case one of our parameters
1871            has const type and constant value.  */
1872         subst_constants (&tem, NULL_RTX, map);
1873         apply_change_group ();
1874         REG_NOTES (map->insn_map[INSN_UID (insn)]) = tem;
1875       }
1876
1877   if (local_return_label)
1878     emit_label (local_return_label);
1879
1880   /* Restore the stack pointer if we saved it above.  */
1881   if (FUNCTION_FLAGS (header) & FUNCTION_FLAGS_CALLS_ALLOCA)
1882     emit_stack_restore (SAVE_BLOCK, stack_save, NULL_RTX);
1883
1884   /* Make copies of the decls of the symbols in the inline function, so that
1885      the copies of the variables get declared in the current function.  Set
1886      up things so that lookup_static_chain knows that to interpret registers
1887      in SAVE_EXPRs for TYPE_SIZEs as local.  */
1888
1889   inline_function_decl = fndecl;
1890   integrate_parm_decls (DECL_ARGUMENTS (fndecl), map, arg_vector);
1891   integrate_decl_tree ((tree) ORIGINAL_DECL_INITIAL (header), 0, map);
1892   inline_function_decl = 0;
1893
1894   /* End the scope containing the copied formal parameter variables
1895      and copied LABEL_DECLs.  */
1896
1897   expand_end_bindings (getdecls (), 1, 1);
1898   block = poplevel (1, 1, 0);
1899   BLOCK_ABSTRACT_ORIGIN (block) = (DECL_ABSTRACT_ORIGIN (fndecl) == NULL
1900                                    ? fndecl : DECL_ABSTRACT_ORIGIN (fndecl));
1901   poplevel (0, 0, 0);
1902   emit_line_note (input_filename, lineno);
1903
1904   if (structure_value_addr)
1905     {
1906       target = gen_rtx (MEM, TYPE_MODE (type),
1907                         memory_address (TYPE_MODE (type), structure_value_addr));
1908       MEM_IN_STRUCT_P (target) = 1;
1909     }
1910   return target;
1911 }
1912 \f
1913 /* Given a chain of PARM_DECLs, ARGS, copy each decl into a VAR_DECL,
1914    push all of those decls and give each one the corresponding home.  */
1915
1916 static void
1917 integrate_parm_decls (args, map, arg_vector)
1918      tree args;
1919      struct inline_remap *map;
1920      rtvec arg_vector;
1921 {
1922   register tree tail;
1923   register int i;
1924
1925   for (tail = args, i = 0; tail; tail = TREE_CHAIN (tail), i++)
1926     {
1927       register tree decl = build_decl (VAR_DECL, DECL_NAME (tail),
1928                                        TREE_TYPE (tail));
1929       rtx new_decl_rtl
1930         = copy_rtx_and_substitute (RTVEC_ELT (arg_vector, i), map);
1931
1932       DECL_ARG_TYPE (decl) = DECL_ARG_TYPE (tail);
1933       /* We really should be setting DECL_INCOMING_RTL to something reasonable
1934          here, but that's going to require some more work.  */
1935       /* DECL_INCOMING_RTL (decl) = ?; */
1936       /* These args would always appear unused, if not for this.  */
1937       TREE_USED (decl) = 1;
1938       /* Prevent warning for shadowing with these.  */
1939       DECL_ABSTRACT_ORIGIN (decl) = tail;
1940       pushdecl (decl);
1941       /* Fully instantiate the address with the equivalent form so that the
1942          debugging information contains the actual register, instead of the
1943          virtual register.   Do this by not passing an insn to
1944          subst_constants.  */
1945       subst_constants (&new_decl_rtl, NULL_RTX, map);
1946       apply_change_group ();
1947       DECL_RTL (decl) = new_decl_rtl;
1948     }
1949 }
1950
1951 /* Given a BLOCK node LET, push decls and levels so as to construct in the
1952    current function a tree of contexts isomorphic to the one that is given.
1953
1954    LEVEL indicates how far down into the BLOCK tree is the node we are
1955    currently traversing.  It is always zero except for recursive calls.
1956
1957    MAP, if nonzero, is a pointer to an inline_remap map which indicates how
1958    registers used in the DECL_RTL field should be remapped.  If it is zero,
1959    no mapping is necessary.  */
1960
1961 static void
1962 integrate_decl_tree (let, level, map)
1963      tree let;
1964      int level;
1965      struct inline_remap *map;
1966 {
1967   tree t, node;
1968
1969   if (level > 0)
1970     pushlevel (0);
1971   
1972   for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
1973     {
1974       tree d;
1975
1976       push_obstacks_nochange ();
1977       saveable_allocation ();
1978       d = copy_node (t);
1979       pop_obstacks ();
1980
1981       if (DECL_RTL (t) != 0)
1982         {
1983           DECL_RTL (d) = copy_rtx_and_substitute (DECL_RTL (t), map);
1984           /* Fully instantiate the address with the equivalent form so that the
1985              debugging information contains the actual register, instead of the
1986              virtual register.   Do this by not passing an insn to
1987              subst_constants.  */
1988           subst_constants (&DECL_RTL (d), NULL_RTX, map);
1989           apply_change_group ();
1990         }
1991       /* These args would always appear unused, if not for this.  */
1992       TREE_USED (d) = 1;
1993       /* Prevent warning for shadowing with these.  */
1994       DECL_ABSTRACT_ORIGIN (d) = t;
1995
1996       if (DECL_LANG_SPECIFIC (d))
1997         copy_lang_decl (d);
1998
1999       pushdecl (d);
2000     }
2001
2002   for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
2003     integrate_decl_tree (t, level + 1, map);
2004
2005   if (level > 0)
2006     {
2007       node = poplevel (1, 0, 0);
2008       if (node)
2009         {
2010           TREE_USED (node) = TREE_USED (let);
2011           BLOCK_ABSTRACT_ORIGIN (node) = let;
2012         }
2013     }
2014 }
2015 \f
2016 /* Create a new copy of an rtx.
2017    Recursively copies the operands of the rtx,
2018    except for those few rtx codes that are sharable.
2019
2020    We always return an rtx that is similar to that incoming rtx, with the
2021    exception of possibly changing a REG to a SUBREG or vice versa.  No
2022    rtl is ever emitted.
2023
2024    Handle constants that need to be placed in the constant pool by
2025    calling `force_const_mem'.  */
2026
2027 rtx
2028 copy_rtx_and_substitute (orig, map)
2029      register rtx orig;
2030      struct inline_remap *map;
2031 {
2032   register rtx copy, temp;
2033   register int i, j;
2034   register RTX_CODE code;
2035   register enum machine_mode mode;
2036   register char *format_ptr;
2037   int regno;
2038
2039   if (orig == 0)
2040     return 0;
2041
2042   code = GET_CODE (orig);
2043   mode = GET_MODE (orig);
2044
2045   switch (code)
2046     {
2047     case REG:
2048       /* If the stack pointer register shows up, it must be part of
2049          stack-adjustments (*not* because we eliminated the frame pointer!).
2050          Small hard registers are returned as-is.  Pseudo-registers
2051          go through their `reg_map'.  */
2052       regno = REGNO (orig);
2053       if (regno <= LAST_VIRTUAL_REGISTER)
2054         {
2055           /* Some hard registers are also mapped,
2056              but others are not translated.  */
2057           if (map->reg_map[regno] != 0)
2058             return map->reg_map[regno];
2059
2060           /* If this is the virtual frame pointer, make space in current
2061              function's stack frame for the stack frame of the inline function.
2062
2063              Copy the address of this area into a pseudo.  Map
2064              virtual_stack_vars_rtx to this pseudo and set up a constant
2065              equivalence for it to be the address.  This will substitute the
2066              address into insns where it can be substituted and use the new
2067              pseudo where it can't.  */
2068           if (regno == VIRTUAL_STACK_VARS_REGNUM)
2069             {
2070               rtx loc, seq;
2071               int size = DECL_FRAME_SIZE (map->fndecl);
2072               int rounded;
2073
2074               start_sequence ();
2075               loc = assign_stack_temp (BLKmode, size, 1);
2076               loc = XEXP (loc, 0);
2077 #ifdef FRAME_GROWS_DOWNWARD
2078               /* In this case, virtual_stack_vars_rtx points to one byte
2079                  higher than the top of the frame area.  So compute the offset
2080                  to one byte higher than our substitute frame.
2081                  Keep the fake frame pointer aligned like a real one.  */
2082               rounded = CEIL_ROUND (size, BIGGEST_ALIGNMENT / BITS_PER_UNIT);
2083               loc = plus_constant (loc, rounded);
2084 #endif
2085               map->reg_map[regno] = temp
2086                 = force_reg (Pmode, force_operand (loc, NULL_RTX));
2087
2088               if (REGNO (temp) < map->const_equiv_map_size)
2089                 {
2090                   map->const_equiv_map[REGNO (temp)] = loc;
2091                   map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
2092                 }
2093
2094               seq = gen_sequence ();
2095               end_sequence ();
2096               emit_insn_after (seq, map->insns_at_start);
2097               return temp;
2098             }
2099           else if (regno == VIRTUAL_INCOMING_ARGS_REGNUM)
2100             {
2101               /* Do the same for a block to contain any arguments referenced
2102                  in memory. */
2103               rtx loc, seq;
2104               int size = FUNCTION_ARGS_SIZE (DECL_SAVED_INSNS (map->fndecl));
2105
2106               start_sequence ();
2107               loc = assign_stack_temp (BLKmode, size, 1);
2108               loc = XEXP (loc, 0);
2109               /* When arguments grow downward, the virtual incoming 
2110                  args pointer points to the top of the argument block,
2111                  so the remapped location better do the same. */
2112 #ifdef ARGS_GROW_DOWNWARD
2113               loc = plus_constant (loc, size);
2114 #endif
2115               map->reg_map[regno] = temp
2116                 = force_reg (Pmode, force_operand (loc, NULL_RTX));
2117
2118               if (REGNO (temp) < map->const_equiv_map_size)
2119                 {
2120                   map->const_equiv_map[REGNO (temp)] = loc;
2121                   map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
2122                 }
2123
2124               seq = gen_sequence ();
2125               end_sequence ();
2126               emit_insn_after (seq, map->insns_at_start);
2127               return temp;
2128             }
2129           else if (REG_FUNCTION_VALUE_P (orig))
2130             {
2131               /* This is a reference to the function return value.  If
2132                  the function doesn't have a return value, error.  If the
2133                  mode doesn't agree, make a SUBREG.  */
2134               if (map->inline_target == 0)
2135                 /* Must be unrolling loops or replicating code if we
2136                    reach here, so return the register unchanged.  */
2137                 return orig;
2138               else if (mode != GET_MODE (map->inline_target))
2139                 return gen_lowpart (mode, map->inline_target);
2140               else
2141                 return map->inline_target;
2142             }
2143           return orig;
2144         }
2145       if (map->reg_map[regno] == NULL)
2146         {
2147           map->reg_map[regno] = gen_reg_rtx (mode);
2148           REG_USERVAR_P (map->reg_map[regno]) = REG_USERVAR_P (orig);
2149           REG_LOOP_TEST_P (map->reg_map[regno]) = REG_LOOP_TEST_P (orig);
2150           RTX_UNCHANGING_P (map->reg_map[regno]) = RTX_UNCHANGING_P (orig);
2151           /* A reg with REG_FUNCTION_VALUE_P true will never reach here.  */
2152         }
2153       return map->reg_map[regno];
2154
2155     case SUBREG:
2156       copy = copy_rtx_and_substitute (SUBREG_REG (orig), map);
2157       /* SUBREG is ordinary, but don't make nested SUBREGs.  */
2158       if (GET_CODE (copy) == SUBREG)
2159         return gen_rtx (SUBREG, GET_MODE (orig), SUBREG_REG (copy),
2160                         SUBREG_WORD (orig) + SUBREG_WORD (copy));
2161       else if (GET_CODE (copy) == CONCAT)
2162         return (subreg_realpart_p (orig) ? XEXP (copy, 0) : XEXP (copy, 1));
2163       else
2164         return gen_rtx (SUBREG, GET_MODE (orig), copy,
2165                         SUBREG_WORD (orig));
2166
2167     case USE:
2168     case CLOBBER:
2169       /* USE and CLOBBER are ordinary, but we convert (use (subreg foo))
2170          to (use foo) if the original insn didn't have a subreg.
2171          Removing the subreg distorts the VAX movstrhi pattern
2172          by changing the mode of an operand.  */
2173       copy = copy_rtx_and_substitute (XEXP (orig, 0), map);
2174       if (GET_CODE (copy) == SUBREG && GET_CODE (XEXP (orig, 0)) != SUBREG)
2175         copy = SUBREG_REG (copy);
2176       return gen_rtx (code, VOIDmode, copy);
2177
2178     case CODE_LABEL:
2179       LABEL_PRESERVE_P (map->label_map[CODE_LABEL_NUMBER (orig)])
2180         = LABEL_PRESERVE_P (orig);
2181       return map->label_map[CODE_LABEL_NUMBER (orig)];
2182
2183     case LABEL_REF:
2184       copy = gen_rtx (LABEL_REF, mode,
2185                       LABEL_REF_NONLOCAL_P (orig) ? XEXP (orig, 0)
2186                       : map->label_map[CODE_LABEL_NUMBER (XEXP (orig, 0))]);
2187       LABEL_OUTSIDE_LOOP_P (copy) = LABEL_OUTSIDE_LOOP_P (orig);
2188
2189       /* The fact that this label was previously nonlocal does not mean
2190          it still is, so we must check if it is within the range of
2191          this function's labels.  */
2192       LABEL_REF_NONLOCAL_P (copy)
2193         = (LABEL_REF_NONLOCAL_P (orig)
2194            && ! (CODE_LABEL_NUMBER (XEXP (copy, 0)) >= get_first_label_num ()
2195                  && CODE_LABEL_NUMBER (XEXP (copy, 0)) < max_label_num ()));
2196
2197       /* If we have made a nonlocal label local, it means that this
2198          inlined call will be refering to our nonlocal goto handler.
2199          So make sure we create one for this block; we normally would
2200          not since this is not otherwise considered a "call".  */
2201       if (LABEL_REF_NONLOCAL_P (orig) && ! LABEL_REF_NONLOCAL_P (copy))
2202         function_call_count++;
2203
2204       return copy;
2205
2206     case PC:
2207     case CC0:
2208     case CONST_INT:
2209       return orig;
2210
2211     case SYMBOL_REF:
2212       /* Symbols which represent the address of a label stored in the constant
2213          pool must be modified to point to a constant pool entry for the
2214          remapped label.  Otherwise, symbols are returned unchanged.  */
2215       if (CONSTANT_POOL_ADDRESS_P (orig))
2216         {
2217           rtx constant = get_pool_constant (orig);
2218           if (GET_CODE (constant) == LABEL_REF)
2219             return XEXP (force_const_mem (Pmode, 
2220                                           copy_rtx_and_substitute (constant,
2221                                                                    map)),
2222                          0);
2223         }
2224
2225       return orig;
2226
2227     case CONST_DOUBLE:
2228       /* We have to make a new copy of this CONST_DOUBLE because don't want
2229          to use the old value of CONST_DOUBLE_MEM.  Also, this may be a
2230          duplicate of a CONST_DOUBLE we have already seen.  */
2231       if (GET_MODE_CLASS (GET_MODE (orig)) == MODE_FLOAT)
2232         {
2233           REAL_VALUE_TYPE d;
2234
2235           REAL_VALUE_FROM_CONST_DOUBLE (d, orig);
2236           return CONST_DOUBLE_FROM_REAL_VALUE (d, GET_MODE (orig));
2237         }
2238       else
2239         return immed_double_const (CONST_DOUBLE_LOW (orig),
2240                                    CONST_DOUBLE_HIGH (orig), VOIDmode);
2241
2242     case CONST:
2243       /* Make new constant pool entry for a constant
2244          that was in the pool of the inline function.  */
2245       if (RTX_INTEGRATED_P (orig))
2246         {
2247           /* If this was an address of a constant pool entry that itself
2248              had to be placed in the constant pool, it might not be a
2249              valid address.  So the recursive call below might turn it
2250              into a register.  In that case, it isn't a constant any
2251              more, so return it.  This has the potential of changing a
2252              MEM into a REG, but we'll assume that it safe.  */
2253           temp = copy_rtx_and_substitute (XEXP (orig, 0), map);
2254           if (! CONSTANT_P (temp))
2255             return temp;
2256           return validize_mem (force_const_mem (GET_MODE (orig), temp));
2257         }
2258       break;
2259
2260     case ADDRESS:
2261       /* If from constant pool address, make new constant pool entry and
2262          return its address.  */
2263       if (! RTX_INTEGRATED_P (orig))
2264         abort ();
2265
2266       temp = force_const_mem (GET_MODE (orig),
2267                               copy_rtx_and_substitute (XEXP (orig, 0), map));
2268
2269 #if 0
2270       /* Legitimizing the address here is incorrect.
2271
2272          The only ADDRESS rtx's that can reach here are ones created by
2273          save_constants.  Hence the operand of the ADDRESS is always legal
2274          in this position of the instruction, since the original rtx without
2275          the ADDRESS was legal.
2276
2277          The reason we don't legitimize the address here is that on the
2278          Sparc, the caller may have a (high ...) surrounding this ADDRESS.
2279          This code forces the operand of the address to a register, which
2280          fails because we can not take the HIGH part of a register.
2281
2282          Also, change_address may create new registers.  These registers
2283          will not have valid reg_map entries.  This can cause try_constants()
2284          to fail because assumes that all registers in the rtx have valid
2285          reg_map entries, and it may end up replacing one of these new
2286          registers with junk. */
2287
2288       if (! memory_address_p (GET_MODE (temp), XEXP (temp, 0)))
2289         temp = change_address (temp, GET_MODE (temp), XEXP (temp, 0));
2290 #endif
2291
2292       return XEXP (temp, 0);
2293
2294     case ASM_OPERANDS:
2295       /* If a single asm insn contains multiple output operands
2296          then it contains multiple ASM_OPERANDS rtx's that share operand 3.
2297          We must make sure that the copied insn continues to share it.  */
2298       if (map->orig_asm_operands_vector == XVEC (orig, 3))
2299         {
2300           copy = rtx_alloc (ASM_OPERANDS);
2301           copy->volatil = orig->volatil;
2302           XSTR (copy, 0) = XSTR (orig, 0);
2303           XSTR (copy, 1) = XSTR (orig, 1);
2304           XINT (copy, 2) = XINT (orig, 2);
2305           XVEC (copy, 3) = map->copy_asm_operands_vector;
2306           XVEC (copy, 4) = map->copy_asm_constraints_vector;
2307           XSTR (copy, 5) = XSTR (orig, 5);
2308           XINT (copy, 6) = XINT (orig, 6);
2309           return copy;
2310         }
2311       break;
2312
2313     case CALL:
2314       /* This is given special treatment because the first
2315          operand of a CALL is a (MEM ...) which may get
2316          forced into a register for cse.  This is undesirable
2317          if function-address cse isn't wanted or if we won't do cse.  */
2318 #ifndef NO_FUNCTION_CSE
2319       if (! (optimize && ! flag_no_function_cse))
2320 #endif
2321         return gen_rtx (CALL, GET_MODE (orig),
2322                         gen_rtx (MEM, GET_MODE (XEXP (orig, 0)),
2323                                  copy_rtx_and_substitute (XEXP (XEXP (orig, 0), 0), map)),
2324                         copy_rtx_and_substitute (XEXP (orig, 1), map));
2325       break;
2326
2327 #if 0
2328       /* Must be ifdefed out for loop unrolling to work.  */
2329     case RETURN:
2330       abort ();
2331 #endif
2332
2333     case SET:
2334       /* If this is setting fp or ap, it means that we have a nonlocal goto.
2335          Don't alter that.
2336          If the nonlocal goto is into the current function,
2337          this will result in unnecessarily bad code, but should work.  */
2338       if (SET_DEST (orig) == virtual_stack_vars_rtx
2339           || SET_DEST (orig) == virtual_incoming_args_rtx)
2340         return gen_rtx (SET, VOIDmode, SET_DEST (orig),
2341                         copy_rtx_and_substitute (SET_SRC (orig), map));
2342       break;
2343
2344     case MEM:
2345       copy = rtx_alloc (MEM);
2346       PUT_MODE (copy, mode);
2347       XEXP (copy, 0) = copy_rtx_and_substitute (XEXP (orig, 0), map);
2348       MEM_IN_STRUCT_P (copy) = MEM_IN_STRUCT_P (orig);
2349       MEM_VOLATILE_P (copy) = MEM_VOLATILE_P (orig);
2350
2351       /* If doing function inlining, this MEM might not be const in the
2352          function that it is being inlined into, and thus may not be
2353          unchanging after function inlining.  Constant pool references are
2354          handled elsewhere, so this doesn't lose RTX_UNCHANGING_P bits
2355          for them.  */
2356       if (! map->integrating)
2357         RTX_UNCHANGING_P (copy) = RTX_UNCHANGING_P (orig);
2358
2359       return copy;
2360     }
2361
2362   copy = rtx_alloc (code);
2363   PUT_MODE (copy, mode);
2364   copy->in_struct = orig->in_struct;
2365   copy->volatil = orig->volatil;
2366   copy->unchanging = orig->unchanging;
2367
2368   format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
2369
2370   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
2371     {
2372       switch (*format_ptr++)
2373         {
2374         case '0':
2375           break;
2376
2377         case 'e':
2378           XEXP (copy, i) = copy_rtx_and_substitute (XEXP (orig, i), map);
2379           break;
2380
2381         case 'u':
2382           /* Change any references to old-insns to point to the
2383              corresponding copied insns.  */
2384           XEXP (copy, i) = map->insn_map[INSN_UID (XEXP (orig, i))];
2385           break;
2386
2387         case 'E':
2388           XVEC (copy, i) = XVEC (orig, i);
2389           if (XVEC (orig, i) != NULL && XVECLEN (orig, i) != 0)
2390             {
2391               XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
2392               for (j = 0; j < XVECLEN (copy, i); j++)
2393                 XVECEXP (copy, i, j)
2394                   = copy_rtx_and_substitute (XVECEXP (orig, i, j), map);
2395             }
2396           break;
2397
2398         case 'w':
2399           XWINT (copy, i) = XWINT (orig, i);
2400           break;
2401
2402         case 'i':
2403           XINT (copy, i) = XINT (orig, i);
2404           break;
2405
2406         case 's':
2407           XSTR (copy, i) = XSTR (orig, i);
2408           break;
2409
2410         default:
2411           abort ();
2412         }
2413     }
2414
2415   if (code == ASM_OPERANDS && map->orig_asm_operands_vector == 0)
2416     {
2417       map->orig_asm_operands_vector = XVEC (orig, 3);
2418       map->copy_asm_operands_vector = XVEC (copy, 3);
2419       map->copy_asm_constraints_vector = XVEC (copy, 4);
2420     }
2421
2422   return copy;
2423 }
2424 \f
2425 /* Substitute known constant values into INSN, if that is valid.  */
2426
2427 void
2428 try_constants (insn, map)
2429      rtx insn;
2430      struct inline_remap *map;
2431 {
2432   int i;
2433
2434   map->num_sets = 0;
2435   subst_constants (&PATTERN (insn), insn, map);
2436
2437   /* Apply the changes if they are valid; otherwise discard them.  */
2438   apply_change_group ();
2439
2440   /* Show we don't know the value of anything stored or clobbered.  */
2441   note_stores (PATTERN (insn), mark_stores);
2442   map->last_pc_value = 0;
2443 #ifdef HAVE_cc0
2444   map->last_cc0_value = 0;
2445 #endif
2446
2447   /* Set up any constant equivalences made in this insn.  */
2448   for (i = 0; i < map->num_sets; i++)
2449     {
2450       if (GET_CODE (map->equiv_sets[i].dest) == REG)
2451         {
2452           int regno = REGNO (map->equiv_sets[i].dest);
2453
2454           if (regno < map->const_equiv_map_size
2455               && (map->const_equiv_map[regno] == 0
2456                   /* Following clause is a hack to make case work where GNU C++
2457                      reassigns a variable to make cse work right.  */
2458                   || ! rtx_equal_p (map->const_equiv_map[regno],
2459                                     map->equiv_sets[i].equiv)))
2460             {
2461               map->const_equiv_map[regno] = map->equiv_sets[i].equiv;
2462               map->const_age_map[regno] = map->const_age;
2463             }
2464         }
2465       else if (map->equiv_sets[i].dest == pc_rtx)
2466         map->last_pc_value = map->equiv_sets[i].equiv;
2467 #ifdef HAVE_cc0
2468       else if (map->equiv_sets[i].dest == cc0_rtx)
2469         map->last_cc0_value = map->equiv_sets[i].equiv;
2470 #endif
2471     }
2472 }
2473 \f
2474 /* Substitute known constants for pseudo regs in the contents of LOC,
2475    which are part of INSN.
2476    If INSN is zero, the substitution should always be done (this is used to
2477    update DECL_RTL).
2478    These changes are taken out by try_constants if the result is not valid.
2479
2480    Note that we are more concerned with determining when the result of a SET
2481    is a constant, for further propagation, than actually inserting constants
2482    into insns; cse will do the latter task better.
2483
2484    This function is also used to adjust address of items previously addressed
2485    via the virtual stack variable or virtual incoming arguments registers.  */
2486
2487 static void
2488 subst_constants (loc, insn, map)
2489      rtx *loc;
2490      rtx insn;
2491      struct inline_remap *map;
2492 {
2493   rtx x = *loc;
2494   register int i;
2495   register enum rtx_code code;
2496   register char *format_ptr;
2497   int num_changes = num_validated_changes ();
2498   rtx new = 0;
2499   enum machine_mode op0_mode;
2500
2501   code = GET_CODE (x);
2502
2503   switch (code)
2504     {
2505     case PC:
2506     case CONST_INT:
2507     case CONST_DOUBLE:
2508     case SYMBOL_REF:
2509     case CONST:
2510     case LABEL_REF:
2511     case ADDRESS:
2512       return;
2513
2514 #ifdef HAVE_cc0
2515     case CC0:
2516       validate_change (insn, loc, map->last_cc0_value, 1);
2517       return;
2518 #endif
2519
2520     case USE:
2521     case CLOBBER:
2522       /* The only thing we can do with a USE or CLOBBER is possibly do
2523          some substitutions in a MEM within it.  */
2524       if (GET_CODE (XEXP (x, 0)) == MEM)
2525         subst_constants (&XEXP (XEXP (x, 0), 0), insn, map);
2526       return;
2527
2528     case REG:
2529       /* Substitute for parms and known constants.  Don't replace
2530          hard regs used as user variables with constants.  */
2531       {
2532         int regno = REGNO (x);
2533
2534         if (! (regno < FIRST_PSEUDO_REGISTER && REG_USERVAR_P (x))
2535             && regno < map->const_equiv_map_size
2536             && map->const_equiv_map[regno] != 0
2537             && map->const_age_map[regno] >= map->const_age)
2538           validate_change (insn, loc, map->const_equiv_map[regno], 1);
2539         return;
2540       }
2541
2542     case SUBREG:
2543       /* SUBREG applied to something other than a reg
2544          should be treated as ordinary, since that must
2545          be a special hack and we don't know how to treat it specially.
2546          Consider for example mulsidi3 in m68k.md.
2547          Ordinary SUBREG of a REG needs this special treatment.  */
2548       if (GET_CODE (SUBREG_REG (x)) == REG)
2549         {
2550           rtx inner = SUBREG_REG (x);
2551           rtx new = 0;
2552
2553           /* We can't call subst_constants on &SUBREG_REG (x) because any
2554              constant or SUBREG wouldn't be valid inside our SUBEG.  Instead,
2555              see what is inside, try to form the new SUBREG and see if that is
2556              valid.  We handle two cases: extracting a full word in an 
2557              integral mode and extracting the low part.  */
2558           subst_constants (&inner, NULL_RTX, map);
2559
2560           if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT
2561               && GET_MODE_SIZE (GET_MODE (x)) == UNITS_PER_WORD
2562               && GET_MODE (SUBREG_REG (x)) != VOIDmode)
2563             new = operand_subword (inner, SUBREG_WORD (x), 0,
2564                                    GET_MODE (SUBREG_REG (x)));
2565
2566           if (new == 0 && subreg_lowpart_p (x))
2567             new = gen_lowpart_common (GET_MODE (x), inner);
2568
2569           if (new)
2570             validate_change (insn, loc, new, 1);
2571
2572           return;
2573         }
2574       break;
2575
2576     case MEM:
2577       subst_constants (&XEXP (x, 0), insn, map);
2578
2579       /* If a memory address got spoiled, change it back.  */
2580       if (insn != 0 && num_validated_changes () != num_changes
2581           && !memory_address_p (GET_MODE (x), XEXP (x, 0)))
2582         cancel_changes (num_changes);
2583       return;
2584
2585     case SET:
2586       {
2587         /* Substitute constants in our source, and in any arguments to a
2588            complex (e..g, ZERO_EXTRACT) destination, but not in the destination
2589            itself.  */
2590         rtx *dest_loc = &SET_DEST (x);
2591         rtx dest = *dest_loc;
2592         rtx src, tem;
2593
2594         subst_constants (&SET_SRC (x), insn, map);
2595         src = SET_SRC (x);
2596
2597         while (GET_CODE (*dest_loc) == ZERO_EXTRACT
2598                /* By convention, we always use ZERO_EXTRACT in the dest.  */
2599 /*             || GET_CODE (*dest_loc) == SIGN_EXTRACT */
2600                || GET_CODE (*dest_loc) == SUBREG
2601                || GET_CODE (*dest_loc) == STRICT_LOW_PART)
2602           {
2603             if (GET_CODE (*dest_loc) == ZERO_EXTRACT)
2604               {
2605                 subst_constants (&XEXP (*dest_loc, 1), insn, map);
2606                 subst_constants (&XEXP (*dest_loc, 2), insn, map);
2607               }
2608             dest_loc = &XEXP (*dest_loc, 0);
2609           }
2610
2611         /* Do substitute in the address of a destination in memory.  */
2612         if (GET_CODE (*dest_loc) == MEM)
2613           subst_constants (&XEXP (*dest_loc, 0), insn, map);
2614
2615         /* Check for the case of DEST a SUBREG, both it and the underlying
2616            register are less than one word, and the SUBREG has the wider mode.
2617            In the case, we are really setting the underlying register to the
2618            source converted to the mode of DEST.  So indicate that.  */
2619         if (GET_CODE (dest) == SUBREG
2620             && GET_MODE_SIZE (GET_MODE (dest)) <= UNITS_PER_WORD
2621             && GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest))) <= UNITS_PER_WORD
2622             && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
2623                       <= GET_MODE_SIZE (GET_MODE (dest)))
2624             && (tem = gen_lowpart_if_possible (GET_MODE (SUBREG_REG (dest)),
2625                                                src)))
2626           src = tem, dest = SUBREG_REG (dest);
2627
2628         /* If storing a recognizable value save it for later recording.  */
2629         if ((map->num_sets < MAX_RECOG_OPERANDS)
2630             && (CONSTANT_P (src)
2631                 || (GET_CODE (src) == REG
2632                     && (REGNO (src) == VIRTUAL_INCOMING_ARGS_REGNUM
2633                         || REGNO (src) == VIRTUAL_STACK_VARS_REGNUM))
2634                 || (GET_CODE (src) == PLUS
2635                     && GET_CODE (XEXP (src, 0)) == REG
2636                     && (REGNO (XEXP (src, 0)) == VIRTUAL_INCOMING_ARGS_REGNUM
2637                         || REGNO (XEXP (src, 0)) == VIRTUAL_STACK_VARS_REGNUM)
2638                     && CONSTANT_P (XEXP (src, 1)))
2639                 || GET_CODE (src) == COMPARE
2640 #ifdef HAVE_cc0
2641                 || dest == cc0_rtx
2642 #endif
2643                 || (dest == pc_rtx
2644                     && (src == pc_rtx || GET_CODE (src) == RETURN
2645                         || GET_CODE (src) == LABEL_REF))))
2646           {
2647             /* Normally, this copy won't do anything.  But, if SRC is a COMPARE
2648                it will cause us to save the COMPARE with any constants
2649                substituted, which is what we want for later.  */
2650             map->equiv_sets[map->num_sets].equiv = copy_rtx (src);
2651             map->equiv_sets[map->num_sets++].dest = dest;
2652           }
2653
2654         return;
2655       }
2656     }
2657
2658   format_ptr = GET_RTX_FORMAT (code);
2659   
2660   /* If the first operand is an expression, save its mode for later.  */
2661   if (*format_ptr == 'e')
2662     op0_mode = GET_MODE (XEXP (x, 0));
2663
2664   for (i = 0; i < GET_RTX_LENGTH (code); i++)
2665     {
2666       switch (*format_ptr++)
2667         {
2668         case '0':
2669           break;
2670
2671         case 'e':
2672           if (XEXP (x, i))
2673             subst_constants (&XEXP (x, i), insn, map);
2674           break;
2675
2676         case 'u':
2677         case 'i':
2678         case 's':
2679         case 'w':
2680           break;
2681
2682         case 'E':
2683           if (XVEC (x, i) != NULL && XVECLEN (x, i) != 0)
2684             {
2685               int j;
2686               for (j = 0; j < XVECLEN (x, i); j++)
2687                 subst_constants (&XVECEXP (x, i, j), insn, map);
2688             }
2689           break;
2690
2691         default:
2692           abort ();
2693         }
2694     }
2695
2696   /* If this is a commutative operation, move a constant to the second
2697      operand unless the second operand is already a CONST_INT.  */
2698   if ((GET_RTX_CLASS (code) == 'c' || code == NE || code == EQ)
2699       && CONSTANT_P (XEXP (x, 0)) && GET_CODE (XEXP (x, 1)) != CONST_INT)
2700     {
2701       rtx tem = XEXP (x, 0);
2702       validate_change (insn, &XEXP (x, 0), XEXP (x, 1), 1);
2703       validate_change (insn, &XEXP (x, 1), tem, 1);
2704     }
2705
2706   /* Simplify the expression in case we put in some constants.  */
2707   switch (GET_RTX_CLASS (code))
2708     {
2709     case '1':
2710       new = simplify_unary_operation (code, GET_MODE (x),
2711                                       XEXP (x, 0), op0_mode);
2712       break;
2713
2714     case '<':
2715       {
2716         enum machine_mode op_mode = GET_MODE (XEXP (x, 0));
2717         if (op_mode == VOIDmode)
2718           op_mode = GET_MODE (XEXP (x, 1));
2719         new = simplify_relational_operation (code, op_mode,
2720                                              XEXP (x, 0), XEXP (x, 1));
2721 #ifdef FLOAT_STORE_FLAG_VALUE
2722         if (new != 0 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2723           new = ((new == const0_rtx) ? CONST0_RTX (GET_MODE (x))
2724                  : CONST_DOUBLE_FROM_REAL_VALUE (FLOAT_STORE_FLAG_VALUE,
2725                                                  GET_MODE (x)));
2726 #endif
2727         break;
2728       }
2729
2730     case '2':
2731     case 'c':
2732       new = simplify_binary_operation (code, GET_MODE (x),
2733                                        XEXP (x, 0), XEXP (x, 1));
2734       break;
2735
2736     case 'b':
2737     case '3':
2738       new = simplify_ternary_operation (code, GET_MODE (x), op0_mode,
2739                                         XEXP (x, 0), XEXP (x, 1), XEXP (x, 2));
2740       break;
2741     }
2742
2743   if (new)
2744     validate_change (insn, loc, new, 1);
2745 }
2746
2747 /* Show that register modified no longer contain known constants.  We are
2748    called from note_stores with parts of the new insn.  */
2749
2750 void
2751 mark_stores (dest, x)
2752      rtx dest;
2753      rtx x;
2754 {
2755   int regno = -1;
2756   enum machine_mode mode;
2757
2758   /* DEST is always the innermost thing set, except in the case of
2759      SUBREGs of hard registers.  */
2760
2761   if (GET_CODE (dest) == REG)
2762     regno = REGNO (dest), mode = GET_MODE (dest);
2763   else if (GET_CODE (dest) == SUBREG && GET_CODE (SUBREG_REG (dest)) == REG)
2764     {
2765       regno = REGNO (SUBREG_REG (dest)) + SUBREG_WORD (dest);
2766       mode = GET_MODE (SUBREG_REG (dest));
2767     }
2768
2769   if (regno >= 0)
2770     {
2771       int last_reg = (regno >= FIRST_PSEUDO_REGISTER ? regno
2772                       : regno + HARD_REGNO_NREGS (regno, mode) - 1);
2773       int i;
2774
2775       for (i = regno; i <= last_reg; i++)
2776         if (i < global_const_equiv_map_size)
2777           global_const_equiv_map[i] = 0;
2778     }
2779 }
2780 \f
2781 /* If any CONST expressions with RTX_INTEGRATED_P are present in the rtx
2782    pointed to by PX, they represent constants in the constant pool.
2783    Replace these with a new memory reference obtained from force_const_mem.
2784    Similarly, ADDRESS expressions with RTX_INTEGRATED_P represent the
2785    address of a constant pool entry.  Replace them with the address of
2786    a new constant pool entry obtained from force_const_mem.  */
2787
2788 static void
2789 restore_constants (px)
2790      rtx *px;
2791 {
2792   rtx x = *px;
2793   int i, j;
2794   char *fmt;
2795
2796   if (x == 0)
2797     return;
2798
2799   if (GET_CODE (x) == CONST_DOUBLE)
2800     {
2801       /* We have to make a new CONST_DOUBLE to ensure that we account for
2802          it correctly.  Using the old CONST_DOUBLE_MEM data is wrong.  */
2803       if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2804         {
2805           REAL_VALUE_TYPE d;
2806
2807           REAL_VALUE_FROM_CONST_DOUBLE (d, x);
2808           *px = CONST_DOUBLE_FROM_REAL_VALUE (d, GET_MODE (x));
2809         }
2810       else
2811         *px = immed_double_const (CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x),
2812                                   VOIDmode);
2813     }
2814
2815   else if (RTX_INTEGRATED_P (x) && GET_CODE (x) == CONST)
2816     {
2817       restore_constants (&XEXP (x, 0));
2818       *px = validize_mem (force_const_mem (GET_MODE (x), XEXP (x, 0)));
2819     }
2820   else if (RTX_INTEGRATED_P (x) && GET_CODE (x) == SUBREG)
2821     {
2822       /* This must be (subreg/i:M1 (const/i:M2 ...) 0).  */
2823       rtx new = XEXP (SUBREG_REG (x), 0);
2824
2825       restore_constants (&new);
2826       new = force_const_mem (GET_MODE (SUBREG_REG (x)), new);
2827       PUT_MODE (new, GET_MODE (x));
2828       *px = validize_mem (new);
2829     }
2830   else if (RTX_INTEGRATED_P (x) && GET_CODE (x) == ADDRESS)
2831     {
2832       restore_constants (&XEXP (x, 0));
2833       *px = XEXP (force_const_mem (GET_MODE (x), XEXP (x, 0)), 0);
2834     }
2835   else
2836     {
2837       fmt = GET_RTX_FORMAT (GET_CODE (x));
2838       for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
2839         {
2840           switch (*fmt++)
2841             {
2842             case 'E':
2843               for (j = 0; j < XVECLEN (x, i); j++)
2844                 restore_constants (&XVECEXP (x, i, j));
2845               break;
2846
2847             case 'e':
2848               restore_constants (&XEXP (x, i));
2849               break;
2850             }
2851         }
2852     }
2853 }
2854 \f
2855 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
2856    given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
2857    that it points to the node itself, thus indicating that the node is its
2858    own (abstract) origin.  Additionally, if the BLOCK_ABSTRACT_ORIGIN for
2859    the given node is NULL, recursively descend the decl/block tree which
2860    it is the root of, and for each other ..._DECL or BLOCK node contained
2861    therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
2862    still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
2863    values to point to themselves.  */
2864
2865 static void
2866 set_block_origin_self (stmt)
2867      register tree stmt;
2868 {
2869   if (BLOCK_ABSTRACT_ORIGIN (stmt) == NULL_TREE)
2870     {
2871       BLOCK_ABSTRACT_ORIGIN (stmt) = stmt;
2872
2873       {
2874         register tree local_decl;
2875
2876         for (local_decl = BLOCK_VARS (stmt);
2877              local_decl != NULL_TREE;
2878              local_decl = TREE_CHAIN (local_decl))
2879           set_decl_origin_self (local_decl);    /* Potential recursion.  */
2880       }
2881
2882       {
2883         register tree subblock;
2884
2885         for (subblock = BLOCK_SUBBLOCKS (stmt);
2886              subblock != NULL_TREE;
2887              subblock = BLOCK_CHAIN (subblock))
2888           set_block_origin_self (subblock);     /* Recurse.  */
2889       }
2890     }
2891 }
2892
2893 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
2894    the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
2895    node to so that it points to the node itself, thus indicating that the
2896    node represents its own (abstract) origin.  Additionally, if the
2897    DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
2898    the decl/block tree of which the given node is the root of, and for
2899    each other ..._DECL or BLOCK node contained therein whose
2900    DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
2901    set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
2902    point to themselves.  */
2903
2904 static void
2905 set_decl_origin_self (decl)
2906      register tree decl;
2907 {
2908   if (DECL_ABSTRACT_ORIGIN (decl) == NULL_TREE)
2909     {
2910       DECL_ABSTRACT_ORIGIN (decl) = decl;
2911       if (TREE_CODE (decl) == FUNCTION_DECL)
2912         {
2913           register tree arg;
2914
2915           for (arg = DECL_ARGUMENTS (decl); arg; arg = TREE_CHAIN (arg))
2916             DECL_ABSTRACT_ORIGIN (arg) = arg;
2917           if (DECL_INITIAL (decl) != NULL_TREE)
2918             set_block_origin_self (DECL_INITIAL (decl));
2919         }
2920     }
2921 }
2922 \f
2923 /* Given a pointer to some BLOCK node, and a boolean value to set the
2924    "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
2925    the given block, and for all local decls and all local sub-blocks
2926    (recursively) which are contained therein.  */
2927
2928 static void
2929 set_block_abstract_flags (stmt, setting)
2930      register tree stmt;
2931      register int setting;
2932 {
2933   BLOCK_ABSTRACT (stmt) = setting;
2934
2935   {
2936     register tree local_decl;
2937
2938     for (local_decl = BLOCK_VARS (stmt);
2939          local_decl != NULL_TREE;
2940          local_decl = TREE_CHAIN (local_decl))
2941       set_decl_abstract_flags (local_decl, setting);
2942   }
2943
2944   {
2945     register tree subblock;
2946
2947     for (subblock = BLOCK_SUBBLOCKS (stmt);
2948          subblock != NULL_TREE;
2949          subblock = BLOCK_CHAIN (subblock))
2950       set_block_abstract_flags (subblock, setting);
2951   }
2952 }
2953
2954 /* Given a pointer to some ..._DECL node, and a boolean value to set the
2955    "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
2956    given decl, and (in the case where the decl is a FUNCTION_DECL) also
2957    set the abstract flags for all of the parameters, local vars, local
2958    blocks and sub-blocks (recursively) to the same setting.  */
2959
2960 void
2961 set_decl_abstract_flags (decl, setting)
2962      register tree decl;
2963      register int setting;
2964 {
2965   DECL_ABSTRACT (decl) = setting;
2966   if (TREE_CODE (decl) == FUNCTION_DECL)
2967     {
2968       register tree arg;
2969
2970       for (arg = DECL_ARGUMENTS (decl); arg; arg = TREE_CHAIN (arg))
2971         DECL_ABSTRACT (arg) = setting;
2972       if (DECL_INITIAL (decl) != NULL_TREE)
2973         set_block_abstract_flags (DECL_INITIAL (decl), setting);
2974     }
2975 }
2976 \f
2977 /* Output the assembly language code for the function FNDECL
2978    from its DECL_SAVED_INSNS.  Used for inline functions that are output
2979    at end of compilation instead of where they came in the source.  */
2980
2981 void
2982 output_inline_function (fndecl)
2983      tree fndecl;
2984 {
2985   rtx head;
2986   rtx last;
2987
2988   if (output_bytecode)
2989     {
2990       warning ("`inline' ignored for bytecode output");
2991       return;
2992     }
2993
2994   head = DECL_SAVED_INSNS (fndecl);
2995   current_function_decl = fndecl;
2996
2997   /* This call is only used to initialize global variables.  */
2998   init_function_start (fndecl, "lossage", 1);
2999
3000   /* Redo parameter determinations in case the FUNCTION_...
3001      macros took machine-specific actions that need to be redone.  */
3002   assign_parms (fndecl, 1);
3003
3004   /* Set stack frame size.  */
3005   assign_stack_local (BLKmode, DECL_FRAME_SIZE (fndecl), 0);
3006
3007   restore_reg_data (FIRST_PARM_INSN (head));
3008
3009   stack_slot_list = STACK_SLOT_LIST (head);
3010
3011   if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_CALLS_ALLOCA)
3012     current_function_calls_alloca = 1;
3013
3014   if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_CALLS_SETJMP)
3015     current_function_calls_setjmp = 1;
3016
3017   if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_CALLS_LONGJMP)
3018     current_function_calls_longjmp = 1;
3019
3020   if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_RETURNS_STRUCT)
3021     current_function_returns_struct = 1;
3022
3023   if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_RETURNS_PCC_STRUCT)
3024     current_function_returns_pcc_struct = 1;
3025
3026   if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_NEEDS_CONTEXT)
3027     current_function_needs_context = 1;
3028
3029   if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_HAS_NONLOCAL_LABEL)
3030     current_function_has_nonlocal_label = 1;
3031
3032   if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_RETURNS_POINTER)
3033     current_function_returns_pointer = 1;
3034
3035   if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_USES_CONST_POOL)
3036     current_function_uses_const_pool = 1;
3037
3038   if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_USES_PIC_OFFSET_TABLE)
3039     current_function_uses_pic_offset_table = 1;
3040
3041   current_function_outgoing_args_size = OUTGOING_ARGS_SIZE (head);
3042   current_function_pops_args = POPS_ARGS (head);
3043
3044   /* There is no need to output a return label again.  */
3045   return_label = 0;
3046
3047   expand_function_end (DECL_SOURCE_FILE (fndecl), DECL_SOURCE_LINE (fndecl), 0);
3048
3049   /* Find last insn and rebuild the constant pool.  */
3050   for (last = FIRST_PARM_INSN (head);
3051        NEXT_INSN (last); last = NEXT_INSN (last))
3052     {
3053       if (GET_RTX_CLASS (GET_CODE (last)) == 'i')
3054         {
3055           restore_constants (&PATTERN (last));
3056           restore_constants (&REG_NOTES (last));
3057         }
3058     }
3059
3060   set_new_first_and_last_insn (FIRST_PARM_INSN (head), last);
3061   set_new_first_and_last_label_num (FIRST_LABELNO (head), LAST_LABELNO (head));
3062
3063   /* We must have already output DWARF debugging information for the
3064      original (abstract) inline function declaration/definition, so
3065      we want to make sure that the debugging information we generate
3066      for this special instance of the inline function refers back to
3067      the information we already generated.  To make sure that happens,
3068      we simply have to set the DECL_ABSTRACT_ORIGIN for the function
3069      node (and for all of the local ..._DECL nodes which are its children)
3070      so that they all point to themselves.  */
3071
3072   set_decl_origin_self (fndecl);
3073
3074   /* We're not deferring this any longer.  */
3075   DECL_DEFER_OUTPUT (fndecl) = 0;
3076
3077   /* Compile this function all the way down to assembly code.  */
3078   rest_of_compilation (fndecl);
3079
3080   current_function_decl = 0;
3081 }