OSDN Git Service

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