OSDN Git Service

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