xref: /freebsd-12.1/contrib/gcc/function.c (revision 04fa5c9c)
1 /* Expands front end tree to back end RTL for GNU C-Compiler
2    Copyright (C) 1987, 88, 89, 91-98, 1999 Free Software Foundation, Inc.
3 
4 This file is part of GNU CC.
5 
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10 
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20 
21 /* $FreeBSD$ */
22 
23 
24 /* This file handles the generation of rtl code from tree structure
25    at the level of the function as a whole.
26    It creates the rtl expressions for parameters and auto variables
27    and has full responsibility for allocating stack slots.
28 
29    `expand_function_start' is called at the beginning of a function,
30    before the function body is parsed, and `expand_function_end' is
31    called after parsing the body.
32 
33    Call `assign_stack_local' to allocate a stack slot for a local variable.
34    This is usually done during the RTL generation for the function body,
35    but it can also be done in the reload pass when a pseudo-register does
36    not get a hard register.
37 
38    Call `put_var_into_stack' when you learn, belatedly, that a variable
39    previously given a pseudo-register must in fact go in the stack.
40    This function changes the DECL_RTL to be a stack slot instead of a reg
41    then scans all the RTL instructions so far generated to correct them.  */
42 
43 #include "config.h"
44 #include "system.h"
45 #include "rtl.h"
46 #include "tree.h"
47 #include "flags.h"
48 #include "except.h"
49 #include "function.h"
50 #include "insn-flags.h"
51 #include "expr.h"
52 #include "insn-codes.h"
53 #include "regs.h"
54 #include "hard-reg-set.h"
55 #include "insn-config.h"
56 #include "recog.h"
57 #include "output.h"
58 #include "basic-block.h"
59 #include "obstack.h"
60 #include "toplev.h"
61 #include "hash.h"
62 
63 #ifndef TRAMPOLINE_ALIGNMENT
64 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
65 #endif
66 
67 #ifndef LOCAL_ALIGNMENT
68 #define LOCAL_ALIGNMENT(TYPE, ALIGNMENT) ALIGNMENT
69 #endif
70 
71 /* Some systems use __main in a way incompatible with its use in gcc, in these
72    cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
73    give the same symbol without quotes for an alternative entry point.  You
74    must define both, or neither.  */
75 #ifndef NAME__MAIN
76 #define NAME__MAIN "__main"
77 #define SYMBOL__MAIN __main
78 #endif
79 
80 /* Round a value to the lowest integer less than it that is a multiple of
81    the required alignment.  Avoid using division in case the value is
82    negative.  Assume the alignment is a power of two.  */
83 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
84 
85 /* Similar, but round to the next highest integer that meets the
86    alignment.  */
87 #define CEIL_ROUND(VALUE,ALIGN)	(((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
88 
89 /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp
90    during rtl generation.  If they are different register numbers, this is
91    always true.  It may also be true if
92    FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl
93    generation.  See fix_lexical_addr for details.  */
94 
95 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
96 #define NEED_SEPARATE_AP
97 #endif
98 
99 /* Number of bytes of args popped by function being compiled on its return.
100    Zero if no bytes are to be popped.
101    May affect compilation of return insn or of function epilogue.  */
102 
103 int current_function_pops_args;
104 
105 /* Nonzero if function being compiled needs to be given an address
106    where the value should be stored.  */
107 
108 int current_function_returns_struct;
109 
110 /* Nonzero if function being compiled needs to
111    return the address of where it has put a structure value.  */
112 
113 int current_function_returns_pcc_struct;
114 
115 /* Nonzero if function being compiled needs to be passed a static chain.  */
116 
117 int current_function_needs_context;
118 
119 /* Nonzero if function being compiled can call setjmp.  */
120 
121 int current_function_calls_setjmp;
122 
123 /* Nonzero if function being compiled can call longjmp.  */
124 
125 int current_function_calls_longjmp;
126 
127 /* Nonzero if function being compiled receives nonlocal gotos
128    from nested functions.  */
129 
130 int current_function_has_nonlocal_label;
131 
132 /* Nonzero if function being compiled has nonlocal gotos to parent
133    function.  */
134 
135 int current_function_has_nonlocal_goto;
136 
137 /* Nonzero if function being compiled contains nested functions.  */
138 
139 int current_function_contains_functions;
140 
141 /* Nonzero if function being compiled doesn't contain any calls
142    (ignoring the prologue and epilogue).  This is set prior to
143    local register allocation and is valid for the remaining
144    compiler passes. */
145 
146 int current_function_is_leaf;
147 
148 /* Nonzero if function being compiled doesn't modify the stack pointer
149    (ignoring the prologue and epilogue).  This is only valid after
150    life_analysis has run. */
151 
152 int current_function_sp_is_unchanging;
153 
154 /* Nonzero if the function being compiled is a leaf function which only
155    uses leaf registers.  This is valid after reload (specifically after
156    sched2) and is useful only if the port defines LEAF_REGISTERS.  */
157 
158 int current_function_uses_only_leaf_regs;
159 
160 /* Nonzero if the function being compiled issues a computed jump.  */
161 
162 int current_function_has_computed_jump;
163 
164 /* Nonzero if the current function is a thunk (a lightweight function that
165    just adjusts one of its arguments and forwards to another function), so
166    we should try to cut corners where we can.  */
167 int current_function_is_thunk;
168 
169 /* Nonzero if function being compiled can call alloca,
170    either as a subroutine or builtin.  */
171 
172 int current_function_calls_alloca;
173 
174 /* Nonzero if the current function returns a pointer type */
175 
176 int current_function_returns_pointer;
177 
178 /* If some insns can be deferred to the delay slots of the epilogue, the
179    delay list for them is recorded here.  */
180 
181 rtx current_function_epilogue_delay_list;
182 
183 /* If function's args have a fixed size, this is that size, in bytes.
184    Otherwise, it is -1.
185    May affect compilation of return insn or of function epilogue.  */
186 
187 int current_function_args_size;
188 
189 /* # bytes the prologue should push and pretend that the caller pushed them.
190    The prologue must do this, but only if parms can be passed in registers.  */
191 
192 int current_function_pretend_args_size;
193 
194 /* # of bytes of outgoing arguments.  If ACCUMULATE_OUTGOING_ARGS is
195    defined, the needed space is pushed by the prologue.  */
196 
197 int current_function_outgoing_args_size;
198 
199 /* This is the offset from the arg pointer to the place where the first
200    anonymous arg can be found, if there is one.  */
201 
202 rtx current_function_arg_offset_rtx;
203 
204 /* Nonzero if current function uses varargs.h or equivalent.
205    Zero for functions that use stdarg.h.  */
206 
207 int current_function_varargs;
208 
209 /* Nonzero if current function uses stdarg.h or equivalent.
210    Zero for functions that use varargs.h.  */
211 
212 int current_function_stdarg;
213 
214 /* Quantities of various kinds of registers
215    used for the current function's args.  */
216 
217 CUMULATIVE_ARGS current_function_args_info;
218 
219 /* Name of function now being compiled.  */
220 
221 char *current_function_name;
222 
223 /* If non-zero, an RTL expression for the location at which the current
224    function returns its result.  If the current function returns its
225    result in a register, current_function_return_rtx will always be
226    the hard register containing the result.  */
227 
228 rtx current_function_return_rtx;
229 
230 /* Nonzero if the current function uses the constant pool.  */
231 
232 int current_function_uses_const_pool;
233 
234 /* Nonzero if the current function uses pic_offset_table_rtx.  */
235 int current_function_uses_pic_offset_table;
236 
237 /* The arg pointer hard register, or the pseudo into which it was copied.  */
238 rtx current_function_internal_arg_pointer;
239 
240 /* Language-specific reason why the current function cannot be made inline.  */
241 char *current_function_cannot_inline;
242 
243 /* Nonzero if instrumentation calls for function entry and exit should be
244    generated.  */
245 int current_function_instrument_entry_exit;
246 
247 /* Nonzero if memory access checking be enabled in the current function.  */
248 int current_function_check_memory_usage;
249 
250 /* The FUNCTION_DECL for an inline function currently being expanded.  */
251 tree inline_function_decl;
252 
253 /* Number of function calls seen so far in current function.  */
254 
255 int function_call_count;
256 
257 /* List (chain of TREE_LIST) of LABEL_DECLs for all nonlocal labels
258    (labels to which there can be nonlocal gotos from nested functions)
259    in this function.  */
260 
261 tree nonlocal_labels;
262 
263 /* List (chain of EXPR_LIST) of stack slots that hold the current handlers
264    for nonlocal gotos.  There is one for every nonlocal label in the function;
265    this list matches the one in nonlocal_labels.
266    Zero when function does not have nonlocal labels.  */
267 
268 rtx nonlocal_goto_handler_slots;
269 
270 /* List (chain of EXPR_LIST) of labels heading the current handlers for
271    nonlocal gotos.  */
272 
273 rtx nonlocal_goto_handler_labels;
274 
275 /* RTX for stack slot that holds the stack pointer value to restore
276    for a nonlocal goto.
277    Zero when function does not have nonlocal labels.  */
278 
279 rtx nonlocal_goto_stack_level;
280 
281 /* Label that will go on parm cleanup code, if any.
282    Jumping to this label runs cleanup code for parameters, if
283    such code must be run.  Following this code is the logical return label.  */
284 
285 rtx cleanup_label;
286 
287 /* Label that will go on function epilogue.
288    Jumping to this label serves as a "return" instruction
289    on machines which require execution of the epilogue on all returns.  */
290 
291 rtx return_label;
292 
293 /* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs.
294    So we can mark them all live at the end of the function, if nonopt.  */
295 rtx save_expr_regs;
296 
297 /* List (chain of EXPR_LISTs) of all stack slots in this function.
298    Made for the sake of unshare_all_rtl.  */
299 rtx stack_slot_list;
300 
301 /* Chain of all RTL_EXPRs that have insns in them.  */
302 tree rtl_expr_chain;
303 
304 /* Label to jump back to for tail recursion, or 0 if we have
305    not yet needed one for this function.  */
306 rtx tail_recursion_label;
307 
308 /* Place after which to insert the tail_recursion_label if we need one.  */
309 rtx tail_recursion_reentry;
310 
311 /* Location at which to save the argument pointer if it will need to be
312    referenced.  There are two cases where this is done: if nonlocal gotos
313    exist, or if vars stored at an offset from the argument pointer will be
314    needed by inner routines.  */
315 
316 rtx arg_pointer_save_area;
317 
318 /* Offset to end of allocated area of stack frame.
319    If stack grows down, this is the address of the last stack slot allocated.
320    If stack grows up, this is the address for the next slot.  */
321 HOST_WIDE_INT frame_offset;
322 
323 /* List (chain of TREE_LISTs) of static chains for containing functions.
324    Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
325    in an RTL_EXPR in the TREE_VALUE.  */
326 static tree context_display;
327 
328 /* List (chain of TREE_LISTs) of trampolines for nested functions.
329    The trampoline sets up the static chain and jumps to the function.
330    We supply the trampoline's address when the function's address is requested.
331 
332    Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
333    in an RTL_EXPR in the TREE_VALUE.  */
334 static tree trampoline_list;
335 
336 /* Insn after which register parms and SAVE_EXPRs are born, if nonopt.  */
337 static rtx parm_birth_insn;
338 
339 #if 0
340 /* Nonzero if a stack slot has been generated whose address is not
341    actually valid.  It means that the generated rtl must all be scanned
342    to detect and correct the invalid addresses where they occur.  */
343 static int invalid_stack_slot;
344 #endif
345 
346 /* Last insn of those whose job was to put parms into their nominal homes.  */
347 static rtx last_parm_insn;
348 
349 /* 1 + last pseudo register number possibly used for loading a copy
350    of a parameter of this function. */
351 int max_parm_reg;
352 
353 /* Vector indexed by REGNO, containing location on stack in which
354    to put the parm which is nominally in pseudo register REGNO,
355    if we discover that that parm must go in the stack.  The highest
356    element in this vector is one less than MAX_PARM_REG, above.  */
357 rtx *parm_reg_stack_loc;
358 
359 /* Nonzero once virtual register instantiation has been done.
360    assign_stack_local uses frame_pointer_rtx when this is nonzero.  */
361 static int virtuals_instantiated;
362 
363 /* These variables hold pointers to functions to
364    save and restore machine-specific data,
365    in push_function_context and pop_function_context.  */
366 void (*save_machine_status) PROTO((struct function *));
367 void (*restore_machine_status) PROTO((struct function *));
368 
369 /* Nonzero if we need to distinguish between the return value of this function
370    and the return value of a function called by this function.  This helps
371    integrate.c  */
372 
373 extern int rtx_equal_function_value_matters;
374 extern tree sequence_rtl_expr;
375 
376 /* In order to evaluate some expressions, such as function calls returning
377    structures in memory, we need to temporarily allocate stack locations.
378    We record each allocated temporary in the following structure.
379 
380    Associated with each temporary slot is a nesting level.  When we pop up
381    one level, all temporaries associated with the previous level are freed.
382    Normally, all temporaries are freed after the execution of the statement
383    in which they were created.  However, if we are inside a ({...}) grouping,
384    the result may be in a temporary and hence must be preserved.  If the
385    result could be in a temporary, we preserve it if we can determine which
386    one it is in.  If we cannot determine which temporary may contain the
387    result, all temporaries are preserved.  A temporary is preserved by
388    pretending it was allocated at the previous nesting level.
389 
390    Automatic variables are also assigned temporary slots, at the nesting
391    level where they are defined.  They are marked a "kept" so that
392    free_temp_slots will not free them.  */
393 
394 struct temp_slot
395 {
396   /* Points to next temporary slot.  */
397   struct temp_slot *next;
398   /* The rtx to used to reference the slot.  */
399   rtx slot;
400   /* The rtx used to represent the address if not the address of the
401      slot above.  May be an EXPR_LIST if multiple addresses exist.  */
402   rtx address;
403   /* The alignment (in bits) of the slot. */
404   int align;
405   /* The size, in units, of the slot.  */
406   HOST_WIDE_INT size;
407   /* The alias set for the slot.  If the alias set is zero, we don't
408      know anything about the alias set of the slot.  We must only
409      reuse a slot if it is assigned an object of the same alias set.
410      Otherwise, the rest of the compiler may assume that the new use
411      of the slot cannot alias the old use of the slot, which is
412      false.  If the slot has alias set zero, then we can't reuse the
413      slot at all, since we have no idea what alias set may have been
414      imposed on the memory.  For example, if the stack slot is the
415      call frame for an inline functioned, we have no idea what alias
416      sets will be assigned to various pieces of the call frame.  */
417   int alias_set;
418   /* The value of `sequence_rtl_expr' when this temporary is allocated.  */
419   tree rtl_expr;
420   /* Non-zero if this temporary is currently in use.  */
421   char in_use;
422   /* Non-zero if this temporary has its address taken.  */
423   char addr_taken;
424   /* Nesting level at which this slot is being used.  */
425   int level;
426   /* Non-zero if this should survive a call to free_temp_slots.  */
427   int keep;
428   /* The offset of the slot from the frame_pointer, including extra space
429      for alignment.  This info is for combine_temp_slots.  */
430   HOST_WIDE_INT base_offset;
431   /* The size of the slot, including extra space for alignment.  This
432      info is for combine_temp_slots.  */
433   HOST_WIDE_INT full_size;
434 };
435 
436 /* List of all temporaries allocated, both available and in use.  */
437 
438 struct temp_slot *temp_slots;
439 
440 /* Current nesting level for temporaries.  */
441 
442 int temp_slot_level;
443 
444 /* Current nesting level for variables in a block.  */
445 
446 int var_temp_slot_level;
447 
448 /* When temporaries are created by TARGET_EXPRs, they are created at
449    this level of temp_slot_level, so that they can remain allocated
450    until no longer needed.  CLEANUP_POINT_EXPRs define the lifetime
451    of TARGET_EXPRs.  */
452 int target_temp_slot_level;
453 
454 /* This structure is used to record MEMs or pseudos used to replace VAR, any
455    SUBREGs of VAR, and any MEMs containing VAR as an address.  We need to
456    maintain this list in case two operands of an insn were required to match;
457    in that case we must ensure we use the same replacement.  */
458 
459 struct fixup_replacement
460 {
461   rtx old;
462   rtx new;
463   struct fixup_replacement *next;
464 };
465 
466 struct insns_for_mem_entry {
467   /* The KEY in HE will be a MEM.  */
468   struct hash_entry he;
469   /* These are the INSNS which reference the MEM.  */
470   rtx insns;
471 };
472 
473 /* Forward declarations.  */
474 
475 static rtx assign_outer_stack_local PROTO ((enum machine_mode, HOST_WIDE_INT,
476 					    int, struct function *));
477 static rtx assign_stack_temp_for_type PROTO ((enum machine_mode, HOST_WIDE_INT,
478 					      int, tree));
479 static struct temp_slot *find_temp_slot_from_address  PROTO((rtx));
480 static void put_reg_into_stack	PROTO((struct function *, rtx, tree,
481 				       enum machine_mode, enum machine_mode,
482 				       int, int, int,
483 				       struct hash_table *));
484 static void fixup_var_refs	PROTO((rtx, enum machine_mode, int,
485 				       struct hash_table *));
486 static struct fixup_replacement
487   *find_fixup_replacement	PROTO((struct fixup_replacement **, rtx));
488 static void fixup_var_refs_insns PROTO((rtx, enum machine_mode, int,
489 					rtx, int, struct hash_table *));
490 static void fixup_var_refs_1	PROTO((rtx, enum machine_mode, rtx *, rtx,
491 				       struct fixup_replacement **));
492 static rtx fixup_memory_subreg	PROTO((rtx, rtx, int));
493 static rtx walk_fixup_memory_subreg  PROTO((rtx, rtx, int));
494 static rtx fixup_stack_1	PROTO((rtx, rtx));
495 static void optimize_bit_field	PROTO((rtx, rtx, rtx *));
496 static void instantiate_decls	PROTO((tree, int));
497 static void instantiate_decls_1	PROTO((tree, int));
498 static void instantiate_decl	PROTO((rtx, int, int));
499 static int instantiate_virtual_regs_1 PROTO((rtx *, rtx, int));
500 static void delete_handlers	PROTO((void));
501 static void pad_to_arg_alignment PROTO((struct args_size *, int));
502 #ifndef ARGS_GROW_DOWNWARD
503 static void pad_below		PROTO((struct args_size *, enum  machine_mode,
504 				       tree));
505 #endif
506 #ifdef ARGS_GROW_DOWNWARD
507 static tree round_down		PROTO((tree, int));
508 #endif
509 static rtx round_trampoline_addr PROTO((rtx));
510 static tree blocks_nreverse	PROTO((tree));
511 static int all_blocks		PROTO((tree, tree *));
512 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
513 static int *record_insns	PROTO((rtx));
514 static int contains		PROTO((rtx, int *));
515 #endif /* HAVE_prologue || HAVE_epilogue */
516 static void put_addressof_into_stack PROTO((rtx, struct hash_table *));
517 static void purge_addressof_1	PROTO((rtx *, rtx, int, int,
518 				       struct hash_table *));
519 static struct hash_entry *insns_for_mem_newfunc PROTO((struct hash_entry *,
520 						       struct hash_table *,
521 						       hash_table_key));
522 static unsigned long insns_for_mem_hash PROTO ((hash_table_key));
523 static boolean insns_for_mem_comp PROTO ((hash_table_key, hash_table_key));
524 static int insns_for_mem_walk   PROTO ((rtx *, void *));
525 static void compute_insns_for_mem PROTO ((rtx, rtx, struct hash_table *));
526 
527 
528 /* Pointer to chain of `struct function' for containing functions.  */
529 struct function *outer_function_chain;
530 
531 /* Given a function decl for a containing function,
532    return the `struct function' for it.  */
533 
534 struct function *
535 find_function_data (decl)
536      tree decl;
537 {
538   struct function *p;
539 
540   for (p = outer_function_chain; p; p = p->next)
541     if (p->decl == decl)
542       return p;
543 
544   abort ();
545 }
546 
547 /* Save the current context for compilation of a nested function.
548    This is called from language-specific code.
549    The caller is responsible for saving any language-specific status,
550    since this function knows only about language-independent variables.  */
551 
552 void
553 push_function_context_to (context)
554      tree context;
555 {
556   struct function *p = (struct function *) xmalloc (sizeof (struct function));
557 
558   p->next = outer_function_chain;
559   outer_function_chain = p;
560 
561   p->name = current_function_name;
562   p->decl = current_function_decl;
563   p->pops_args = current_function_pops_args;
564   p->returns_struct = current_function_returns_struct;
565   p->returns_pcc_struct = current_function_returns_pcc_struct;
566   p->returns_pointer = current_function_returns_pointer;
567   p->needs_context = current_function_needs_context;
568   p->calls_setjmp = current_function_calls_setjmp;
569   p->calls_longjmp = current_function_calls_longjmp;
570   p->calls_alloca = current_function_calls_alloca;
571   p->has_nonlocal_label = current_function_has_nonlocal_label;
572   p->has_nonlocal_goto = current_function_has_nonlocal_goto;
573   p->contains_functions = current_function_contains_functions;
574   p->has_computed_jump = current_function_has_computed_jump;
575   p->is_thunk = current_function_is_thunk;
576   p->args_size = current_function_args_size;
577   p->pretend_args_size = current_function_pretend_args_size;
578   p->arg_offset_rtx = current_function_arg_offset_rtx;
579   p->varargs = current_function_varargs;
580   p->stdarg = current_function_stdarg;
581   p->uses_const_pool = current_function_uses_const_pool;
582   p->uses_pic_offset_table = current_function_uses_pic_offset_table;
583   p->internal_arg_pointer = current_function_internal_arg_pointer;
584   p->cannot_inline = current_function_cannot_inline;
585   p->max_parm_reg = max_parm_reg;
586   p->parm_reg_stack_loc = parm_reg_stack_loc;
587   p->outgoing_args_size = current_function_outgoing_args_size;
588   p->return_rtx = current_function_return_rtx;
589   p->nonlocal_goto_handler_slots = nonlocal_goto_handler_slots;
590   p->nonlocal_goto_handler_labels = nonlocal_goto_handler_labels;
591   p->nonlocal_goto_stack_level = nonlocal_goto_stack_level;
592   p->nonlocal_labels = nonlocal_labels;
593   p->cleanup_label = cleanup_label;
594   p->return_label = return_label;
595   p->save_expr_regs = save_expr_regs;
596   p->stack_slot_list = stack_slot_list;
597   p->parm_birth_insn = parm_birth_insn;
598   p->frame_offset = frame_offset;
599   p->tail_recursion_label = tail_recursion_label;
600   p->tail_recursion_reentry = tail_recursion_reentry;
601   p->arg_pointer_save_area = arg_pointer_save_area;
602   p->rtl_expr_chain = rtl_expr_chain;
603   p->last_parm_insn = last_parm_insn;
604   p->context_display = context_display;
605   p->trampoline_list = trampoline_list;
606   p->function_call_count = function_call_count;
607   p->temp_slots = temp_slots;
608   p->temp_slot_level = temp_slot_level;
609   p->target_temp_slot_level = target_temp_slot_level;
610   p->var_temp_slot_level = var_temp_slot_level;
611   p->fixup_var_refs_queue = 0;
612   p->epilogue_delay_list = current_function_epilogue_delay_list;
613   p->args_info = current_function_args_info;
614   p->check_memory_usage = current_function_check_memory_usage;
615   p->instrument_entry_exit = current_function_instrument_entry_exit;
616 
617   save_tree_status (p, context);
618   save_storage_status (p);
619   save_emit_status (p);
620   save_expr_status (p);
621   save_stmt_status (p);
622   save_varasm_status (p, context);
623   if (save_machine_status)
624     (*save_machine_status) (p);
625 }
626 
627 void
628 push_function_context ()
629 {
630   push_function_context_to (current_function_decl);
631 }
632 
633 /* Restore the last saved context, at the end of a nested function.
634    This function is called from language-specific code.  */
635 
636 void
637 pop_function_context_from (context)
638      tree context;
639 {
640   struct function *p = outer_function_chain;
641   struct var_refs_queue *queue;
642 
643   outer_function_chain = p->next;
644 
645   current_function_contains_functions
646     = p->contains_functions || p->inline_obstacks
647       || context == current_function_decl;
648   current_function_has_computed_jump = p->has_computed_jump;
649   current_function_name = p->name;
650   current_function_decl = p->decl;
651   current_function_pops_args = p->pops_args;
652   current_function_returns_struct = p->returns_struct;
653   current_function_returns_pcc_struct = p->returns_pcc_struct;
654   current_function_returns_pointer = p->returns_pointer;
655   current_function_needs_context = p->needs_context;
656   current_function_calls_setjmp = p->calls_setjmp;
657   current_function_calls_longjmp = p->calls_longjmp;
658   current_function_calls_alloca = p->calls_alloca;
659   current_function_has_nonlocal_label = p->has_nonlocal_label;
660   current_function_has_nonlocal_goto = p->has_nonlocal_goto;
661   current_function_is_thunk = p->is_thunk;
662   current_function_args_size = p->args_size;
663   current_function_pretend_args_size = p->pretend_args_size;
664   current_function_arg_offset_rtx = p->arg_offset_rtx;
665   current_function_varargs = p->varargs;
666   current_function_stdarg = p->stdarg;
667   current_function_uses_const_pool = p->uses_const_pool;
668   current_function_uses_pic_offset_table = p->uses_pic_offset_table;
669   current_function_internal_arg_pointer = p->internal_arg_pointer;
670   current_function_cannot_inline = p->cannot_inline;
671   max_parm_reg = p->max_parm_reg;
672   parm_reg_stack_loc = p->parm_reg_stack_loc;
673   current_function_outgoing_args_size = p->outgoing_args_size;
674   current_function_return_rtx = p->return_rtx;
675   nonlocal_goto_handler_slots = p->nonlocal_goto_handler_slots;
676   nonlocal_goto_handler_labels = p->nonlocal_goto_handler_labels;
677   nonlocal_goto_stack_level = p->nonlocal_goto_stack_level;
678   nonlocal_labels = p->nonlocal_labels;
679   cleanup_label = p->cleanup_label;
680   return_label = p->return_label;
681   save_expr_regs = p->save_expr_regs;
682   stack_slot_list = p->stack_slot_list;
683   parm_birth_insn = p->parm_birth_insn;
684   frame_offset = p->frame_offset;
685   tail_recursion_label = p->tail_recursion_label;
686   tail_recursion_reentry = p->tail_recursion_reentry;
687   arg_pointer_save_area = p->arg_pointer_save_area;
688   rtl_expr_chain = p->rtl_expr_chain;
689   last_parm_insn = p->last_parm_insn;
690   context_display = p->context_display;
691   trampoline_list = p->trampoline_list;
692   function_call_count = p->function_call_count;
693   temp_slots = p->temp_slots;
694   temp_slot_level = p->temp_slot_level;
695   target_temp_slot_level = p->target_temp_slot_level;
696   var_temp_slot_level = p->var_temp_slot_level;
697   current_function_epilogue_delay_list = p->epilogue_delay_list;
698   reg_renumber = 0;
699   current_function_args_info = p->args_info;
700   current_function_check_memory_usage = p->check_memory_usage;
701   current_function_instrument_entry_exit = p->instrument_entry_exit;
702 
703   restore_tree_status (p, context);
704   restore_storage_status (p);
705   restore_expr_status (p);
706   restore_emit_status (p);
707   restore_stmt_status (p);
708   restore_varasm_status (p);
709 
710   if (restore_machine_status)
711     (*restore_machine_status) (p);
712 
713   /* Finish doing put_var_into_stack for any of our variables
714      which became addressable during the nested function.  */
715   for (queue = p->fixup_var_refs_queue; queue; queue = queue->next)
716     fixup_var_refs (queue->modified, queue->promoted_mode,
717 		    queue->unsignedp, 0);
718 
719   free (p);
720 
721   /* Reset variables that have known state during rtx generation.  */
722   rtx_equal_function_value_matters = 1;
723   virtuals_instantiated = 0;
724 }
725 
726 void pop_function_context ()
727 {
728   pop_function_context_from (current_function_decl);
729 }
730 
731 /* Allocate fixed slots in the stack frame of the current function.  */
732 
733 /* Return size needed for stack frame based on slots so far allocated.
734    This size counts from zero.  It is not rounded to PREFERRED_STACK_BOUNDARY;
735    the caller may have to do that.  */
736 
737 HOST_WIDE_INT
738 get_frame_size ()
739 {
740 #ifdef FRAME_GROWS_DOWNWARD
741   return -frame_offset;
742 #else
743   return frame_offset;
744 #endif
745 }
746 
747 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
748    with machine mode MODE.
749 
750    ALIGN controls the amount of alignment for the address of the slot:
751    0 means according to MODE,
752    -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
753    positive specifies alignment boundary in bits.
754 
755    We do not round to stack_boundary here.  */
756 
757 rtx
758 assign_stack_local (mode, size, align)
759      enum machine_mode mode;
760      HOST_WIDE_INT size;
761      int align;
762 {
763   register rtx x, addr;
764   int bigend_correction = 0;
765   int alignment;
766 
767   if (align == 0)
768     {
769       tree type;
770 
771       alignment = GET_MODE_ALIGNMENT (mode);
772       if (mode == BLKmode)
773 	alignment = BIGGEST_ALIGNMENT;
774 
775       /* Allow the target to (possibly) increase the alignment of this
776 	 stack slot.  */
777       type = type_for_mode (mode, 0);
778       if (type)
779 	alignment = LOCAL_ALIGNMENT (type, alignment);
780 
781       alignment /= BITS_PER_UNIT;
782     }
783   else if (align == -1)
784     {
785       alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
786       size = CEIL_ROUND (size, alignment);
787     }
788   else
789     alignment = align / BITS_PER_UNIT;
790 
791 #ifdef FRAME_GROWS_DOWNWARD
792   frame_offset -= size;
793 #endif
794 
795   /* Round frame offset to that alignment.
796      We must be careful here, since FRAME_OFFSET might be negative and
797      division with a negative dividend isn't as well defined as we might
798      like.  So we instead assume that ALIGNMENT is a power of two and
799      use logical operations which are unambiguous.  */
800 #ifdef FRAME_GROWS_DOWNWARD
801   frame_offset = FLOOR_ROUND (frame_offset, alignment);
802 #else
803   frame_offset = CEIL_ROUND (frame_offset, alignment);
804 #endif
805 
806   /* On a big-endian machine, if we are allocating more space than we will use,
807      use the least significant bytes of those that are allocated.  */
808   if (BYTES_BIG_ENDIAN && mode != BLKmode)
809     bigend_correction = size - GET_MODE_SIZE (mode);
810 
811   /* If we have already instantiated virtual registers, return the actual
812      address relative to the frame pointer.  */
813   if (virtuals_instantiated)
814     addr = plus_constant (frame_pointer_rtx,
815 			  (frame_offset + bigend_correction
816 			   + STARTING_FRAME_OFFSET));
817   else
818     addr = plus_constant (virtual_stack_vars_rtx,
819 			  frame_offset + bigend_correction);
820 
821 #ifndef FRAME_GROWS_DOWNWARD
822   frame_offset += size;
823 #endif
824 
825   x = gen_rtx_MEM (mode, addr);
826 
827   stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, x, stack_slot_list);
828 
829   return x;
830 }
831 
832 /* Assign a stack slot in a containing function.
833    First three arguments are same as in preceding function.
834    The last argument specifies the function to allocate in.  */
835 
836 static rtx
837 assign_outer_stack_local (mode, size, align, function)
838      enum machine_mode mode;
839      HOST_WIDE_INT size;
840      int align;
841      struct function *function;
842 {
843   register rtx x, addr;
844   int bigend_correction = 0;
845   int alignment;
846 
847   /* Allocate in the memory associated with the function in whose frame
848      we are assigning.  */
849   push_obstacks (function->function_obstack,
850 		 function->function_maybepermanent_obstack);
851 
852   if (align == 0)
853     {
854       tree type;
855 
856       alignment = GET_MODE_ALIGNMENT (mode);
857       if (mode == BLKmode)
858 	alignment = BIGGEST_ALIGNMENT;
859 
860       /* Allow the target to (possibly) increase the alignment of this
861 	 stack slot.  */
862       type = type_for_mode (mode, 0);
863       if (type)
864 	alignment = LOCAL_ALIGNMENT (type, alignment);
865 
866       alignment /= BITS_PER_UNIT;
867     }
868   else if (align == -1)
869     {
870       alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
871       size = CEIL_ROUND (size, alignment);
872     }
873   else
874     alignment = align / BITS_PER_UNIT;
875 
876 #ifdef FRAME_GROWS_DOWNWARD
877   function->frame_offset -= size;
878 #endif
879 
880   /* Round frame offset to that alignment.  */
881 #ifdef FRAME_GROWS_DOWNWARD
882   function->frame_offset = FLOOR_ROUND (function->frame_offset, alignment);
883 #else
884   function->frame_offset = CEIL_ROUND (function->frame_offset, alignment);
885 #endif
886 
887   /* On a big-endian machine, if we are allocating more space than we will use,
888      use the least significant bytes of those that are allocated.  */
889   if (BYTES_BIG_ENDIAN && mode != BLKmode)
890     bigend_correction = size - GET_MODE_SIZE (mode);
891 
892   addr = plus_constant (virtual_stack_vars_rtx,
893 			function->frame_offset + bigend_correction);
894 #ifndef FRAME_GROWS_DOWNWARD
895   function->frame_offset += size;
896 #endif
897 
898   x = gen_rtx_MEM (mode, addr);
899 
900   function->stack_slot_list
901     = gen_rtx_EXPR_LIST (VOIDmode, x, function->stack_slot_list);
902 
903   pop_obstacks ();
904 
905   return x;
906 }
907 
908 /* Allocate a temporary stack slot and record it for possible later
909    reuse.
910 
911    MODE is the machine mode to be given to the returned rtx.
912 
913    SIZE is the size in units of the space required.  We do no rounding here
914    since assign_stack_local will do any required rounding.
915 
916    KEEP is 1 if this slot is to be retained after a call to
917    free_temp_slots.  Automatic variables for a block are allocated
918    with this flag.  KEEP is 2 if we allocate a longer term temporary,
919    whose lifetime is controlled by CLEANUP_POINT_EXPRs.  KEEP is 3
920    if we are to allocate something at an inner level to be treated as
921    a variable in the block (e.g., a SAVE_EXPR).
922 
923    TYPE is the type that will be used for the stack slot.  */
924 
925 static rtx
926 assign_stack_temp_for_type (mode, size, keep, type)
927      enum machine_mode mode;
928      HOST_WIDE_INT size;
929      int keep;
930      tree type;
931 {
932   int align;
933   int alias_set;
934   struct temp_slot *p, *best_p = 0;
935 
936   /* If SIZE is -1 it means that somebody tried to allocate a temporary
937      of a variable size.  */
938   if (size == -1)
939     abort ();
940 
941   /* If we know the alias set for the memory that will be used, use
942      it.  If there's no TYPE, then we don't know anything about the
943      alias set for the memory.  */
944   if (type)
945     alias_set = get_alias_set (type);
946   else
947     alias_set = 0;
948 
949   align = GET_MODE_ALIGNMENT (mode);
950   if (mode == BLKmode)
951     align = BIGGEST_ALIGNMENT;
952 
953   if (! type)
954     type = type_for_mode (mode, 0);
955   if (type)
956     align = LOCAL_ALIGNMENT (type, align);
957 
958   /* Try to find an available, already-allocated temporary of the proper
959      mode which meets the size and alignment requirements.  Choose the
960      smallest one with the closest alignment.  */
961   for (p = temp_slots; p; p = p->next)
962     if (p->align >= align && p->size >= size && GET_MODE (p->slot) == mode
963 	&& ! p->in_use
964 	&& (!flag_strict_aliasing
965 	    || (alias_set && p->alias_set == alias_set))
966 	&& (best_p == 0 || best_p->size > p->size
967 	    || (best_p->size == p->size && best_p->align > p->align)))
968       {
969 	if (p->align == align && p->size == size)
970 	  {
971 	    best_p = 0;
972 	    break;
973 	  }
974 	best_p = p;
975       }
976 
977   /* Make our best, if any, the one to use.  */
978   if (best_p)
979     {
980       /* If there are enough aligned bytes left over, make them into a new
981 	 temp_slot so that the extra bytes don't get wasted.  Do this only
982 	 for BLKmode slots, so that we can be sure of the alignment.  */
983       if (GET_MODE (best_p->slot) == BLKmode
984 	  /* We can't split slots if -fstrict-aliasing because the
985 	     information about the alias set for the new slot will be
986 	     lost.  */
987 	  && !flag_strict_aliasing)
988 	{
989 	  int alignment = best_p->align / BITS_PER_UNIT;
990 	  HOST_WIDE_INT rounded_size = CEIL_ROUND (size, alignment);
991 
992 	  if (best_p->size - rounded_size >= alignment)
993 	    {
994 	      p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
995 	      p->in_use = p->addr_taken = 0;
996 	      p->size = best_p->size - rounded_size;
997 	      p->base_offset = best_p->base_offset + rounded_size;
998 	      p->full_size = best_p->full_size - rounded_size;
999 	      p->slot = gen_rtx_MEM (BLKmode,
1000 				     plus_constant (XEXP (best_p->slot, 0),
1001 						    rounded_size));
1002 	      p->align = best_p->align;
1003 	      p->address = 0;
1004 	      p->rtl_expr = 0;
1005 	      p->next = temp_slots;
1006 	      temp_slots = p;
1007 
1008 	      stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, p->slot,
1009 						   stack_slot_list);
1010 
1011 	      best_p->size = rounded_size;
1012 	      best_p->full_size = rounded_size;
1013 	    }
1014 	}
1015 
1016       p = best_p;
1017     }
1018 
1019   /* If we still didn't find one, make a new temporary.  */
1020   if (p == 0)
1021     {
1022       HOST_WIDE_INT frame_offset_old = frame_offset;
1023 
1024       p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
1025 
1026       /* We are passing an explicit alignment request to assign_stack_local.
1027 	 One side effect of that is assign_stack_local will not round SIZE
1028 	 to ensure the frame offset remains suitably aligned.
1029 
1030 	 So for requests which depended on the rounding of SIZE, we go ahead
1031 	 and round it now.  We also make sure ALIGNMENT is at least
1032 	 BIGGEST_ALIGNMENT.  */
1033       if (mode == BLKmode && align < BIGGEST_ALIGNMENT)
1034 	abort();
1035       p->slot = assign_stack_local (mode,
1036 				    (mode == BLKmode
1037 				     ? CEIL_ROUND (size, align / BITS_PER_UNIT)
1038 				     : size),
1039 				    align);
1040 
1041       p->align = align;
1042       p->alias_set = alias_set;
1043 
1044       /* The following slot size computation is necessary because we don't
1045 	 know the actual size of the temporary slot until assign_stack_local
1046 	 has performed all the frame alignment and size rounding for the
1047 	 requested temporary.  Note that extra space added for alignment
1048 	 can be either above or below this stack slot depending on which
1049 	 way the frame grows.  We include the extra space if and only if it
1050 	 is above this slot.  */
1051 #ifdef FRAME_GROWS_DOWNWARD
1052       p->size = frame_offset_old - frame_offset;
1053 #else
1054       p->size = size;
1055 #endif
1056 
1057       /* Now define the fields used by combine_temp_slots.  */
1058 #ifdef FRAME_GROWS_DOWNWARD
1059       p->base_offset = frame_offset;
1060       p->full_size = frame_offset_old - frame_offset;
1061 #else
1062       p->base_offset = frame_offset_old;
1063       p->full_size = frame_offset - frame_offset_old;
1064 #endif
1065       p->address = 0;
1066       p->next = temp_slots;
1067       temp_slots = p;
1068     }
1069 
1070   p->in_use = 1;
1071   p->addr_taken = 0;
1072   p->rtl_expr = sequence_rtl_expr;
1073 
1074   if (keep == 2)
1075     {
1076       p->level = target_temp_slot_level;
1077       p->keep = 0;
1078     }
1079   else if (keep == 3)
1080     {
1081       p->level = var_temp_slot_level;
1082       p->keep = 0;
1083     }
1084   else
1085     {
1086       p->level = temp_slot_level;
1087       p->keep = keep;
1088     }
1089 
1090   /* We may be reusing an old slot, so clear any MEM flags that may have been
1091      set from before.  */
1092   RTX_UNCHANGING_P (p->slot) = 0;
1093   MEM_IN_STRUCT_P (p->slot) = 0;
1094   MEM_SCALAR_P (p->slot) = 0;
1095   MEM_ALIAS_SET (p->slot) = 0;
1096   return p->slot;
1097 }
1098 
1099 /* Allocate a temporary stack slot and record it for possible later
1100    reuse.  First three arguments are same as in preceding function.  */
1101 
1102 rtx
1103 assign_stack_temp (mode, size, keep)
1104      enum machine_mode mode;
1105      HOST_WIDE_INT size;
1106      int keep;
1107 {
1108   return assign_stack_temp_for_type (mode, size, keep, NULL_TREE);
1109 }
1110 
1111 /* Assign a temporary of given TYPE.
1112    KEEP is as for assign_stack_temp.
1113    MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
1114    it is 0 if a register is OK.
1115    DONT_PROMOTE is 1 if we should not promote values in register
1116    to wider modes.  */
1117 
1118 rtx
1119 assign_temp (type, keep, memory_required, dont_promote)
1120      tree type;
1121      int keep;
1122      int memory_required;
1123      int dont_promote;
1124 {
1125   enum machine_mode mode = TYPE_MODE (type);
1126   int unsignedp = TREE_UNSIGNED (type);
1127 
1128   if (mode == BLKmode || memory_required)
1129     {
1130       HOST_WIDE_INT size = int_size_in_bytes (type);
1131       rtx tmp;
1132 
1133       /* Unfortunately, we don't yet know how to allocate variable-sized
1134 	 temporaries.  However, sometimes we have a fixed upper limit on
1135 	 the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that
1136 	 instead.  This is the case for Chill variable-sized strings.  */
1137       if (size == -1 && TREE_CODE (type) == ARRAY_TYPE
1138 	  && TYPE_ARRAY_MAX_SIZE (type) != NULL_TREE
1139 	  && TREE_CODE (TYPE_ARRAY_MAX_SIZE (type)) == INTEGER_CST)
1140 	size = TREE_INT_CST_LOW (TYPE_ARRAY_MAX_SIZE (type));
1141 
1142       tmp = assign_stack_temp_for_type (mode, size, keep, type);
1143       MEM_SET_IN_STRUCT_P (tmp, AGGREGATE_TYPE_P (type));
1144       return tmp;
1145     }
1146 
1147 #ifndef PROMOTE_FOR_CALL_ONLY
1148   if (! dont_promote)
1149     mode = promote_mode (type, mode, &unsignedp, 0);
1150 #endif
1151 
1152   return gen_reg_rtx (mode);
1153 }
1154 
1155 /* Combine temporary stack slots which are adjacent on the stack.
1156 
1157    This allows for better use of already allocated stack space.  This is only
1158    done for BLKmode slots because we can be sure that we won't have alignment
1159    problems in this case.  */
1160 
1161 void
1162 combine_temp_slots ()
1163 {
1164   struct temp_slot *p, *q;
1165   struct temp_slot *prev_p, *prev_q;
1166   int num_slots;
1167 
1168   /* We can't combine slots, because the information about which slot
1169      is in which alias set will be lost.  */
1170   if (flag_strict_aliasing)
1171     return;
1172 
1173   /* If there are a lot of temp slots, don't do anything unless
1174      high levels of optimizaton.  */
1175   if (! flag_expensive_optimizations)
1176     for (p = temp_slots, num_slots = 0; p; p = p->next, num_slots++)
1177       if (num_slots > 100 || (num_slots > 10 && optimize == 0))
1178 	return;
1179 
1180   for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots)
1181     {
1182       int delete_p = 0;
1183 
1184       if (! p->in_use && GET_MODE (p->slot) == BLKmode)
1185 	for (q = p->next, prev_q = p; q; q = prev_q->next)
1186 	  {
1187 	    int delete_q = 0;
1188 	    if (! q->in_use && GET_MODE (q->slot) == BLKmode)
1189 	      {
1190 		if (p->base_offset + p->full_size == q->base_offset)
1191 		  {
1192 		    /* Q comes after P; combine Q into P.  */
1193 		    p->size += q->size;
1194 		    p->full_size += q->full_size;
1195 		    delete_q = 1;
1196 		  }
1197 		else if (q->base_offset + q->full_size == p->base_offset)
1198 		  {
1199 		    /* P comes after Q; combine P into Q.  */
1200 		    q->size += p->size;
1201 		    q->full_size += p->full_size;
1202 		    delete_p = 1;
1203 		    break;
1204 		  }
1205 	      }
1206 	    /* Either delete Q or advance past it.  */
1207 	    if (delete_q)
1208 	      prev_q->next = q->next;
1209 	    else
1210 	      prev_q = q;
1211 	  }
1212       /* Either delete P or advance past it.  */
1213       if (delete_p)
1214 	{
1215 	  if (prev_p)
1216 	    prev_p->next = p->next;
1217 	  else
1218 	    temp_slots = p->next;
1219 	}
1220       else
1221 	prev_p = p;
1222     }
1223 }
1224 
1225 /* Find the temp slot corresponding to the object at address X.  */
1226 
1227 static struct temp_slot *
1228 find_temp_slot_from_address (x)
1229      rtx x;
1230 {
1231   struct temp_slot *p;
1232   rtx next;
1233 
1234   for (p = temp_slots; p; p = p->next)
1235     {
1236       if (! p->in_use)
1237 	continue;
1238 
1239       else if (XEXP (p->slot, 0) == x
1240 	       || p->address == x
1241 	       || (GET_CODE (x) == PLUS
1242 		   && XEXP (x, 0) == virtual_stack_vars_rtx
1243 		   && GET_CODE (XEXP (x, 1)) == CONST_INT
1244 		   && INTVAL (XEXP (x, 1)) >= p->base_offset
1245 		   && INTVAL (XEXP (x, 1)) < p->base_offset + p->full_size))
1246 	return p;
1247 
1248       else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST)
1249 	for (next = p->address; next; next = XEXP (next, 1))
1250 	  if (XEXP (next, 0) == x)
1251 	    return p;
1252     }
1253 
1254   return 0;
1255 }
1256 
1257 /* Indicate that NEW is an alternate way of referring to the temp slot
1258    that previously was known by OLD.  */
1259 
1260 void
1261 update_temp_slot_address (old, new)
1262      rtx old, new;
1263 {
1264   struct temp_slot *p = find_temp_slot_from_address (old);
1265 
1266   /* If none, return.  Else add NEW as an alias.  */
1267   if (p == 0)
1268     return;
1269   else if (p->address == 0)
1270     p->address = new;
1271   else
1272     {
1273       if (GET_CODE (p->address) != EXPR_LIST)
1274 	p->address = gen_rtx_EXPR_LIST (VOIDmode, p->address, NULL_RTX);
1275 
1276       p->address = gen_rtx_EXPR_LIST (VOIDmode, new, p->address);
1277     }
1278 }
1279 
1280 /* If X could be a reference to a temporary slot, mark the fact that its
1281    address was taken.  */
1282 
1283 void
1284 mark_temp_addr_taken (x)
1285      rtx x;
1286 {
1287   struct temp_slot *p;
1288 
1289   if (x == 0)
1290     return;
1291 
1292   /* If X is not in memory or is at a constant address, it cannot be in
1293      a temporary slot.  */
1294   if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1295     return;
1296 
1297   p = find_temp_slot_from_address (XEXP (x, 0));
1298   if (p != 0)
1299     p->addr_taken = 1;
1300 }
1301 
1302 /* If X could be a reference to a temporary slot, mark that slot as
1303    belonging to the to one level higher than the current level.  If X
1304    matched one of our slots, just mark that one.  Otherwise, we can't
1305    easily predict which it is, so upgrade all of them.  Kept slots
1306    need not be touched.
1307 
1308    This is called when an ({...}) construct occurs and a statement
1309    returns a value in memory.  */
1310 
1311 void
1312 preserve_temp_slots (x)
1313      rtx x;
1314 {
1315   struct temp_slot *p = 0;
1316 
1317   /* If there is no result, we still might have some objects whose address
1318      were taken, so we need to make sure they stay around.  */
1319   if (x == 0)
1320     {
1321       for (p = temp_slots; p; p = p->next)
1322 	if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1323 	  p->level--;
1324 
1325       return;
1326     }
1327 
1328   /* If X is a register that is being used as a pointer, see if we have
1329      a temporary slot we know it points to.  To be consistent with
1330      the code below, we really should preserve all non-kept slots
1331      if we can't find a match, but that seems to be much too costly.  */
1332   if (GET_CODE (x) == REG && REGNO_POINTER_FLAG (REGNO (x)))
1333     p = find_temp_slot_from_address (x);
1334 
1335   /* If X is not in memory or is at a constant address, it cannot be in
1336      a temporary slot, but it can contain something whose address was
1337      taken.  */
1338   if (p == 0 && (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))))
1339     {
1340       for (p = temp_slots; p; p = p->next)
1341 	if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1342 	  p->level--;
1343 
1344       return;
1345     }
1346 
1347   /* First see if we can find a match.  */
1348   if (p == 0)
1349     p = find_temp_slot_from_address (XEXP (x, 0));
1350 
1351   if (p != 0)
1352     {
1353       /* Move everything at our level whose address was taken to our new
1354 	 level in case we used its address.  */
1355       struct temp_slot *q;
1356 
1357       if (p->level == temp_slot_level)
1358 	{
1359 	  for (q = temp_slots; q; q = q->next)
1360 	    if (q != p && q->addr_taken && q->level == p->level)
1361 	      q->level--;
1362 
1363 	  p->level--;
1364 	  p->addr_taken = 0;
1365 	}
1366       return;
1367     }
1368 
1369   /* Otherwise, preserve all non-kept slots at this level.  */
1370   for (p = temp_slots; p; p = p->next)
1371     if (p->in_use && p->level == temp_slot_level && ! p->keep)
1372       p->level--;
1373 }
1374 
1375 /* X is the result of an RTL_EXPR.  If it is a temporary slot associated
1376    with that RTL_EXPR, promote it into a temporary slot at the present
1377    level so it will not be freed when we free slots made in the
1378    RTL_EXPR.  */
1379 
1380 void
1381 preserve_rtl_expr_result (x)
1382      rtx x;
1383 {
1384   struct temp_slot *p;
1385 
1386   /* If X is not in memory or is at a constant address, it cannot be in
1387      a temporary slot.  */
1388   if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1389     return;
1390 
1391   /* If we can find a match, move it to our level unless it is already at
1392      an upper level.  */
1393   p = find_temp_slot_from_address (XEXP (x, 0));
1394   if (p != 0)
1395     {
1396       p->level = MIN (p->level, temp_slot_level);
1397       p->rtl_expr = 0;
1398     }
1399 
1400   return;
1401 }
1402 
1403 /* Free all temporaries used so far.  This is normally called at the end
1404    of generating code for a statement.  Don't free any temporaries
1405    currently in use for an RTL_EXPR that hasn't yet been emitted.
1406    We could eventually do better than this since it can be reused while
1407    generating the same RTL_EXPR, but this is complex and probably not
1408    worthwhile.  */
1409 
1410 void
1411 free_temp_slots ()
1412 {
1413   struct temp_slot *p;
1414 
1415   for (p = temp_slots; p; p = p->next)
1416     if (p->in_use && p->level == temp_slot_level && ! p->keep
1417 	&& p->rtl_expr == 0)
1418       p->in_use = 0;
1419 
1420   combine_temp_slots ();
1421 }
1422 
1423 /* Free all temporary slots used in T, an RTL_EXPR node.  */
1424 
1425 void
1426 free_temps_for_rtl_expr (t)
1427      tree t;
1428 {
1429   struct temp_slot *p;
1430 
1431   for (p = temp_slots; p; p = p->next)
1432     if (p->rtl_expr == t)
1433       p->in_use = 0;
1434 
1435   combine_temp_slots ();
1436 }
1437 
1438 /* Mark all temporaries ever allocated in this function as not suitable
1439    for reuse until the current level is exited.  */
1440 
1441 void
1442 mark_all_temps_used ()
1443 {
1444   struct temp_slot *p;
1445 
1446   for (p = temp_slots; p; p = p->next)
1447     {
1448       p->in_use = p->keep = 1;
1449       p->level = MIN (p->level, temp_slot_level);
1450     }
1451 }
1452 
1453 /* Push deeper into the nesting level for stack temporaries.  */
1454 
1455 void
1456 push_temp_slots ()
1457 {
1458   temp_slot_level++;
1459 }
1460 
1461 /* Likewise, but save the new level as the place to allocate variables
1462    for blocks.  */
1463 
1464 void
1465 push_temp_slots_for_block ()
1466 {
1467   push_temp_slots ();
1468 
1469   var_temp_slot_level = temp_slot_level;
1470 }
1471 
1472 /* Likewise, but save the new level as the place to allocate temporaries
1473    for TARGET_EXPRs.  */
1474 
1475 void
1476 push_temp_slots_for_target ()
1477 {
1478   push_temp_slots ();
1479 
1480   target_temp_slot_level = temp_slot_level;
1481 }
1482 
1483 /* Set and get the value of target_temp_slot_level.  The only
1484    permitted use of these functions is to save and restore this value.  */
1485 
1486 int
1487 get_target_temp_slot_level ()
1488 {
1489   return target_temp_slot_level;
1490 }
1491 
1492 void
1493 set_target_temp_slot_level (level)
1494      int level;
1495 {
1496   target_temp_slot_level = level;
1497 }
1498 
1499 /* Pop a temporary nesting level.  All slots in use in the current level
1500    are freed.  */
1501 
1502 void
1503 pop_temp_slots ()
1504 {
1505   struct temp_slot *p;
1506 
1507   for (p = temp_slots; p; p = p->next)
1508     if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0)
1509       p->in_use = 0;
1510 
1511   combine_temp_slots ();
1512 
1513   temp_slot_level--;
1514 }
1515 
1516 /* Initialize temporary slots.  */
1517 
1518 void
1519 init_temp_slots ()
1520 {
1521   /* We have not allocated any temporaries yet.  */
1522   temp_slots = 0;
1523   temp_slot_level = 0;
1524   var_temp_slot_level = 0;
1525   target_temp_slot_level = 0;
1526 }
1527 
1528 /* Retroactively move an auto variable from a register to a stack slot.
1529    This is done when an address-reference to the variable is seen.  */
1530 
1531 void
1532 put_var_into_stack (decl)
1533      tree decl;
1534 {
1535   register rtx reg;
1536   enum machine_mode promoted_mode, decl_mode;
1537   struct function *function = 0;
1538   tree context;
1539   int can_use_addressof;
1540 
1541   context = decl_function_context (decl);
1542 
1543   /* Get the current rtl used for this object and its original mode.  */
1544   reg = TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl) : DECL_RTL (decl);
1545 
1546   /* No need to do anything if decl has no rtx yet
1547      since in that case caller is setting TREE_ADDRESSABLE
1548      and a stack slot will be assigned when the rtl is made.  */
1549   if (reg == 0)
1550     return;
1551 
1552   /* Get the declared mode for this object.  */
1553   decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl))
1554 	       : DECL_MODE (decl));
1555   /* Get the mode it's actually stored in.  */
1556   promoted_mode = GET_MODE (reg);
1557 
1558   /* If this variable comes from an outer function,
1559      find that function's saved context.  */
1560   if (context != current_function_decl && context != inline_function_decl)
1561     for (function = outer_function_chain; function; function = function->next)
1562       if (function->decl == context)
1563 	break;
1564 
1565   /* If this is a variable-size object with a pseudo to address it,
1566      put that pseudo into the stack, if the var is nonlocal.  */
1567   if (DECL_NONLOCAL (decl)
1568       && GET_CODE (reg) == MEM
1569       && GET_CODE (XEXP (reg, 0)) == REG
1570       && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
1571     {
1572       reg = XEXP (reg, 0);
1573       decl_mode = promoted_mode = GET_MODE (reg);
1574     }
1575 
1576   can_use_addressof
1577     = (function == 0
1578        && optimize > 0
1579        /* FIXME make it work for promoted modes too */
1580        && decl_mode == promoted_mode
1581 #ifdef NON_SAVING_SETJMP
1582        && ! (NON_SAVING_SETJMP && current_function_calls_setjmp)
1583 #endif
1584        );
1585 
1586   /* If we can't use ADDRESSOF, make sure we see through one we already
1587      generated.  */
1588   if (! can_use_addressof && GET_CODE (reg) == MEM
1589       && GET_CODE (XEXP (reg, 0)) == ADDRESSOF)
1590     reg = XEXP (XEXP (reg, 0), 0);
1591 
1592   /* Now we should have a value that resides in one or more pseudo regs.  */
1593 
1594   if (GET_CODE (reg) == REG)
1595     {
1596       /* If this variable lives in the current function and we don't need
1597 	 to put things in the stack for the sake of setjmp, try to keep it
1598 	 in a register until we know we actually need the address.  */
1599       if (can_use_addressof)
1600 	gen_mem_addressof (reg, decl);
1601       else
1602 	put_reg_into_stack (function, reg, TREE_TYPE (decl),
1603 			    promoted_mode, decl_mode,
1604 			    TREE_SIDE_EFFECTS (decl), 0,
1605 			    TREE_USED (decl) || DECL_INITIAL (decl) != 0,
1606 			    0);
1607     }
1608   else if (GET_CODE (reg) == CONCAT)
1609     {
1610       /* A CONCAT contains two pseudos; put them both in the stack.
1611 	 We do it so they end up consecutive.  */
1612       enum machine_mode part_mode = GET_MODE (XEXP (reg, 0));
1613       tree part_type = TREE_TYPE (TREE_TYPE (decl));
1614 #ifdef FRAME_GROWS_DOWNWARD
1615       /* Since part 0 should have a lower address, do it second.  */
1616       put_reg_into_stack (function, XEXP (reg, 1), part_type, part_mode,
1617 			  part_mode, TREE_SIDE_EFFECTS (decl), 0,
1618 			  TREE_USED (decl) || DECL_INITIAL (decl) != 0,
1619 			  0);
1620       put_reg_into_stack (function, XEXP (reg, 0), part_type, part_mode,
1621 			  part_mode, TREE_SIDE_EFFECTS (decl), 0,
1622 			  TREE_USED (decl) || DECL_INITIAL (decl) != 0,
1623 			  0);
1624 #else
1625       put_reg_into_stack (function, XEXP (reg, 0), part_type, part_mode,
1626 			  part_mode, TREE_SIDE_EFFECTS (decl), 0,
1627 			  TREE_USED (decl) || DECL_INITIAL (decl) != 0,
1628 			  0);
1629       put_reg_into_stack (function, XEXP (reg, 1), part_type, part_mode,
1630 			  part_mode, TREE_SIDE_EFFECTS (decl), 0,
1631 			  TREE_USED (decl) || DECL_INITIAL (decl) != 0,
1632 			  0);
1633 #endif
1634 
1635       /* Change the CONCAT into a combined MEM for both parts.  */
1636       PUT_CODE (reg, MEM);
1637       MEM_VOLATILE_P (reg) = MEM_VOLATILE_P (XEXP (reg, 0));
1638       MEM_ALIAS_SET (reg) = get_alias_set (decl);
1639 
1640       /* The two parts are in memory order already.
1641 	 Use the lower parts address as ours.  */
1642       XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0);
1643       /* Prevent sharing of rtl that might lose.  */
1644       if (GET_CODE (XEXP (reg, 0)) == PLUS)
1645 	XEXP (reg, 0) = copy_rtx (XEXP (reg, 0));
1646     }
1647   else
1648     return;
1649 
1650   if (current_function_check_memory_usage)
1651     emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
1652 		       XEXP (reg, 0), Pmode,
1653 		       GEN_INT (GET_MODE_SIZE (GET_MODE (reg))),
1654 		       TYPE_MODE (sizetype),
1655 		       GEN_INT (MEMORY_USE_RW),
1656 		       TYPE_MODE (integer_type_node));
1657 }
1658 
1659 /* Subroutine of put_var_into_stack.  This puts a single pseudo reg REG
1660    into the stack frame of FUNCTION (0 means the current function).
1661    DECL_MODE is the machine mode of the user-level data type.
1662    PROMOTED_MODE is the machine mode of the register.
1663    VOLATILE_P is nonzero if this is for a "volatile" decl.
1664    USED_P is nonzero if this reg might have already been used in an insn.  */
1665 
1666 static void
1667 put_reg_into_stack (function, reg, type, promoted_mode, decl_mode, volatile_p,
1668 		    original_regno, used_p, ht)
1669      struct function *function;
1670      rtx reg;
1671      tree type;
1672      enum machine_mode promoted_mode, decl_mode;
1673      int volatile_p;
1674      int original_regno;
1675      int used_p;
1676      struct hash_table *ht;
1677 {
1678   rtx new = 0;
1679   int regno = original_regno;
1680 
1681   if (regno == 0)
1682     regno = REGNO (reg);
1683 
1684   if (function)
1685     {
1686       if (regno < function->max_parm_reg)
1687 	new = function->parm_reg_stack_loc[regno];
1688       if (new == 0)
1689 	new = assign_outer_stack_local (decl_mode, GET_MODE_SIZE (decl_mode),
1690 					0, function);
1691     }
1692   else
1693     {
1694       if (regno < max_parm_reg)
1695 	new = parm_reg_stack_loc[regno];
1696       if (new == 0)
1697 	new = assign_stack_local (decl_mode, GET_MODE_SIZE (decl_mode), 0);
1698     }
1699 
1700   PUT_MODE (reg, decl_mode);
1701   XEXP (reg, 0) = XEXP (new, 0);
1702   /* `volatil' bit means one thing for MEMs, another entirely for REGs.  */
1703   MEM_VOLATILE_P (reg) = volatile_p;
1704   PUT_CODE (reg, MEM);
1705 
1706   /* If this is a memory ref that contains aggregate components,
1707      mark it as such for cse and loop optimize.  If we are reusing a
1708      previously generated stack slot, then we need to copy the bit in
1709      case it was set for other reasons.  For instance, it is set for
1710      __builtin_va_alist.  */
1711   MEM_SET_IN_STRUCT_P (reg,
1712 		       AGGREGATE_TYPE_P (type) || MEM_IN_STRUCT_P (new));
1713   MEM_ALIAS_SET (reg) = get_alias_set (type);
1714 
1715   /* Now make sure that all refs to the variable, previously made
1716      when it was a register, are fixed up to be valid again.  */
1717 
1718   if (used_p && function != 0)
1719     {
1720       struct var_refs_queue *temp;
1721 
1722       /* Variable is inherited; fix it up when we get back to its function.  */
1723       push_obstacks (function->function_obstack,
1724 		     function->function_maybepermanent_obstack);
1725 
1726       /* See comment in restore_tree_status in tree.c for why this needs to be
1727 	 on saveable obstack.  */
1728       temp
1729 	= (struct var_refs_queue *) savealloc (sizeof (struct var_refs_queue));
1730       temp->modified = reg;
1731       temp->promoted_mode = promoted_mode;
1732       temp->unsignedp = TREE_UNSIGNED (type);
1733       temp->next = function->fixup_var_refs_queue;
1734       function->fixup_var_refs_queue = temp;
1735       pop_obstacks ();
1736     }
1737   else if (used_p)
1738     /* Variable is local; fix it up now.  */
1739     fixup_var_refs (reg, promoted_mode, TREE_UNSIGNED (type), ht);
1740 }
1741 
1742 static void
1743 fixup_var_refs (var, promoted_mode, unsignedp, ht)
1744      rtx var;
1745      enum machine_mode promoted_mode;
1746      int unsignedp;
1747      struct hash_table *ht;
1748 {
1749   tree pending;
1750   rtx first_insn = get_insns ();
1751   struct sequence_stack *stack = sequence_stack;
1752   tree rtl_exps = rtl_expr_chain;
1753 
1754   /* Must scan all insns for stack-refs that exceed the limit.  */
1755   fixup_var_refs_insns (var, promoted_mode, unsignedp, first_insn,
1756 			stack == 0, ht);
1757   /* If there's a hash table, it must record all uses of VAR.  */
1758   if (ht)
1759     return;
1760 
1761   /* Scan all pending sequences too.  */
1762   for (; stack; stack = stack->next)
1763     {
1764       push_to_sequence (stack->first);
1765       fixup_var_refs_insns (var, promoted_mode, unsignedp,
1766 			    stack->first, stack->next != 0, 0);
1767       /* Update remembered end of sequence
1768 	 in case we added an insn at the end.  */
1769       stack->last = get_last_insn ();
1770       end_sequence ();
1771     }
1772 
1773   /* Scan all waiting RTL_EXPRs too.  */
1774   for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
1775     {
1776       rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
1777       if (seq != const0_rtx && seq != 0)
1778 	{
1779 	  push_to_sequence (seq);
1780 	  fixup_var_refs_insns (var, promoted_mode, unsignedp, seq, 0,
1781 				0);
1782 	  end_sequence ();
1783 	}
1784     }
1785 
1786   /* Scan the catch clauses for exception handling too.  */
1787   push_to_sequence (catch_clauses);
1788   fixup_var_refs_insns (var, promoted_mode, unsignedp, catch_clauses,
1789 			0, 0);
1790   end_sequence ();
1791 }
1792 
1793 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1794    some part of an insn.  Return a struct fixup_replacement whose OLD
1795    value is equal to X.  Allocate a new structure if no such entry exists.  */
1796 
1797 static struct fixup_replacement *
1798 find_fixup_replacement (replacements, x)
1799      struct fixup_replacement **replacements;
1800      rtx x;
1801 {
1802   struct fixup_replacement *p;
1803 
1804   /* See if we have already replaced this.  */
1805   for (p = *replacements; p && p->old != x; p = p->next)
1806     ;
1807 
1808   if (p == 0)
1809     {
1810       p = (struct fixup_replacement *) oballoc (sizeof (struct fixup_replacement));
1811       p->old = x;
1812       p->new = 0;
1813       p->next = *replacements;
1814       *replacements = p;
1815     }
1816 
1817   return p;
1818 }
1819 
1820 /* Scan the insn-chain starting with INSN for refs to VAR
1821    and fix them up.  TOPLEVEL is nonzero if this chain is the
1822    main chain of insns for the current function.  */
1823 
1824 static void
1825 fixup_var_refs_insns (var, promoted_mode, unsignedp, insn, toplevel, ht)
1826      rtx var;
1827      enum machine_mode promoted_mode;
1828      int unsignedp;
1829      rtx insn;
1830      int toplevel;
1831      struct hash_table *ht;
1832 {
1833   rtx call_dest = 0;
1834   rtx insn_list = NULL_RTX;
1835 
1836   /* If we already know which INSNs reference VAR there's no need
1837      to walk the entire instruction chain.  */
1838   if (ht)
1839     {
1840       insn_list = ((struct insns_for_mem_entry *)
1841 		   hash_lookup (ht, var, /*create=*/0, /*copy=*/0))->insns;
1842       insn = insn_list ? XEXP (insn_list, 0) : NULL_RTX;
1843       insn_list = XEXP (insn_list, 1);
1844     }
1845 
1846   while (insn)
1847     {
1848       rtx next = NEXT_INSN (insn);
1849       rtx set, prev, prev_set;
1850       rtx note;
1851 
1852       if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1853 	{
1854 	  /* If this is a CLOBBER of VAR, delete it.
1855 
1856 	     If it has a REG_LIBCALL note, delete the REG_LIBCALL
1857 	     and REG_RETVAL notes too.  */
1858  	  if (GET_CODE (PATTERN (insn)) == CLOBBER
1859 	      && (XEXP (PATTERN (insn), 0) == var
1860 		  || (GET_CODE (XEXP (PATTERN (insn), 0)) == CONCAT
1861 		      && (XEXP (XEXP (PATTERN (insn), 0), 0) == var
1862 			  || XEXP (XEXP (PATTERN (insn), 0), 1) == var))))
1863 	    {
1864 	      if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0)
1865 		/* The REG_LIBCALL note will go away since we are going to
1866 		   turn INSN into a NOTE, so just delete the
1867 		   corresponding REG_RETVAL note.  */
1868 		remove_note (XEXP (note, 0),
1869 			     find_reg_note (XEXP (note, 0), REG_RETVAL,
1870 					    NULL_RTX));
1871 
1872 	      /* In unoptimized compilation, we shouldn't call delete_insn
1873 		 except in jump.c doing warnings.  */
1874 	      PUT_CODE (insn, NOTE);
1875 	      NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1876 	      NOTE_SOURCE_FILE (insn) = 0;
1877 	    }
1878 
1879 	  /* The insn to load VAR from a home in the arglist
1880 	     is now a no-op.  When we see it, just delete it.
1881 	     Similarly if this is storing VAR from a register from which
1882 	     it was loaded in the previous insn.  This will occur
1883 	     when an ADDRESSOF was made for an arglist slot.  */
1884 	  else if (toplevel
1885 		   && (set = single_set (insn)) != 0
1886 		   && SET_DEST (set) == var
1887 		   /* If this represents the result of an insn group,
1888 		      don't delete the insn.  */
1889 		   && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0
1890 		   && (rtx_equal_p (SET_SRC (set), var)
1891 		       || (GET_CODE (SET_SRC (set)) == REG
1892 			   && (prev = prev_nonnote_insn (insn)) != 0
1893 			   && (prev_set = single_set (prev)) != 0
1894 			   && SET_DEST (prev_set) == SET_SRC (set)
1895 			   && rtx_equal_p (SET_SRC (prev_set), var))))
1896 	    {
1897 	      /* In unoptimized compilation, we shouldn't call delete_insn
1898 		 except in jump.c doing warnings.  */
1899 	      PUT_CODE (insn, NOTE);
1900 	      NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1901 	      NOTE_SOURCE_FILE (insn) = 0;
1902 	      if (insn == last_parm_insn)
1903 		last_parm_insn = PREV_INSN (next);
1904 	    }
1905 	  else
1906 	    {
1907 	      struct fixup_replacement *replacements = 0;
1908 	      rtx next_insn = NEXT_INSN (insn);
1909 
1910 	      if (SMALL_REGISTER_CLASSES)
1911 		{
1912 		  /* If the insn that copies the results of a CALL_INSN
1913 		     into a pseudo now references VAR, we have to use an
1914 		     intermediate pseudo since we want the life of the
1915 		     return value register to be only a single insn.
1916 
1917 		     If we don't use an intermediate pseudo, such things as
1918 		     address computations to make the address of VAR valid
1919 		     if it is not can be placed between the CALL_INSN and INSN.
1920 
1921 		     To make sure this doesn't happen, we record the destination
1922 		     of the CALL_INSN and see if the next insn uses both that
1923 		     and VAR.  */
1924 
1925 		  if (call_dest != 0 && GET_CODE (insn) == INSN
1926 		      && reg_mentioned_p (var, PATTERN (insn))
1927 		      && reg_mentioned_p (call_dest, PATTERN (insn)))
1928 		    {
1929 		      rtx temp = gen_reg_rtx (GET_MODE (call_dest));
1930 
1931 		      emit_insn_before (gen_move_insn (temp, call_dest), insn);
1932 
1933 		      PATTERN (insn) = replace_rtx (PATTERN (insn),
1934 						    call_dest, temp);
1935 		    }
1936 
1937 		  if (GET_CODE (insn) == CALL_INSN
1938 		      && GET_CODE (PATTERN (insn)) == SET)
1939 		    call_dest = SET_DEST (PATTERN (insn));
1940 		  else if (GET_CODE (insn) == CALL_INSN
1941 			   && GET_CODE (PATTERN (insn)) == PARALLEL
1942 			   && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
1943 		    call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
1944 		  else
1945 		    call_dest = 0;
1946 		}
1947 
1948 	      /* See if we have to do anything to INSN now that VAR is in
1949 		 memory.  If it needs to be loaded into a pseudo, use a single
1950 		 pseudo for the entire insn in case there is a MATCH_DUP
1951 		 between two operands.  We pass a pointer to the head of
1952 		 a list of struct fixup_replacements.  If fixup_var_refs_1
1953 		 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1954 		 it will record them in this list.
1955 
1956 		 If it allocated a pseudo for any replacement, we copy into
1957 		 it here.  */
1958 
1959 	      fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn,
1960 				&replacements);
1961 
1962 	      /* If this is last_parm_insn, and any instructions were output
1963 		 after it to fix it up, then we must set last_parm_insn to
1964 		 the last such instruction emitted.  */
1965 	      if (insn == last_parm_insn)
1966 		last_parm_insn = PREV_INSN (next_insn);
1967 
1968 	      while (replacements)
1969 		{
1970 		  if (GET_CODE (replacements->new) == REG)
1971 		    {
1972 		      rtx insert_before;
1973 		      rtx seq;
1974 
1975 		      /* OLD might be a (subreg (mem)).  */
1976 		      if (GET_CODE (replacements->old) == SUBREG)
1977 			replacements->old
1978 			  = fixup_memory_subreg (replacements->old, insn, 0);
1979 		      else
1980 			replacements->old
1981 			  = fixup_stack_1 (replacements->old, insn);
1982 
1983 		      insert_before = insn;
1984 
1985 		      /* If we are changing the mode, do a conversion.
1986 			 This might be wasteful, but combine.c will
1987 			 eliminate much of the waste.  */
1988 
1989 		      if (GET_MODE (replacements->new)
1990 			  != GET_MODE (replacements->old))
1991 			{
1992 			  start_sequence ();
1993 			  convert_move (replacements->new,
1994 					replacements->old, unsignedp);
1995 			  seq = gen_sequence ();
1996 			  end_sequence ();
1997 			}
1998 		      else
1999 			seq = gen_move_insn (replacements->new,
2000 					     replacements->old);
2001 
2002 		      emit_insn_before (seq, insert_before);
2003 		    }
2004 
2005 		  replacements = replacements->next;
2006 		}
2007 	    }
2008 
2009 	  /* Also fix up any invalid exprs in the REG_NOTES of this insn.
2010 	     But don't touch other insns referred to by reg-notes;
2011 	     we will get them elsewhere.  */
2012 	  for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2013 	    if (GET_CODE (note) != INSN_LIST)
2014 	      XEXP (note, 0)
2015 		= walk_fixup_memory_subreg (XEXP (note, 0), insn, 1);
2016 	}
2017 
2018       if (!ht)
2019 	insn = next;
2020       else if (insn_list)
2021 	{
2022 	  insn = XEXP (insn_list, 0);
2023 	  insn_list = XEXP (insn_list, 1);
2024 	}
2025       else
2026 	insn = NULL_RTX;
2027     }
2028 }
2029 
2030 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
2031    See if the rtx expression at *LOC in INSN needs to be changed.
2032 
2033    REPLACEMENTS is a pointer to a list head that starts out zero, but may
2034    contain a list of original rtx's and replacements. If we find that we need
2035    to modify this insn by replacing a memory reference with a pseudo or by
2036    making a new MEM to implement a SUBREG, we consult that list to see if
2037    we have already chosen a replacement. If none has already been allocated,
2038    we allocate it and update the list.  fixup_var_refs_insns will copy VAR
2039    or the SUBREG, as appropriate, to the pseudo.  */
2040 
2041 static void
2042 fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements)
2043      register rtx var;
2044      enum machine_mode promoted_mode;
2045      register rtx *loc;
2046      rtx insn;
2047      struct fixup_replacement **replacements;
2048 {
2049   register int i;
2050   register rtx x = *loc;
2051   RTX_CODE code = GET_CODE (x);
2052   register char *fmt;
2053   register rtx tem, tem1;
2054   struct fixup_replacement *replacement;
2055 
2056   switch (code)
2057     {
2058     case ADDRESSOF:
2059       if (XEXP (x, 0) == var)
2060 	{
2061 	  /* Prevent sharing of rtl that might lose.  */
2062 	  rtx sub = copy_rtx (XEXP (var, 0));
2063 
2064 	  if (! validate_change (insn, loc, sub, 0))
2065 	    {
2066 	      rtx y = gen_reg_rtx (GET_MODE (sub));
2067 	      rtx seq, new_insn;
2068 
2069 	      /* We should be able to replace with a register or all is lost.
2070 		 Note that we can't use validate_change to verify this, since
2071 		 we're not caring for replacing all dups simultaneously.  */
2072 	      if (! validate_replace_rtx (*loc, y, insn))
2073 		abort ();
2074 
2075 	      /* Careful!  First try to recognize a direct move of the
2076 		 value, mimicking how things are done in gen_reload wrt
2077 		 PLUS.  Consider what happens when insn is a conditional
2078 		 move instruction and addsi3 clobbers flags.  */
2079 
2080 	      start_sequence ();
2081 	      new_insn = emit_insn (gen_rtx_SET (VOIDmode, y, sub));
2082 	      seq = gen_sequence ();
2083 	      end_sequence ();
2084 
2085 	      if (recog_memoized (new_insn) < 0)
2086 		{
2087 		  /* That failed.  Fall back on force_operand and hope.  */
2088 
2089 		  start_sequence ();
2090 		  force_operand (sub, y);
2091 		  seq = gen_sequence ();
2092 		  end_sequence ();
2093 		}
2094 
2095 #ifdef HAVE_cc0
2096 	      /* Don't separate setter from user.  */
2097 	      if (PREV_INSN (insn) && sets_cc0_p (PREV_INSN (insn)))
2098 		insn = PREV_INSN (insn);
2099 #endif
2100 
2101 	      emit_insn_before (seq, insn);
2102 	    }
2103 	}
2104       return;
2105 
2106     case MEM:
2107       if (var == x)
2108 	{
2109 	  /* If we already have a replacement, use it.  Otherwise,
2110 	     try to fix up this address in case it is invalid.  */
2111 
2112 	  replacement = find_fixup_replacement (replacements, var);
2113 	  if (replacement->new)
2114 	    {
2115 	      *loc = replacement->new;
2116 	      return;
2117 	    }
2118 
2119 	  *loc = replacement->new = x = fixup_stack_1 (x, insn);
2120 
2121 	  /* Unless we are forcing memory to register or we changed the mode,
2122 	     we can leave things the way they are if the insn is valid.  */
2123 
2124 	  INSN_CODE (insn) = -1;
2125 	  if (! flag_force_mem && GET_MODE (x) == promoted_mode
2126 	      && recog_memoized (insn) >= 0)
2127 	    return;
2128 
2129 	  *loc = replacement->new = gen_reg_rtx (promoted_mode);
2130 	  return;
2131 	}
2132 
2133       /* If X contains VAR, we need to unshare it here so that we update
2134 	 each occurrence separately.  But all identical MEMs in one insn
2135 	 must be replaced with the same rtx because of the possibility of
2136 	 MATCH_DUPs.  */
2137 
2138       if (reg_mentioned_p (var, x))
2139 	{
2140 	  replacement = find_fixup_replacement (replacements, x);
2141 	  if (replacement->new == 0)
2142 	    replacement->new = copy_most_rtx (x, var);
2143 
2144 	  *loc = x = replacement->new;
2145 	}
2146       break;
2147 
2148     case REG:
2149     case CC0:
2150     case PC:
2151     case CONST_INT:
2152     case CONST:
2153     case SYMBOL_REF:
2154     case LABEL_REF:
2155     case CONST_DOUBLE:
2156       return;
2157 
2158     case SIGN_EXTRACT:
2159     case ZERO_EXTRACT:
2160       /* Note that in some cases those types of expressions are altered
2161 	 by optimize_bit_field, and do not survive to get here.  */
2162       if (XEXP (x, 0) == var
2163 	  || (GET_CODE (XEXP (x, 0)) == SUBREG
2164 	      && SUBREG_REG (XEXP (x, 0)) == var))
2165 	{
2166 	  /* Get TEM as a valid MEM in the mode presently in the insn.
2167 
2168 	     We don't worry about the possibility of MATCH_DUP here; it
2169 	     is highly unlikely and would be tricky to handle.  */
2170 
2171 	  tem = XEXP (x, 0);
2172 	  if (GET_CODE (tem) == SUBREG)
2173 	    {
2174 	      if (GET_MODE_BITSIZE (GET_MODE (tem))
2175 		  > GET_MODE_BITSIZE (GET_MODE (var)))
2176 		{
2177 		  replacement = find_fixup_replacement (replacements, var);
2178 		  if (replacement->new == 0)
2179 		    replacement->new = gen_reg_rtx (GET_MODE (var));
2180 		  SUBREG_REG (tem) = replacement->new;
2181 		}
2182 	      else
2183 		tem = fixup_memory_subreg (tem, insn, 0);
2184 	    }
2185 	  else
2186 	    tem = fixup_stack_1 (tem, insn);
2187 
2188 	  /* Unless we want to load from memory, get TEM into the proper mode
2189 	     for an extract from memory.  This can only be done if the
2190 	     extract is at a constant position and length.  */
2191 
2192 	  if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
2193 	      && GET_CODE (XEXP (x, 2)) == CONST_INT
2194 	      && ! mode_dependent_address_p (XEXP (tem, 0))
2195 	      && ! MEM_VOLATILE_P (tem))
2196 	    {
2197 	      enum machine_mode wanted_mode = VOIDmode;
2198 	      enum machine_mode is_mode = GET_MODE (tem);
2199 	      HOST_WIDE_INT pos = INTVAL (XEXP (x, 2));
2200 
2201 #ifdef HAVE_extzv
2202 	      if (GET_CODE (x) == ZERO_EXTRACT)
2203 		{
2204 		  wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
2205 		  if (wanted_mode == VOIDmode)
2206 		    wanted_mode = word_mode;
2207 		}
2208 #endif
2209 #ifdef HAVE_extv
2210 	      if (GET_CODE (x) == SIGN_EXTRACT)
2211 		{
2212 		  wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
2213 		  if (wanted_mode == VOIDmode)
2214 		    wanted_mode = word_mode;
2215 		}
2216 #endif
2217 	      /* If we have a narrower mode, we can do something.  */
2218 	      if (wanted_mode != VOIDmode
2219 		  && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
2220 		{
2221 		  HOST_WIDE_INT offset = pos / BITS_PER_UNIT;
2222 		  rtx old_pos = XEXP (x, 2);
2223 		  rtx newmem;
2224 
2225 		  /* If the bytes and bits are counted differently, we
2226 		     must adjust the offset.  */
2227 		  if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
2228 		    offset = (GET_MODE_SIZE (is_mode)
2229 			      - GET_MODE_SIZE (wanted_mode) - offset);
2230 
2231 		  pos %= GET_MODE_BITSIZE (wanted_mode);
2232 
2233 		  newmem = gen_rtx_MEM (wanted_mode,
2234 					plus_constant (XEXP (tem, 0), offset));
2235 		  RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
2236 		  MEM_COPY_ATTRIBUTES (newmem, tem);
2237 
2238 		  /* Make the change and see if the insn remains valid.  */
2239 		  INSN_CODE (insn) = -1;
2240 		  XEXP (x, 0) = newmem;
2241 		  XEXP (x, 2) = GEN_INT (pos);
2242 
2243 		  if (recog_memoized (insn) >= 0)
2244 		    return;
2245 
2246 		  /* Otherwise, restore old position.  XEXP (x, 0) will be
2247 		     restored later.  */
2248 		  XEXP (x, 2) = old_pos;
2249 		}
2250 	    }
2251 
2252 	  /* If we get here, the bitfield extract insn can't accept a memory
2253 	     reference.  Copy the input into a register.  */
2254 
2255 	  tem1 = gen_reg_rtx (GET_MODE (tem));
2256 	  emit_insn_before (gen_move_insn (tem1, tem), insn);
2257 	  XEXP (x, 0) = tem1;
2258 	  return;
2259 	}
2260       break;
2261 
2262     case SUBREG:
2263       if (SUBREG_REG (x) == var)
2264 	{
2265 	  /* If this is a special SUBREG made because VAR was promoted
2266 	     from a wider mode, replace it with VAR and call ourself
2267 	     recursively, this time saying that the object previously
2268 	     had its current mode (by virtue of the SUBREG).  */
2269 
2270 	  if (SUBREG_PROMOTED_VAR_P (x))
2271 	    {
2272 	      *loc = var;
2273 	      fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements);
2274 	      return;
2275 	    }
2276 
2277 	  /* If this SUBREG makes VAR wider, it has become a paradoxical
2278 	     SUBREG with VAR in memory, but these aren't allowed at this
2279 	     stage of the compilation.  So load VAR into a pseudo and take
2280 	     a SUBREG of that pseudo.  */
2281 	  if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
2282 	    {
2283 	      replacement = find_fixup_replacement (replacements, var);
2284 	      if (replacement->new == 0)
2285 		replacement->new = gen_reg_rtx (GET_MODE (var));
2286 	      SUBREG_REG (x) = replacement->new;
2287 	      return;
2288 	    }
2289 
2290 	  /* See if we have already found a replacement for this SUBREG.
2291 	     If so, use it.  Otherwise, make a MEM and see if the insn
2292 	     is recognized.  If not, or if we should force MEM into a register,
2293 	     make a pseudo for this SUBREG.  */
2294 	  replacement = find_fixup_replacement (replacements, x);
2295 	  if (replacement->new)
2296 	    {
2297 	      *loc = replacement->new;
2298 	      return;
2299 	    }
2300 
2301 	  replacement->new = *loc = fixup_memory_subreg (x, insn, 0);
2302 
2303 	  INSN_CODE (insn) = -1;
2304 	  if (! flag_force_mem && recog_memoized (insn) >= 0)
2305 	    return;
2306 
2307 	  *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
2308 	  return;
2309 	}
2310       break;
2311 
2312     case SET:
2313       /* First do special simplification of bit-field references.  */
2314       if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
2315 	  || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
2316 	optimize_bit_field (x, insn, 0);
2317       if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
2318 	  || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
2319 	optimize_bit_field (x, insn, NULL_PTR);
2320 
2321       /* For a paradoxical SUBREG inside a ZERO_EXTRACT, load the object
2322 	 into a register and then store it back out.  */
2323       if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT
2324 	  && GET_CODE (XEXP (SET_DEST (x), 0)) == SUBREG
2325 	  && SUBREG_REG (XEXP (SET_DEST (x), 0)) == var
2326 	  && (GET_MODE_SIZE (GET_MODE (XEXP (SET_DEST (x), 0)))
2327 	      > GET_MODE_SIZE (GET_MODE (var))))
2328 	{
2329 	  replacement = find_fixup_replacement (replacements, var);
2330 	  if (replacement->new == 0)
2331 	    replacement->new = gen_reg_rtx (GET_MODE (var));
2332 
2333 	  SUBREG_REG (XEXP (SET_DEST (x), 0)) = replacement->new;
2334 	  emit_insn_after (gen_move_insn (var, replacement->new), insn);
2335 	}
2336 
2337       /* If SET_DEST is now a paradoxical SUBREG, put the result of this
2338 	 insn into a pseudo and store the low part of the pseudo into VAR.  */
2339       if (GET_CODE (SET_DEST (x)) == SUBREG
2340 	  && SUBREG_REG (SET_DEST (x)) == var
2341 	  && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
2342 	      > GET_MODE_SIZE (GET_MODE (var))))
2343 	{
2344 	  SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
2345 	  emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
2346 							    tem)),
2347 			   insn);
2348 	  break;
2349 	}
2350 
2351       {
2352 	rtx dest = SET_DEST (x);
2353 	rtx src = SET_SRC (x);
2354 #ifdef HAVE_insv
2355 	rtx outerdest = dest;
2356 #endif
2357 
2358 	while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
2359 	       || GET_CODE (dest) == SIGN_EXTRACT
2360 	       || GET_CODE (dest) == ZERO_EXTRACT)
2361 	  dest = XEXP (dest, 0);
2362 
2363 	if (GET_CODE (src) == SUBREG)
2364 	  src = XEXP (src, 0);
2365 
2366 	/* If VAR does not appear at the top level of the SET
2367 	   just scan the lower levels of the tree.  */
2368 
2369         if (src != var && dest != var)
2370 	  break;
2371 
2372 	/* We will need to rerecognize this insn.  */
2373 	INSN_CODE (insn) = -1;
2374 
2375 #ifdef HAVE_insv
2376 	if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var)
2377 	  {
2378 	    /* Since this case will return, ensure we fixup all the
2379 	       operands here.  */
2380 	    fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1),
2381 			      insn, replacements);
2382 	    fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2),
2383 			      insn, replacements);
2384 	    fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x),
2385 			      insn, replacements);
2386 
2387 	    tem = XEXP (outerdest, 0);
2388 
2389 	    /* Clean up (SUBREG:SI (MEM:mode ...) 0)
2390 	       that may appear inside a ZERO_EXTRACT.
2391 	       This was legitimate when the MEM was a REG.  */
2392 	    if (GET_CODE (tem) == SUBREG
2393 		&& SUBREG_REG (tem) == var)
2394 	      tem = fixup_memory_subreg (tem, insn, 0);
2395 	    else
2396 	      tem = fixup_stack_1 (tem, insn);
2397 
2398 	    if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
2399 		&& GET_CODE (XEXP (outerdest, 2)) == CONST_INT
2400 		&& ! mode_dependent_address_p (XEXP (tem, 0))
2401 		&& ! MEM_VOLATILE_P (tem))
2402 	      {
2403 		enum machine_mode wanted_mode;
2404 		enum machine_mode is_mode = GET_MODE (tem);
2405 		HOST_WIDE_INT pos = INTVAL (XEXP (outerdest, 2));
2406 
2407 		wanted_mode = insn_operand_mode[(int) CODE_FOR_insv][0];
2408 		if (wanted_mode == VOIDmode)
2409 		  wanted_mode = word_mode;
2410 
2411 		/* If we have a narrower mode, we can do something.  */
2412 		if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
2413 		  {
2414 		    HOST_WIDE_INT offset = pos / BITS_PER_UNIT;
2415 		    rtx old_pos = XEXP (outerdest, 2);
2416 		    rtx newmem;
2417 
2418 		    if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
2419 		      offset = (GET_MODE_SIZE (is_mode)
2420 				- GET_MODE_SIZE (wanted_mode) - offset);
2421 
2422 		    pos %= GET_MODE_BITSIZE (wanted_mode);
2423 
2424 		    newmem = gen_rtx_MEM (wanted_mode,
2425 					  plus_constant (XEXP (tem, 0), offset));
2426 		    RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
2427 		    MEM_COPY_ATTRIBUTES (newmem, tem);
2428 
2429 		    /* Make the change and see if the insn remains valid.  */
2430 		    INSN_CODE (insn) = -1;
2431 		    XEXP (outerdest, 0) = newmem;
2432 		    XEXP (outerdest, 2) = GEN_INT (pos);
2433 
2434 		    if (recog_memoized (insn) >= 0)
2435 		      return;
2436 
2437 		    /* Otherwise, restore old position.  XEXP (x, 0) will be
2438 		       restored later.  */
2439 		    XEXP (outerdest, 2) = old_pos;
2440 		  }
2441 	      }
2442 
2443 	    /* If we get here, the bit-field store doesn't allow memory
2444 	       or isn't located at a constant position.  Load the value into
2445 	       a register, do the store, and put it back into memory.  */
2446 
2447 	    tem1 = gen_reg_rtx (GET_MODE (tem));
2448 	    emit_insn_before (gen_move_insn (tem1, tem), insn);
2449 	    emit_insn_after (gen_move_insn (tem, tem1), insn);
2450 	    XEXP (outerdest, 0) = tem1;
2451 	    return;
2452 	  }
2453 #endif
2454 
2455 	/* STRICT_LOW_PART is a no-op on memory references
2456 	   and it can cause combinations to be unrecognizable,
2457 	   so eliminate it.  */
2458 
2459 	if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
2460 	  SET_DEST (x) = XEXP (SET_DEST (x), 0);
2461 
2462 	/* A valid insn to copy VAR into or out of a register
2463 	   must be left alone, to avoid an infinite loop here.
2464 	   If the reference to VAR is by a subreg, fix that up,
2465 	   since SUBREG is not valid for a memref.
2466 	   Also fix up the address of the stack slot.
2467 
2468 	   Note that we must not try to recognize the insn until
2469 	   after we know that we have valid addresses and no
2470 	   (subreg (mem ...) ...) constructs, since these interfere
2471 	   with determining the validity of the insn.  */
2472 
2473 	if ((SET_SRC (x) == var
2474 	     || (GET_CODE (SET_SRC (x)) == SUBREG
2475 		 && SUBREG_REG (SET_SRC (x)) == var))
2476 	    && (GET_CODE (SET_DEST (x)) == REG
2477 		|| (GET_CODE (SET_DEST (x)) == SUBREG
2478 		    && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
2479 	    && GET_MODE (var) == promoted_mode
2480 	    && x == single_set (insn))
2481 	  {
2482 	    rtx pat;
2483 
2484 	    replacement = find_fixup_replacement (replacements, SET_SRC (x));
2485 	    if (replacement->new)
2486 	      SET_SRC (x) = replacement->new;
2487 	    else if (GET_CODE (SET_SRC (x)) == SUBREG)
2488 	      SET_SRC (x) = replacement->new
2489 		= fixup_memory_subreg (SET_SRC (x), insn, 0);
2490 	    else
2491 	      SET_SRC (x) = replacement->new
2492 		= fixup_stack_1 (SET_SRC (x), insn);
2493 
2494 	    if (recog_memoized (insn) >= 0)
2495 	      return;
2496 
2497 	    /* INSN is not valid, but we know that we want to
2498 	       copy SET_SRC (x) to SET_DEST (x) in some way.  So
2499 	       we generate the move and see whether it requires more
2500 	       than one insn.  If it does, we emit those insns and
2501 	       delete INSN.  Otherwise, we an just replace the pattern
2502 	       of INSN; we have already verified above that INSN has
2503 	       no other function that to do X.  */
2504 
2505 	    pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2506 	    if (GET_CODE (pat) == SEQUENCE)
2507 	      {
2508 		emit_insn_after (pat, insn);
2509 		PUT_CODE (insn, NOTE);
2510 		NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2511 		NOTE_SOURCE_FILE (insn) = 0;
2512 	      }
2513 	    else
2514 	      PATTERN (insn) = pat;
2515 
2516 	    return;
2517 	  }
2518 
2519 	if ((SET_DEST (x) == var
2520 	     || (GET_CODE (SET_DEST (x)) == SUBREG
2521 		 && SUBREG_REG (SET_DEST (x)) == var))
2522 	    && (GET_CODE (SET_SRC (x)) == REG
2523 		|| (GET_CODE (SET_SRC (x)) == SUBREG
2524 		    && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
2525 	    && GET_MODE (var) == promoted_mode
2526 	    && x == single_set (insn))
2527 	  {
2528 	    rtx pat;
2529 
2530 	    if (GET_CODE (SET_DEST (x)) == SUBREG)
2531 	      SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn, 0);
2532 	    else
2533 	      SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
2534 
2535 	    if (recog_memoized (insn) >= 0)
2536 	      return;
2537 
2538 	    pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2539 	    if (GET_CODE (pat) == SEQUENCE)
2540 	      {
2541 		emit_insn_after (pat, insn);
2542 		PUT_CODE (insn, NOTE);
2543 		NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2544 		NOTE_SOURCE_FILE (insn) = 0;
2545 	      }
2546 	    else
2547 	      PATTERN (insn) = pat;
2548 
2549 	    return;
2550 	  }
2551 
2552 	/* Otherwise, storing into VAR must be handled specially
2553 	   by storing into a temporary and copying that into VAR
2554 	   with a new insn after this one.  Note that this case
2555 	   will be used when storing into a promoted scalar since
2556 	   the insn will now have different modes on the input
2557 	   and output and hence will be invalid (except for the case
2558 	   of setting it to a constant, which does not need any
2559 	   change if it is valid).  We generate extra code in that case,
2560 	   but combine.c will eliminate it.  */
2561 
2562 	if (dest == var)
2563 	  {
2564 	    rtx temp;
2565 	    rtx fixeddest = SET_DEST (x);
2566 
2567 	    /* STRICT_LOW_PART can be discarded, around a MEM.  */
2568 	    if (GET_CODE (fixeddest) == STRICT_LOW_PART)
2569 	      fixeddest = XEXP (fixeddest, 0);
2570 	    /* Convert (SUBREG (MEM)) to a MEM in a changed mode.  */
2571 	    if (GET_CODE (fixeddest) == SUBREG)
2572 	      {
2573 		fixeddest = fixup_memory_subreg (fixeddest, insn, 0);
2574 		promoted_mode = GET_MODE (fixeddest);
2575 	      }
2576 	    else
2577 	      fixeddest = fixup_stack_1 (fixeddest, insn);
2578 
2579 	    temp = gen_reg_rtx (promoted_mode);
2580 
2581 	    emit_insn_after (gen_move_insn (fixeddest,
2582 					    gen_lowpart (GET_MODE (fixeddest),
2583 							 temp)),
2584 			     insn);
2585 
2586 	    SET_DEST (x) = temp;
2587 	  }
2588       }
2589 
2590     default:
2591       break;
2592     }
2593 
2594   /* Nothing special about this RTX; fix its operands.  */
2595 
2596   fmt = GET_RTX_FORMAT (code);
2597   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2598     {
2599       if (fmt[i] == 'e')
2600 	fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements);
2601       if (fmt[i] == 'E')
2602 	{
2603 	  register int j;
2604 	  for (j = 0; j < XVECLEN (x, i); j++)
2605 	    fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j),
2606 			      insn, replacements);
2607 	}
2608     }
2609 }
2610 
2611 /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
2612    return an rtx (MEM:m1 newaddr) which is equivalent.
2613    If any insns must be emitted to compute NEWADDR, put them before INSN.
2614 
2615    UNCRITICAL nonzero means accept paradoxical subregs.
2616    This is used for subregs found inside REG_NOTES.  */
2617 
2618 static rtx
2619 fixup_memory_subreg (x, insn, uncritical)
2620      rtx x;
2621      rtx insn;
2622      int uncritical;
2623 {
2624   int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
2625   rtx addr = XEXP (SUBREG_REG (x), 0);
2626   enum machine_mode mode = GET_MODE (x);
2627   rtx result;
2628 
2629   /* Paradoxical SUBREGs are usually invalid during RTL generation.  */
2630   if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
2631       && ! uncritical)
2632     abort ();
2633 
2634   if (BYTES_BIG_ENDIAN)
2635     offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
2636 	       - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
2637   addr = plus_constant (addr, offset);
2638   if (!flag_force_addr && memory_address_p (mode, addr))
2639     /* Shortcut if no insns need be emitted.  */
2640     return change_address (SUBREG_REG (x), mode, addr);
2641   start_sequence ();
2642   result = change_address (SUBREG_REG (x), mode, addr);
2643   emit_insn_before (gen_sequence (), insn);
2644   end_sequence ();
2645   return result;
2646 }
2647 
2648 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2649    Replace subexpressions of X in place.
2650    If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2651    Otherwise return X, with its contents possibly altered.
2652 
2653    If any insns must be emitted to compute NEWADDR, put them before INSN.
2654 
2655    UNCRITICAL is as in fixup_memory_subreg.  */
2656 
2657 static rtx
2658 walk_fixup_memory_subreg (x, insn, uncritical)
2659      register rtx x;
2660      rtx insn;
2661      int uncritical;
2662 {
2663   register enum rtx_code code;
2664   register char *fmt;
2665   register int i;
2666 
2667   if (x == 0)
2668     return 0;
2669 
2670   code = GET_CODE (x);
2671 
2672   if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
2673     return fixup_memory_subreg (x, insn, uncritical);
2674 
2675   /* Nothing special about this RTX; fix its operands.  */
2676 
2677   fmt = GET_RTX_FORMAT (code);
2678   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2679     {
2680       if (fmt[i] == 'e')
2681 	XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn, uncritical);
2682       if (fmt[i] == 'E')
2683 	{
2684 	  register int j;
2685 	  for (j = 0; j < XVECLEN (x, i); j++)
2686 	    XVECEXP (x, i, j)
2687 	      = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn, uncritical);
2688 	}
2689     }
2690   return x;
2691 }
2692 
2693 /* For each memory ref within X, if it refers to a stack slot
2694    with an out of range displacement, put the address in a temp register
2695    (emitting new insns before INSN to load these registers)
2696    and alter the memory ref to use that register.
2697    Replace each such MEM rtx with a copy, to avoid clobberage.  */
2698 
2699 static rtx
2700 fixup_stack_1 (x, insn)
2701      rtx x;
2702      rtx insn;
2703 {
2704   register int i;
2705   register RTX_CODE code = GET_CODE (x);
2706   register char *fmt;
2707 
2708   if (code == MEM)
2709     {
2710       register rtx ad = XEXP (x, 0);
2711       /* If we have address of a stack slot but it's not valid
2712 	 (displacement is too large), compute the sum in a register.  */
2713       if (GET_CODE (ad) == PLUS
2714 	  && GET_CODE (XEXP (ad, 0)) == REG
2715 	  && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
2716 	       && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER)
2717 	      || REGNO (XEXP (ad, 0)) == FRAME_POINTER_REGNUM
2718 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2719 	      || REGNO (XEXP (ad, 0)) == HARD_FRAME_POINTER_REGNUM
2720 #endif
2721 	      || REGNO (XEXP (ad, 0)) == STACK_POINTER_REGNUM
2722 	      || REGNO (XEXP (ad, 0)) == ARG_POINTER_REGNUM
2723 	      || XEXP (ad, 0) == current_function_internal_arg_pointer)
2724 	  && GET_CODE (XEXP (ad, 1)) == CONST_INT)
2725 	{
2726 	  rtx temp, seq;
2727 	  if (memory_address_p (GET_MODE (x), ad))
2728 	    return x;
2729 
2730 	  start_sequence ();
2731 	  temp = copy_to_reg (ad);
2732 	  seq = gen_sequence ();
2733 	  end_sequence ();
2734 	  emit_insn_before (seq, insn);
2735 	  return change_address (x, VOIDmode, temp);
2736 	}
2737       return x;
2738     }
2739 
2740   fmt = GET_RTX_FORMAT (code);
2741   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2742     {
2743       if (fmt[i] == 'e')
2744 	XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
2745       if (fmt[i] == 'E')
2746 	{
2747 	  register int j;
2748 	  for (j = 0; j < XVECLEN (x, i); j++)
2749 	    XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
2750 	}
2751     }
2752   return x;
2753 }
2754 
2755 /* Optimization: a bit-field instruction whose field
2756    happens to be a byte or halfword in memory
2757    can be changed to a move instruction.
2758 
2759    We call here when INSN is an insn to examine or store into a bit-field.
2760    BODY is the SET-rtx to be altered.
2761 
2762    EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2763    (Currently this is called only from function.c, and EQUIV_MEM
2764    is always 0.)  */
2765 
2766 static void
2767 optimize_bit_field (body, insn, equiv_mem)
2768      rtx body;
2769      rtx insn;
2770      rtx *equiv_mem;
2771 {
2772   register rtx bitfield;
2773   int destflag;
2774   rtx seq = 0;
2775   enum machine_mode mode;
2776 
2777   if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
2778       || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
2779     bitfield = SET_DEST (body), destflag = 1;
2780   else
2781     bitfield = SET_SRC (body), destflag = 0;
2782 
2783   /* First check that the field being stored has constant size and position
2784      and is in fact a byte or halfword suitably aligned.  */
2785 
2786   if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
2787       && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
2788       && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
2789 	  != BLKmode)
2790       && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
2791     {
2792       register rtx memref = 0;
2793 
2794       /* Now check that the containing word is memory, not a register,
2795 	 and that it is safe to change the machine mode.  */
2796 
2797       if (GET_CODE (XEXP (bitfield, 0)) == MEM)
2798 	memref = XEXP (bitfield, 0);
2799       else if (GET_CODE (XEXP (bitfield, 0)) == REG
2800 	       && equiv_mem != 0)
2801 	memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
2802       else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2803 	       && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
2804 	memref = SUBREG_REG (XEXP (bitfield, 0));
2805       else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2806 	       && equiv_mem != 0
2807 	       && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
2808 	memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
2809 
2810       if (memref
2811 	  && ! mode_dependent_address_p (XEXP (memref, 0))
2812 	  && ! MEM_VOLATILE_P (memref))
2813 	{
2814 	  /* Now adjust the address, first for any subreg'ing
2815 	     that we are now getting rid of,
2816 	     and then for which byte of the word is wanted.  */
2817 
2818 	  HOST_WIDE_INT offset = INTVAL (XEXP (bitfield, 2));
2819 	  rtx insns;
2820 
2821 	  /* Adjust OFFSET to count bits from low-address byte.  */
2822 	  if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN)
2823 	    offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
2824 		      - offset - INTVAL (XEXP (bitfield, 1)));
2825 
2826 	  /* Adjust OFFSET to count bytes from low-address byte.  */
2827 	  offset /= BITS_PER_UNIT;
2828 	  if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
2829 	    {
2830 	      offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD;
2831 	      if (BYTES_BIG_ENDIAN)
2832 		offset -= (MIN (UNITS_PER_WORD,
2833 				GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
2834 			   - MIN (UNITS_PER_WORD,
2835 				  GET_MODE_SIZE (GET_MODE (memref))));
2836 	    }
2837 
2838 	  start_sequence ();
2839 	  memref = change_address (memref, mode,
2840 				   plus_constant (XEXP (memref, 0), offset));
2841 	  insns = get_insns ();
2842 	  end_sequence ();
2843 	  emit_insns_before (insns, insn);
2844 
2845 	  /* Store this memory reference where
2846 	     we found the bit field reference.  */
2847 
2848 	  if (destflag)
2849 	    {
2850 	      validate_change (insn, &SET_DEST (body), memref, 1);
2851 	      if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
2852 		{
2853 		  rtx src = SET_SRC (body);
2854 		  while (GET_CODE (src) == SUBREG
2855 			 && SUBREG_WORD (src) == 0)
2856 		    src = SUBREG_REG (src);
2857 		  if (GET_MODE (src) != GET_MODE (memref))
2858 		    src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
2859 		  validate_change (insn, &SET_SRC (body), src, 1);
2860 		}
2861 	      else if (GET_MODE (SET_SRC (body)) != VOIDmode
2862 		       && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
2863 		/* This shouldn't happen because anything that didn't have
2864 		   one of these modes should have got converted explicitly
2865 		   and then referenced through a subreg.
2866 		   This is so because the original bit-field was
2867 		   handled by agg_mode and so its tree structure had
2868 		   the same mode that memref now has.  */
2869 		abort ();
2870 	    }
2871 	  else
2872 	    {
2873 	      rtx dest = SET_DEST (body);
2874 
2875 	      while (GET_CODE (dest) == SUBREG
2876 		     && SUBREG_WORD (dest) == 0
2877 		     && (GET_MODE_CLASS (GET_MODE (dest))
2878 			 == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest))))
2879 		     && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
2880 			 <= UNITS_PER_WORD))
2881 		dest = SUBREG_REG (dest);
2882 
2883 	      validate_change (insn, &SET_DEST (body), dest, 1);
2884 
2885 	      if (GET_MODE (dest) == GET_MODE (memref))
2886 		validate_change (insn, &SET_SRC (body), memref, 1);
2887 	      else
2888 		{
2889 		  /* Convert the mem ref to the destination mode.  */
2890 		  rtx newreg = gen_reg_rtx (GET_MODE (dest));
2891 
2892 		  start_sequence ();
2893 		  convert_move (newreg, memref,
2894 				GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
2895 		  seq = get_insns ();
2896 		  end_sequence ();
2897 
2898 		  validate_change (insn, &SET_SRC (body), newreg, 1);
2899 		}
2900 	    }
2901 
2902 	  /* See if we can convert this extraction or insertion into
2903 	     a simple move insn.  We might not be able to do so if this
2904 	     was, for example, part of a PARALLEL.
2905 
2906 	     If we succeed, write out any needed conversions.  If we fail,
2907 	     it is hard to guess why we failed, so don't do anything
2908 	     special; just let the optimization be suppressed.  */
2909 
2910 	  if (apply_change_group () && seq)
2911 	    emit_insns_before (seq, insn);
2912 	}
2913     }
2914 }
2915 
2916 /* These routines are responsible for converting virtual register references
2917    to the actual hard register references once RTL generation is complete.
2918 
2919    The following four variables are used for communication between the
2920    routines.  They contain the offsets of the virtual registers from their
2921    respective hard registers.  */
2922 
2923 static int in_arg_offset;
2924 static int var_offset;
2925 static int dynamic_offset;
2926 static int out_arg_offset;
2927 static int cfa_offset;
2928 
2929 /* In most machines, the stack pointer register is equivalent to the bottom
2930    of the stack.  */
2931 
2932 #ifndef STACK_POINTER_OFFSET
2933 #define STACK_POINTER_OFFSET	0
2934 #endif
2935 
2936 /* If not defined, pick an appropriate default for the offset of dynamically
2937    allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2938    REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE.  */
2939 
2940 #ifndef STACK_DYNAMIC_OFFSET
2941 
2942 #ifdef ACCUMULATE_OUTGOING_ARGS
2943 /* The bottom of the stack points to the actual arguments.  If
2944    REG_PARM_STACK_SPACE is defined, this includes the space for the register
2945    parameters.  However, if OUTGOING_REG_PARM_STACK space is not defined,
2946    stack space for register parameters is not pushed by the caller, but
2947    rather part of the fixed stack areas and hence not included in
2948    `current_function_outgoing_args_size'.  Nevertheless, we must allow
2949    for it when allocating stack dynamic objects.  */
2950 
2951 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2952 #define STACK_DYNAMIC_OFFSET(FNDECL)	\
2953 (current_function_outgoing_args_size	\
2954  + REG_PARM_STACK_SPACE (FNDECL) + (STACK_POINTER_OFFSET))
2955 
2956 #else
2957 #define STACK_DYNAMIC_OFFSET(FNDECL)	\
2958 (current_function_outgoing_args_size + (STACK_POINTER_OFFSET))
2959 #endif
2960 
2961 #else
2962 #define STACK_DYNAMIC_OFFSET(FNDECL) STACK_POINTER_OFFSET
2963 #endif
2964 #endif
2965 
2966 /* On a few machines, the CFA coincides with the arg pointer.  */
2967 
2968 #ifndef ARG_POINTER_CFA_OFFSET
2969 #define ARG_POINTER_CFA_OFFSET 0
2970 #endif
2971 
2972 
2973 /* Build up a (MEM (ADDRESSOF (REG))) rtx for a register REG that just had
2974    its address taken.  DECL is the decl for the object stored in the
2975    register, for later use if we do need to force REG into the stack.
2976    REG is overwritten by the MEM like in put_reg_into_stack.  */
2977 
2978 rtx
2979 gen_mem_addressof (reg, decl)
2980      rtx reg;
2981      tree decl;
2982 {
2983   tree type = TREE_TYPE (decl);
2984   rtx r = gen_rtx_ADDRESSOF (Pmode, gen_reg_rtx (GET_MODE (reg)), REGNO (reg));
2985   SET_ADDRESSOF_DECL (r, decl);
2986   /* If the original REG was a user-variable, then so is the REG whose
2987      address is being taken.  */
2988   REG_USERVAR_P (XEXP (r, 0)) = REG_USERVAR_P (reg);
2989 
2990   XEXP (reg, 0) = r;
2991   PUT_CODE (reg, MEM);
2992   PUT_MODE (reg, DECL_MODE (decl));
2993   MEM_VOLATILE_P (reg) = TREE_SIDE_EFFECTS (decl);
2994   MEM_SET_IN_STRUCT_P (reg, AGGREGATE_TYPE_P (type));
2995   MEM_ALIAS_SET (reg) = get_alias_set (decl);
2996 
2997   if (TREE_USED (decl) || DECL_INITIAL (decl) != 0)
2998     fixup_var_refs (reg, GET_MODE (reg), TREE_UNSIGNED (type), 0);
2999 
3000   return reg;
3001 }
3002 
3003 /* If DECL has an RTL that is an ADDRESSOF rtx, put it into the stack.  */
3004 
3005 void
3006 flush_addressof (decl)
3007      tree decl;
3008 {
3009   if ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == VAR_DECL)
3010       && DECL_RTL (decl) != 0
3011       && GET_CODE (DECL_RTL (decl)) == MEM
3012       && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF
3013       && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 0)) == REG)
3014     put_addressof_into_stack (XEXP (DECL_RTL (decl), 0), 0);
3015 }
3016 
3017 /* Force the register pointed to by R, an ADDRESSOF rtx, into the stack.  */
3018 
3019 static void
3020 put_addressof_into_stack (r, ht)
3021      rtx r;
3022      struct hash_table *ht;
3023 {
3024   tree decl = ADDRESSOF_DECL (r);
3025   rtx reg = XEXP (r, 0);
3026 
3027   if (GET_CODE (reg) != REG)
3028     abort ();
3029 
3030   put_reg_into_stack (0, reg, TREE_TYPE (decl), GET_MODE (reg),
3031 		      DECL_MODE (decl), TREE_SIDE_EFFECTS (decl),
3032 		      ADDRESSOF_REGNO (r),
3033 		      TREE_USED (decl) || DECL_INITIAL (decl) != 0, ht);
3034 }
3035 
3036 /* List of replacements made below in purge_addressof_1 when creating
3037    bitfield insertions.  */
3038 static rtx purge_bitfield_addressof_replacements;
3039 
3040 /* List of replacements made below in purge_addressof_1 for patterns
3041    (MEM (ADDRESSOF (REG ...))).  The key of the list entry is the
3042    corresponding (ADDRESSOF (REG ...)) and value is a substitution for
3043    the all pattern.  List PURGE_BITFIELD_ADDRESSOF_REPLACEMENTS is not
3044    enough in complex cases, e.g. when some field values can be
3045    extracted by usage MEM with narrower mode. */
3046 static rtx purge_addressof_replacements;
3047 
3048 /* Helper function for purge_addressof.  See if the rtx expression at *LOC
3049    in INSN needs to be changed.  If FORCE, always put any ADDRESSOFs into
3050    the stack.  */
3051 
3052 static void
3053 purge_addressof_1 (loc, insn, force, store, ht)
3054      rtx *loc;
3055      rtx insn;
3056      int force, store;
3057      struct hash_table *ht;
3058 {
3059   rtx x;
3060   RTX_CODE code;
3061   int i, j;
3062   char *fmt;
3063 
3064   /* Re-start here to avoid recursion in common cases.  */
3065  restart:
3066 
3067   x = *loc;
3068   if (x == 0)
3069     return;
3070 
3071   code = GET_CODE (x);
3072 
3073   if (code == ADDRESSOF && GET_CODE (XEXP (x, 0)) == MEM)
3074     {
3075       rtx insns;
3076       /* We must create a copy of the rtx because it was created by
3077 	 overwriting a REG rtx which is always shared.  */
3078       rtx sub = copy_rtx (XEXP (XEXP (x, 0), 0));
3079 
3080       if (validate_change (insn, loc, sub, 0)
3081 	  || validate_replace_rtx (x, sub, insn))
3082 	return;
3083 
3084       start_sequence ();
3085       sub = force_operand (sub, NULL_RTX);
3086       if (! validate_change (insn, loc, sub, 0)
3087 	  && ! validate_replace_rtx (x, sub, insn))
3088 	abort ();
3089 
3090       insns = gen_sequence ();
3091       end_sequence ();
3092       emit_insn_before (insns, insn);
3093       return;
3094     }
3095   else if (code == MEM && GET_CODE (XEXP (x, 0)) == ADDRESSOF && ! force)
3096     {
3097       rtx sub = XEXP (XEXP (x, 0), 0);
3098       rtx sub2;
3099 
3100       if (GET_CODE (sub) == MEM)
3101 	{
3102 	  sub2 = gen_rtx_MEM (GET_MODE (x), copy_rtx (XEXP (sub, 0)));
3103 	  MEM_COPY_ATTRIBUTES (sub2, sub);
3104 	  RTX_UNCHANGING_P (sub2) = RTX_UNCHANGING_P (sub);
3105 	  sub = sub2;
3106 	}
3107 
3108       if (GET_CODE (sub) == REG
3109 	  && (MEM_VOLATILE_P (x) || GET_MODE (x) == BLKmode))
3110 	{
3111 	  put_addressof_into_stack (XEXP (x, 0), ht);
3112 	  return;
3113 	}
3114       else if (GET_CODE (sub) == REG && GET_MODE (x) != GET_MODE (sub))
3115 	{
3116 	  int size_x, size_sub;
3117 
3118 	  if (!insn)
3119 	    {
3120 	      /* When processing REG_NOTES look at the list of
3121 		 replacements done on the insn to find the register that X
3122 		 was replaced by.  */
3123 	      rtx tem;
3124 
3125 	      for (tem = purge_bitfield_addressof_replacements;
3126 		   tem != NULL_RTX;
3127 		   tem = XEXP (XEXP (tem, 1), 1))
3128 		if (rtx_equal_p (x, XEXP (tem, 0)))
3129 		  {
3130 		    *loc = XEXP (XEXP (tem, 1), 0);
3131 		    return;
3132 		  }
3133 
3134 	      /* See comment for purge_addressof_replacements. */
3135 	      for (tem = purge_addressof_replacements;
3136 		   tem != NULL_RTX;
3137 		   tem = XEXP (XEXP (tem, 1), 1))
3138 		if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0)))
3139 		  {
3140 		    rtx z = XEXP (XEXP (tem, 1), 0);
3141 
3142 		    if (GET_MODE (x) == GET_MODE (z)
3143 			|| (GET_CODE (XEXP (XEXP (tem, 1), 0)) != REG
3144 			    && GET_CODE (XEXP (XEXP (tem, 1), 0)) != SUBREG))
3145 		      abort ();
3146 
3147 		    /* It can happen that the note may speak of things
3148 		       in a wider (or just different) mode than the
3149 		       code did.  This is especially true of
3150 		       REG_RETVAL. */
3151 
3152 		    if (GET_CODE (z) == SUBREG && SUBREG_WORD (z) == 0)
3153 		      z = SUBREG_REG (z);
3154 
3155 		    if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD
3156 			&& (GET_MODE_SIZE (GET_MODE (x))
3157 			    > GET_MODE_SIZE (GET_MODE (z))))
3158 		      {
3159 			/* This can occur as a result in invalid
3160 			   pointer casts, e.g. float f; ...
3161 			   *(long long int *)&f.
3162 			   ??? We could emit a warning here, but
3163 			   without a line number that wouldn't be
3164 			   very helpful.  */
3165 			z = gen_rtx_SUBREG (GET_MODE (x), z, 0);
3166 		      }
3167 		    else
3168 		      z = gen_lowpart (GET_MODE (x), z);
3169 
3170 		    *loc = z;
3171 		    return;
3172 		  }
3173 
3174 	      /* There should always be such a replacement.  */
3175 	      abort ();
3176 	    }
3177 
3178 	  size_x = GET_MODE_BITSIZE (GET_MODE (x));
3179 	  size_sub = GET_MODE_BITSIZE (GET_MODE (sub));
3180 
3181 	  /* Don't even consider working with paradoxical subregs,
3182 	     or the moral equivalent seen here.  */
3183 	  if (size_x <= size_sub
3184 	      && int_mode_for_mode (GET_MODE (sub)) != BLKmode)
3185 	    {
3186 	      /* Do a bitfield insertion to mirror what would happen
3187 		 in memory.  */
3188 
3189 	      rtx val, seq;
3190 
3191 	      if (store)
3192 		{
3193 		  rtx p = PREV_INSN (insn);
3194 
3195 		  start_sequence ();
3196 		  val = gen_reg_rtx (GET_MODE (x));
3197 		  if (! validate_change (insn, loc, val, 0))
3198 		    {
3199 		      /* Discard the current sequence and put the
3200 			 ADDRESSOF on stack.  */
3201 		      end_sequence ();
3202 		      goto give_up;
3203 		    }
3204 		  seq = gen_sequence ();
3205 		  end_sequence ();
3206 		  emit_insn_before (seq, insn);
3207 		  compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (),
3208 					 insn, ht);
3209 
3210 		  start_sequence ();
3211 		  store_bit_field (sub, size_x, 0, GET_MODE (x),
3212 				   val, GET_MODE_SIZE (GET_MODE (sub)),
3213 				   GET_MODE_SIZE (GET_MODE (sub)));
3214 
3215 		  /* Make sure to unshare any shared rtl that store_bit_field
3216 		     might have created.  */
3217 		  for (p = get_insns(); p; p = NEXT_INSN (p))
3218 		    {
3219 		      reset_used_flags (PATTERN (p));
3220 		      reset_used_flags (REG_NOTES (p));
3221 		      reset_used_flags (LOG_LINKS (p));
3222 		    }
3223 		  unshare_all_rtl (get_insns ());
3224 
3225 		  seq = gen_sequence ();
3226 		  end_sequence ();
3227 		  p = emit_insn_after (seq, insn);
3228 		  if (NEXT_INSN (insn))
3229 		    compute_insns_for_mem (NEXT_INSN (insn),
3230 					   p ? NEXT_INSN (p) : NULL_RTX,
3231 					   ht);
3232 		}
3233 	      else
3234 		{
3235 		  rtx p = PREV_INSN (insn);
3236 
3237 		  start_sequence ();
3238 		  val = extract_bit_field (sub, size_x, 0, 1, NULL_RTX,
3239 					   GET_MODE (x), GET_MODE (x),
3240 					   GET_MODE_SIZE (GET_MODE (sub)),
3241 					   GET_MODE_SIZE (GET_MODE (sub)));
3242 
3243 		  if (! validate_change (insn, loc, val, 0))
3244 		    {
3245 		      /* Discard the current sequence and put the
3246 			 ADDRESSOF on stack.  */
3247 		      end_sequence ();
3248 		      goto give_up;
3249 		    }
3250 
3251 		  seq = gen_sequence ();
3252 		  end_sequence ();
3253 		  emit_insn_before (seq, insn);
3254 		  compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (),
3255 					 insn, ht);
3256 		}
3257 
3258 	      /* Remember the replacement so that the same one can be done
3259 		 on the REG_NOTES.  */
3260 	      purge_bitfield_addressof_replacements
3261 		= gen_rtx_EXPR_LIST (VOIDmode, x,
3262 				     gen_rtx_EXPR_LIST
3263 				     (VOIDmode, val,
3264 				      purge_bitfield_addressof_replacements));
3265 
3266 	      /* We replaced with a reg -- all done.  */
3267 	      return;
3268 	    }
3269 	}
3270       else if (validate_change (insn, loc, sub, 0))
3271 	{
3272 	  /* Remember the replacement so that the same one can be done
3273 	     on the REG_NOTES.  */
3274 	  if (GET_CODE (sub) == REG || GET_CODE (sub) == SUBREG)
3275 	    {
3276 	      rtx tem;
3277 
3278 	      for (tem = purge_addressof_replacements;
3279 		   tem != NULL_RTX;
3280 		   tem = XEXP (XEXP (tem, 1), 1))
3281 		if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0)))
3282 		  {
3283 		    XEXP (XEXP (tem, 1), 0) = sub;
3284 		    return;
3285 		  }
3286 	      purge_addressof_replacements
3287 		= gen_rtx (EXPR_LIST, VOIDmode, XEXP (x, 0),
3288 			   gen_rtx_EXPR_LIST (VOIDmode, sub,
3289 					      purge_addressof_replacements));
3290 	      return;
3291 	    }
3292 	  goto restart;
3293 	}
3294     give_up:;
3295       /* else give up and put it into the stack */
3296     }
3297   else if (code == ADDRESSOF)
3298     {
3299       put_addressof_into_stack (x, ht);
3300       return;
3301     }
3302   else if (code == SET)
3303     {
3304       purge_addressof_1 (&SET_DEST (x), insn, force, 1, ht);
3305       purge_addressof_1 (&SET_SRC (x), insn, force, 0, ht);
3306       return;
3307     }
3308 
3309   /* Scan all subexpressions. */
3310   fmt = GET_RTX_FORMAT (code);
3311   for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
3312     {
3313       if (*fmt == 'e')
3314 	purge_addressof_1 (&XEXP (x, i), insn, force, 0, ht);
3315       else if (*fmt == 'E')
3316 	for (j = 0; j < XVECLEN (x, i); j++)
3317 	  purge_addressof_1 (&XVECEXP (x, i, j), insn, force, 0, ht);
3318     }
3319 }
3320 
3321 /* Return a new hash table entry in HT.  */
3322 
3323 static struct hash_entry *
3324 insns_for_mem_newfunc (he, ht, k)
3325      struct hash_entry *he;
3326      struct hash_table *ht;
3327      hash_table_key k ATTRIBUTE_UNUSED;
3328 {
3329   struct insns_for_mem_entry *ifmhe;
3330   if (he)
3331     return he;
3332 
3333   ifmhe = ((struct insns_for_mem_entry *)
3334 	   hash_allocate (ht, sizeof (struct insns_for_mem_entry)));
3335   ifmhe->insns = NULL_RTX;
3336 
3337   return &ifmhe->he;
3338 }
3339 
3340 /* Return a hash value for K, a REG.  */
3341 
3342 static unsigned long
3343 insns_for_mem_hash (k)
3344      hash_table_key k;
3345 {
3346   /* K is really a RTX.  Just use the address as the hash value.  */
3347   return (unsigned long) k;
3348 }
3349 
3350 /* Return non-zero if K1 and K2 (two REGs) are the same.  */
3351 
3352 static boolean
3353 insns_for_mem_comp (k1, k2)
3354      hash_table_key k1;
3355      hash_table_key k2;
3356 {
3357   return k1 == k2;
3358 }
3359 
3360 struct insns_for_mem_walk_info {
3361   /* The hash table that we are using to record which INSNs use which
3362      MEMs.  */
3363   struct hash_table *ht;
3364 
3365   /* The INSN we are currently proessing.  */
3366   rtx insn;
3367 
3368   /* Zero if we are walking to find ADDRESSOFs, one if we are walking
3369      to find the insns that use the REGs in the ADDRESSOFs.  */
3370   int pass;
3371 };
3372 
3373 /* Called from compute_insns_for_mem via for_each_rtx.  If R is a REG
3374    that might be used in an ADDRESSOF expression, record this INSN in
3375    the hash table given by DATA (which is really a pointer to an
3376    insns_for_mem_walk_info structure).  */
3377 
3378 static int
3379 insns_for_mem_walk (r, data)
3380      rtx *r;
3381      void *data;
3382 {
3383   struct insns_for_mem_walk_info *ifmwi
3384     = (struct insns_for_mem_walk_info *) data;
3385 
3386   if (ifmwi->pass == 0 && *r && GET_CODE (*r) == ADDRESSOF
3387       && GET_CODE (XEXP (*r, 0)) == REG)
3388     hash_lookup (ifmwi->ht, XEXP (*r, 0), /*create=*/1, /*copy=*/0);
3389   else if (ifmwi->pass == 1 && *r && GET_CODE (*r) == REG)
3390     {
3391       /* Lookup this MEM in the hashtable, creating it if necessary.  */
3392       struct insns_for_mem_entry *ifme
3393 	= (struct insns_for_mem_entry *) hash_lookup (ifmwi->ht,
3394 						      *r,
3395 						      /*create=*/0,
3396 						      /*copy=*/0);
3397 
3398       /* If we have not already recorded this INSN, do so now.  Since
3399 	 we process the INSNs in order, we know that if we have
3400 	 recorded it it must be at the front of the list.  */
3401       if (ifme && (!ifme->insns || XEXP (ifme->insns, 0) != ifmwi->insn))
3402 	{
3403 	  /* We do the allocation on the same obstack as is used for
3404 	     the hash table since this memory will not be used once
3405 	     the hash table is deallocated.  */
3406 	  push_obstacks (&ifmwi->ht->memory, &ifmwi->ht->memory);
3407 	  ifme->insns = gen_rtx_EXPR_LIST (VOIDmode, ifmwi->insn,
3408 					   ifme->insns);
3409 	  pop_obstacks ();
3410 	}
3411     }
3412 
3413   return 0;
3414 }
3415 
3416 /* Walk the INSNS, until we reach LAST_INSN, recording which INSNs use
3417    which REGs in HT.  */
3418 
3419 static void
3420 compute_insns_for_mem (insns, last_insn, ht)
3421      rtx insns;
3422      rtx last_insn;
3423      struct hash_table *ht;
3424 {
3425   rtx insn;
3426   struct insns_for_mem_walk_info ifmwi;
3427   ifmwi.ht = ht;
3428 
3429   for (ifmwi.pass = 0; ifmwi.pass < 2; ++ifmwi.pass)
3430     for (insn = insns; insn != last_insn; insn = NEXT_INSN (insn))
3431       if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3432 	{
3433 	  ifmwi.insn = insn;
3434 	  for_each_rtx (&insn, insns_for_mem_walk, &ifmwi);
3435 	}
3436 }
3437 
3438 /* Eliminate all occurrences of ADDRESSOF from INSNS.  Elide any remaining
3439    (MEM (ADDRESSOF)) patterns, and force any needed registers into the
3440    stack.  */
3441 
3442 void
3443 purge_addressof (insns)
3444      rtx insns;
3445 {
3446   rtx insn;
3447   struct hash_table ht;
3448 
3449   /* When we actually purge ADDRESSOFs, we turn REGs into MEMs.  That
3450      requires a fixup pass over the instruction stream to correct
3451      INSNs that depended on the REG being a REG, and not a MEM.  But,
3452      these fixup passes are slow.  Furthermore, more MEMs are not
3453      mentioned in very many instructions.  So, we speed up the process
3454      by pre-calculating which REGs occur in which INSNs; that allows
3455      us to perform the fixup passes much more quickly.  */
3456   hash_table_init (&ht,
3457 		   insns_for_mem_newfunc,
3458 		   insns_for_mem_hash,
3459 		   insns_for_mem_comp);
3460   compute_insns_for_mem (insns, NULL_RTX, &ht);
3461 
3462   for (insn = insns; insn; insn = NEXT_INSN (insn))
3463     if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
3464 	|| GET_CODE (insn) == CALL_INSN)
3465       {
3466 	purge_addressof_1 (&PATTERN (insn), insn,
3467 			   asm_noperands (PATTERN (insn)) > 0, 0, &ht);
3468 	purge_addressof_1 (&REG_NOTES (insn), NULL_RTX, 0, 0, &ht);
3469       }
3470 
3471   /* Clean up.  */
3472   hash_table_free (&ht);
3473   purge_bitfield_addressof_replacements = 0;
3474   purge_addressof_replacements = 0;
3475 }
3476 
3477 /* Pass through the INSNS of function FNDECL and convert virtual register
3478    references to hard register references.  */
3479 
3480 void
3481 instantiate_virtual_regs (fndecl, insns)
3482      tree fndecl;
3483      rtx insns;
3484 {
3485   rtx insn;
3486   int i;
3487 
3488   /* Compute the offsets to use for this function.  */
3489   in_arg_offset = FIRST_PARM_OFFSET (fndecl);
3490   var_offset = STARTING_FRAME_OFFSET;
3491   dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
3492   out_arg_offset = STACK_POINTER_OFFSET;
3493   cfa_offset = ARG_POINTER_CFA_OFFSET;
3494 
3495   /* Scan all variables and parameters of this function.  For each that is
3496      in memory, instantiate all virtual registers if the result is a valid
3497      address.  If not, we do it later.  That will handle most uses of virtual
3498      regs on many machines.  */
3499   instantiate_decls (fndecl, 1);
3500 
3501   /* Initialize recognition, indicating that volatile is OK.  */
3502   init_recog ();
3503 
3504   /* Scan through all the insns, instantiating every virtual register still
3505      present.  */
3506   for (insn = insns; insn; insn = NEXT_INSN (insn))
3507     if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
3508 	|| GET_CODE (insn) == CALL_INSN)
3509       {
3510 	instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1);
3511 	instantiate_virtual_regs_1 (&REG_NOTES (insn), NULL_RTX, 0);
3512       }
3513 
3514   /* Instantiate the stack slots for the parm registers, for later use in
3515      addressof elimination.  */
3516   for (i = 0; i < max_parm_reg; ++i)
3517     if (parm_reg_stack_loc[i])
3518       instantiate_virtual_regs_1 (&parm_reg_stack_loc[i], NULL_RTX, 0);
3519 
3520   /* Now instantiate the remaining register equivalences for debugging info.
3521      These will not be valid addresses.  */
3522   instantiate_decls (fndecl, 0);
3523 
3524   /* Indicate that, from now on, assign_stack_local should use
3525      frame_pointer_rtx.  */
3526   virtuals_instantiated = 1;
3527 }
3528 
3529 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
3530    all virtual registers in their DECL_RTL's.
3531 
3532    If VALID_ONLY, do this only if the resulting address is still valid.
3533    Otherwise, always do it.  */
3534 
3535 static void
3536 instantiate_decls (fndecl, valid_only)
3537      tree fndecl;
3538      int valid_only;
3539 {
3540   tree decl;
3541 
3542   if (DECL_SAVED_INSNS (fndecl))
3543     /* When compiling an inline function, the obstack used for
3544        rtl allocation is the maybepermanent_obstack.  Calling
3545        `resume_temporary_allocation' switches us back to that
3546        obstack while we process this function's parameters.  */
3547     resume_temporary_allocation ();
3548 
3549   /* Process all parameters of the function.  */
3550   for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
3551     {
3552       HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
3553 
3554       instantiate_decl (DECL_RTL (decl), size, valid_only);
3555 
3556       /* If the parameter was promoted, then the incoming RTL mode may be
3557 	 larger than the declared type size.  We must use the larger of
3558 	 the two sizes.  */
3559       size = MAX (GET_MODE_SIZE (GET_MODE (DECL_INCOMING_RTL (decl))), size);
3560       instantiate_decl (DECL_INCOMING_RTL (decl), size, valid_only);
3561     }
3562 
3563   /* Now process all variables defined in the function or its subblocks.  */
3564   instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
3565 
3566   if (DECL_INLINE (fndecl) || DECL_DEFER_OUTPUT (fndecl))
3567     {
3568       /* Save all rtl allocated for this function by raising the
3569 	 high-water mark on the maybepermanent_obstack.  */
3570       preserve_data ();
3571       /* All further rtl allocation is now done in the current_obstack.  */
3572       rtl_in_current_obstack ();
3573     }
3574 }
3575 
3576 /* Subroutine of instantiate_decls: Process all decls in the given
3577    BLOCK node and all its subblocks.  */
3578 
3579 static void
3580 instantiate_decls_1 (let, valid_only)
3581      tree let;
3582      int valid_only;
3583 {
3584   tree t;
3585 
3586   for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
3587     instantiate_decl (DECL_RTL (t), int_size_in_bytes (TREE_TYPE (t)),
3588 		      valid_only);
3589 
3590   /* Process all subblocks.  */
3591   for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
3592     instantiate_decls_1 (t, valid_only);
3593 }
3594 
3595 /* Subroutine of the preceding procedures: Given RTL representing a
3596    decl and the size of the object, do any instantiation required.
3597 
3598    If VALID_ONLY is non-zero, it means that the RTL should only be
3599    changed if the new address is valid.  */
3600 
3601 static void
3602 instantiate_decl (x, size, valid_only)
3603      rtx x;
3604      int size;
3605      int valid_only;
3606 {
3607   enum machine_mode mode;
3608   rtx addr;
3609 
3610   /* If this is not a MEM, no need to do anything.  Similarly if the
3611      address is a constant or a register that is not a virtual register.  */
3612 
3613   if (x == 0 || GET_CODE (x) != MEM)
3614     return;
3615 
3616   addr = XEXP (x, 0);
3617   if (CONSTANT_P (addr)
3618       || (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == REG)
3619       || (GET_CODE (addr) == REG
3620 	  && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
3621 	      || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
3622     return;
3623 
3624   /* If we should only do this if the address is valid, copy the address.
3625      We need to do this so we can undo any changes that might make the
3626      address invalid.  This copy is unfortunate, but probably can't be
3627      avoided.  */
3628 
3629   if (valid_only)
3630     addr = copy_rtx (addr);
3631 
3632   instantiate_virtual_regs_1 (&addr, NULL_RTX, 0);
3633 
3634   if (valid_only)
3635     {
3636       /* Now verify that the resulting address is valid for every integer or
3637 	 floating-point mode up to and including SIZE bytes long.  We do this
3638 	 since the object might be accessed in any mode and frame addresses
3639 	 are shared.  */
3640 
3641       for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
3642 	   mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
3643 	   mode = GET_MODE_WIDER_MODE (mode))
3644 	if (! memory_address_p (mode, addr))
3645 	  return;
3646 
3647       for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
3648 	   mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
3649 	   mode = GET_MODE_WIDER_MODE (mode))
3650 	if (! memory_address_p (mode, addr))
3651 	  return;
3652     }
3653 
3654   /* Put back the address now that we have updated it and we either know
3655      it is valid or we don't care whether it is valid.  */
3656 
3657   XEXP (x, 0) = addr;
3658 }
3659 
3660 /* Given a pointer to a piece of rtx and an optional pointer to the
3661    containing object, instantiate any virtual registers present in it.
3662 
3663    If EXTRA_INSNS, we always do the replacement and generate
3664    any extra insns before OBJECT.  If it zero, we do nothing if replacement
3665    is not valid.
3666 
3667    Return 1 if we either had nothing to do or if we were able to do the
3668    needed replacement.  Return 0 otherwise; we only return zero if
3669    EXTRA_INSNS is zero.
3670 
3671    We first try some simple transformations to avoid the creation of extra
3672    pseudos.  */
3673 
3674 static int
3675 instantiate_virtual_regs_1 (loc, object, extra_insns)
3676      rtx *loc;
3677      rtx object;
3678      int extra_insns;
3679 {
3680   rtx x;
3681   RTX_CODE code;
3682   rtx new = 0;
3683   HOST_WIDE_INT offset = 0;
3684   rtx temp;
3685   rtx seq;
3686   int i, j;
3687   char *fmt;
3688 
3689   /* Re-start here to avoid recursion in common cases.  */
3690  restart:
3691 
3692   x = *loc;
3693   if (x == 0)
3694     return 1;
3695 
3696   code = GET_CODE (x);
3697 
3698   /* Check for some special cases.  */
3699   switch (code)
3700     {
3701     case CONST_INT:
3702     case CONST_DOUBLE:
3703     case CONST:
3704     case SYMBOL_REF:
3705     case CODE_LABEL:
3706     case PC:
3707     case CC0:
3708     case ASM_INPUT:
3709     case ADDR_VEC:
3710     case ADDR_DIFF_VEC:
3711     case RETURN:
3712       return 1;
3713 
3714     case SET:
3715       /* We are allowed to set the virtual registers.  This means that
3716 	 the actual register should receive the source minus the
3717 	 appropriate offset.  This is used, for example, in the handling
3718 	 of non-local gotos.  */
3719       if (SET_DEST (x) == virtual_incoming_args_rtx)
3720 	new = arg_pointer_rtx, offset = - in_arg_offset;
3721       else if (SET_DEST (x) == virtual_stack_vars_rtx)
3722 	new = frame_pointer_rtx, offset = - var_offset;
3723       else if (SET_DEST (x) == virtual_stack_dynamic_rtx)
3724 	new = stack_pointer_rtx, offset = - dynamic_offset;
3725       else if (SET_DEST (x) == virtual_outgoing_args_rtx)
3726 	new = stack_pointer_rtx, offset = - out_arg_offset;
3727       else if (SET_DEST (x) == virtual_cfa_rtx)
3728 	new = arg_pointer_rtx, offset = - cfa_offset;
3729 
3730       if (new)
3731 	{
3732 	  /* The only valid sources here are PLUS or REG.  Just do
3733 	     the simplest possible thing to handle them.  */
3734 	  if (GET_CODE (SET_SRC (x)) != REG
3735 	      && GET_CODE (SET_SRC (x)) != PLUS)
3736 	    abort ();
3737 
3738 	  start_sequence ();
3739 	  if (GET_CODE (SET_SRC (x)) != REG)
3740 	    temp = force_operand (SET_SRC (x), NULL_RTX);
3741 	  else
3742 	    temp = SET_SRC (x);
3743 	  temp = force_operand (plus_constant (temp, offset), NULL_RTX);
3744 	  seq = get_insns ();
3745 	  end_sequence ();
3746 
3747 	  emit_insns_before (seq, object);
3748 	  SET_DEST (x) = new;
3749 
3750 	  if (! validate_change (object, &SET_SRC (x), temp, 0)
3751 	      || ! extra_insns)
3752 	    abort ();
3753 
3754 	  return 1;
3755 	}
3756 
3757       instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns);
3758       loc = &SET_SRC (x);
3759       goto restart;
3760 
3761     case PLUS:
3762       /* Handle special case of virtual register plus constant.  */
3763       if (CONSTANT_P (XEXP (x, 1)))
3764 	{
3765 	  rtx old, new_offset;
3766 
3767 	  /* Check for (plus (plus VIRT foo) (const_int)) first.  */
3768 	  if (GET_CODE (XEXP (x, 0)) == PLUS)
3769 	    {
3770 	      rtx inner = XEXP (XEXP (x, 0), 0);
3771 
3772 	      if (inner == virtual_incoming_args_rtx)
3773 		new = arg_pointer_rtx, offset = in_arg_offset;
3774 	      else if (inner == virtual_stack_vars_rtx)
3775 		new = frame_pointer_rtx, offset = var_offset;
3776 	      else if (inner == virtual_stack_dynamic_rtx)
3777 		new = stack_pointer_rtx, offset = dynamic_offset;
3778 	      else if (inner == virtual_outgoing_args_rtx)
3779 		new = stack_pointer_rtx, offset = out_arg_offset;
3780 	      else if (inner == virtual_cfa_rtx)
3781 	        new = arg_pointer_rtx, offset = cfa_offset;
3782 	      else
3783 		{
3784 		  loc = &XEXP (x, 0);
3785 		  goto restart;
3786 		}
3787 
3788 	      instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object,
3789 					  extra_insns);
3790 	      new = gen_rtx_PLUS (Pmode, new, XEXP (XEXP (x, 0), 1));
3791 	    }
3792 
3793 	  else if (XEXP (x, 0) == virtual_incoming_args_rtx)
3794 	    new = arg_pointer_rtx, offset = in_arg_offset;
3795 	  else if (XEXP (x, 0) == virtual_stack_vars_rtx)
3796 	    new = frame_pointer_rtx, offset = var_offset;
3797 	  else if (XEXP (x, 0) == virtual_stack_dynamic_rtx)
3798 	    new = stack_pointer_rtx, offset = dynamic_offset;
3799 	  else if (XEXP (x, 0) == virtual_outgoing_args_rtx)
3800 	    new = stack_pointer_rtx, offset = out_arg_offset;
3801           else if (XEXP (x, 0) == virtual_cfa_rtx)
3802             new = arg_pointer_rtx, offset = cfa_offset;
3803 	  else
3804 	    {
3805 	      /* We know the second operand is a constant.  Unless the
3806 		 first operand is a REG (which has been already checked),
3807 		 it needs to be checked.  */
3808 	      if (GET_CODE (XEXP (x, 0)) != REG)
3809 		{
3810 		  loc = &XEXP (x, 0);
3811 		  goto restart;
3812 		}
3813 	      return 1;
3814 	    }
3815 
3816 	  new_offset = plus_constant (XEXP (x, 1), offset);
3817 
3818 	  /* If the new constant is zero, try to replace the sum with just
3819 	     the register.  */
3820 	  if (new_offset == const0_rtx
3821 	      && validate_change (object, loc, new, 0))
3822 	    return 1;
3823 
3824 	  /* Next try to replace the register and new offset.
3825 	     There are two changes to validate here and we can't assume that
3826 	     in the case of old offset equals new just changing the register
3827 	     will yield a valid insn.  In the interests of a little efficiency,
3828 	     however, we only call validate change once (we don't queue up the
3829 	     changes and then call apply_change_group).  */
3830 
3831 	  old = XEXP (x, 0);
3832 	  if (offset == 0
3833 	      ? ! validate_change (object, &XEXP (x, 0), new, 0)
3834 	      : (XEXP (x, 0) = new,
3835 		 ! validate_change (object, &XEXP (x, 1), new_offset, 0)))
3836 	    {
3837 	      if (! extra_insns)
3838 		{
3839 		  XEXP (x, 0) = old;
3840 		  return 0;
3841 		}
3842 
3843 	      /* Otherwise copy the new constant into a register and replace
3844 		 constant with that register.  */
3845 	      temp = gen_reg_rtx (Pmode);
3846 	      XEXP (x, 0) = new;
3847 	      if (validate_change (object, &XEXP (x, 1), temp, 0))
3848 		emit_insn_before (gen_move_insn (temp, new_offset), object);
3849 	      else
3850 		{
3851 		  /* If that didn't work, replace this expression with a
3852 		     register containing the sum.  */
3853 
3854 		  XEXP (x, 0) = old;
3855 		  new = gen_rtx_PLUS (Pmode, new, new_offset);
3856 
3857 		  start_sequence ();
3858 		  temp = force_operand (new, NULL_RTX);
3859 		  seq = get_insns ();
3860 		  end_sequence ();
3861 
3862 		  emit_insns_before (seq, object);
3863 		  if (! validate_change (object, loc, temp, 0)
3864 		      && ! validate_replace_rtx (x, temp, object))
3865 		    abort ();
3866 		}
3867 	    }
3868 
3869 	  return 1;
3870 	}
3871 
3872       /* Fall through to generic two-operand expression case.  */
3873     case EXPR_LIST:
3874     case CALL:
3875     case COMPARE:
3876     case MINUS:
3877     case MULT:
3878     case DIV:      case UDIV:
3879     case MOD:      case UMOD:
3880     case AND:      case IOR:      case XOR:
3881     case ROTATERT: case ROTATE:
3882     case ASHIFTRT: case LSHIFTRT: case ASHIFT:
3883     case NE:       case EQ:
3884     case GE:       case GT:       case GEU:    case GTU:
3885     case LE:       case LT:       case LEU:    case LTU:
3886       if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
3887 	instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns);
3888       loc = &XEXP (x, 0);
3889       goto restart;
3890 
3891     case MEM:
3892       /* Most cases of MEM that convert to valid addresses have already been
3893 	 handled by our scan of decls.  The only special handling we
3894 	 need here is to make a copy of the rtx to ensure it isn't being
3895 	 shared if we have to change it to a pseudo.
3896 
3897 	 If the rtx is a simple reference to an address via a virtual register,
3898 	 it can potentially be shared.  In such cases, first try to make it
3899 	 a valid address, which can also be shared.  Otherwise, copy it and
3900 	 proceed normally.
3901 
3902 	 First check for common cases that need no processing.  These are
3903 	 usually due to instantiation already being done on a previous instance
3904 	 of a shared rtx.  */
3905 
3906       temp = XEXP (x, 0);
3907       if (CONSTANT_ADDRESS_P (temp)
3908 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3909 	  || temp == arg_pointer_rtx
3910 #endif
3911 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3912 	  || temp == hard_frame_pointer_rtx
3913 #endif
3914 	  || temp == frame_pointer_rtx)
3915 	return 1;
3916 
3917       if (GET_CODE (temp) == PLUS
3918 	  && CONSTANT_ADDRESS_P (XEXP (temp, 1))
3919 	  && (XEXP (temp, 0) == frame_pointer_rtx
3920 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3921 	      || XEXP (temp, 0) == hard_frame_pointer_rtx
3922 #endif
3923 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3924 	      || XEXP (temp, 0) == arg_pointer_rtx
3925 #endif
3926 	      ))
3927 	return 1;
3928 
3929       if (temp == virtual_stack_vars_rtx
3930 	  || temp == virtual_incoming_args_rtx
3931 	  || (GET_CODE (temp) == PLUS
3932 	      && CONSTANT_ADDRESS_P (XEXP (temp, 1))
3933 	      && (XEXP (temp, 0) == virtual_stack_vars_rtx
3934 		  || XEXP (temp, 0) == virtual_incoming_args_rtx)))
3935 	{
3936 	  /* This MEM may be shared.  If the substitution can be done without
3937 	     the need to generate new pseudos, we want to do it in place
3938 	     so all copies of the shared rtx benefit.  The call below will
3939 	     only make substitutions if the resulting address is still
3940 	     valid.
3941 
3942 	     Note that we cannot pass X as the object in the recursive call
3943 	     since the insn being processed may not allow all valid
3944 	     addresses.  However, if we were not passed on object, we can
3945 	     only modify X without copying it if X will have a valid
3946 	     address.
3947 
3948 	     ??? Also note that this can still lose if OBJECT is an insn that
3949 	     has less restrictions on an address that some other insn.
3950 	     In that case, we will modify the shared address.  This case
3951 	     doesn't seem very likely, though.  One case where this could
3952 	     happen is in the case of a USE or CLOBBER reference, but we
3953 	     take care of that below.  */
3954 
3955 	  if (instantiate_virtual_regs_1 (&XEXP (x, 0),
3956 					  object ? object : x, 0))
3957 	    return 1;
3958 
3959 	  /* Otherwise make a copy and process that copy.  We copy the entire
3960 	     RTL expression since it might be a PLUS which could also be
3961 	     shared.  */
3962 	  *loc = x = copy_rtx (x);
3963 	}
3964 
3965       /* Fall through to generic unary operation case.  */
3966     case SUBREG:
3967     case STRICT_LOW_PART:
3968     case NEG:          case NOT:
3969     case PRE_DEC:      case PRE_INC:      case POST_DEC:    case POST_INC:
3970     case SIGN_EXTEND:  case ZERO_EXTEND:
3971     case TRUNCATE:     case FLOAT_EXTEND: case FLOAT_TRUNCATE:
3972     case FLOAT:        case FIX:
3973     case UNSIGNED_FIX: case UNSIGNED_FLOAT:
3974     case ABS:
3975     case SQRT:
3976     case FFS:
3977       /* These case either have just one operand or we know that we need not
3978 	 check the rest of the operands.  */
3979       loc = &XEXP (x, 0);
3980       goto restart;
3981 
3982     case USE:
3983     case CLOBBER:
3984       /* If the operand is a MEM, see if the change is a valid MEM.  If not,
3985 	 go ahead and make the invalid one, but do it to a copy.  For a REG,
3986 	 just make the recursive call, since there's no chance of a problem. */
3987 
3988       if ((GET_CODE (XEXP (x, 0)) == MEM
3989 	   && instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), XEXP (x, 0),
3990 					  0))
3991 	  || (GET_CODE (XEXP (x, 0)) == REG
3992 	      && instantiate_virtual_regs_1 (&XEXP (x, 0), object, 0)))
3993 	return 1;
3994 
3995       XEXP (x, 0) = copy_rtx (XEXP (x, 0));
3996       loc = &XEXP (x, 0);
3997       goto restart;
3998 
3999     case REG:
4000       /* Try to replace with a PLUS.  If that doesn't work, compute the sum
4001 	 in front of this insn and substitute the temporary.  */
4002       if (x == virtual_incoming_args_rtx)
4003 	new = arg_pointer_rtx, offset = in_arg_offset;
4004       else if (x == virtual_stack_vars_rtx)
4005 	new = frame_pointer_rtx, offset = var_offset;
4006       else if (x == virtual_stack_dynamic_rtx)
4007 	new = stack_pointer_rtx, offset = dynamic_offset;
4008       else if (x == virtual_outgoing_args_rtx)
4009 	new = stack_pointer_rtx, offset = out_arg_offset;
4010       else if (x == virtual_cfa_rtx)
4011         new = arg_pointer_rtx, offset = cfa_offset;
4012 
4013       if (new)
4014 	{
4015 	  temp = plus_constant (new, offset);
4016 	  if (!validate_change (object, loc, temp, 0))
4017 	    {
4018 	      if (! extra_insns)
4019 		return 0;
4020 
4021 	      start_sequence ();
4022 	      temp = force_operand (temp, NULL_RTX);
4023 	      seq = get_insns ();
4024 	      end_sequence ();
4025 
4026 	      emit_insns_before (seq, object);
4027 	      if (! validate_change (object, loc, temp, 0)
4028 		  && ! validate_replace_rtx (x, temp, object))
4029 		abort ();
4030 	    }
4031 	}
4032 
4033       return 1;
4034 
4035     case ADDRESSOF:
4036       if (GET_CODE (XEXP (x, 0)) == REG)
4037 	return 1;
4038 
4039       else if (GET_CODE (XEXP (x, 0)) == MEM)
4040 	{
4041 	  /* If we have a (addressof (mem ..)), do any instantiation inside
4042 	     since we know we'll be making the inside valid when we finally
4043 	     remove the ADDRESSOF.  */
4044 	  instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), NULL_RTX, 0);
4045 	  return 1;
4046 	}
4047       break;
4048 
4049     default:
4050       break;
4051     }
4052 
4053   /* Scan all subexpressions.  */
4054   fmt = GET_RTX_FORMAT (code);
4055   for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
4056     if (*fmt == 'e')
4057       {
4058 	if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns))
4059 	  return 0;
4060       }
4061     else if (*fmt == 'E')
4062       for (j = 0; j < XVECLEN (x, i); j++)
4063 	if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object,
4064 					  extra_insns))
4065 	  return 0;
4066 
4067   return 1;
4068 }
4069 
4070 /* Optimization: assuming this function does not receive nonlocal gotos,
4071    delete the handlers for such, as well as the insns to establish
4072    and disestablish them.  */
4073 
4074 static void
4075 delete_handlers ()
4076 {
4077   rtx insn;
4078   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4079     {
4080       /* Delete the handler by turning off the flag that would
4081 	 prevent jump_optimize from deleting it.
4082 	 Also permit deletion of the nonlocal labels themselves
4083 	 if nothing local refers to them.  */
4084       if (GET_CODE (insn) == CODE_LABEL)
4085 	{
4086 	  tree t, last_t;
4087 
4088 	  LABEL_PRESERVE_P (insn) = 0;
4089 
4090 	  /* Remove it from the nonlocal_label list, to avoid confusing
4091 	     flow.  */
4092 	  for (t = nonlocal_labels, last_t = 0; t;
4093 	       last_t = t, t = TREE_CHAIN (t))
4094 	    if (DECL_RTL (TREE_VALUE (t)) == insn)
4095 	      break;
4096 	  if (t)
4097 	    {
4098 	      if (! last_t)
4099 		nonlocal_labels = TREE_CHAIN (nonlocal_labels);
4100 	      else
4101 		TREE_CHAIN (last_t) = TREE_CHAIN (t);
4102 	    }
4103 	}
4104       if (GET_CODE (insn) == INSN)
4105 	{
4106 	  int can_delete = 0;
4107 	  rtx t;
4108 	  for (t = nonlocal_goto_handler_slots; t != 0; t = XEXP (t, 1))
4109 	    if (reg_mentioned_p (t, PATTERN (insn)))
4110 	      {
4111 		can_delete = 1;
4112 		break;
4113 	      }
4114 	  if (can_delete
4115 	      || (nonlocal_goto_stack_level != 0
4116 		  && reg_mentioned_p (nonlocal_goto_stack_level,
4117 				      PATTERN (insn))))
4118 	    delete_insn (insn);
4119 	}
4120     }
4121 }
4122 
4123 /* Output a USE for any register use in RTL.
4124    This is used with -noreg to mark the extent of lifespan
4125    of any registers used in a user-visible variable's DECL_RTL.  */
4126 
4127 void
4128 use_variable (rtl)
4129      rtx rtl;
4130 {
4131   if (GET_CODE (rtl) == REG)
4132     /* This is a register variable.  */
4133     emit_insn (gen_rtx_USE (VOIDmode, rtl));
4134   else if (GET_CODE (rtl) == MEM
4135 	   && GET_CODE (XEXP (rtl, 0)) == REG
4136 	   && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
4137 	       || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
4138 	   && XEXP (rtl, 0) != current_function_internal_arg_pointer)
4139     /* This is a variable-sized structure.  */
4140     emit_insn (gen_rtx_USE (VOIDmode, XEXP (rtl, 0)));
4141 }
4142 
4143 /* Like use_variable except that it outputs the USEs after INSN
4144    instead of at the end of the insn-chain.  */
4145 
4146 void
4147 use_variable_after (rtl, insn)
4148      rtx rtl, insn;
4149 {
4150   if (GET_CODE (rtl) == REG)
4151     /* This is a register variable.  */
4152     emit_insn_after (gen_rtx_USE (VOIDmode, rtl), insn);
4153   else if (GET_CODE (rtl) == MEM
4154 	   && GET_CODE (XEXP (rtl, 0)) == REG
4155 	   && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
4156 	       || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
4157 	   && XEXP (rtl, 0) != current_function_internal_arg_pointer)
4158     /* This is a variable-sized structure.  */
4159     emit_insn_after (gen_rtx_USE (VOIDmode, XEXP (rtl, 0)), insn);
4160 }
4161 
4162 int
4163 max_parm_reg_num ()
4164 {
4165   return max_parm_reg;
4166 }
4167 
4168 /* Return the first insn following those generated by `assign_parms'.  */
4169 
4170 rtx
4171 get_first_nonparm_insn ()
4172 {
4173   if (last_parm_insn)
4174     return NEXT_INSN (last_parm_insn);
4175   return get_insns ();
4176 }
4177 
4178 /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
4179    Crash if there is none.  */
4180 
4181 rtx
4182 get_first_block_beg ()
4183 {
4184   register rtx searcher;
4185   register rtx insn = get_first_nonparm_insn ();
4186 
4187   for (searcher = insn; searcher; searcher = NEXT_INSN (searcher))
4188     if (GET_CODE (searcher) == NOTE
4189 	&& NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG)
4190       return searcher;
4191 
4192   abort ();	/* Invalid call to this function.  (See comments above.)  */
4193   return NULL_RTX;
4194 }
4195 
4196 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
4197    This means a type for which function calls must pass an address to the
4198    function or get an address back from the function.
4199    EXP may be a type node or an expression (whose type is tested).  */
4200 
4201 int
4202 aggregate_value_p (exp)
4203      tree exp;
4204 {
4205   int i, regno, nregs;
4206   rtx reg;
4207   tree type;
4208   if (TREE_CODE_CLASS (TREE_CODE (exp)) == 't')
4209     type = exp;
4210   else
4211     type = TREE_TYPE (exp);
4212 
4213   if (RETURN_IN_MEMORY (type))
4214     return 1;
4215   /* Types that are TREE_ADDRESSABLE must be constructed in memory,
4216      and thus can't be returned in registers.  */
4217   if (TREE_ADDRESSABLE (type))
4218     return 1;
4219   if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
4220     return 1;
4221   /* Make sure we have suitable call-clobbered regs to return
4222      the value in; if not, we must return it in memory.  */
4223   reg = hard_function_value (type, 0);
4224 
4225   /* If we have something other than a REG (e.g. a PARALLEL), then assume
4226      it is OK.  */
4227   if (GET_CODE (reg) != REG)
4228     return 0;
4229 
4230   regno = REGNO (reg);
4231   nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type));
4232   for (i = 0; i < nregs; i++)
4233     if (! call_used_regs[regno + i])
4234       return 1;
4235   return 0;
4236 }
4237 
4238 /* Assign RTL expressions to the function's parameters.
4239    This may involve copying them into registers and using
4240    those registers as the RTL for them.
4241 
4242    If SECOND_TIME is non-zero it means that this function is being
4243    called a second time.  This is done by integrate.c when a function's
4244    compilation is deferred.  We need to come back here in case the
4245    FUNCTION_ARG macro computes items needed for the rest of the compilation
4246    (such as changing which registers are fixed or caller-saved).  But suppress
4247    writing any insns or setting DECL_RTL of anything in this case.  */
4248 
4249 void
4250 assign_parms (fndecl, second_time)
4251      tree fndecl;
4252      int second_time;
4253 {
4254   register tree parm;
4255   register rtx entry_parm = 0;
4256   register rtx stack_parm = 0;
4257   CUMULATIVE_ARGS args_so_far;
4258   enum machine_mode promoted_mode, passed_mode;
4259   enum machine_mode nominal_mode, promoted_nominal_mode;
4260   int unsignedp;
4261   /* Total space needed so far for args on the stack,
4262      given as a constant and a tree-expression.  */
4263   struct args_size stack_args_size;
4264   tree fntype = TREE_TYPE (fndecl);
4265   tree fnargs = DECL_ARGUMENTS (fndecl);
4266   /* This is used for the arg pointer when referring to stack args.  */
4267   rtx internal_arg_pointer;
4268   /* This is a dummy PARM_DECL that we used for the function result if
4269      the function returns a structure.  */
4270   tree function_result_decl = 0;
4271 #ifdef SETUP_INCOMING_VARARGS
4272   int varargs_setup = 0;
4273 #endif
4274   rtx conversion_insns = 0;
4275 
4276   /* Nonzero if the last arg is named `__builtin_va_alist',
4277      which is used on some machines for old-fashioned non-ANSI varargs.h;
4278      this should be stuck onto the stack as if it had arrived there.  */
4279   int hide_last_arg
4280     = (current_function_varargs
4281        && fnargs
4282        && (parm = tree_last (fnargs)) != 0
4283        && DECL_NAME (parm)
4284        && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
4285 		     "__builtin_va_alist")));
4286 
4287   /* Nonzero if function takes extra anonymous args.
4288      This means the last named arg must be on the stack
4289      right before the anonymous ones.  */
4290   int stdarg
4291     = (TYPE_ARG_TYPES (fntype) != 0
4292        && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
4293 	   != void_type_node));
4294 
4295   current_function_stdarg = stdarg;
4296 
4297   /* If the reg that the virtual arg pointer will be translated into is
4298      not a fixed reg or is the stack pointer, make a copy of the virtual
4299      arg pointer, and address parms via the copy.  The frame pointer is
4300      considered fixed even though it is not marked as such.
4301 
4302      The second time through, simply use ap to avoid generating rtx.  */
4303 
4304   if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
4305        || ! (fixed_regs[ARG_POINTER_REGNUM]
4306 	     || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM))
4307       && ! second_time)
4308     internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
4309   else
4310     internal_arg_pointer = virtual_incoming_args_rtx;
4311   current_function_internal_arg_pointer = internal_arg_pointer;
4312 
4313   stack_args_size.constant = 0;
4314   stack_args_size.var = 0;
4315 
4316   /* If struct value address is treated as the first argument, make it so.  */
4317   if (aggregate_value_p (DECL_RESULT (fndecl))
4318       && ! current_function_returns_pcc_struct
4319       && struct_value_incoming_rtx == 0)
4320     {
4321       tree type = build_pointer_type (TREE_TYPE (fntype));
4322 
4323       function_result_decl = build_decl (PARM_DECL, NULL_TREE, type);
4324 
4325       DECL_ARG_TYPE (function_result_decl) = type;
4326       TREE_CHAIN (function_result_decl) = fnargs;
4327       fnargs = function_result_decl;
4328     }
4329 
4330   max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
4331   parm_reg_stack_loc = (rtx *) savealloc (max_parm_reg * sizeof (rtx));
4332   bzero ((char *) parm_reg_stack_loc, max_parm_reg * sizeof (rtx));
4333 
4334 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
4335   INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX);
4336 #else
4337   INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX, 0);
4338 #endif
4339 
4340   /* We haven't yet found an argument that we must push and pretend the
4341      caller did.  */
4342   current_function_pretend_args_size = 0;
4343 
4344   for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
4345     {
4346       int aggregate = AGGREGATE_TYPE_P (TREE_TYPE (parm));
4347       struct args_size stack_offset;
4348       struct args_size arg_size;
4349       int passed_pointer = 0;
4350       int did_conversion = 0;
4351       tree passed_type = DECL_ARG_TYPE (parm);
4352       tree nominal_type = TREE_TYPE (parm);
4353       int pretend_named;
4354 
4355       /* Set LAST_NAMED if this is last named arg before some
4356 	 anonymous args.  */
4357       int last_named = ((TREE_CHAIN (parm) == 0
4358 			 || DECL_NAME (TREE_CHAIN (parm)) == 0)
4359 			&& (stdarg || current_function_varargs));
4360       /* Set NAMED_ARG if this arg should be treated as a named arg.  For
4361 	 most machines, if this is a varargs/stdarg function, then we treat
4362 	 the last named arg as if it were anonymous too.  */
4363       int named_arg = STRICT_ARGUMENT_NAMING ? 1 : ! last_named;
4364 
4365       if (TREE_TYPE (parm) == error_mark_node
4366 	  /* This can happen after weird syntax errors
4367 	     or if an enum type is defined among the parms.  */
4368 	  || TREE_CODE (parm) != PARM_DECL
4369 	  || passed_type == NULL)
4370 	{
4371 	  DECL_INCOMING_RTL (parm) = DECL_RTL (parm)
4372 	    = gen_rtx_MEM (BLKmode, const0_rtx);
4373 	  TREE_USED (parm) = 1;
4374 	  continue;
4375 	}
4376 
4377       /* For varargs.h function, save info about regs and stack space
4378 	 used by the individual args, not including the va_alist arg.  */
4379       if (hide_last_arg && last_named)
4380 	current_function_args_info = args_so_far;
4381 
4382       /* Find mode of arg as it is passed, and mode of arg
4383 	 as it should be during execution of this function.  */
4384       passed_mode = TYPE_MODE (passed_type);
4385       nominal_mode = TYPE_MODE (nominal_type);
4386 
4387       /* If the parm's mode is VOID, its value doesn't matter,
4388 	 and avoid the usual things like emit_move_insn that could crash.  */
4389       if (nominal_mode == VOIDmode)
4390 	{
4391 	  DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = const0_rtx;
4392 	  continue;
4393 	}
4394 
4395       /* If the parm is to be passed as a transparent union, use the
4396 	 type of the first field for the tests below.  We have already
4397 	 verified that the modes are the same.  */
4398       if (DECL_TRANSPARENT_UNION (parm)
4399 	  || TYPE_TRANSPARENT_UNION (passed_type))
4400 	passed_type = TREE_TYPE (TYPE_FIELDS (passed_type));
4401 
4402       /* See if this arg was passed by invisible reference.  It is if
4403 	 it is an object whose size depends on the contents of the
4404 	 object itself or if the machine requires these objects be passed
4405 	 that way.  */
4406 
4407       if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
4408 	   && contains_placeholder_p (TYPE_SIZE (passed_type)))
4409 	  || TREE_ADDRESSABLE (passed_type)
4410 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
4411 	  || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
4412 					      passed_type, named_arg)
4413 #endif
4414 	  )
4415 	{
4416 	  passed_type = nominal_type = build_pointer_type (passed_type);
4417 	  passed_pointer = 1;
4418 	  passed_mode = nominal_mode = Pmode;
4419 	}
4420 
4421       promoted_mode = passed_mode;
4422 
4423 #ifdef PROMOTE_FUNCTION_ARGS
4424       /* Compute the mode in which the arg is actually extended to.  */
4425       unsignedp = TREE_UNSIGNED (passed_type);
4426       promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1);
4427 #endif
4428 
4429       /* Let machine desc say which reg (if any) the parm arrives in.
4430 	 0 means it arrives on the stack.  */
4431 #ifdef FUNCTION_INCOMING_ARG
4432       entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
4433 					  passed_type, named_arg);
4434 #else
4435       entry_parm = FUNCTION_ARG (args_so_far, promoted_mode,
4436 				 passed_type, named_arg);
4437 #endif
4438 
4439       if (entry_parm == 0)
4440 	promoted_mode = passed_mode;
4441 
4442 #ifdef SETUP_INCOMING_VARARGS
4443       /* If this is the last named parameter, do any required setup for
4444 	 varargs or stdargs.  We need to know about the case of this being an
4445 	 addressable type, in which case we skip the registers it
4446 	 would have arrived in.
4447 
4448 	 For stdargs, LAST_NAMED will be set for two parameters, the one that
4449 	 is actually the last named, and the dummy parameter.  We only
4450 	 want to do this action once.
4451 
4452 	 Also, indicate when RTL generation is to be suppressed.  */
4453       if (last_named && !varargs_setup)
4454 	{
4455 	  SETUP_INCOMING_VARARGS (args_so_far, promoted_mode, passed_type,
4456 				  current_function_pretend_args_size,
4457 				  second_time);
4458 	  varargs_setup = 1;
4459 	}
4460 #endif
4461 
4462       /* Determine parm's home in the stack,
4463 	 in case it arrives in the stack or we should pretend it did.
4464 
4465 	 Compute the stack position and rtx where the argument arrives
4466 	 and its size.
4467 
4468 	 There is one complexity here:  If this was a parameter that would
4469 	 have been passed in registers, but wasn't only because it is
4470 	 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
4471 	 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
4472 	 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
4473 	 0 as it was the previous time.  */
4474 
4475       pretend_named = named_arg || PRETEND_OUTGOING_VARARGS_NAMED;
4476       locate_and_pad_parm (promoted_mode, passed_type,
4477 #ifdef STACK_PARMS_IN_REG_PARM_AREA
4478 			   1,
4479 #else
4480 #ifdef FUNCTION_INCOMING_ARG
4481 			   FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
4482 						  passed_type,
4483 						  pretend_named) != 0,
4484 #else
4485 			   FUNCTION_ARG (args_so_far, promoted_mode,
4486 					 passed_type,
4487 					 pretend_named) != 0,
4488 #endif
4489 #endif
4490 			   fndecl, &stack_args_size, &stack_offset, &arg_size);
4491 
4492       if (! second_time)
4493 	{
4494 	  rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
4495 
4496 	  if (offset_rtx == const0_rtx)
4497 	    stack_parm = gen_rtx_MEM (promoted_mode, internal_arg_pointer);
4498 	  else
4499 	    stack_parm = gen_rtx_MEM (promoted_mode,
4500 				      gen_rtx_PLUS (Pmode,
4501 						    internal_arg_pointer,
4502 						    offset_rtx));
4503 
4504 	  /* If this is a memory ref that contains aggregate components,
4505 	     mark it as such for cse and loop optimize.  Likewise if it
4506 	     is readonly.  */
4507 	  MEM_SET_IN_STRUCT_P (stack_parm, aggregate);
4508 	  RTX_UNCHANGING_P (stack_parm) = TREE_READONLY (parm);
4509 	  MEM_ALIAS_SET (stack_parm) = get_alias_set (parm);
4510 	}
4511 
4512       /* If this parameter was passed both in registers and in the stack,
4513 	 use the copy on the stack.  */
4514       if (MUST_PASS_IN_STACK (promoted_mode, passed_type))
4515 	entry_parm = 0;
4516 
4517 #ifdef FUNCTION_ARG_PARTIAL_NREGS
4518       /* If this parm was passed part in regs and part in memory,
4519 	 pretend it arrived entirely in memory
4520 	 by pushing the register-part onto the stack.
4521 
4522 	 In the special case of a DImode or DFmode that is split,
4523 	 we could put it together in a pseudoreg directly,
4524 	 but for now that's not worth bothering with.  */
4525 
4526       if (entry_parm)
4527 	{
4528 	  int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, promoted_mode,
4529 						  passed_type, named_arg);
4530 
4531 	  if (nregs > 0)
4532 	    {
4533 	      current_function_pretend_args_size
4534 		= (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
4535 		   / (PARM_BOUNDARY / BITS_PER_UNIT)
4536 		   * (PARM_BOUNDARY / BITS_PER_UNIT));
4537 
4538 	      if (! second_time)
4539 		{
4540 		  /* Handle calls that pass values in multiple non-contiguous
4541 		     locations.  The Irix 6 ABI has examples of this.  */
4542 		  if (GET_CODE (entry_parm) == PARALLEL)
4543 		    emit_group_store (validize_mem (stack_parm), entry_parm,
4544 				      int_size_in_bytes (TREE_TYPE (parm)),
4545 				      (TYPE_ALIGN (TREE_TYPE (parm))
4546 				       / BITS_PER_UNIT));
4547 		  else
4548 		    move_block_from_reg (REGNO (entry_parm),
4549 					 validize_mem (stack_parm), nregs,
4550 					 int_size_in_bytes (TREE_TYPE (parm)));
4551 		}
4552 	      entry_parm = stack_parm;
4553 	    }
4554 	}
4555 #endif
4556 
4557       /* If we didn't decide this parm came in a register,
4558 	 by default it came on the stack.  */
4559       if (entry_parm == 0)
4560 	entry_parm = stack_parm;
4561 
4562       /* Record permanently how this parm was passed.  */
4563       if (! second_time)
4564 	DECL_INCOMING_RTL (parm) = entry_parm;
4565 
4566       /* If there is actually space on the stack for this parm,
4567 	 count it in stack_args_size; otherwise set stack_parm to 0
4568 	 to indicate there is no preallocated stack slot for the parm.  */
4569 
4570       if (entry_parm == stack_parm
4571           || (GET_CODE (entry_parm) == PARALLEL
4572               && XEXP (XVECEXP (entry_parm, 0, 0), 0) == NULL_RTX)
4573 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
4574 	  /* On some machines, even if a parm value arrives in a register
4575 	     there is still an (uninitialized) stack slot allocated for it.
4576 
4577 	     ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
4578 	     whether this parameter already has a stack slot allocated,
4579 	     because an arg block exists only if current_function_args_size
4580 	     is larger than some threshold, and we haven't calculated that
4581 	     yet.  So, for now, we just assume that stack slots never exist
4582 	     in this case.  */
4583 	  || REG_PARM_STACK_SPACE (fndecl) > 0
4584 #endif
4585 	  )
4586 	{
4587 	  stack_args_size.constant += arg_size.constant;
4588 	  if (arg_size.var)
4589 	    ADD_PARM_SIZE (stack_args_size, arg_size.var);
4590 	}
4591       else
4592 	/* No stack slot was pushed for this parm.  */
4593 	stack_parm = 0;
4594 
4595       /* Update info on where next arg arrives in registers.  */
4596 
4597       FUNCTION_ARG_ADVANCE (args_so_far, promoted_mode,
4598 			    passed_type, named_arg);
4599 
4600       /* If this is our second time through, we are done with this parm.  */
4601       if (second_time)
4602 	continue;
4603 
4604       /* If we can't trust the parm stack slot to be aligned enough
4605 	 for its ultimate type, don't use that slot after entry.
4606 	 We'll make another stack slot, if we need one.  */
4607       {
4608 	int thisparm_boundary
4609 	  = FUNCTION_ARG_BOUNDARY (promoted_mode, passed_type);
4610 
4611 	if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary)
4612 	  stack_parm = 0;
4613       }
4614 
4615       /* If parm was passed in memory, and we need to convert it on entry,
4616 	 don't store it back in that same slot.  */
4617       if (entry_parm != 0
4618 	  && nominal_mode != BLKmode && nominal_mode != passed_mode)
4619 	stack_parm = 0;
4620 
4621 #if 0
4622       /* Now adjust STACK_PARM to the mode and precise location
4623 	 where this parameter should live during execution,
4624 	 if we discover that it must live in the stack during execution.
4625 	 To make debuggers happier on big-endian machines, we store
4626 	 the value in the last bytes of the space available.  */
4627 
4628       if (nominal_mode != BLKmode && nominal_mode != passed_mode
4629 	  && stack_parm != 0)
4630 	{
4631 	  rtx offset_rtx;
4632 
4633 	  if (BYTES_BIG_ENDIAN
4634 	      && GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD)
4635 	    stack_offset.constant += (GET_MODE_SIZE (passed_mode)
4636 				      - GET_MODE_SIZE (nominal_mode));
4637 
4638 	  offset_rtx = ARGS_SIZE_RTX (stack_offset);
4639 	  if (offset_rtx == const0_rtx)
4640 	    stack_parm = gen_rtx_MEM (nominal_mode, internal_arg_pointer);
4641 	  else
4642 	    stack_parm = gen_rtx_MEM (nominal_mode,
4643 				      gen_rtx_PLUS (Pmode,
4644 						    internal_arg_pointer,
4645 						    offset_rtx));
4646 
4647 	  /* If this is a memory ref that contains aggregate components,
4648 	     mark it as such for cse and loop optimize.  */
4649 	  MEM_SET_IN_STRUCT_P (stack_parm, aggregate);
4650 	}
4651 #endif /* 0 */
4652 
4653 #ifdef STACK_REGS
4654       /* We need this "use" info, because the gcc-register->stack-register
4655 	 converter in reg-stack.c needs to know which registers are active
4656 	 at the start of the function call.  The actual parameter loading
4657 	 instructions are not always available then anymore, since they might
4658 	 have been optimised away.  */
4659 
4660       if (GET_CODE (entry_parm) == REG && !(hide_last_arg && last_named))
4661 	  emit_insn (gen_rtx_USE (GET_MODE (entry_parm), entry_parm));
4662 #endif
4663 
4664       /* ENTRY_PARM is an RTX for the parameter as it arrives,
4665 	 in the mode in which it arrives.
4666 	 STACK_PARM is an RTX for a stack slot where the parameter can live
4667 	 during the function (in case we want to put it there).
4668 	 STACK_PARM is 0 if no stack slot was pushed for it.
4669 
4670 	 Now output code if necessary to convert ENTRY_PARM to
4671 	 the type in which this function declares it,
4672 	 and store that result in an appropriate place,
4673 	 which may be a pseudo reg, may be STACK_PARM,
4674 	 or may be a local stack slot if STACK_PARM is 0.
4675 
4676 	 Set DECL_RTL to that place.  */
4677 
4678       if (nominal_mode == BLKmode || GET_CODE (entry_parm) == PARALLEL)
4679 	{
4680 	  /* If a BLKmode arrives in registers, copy it to a stack slot.
4681 	     Handle calls that pass values in multiple non-contiguous
4682 	     locations.  The Irix 6 ABI has examples of this.  */
4683 	  if (GET_CODE (entry_parm) == REG
4684 	      || GET_CODE (entry_parm) == PARALLEL)
4685 	    {
4686 	      int size_stored
4687 		= CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
4688 			      UNITS_PER_WORD);
4689 
4690 	      /* Note that we will be storing an integral number of words.
4691 		 So we have to be careful to ensure that we allocate an
4692 		 integral number of words.  We do this below in the
4693 		 assign_stack_local if space was not allocated in the argument
4694 		 list.  If it was, this will not work if PARM_BOUNDARY is not
4695 		 a multiple of BITS_PER_WORD.  It isn't clear how to fix this
4696 		 if it becomes a problem.  */
4697 
4698 	      if (stack_parm == 0)
4699 		{
4700 		  stack_parm
4701 		    = assign_stack_local (GET_MODE (entry_parm),
4702 					  size_stored, 0);
4703 
4704 		  /* If this is a memory ref that contains aggregate
4705 		     components, mark it as such for cse and loop optimize.  */
4706 		  MEM_SET_IN_STRUCT_P (stack_parm, aggregate);
4707 		}
4708 
4709 	      else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
4710 		abort ();
4711 
4712 	      if (TREE_READONLY (parm))
4713 		RTX_UNCHANGING_P (stack_parm) = 1;
4714 
4715 	      /* Handle calls that pass values in multiple non-contiguous
4716 		 locations.  The Irix 6 ABI has examples of this.  */
4717 	      if (GET_CODE (entry_parm) == PARALLEL)
4718 		emit_group_store (validize_mem (stack_parm), entry_parm,
4719 				  int_size_in_bytes (TREE_TYPE (parm)),
4720 				  (TYPE_ALIGN (TREE_TYPE (parm))
4721 				   / BITS_PER_UNIT));
4722 	      else
4723 		move_block_from_reg (REGNO (entry_parm),
4724 				     validize_mem (stack_parm),
4725 				     size_stored / UNITS_PER_WORD,
4726 				     int_size_in_bytes (TREE_TYPE (parm)));
4727 	    }
4728 	  DECL_RTL (parm) = stack_parm;
4729 	}
4730       else if (! ((obey_regdecls && ! DECL_REGISTER (parm)
4731 		   && ! DECL_INLINE (fndecl))
4732 		  /* layout_decl may set this.  */
4733 		  || TREE_ADDRESSABLE (parm)
4734 		  || TREE_SIDE_EFFECTS (parm)
4735 		  /* If -ffloat-store specified, don't put explicit
4736 		     float variables into registers.  */
4737 		  || (flag_float_store
4738 		      && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
4739 	       /* Always assign pseudo to structure return or item passed
4740 		  by invisible reference.  */
4741 	       || passed_pointer || parm == function_result_decl)
4742 	{
4743 	  /* Store the parm in a pseudoregister during the function, but we
4744 	     may need to do it in a wider mode.  */
4745 
4746 	  register rtx parmreg;
4747 	  int regno, regnoi = 0, regnor = 0;
4748 
4749 	  unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
4750 
4751 	  promoted_nominal_mode
4752 	    = promote_mode (TREE_TYPE (parm), nominal_mode, &unsignedp, 0);
4753 
4754 	  parmreg = gen_reg_rtx (promoted_nominal_mode);
4755 	  mark_user_reg (parmreg);
4756 
4757 	  /* If this was an item that we received a pointer to, set DECL_RTL
4758 	     appropriately.  */
4759 	  if (passed_pointer)
4760 	    {
4761 	      DECL_RTL (parm)
4762 		= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (passed_type)), parmreg);
4763 	      MEM_SET_IN_STRUCT_P (DECL_RTL (parm), aggregate);
4764 	    }
4765 	  else
4766 	    DECL_RTL (parm) = parmreg;
4767 
4768 	  /* Copy the value into the register.  */
4769 	  if (nominal_mode != passed_mode
4770 	      || promoted_nominal_mode != promoted_mode)
4771 	    {
4772 	      int save_tree_used;
4773 	      /* ENTRY_PARM has been converted to PROMOTED_MODE, its
4774 		 mode, by the caller.  We now have to convert it to
4775 		 NOMINAL_MODE, if different.  However, PARMREG may be in
4776 		 a different mode than NOMINAL_MODE if it is being stored
4777 		 promoted.
4778 
4779 		 If ENTRY_PARM is a hard register, it might be in a register
4780 		 not valid for operating in its mode (e.g., an odd-numbered
4781 		 register for a DFmode).  In that case, moves are the only
4782 		 thing valid, so we can't do a convert from there.  This
4783 		 occurs when the calling sequence allow such misaligned
4784 		 usages.
4785 
4786 		 In addition, the conversion may involve a call, which could
4787 		 clobber parameters which haven't been copied to pseudo
4788 		 registers yet.  Therefore, we must first copy the parm to
4789 		 a pseudo reg here, and save the conversion until after all
4790 		 parameters have been moved.  */
4791 
4792 	      rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
4793 
4794 	      emit_move_insn (tempreg, validize_mem (entry_parm));
4795 
4796 	      push_to_sequence (conversion_insns);
4797 	      tempreg = convert_to_mode (nominal_mode, tempreg, unsignedp);
4798 
4799 	      /* TREE_USED gets set erroneously during expand_assignment.  */
4800 	      save_tree_used = TREE_USED (parm);
4801 	      expand_assignment (parm,
4802 				 make_tree (nominal_type, tempreg), 0, 0);
4803 	      TREE_USED (parm) = save_tree_used;
4804 	      conversion_insns = get_insns ();
4805 	      did_conversion = 1;
4806 	      end_sequence ();
4807 	    }
4808 	  else
4809 	    emit_move_insn (parmreg, validize_mem (entry_parm));
4810 
4811 	  /* If we were passed a pointer but the actual value
4812 	     can safely live in a register, put it in one.  */
4813 	  if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
4814 	      && ! ((obey_regdecls && ! DECL_REGISTER (parm)
4815 		     && ! DECL_INLINE (fndecl))
4816 		    /* layout_decl may set this.  */
4817 		    || TREE_ADDRESSABLE (parm)
4818 		    || TREE_SIDE_EFFECTS (parm)
4819 		    /* If -ffloat-store specified, don't put explicit
4820 		       float variables into registers.  */
4821 		    || (flag_float_store
4822 			&& TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))
4823 	    {
4824 	      /* We can't use nominal_mode, because it will have been set to
4825 		 Pmode above.  We must use the actual mode of the parm.  */
4826 	      parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
4827 	      mark_user_reg (parmreg);
4828 	      emit_move_insn (parmreg, DECL_RTL (parm));
4829 	      DECL_RTL (parm) = parmreg;
4830 	      /* STACK_PARM is the pointer, not the parm, and PARMREG is
4831 		 now the parm.  */
4832 	      stack_parm = 0;
4833 	    }
4834 #ifdef FUNCTION_ARG_CALLEE_COPIES
4835 	  /* If we are passed an arg by reference and it is our responsibility
4836 	     to make a copy, do it now.
4837 	     PASSED_TYPE and PASSED mode now refer to the pointer, not the
4838 	     original argument, so we must recreate them in the call to
4839 	     FUNCTION_ARG_CALLEE_COPIES.  */
4840 	  /* ??? Later add code to handle the case that if the argument isn't
4841 	     modified, don't do the copy.  */
4842 
4843 	  else if (passed_pointer
4844 		   && FUNCTION_ARG_CALLEE_COPIES (args_so_far,
4845 						  TYPE_MODE (DECL_ARG_TYPE (parm)),
4846 						  DECL_ARG_TYPE (parm),
4847 						  named_arg)
4848 		   && ! TREE_ADDRESSABLE (DECL_ARG_TYPE (parm)))
4849 	    {
4850 	      rtx copy;
4851 	      tree type = DECL_ARG_TYPE (parm);
4852 
4853 	      /* This sequence may involve a library call perhaps clobbering
4854 		 registers that haven't been copied to pseudos yet.  */
4855 
4856 	      push_to_sequence (conversion_insns);
4857 
4858 	      if (TYPE_SIZE (type) == 0
4859 		  || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4860 		/* This is a variable sized object.  */
4861 		copy = gen_rtx_MEM (BLKmode,
4862 				    allocate_dynamic_stack_space
4863 				    (expr_size (parm), NULL_RTX,
4864 				     TYPE_ALIGN (type)));
4865 	      else
4866 		copy = assign_stack_temp (TYPE_MODE (type),
4867 					  int_size_in_bytes (type), 1);
4868 	      MEM_SET_IN_STRUCT_P (copy, AGGREGATE_TYPE_P (type));
4869 	      RTX_UNCHANGING_P (copy) = TREE_READONLY (parm);
4870 
4871 	      store_expr (parm, copy, 0);
4872 	      emit_move_insn (parmreg, XEXP (copy, 0));
4873 	      if (current_function_check_memory_usage)
4874 		emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
4875 				   XEXP (copy, 0), Pmode,
4876 				   GEN_INT (int_size_in_bytes (type)),
4877 				   TYPE_MODE (sizetype),
4878 				   GEN_INT (MEMORY_USE_RW),
4879 				   TYPE_MODE (integer_type_node));
4880 	      conversion_insns = get_insns ();
4881 	      did_conversion = 1;
4882 	      end_sequence ();
4883 	    }
4884 #endif /* FUNCTION_ARG_CALLEE_COPIES */
4885 
4886 	  /* In any case, record the parm's desired stack location
4887 	     in case we later discover it must live in the stack.
4888 
4889 	     If it is a COMPLEX value, store the stack location for both
4890 	     halves.  */
4891 
4892 	  if (GET_CODE (parmreg) == CONCAT)
4893 	    regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1)));
4894 	  else
4895 	    regno = REGNO (parmreg);
4896 
4897 	  if (regno >= max_parm_reg)
4898 	    {
4899 	      rtx *new;
4900 	      int old_max_parm_reg = max_parm_reg;
4901 
4902 	      /* It's slow to expand this one register at a time,
4903 		 but it's also rare and we need max_parm_reg to be
4904 		 precisely correct.  */
4905 	      max_parm_reg = regno + 1;
4906 	      new = (rtx *) savealloc (max_parm_reg * sizeof (rtx));
4907 	      bcopy ((char *) parm_reg_stack_loc, (char *) new,
4908 		     old_max_parm_reg * sizeof (rtx));
4909 	      bzero ((char *) (new + old_max_parm_reg),
4910 		     (max_parm_reg - old_max_parm_reg) * sizeof (rtx));
4911 	      parm_reg_stack_loc = new;
4912 	    }
4913 
4914 	  if (GET_CODE (parmreg) == CONCAT)
4915 	    {
4916 	      enum machine_mode submode = GET_MODE (XEXP (parmreg, 0));
4917 
4918 	      regnor = REGNO (gen_realpart (submode, parmreg));
4919 	      regnoi = REGNO (gen_imagpart (submode, parmreg));
4920 
4921 	      if (stack_parm != 0)
4922 		{
4923 		  parm_reg_stack_loc[regnor]
4924 		    = gen_realpart (submode, stack_parm);
4925 		  parm_reg_stack_loc[regnoi]
4926 		    = gen_imagpart (submode, stack_parm);
4927 		}
4928 	      else
4929 		{
4930 		  parm_reg_stack_loc[regnor] = 0;
4931 		  parm_reg_stack_loc[regnoi] = 0;
4932 		}
4933 	    }
4934 	  else
4935 	    parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
4936 
4937 	  /* Mark the register as eliminable if we did no conversion
4938 	     and it was copied from memory at a fixed offset,
4939 	     and the arg pointer was not copied to a pseudo-reg.
4940 	     If the arg pointer is a pseudo reg or the offset formed
4941 	     an invalid address, such memory-equivalences
4942 	     as we make here would screw up life analysis for it.  */
4943 	  if (nominal_mode == passed_mode
4944 	      && ! did_conversion
4945 	      && stack_parm != 0
4946 	      && GET_CODE (stack_parm) == MEM
4947 	      && stack_offset.var == 0
4948 	      && reg_mentioned_p (virtual_incoming_args_rtx,
4949 				  XEXP (stack_parm, 0)))
4950 	    {
4951 	      rtx linsn = get_last_insn ();
4952 	      rtx sinsn, set;
4953 
4954 	      /* Mark complex types separately.  */
4955 	      if (GET_CODE (parmreg) == CONCAT)
4956 		/* Scan backwards for the set of the real and
4957 		   imaginary parts.  */
4958 		for (sinsn = linsn; sinsn != 0;
4959 		     sinsn = prev_nonnote_insn (sinsn))
4960 		  {
4961 		    set = single_set (sinsn);
4962 		    if (set != 0
4963 			&& SET_DEST (set) == regno_reg_rtx [regnoi])
4964 		      REG_NOTES (sinsn)
4965 			= gen_rtx_EXPR_LIST (REG_EQUIV,
4966 					     parm_reg_stack_loc[regnoi],
4967 					     REG_NOTES (sinsn));
4968 		    else if (set != 0
4969 			     && SET_DEST (set) == regno_reg_rtx [regnor])
4970 		      REG_NOTES (sinsn)
4971 			= gen_rtx_EXPR_LIST (REG_EQUIV,
4972 					     parm_reg_stack_loc[regnor],
4973 					     REG_NOTES (sinsn));
4974 		  }
4975 	      else if ((set = single_set (linsn)) != 0
4976 		       && SET_DEST (set) == parmreg)
4977 	        REG_NOTES (linsn)
4978 		  = gen_rtx_EXPR_LIST (REG_EQUIV,
4979 				       stack_parm, REG_NOTES (linsn));
4980 	    }
4981 
4982 	  /* For pointer data type, suggest pointer register.  */
4983 	  if (POINTER_TYPE_P (TREE_TYPE (parm)))
4984 	    mark_reg_pointer (parmreg,
4985 			      (TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm)))
4986 			       / BITS_PER_UNIT));
4987 	}
4988       else
4989 	{
4990 	  /* Value must be stored in the stack slot STACK_PARM
4991 	     during function execution.  */
4992 
4993 	  if (promoted_mode != nominal_mode)
4994 	    {
4995 	      /* Conversion is required.   */
4996 	      rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
4997 
4998 	      emit_move_insn (tempreg, validize_mem (entry_parm));
4999 
5000 	      push_to_sequence (conversion_insns);
5001 	      entry_parm = convert_to_mode (nominal_mode, tempreg,
5002 					    TREE_UNSIGNED (TREE_TYPE (parm)));
5003 	      if (stack_parm)
5004 		{
5005 		  /* ??? This may need a big-endian conversion on sparc64.  */
5006 		  stack_parm = change_address (stack_parm, nominal_mode,
5007 					       NULL_RTX);
5008 		}
5009 	      conversion_insns = get_insns ();
5010 	      did_conversion = 1;
5011 	      end_sequence ();
5012 	    }
5013 
5014 	  if (entry_parm != stack_parm)
5015 	    {
5016 	      if (stack_parm == 0)
5017 		{
5018 		  stack_parm
5019 		    = assign_stack_local (GET_MODE (entry_parm),
5020 					  GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
5021 		  /* If this is a memory ref that contains aggregate components,
5022 		     mark it as such for cse and loop optimize.  */
5023 		  MEM_SET_IN_STRUCT_P (stack_parm, aggregate);
5024 		}
5025 
5026 	      if (promoted_mode != nominal_mode)
5027 		{
5028 		  push_to_sequence (conversion_insns);
5029 		  emit_move_insn (validize_mem (stack_parm),
5030 				  validize_mem (entry_parm));
5031 		  conversion_insns = get_insns ();
5032 		  end_sequence ();
5033 		}
5034 	      else
5035 		emit_move_insn (validize_mem (stack_parm),
5036 				validize_mem (entry_parm));
5037 	    }
5038 	  if (current_function_check_memory_usage)
5039 	    {
5040 	      push_to_sequence (conversion_insns);
5041 	      emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
5042 				 XEXP (stack_parm, 0), Pmode,
5043 				 GEN_INT (GET_MODE_SIZE (GET_MODE
5044 							 (entry_parm))),
5045 				 TYPE_MODE (sizetype),
5046 				 GEN_INT (MEMORY_USE_RW),
5047 				 TYPE_MODE (integer_type_node));
5048 
5049 	      conversion_insns = get_insns ();
5050 	      end_sequence ();
5051 	    }
5052 	  DECL_RTL (parm) = stack_parm;
5053 	}
5054 
5055       /* If this "parameter" was the place where we are receiving the
5056 	 function's incoming structure pointer, set up the result.  */
5057       if (parm == function_result_decl)
5058 	{
5059 	  tree result = DECL_RESULT (fndecl);
5060 	  tree restype = TREE_TYPE (result);
5061 
5062 	  DECL_RTL (result)
5063 	    = gen_rtx_MEM (DECL_MODE (result), DECL_RTL (parm));
5064 
5065 	  MEM_SET_IN_STRUCT_P (DECL_RTL (result),
5066 			       AGGREGATE_TYPE_P (restype));
5067 	}
5068 
5069       if (TREE_THIS_VOLATILE (parm))
5070 	MEM_VOLATILE_P (DECL_RTL (parm)) = 1;
5071       if (TREE_READONLY (parm))
5072 	RTX_UNCHANGING_P (DECL_RTL (parm)) = 1;
5073     }
5074 
5075   /* Output all parameter conversion instructions (possibly including calls)
5076      now that all parameters have been copied out of hard registers.  */
5077   emit_insns (conversion_insns);
5078 
5079   last_parm_insn = get_last_insn ();
5080 
5081   current_function_args_size = stack_args_size.constant;
5082 
5083   /* Adjust function incoming argument size for alignment and
5084      minimum length.  */
5085 
5086 #ifdef REG_PARM_STACK_SPACE
5087 #ifndef MAYBE_REG_PARM_STACK_SPACE
5088   current_function_args_size = MAX (current_function_args_size,
5089 				    REG_PARM_STACK_SPACE (fndecl));
5090 #endif
5091 #endif
5092 
5093 #ifdef STACK_BOUNDARY
5094 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
5095 
5096   current_function_args_size
5097     = ((current_function_args_size + STACK_BYTES - 1)
5098        / STACK_BYTES) * STACK_BYTES;
5099 #endif
5100 
5101 #ifdef ARGS_GROW_DOWNWARD
5102   current_function_arg_offset_rtx
5103     = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
5104        : expand_expr (size_binop (MINUS_EXPR, stack_args_size.var,
5105 				  size_int (-stack_args_size.constant)),
5106 		      NULL_RTX, VOIDmode, EXPAND_MEMORY_USE_BAD));
5107 #else
5108   current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
5109 #endif
5110 
5111   /* See how many bytes, if any, of its args a function should try to pop
5112      on return.  */
5113 
5114   current_function_pops_args = RETURN_POPS_ARGS (fndecl, TREE_TYPE (fndecl),
5115 						 current_function_args_size);
5116 
5117   /* For stdarg.h function, save info about
5118      regs and stack space used by the named args.  */
5119 
5120   if (!hide_last_arg)
5121     current_function_args_info = args_so_far;
5122 
5123   /* Set the rtx used for the function return value.  Put this in its
5124      own variable so any optimizers that need this information don't have
5125      to include tree.h.  Do this here so it gets done when an inlined
5126      function gets output.  */
5127 
5128   current_function_return_rtx = DECL_RTL (DECL_RESULT (fndecl));
5129 }
5130 
5131 /* Indicate whether REGNO is an incoming argument to the current function
5132    that was promoted to a wider mode.  If so, return the RTX for the
5133    register (to get its mode).  PMODE and PUNSIGNEDP are set to the mode
5134    that REGNO is promoted from and whether the promotion was signed or
5135    unsigned.  */
5136 
5137 #ifdef PROMOTE_FUNCTION_ARGS
5138 
5139 rtx
5140 promoted_input_arg (regno, pmode, punsignedp)
5141      int regno;
5142      enum machine_mode *pmode;
5143      int *punsignedp;
5144 {
5145   tree arg;
5146 
5147   for (arg = DECL_ARGUMENTS (current_function_decl); arg;
5148        arg = TREE_CHAIN (arg))
5149     if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
5150 	&& REGNO (DECL_INCOMING_RTL (arg)) == regno
5151 	&& TYPE_MODE (DECL_ARG_TYPE (arg)) == TYPE_MODE (TREE_TYPE (arg)))
5152       {
5153 	enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
5154 	int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
5155 
5156 	mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1);
5157 	if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
5158 	    && mode != DECL_MODE (arg))
5159 	  {
5160 	    *pmode = DECL_MODE (arg);
5161 	    *punsignedp = unsignedp;
5162 	    return DECL_INCOMING_RTL (arg);
5163 	  }
5164       }
5165 
5166   return 0;
5167 }
5168 
5169 #endif
5170 
5171 /* Compute the size and offset from the start of the stacked arguments for a
5172    parm passed in mode PASSED_MODE and with type TYPE.
5173 
5174    INITIAL_OFFSET_PTR points to the current offset into the stacked
5175    arguments.
5176 
5177    The starting offset and size for this parm are returned in *OFFSET_PTR
5178    and *ARG_SIZE_PTR, respectively.
5179 
5180    IN_REGS is non-zero if the argument will be passed in registers.  It will
5181    never be set if REG_PARM_STACK_SPACE is not defined.
5182 
5183    FNDECL is the function in which the argument was defined.
5184 
5185    There are two types of rounding that are done.  The first, controlled by
5186    FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
5187    list to be aligned to the specific boundary (in bits).  This rounding
5188    affects the initial and starting offsets, but not the argument size.
5189 
5190    The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
5191    optionally rounds the size of the parm to PARM_BOUNDARY.  The
5192    initial offset is not affected by this rounding, while the size always
5193    is and the starting offset may be.  */
5194 
5195 /*  offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
5196     initial_offset_ptr is positive because locate_and_pad_parm's
5197     callers pass in the total size of args so far as
5198     initial_offset_ptr. arg_size_ptr is always positive.*/
5199 
5200 void
5201 locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
5202 		     initial_offset_ptr, offset_ptr, arg_size_ptr)
5203      enum machine_mode passed_mode;
5204      tree type;
5205      int in_regs;
5206      tree fndecl ATTRIBUTE_UNUSED;
5207      struct args_size *initial_offset_ptr;
5208      struct args_size *offset_ptr;
5209      struct args_size *arg_size_ptr;
5210 {
5211   tree sizetree
5212     = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
5213   enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
5214   int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
5215 
5216 #ifdef REG_PARM_STACK_SPACE
5217   /* If we have found a stack parm before we reach the end of the
5218      area reserved for registers, skip that area.  */
5219   if (! in_regs)
5220     {
5221       int reg_parm_stack_space = 0;
5222 
5223 #ifdef MAYBE_REG_PARM_STACK_SPACE
5224       reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
5225 #else
5226       reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
5227 #endif
5228       if (reg_parm_stack_space > 0)
5229 	{
5230 	  if (initial_offset_ptr->var)
5231 	    {
5232 	      initial_offset_ptr->var
5233 		= size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
5234 			      size_int (reg_parm_stack_space));
5235 	      initial_offset_ptr->constant = 0;
5236 	    }
5237 	  else if (initial_offset_ptr->constant < reg_parm_stack_space)
5238 	    initial_offset_ptr->constant = reg_parm_stack_space;
5239 	}
5240     }
5241 #endif /* REG_PARM_STACK_SPACE */
5242 
5243   arg_size_ptr->var = 0;
5244   arg_size_ptr->constant = 0;
5245 
5246 #ifdef ARGS_GROW_DOWNWARD
5247   if (initial_offset_ptr->var)
5248     {
5249       offset_ptr->constant = 0;
5250       offset_ptr->var = size_binop (MINUS_EXPR, integer_zero_node,
5251 				    initial_offset_ptr->var);
5252     }
5253   else
5254     {
5255       offset_ptr->constant = - initial_offset_ptr->constant;
5256       offset_ptr->var = 0;
5257     }
5258   if (where_pad != none
5259       && (TREE_CODE (sizetree) != INTEGER_CST
5260 	  || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
5261     sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5262   SUB_PARM_SIZE (*offset_ptr, sizetree);
5263   if (where_pad != downward)
5264     pad_to_arg_alignment (offset_ptr, boundary);
5265   if (initial_offset_ptr->var)
5266     {
5267       arg_size_ptr->var = size_binop (MINUS_EXPR,
5268 				      size_binop (MINUS_EXPR,
5269 						  integer_zero_node,
5270 						  initial_offset_ptr->var),
5271 				      offset_ptr->var);
5272     }
5273   else
5274     {
5275       arg_size_ptr->constant = (- initial_offset_ptr->constant
5276 				- offset_ptr->constant);
5277     }
5278 #else /* !ARGS_GROW_DOWNWARD */
5279   pad_to_arg_alignment (initial_offset_ptr, boundary);
5280   *offset_ptr = *initial_offset_ptr;
5281 
5282 #ifdef PUSH_ROUNDING
5283   if (passed_mode != BLKmode)
5284     sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
5285 #endif
5286 
5287   /* Pad_below needs the pre-rounded size to know how much to pad below
5288      so this must be done before rounding up.  */
5289   if (where_pad == downward
5290     /* However, BLKmode args passed in regs have their padding done elsewhere.
5291        The stack slot must be able to hold the entire register.  */
5292       && !(in_regs && passed_mode == BLKmode))
5293     pad_below (offset_ptr, passed_mode, sizetree);
5294 
5295   if (where_pad != none
5296       && (TREE_CODE (sizetree) != INTEGER_CST
5297 	  || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
5298     sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5299 
5300   ADD_PARM_SIZE (*arg_size_ptr, sizetree);
5301 #endif /* ARGS_GROW_DOWNWARD */
5302 }
5303 
5304 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
5305    BOUNDARY is measured in bits, but must be a multiple of a storage unit.  */
5306 
5307 static void
5308 pad_to_arg_alignment (offset_ptr, boundary)
5309      struct args_size *offset_ptr;
5310      int boundary;
5311 {
5312   int boundary_in_bytes = boundary / BITS_PER_UNIT;
5313 
5314   if (boundary > BITS_PER_UNIT)
5315     {
5316       if (offset_ptr->var)
5317 	{
5318 	  offset_ptr->var  =
5319 #ifdef ARGS_GROW_DOWNWARD
5320 	    round_down
5321 #else
5322 	    round_up
5323 #endif
5324 	      (ARGS_SIZE_TREE (*offset_ptr),
5325 	       boundary / BITS_PER_UNIT);
5326 	  offset_ptr->constant = 0; /*?*/
5327 	}
5328       else
5329 	offset_ptr->constant =
5330 #ifdef ARGS_GROW_DOWNWARD
5331 	  FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes);
5332 #else
5333 	  CEIL_ROUND (offset_ptr->constant, boundary_in_bytes);
5334 #endif
5335     }
5336 }
5337 
5338 #ifndef ARGS_GROW_DOWNWARD
5339 static void
5340 pad_below (offset_ptr, passed_mode, sizetree)
5341      struct args_size *offset_ptr;
5342      enum machine_mode passed_mode;
5343      tree sizetree;
5344 {
5345   if (passed_mode != BLKmode)
5346     {
5347       if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
5348 	offset_ptr->constant
5349 	  += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
5350 	       / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
5351 	      - GET_MODE_SIZE (passed_mode));
5352     }
5353   else
5354     {
5355       if (TREE_CODE (sizetree) != INTEGER_CST
5356 	  || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
5357 	{
5358 	  /* Round the size up to multiple of PARM_BOUNDARY bits.  */
5359 	  tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5360 	  /* Add it in.  */
5361 	  ADD_PARM_SIZE (*offset_ptr, s2);
5362 	  SUB_PARM_SIZE (*offset_ptr, sizetree);
5363 	}
5364     }
5365 }
5366 #endif
5367 
5368 #ifdef ARGS_GROW_DOWNWARD
5369 static tree
5370 round_down (value, divisor)
5371      tree value;
5372      int divisor;
5373 {
5374   return size_binop (MULT_EXPR,
5375 		     size_binop (FLOOR_DIV_EXPR, value, size_int (divisor)),
5376 		     size_int (divisor));
5377 }
5378 #endif
5379 
5380 /* Walk the tree of blocks describing the binding levels within a function
5381    and warn about uninitialized variables.
5382    This is done after calling flow_analysis and before global_alloc
5383    clobbers the pseudo-regs to hard regs.  */
5384 
5385 void
5386 uninitialized_vars_warning (block)
5387      tree block;
5388 {
5389   register tree decl, sub;
5390   for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
5391     {
5392       if (TREE_CODE (decl) == VAR_DECL
5393 	  /* These warnings are unreliable for and aggregates
5394 	     because assigning the fields one by one can fail to convince
5395 	     flow.c that the entire aggregate was initialized.
5396 	     Unions are troublesome because members may be shorter.  */
5397 	  && ! AGGREGATE_TYPE_P (TREE_TYPE (decl))
5398 	  && DECL_RTL (decl) != 0
5399 	  && GET_CODE (DECL_RTL (decl)) == REG
5400 	  /* Global optimizations can make it difficult to determine if a
5401 	     particular variable has been initialized.  However, a VAR_DECL
5402 	     with a nonzero DECL_INITIAL had an initializer, so do not
5403 	     claim it is potentially uninitialized.
5404 
5405 	     We do not care about the actual value in DECL_INITIAL, so we do
5406 	     not worry that it may be a dangling pointer.  */
5407 	  && DECL_INITIAL (decl) == NULL_TREE
5408 	  && regno_uninitialized (REGNO (DECL_RTL (decl))))
5409 	warning_with_decl (decl,
5410 			   "`%s' might be used uninitialized in this function");
5411       if (TREE_CODE (decl) == VAR_DECL
5412 	  && DECL_RTL (decl) != 0
5413 	  && GET_CODE (DECL_RTL (decl)) == REG
5414 	  && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
5415 	warning_with_decl (decl,
5416 			   "variable `%s' might be clobbered by `longjmp' or `vfork'");
5417     }
5418   for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
5419     uninitialized_vars_warning (sub);
5420 }
5421 
5422 /* Do the appropriate part of uninitialized_vars_warning
5423    but for arguments instead of local variables.  */
5424 
5425 void
5426 setjmp_args_warning ()
5427 {
5428   register tree decl;
5429   for (decl = DECL_ARGUMENTS (current_function_decl);
5430        decl; decl = TREE_CHAIN (decl))
5431     if (DECL_RTL (decl) != 0
5432 	&& GET_CODE (DECL_RTL (decl)) == REG
5433 	&& regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
5434       warning_with_decl (decl, "argument `%s' might be clobbered by `longjmp' or `vfork'");
5435 }
5436 
5437 /* If this function call setjmp, put all vars into the stack
5438    unless they were declared `register'.  */
5439 
5440 void
5441 setjmp_protect (block)
5442      tree block;
5443 {
5444   register tree decl, sub;
5445   for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
5446     if ((TREE_CODE (decl) == VAR_DECL
5447 	 || TREE_CODE (decl) == PARM_DECL)
5448 	&& DECL_RTL (decl) != 0
5449 	&& (GET_CODE (DECL_RTL (decl)) == REG
5450 	    || (GET_CODE (DECL_RTL (decl)) == MEM
5451 		&& GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF))
5452 	/* If this variable came from an inline function, it must be
5453 	   that its life doesn't overlap the setjmp.  If there was a
5454 	   setjmp in the function, it would already be in memory.  We
5455 	   must exclude such variable because their DECL_RTL might be
5456 	   set to strange things such as virtual_stack_vars_rtx.  */
5457 	&& ! DECL_FROM_INLINE (decl)
5458 	&& (
5459 #ifdef NON_SAVING_SETJMP
5460 	    /* If longjmp doesn't restore the registers,
5461 	       don't put anything in them.  */
5462 	    NON_SAVING_SETJMP
5463 	    ||
5464 #endif
5465 	    ! DECL_REGISTER (decl)))
5466       put_var_into_stack (decl);
5467   for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
5468     setjmp_protect (sub);
5469 }
5470 
5471 /* Like the previous function, but for args instead of local variables.  */
5472 
5473 void
5474 setjmp_protect_args ()
5475 {
5476   register tree decl;
5477   for (decl = DECL_ARGUMENTS (current_function_decl);
5478        decl; decl = TREE_CHAIN (decl))
5479     if ((TREE_CODE (decl) == VAR_DECL
5480 	 || TREE_CODE (decl) == PARM_DECL)
5481 	&& DECL_RTL (decl) != 0
5482 	&& (GET_CODE (DECL_RTL (decl)) == REG
5483 	    || (GET_CODE (DECL_RTL (decl)) == MEM
5484 		&& GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF))
5485 	&& (
5486 	    /* If longjmp doesn't restore the registers,
5487 	       don't put anything in them.  */
5488 #ifdef NON_SAVING_SETJMP
5489 	    NON_SAVING_SETJMP
5490 	    ||
5491 #endif
5492 	    ! DECL_REGISTER (decl)))
5493       put_var_into_stack (decl);
5494 }
5495 
5496 /* Return the context-pointer register corresponding to DECL,
5497    or 0 if it does not need one.  */
5498 
5499 rtx
5500 lookup_static_chain (decl)
5501      tree decl;
5502 {
5503   tree context = decl_function_context (decl);
5504   tree link;
5505 
5506   if (context == 0
5507       || (TREE_CODE (decl) == FUNCTION_DECL && DECL_NO_STATIC_CHAIN (decl)))
5508     return 0;
5509 
5510   /* We treat inline_function_decl as an alias for the current function
5511      because that is the inline function whose vars, types, etc.
5512      are being merged into the current function.
5513      See expand_inline_function.  */
5514   if (context == current_function_decl || context == inline_function_decl)
5515     return virtual_stack_vars_rtx;
5516 
5517   for (link = context_display; link; link = TREE_CHAIN (link))
5518     if (TREE_PURPOSE (link) == context)
5519       return RTL_EXPR_RTL (TREE_VALUE (link));
5520 
5521   abort ();
5522 }
5523 
5524 /* Convert a stack slot address ADDR for variable VAR
5525    (from a containing function)
5526    into an address valid in this function (using a static chain).  */
5527 
5528 rtx
5529 fix_lexical_addr (addr, var)
5530      rtx addr;
5531      tree var;
5532 {
5533   rtx basereg;
5534   HOST_WIDE_INT displacement;
5535   tree context = decl_function_context (var);
5536   struct function *fp;
5537   rtx base = 0;
5538 
5539   /* If this is the present function, we need not do anything.  */
5540   if (context == current_function_decl || context == inline_function_decl)
5541     return addr;
5542 
5543   for (fp = outer_function_chain; fp; fp = fp->next)
5544     if (fp->decl == context)
5545       break;
5546 
5547   if (fp == 0)
5548     abort ();
5549 
5550   if (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == MEM)
5551     addr = XEXP (XEXP (addr, 0), 0);
5552 
5553   /* Decode given address as base reg plus displacement.  */
5554   if (GET_CODE (addr) == REG)
5555     basereg = addr, displacement = 0;
5556   else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
5557     basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
5558   else
5559     abort ();
5560 
5561   /* We accept vars reached via the containing function's
5562      incoming arg pointer and via its stack variables pointer.  */
5563   if (basereg == fp->internal_arg_pointer)
5564     {
5565       /* If reached via arg pointer, get the arg pointer value
5566 	 out of that function's stack frame.
5567 
5568 	 There are two cases:  If a separate ap is needed, allocate a
5569 	 slot in the outer function for it and dereference it that way.
5570 	 This is correct even if the real ap is actually a pseudo.
5571 	 Otherwise, just adjust the offset from the frame pointer to
5572 	 compensate.  */
5573 
5574 #ifdef NEED_SEPARATE_AP
5575       rtx addr;
5576 
5577       if (fp->arg_pointer_save_area == 0)
5578 	fp->arg_pointer_save_area
5579 	  = assign_outer_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0, fp);
5580 
5581       addr = fix_lexical_addr (XEXP (fp->arg_pointer_save_area, 0), var);
5582       addr = memory_address (Pmode, addr);
5583 
5584       base = copy_to_reg (gen_rtx_MEM (Pmode, addr));
5585 #else
5586       displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
5587       base = lookup_static_chain (var);
5588 #endif
5589     }
5590 
5591   else if (basereg == virtual_stack_vars_rtx)
5592     {
5593       /* This is the same code as lookup_static_chain, duplicated here to
5594 	 avoid an extra call to decl_function_context.  */
5595       tree link;
5596 
5597       for (link = context_display; link; link = TREE_CHAIN (link))
5598 	if (TREE_PURPOSE (link) == context)
5599 	  {
5600 	    base = RTL_EXPR_RTL (TREE_VALUE (link));
5601 	    break;
5602 	  }
5603     }
5604 
5605   if (base == 0)
5606     abort ();
5607 
5608   /* Use same offset, relative to appropriate static chain or argument
5609      pointer.  */
5610   return plus_constant (base, displacement);
5611 }
5612 
5613 /* Return the address of the trampoline for entering nested fn FUNCTION.
5614    If necessary, allocate a trampoline (in the stack frame)
5615    and emit rtl to initialize its contents (at entry to this function).  */
5616 
5617 rtx
5618 trampoline_address (function)
5619      tree function;
5620 {
5621   tree link;
5622   tree rtlexp;
5623   rtx tramp;
5624   struct function *fp;
5625   tree fn_context;
5626 
5627   /* Find an existing trampoline and return it.  */
5628   for (link = trampoline_list; link; link = TREE_CHAIN (link))
5629     if (TREE_PURPOSE (link) == function)
5630       return
5631 	round_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0));
5632 
5633   for (fp = outer_function_chain; fp; fp = fp->next)
5634     for (link = fp->trampoline_list; link; link = TREE_CHAIN (link))
5635       if (TREE_PURPOSE (link) == function)
5636 	{
5637 	  tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
5638 				    function);
5639 	  return round_trampoline_addr (tramp);
5640 	}
5641 
5642   /* None exists; we must make one.  */
5643 
5644   /* Find the `struct function' for the function containing FUNCTION.  */
5645   fp = 0;
5646   fn_context = decl_function_context (function);
5647   if (fn_context != current_function_decl
5648       && fn_context != inline_function_decl)
5649     for (fp = outer_function_chain; fp; fp = fp->next)
5650       if (fp->decl == fn_context)
5651 	break;
5652 
5653   /* Allocate run-time space for this trampoline
5654      (usually in the defining function's stack frame).  */
5655 #ifdef ALLOCATE_TRAMPOLINE
5656   tramp = ALLOCATE_TRAMPOLINE (fp);
5657 #else
5658   /* If rounding needed, allocate extra space
5659      to ensure we have TRAMPOLINE_SIZE bytes left after rounding up.  */
5660 #ifdef TRAMPOLINE_ALIGNMENT
5661 #define TRAMPOLINE_REAL_SIZE \
5662   (TRAMPOLINE_SIZE + (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT) - 1)
5663 #else
5664 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
5665 #endif
5666   if (fp != 0)
5667     tramp = assign_outer_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0, fp);
5668   else
5669     tramp = assign_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0);
5670 #endif
5671 
5672   /* Record the trampoline for reuse and note it for later initialization
5673      by expand_function_end.  */
5674   if (fp != 0)
5675     {
5676       push_obstacks (fp->function_maybepermanent_obstack,
5677 		     fp->function_maybepermanent_obstack);
5678       rtlexp = make_node (RTL_EXPR);
5679       RTL_EXPR_RTL (rtlexp) = tramp;
5680       fp->trampoline_list = tree_cons (function, rtlexp, fp->trampoline_list);
5681       pop_obstacks ();
5682     }
5683   else
5684     {
5685       /* Make the RTL_EXPR node temporary, not momentary, so that the
5686 	 trampoline_list doesn't become garbage.  */
5687       int momentary = suspend_momentary ();
5688       rtlexp = make_node (RTL_EXPR);
5689       resume_momentary (momentary);
5690 
5691       RTL_EXPR_RTL (rtlexp) = tramp;
5692       trampoline_list = tree_cons (function, rtlexp, trampoline_list);
5693     }
5694 
5695   tramp = fix_lexical_addr (XEXP (tramp, 0), function);
5696   return round_trampoline_addr (tramp);
5697 }
5698 
5699 /* Given a trampoline address,
5700    round it to multiple of TRAMPOLINE_ALIGNMENT.  */
5701 
5702 static rtx
5703 round_trampoline_addr (tramp)
5704      rtx tramp;
5705 {
5706 #ifdef TRAMPOLINE_ALIGNMENT
5707   /* Round address up to desired boundary.  */
5708   rtx temp = gen_reg_rtx (Pmode);
5709   temp = expand_binop (Pmode, add_optab, tramp,
5710 		       GEN_INT (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT - 1),
5711 		       temp, 0, OPTAB_LIB_WIDEN);
5712   tramp = expand_binop (Pmode, and_optab, temp,
5713 			GEN_INT (- TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT),
5714 			temp, 0, OPTAB_LIB_WIDEN);
5715 #endif
5716   return tramp;
5717 }
5718 
5719 /* The functions identify_blocks and reorder_blocks provide a way to
5720    reorder the tree of BLOCK nodes, for optimizers that reshuffle or
5721    duplicate portions of the RTL code.  Call identify_blocks before
5722    changing the RTL, and call reorder_blocks after.  */
5723 
5724 /* Put all this function's BLOCK nodes including those that are chained
5725    onto the first block into a vector, and return it.
5726    Also store in each NOTE for the beginning or end of a block
5727    the index of that block in the vector.
5728    The arguments are BLOCK, the chain of top-level blocks of the function,
5729    and INSNS, the insn chain of the function.  */
5730 
5731 tree *
5732 identify_blocks (block, insns)
5733      tree block;
5734      rtx insns;
5735 {
5736   int n_blocks;
5737   tree *block_vector;
5738   int *block_stack;
5739   int depth = 0;
5740   int next_block_number = 1;
5741   int current_block_number = 1;
5742   rtx insn;
5743 
5744   if (block == 0)
5745     return 0;
5746 
5747   n_blocks = all_blocks (block, 0);
5748   block_vector = (tree *) xmalloc (n_blocks * sizeof (tree));
5749   block_stack = (int *) alloca (n_blocks * sizeof (int));
5750 
5751   all_blocks (block, block_vector);
5752 
5753   for (insn = insns; insn; insn = NEXT_INSN (insn))
5754     if (GET_CODE (insn) == NOTE)
5755       {
5756 	if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
5757 	  {
5758 	    block_stack[depth++] = current_block_number;
5759 	    current_block_number = next_block_number;
5760 	    NOTE_BLOCK_NUMBER (insn) =  next_block_number++;
5761 	  }
5762 	if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
5763 	  {
5764 	    NOTE_BLOCK_NUMBER (insn) = current_block_number;
5765 	    current_block_number = block_stack[--depth];
5766 	  }
5767       }
5768 
5769   if (n_blocks != next_block_number)
5770     abort ();
5771 
5772   return block_vector;
5773 }
5774 
5775 /* Given BLOCK_VECTOR which was returned by identify_blocks,
5776    and a revised instruction chain, rebuild the tree structure
5777    of BLOCK nodes to correspond to the new order of RTL.
5778    The new block tree is inserted below TOP_BLOCK.
5779    Returns the current top-level block.  */
5780 
5781 tree
5782 reorder_blocks (block_vector, block, insns)
5783      tree *block_vector;
5784      tree block;
5785      rtx insns;
5786 {
5787   tree current_block = block;
5788   rtx insn;
5789 
5790   if (block_vector == 0)
5791     return block;
5792 
5793   /* Prune the old trees away, so that it doesn't get in the way.  */
5794   BLOCK_SUBBLOCKS (current_block) = 0;
5795   BLOCK_CHAIN (current_block) = 0;
5796 
5797   for (insn = insns; insn; insn = NEXT_INSN (insn))
5798     if (GET_CODE (insn) == NOTE)
5799       {
5800 	if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
5801 	  {
5802 	    tree block = block_vector[NOTE_BLOCK_NUMBER (insn)];
5803 	    /* If we have seen this block before, copy it.  */
5804 	    if (TREE_ASM_WRITTEN (block))
5805 	      block = copy_node (block);
5806 	    BLOCK_SUBBLOCKS (block) = 0;
5807 	    TREE_ASM_WRITTEN (block) = 1;
5808 	    BLOCK_SUPERCONTEXT (block) = current_block;
5809 	    BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
5810 	    BLOCK_SUBBLOCKS (current_block) = block;
5811 	    current_block = block;
5812 	    NOTE_SOURCE_FILE (insn) = 0;
5813 	  }
5814 	if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
5815 	  {
5816 	    BLOCK_SUBBLOCKS (current_block)
5817 	      = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
5818 	    current_block = BLOCK_SUPERCONTEXT (current_block);
5819 	    NOTE_SOURCE_FILE (insn) = 0;
5820 	  }
5821       }
5822 
5823   BLOCK_SUBBLOCKS (current_block)
5824     = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
5825   return current_block;
5826 }
5827 
5828 /* Reverse the order of elements in the chain T of blocks,
5829    and return the new head of the chain (old last element).  */
5830 
5831 static tree
5832 blocks_nreverse (t)
5833      tree t;
5834 {
5835   register tree prev = 0, decl, next;
5836   for (decl = t; decl; decl = next)
5837     {
5838       next = BLOCK_CHAIN (decl);
5839       BLOCK_CHAIN (decl) = prev;
5840       prev = decl;
5841     }
5842   return prev;
5843 }
5844 
5845 /* Count the subblocks of the list starting with BLOCK, and list them
5846    all into the vector VECTOR.  Also clear TREE_ASM_WRITTEN in all
5847    blocks.  */
5848 
5849 static int
5850 all_blocks (block, vector)
5851      tree block;
5852      tree *vector;
5853 {
5854   int n_blocks = 0;
5855 
5856   while (block)
5857     {
5858       TREE_ASM_WRITTEN (block) = 0;
5859 
5860       /* Record this block.  */
5861       if (vector)
5862 	vector[n_blocks] = block;
5863 
5864       ++n_blocks;
5865 
5866       /* Record the subblocks, and their subblocks...  */
5867       n_blocks += all_blocks (BLOCK_SUBBLOCKS (block),
5868 			      vector ? vector + n_blocks : 0);
5869       block = BLOCK_CHAIN (block);
5870     }
5871 
5872   return n_blocks;
5873 }
5874 
5875 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
5876    and initialize static variables for generating RTL for the statements
5877    of the function.  */
5878 
5879 void
5880 init_function_start (subr, filename, line)
5881      tree subr;
5882      char *filename;
5883      int line;
5884 {
5885   init_stmt_for_function ();
5886 
5887   cse_not_expected = ! optimize;
5888 
5889   /* Caller save not needed yet.  */
5890   caller_save_needed = 0;
5891 
5892   /* No stack slots have been made yet.  */
5893   stack_slot_list = 0;
5894 
5895   /* There is no stack slot for handling nonlocal gotos.  */
5896   nonlocal_goto_handler_slots = 0;
5897   nonlocal_goto_stack_level = 0;
5898 
5899   /* No labels have been declared for nonlocal use.  */
5900   nonlocal_labels = 0;
5901   nonlocal_goto_handler_labels = 0;
5902 
5903   /* No function calls so far in this function.  */
5904   function_call_count = 0;
5905 
5906   /* No parm regs have been allocated.
5907      (This is important for output_inline_function.)  */
5908   max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
5909 
5910   /* Initialize the RTL mechanism.  */
5911   init_emit ();
5912 
5913   /* Initialize the queue of pending postincrement and postdecrements,
5914      and some other info in expr.c.  */
5915   init_expr ();
5916 
5917   /* We haven't done register allocation yet.  */
5918   reg_renumber = 0;
5919 
5920   init_const_rtx_hash_table ();
5921 
5922   current_function_name = (*decl_printable_name) (subr, 2);
5923 
5924   /* Nonzero if this is a nested function that uses a static chain.  */
5925 
5926   current_function_needs_context
5927     = (decl_function_context (current_function_decl) != 0
5928        && ! DECL_NO_STATIC_CHAIN (current_function_decl));
5929 
5930   /* Set if a call to setjmp is seen.  */
5931   current_function_calls_setjmp = 0;
5932 
5933   /* Set if a call to longjmp is seen.  */
5934   current_function_calls_longjmp = 0;
5935 
5936   current_function_calls_alloca = 0;
5937   current_function_has_nonlocal_label = 0;
5938   current_function_has_nonlocal_goto = 0;
5939   current_function_contains_functions = 0;
5940   current_function_is_leaf = 0;
5941   current_function_sp_is_unchanging = 0;
5942   current_function_uses_only_leaf_regs = 0;
5943   current_function_has_computed_jump = 0;
5944   current_function_is_thunk = 0;
5945 
5946   current_function_returns_pcc_struct = 0;
5947   current_function_returns_struct = 0;
5948   current_function_epilogue_delay_list = 0;
5949   current_function_uses_const_pool = 0;
5950   current_function_uses_pic_offset_table = 0;
5951   current_function_cannot_inline = 0;
5952 
5953   /* We have not yet needed to make a label to jump to for tail-recursion.  */
5954   tail_recursion_label = 0;
5955 
5956   /* We haven't had a need to make a save area for ap yet.  */
5957 
5958   arg_pointer_save_area = 0;
5959 
5960   /* No stack slots allocated yet.  */
5961   frame_offset = 0;
5962 
5963   /* No SAVE_EXPRs in this function yet.  */
5964   save_expr_regs = 0;
5965 
5966   /* No RTL_EXPRs in this function yet.  */
5967   rtl_expr_chain = 0;
5968 
5969   /* Set up to allocate temporaries.  */
5970   init_temp_slots ();
5971 
5972   /* Within function body, compute a type's size as soon it is laid out.  */
5973   immediate_size_expand++;
5974 
5975   /* We haven't made any trampolines for this function yet.  */
5976   trampoline_list = 0;
5977 
5978   init_pending_stack_adjust ();
5979   inhibit_defer_pop = 0;
5980 
5981   current_function_outgoing_args_size = 0;
5982 
5983   /* Prevent ever trying to delete the first instruction of a function.
5984      Also tell final how to output a linenum before the function prologue.
5985      Note linenums could be missing, e.g. when compiling a Java .class file. */
5986   if (line > 0)
5987     emit_line_note (filename, line);
5988 
5989   /* Make sure first insn is a note even if we don't want linenums.
5990      This makes sure the first insn will never be deleted.
5991      Also, final expects a note to appear there.  */
5992   emit_note (NULL_PTR, NOTE_INSN_DELETED);
5993 
5994   /* Set flags used by final.c.  */
5995   if (aggregate_value_p (DECL_RESULT (subr)))
5996     {
5997 #ifdef PCC_STATIC_STRUCT_RETURN
5998       current_function_returns_pcc_struct = 1;
5999 #endif
6000       current_function_returns_struct = 1;
6001     }
6002 
6003   /* Warn if this value is an aggregate type,
6004      regardless of which calling convention we are using for it.  */
6005   if (warn_aggregate_return
6006       && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
6007     warning ("function returns an aggregate");
6008 
6009   current_function_returns_pointer
6010     = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
6011 
6012   /* Indicate that we need to distinguish between the return value of the
6013      present function and the return value of a function being called.  */
6014   rtx_equal_function_value_matters = 1;
6015 
6016   /* Indicate that we have not instantiated virtual registers yet.  */
6017   virtuals_instantiated = 0;
6018 
6019   /* Indicate we have no need of a frame pointer yet.  */
6020   frame_pointer_needed = 0;
6021 
6022   /* By default assume not varargs or stdarg.  */
6023   current_function_varargs = 0;
6024   current_function_stdarg = 0;
6025 }
6026 
6027 /* Indicate that the current function uses extra args
6028    not explicitly mentioned in the argument list in any fashion.  */
6029 
6030 void
6031 mark_varargs ()
6032 {
6033   current_function_varargs = 1;
6034 }
6035 
6036 /* Expand a call to __main at the beginning of a possible main function.  */
6037 
6038 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
6039 #undef HAS_INIT_SECTION
6040 #define HAS_INIT_SECTION
6041 #endif
6042 
6043 #ifndef GEN_CALL__MAIN
6044 #define GEN_CALL__MAIN \
6045   do {									\
6046     emit_library_call (gen_rtx (SYMBOL_REF, Pmode, NAME__MAIN), 0,	\
6047 		       VOIDmode, 0);					\
6048   } while (0)
6049 #endif
6050 
6051 void
6052 expand_main_function ()
6053 {
6054 #if defined(INVOKE__main) || !defined (HAS_INIT_SECTION)
6055   GEN_CALL__MAIN;
6056 #endif /* not HAS_INIT_SECTION */
6057 }
6058 
6059 extern struct obstack permanent_obstack;
6060 
6061 /* Start the RTL for a new function, and set variables used for
6062    emitting RTL.
6063    SUBR is the FUNCTION_DECL node.
6064    PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
6065    the function's parameters, which must be run at any return statement.  */
6066 
6067 void
6068 expand_function_start (subr, parms_have_cleanups)
6069      tree subr;
6070      int parms_have_cleanups;
6071 {
6072   register int i;
6073   tree tem;
6074   rtx last_ptr = NULL_RTX;
6075 
6076   /* Make sure volatile mem refs aren't considered
6077      valid operands of arithmetic insns.  */
6078   init_recog_no_volatile ();
6079 
6080   /* Set this before generating any memory accesses.  */
6081   current_function_check_memory_usage
6082     = (flag_check_memory_usage
6083        && ! DECL_NO_CHECK_MEMORY_USAGE (current_function_decl));
6084 
6085   current_function_instrument_entry_exit
6086     = (flag_instrument_function_entry_exit
6087        && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr));
6088 
6089   /* If function gets a static chain arg, store it in the stack frame.
6090      Do this first, so it gets the first stack slot offset.  */
6091   if (current_function_needs_context)
6092     {
6093       last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
6094 
6095       /* Delay copying static chain if it is not a register to avoid
6096 	 conflicts with regs used for parameters.  */
6097       if (! SMALL_REGISTER_CLASSES
6098 	  || GET_CODE (static_chain_incoming_rtx) == REG)
6099         emit_move_insn (last_ptr, static_chain_incoming_rtx);
6100     }
6101 
6102   /* If the parameters of this function need cleaning up, get a label
6103      for the beginning of the code which executes those cleanups.  This must
6104      be done before doing anything with return_label.  */
6105   if (parms_have_cleanups)
6106     cleanup_label = gen_label_rtx ();
6107   else
6108     cleanup_label = 0;
6109 
6110   /* Make the label for return statements to jump to, if this machine
6111      does not have a one-instruction return and uses an epilogue,
6112      or if it returns a structure, or if it has parm cleanups.  */
6113 #ifdef HAVE_return
6114   if (cleanup_label == 0 && HAVE_return
6115       && ! current_function_instrument_entry_exit
6116       && ! current_function_returns_pcc_struct
6117       && ! (current_function_returns_struct && ! optimize))
6118     return_label = 0;
6119   else
6120     return_label = gen_label_rtx ();
6121 #else
6122   return_label = gen_label_rtx ();
6123 #endif
6124 
6125   /* Initialize rtx used to return the value.  */
6126   /* Do this before assign_parms so that we copy the struct value address
6127      before any library calls that assign parms might generate.  */
6128 
6129   /* Decide whether to return the value in memory or in a register.  */
6130   if (aggregate_value_p (DECL_RESULT (subr)))
6131     {
6132       /* Returning something that won't go in a register.  */
6133       register rtx value_address = 0;
6134 
6135 #ifdef PCC_STATIC_STRUCT_RETURN
6136       if (current_function_returns_pcc_struct)
6137 	{
6138 	  int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
6139 	  value_address = assemble_static_space (size);
6140 	}
6141       else
6142 #endif
6143 	{
6144 	  /* Expect to be passed the address of a place to store the value.
6145 	     If it is passed as an argument, assign_parms will take care of
6146 	     it.  */
6147 	  if (struct_value_incoming_rtx)
6148 	    {
6149 	      value_address = gen_reg_rtx (Pmode);
6150 	      emit_move_insn (value_address, struct_value_incoming_rtx);
6151 	    }
6152 	}
6153       if (value_address)
6154 	{
6155 	  DECL_RTL (DECL_RESULT (subr))
6156 	    = gen_rtx_MEM (DECL_MODE (DECL_RESULT (subr)), value_address);
6157 	  MEM_SET_IN_STRUCT_P (DECL_RTL (DECL_RESULT (subr)),
6158 			       AGGREGATE_TYPE_P (TREE_TYPE
6159 						 (DECL_RESULT
6160 						  (subr))));
6161 	}
6162     }
6163   else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
6164     /* If return mode is void, this decl rtl should not be used.  */
6165     DECL_RTL (DECL_RESULT (subr)) = 0;
6166   else if (parms_have_cleanups || current_function_instrument_entry_exit)
6167     {
6168       /* If function will end with cleanup code for parms,
6169 	 compute the return values into a pseudo reg,
6170 	 which we will copy into the true return register
6171 	 after the cleanups are done.  */
6172 
6173       enum machine_mode mode = DECL_MODE (DECL_RESULT (subr));
6174 
6175 #ifdef PROMOTE_FUNCTION_RETURN
6176       tree type = TREE_TYPE (DECL_RESULT (subr));
6177       int unsignedp = TREE_UNSIGNED (type);
6178 
6179       mode = promote_mode (type, mode, &unsignedp, 1);
6180 #endif
6181 
6182       DECL_RTL (DECL_RESULT (subr)) = gen_reg_rtx (mode);
6183     }
6184   else
6185     /* Scalar, returned in a register.  */
6186     {
6187 #ifdef FUNCTION_OUTGOING_VALUE
6188       DECL_RTL (DECL_RESULT (subr))
6189 	= FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
6190 #else
6191       DECL_RTL (DECL_RESULT (subr))
6192 	= FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
6193 #endif
6194 
6195       /* Mark this reg as the function's return value.  */
6196       if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG)
6197 	{
6198 	  REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1;
6199 	  /* Needed because we may need to move this to memory
6200 	     in case it's a named return value whose address is taken.  */
6201 	  DECL_REGISTER (DECL_RESULT (subr)) = 1;
6202 	}
6203     }
6204 
6205   /* Initialize rtx for parameters and local variables.
6206      In some cases this requires emitting insns.  */
6207 
6208   assign_parms (subr, 0);
6209 
6210   /* Copy the static chain now if it wasn't a register.  The delay is to
6211      avoid conflicts with the parameter passing registers.  */
6212 
6213   if (SMALL_REGISTER_CLASSES && current_function_needs_context)
6214       if (GET_CODE (static_chain_incoming_rtx) != REG)
6215         emit_move_insn (last_ptr, static_chain_incoming_rtx);
6216 
6217   /* The following was moved from init_function_start.
6218      The move is supposed to make sdb output more accurate.  */
6219   /* Indicate the beginning of the function body,
6220      as opposed to parm setup.  */
6221   emit_note (NULL_PTR, NOTE_INSN_FUNCTION_BEG);
6222 
6223   /* If doing stupid allocation, mark parms as born here.  */
6224 
6225   if (GET_CODE (get_last_insn ()) != NOTE)
6226     emit_note (NULL_PTR, NOTE_INSN_DELETED);
6227   parm_birth_insn = get_last_insn ();
6228 
6229   if (obey_regdecls)
6230     {
6231       for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
6232 	use_variable (regno_reg_rtx[i]);
6233 
6234       if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
6235 	use_variable (current_function_internal_arg_pointer);
6236     }
6237 
6238   context_display = 0;
6239   if (current_function_needs_context)
6240     {
6241       /* Fetch static chain values for containing functions.  */
6242       tem = decl_function_context (current_function_decl);
6243       /* If not doing stupid register allocation copy the static chain
6244 	 pointer into a pseudo.  If we have small register classes, copy
6245 	 the value from memory if static_chain_incoming_rtx is a REG.  If
6246 	 we do stupid register allocation, we use the stack address
6247 	 generated above.  */
6248       if (tem && ! obey_regdecls)
6249 	{
6250 	  /* If the static chain originally came in a register, put it back
6251 	     there, then move it out in the next insn.  The reason for
6252 	     this peculiar code is to satisfy function integration.  */
6253 	  if (SMALL_REGISTER_CLASSES
6254 	      && GET_CODE (static_chain_incoming_rtx) == REG)
6255 	    emit_move_insn (static_chain_incoming_rtx, last_ptr);
6256 	  last_ptr = copy_to_reg (static_chain_incoming_rtx);
6257 	}
6258 
6259       while (tem)
6260 	{
6261 	  tree rtlexp = make_node (RTL_EXPR);
6262 
6263 	  RTL_EXPR_RTL (rtlexp) = last_ptr;
6264 	  context_display = tree_cons (tem, rtlexp, context_display);
6265 	  tem = decl_function_context (tem);
6266 	  if (tem == 0)
6267 	    break;
6268 	  /* Chain thru stack frames, assuming pointer to next lexical frame
6269 	     is found at the place we always store it.  */
6270 #ifdef FRAME_GROWS_DOWNWARD
6271 	  last_ptr = plus_constant (last_ptr, - GET_MODE_SIZE (Pmode));
6272 #endif
6273 	  last_ptr = copy_to_reg (gen_rtx_MEM (Pmode,
6274 					       memory_address (Pmode, last_ptr)));
6275 
6276 	  /* If we are not optimizing, ensure that we know that this
6277 	     piece of context is live over the entire function.  */
6278 	  if (! optimize)
6279 	    save_expr_regs = gen_rtx_EXPR_LIST (VOIDmode, last_ptr,
6280 						save_expr_regs);
6281 	}
6282     }
6283 
6284   if (current_function_instrument_entry_exit)
6285     {
6286       rtx fun = DECL_RTL (current_function_decl);
6287       if (GET_CODE (fun) == MEM)
6288 	fun = XEXP (fun, 0);
6289       else
6290 	abort ();
6291       emit_library_call (profile_function_entry_libfunc, 0, VOIDmode, 2,
6292 			 fun, Pmode,
6293 			 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
6294 						     0,
6295 						     hard_frame_pointer_rtx),
6296 			 Pmode);
6297     }
6298 
6299   /* After the display initializations is where the tail-recursion label
6300      should go, if we end up needing one.   Ensure we have a NOTE here
6301      since some things (like trampolines) get placed before this.  */
6302   tail_recursion_reentry = emit_note (NULL_PTR, NOTE_INSN_DELETED);
6303 
6304   /* Evaluate now the sizes of any types declared among the arguments.  */
6305   for (tem = nreverse (get_pending_sizes ()); tem; tem = TREE_CHAIN (tem))
6306     {
6307       expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode,
6308 		   EXPAND_MEMORY_USE_BAD);
6309       /* Flush the queue in case this parameter declaration has
6310 	 side-effects.  */
6311       emit_queue ();
6312     }
6313 
6314   /* Make sure there is a line number after the function entry setup code.  */
6315   force_next_line_note ();
6316 }
6317 
6318 /* Generate RTL for the end of the current function.
6319    FILENAME and LINE are the current position in the source file.
6320 
6321    It is up to language-specific callers to do cleanups for parameters--
6322    or else, supply 1 for END_BINDINGS and we will call expand_end_bindings.  */
6323 
6324 void
6325 expand_function_end (filename, line, end_bindings)
6326      char *filename;
6327      int line;
6328      int end_bindings;
6329 {
6330   register int i;
6331   tree link;
6332 
6333 #ifdef TRAMPOLINE_TEMPLATE
6334   static rtx initial_trampoline;
6335 #endif
6336 
6337 #ifdef NON_SAVING_SETJMP
6338   /* Don't put any variables in registers if we call setjmp
6339      on a machine that fails to restore the registers.  */
6340   if (NON_SAVING_SETJMP && current_function_calls_setjmp)
6341     {
6342       if (DECL_INITIAL (current_function_decl) != error_mark_node)
6343 	setjmp_protect (DECL_INITIAL (current_function_decl));
6344 
6345       setjmp_protect_args ();
6346     }
6347 #endif
6348 
6349   /* Save the argument pointer if a save area was made for it.  */
6350   if (arg_pointer_save_area)
6351     {
6352       /* arg_pointer_save_area may not be a valid memory address, so we
6353 	 have to check it and fix it if necessary.  */
6354       rtx seq;
6355       start_sequence ();
6356       emit_move_insn (validize_mem (arg_pointer_save_area),
6357 		      virtual_incoming_args_rtx);
6358       seq = gen_sequence ();
6359       end_sequence ();
6360       emit_insn_before (seq, tail_recursion_reentry);
6361     }
6362 
6363   /* Initialize any trampolines required by this function.  */
6364   for (link = trampoline_list; link; link = TREE_CHAIN (link))
6365     {
6366       tree function = TREE_PURPOSE (link);
6367       rtx context = lookup_static_chain (function);
6368       rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
6369 #ifdef TRAMPOLINE_TEMPLATE
6370       rtx blktramp;
6371 #endif
6372       rtx seq;
6373 
6374 #ifdef TRAMPOLINE_TEMPLATE
6375       /* First make sure this compilation has a template for
6376 	 initializing trampolines.  */
6377       if (initial_trampoline == 0)
6378 	{
6379 	  end_temporary_allocation ();
6380 	  initial_trampoline
6381 	    = gen_rtx_MEM (BLKmode, assemble_trampoline_template ());
6382 	  resume_temporary_allocation ();
6383 	}
6384 #endif
6385 
6386       /* Generate insns to initialize the trampoline.  */
6387       start_sequence ();
6388       tramp = round_trampoline_addr (XEXP (tramp, 0));
6389 #ifdef TRAMPOLINE_TEMPLATE
6390       blktramp = change_address (initial_trampoline, BLKmode, tramp);
6391       emit_block_move (blktramp, initial_trampoline,
6392 		       GEN_INT (TRAMPOLINE_SIZE),
6393 		       TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
6394 #endif
6395       INITIALIZE_TRAMPOLINE (tramp, XEXP (DECL_RTL (function), 0), context);
6396       seq = get_insns ();
6397       end_sequence ();
6398 
6399       /* Put those insns at entry to the containing function (this one).  */
6400       emit_insns_before (seq, tail_recursion_reentry);
6401     }
6402 
6403   /* If we are doing stack checking and this function makes calls,
6404      do a stack probe at the start of the function to ensure we have enough
6405      space for another stack frame.  */
6406   if (flag_stack_check && ! STACK_CHECK_BUILTIN)
6407     {
6408       rtx insn, seq;
6409 
6410       for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
6411 	if (GET_CODE (insn) == CALL_INSN)
6412 	  {
6413 	    start_sequence ();
6414 	    probe_stack_range (STACK_CHECK_PROTECT,
6415 			       GEN_INT (STACK_CHECK_MAX_FRAME_SIZE));
6416 	    seq = get_insns ();
6417 	    end_sequence ();
6418 	    emit_insns_before (seq, tail_recursion_reentry);
6419 	    break;
6420 	  }
6421     }
6422 
6423   /* Warn about unused parms if extra warnings were specified.  */
6424   if (warn_unused && extra_warnings)
6425     {
6426       tree decl;
6427 
6428       for (decl = DECL_ARGUMENTS (current_function_decl);
6429 	   decl; decl = TREE_CHAIN (decl))
6430 	if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
6431 	    && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
6432 	  warning_with_decl (decl, "unused parameter `%s'");
6433     }
6434 
6435   /* Delete handlers for nonlocal gotos if nothing uses them.  */
6436   if (nonlocal_goto_handler_slots != 0
6437       && ! current_function_has_nonlocal_label)
6438     delete_handlers ();
6439 
6440   /* End any sequences that failed to be closed due to syntax errors.  */
6441   while (in_sequence_p ())
6442     end_sequence ();
6443 
6444   /* Outside function body, can't compute type's actual size
6445      until next function's body starts.  */
6446   immediate_size_expand--;
6447 
6448   /* If doing stupid register allocation,
6449      mark register parms as dying here.  */
6450 
6451   if (obey_regdecls)
6452     {
6453       rtx tem;
6454       for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
6455 	use_variable (regno_reg_rtx[i]);
6456 
6457       /* Likewise for the regs of all the SAVE_EXPRs in the function.  */
6458 
6459       for (tem = save_expr_regs; tem; tem = XEXP (tem, 1))
6460 	{
6461 	  use_variable (XEXP (tem, 0));
6462 	  use_variable_after (XEXP (tem, 0), parm_birth_insn);
6463 	}
6464 
6465       if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
6466 	use_variable (current_function_internal_arg_pointer);
6467     }
6468 
6469   clear_pending_stack_adjust ();
6470   do_pending_stack_adjust ();
6471 
6472   /* Mark the end of the function body.
6473      If control reaches this insn, the function can drop through
6474      without returning a value.  */
6475   emit_note (NULL_PTR, NOTE_INSN_FUNCTION_END);
6476 
6477   /* Must mark the last line number note in the function, so that the test
6478      coverage code can avoid counting the last line twice.  This just tells
6479      the code to ignore the immediately following line note, since there
6480      already exists a copy of this note somewhere above.  This line number
6481      note is still needed for debugging though, so we can't delete it.  */
6482   if (flag_test_coverage)
6483     emit_note (NULL_PTR, NOTE_REPEATED_LINE_NUMBER);
6484 
6485   /* Output a linenumber for the end of the function.
6486      SDB depends on this.  */
6487   emit_line_note_force (filename, line);
6488 
6489   /* Output the label for the actual return from the function,
6490      if one is expected.  This happens either because a function epilogue
6491      is used instead of a return instruction, or because a return was done
6492      with a goto in order to run local cleanups, or because of pcc-style
6493      structure returning.  */
6494 
6495   if (return_label)
6496     emit_label (return_label);
6497 
6498   /* C++ uses this.  */
6499   if (end_bindings)
6500     expand_end_bindings (0, 0, 0);
6501 
6502   /* Now handle any leftover exception regions that may have been
6503      created for the parameters.  */
6504   {
6505     rtx last = get_last_insn ();
6506     rtx label;
6507 
6508     expand_leftover_cleanups ();
6509 
6510     /* If the above emitted any code, may sure we jump around it.  */
6511     if (last != get_last_insn ())
6512       {
6513 	label = gen_label_rtx ();
6514 	last = emit_jump_insn_after (gen_jump (label), last);
6515 	last = emit_barrier_after (last);
6516 	emit_label (label);
6517       }
6518   }
6519 
6520   if (current_function_instrument_entry_exit)
6521     {
6522       rtx fun = DECL_RTL (current_function_decl);
6523       if (GET_CODE (fun) == MEM)
6524 	fun = XEXP (fun, 0);
6525       else
6526 	abort ();
6527       emit_library_call (profile_function_exit_libfunc, 0, VOIDmode, 2,
6528 			 fun, Pmode,
6529 			 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
6530 						     0,
6531 						     hard_frame_pointer_rtx),
6532 			 Pmode);
6533     }
6534 
6535   /* If we had calls to alloca, and this machine needs
6536      an accurate stack pointer to exit the function,
6537      insert some code to save and restore the stack pointer.  */
6538 #ifdef EXIT_IGNORE_STACK
6539   if (! EXIT_IGNORE_STACK)
6540 #endif
6541     if (current_function_calls_alloca)
6542       {
6543 	rtx tem = 0;
6544 
6545 	emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
6546 	emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
6547       }
6548 
6549   /* If scalar return value was computed in a pseudo-reg,
6550      copy that to the hard return register.  */
6551   if (DECL_RTL (DECL_RESULT (current_function_decl)) != 0
6552       && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG
6553       && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl)))
6554 	  >= FIRST_PSEUDO_REGISTER))
6555     {
6556       rtx real_decl_result;
6557 
6558 #ifdef FUNCTION_OUTGOING_VALUE
6559       real_decl_result
6560 	= FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
6561 				   current_function_decl);
6562 #else
6563       real_decl_result
6564 	= FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
6565 			  current_function_decl);
6566 #endif
6567       REG_FUNCTION_VALUE_P (real_decl_result) = 1;
6568       /* If this is a BLKmode structure being returned in registers, then use
6569 	 the mode computed in expand_return.  */
6570       if (GET_MODE (real_decl_result) == BLKmode)
6571 	PUT_MODE (real_decl_result,
6572 		  GET_MODE (DECL_RTL (DECL_RESULT (current_function_decl))));
6573       emit_move_insn (real_decl_result,
6574 		      DECL_RTL (DECL_RESULT (current_function_decl)));
6575       emit_insn (gen_rtx_USE (VOIDmode, real_decl_result));
6576 
6577       /* The delay slot scheduler assumes that current_function_return_rtx
6578 	 holds the hard register containing the return value, not a temporary
6579 	 pseudo.  */
6580       current_function_return_rtx = real_decl_result;
6581     }
6582 
6583   /* If returning a structure, arrange to return the address of the value
6584      in a place where debuggers expect to find it.
6585 
6586      If returning a structure PCC style,
6587      the caller also depends on this value.
6588      And current_function_returns_pcc_struct is not necessarily set.  */
6589   if (current_function_returns_struct
6590       || current_function_returns_pcc_struct)
6591     {
6592       rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
6593       tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
6594 #ifdef FUNCTION_OUTGOING_VALUE
6595       rtx outgoing
6596 	= FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
6597 				   current_function_decl);
6598 #else
6599       rtx outgoing
6600 	= FUNCTION_VALUE (build_pointer_type (type),
6601 			  current_function_decl);
6602 #endif
6603 
6604       /* Mark this as a function return value so integrate will delete the
6605 	 assignment and USE below when inlining this function.  */
6606       REG_FUNCTION_VALUE_P (outgoing) = 1;
6607 
6608       emit_move_insn (outgoing, value_address);
6609       use_variable (outgoing);
6610     }
6611 
6612   /* If this is an implementation of __throw, do what's necessary to
6613      communicate between __builtin_eh_return and the epilogue.  */
6614   expand_eh_return ();
6615 
6616   /* Output a return insn if we are using one.
6617      Otherwise, let the rtl chain end here, to drop through
6618      into the epilogue.  */
6619 
6620 #ifdef HAVE_return
6621   if (HAVE_return)
6622     {
6623       emit_jump_insn (gen_return ());
6624       emit_barrier ();
6625     }
6626 #endif
6627 
6628   /* Fix up any gotos that jumped out to the outermost
6629      binding level of the function.
6630      Must follow emitting RETURN_LABEL.  */
6631 
6632   /* If you have any cleanups to do at this point,
6633      and they need to create temporary variables,
6634      then you will lose.  */
6635   expand_fixups (get_insns ());
6636 }
6637 
6638 /* These arrays record the INSN_UIDs of the prologue and epilogue insns.  */
6639 
6640 static int *prologue;
6641 static int *epilogue;
6642 
6643 /* Create an array that records the INSN_UIDs of INSNS (either a sequence
6644    or a single insn).  */
6645 
6646 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
6647 static int *
6648 record_insns (insns)
6649      rtx insns;
6650 {
6651   int *vec;
6652 
6653   if (GET_CODE (insns) == SEQUENCE)
6654     {
6655       int len = XVECLEN (insns, 0);
6656       vec = (int *) oballoc ((len + 1) * sizeof (int));
6657       vec[len] = 0;
6658       while (--len >= 0)
6659 	vec[len] = INSN_UID (XVECEXP (insns, 0, len));
6660     }
6661   else
6662     {
6663       vec = (int *) oballoc (2 * sizeof (int));
6664       vec[0] = INSN_UID (insns);
6665       vec[1] = 0;
6666     }
6667   return vec;
6668 }
6669 
6670 /* Determine how many INSN_UIDs in VEC are part of INSN.  */
6671 
6672 static int
6673 contains (insn, vec)
6674      rtx insn;
6675      int *vec;
6676 {
6677   register int i, j;
6678 
6679   if (GET_CODE (insn) == INSN
6680       && GET_CODE (PATTERN (insn)) == SEQUENCE)
6681     {
6682       int count = 0;
6683       for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
6684 	for (j = 0; vec[j]; j++)
6685 	  if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == vec[j])
6686 	    count++;
6687       return count;
6688     }
6689   else
6690     {
6691       for (j = 0; vec[j]; j++)
6692 	if (INSN_UID (insn) == vec[j])
6693 	  return 1;
6694     }
6695   return 0;
6696 }
6697 #endif /* HAVE_prologue || HAVE_epilogue */
6698 
6699 /* Generate the prologue and epilogue RTL if the machine supports it.  Thread
6700    this into place with notes indicating where the prologue ends and where
6701    the epilogue begins.  Update the basic block information when possible.  */
6702 
6703 void
6704 thread_prologue_and_epilogue_insns (f)
6705      rtx f ATTRIBUTE_UNUSED;
6706 {
6707   int inserted = 0;
6708 #ifdef HAVE_prologue
6709   rtx prologue_end = NULL_RTX;
6710 #endif
6711 
6712   prologue = 0;
6713 #ifdef HAVE_prologue
6714   if (HAVE_prologue)
6715     {
6716       rtx seq;
6717 
6718       start_sequence ();
6719       seq = gen_prologue();
6720       emit_insn (seq);
6721 
6722       /* Retain a map of the prologue insns.  */
6723       if (GET_CODE (seq) != SEQUENCE)
6724 	seq = get_insns ();
6725       prologue = record_insns (seq);
6726 
6727       prologue_end = emit_note (NULL, NOTE_INSN_PROLOGUE_END);
6728       seq = gen_sequence ();
6729       end_sequence ();
6730 
6731       /* If optimization is off, and perhaps in an empty function,
6732 	 the entry block will have no successors.  */
6733       if (ENTRY_BLOCK_PTR->succ)
6734 	{
6735 	  /* Can't deal with multiple successsors of the entry block.  */
6736 	  if (ENTRY_BLOCK_PTR->succ->succ_next)
6737 	    abort ();
6738 
6739 	  insert_insn_on_edge (seq, ENTRY_BLOCK_PTR->succ);
6740 	  inserted = 1;
6741 	}
6742       else
6743 	emit_insn_after (seq, f);
6744     }
6745 #endif
6746 
6747   epilogue = 0;
6748 #ifdef HAVE_epilogue
6749   if (HAVE_epilogue)
6750     {
6751       edge e;
6752       basic_block bb = 0;
6753       rtx tail = get_last_insn ();
6754 
6755       /* ??? This is gastly.  If function returns were not done via uses,
6756 	 but via mark_regs_live_at_end, we could use insert_insn_on_edge
6757 	 and all of this uglyness would go away.  */
6758 
6759       switch (optimize)
6760 	{
6761 	default:
6762 	  /* If the exit block has no non-fake predecessors, we don't
6763 	     need an epilogue.  Furthermore, only pay attention to the
6764 	     fallthru predecessors; if (conditional) return insns were
6765 	     generated, by definition we do not need to emit epilogue
6766 	     insns.  */
6767 
6768 	  for (e = EXIT_BLOCK_PTR->pred; e ; e = e->pred_next)
6769 	    if ((e->flags & EDGE_FAKE) == 0
6770 		&& (e->flags & EDGE_FALLTHRU) != 0)
6771 	      break;
6772 	  if (e == NULL)
6773 	    break;
6774 
6775 	  /* We can't handle multiple epilogues -- if one is needed,
6776 	     we won't be able to place it multiple times.
6777 
6778 	     ??? Fix epilogue expanders to not assume they are the
6779 	     last thing done compiling the function.  Either that
6780 	     or copy_rtx each insn.
6781 
6782 	     ??? Blah, it's not a simple expression to assert that
6783 	     we've exactly one fallthru exit edge.  */
6784 
6785 	  bb = e->src;
6786 	  tail = bb->end;
6787 
6788 	  /* ??? If the last insn of the basic block is a jump, then we
6789 	     are creating a new basic block.  Wimp out and leave these
6790 	     insns outside any block.  */
6791 	  if (GET_CODE (tail) == JUMP_INSN)
6792 	    bb = 0;
6793 
6794 	  /* FALLTHRU */
6795 	case 0:
6796 	  {
6797 	    rtx prev, seq, first_use;
6798 
6799 	    /* Move the USE insns at the end of a function onto a list.  */
6800 	    prev = tail;
6801 	    if (GET_CODE (prev) == BARRIER
6802 		|| GET_CODE (prev) == NOTE)
6803 	      prev = prev_nonnote_insn (prev);
6804 
6805 	    first_use = 0;
6806 	    if (prev
6807 		&& GET_CODE (prev) == INSN
6808 		&& GET_CODE (PATTERN (prev)) == USE)
6809 	      {
6810 		/* If the end of the block is the use, grab hold of something
6811 		   else so that we emit barriers etc in the right place.  */
6812 		if (prev == tail)
6813 		  {
6814 		    do
6815 		      tail = PREV_INSN (tail);
6816 		    while (GET_CODE (tail) == INSN
6817 			   && GET_CODE (PATTERN (tail)) == USE);
6818 		  }
6819 
6820 		do
6821 		  {
6822 		    rtx use = prev;
6823 		    prev = prev_nonnote_insn (prev);
6824 
6825 		    remove_insn (use);
6826 		    if (first_use)
6827 		      {
6828 			NEXT_INSN (use) = first_use;
6829 			PREV_INSN (first_use) = use;
6830 		      }
6831 		    else
6832 		      NEXT_INSN (use) = NULL_RTX;
6833 		    first_use = use;
6834 		  }
6835 		while (prev
6836 		       && GET_CODE (prev) == INSN
6837 		       && GET_CODE (PATTERN (prev)) == USE);
6838 	      }
6839 
6840 	    /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, the
6841 	       epilogue insns, the USE insns at the end of a function,
6842 	       the jump insn that returns, and then a BARRIER.  */
6843 
6844 	    if (GET_CODE (tail) != BARRIER)
6845 	      {
6846 		prev = next_nonnote_insn (tail);
6847 		if (!prev || GET_CODE (prev) != BARRIER)
6848 		  emit_barrier_after (tail);
6849 	      }
6850 
6851 	    seq = gen_epilogue ();
6852 	    prev = tail;
6853 	    tail = emit_jump_insn_after (seq, tail);
6854 
6855 	    /* Insert the USE insns immediately before the return insn, which
6856 	       must be the last instruction emitted in the sequence.  */
6857 	    if (first_use)
6858 	      emit_insns_before (first_use, tail);
6859 	    emit_note_after (NOTE_INSN_EPILOGUE_BEG, prev);
6860 
6861 	    /* Update the tail of the basic block.  */
6862 	    if (bb)
6863 	      bb->end = tail;
6864 
6865 	    /* Retain a map of the epilogue insns.  */
6866 	    epilogue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : tail);
6867 	  }
6868 	}
6869     }
6870 #endif
6871 
6872   if (inserted)
6873     commit_edge_insertions ();
6874 
6875 #ifdef HAVE_prologue
6876   if (prologue_end)
6877     {
6878       rtx insn, prev;
6879 
6880       /* GDB handles `break f' by setting a breakpoint on the first
6881 	 line note *after* the prologue.  Which means (1) that if
6882 	 there are line number notes before where we inserted the
6883 	 prologue we should move them, and (2) if there is no such
6884 	 note, then we should generate one at the prologue.  */
6885 
6886       for (insn = prologue_end; insn ; insn = prev)
6887 	{
6888 	  prev = PREV_INSN (insn);
6889 	  if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
6890 	    {
6891 	      /* Note that we cannot reorder the first insn in the
6892 		 chain, since rest_of_compilation relies on that
6893 		 remaining constant.  Do the next best thing.  */
6894 	      if (prev == NULL)
6895 		{
6896 		  emit_line_note_after (NOTE_SOURCE_FILE (insn),
6897 					NOTE_LINE_NUMBER (insn),
6898 					prologue_end);
6899 		  NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
6900 		}
6901 	      else
6902 		reorder_insns (insn, insn, prologue_end);
6903 	    }
6904 	}
6905 
6906       insn = NEXT_INSN (prologue_end);
6907       if (! insn || GET_CODE (insn) != NOTE || NOTE_LINE_NUMBER (insn) <= 0)
6908 	{
6909 	  for (insn = next_active_insn (f); insn ; insn = PREV_INSN (insn))
6910 	    {
6911 	      if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
6912 		{
6913 		  emit_line_note_after (NOTE_SOURCE_FILE (insn),
6914 					NOTE_LINE_NUMBER (insn),
6915 					prologue_end);
6916 		  break;
6917 		}
6918 	    }
6919 	}
6920       }
6921   #endif
6922 }
6923 
6924 /* Reposition the prologue-end and epilogue-begin notes after instruction
6925    scheduling and delayed branch scheduling.  */
6926 
6927 void
6928 reposition_prologue_and_epilogue_notes (f)
6929      rtx f ATTRIBUTE_UNUSED;
6930 {
6931 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
6932   /* Reposition the prologue and epilogue notes.  */
6933   if (n_basic_blocks)
6934     {
6935       int len;
6936 
6937       if (prologue)
6938 	{
6939 	  register rtx insn, note = 0;
6940 
6941 	  /* Scan from the beginning until we reach the last prologue insn.
6942 	     We apparently can't depend on basic_block_{head,end} after
6943 	     reorg has run.  */
6944 	  for (len = 0; prologue[len]; len++)
6945 	    ;
6946 	  for (insn = f; len && insn; insn = NEXT_INSN (insn))
6947 	    {
6948 	      if (GET_CODE (insn) == NOTE)
6949 		{
6950 		  if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
6951 		    note = insn;
6952 		}
6953 	      else if ((len -= contains (insn, prologue)) == 0)
6954 		{
6955 		  rtx next;
6956 		  /* Find the prologue-end note if we haven't already, and
6957 		     move it to just after the last prologue insn.  */
6958 		  if (note == 0)
6959 		    {
6960 		      for (note = insn; (note = NEXT_INSN (note));)
6961 			if (GET_CODE (note) == NOTE
6962 			    && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
6963 			  break;
6964 		    }
6965 
6966 		  next = NEXT_INSN (note);
6967 
6968 		  /* Whether or not we can depend on BLOCK_HEAD,
6969 		     attempt to keep it up-to-date.  */
6970 		  if (BLOCK_HEAD (0) == note)
6971 		    BLOCK_HEAD (0) = next;
6972 
6973 		  remove_insn (note);
6974 		  add_insn_after (note, insn);
6975 		}
6976 	    }
6977 	}
6978 
6979       if (epilogue)
6980 	{
6981 	  register rtx insn, note = 0;
6982 
6983 	  /* Scan from the end until we reach the first epilogue insn.
6984 	     We apparently can't depend on basic_block_{head,end} after
6985 	     reorg has run.  */
6986 	  for (len = 0; epilogue[len]; len++)
6987 	    ;
6988 	  for (insn = get_last_insn (); len && insn; insn = PREV_INSN (insn))
6989 	    {
6990 	      if (GET_CODE (insn) == NOTE)
6991 		{
6992 		  if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
6993 		    note = insn;
6994 		}
6995 	      else if ((len -= contains (insn, epilogue)) == 0)
6996 		{
6997 		  /* Find the epilogue-begin note if we haven't already, and
6998 		     move it to just before the first epilogue insn.  */
6999 		  if (note == 0)
7000 		    {
7001 		      for (note = insn; (note = PREV_INSN (note));)
7002 			if (GET_CODE (note) == NOTE
7003 			    && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
7004 			  break;
7005 		    }
7006 
7007 		  /* Whether or not we can depend on BLOCK_HEAD,
7008 		     attempt to keep it up-to-date.  */
7009 		  if (n_basic_blocks
7010 		      && BLOCK_HEAD (n_basic_blocks-1) == insn)
7011 		    BLOCK_HEAD (n_basic_blocks-1) = note;
7012 
7013 		  remove_insn (note);
7014 		  add_insn_before (note, insn);
7015 		}
7016 	    }
7017 	}
7018     }
7019 #endif /* HAVE_prologue or HAVE_epilogue */
7020 }
7021