OSDN Git Service

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