OSDN Git Service

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