OSDN Git Service

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