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