OSDN Git Service

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