OSDN Git Service

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