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