OSDN Git Service

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