OSDN Git Service

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