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