OSDN Git Service

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