OSDN Git Service

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