OSDN Git Service

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