OSDN Git Service

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