OSDN Git Service

Fix typos in comments.
[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 neither. */
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 referring 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    address 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 between 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) || DECL_DEFER_OUTPUT (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) || DECL_DEFER_OUTPUT (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           || TREE_ADDRESSABLE (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 #ifdef STACK_REGS
3501       /* We need this "use" info, because the gcc-register->stack-register
3502          converter in reg-stack.c needs to know which registers are active
3503          at the start of the function call.  The actual parameter loading
3504          instructions are not always available then anymore, since they might
3505          have been optimised away.  */
3506
3507       if (GET_CODE (entry_parm) == REG && !(hide_last_arg && last_named))
3508           emit_insn (gen_rtx (USE, GET_MODE (entry_parm), entry_parm));
3509 #endif
3510
3511       /* ENTRY_PARM is an RTX for the parameter as it arrives,
3512          in the mode in which it arrives.
3513          STACK_PARM is an RTX for a stack slot where the parameter can live
3514          during the function (in case we want to put it there).
3515          STACK_PARM is 0 if no stack slot was pushed for it.
3516
3517          Now output code if necessary to convert ENTRY_PARM to
3518          the type in which this function declares it,
3519          and store that result in an appropriate place,
3520          which may be a pseudo reg, may be STACK_PARM,
3521          or may be a local stack slot if STACK_PARM is 0.
3522
3523          Set DECL_RTL to that place.  */
3524
3525       if (nominal_mode == BLKmode)
3526         {
3527           /* If a BLKmode arrives in registers, copy it to a stack slot.  */
3528           if (GET_CODE (entry_parm) == REG)
3529             {
3530               int size_stored = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
3531                                             UNITS_PER_WORD);
3532
3533               /* Note that we will be storing an integral number of words.
3534                  So we have to be careful to ensure that we allocate an
3535                  integral number of words.  We do this below in the
3536                  assign_stack_local if space was not allocated in the argument
3537                  list.  If it was, this will not work if PARM_BOUNDARY is not
3538                  a multiple of BITS_PER_WORD.  It isn't clear how to fix this
3539                  if it becomes a problem.  */
3540
3541               if (stack_parm == 0)
3542                 {
3543                   stack_parm
3544                     = assign_stack_local (GET_MODE (entry_parm), size_stored, 0);
3545                   /* If this is a memory ref that contains aggregate components,
3546                      mark it as such for cse and loop optimize.  */
3547                   MEM_IN_STRUCT_P (stack_parm) = aggregate;
3548                 }
3549
3550               else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
3551                 abort ();
3552
3553               if (TREE_READONLY (parm))
3554                 RTX_UNCHANGING_P (stack_parm) = 1;
3555
3556               move_block_from_reg (REGNO (entry_parm),
3557                                    validize_mem (stack_parm),
3558                                    size_stored / UNITS_PER_WORD,
3559                                    int_size_in_bytes (TREE_TYPE (parm)));
3560             }
3561           DECL_RTL (parm) = stack_parm;
3562         }
3563       else if (! ((obey_regdecls && ! DECL_REGISTER (parm)
3564                    && ! DECL_INLINE (fndecl))
3565                   /* layout_decl may set this.  */
3566                   || TREE_ADDRESSABLE (parm)
3567                   || TREE_SIDE_EFFECTS (parm)
3568                   /* If -ffloat-store specified, don't put explicit
3569                      float variables into registers.  */
3570                   || (flag_float_store
3571                       && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
3572                /* Always assign pseudo to structure return or item passed
3573                   by invisible reference.  */
3574                || passed_pointer || parm == function_result_decl)
3575         {
3576           /* Store the parm in a pseudoregister during the function, but we
3577              may need to do it in a wider mode.  */
3578
3579           register rtx parmreg;
3580           int regno, regnoi, regnor;
3581
3582           unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
3583           nominal_mode = promote_mode (TREE_TYPE (parm), nominal_mode,
3584                                        &unsignedp, 1);
3585
3586           parmreg = gen_reg_rtx (nominal_mode);
3587           REG_USERVAR_P (parmreg) = 1;
3588
3589           /* If this was an item that we received a pointer to, set DECL_RTL
3590              appropriately.  */
3591           if (passed_pointer)
3592             {
3593               DECL_RTL (parm) = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (passed_type)), parmreg);
3594               MEM_IN_STRUCT_P (DECL_RTL (parm)) = aggregate;
3595             }
3596           else
3597             DECL_RTL (parm) = parmreg;
3598
3599           /* Copy the value into the register.  */
3600           if (GET_MODE (parmreg) != GET_MODE (entry_parm))
3601             {
3602               /* If ENTRY_PARM is a hard register, it might be in a register
3603                  not valid for operating in its mode (e.g., an odd-numbered
3604                  register for a DFmode).  In that case, moves are the only
3605                  thing valid, so we can't do a convert from there.  This
3606                  occurs when the calling sequence allow such misaligned
3607                  usages.
3608
3609                  In addition, the conversion may involve a call, which could
3610                  clobber parameters which haven't been copied to pseudo
3611                  registers yet.  Therefore, we must first copy the parm to
3612                  a pseudo reg here, and save the conversion until after all
3613                  parameters have been moved.  */
3614
3615               rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
3616
3617               emit_move_insn (tempreg, validize_mem (entry_parm));
3618
3619               push_to_sequence (conversion_insns);
3620               convert_move (parmreg, tempreg, unsignedp);
3621               conversion_insns = get_insns ();
3622               end_sequence ();
3623             }
3624           else
3625             emit_move_insn (parmreg, validize_mem (entry_parm));
3626
3627           /* If we were passed a pointer but the actual value
3628              can safely live in a register, put it in one.  */
3629           if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
3630               && ! ((obey_regdecls && ! DECL_REGISTER (parm)
3631                      && ! DECL_INLINE (fndecl))
3632                     /* layout_decl may set this.  */
3633                     || TREE_ADDRESSABLE (parm)
3634                     || TREE_SIDE_EFFECTS (parm)
3635                     /* If -ffloat-store specified, don't put explicit
3636                        float variables into registers.  */
3637                     || (flag_float_store
3638                         && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))
3639             {
3640               /* We can't use nominal_mode, because it will have been set to
3641                  Pmode above.  We must use the actual mode of the parm.  */
3642               parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
3643               REG_USERVAR_P (parmreg) = 1;
3644               emit_move_insn (parmreg, DECL_RTL (parm));
3645               DECL_RTL (parm) = parmreg;
3646               /* STACK_PARM is the pointer, not the parm, and PARMREG is
3647                  now the parm.  */
3648               stack_parm = 0;
3649             }
3650 #ifdef FUNCTION_ARG_CALLEE_COPIES
3651           /* If we are passed an arg by reference and it is our responsibility
3652              to make a copy, do it now.
3653              PASSED_TYPE and PASSED mode now refer to the pointer, not the
3654              original argument, so we must recreate them in the call to
3655              FUNCTION_ARG_CALLEE_COPIES.  */
3656           /* ??? Later add code to handle the case that if the argument isn't
3657              modified, don't do the copy.  */
3658
3659           else if (passed_pointer
3660                    && FUNCTION_ARG_CALLEE_COPIES (args_so_far,
3661                                                   TYPE_MODE (DECL_ARG_TYPE (parm)),
3662                                                   DECL_ARG_TYPE (parm),
3663                                                   ! last_named))
3664             {
3665               rtx copy;
3666               tree type = DECL_ARG_TYPE (parm);
3667
3668               /* This sequence may involve a library call perhaps clobbering
3669                  registers that haven't been copied to pseudos yet.  */
3670
3671               push_to_sequence (conversion_insns);
3672
3673               if (TYPE_SIZE (type) == 0
3674                   || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
3675                 /* This is a variable sized object.  */
3676                 copy = gen_rtx (MEM, BLKmode,
3677                                 allocate_dynamic_stack_space
3678                                 (expr_size (parm), NULL_RTX,
3679                                  TYPE_ALIGN (type)));
3680               else
3681                 copy = assign_stack_temp (TYPE_MODE (type),
3682                                           int_size_in_bytes (type), 1);
3683               MEM_IN_STRUCT_P (copy) = AGGREGATE_TYPE_P (type);
3684
3685               store_expr (parm, copy, 0);
3686               emit_move_insn (parmreg, XEXP (copy, 0));
3687               conversion_insns = get_insns ();
3688               end_sequence ();
3689             }
3690 #endif /* FUNCTION_ARG_CALLEE_COPIES */
3691
3692           /* In any case, record the parm's desired stack location
3693              in case we later discover it must live in the stack. 
3694
3695              If it is a COMPLEX value, store the stack location for both
3696              halves.  */
3697
3698           if (GET_CODE (parmreg) == CONCAT)
3699             regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1)));
3700           else
3701             regno = REGNO (parmreg);
3702
3703           if (regno >= nparmregs)
3704             {
3705               rtx *new;
3706               int old_nparmregs = nparmregs;
3707
3708               nparmregs = regno + 5;
3709               new = (rtx *) oballoc (nparmregs * sizeof (rtx));
3710               bcopy ((char *) parm_reg_stack_loc, (char *) new,
3711                      old_nparmregs * sizeof (rtx));
3712               bzero ((char *) (new + old_nparmregs),
3713                      (nparmregs - old_nparmregs) * sizeof (rtx));
3714               parm_reg_stack_loc = new;
3715             }
3716
3717           if (GET_CODE (parmreg) == CONCAT)
3718             {
3719               enum machine_mode submode = GET_MODE (XEXP (parmreg, 0));
3720
3721               regnor = REGNO (gen_realpart (submode, parmreg));
3722               regnoi = REGNO (gen_imagpart (submode, parmreg));
3723
3724               if (stack_parm != 0)
3725                 {
3726                   parm_reg_stack_loc[regnor]
3727                     = gen_realpart (submode, stack_parm);
3728                   parm_reg_stack_loc[regnoi]
3729                     = gen_imagpart (submode, stack_parm);
3730                 }
3731               else
3732                 {
3733                   parm_reg_stack_loc[regnor] = 0;
3734                   parm_reg_stack_loc[regnoi] = 0;
3735                 }
3736             }
3737           else
3738             parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
3739
3740           /* Mark the register as eliminable if we did no conversion
3741              and it was copied from memory at a fixed offset,
3742              and the arg pointer was not copied to a pseudo-reg.
3743              If the arg pointer is a pseudo reg or the offset formed
3744              an invalid address, such memory-equivalences
3745              as we make here would screw up life analysis for it.  */
3746           if (nominal_mode == passed_mode
3747               && ! conversion_insns
3748               && GET_CODE (entry_parm) == MEM
3749               && entry_parm == stack_parm
3750               && stack_offset.var == 0
3751               && reg_mentioned_p (virtual_incoming_args_rtx,
3752                                   XEXP (entry_parm, 0)))
3753             {
3754               rtx linsn = get_last_insn ();
3755
3756               /* Mark complex types separately.  */
3757               if (GET_CODE (parmreg) == CONCAT)
3758                 {
3759                   REG_NOTES (linsn)
3760                       = gen_rtx (EXPR_LIST, REG_EQUIV,
3761                                  parm_reg_stack_loc[regnoi], REG_NOTES (linsn));
3762
3763                   /* Now search backward for where we set the real part.  */
3764                   for (; linsn != 0
3765                        && ! reg_referenced_p (parm_reg_stack_loc[regnor],
3766                                               PATTERN (linsn));
3767                        linsn = prev_nonnote_insn (linsn))
3768                     ;
3769
3770                   REG_NOTES (linsn)
3771                       = gen_rtx (EXPR_LIST, REG_EQUIV,
3772                                  parm_reg_stack_loc[regnor], REG_NOTES (linsn));
3773                 }
3774               else
3775                 REG_NOTES (linsn)
3776                  = gen_rtx (EXPR_LIST, REG_EQUIV,
3777                             entry_parm, REG_NOTES (linsn));
3778             }
3779
3780           /* For pointer data type, suggest pointer register.  */
3781           if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE)
3782             mark_reg_pointer (parmreg);
3783         }
3784       else
3785         {
3786           /* Value must be stored in the stack slot STACK_PARM
3787              during function execution.  */
3788
3789           if (passed_mode != nominal_mode)
3790             {
3791               /* Conversion is required.   */
3792               rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
3793
3794               emit_move_insn (tempreg, validize_mem (entry_parm));
3795
3796               push_to_sequence (conversion_insns);
3797               entry_parm = convert_to_mode (nominal_mode, tempreg,
3798                                             TREE_UNSIGNED (TREE_TYPE (parm)));
3799               conversion_insns = get_insns ();
3800               end_sequence ();
3801             }
3802
3803           if (entry_parm != stack_parm)
3804             {
3805               if (stack_parm == 0)
3806                 {
3807                   stack_parm
3808                     = assign_stack_local (GET_MODE (entry_parm),
3809                                           GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
3810                   /* If this is a memory ref that contains aggregate components,
3811                      mark it as such for cse and loop optimize.  */
3812                   MEM_IN_STRUCT_P (stack_parm) = aggregate;
3813                 }
3814
3815               if (passed_mode != nominal_mode)
3816                 {
3817                   push_to_sequence (conversion_insns);
3818                   emit_move_insn (validize_mem (stack_parm),
3819                                   validize_mem (entry_parm));
3820                   conversion_insns = get_insns ();
3821                   end_sequence ();
3822                 }
3823               else
3824                 emit_move_insn (validize_mem (stack_parm),
3825                                 validize_mem (entry_parm));
3826             }
3827
3828           DECL_RTL (parm) = stack_parm;
3829         }
3830       
3831       /* If this "parameter" was the place where we are receiving the
3832          function's incoming structure pointer, set up the result.  */
3833       if (parm == function_result_decl)
3834         {
3835           tree result = DECL_RESULT (fndecl);
3836           tree restype = TREE_TYPE (result);
3837
3838           DECL_RTL (result)
3839             = gen_rtx (MEM, DECL_MODE (result), DECL_RTL (parm));
3840
3841           MEM_IN_STRUCT_P (DECL_RTL (result)) = AGGREGATE_TYPE_P (restype);
3842         }
3843
3844       if (TREE_THIS_VOLATILE (parm))
3845         MEM_VOLATILE_P (DECL_RTL (parm)) = 1;
3846       if (TREE_READONLY (parm))
3847         RTX_UNCHANGING_P (DECL_RTL (parm)) = 1;
3848     }
3849
3850   /* Output all parameter conversion instructions (possibly including calls)
3851      now that all parameters have been copied out of hard registers.  */
3852   emit_insns (conversion_insns);
3853
3854   max_parm_reg = max_reg_num ();
3855   last_parm_insn = get_last_insn ();
3856
3857   current_function_args_size = stack_args_size.constant;
3858
3859   /* Adjust function incoming argument size for alignment and
3860      minimum length.  */
3861
3862 #ifdef REG_PARM_STACK_SPACE
3863 #ifndef MAYBE_REG_PARM_STACK_SPACE
3864   current_function_args_size = MAX (current_function_args_size,
3865                                     REG_PARM_STACK_SPACE (fndecl));
3866 #endif
3867 #endif
3868
3869 #ifdef STACK_BOUNDARY
3870 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
3871
3872   current_function_args_size
3873     = ((current_function_args_size + STACK_BYTES - 1)
3874        / STACK_BYTES) * STACK_BYTES;
3875 #endif  
3876
3877 #ifdef ARGS_GROW_DOWNWARD
3878   current_function_arg_offset_rtx
3879     = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
3880        : expand_expr (size_binop (MINUS_EXPR, stack_args_size.var,      
3881                                   size_int (-stack_args_size.constant)),   
3882                       NULL_RTX, VOIDmode, 0));
3883 #else
3884   current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
3885 #endif
3886
3887   /* See how many bytes, if any, of its args a function should try to pop
3888      on return.  */
3889
3890   current_function_pops_args = RETURN_POPS_ARGS (fndecl, TREE_TYPE (fndecl),
3891                                                  current_function_args_size);
3892
3893   /* For stdarg.h function, save info about
3894      regs and stack space used by the named args.  */
3895
3896   if (!hide_last_arg)
3897     current_function_args_info = args_so_far;
3898
3899   /* Set the rtx used for the function return value.  Put this in its
3900      own variable so any optimizers that need this information don't have
3901      to include tree.h.  Do this here so it gets done when an inlined
3902      function gets output.  */
3903
3904   current_function_return_rtx = DECL_RTL (DECL_RESULT (fndecl));
3905 }
3906 \f
3907 /* Indicate whether REGNO is an incoming argument to the current function
3908    that was promoted to a wider mode.  If so, return the RTX for the
3909    register (to get its mode).  PMODE and PUNSIGNEDP are set to the mode
3910    that REGNO is promoted from and whether the promotion was signed or
3911    unsigned.  */
3912
3913 #ifdef PROMOTE_FUNCTION_ARGS
3914
3915 rtx
3916 promoted_input_arg (regno, pmode, punsignedp)
3917      int regno;
3918      enum machine_mode *pmode;
3919      int *punsignedp;
3920 {
3921   tree arg;
3922
3923   for (arg = DECL_ARGUMENTS (current_function_decl); arg;
3924        arg = TREE_CHAIN (arg))
3925     if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
3926         && REGNO (DECL_INCOMING_RTL (arg)) == regno)
3927       {
3928         enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
3929         int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
3930
3931         mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1);
3932         if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
3933             && mode != DECL_MODE (arg))
3934           {
3935             *pmode = DECL_MODE (arg);
3936             *punsignedp = unsignedp;
3937             return DECL_INCOMING_RTL (arg);
3938           }
3939       }
3940
3941   return 0;
3942 }
3943
3944 #endif
3945 \f
3946 /* Compute the size and offset from the start of the stacked arguments for a
3947    parm passed in mode PASSED_MODE and with type TYPE.
3948
3949    INITIAL_OFFSET_PTR points to the current offset into the stacked
3950    arguments.
3951
3952    The starting offset and size for this parm are returned in *OFFSET_PTR
3953    and *ARG_SIZE_PTR, respectively.
3954
3955    IN_REGS is non-zero if the argument will be passed in registers.  It will
3956    never be set if REG_PARM_STACK_SPACE is not defined.
3957
3958    FNDECL is the function in which the argument was defined.
3959
3960    There are two types of rounding that are done.  The first, controlled by
3961    FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
3962    list to be aligned to the specific boundary (in bits).  This rounding
3963    affects the initial and starting offsets, but not the argument size.
3964
3965    The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
3966    optionally rounds the size of the parm to PARM_BOUNDARY.  The
3967    initial offset is not affected by this rounding, while the size always
3968    is and the starting offset may be.  */
3969
3970 /*  offset_ptr will be negative for ARGS_GROW_DOWNWARD case; 
3971     initial_offset_ptr is positive because locate_and_pad_parm's
3972     callers pass in the total size of args so far as
3973     initial_offset_ptr. arg_size_ptr is always positive.*/
3974
3975 void
3976 locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
3977                      initial_offset_ptr, offset_ptr, arg_size_ptr)
3978      enum machine_mode passed_mode;
3979      tree type;
3980      int in_regs;
3981      tree fndecl;
3982      struct args_size *initial_offset_ptr;
3983      struct args_size *offset_ptr;
3984      struct args_size *arg_size_ptr;
3985 {
3986   tree sizetree
3987     = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
3988   enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
3989   int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
3990   int boundary_in_bytes = boundary / BITS_PER_UNIT;
3991   int reg_parm_stack_space = 0;
3992
3993 #ifdef REG_PARM_STACK_SPACE
3994   /* If we have found a stack parm before we reach the end of the
3995      area reserved for registers, skip that area.  */
3996   if (! in_regs)
3997     {
3998 #ifdef MAYBE_REG_PARM_STACK_SPACE
3999       reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
4000 #else
4001       reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
4002 #endif
4003       if (reg_parm_stack_space > 0)
4004         {
4005           if (initial_offset_ptr->var)
4006             {
4007               initial_offset_ptr->var
4008                 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
4009                               size_int (reg_parm_stack_space));
4010               initial_offset_ptr->constant = 0;
4011             }
4012           else if (initial_offset_ptr->constant < reg_parm_stack_space)
4013             initial_offset_ptr->constant = reg_parm_stack_space;
4014         }
4015     }
4016 #endif /* REG_PARM_STACK_SPACE */
4017
4018   arg_size_ptr->var = 0;
4019   arg_size_ptr->constant = 0;
4020
4021 #ifdef ARGS_GROW_DOWNWARD
4022   if (initial_offset_ptr->var)
4023     {
4024       offset_ptr->constant = 0;
4025       offset_ptr->var = size_binop (MINUS_EXPR, integer_zero_node,
4026                                     initial_offset_ptr->var);
4027     }
4028   else
4029     {
4030       offset_ptr->constant = - initial_offset_ptr->constant;
4031       offset_ptr->var = 0;
4032     }
4033   if (where_pad != none
4034       && (TREE_CODE (sizetree) != INTEGER_CST
4035           || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
4036     sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4037   SUB_PARM_SIZE (*offset_ptr, sizetree);
4038   if (where_pad != downward)
4039     pad_to_arg_alignment (offset_ptr, boundary);
4040   if (initial_offset_ptr->var)
4041     {
4042       arg_size_ptr->var = size_binop (MINUS_EXPR,
4043                                       size_binop (MINUS_EXPR,
4044                                                   integer_zero_node,
4045                                                   initial_offset_ptr->var),
4046                                       offset_ptr->var);
4047     }
4048   else
4049     {
4050       arg_size_ptr->constant = (- initial_offset_ptr->constant -
4051                                 offset_ptr->constant); 
4052     }
4053 #else /* !ARGS_GROW_DOWNWARD */
4054   pad_to_arg_alignment (initial_offset_ptr, boundary);
4055   *offset_ptr = *initial_offset_ptr;
4056
4057 #ifdef PUSH_ROUNDING
4058   if (passed_mode != BLKmode)
4059     sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
4060 #endif
4061
4062   /* Pad_below needs the pre-rounded size to know how much to pad below
4063      so this must be done before rounding up.  */
4064   if (where_pad == downward
4065     /* However, BLKmode args passed in regs have their padding done elsewhere.
4066        The stack slot must be able to hold the entire register.  */
4067       && !(in_regs && passed_mode == BLKmode))
4068     pad_below (offset_ptr, passed_mode, sizetree);
4069
4070   if (where_pad != none
4071       && (TREE_CODE (sizetree) != INTEGER_CST
4072           || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
4073     sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4074
4075   ADD_PARM_SIZE (*arg_size_ptr, sizetree);
4076 #endif /* ARGS_GROW_DOWNWARD */
4077 }
4078
4079 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
4080    BOUNDARY is measured in bits, but must be a multiple of a storage unit.  */
4081
4082 static void
4083 pad_to_arg_alignment (offset_ptr, boundary)
4084      struct args_size *offset_ptr;
4085      int boundary;
4086 {
4087   int boundary_in_bytes = boundary / BITS_PER_UNIT;
4088   
4089   if (boundary > BITS_PER_UNIT)
4090     {
4091       if (offset_ptr->var)
4092         {
4093           offset_ptr->var  =
4094 #ifdef ARGS_GROW_DOWNWARD
4095             round_down 
4096 #else
4097             round_up
4098 #endif
4099               (ARGS_SIZE_TREE (*offset_ptr),
4100                boundary / BITS_PER_UNIT);
4101           offset_ptr->constant = 0; /*?*/
4102         }
4103       else
4104         offset_ptr->constant =
4105 #ifdef ARGS_GROW_DOWNWARD
4106           FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes);
4107 #else
4108           CEIL_ROUND (offset_ptr->constant, boundary_in_bytes);
4109 #endif
4110     }
4111 }
4112
4113 static void
4114 pad_below (offset_ptr, passed_mode, sizetree)
4115      struct args_size *offset_ptr;
4116      enum machine_mode passed_mode;
4117      tree sizetree;
4118 {
4119   if (passed_mode != BLKmode)
4120     {
4121       if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
4122         offset_ptr->constant
4123           += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
4124                / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
4125               - GET_MODE_SIZE (passed_mode));
4126     }
4127   else
4128     {
4129       if (TREE_CODE (sizetree) != INTEGER_CST
4130           || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
4131         {
4132           /* Round the size up to multiple of PARM_BOUNDARY bits.  */
4133           tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4134           /* Add it in.  */
4135           ADD_PARM_SIZE (*offset_ptr, s2);
4136           SUB_PARM_SIZE (*offset_ptr, sizetree);
4137         }
4138     }
4139 }
4140
4141 static tree
4142 round_down (value, divisor)
4143      tree value;
4144      int divisor;
4145 {
4146   return size_binop (MULT_EXPR,
4147                      size_binop (FLOOR_DIV_EXPR, value, size_int (divisor)),
4148                      size_int (divisor));
4149 }
4150 \f
4151 /* Walk the tree of blocks describing the binding levels within a function
4152    and warn about uninitialized variables.
4153    This is done after calling flow_analysis and before global_alloc
4154    clobbers the pseudo-regs to hard regs.  */
4155
4156 void
4157 uninitialized_vars_warning (block)
4158      tree block;
4159 {
4160   register tree decl, sub;
4161   for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
4162     {
4163       if (TREE_CODE (decl) == VAR_DECL
4164           /* These warnings are unreliable for and aggregates
4165              because assigning the fields one by one can fail to convince
4166              flow.c that the entire aggregate was initialized.
4167              Unions are troublesome because members may be shorter.  */
4168           && ! AGGREGATE_TYPE_P (TREE_TYPE (decl))
4169           && DECL_RTL (decl) != 0
4170           && GET_CODE (DECL_RTL (decl)) == REG
4171           && regno_uninitialized (REGNO (DECL_RTL (decl))))
4172         warning_with_decl (decl,
4173                            "`%s' might be used uninitialized in this function");
4174       if (TREE_CODE (decl) == VAR_DECL
4175           && DECL_RTL (decl) != 0
4176           && GET_CODE (DECL_RTL (decl)) == REG
4177           && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
4178         warning_with_decl (decl,
4179                            "variable `%s' might be clobbered by `longjmp' or `vfork'");
4180     }
4181   for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
4182     uninitialized_vars_warning (sub);
4183 }
4184
4185 /* Do the appropriate part of uninitialized_vars_warning
4186    but for arguments instead of local variables.  */
4187
4188 void
4189 setjmp_args_warning (block)
4190      tree block;
4191 {
4192   register tree decl;
4193   for (decl = DECL_ARGUMENTS (current_function_decl);
4194        decl; decl = TREE_CHAIN (decl))
4195     if (DECL_RTL (decl) != 0
4196         && GET_CODE (DECL_RTL (decl)) == REG
4197         && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
4198       warning_with_decl (decl, "argument `%s' might be clobbered by `longjmp' or `vfork'");
4199 }
4200
4201 /* If this function call setjmp, put all vars into the stack
4202    unless they were declared `register'.  */
4203
4204 void
4205 setjmp_protect (block)
4206      tree block;
4207 {
4208   register tree decl, sub;
4209   for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
4210     if ((TREE_CODE (decl) == VAR_DECL
4211          || TREE_CODE (decl) == PARM_DECL)
4212         && DECL_RTL (decl) != 0
4213         && GET_CODE (DECL_RTL (decl)) == REG
4214         /* If this variable came from an inline function, it must be
4215            that it's life doesn't overlap the setjmp.  If there was a
4216            setjmp in the function, it would already be in memory.  We
4217            must exclude such variable because their DECL_RTL might be
4218            set to strange things such as virtual_stack_vars_rtx.  */
4219         && ! DECL_FROM_INLINE (decl)
4220         && (
4221 #ifdef NON_SAVING_SETJMP
4222             /* If longjmp doesn't restore the registers,
4223                don't put anything in them.  */
4224             NON_SAVING_SETJMP
4225             ||
4226 #endif
4227             ! DECL_REGISTER (decl)))
4228       put_var_into_stack (decl);
4229   for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
4230     setjmp_protect (sub);
4231 }
4232 \f
4233 /* Like the previous function, but for args instead of local variables.  */
4234
4235 void
4236 setjmp_protect_args ()
4237 {
4238   register tree decl, sub;
4239   for (decl = DECL_ARGUMENTS (current_function_decl);
4240        decl; decl = TREE_CHAIN (decl))
4241     if ((TREE_CODE (decl) == VAR_DECL
4242          || TREE_CODE (decl) == PARM_DECL)
4243         && DECL_RTL (decl) != 0
4244         && GET_CODE (DECL_RTL (decl)) == REG
4245         && (
4246             /* If longjmp doesn't restore the registers,
4247                don't put anything in them.  */
4248 #ifdef NON_SAVING_SETJMP
4249             NON_SAVING_SETJMP
4250             ||
4251 #endif
4252             ! DECL_REGISTER (decl)))
4253       put_var_into_stack (decl);
4254 }
4255 \f
4256 /* Return the context-pointer register corresponding to DECL,
4257    or 0 if it does not need one.  */
4258
4259 rtx
4260 lookup_static_chain (decl)
4261      tree decl;
4262 {
4263   tree context = decl_function_context (decl);
4264   tree link;
4265
4266   if (context == 0)
4267     return 0;
4268   
4269   /* We treat inline_function_decl as an alias for the current function
4270      because that is the inline function whose vars, types, etc.
4271      are being merged into the current function.
4272      See expand_inline_function.  */
4273   if (context == current_function_decl || context == inline_function_decl)
4274     return virtual_stack_vars_rtx;
4275
4276   for (link = context_display; link; link = TREE_CHAIN (link))
4277     if (TREE_PURPOSE (link) == context)
4278       return RTL_EXPR_RTL (TREE_VALUE (link));
4279
4280   abort ();
4281 }
4282 \f
4283 /* Convert a stack slot address ADDR for variable VAR
4284    (from a containing function)
4285    into an address valid in this function (using a static chain).  */
4286
4287 rtx
4288 fix_lexical_addr (addr, var)
4289      rtx addr;
4290      tree var;
4291 {
4292   rtx basereg;
4293   int displacement;
4294   tree context = decl_function_context (var);
4295   struct function *fp;
4296   rtx base = 0;
4297
4298   /* If this is the present function, we need not do anything.  */
4299   if (context == current_function_decl || context == inline_function_decl)
4300     return addr;
4301
4302   for (fp = outer_function_chain; fp; fp = fp->next)
4303     if (fp->decl == context)
4304       break;
4305
4306   if (fp == 0)
4307     abort ();
4308
4309   /* Decode given address as base reg plus displacement.  */
4310   if (GET_CODE (addr) == REG)
4311     basereg = addr, displacement = 0;
4312   else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
4313     basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
4314   else
4315     abort ();
4316
4317   /* We accept vars reached via the containing function's
4318      incoming arg pointer and via its stack variables pointer.  */
4319   if (basereg == fp->internal_arg_pointer)
4320     {
4321       /* If reached via arg pointer, get the arg pointer value
4322          out of that function's stack frame.
4323
4324          There are two cases:  If a separate ap is needed, allocate a
4325          slot in the outer function for it and dereference it that way.
4326          This is correct even if the real ap is actually a pseudo.
4327          Otherwise, just adjust the offset from the frame pointer to
4328          compensate.  */
4329
4330 #ifdef NEED_SEPARATE_AP
4331       rtx addr;
4332
4333       if (fp->arg_pointer_save_area == 0)
4334         fp->arg_pointer_save_area
4335           = assign_outer_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0, fp);
4336
4337       addr = fix_lexical_addr (XEXP (fp->arg_pointer_save_area, 0), var);
4338       addr = memory_address (Pmode, addr);
4339
4340       base = copy_to_reg (gen_rtx (MEM, Pmode, addr));
4341 #else
4342       displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
4343       base = lookup_static_chain (var);
4344 #endif
4345     }
4346
4347   else if (basereg == virtual_stack_vars_rtx)
4348     {
4349       /* This is the same code as lookup_static_chain, duplicated here to
4350          avoid an extra call to decl_function_context.  */
4351       tree link;
4352
4353       for (link = context_display; link; link = TREE_CHAIN (link))
4354         if (TREE_PURPOSE (link) == context)
4355           {
4356             base = RTL_EXPR_RTL (TREE_VALUE (link));
4357             break;
4358           }
4359     }
4360
4361   if (base == 0)
4362     abort ();
4363
4364   /* Use same offset, relative to appropriate static chain or argument
4365      pointer.  */
4366   return plus_constant (base, displacement);
4367 }
4368 \f
4369 /* Return the address of the trampoline for entering nested fn FUNCTION.
4370    If necessary, allocate a trampoline (in the stack frame)
4371    and emit rtl to initialize its contents (at entry to this function).  */
4372
4373 rtx
4374 trampoline_address (function)
4375      tree function;
4376 {
4377   tree link;
4378   tree rtlexp;
4379   rtx tramp;
4380   struct function *fp;
4381   tree fn_context;
4382
4383   /* Find an existing trampoline and return it.  */
4384   for (link = trampoline_list; link; link = TREE_CHAIN (link))
4385     if (TREE_PURPOSE (link) == function)
4386       return
4387         round_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0));
4388
4389   for (fp = outer_function_chain; fp; fp = fp->next)
4390     for (link = fp->trampoline_list; link; link = TREE_CHAIN (link))
4391       if (TREE_PURPOSE (link) == function)
4392         {
4393           tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
4394                                     function);
4395           return round_trampoline_addr (tramp);
4396         }
4397
4398   /* None exists; we must make one.  */
4399
4400   /* Find the `struct function' for the function containing FUNCTION.  */
4401   fp = 0;
4402   fn_context = decl_function_context (function);
4403   if (fn_context != current_function_decl)
4404     for (fp = outer_function_chain; fp; fp = fp->next)
4405       if (fp->decl == fn_context)
4406         break;
4407
4408   /* Allocate run-time space for this trampoline
4409      (usually in the defining function's stack frame).  */
4410 #ifdef ALLOCATE_TRAMPOLINE
4411   tramp = ALLOCATE_TRAMPOLINE (fp);
4412 #else
4413   /* If rounding needed, allocate extra space
4414      to ensure we have TRAMPOLINE_SIZE bytes left after rounding up.  */
4415 #ifdef TRAMPOLINE_ALIGNMENT
4416 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE + TRAMPOLINE_ALIGNMENT - 1)
4417 #else
4418 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
4419 #endif
4420   if (fp != 0)
4421     tramp = assign_outer_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0, fp);
4422   else
4423     tramp = assign_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0);
4424 #endif
4425
4426   /* Record the trampoline for reuse and note it for later initialization
4427      by expand_function_end.  */
4428   if (fp != 0)
4429     {
4430       push_obstacks (fp->function_maybepermanent_obstack,
4431                      fp->function_maybepermanent_obstack);
4432       rtlexp = make_node (RTL_EXPR);
4433       RTL_EXPR_RTL (rtlexp) = tramp;
4434       fp->trampoline_list = tree_cons (function, rtlexp, fp->trampoline_list);
4435       pop_obstacks ();
4436     }
4437   else
4438     {
4439       /* Make the RTL_EXPR node temporary, not momentary, so that the
4440          trampoline_list doesn't become garbage.  */
4441       int momentary = suspend_momentary ();
4442       rtlexp = make_node (RTL_EXPR);
4443       resume_momentary (momentary);
4444
4445       RTL_EXPR_RTL (rtlexp) = tramp;
4446       trampoline_list = tree_cons (function, rtlexp, trampoline_list);
4447     }
4448
4449   tramp = fix_lexical_addr (XEXP (tramp, 0), function);
4450   return round_trampoline_addr (tramp);
4451 }
4452
4453 /* Given a trampoline address,
4454    round it to multiple of TRAMPOLINE_ALIGNMENT.  */
4455
4456 static rtx
4457 round_trampoline_addr (tramp)
4458      rtx tramp;
4459 {
4460 #ifdef TRAMPOLINE_ALIGNMENT
4461   /* Round address up to desired boundary.  */
4462   rtx temp = gen_reg_rtx (Pmode);
4463   temp = expand_binop (Pmode, add_optab, tramp,
4464                        GEN_INT (TRAMPOLINE_ALIGNMENT - 1),
4465                        temp, 0, OPTAB_LIB_WIDEN);
4466   tramp = expand_binop (Pmode, and_optab, temp,
4467                         GEN_INT (- TRAMPOLINE_ALIGNMENT),
4468                         temp, 0, OPTAB_LIB_WIDEN);
4469 #endif
4470   return tramp;
4471 }
4472 \f
4473 /* The functions identify_blocks and reorder_blocks provide a way to
4474    reorder the tree of BLOCK nodes, for optimizers that reshuffle or
4475    duplicate portions of the RTL code.  Call identify_blocks before
4476    changing the RTL, and call reorder_blocks after.  */
4477
4478 /* Put all this function's BLOCK nodes into a vector, and return it.
4479    Also store in each NOTE for the beginning or end of a block
4480    the index of that block in the vector.
4481    The arguments are TOP_BLOCK, the top-level block of the function,
4482    and INSNS, the insn chain of the function.  */
4483
4484 tree *
4485 identify_blocks (top_block, insns)
4486      tree top_block;
4487      rtx insns;
4488 {
4489   int n_blocks;
4490   tree *block_vector;
4491   int *block_stack;
4492   int depth = 0;
4493   int next_block_number = 0;
4494   int current_block_number = 0;
4495   rtx insn;
4496
4497   if (top_block == 0)
4498     return 0;
4499
4500   n_blocks = all_blocks (top_block, 0);
4501   block_vector = (tree *) xmalloc (n_blocks * sizeof (tree));
4502   block_stack = (int *) alloca (n_blocks * sizeof (int));
4503
4504   all_blocks (top_block, block_vector);
4505
4506   for (insn = insns; insn; insn = NEXT_INSN (insn))
4507     if (GET_CODE (insn) == NOTE)
4508       {
4509         if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
4510           {
4511             block_stack[depth++] = current_block_number;
4512             current_block_number = next_block_number;
4513             NOTE_BLOCK_NUMBER (insn) =  next_block_number++;
4514           }
4515         if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
4516           {
4517             current_block_number = block_stack[--depth];
4518             NOTE_BLOCK_NUMBER (insn) = current_block_number;
4519           }
4520       }
4521
4522   return block_vector;
4523 }
4524
4525 /* Given BLOCK_VECTOR which was returned by identify_blocks,
4526    and a revised instruction chain, rebuild the tree structure
4527    of BLOCK nodes to correspond to the new order of RTL.
4528    The new block tree is inserted below TOP_BLOCK.
4529    Returns the current top-level block.  */
4530
4531 tree
4532 reorder_blocks (block_vector, top_block, insns)
4533      tree *block_vector;
4534      tree top_block;
4535      rtx insns;
4536 {
4537   tree current_block = top_block;
4538   rtx insn;
4539
4540   if (block_vector == 0)
4541     return top_block;
4542
4543   /* Prune the old tree away, so that it doesn't get in the way.  */
4544   BLOCK_SUBBLOCKS (current_block) = 0;
4545
4546   for (insn = insns; insn; insn = NEXT_INSN (insn))
4547     if (GET_CODE (insn) == NOTE)
4548       {
4549         if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
4550           {
4551             tree block = block_vector[NOTE_BLOCK_NUMBER (insn)];
4552             /* If we have seen this block before, copy it.  */
4553             if (TREE_ASM_WRITTEN (block))
4554               block = copy_node (block);
4555             BLOCK_SUBBLOCKS (block) = 0;
4556             TREE_ASM_WRITTEN (block) = 1;
4557             BLOCK_SUPERCONTEXT (block) = current_block; 
4558             BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
4559             BLOCK_SUBBLOCKS (current_block) = block;
4560             current_block = block;
4561             NOTE_SOURCE_FILE (insn) = 0;
4562           }
4563         if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
4564           {
4565             BLOCK_SUBBLOCKS (current_block)
4566               = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
4567             current_block = BLOCK_SUPERCONTEXT (current_block);
4568             NOTE_SOURCE_FILE (insn) = 0;
4569           }
4570       }
4571
4572   return current_block;
4573 }
4574
4575 /* Reverse the order of elements in the chain T of blocks,
4576    and return the new head of the chain (old last element).  */
4577
4578 static tree
4579 blocks_nreverse (t)
4580      tree t;
4581 {
4582   register tree prev = 0, decl, next;
4583   for (decl = t; decl; decl = next)
4584     {
4585       next = BLOCK_CHAIN (decl);
4586       BLOCK_CHAIN (decl) = prev;
4587       prev = decl;
4588     }
4589   return prev;
4590 }
4591
4592 /* Count the subblocks of BLOCK, and list them all into the vector VECTOR.
4593    Also clear TREE_ASM_WRITTEN in all blocks.  */
4594
4595 static int
4596 all_blocks (block, vector)
4597      tree block;
4598      tree *vector;
4599 {
4600   int n_blocks = 1;
4601   tree subblocks; 
4602
4603   TREE_ASM_WRITTEN (block) = 0;
4604   /* Record this block.  */
4605   if (vector)
4606     vector[0] = block;
4607
4608   /* Record the subblocks, and their subblocks.  */
4609   for (subblocks = BLOCK_SUBBLOCKS (block);
4610        subblocks; subblocks = BLOCK_CHAIN (subblocks))
4611     n_blocks += all_blocks (subblocks, vector ? vector + n_blocks : 0);
4612
4613   return n_blocks;
4614 }
4615 \f
4616 /* Build bytecode call descriptor for function SUBR. */
4617
4618 rtx
4619 bc_build_calldesc (subr)
4620   tree subr;
4621 {
4622   tree calldesc = 0, arg;
4623   int nargs = 0;
4624
4625   /* Build the argument description vector in reverse order.  */
4626   DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
4627   nargs = 0;
4628
4629   for (arg = DECL_ARGUMENTS (subr); arg; arg = TREE_CHAIN (arg))
4630     {
4631       ++nargs;
4632
4633       calldesc = tree_cons ((tree) 0, size_in_bytes (TREE_TYPE (arg)), calldesc);
4634       calldesc = tree_cons ((tree) 0, bc_runtime_type_code (TREE_TYPE (arg)), calldesc);
4635     }
4636
4637   DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
4638
4639   /* Prepend the function's return type.  */
4640   calldesc = tree_cons ((tree) 0,
4641                         size_in_bytes (TREE_TYPE (TREE_TYPE (subr))),
4642                         calldesc);
4643
4644   calldesc = tree_cons ((tree) 0,
4645                         bc_runtime_type_code (TREE_TYPE (TREE_TYPE (subr))),
4646                         calldesc);
4647
4648   /* Prepend the arg count.  */
4649   calldesc = tree_cons ((tree) 0, build_int_2 (nargs, 0), calldesc);
4650
4651   /* Output the call description vector and get its address.  */
4652   calldesc = build_nt (CONSTRUCTOR, (tree) 0, calldesc);
4653   TREE_TYPE (calldesc) = build_array_type (integer_type_node,
4654                                            build_index_type (build_int_2 (nargs * 2, 0)));
4655
4656   return output_constant_def (calldesc);
4657 }
4658
4659
4660 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
4661    and initialize static variables for generating RTL for the statements
4662    of the function.  */
4663
4664 void
4665 init_function_start (subr, filename, line)
4666      tree subr;
4667      char *filename;
4668      int line;
4669 {
4670   char *junk;
4671
4672   if (output_bytecode)
4673     {
4674       this_function_decl = subr;
4675       this_function_calldesc = bc_build_calldesc (subr);
4676       local_vars_size = 0;
4677       stack_depth = 0;
4678       max_stack_depth = 0;
4679       stmt_expr_depth = 0;
4680       return;
4681     }
4682
4683   init_stmt_for_function ();
4684
4685   cse_not_expected = ! optimize;
4686
4687   /* Caller save not needed yet.  */
4688   caller_save_needed = 0;
4689
4690   /* No stack slots have been made yet.  */
4691   stack_slot_list = 0;
4692
4693   /* There is no stack slot for handling nonlocal gotos.  */
4694   nonlocal_goto_handler_slot = 0;
4695   nonlocal_goto_stack_level = 0;
4696
4697   /* No labels have been declared for nonlocal use.  */
4698   nonlocal_labels = 0;
4699
4700   /* No function calls so far in this function.  */
4701   function_call_count = 0;
4702
4703   /* No parm regs have been allocated.
4704      (This is important for output_inline_function.)  */
4705   max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
4706
4707   /* Initialize the RTL mechanism.  */
4708   init_emit ();
4709
4710   /* Initialize the queue of pending postincrement and postdecrements,
4711      and some other info in expr.c.  */
4712   init_expr ();
4713
4714   /* We haven't done register allocation yet.  */
4715   reg_renumber = 0;
4716
4717   init_const_rtx_hash_table ();
4718
4719   current_function_name = (*decl_printable_name) (subr, &junk);
4720
4721   /* Nonzero if this is a nested function that uses a static chain.  */
4722
4723   current_function_needs_context
4724     = (decl_function_context (current_function_decl) != 0);
4725
4726   /* Set if a call to setjmp is seen.  */
4727   current_function_calls_setjmp = 0;
4728
4729   /* Set if a call to longjmp is seen.  */
4730   current_function_calls_longjmp = 0;
4731
4732   current_function_calls_alloca = 0;
4733   current_function_has_nonlocal_label = 0;
4734   current_function_has_nonlocal_goto = 0;
4735   current_function_contains_functions = 0;
4736
4737   current_function_returns_pcc_struct = 0;
4738   current_function_returns_struct = 0;
4739   current_function_epilogue_delay_list = 0;
4740   current_function_uses_const_pool = 0;
4741   current_function_uses_pic_offset_table = 0;
4742
4743   /* We have not yet needed to make a label to jump to for tail-recursion.  */
4744   tail_recursion_label = 0;
4745
4746   /* We haven't had a need to make a save area for ap yet.  */
4747
4748   arg_pointer_save_area = 0;
4749
4750   /* No stack slots allocated yet.  */
4751   frame_offset = 0;
4752
4753   /* No SAVE_EXPRs in this function yet.  */
4754   save_expr_regs = 0;
4755
4756   /* No RTL_EXPRs in this function yet.  */
4757   rtl_expr_chain = 0;
4758
4759   /* We have not allocated any temporaries yet.  */
4760   temp_slots = 0;
4761   temp_slot_level = 0;
4762   target_temp_slot_level = 0;
4763
4764   /* Within function body, compute a type's size as soon it is laid out.  */
4765   immediate_size_expand++;
4766
4767   /* We haven't made any trampolines for this function yet.  */
4768   trampoline_list = 0;
4769
4770   init_pending_stack_adjust ();
4771   inhibit_defer_pop = 0;
4772
4773   current_function_outgoing_args_size = 0;
4774
4775   /* Initialize the insn lengths.  */
4776   init_insn_lengths ();
4777
4778   /* Prevent ever trying to delete the first instruction of a function.
4779      Also tell final how to output a linenum before the function prologue.  */
4780   emit_line_note (filename, line);
4781
4782   /* Make sure first insn is a note even if we don't want linenums.
4783      This makes sure the first insn will never be deleted.
4784      Also, final expects a note to appear there.  */
4785   emit_note (NULL_PTR, NOTE_INSN_DELETED);
4786
4787   /* Set flags used by final.c.  */
4788   if (aggregate_value_p (DECL_RESULT (subr)))
4789     {
4790 #ifdef PCC_STATIC_STRUCT_RETURN
4791       current_function_returns_pcc_struct = 1;
4792 #endif
4793       current_function_returns_struct = 1;
4794     }
4795
4796   /* Warn if this value is an aggregate type,
4797      regardless of which calling convention we are using for it.  */
4798   if (warn_aggregate_return
4799       && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
4800     warning ("function returns an aggregate");
4801
4802   current_function_returns_pointer
4803     = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
4804
4805   /* Indicate that we need to distinguish between the return value of the
4806      present function and the return value of a function being called.  */
4807   rtx_equal_function_value_matters = 1;
4808
4809   /* Indicate that we have not instantiated virtual registers yet.  */
4810   virtuals_instantiated = 0;
4811
4812   /* Indicate we have no need of a frame pointer yet.  */
4813   frame_pointer_needed = 0;
4814
4815   /* By default assume not varargs.  */
4816   current_function_varargs = 0;
4817 }
4818
4819 /* Indicate that the current function uses extra args
4820    not explicitly mentioned in the argument list in any fashion.  */
4821
4822 void
4823 mark_varargs ()
4824 {
4825   current_function_varargs = 1;
4826 }
4827
4828 /* Expand a call to __main at the beginning of a possible main function.  */
4829
4830 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
4831 #undef HAS_INIT_SECTION
4832 #define HAS_INIT_SECTION
4833 #endif
4834
4835 void
4836 expand_main_function ()
4837 {
4838   if (!output_bytecode)
4839     {
4840       /* The zero below avoids a possible parse error */
4841       0;
4842 #if !defined (HAS_INIT_SECTION)
4843       emit_library_call (gen_rtx (SYMBOL_REF, Pmode, NAME__MAIN), 0,
4844                          VOIDmode, 0);
4845 #endif /* not HAS_INIT_SECTION */
4846     }
4847 }
4848 \f
4849 extern struct obstack permanent_obstack;
4850
4851 /* Expand start of bytecode function. See comment at
4852    expand_function_start below for details. */
4853
4854 void
4855 bc_expand_function_start (subr, parms_have_cleanups)
4856   tree subr;
4857   int parms_have_cleanups;
4858 {
4859   char label[20], *name;
4860   static int nlab;
4861   tree thisarg;
4862   int argsz;
4863
4864   if (TREE_PUBLIC (subr))
4865     bc_globalize_label (IDENTIFIER_POINTER (DECL_NAME (subr)));
4866
4867 #ifdef DEBUG_PRINT_CODE
4868   fprintf (stderr, "\n<func %s>\n", IDENTIFIER_POINTER (DECL_NAME (subr)));
4869 #endif
4870
4871   for (argsz = 0, thisarg = DECL_ARGUMENTS (subr); thisarg; thisarg = TREE_CHAIN (thisarg))
4872     {
4873       if (DECL_RTL (thisarg))
4874         abort ();               /* Should be NULL here I think.  */
4875       else if (TREE_CONSTANT (DECL_SIZE (thisarg)))
4876         {
4877           DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
4878           argsz += TREE_INT_CST_LOW (DECL_SIZE (thisarg));
4879         }
4880       else
4881         {
4882           /* Variable-sized objects are pointers to their storage. */
4883           DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
4884           argsz += POINTER_SIZE;
4885         }
4886     }
4887
4888   bc_begin_function (bc_xstrdup (IDENTIFIER_POINTER (DECL_NAME (subr))));
4889
4890   ASM_GENERATE_INTERNAL_LABEL (label, "LX", nlab);
4891
4892   ++nlab;
4893   name = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
4894   this_function_callinfo = bc_gen_rtx (name, 0, (struct bc_label *) 0);
4895   this_function_bytecode =
4896     bc_emit_trampoline (BYTECODE_LABEL (this_function_callinfo));
4897 }
4898
4899
4900 /* Expand end of bytecode function. See details the comment of
4901    expand_function_end(), below. */
4902
4903 void
4904 bc_expand_function_end ()
4905 {
4906   char *ptrconsts;
4907
4908   expand_null_return ();
4909
4910   /* Emit any fixup code. This must be done before the call to
4911      to BC_END_FUNCTION (), since that will cause the bytecode
4912      segment to be finished off and closed. */
4913
4914   expand_fixups (NULL_RTX);
4915
4916   ptrconsts = bc_end_function ();
4917
4918   bc_align_const (2 /* INT_ALIGN */);
4919
4920   /* If this changes also make sure to change bc-interp.h!  */
4921
4922   bc_emit_const_labeldef (BYTECODE_LABEL (this_function_callinfo));
4923   bc_emit_const ((char *) &max_stack_depth, sizeof max_stack_depth);
4924   bc_emit_const ((char *) &local_vars_size, sizeof local_vars_size);
4925   bc_emit_const_labelref (this_function_bytecode, 0);
4926   bc_emit_const_labelref (ptrconsts, 0);
4927   bc_emit_const_labelref (BYTECODE_LABEL (this_function_calldesc), 0);
4928 }
4929
4930
4931 /* Start the RTL for a new function, and set variables used for
4932    emitting RTL.
4933    SUBR is the FUNCTION_DECL node.
4934    PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
4935    the function's parameters, which must be run at any return statement.  */
4936
4937 void
4938 expand_function_start (subr, parms_have_cleanups)
4939      tree subr;
4940      int parms_have_cleanups;
4941 {
4942   register int i;
4943   tree tem;
4944   rtx last_ptr;
4945
4946   if (output_bytecode)
4947     {
4948       bc_expand_function_start (subr, parms_have_cleanups);
4949       return;
4950     }
4951
4952   /* Make sure volatile mem refs aren't considered
4953      valid operands of arithmetic insns.  */
4954   init_recog_no_volatile ();
4955
4956   /* If function gets a static chain arg, store it in the stack frame.
4957      Do this first, so it gets the first stack slot offset.  */
4958   if (current_function_needs_context)
4959     {
4960       last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
4961
4962 #ifdef SMALL_REGISTER_CLASSES
4963       /* Delay copying static chain if it is not a register to avoid
4964          conflicts with regs used for parameters.  */
4965       if (GET_CODE (static_chain_incoming_rtx) == REG)
4966 #endif
4967         emit_move_insn (last_ptr, static_chain_incoming_rtx);
4968     }
4969
4970   /* If the parameters of this function need cleaning up, get a label
4971      for the beginning of the code which executes those cleanups.  This must
4972      be done before doing anything with return_label.  */
4973   if (parms_have_cleanups)
4974     cleanup_label = gen_label_rtx ();
4975   else
4976     cleanup_label = 0;
4977
4978   /* Make the label for return statements to jump to, if this machine
4979      does not have a one-instruction return and uses an epilogue,
4980      or if it returns a structure, or if it has parm cleanups.  */
4981 #ifdef HAVE_return
4982   if (cleanup_label == 0 && HAVE_return
4983       && ! current_function_returns_pcc_struct
4984       && ! (current_function_returns_struct && ! optimize))
4985     return_label = 0;
4986   else
4987     return_label = gen_label_rtx ();
4988 #else
4989   return_label = gen_label_rtx ();
4990 #endif
4991
4992   /* Initialize rtx used to return the value.  */
4993   /* Do this before assign_parms so that we copy the struct value address
4994      before any library calls that assign parms might generate.  */
4995
4996   /* Decide whether to return the value in memory or in a register.  */
4997   if (aggregate_value_p (DECL_RESULT (subr)))
4998     {
4999       /* Returning something that won't go in a register.  */
5000       register rtx value_address = 0;
5001
5002 #ifdef PCC_STATIC_STRUCT_RETURN
5003       if (current_function_returns_pcc_struct)
5004         {
5005           int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
5006           value_address = assemble_static_space (size);
5007         }
5008       else
5009 #endif
5010         {
5011           /* Expect to be passed the address of a place to store the value.
5012              If it is passed as an argument, assign_parms will take care of
5013              it.  */
5014           if (struct_value_incoming_rtx)
5015             {
5016               value_address = gen_reg_rtx (Pmode);
5017               emit_move_insn (value_address, struct_value_incoming_rtx);
5018             }
5019         }
5020       if (value_address)
5021         {
5022           DECL_RTL (DECL_RESULT (subr))
5023             = gen_rtx (MEM, DECL_MODE (DECL_RESULT (subr)), value_address);
5024           MEM_IN_STRUCT_P (DECL_RTL (DECL_RESULT (subr)))
5025             = AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
5026         }
5027     }
5028   else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
5029     /* If return mode is void, this decl rtl should not be used.  */
5030     DECL_RTL (DECL_RESULT (subr)) = 0;
5031   else if (parms_have_cleanups)
5032     {
5033       /* If function will end with cleanup code for parms,
5034          compute the return values into a pseudo reg,
5035          which we will copy into the true return register
5036          after the cleanups are done.  */
5037
5038       enum machine_mode mode = DECL_MODE (DECL_RESULT (subr));
5039
5040 #ifdef PROMOTE_FUNCTION_RETURN
5041       tree type = TREE_TYPE (DECL_RESULT (subr));
5042       int unsignedp = TREE_UNSIGNED (type);
5043
5044       mode = promote_mode (type, mode, &unsignedp, 1);
5045 #endif
5046
5047       DECL_RTL (DECL_RESULT (subr)) = gen_reg_rtx (mode);
5048     }
5049   else
5050     /* Scalar, returned in a register.  */
5051     {
5052 #ifdef FUNCTION_OUTGOING_VALUE
5053       DECL_RTL (DECL_RESULT (subr))
5054         = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
5055 #else
5056       DECL_RTL (DECL_RESULT (subr))
5057         = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
5058 #endif
5059
5060       /* Mark this reg as the function's return value.  */
5061       if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG)
5062         {
5063           REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1;
5064           /* Needed because we may need to move this to memory
5065              in case it's a named return value whose address is taken.  */
5066           DECL_REGISTER (DECL_RESULT (subr)) = 1;
5067         }
5068     }
5069
5070   /* Initialize rtx for parameters and local variables.
5071      In some cases this requires emitting insns.  */
5072
5073   assign_parms (subr, 0);
5074
5075 #ifdef SMALL_REGISTER_CLASSES
5076   /* Copy the static chain now if it wasn't a register.  The delay is to
5077      avoid conflicts with the parameter passing registers.  */
5078
5079   if (current_function_needs_context)
5080       if (GET_CODE (static_chain_incoming_rtx) != REG)
5081         emit_move_insn (last_ptr, static_chain_incoming_rtx);
5082 #endif
5083
5084   /* The following was moved from init_function_start.
5085      The move is supposed to make sdb output more accurate.  */
5086   /* Indicate the beginning of the function body,
5087      as opposed to parm setup.  */
5088   emit_note (NULL_PTR, NOTE_INSN_FUNCTION_BEG);
5089
5090   /* If doing stupid allocation, mark parms as born here.  */
5091
5092   if (GET_CODE (get_last_insn ()) != NOTE)
5093     emit_note (NULL_PTR, NOTE_INSN_DELETED);
5094   parm_birth_insn = get_last_insn ();
5095
5096   if (obey_regdecls)
5097     {
5098       for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
5099         use_variable (regno_reg_rtx[i]);
5100
5101       if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
5102         use_variable (current_function_internal_arg_pointer);
5103     }
5104
5105   /* Fetch static chain values for containing functions.  */
5106   tem = decl_function_context (current_function_decl);
5107   /* If not doing stupid register allocation copy the static chain
5108      pointer into a pseudo.  If we have small register classes, copy the
5109      value from memory if static_chain_incoming_rtx is a REG.  If we do
5110      stupid register allocation, we use the stack address generated above.  */
5111   if (tem && ! obey_regdecls)
5112     {
5113 #ifdef SMALL_REGISTER_CLASSES
5114       /* If the static chain originally came in a register, put it back
5115          there, then move it out in the next insn.  The reason for
5116          this peculiar code is to satisfy function integration.  */
5117       if (GET_CODE (static_chain_incoming_rtx) == REG)
5118         emit_move_insn (static_chain_incoming_rtx, last_ptr);
5119 #endif
5120
5121       last_ptr = copy_to_reg (static_chain_incoming_rtx);
5122     }
5123
5124   context_display = 0;
5125   while (tem)
5126     {
5127       tree rtlexp = make_node (RTL_EXPR);
5128
5129       RTL_EXPR_RTL (rtlexp) = last_ptr;
5130       context_display = tree_cons (tem, rtlexp, context_display);
5131       tem = decl_function_context (tem);
5132       if (tem == 0)
5133         break;
5134       /* Chain thru stack frames, assuming pointer to next lexical frame
5135          is found at the place we always store it.  */
5136 #ifdef FRAME_GROWS_DOWNWARD
5137       last_ptr = plus_constant (last_ptr, - GET_MODE_SIZE (Pmode));
5138 #endif
5139       last_ptr = copy_to_reg (gen_rtx (MEM, Pmode,
5140                                        memory_address (Pmode, last_ptr)));
5141
5142       /* If we are not optimizing, ensure that we know that this
5143          piece of context is live over the entire function.  */
5144       if (! optimize)
5145         save_expr_regs = gen_rtx (EXPR_LIST, VOIDmode, last_ptr,
5146                                   save_expr_regs);
5147     }
5148
5149   /* After the display initializations is where the tail-recursion label
5150      should go, if we end up needing one.   Ensure we have a NOTE here
5151      since some things (like trampolines) get placed before this.  */
5152   tail_recursion_reentry = emit_note (NULL_PTR, NOTE_INSN_DELETED);
5153
5154   /* Evaluate now the sizes of any types declared among the arguments.  */
5155   for (tem = nreverse (get_pending_sizes ()); tem; tem = TREE_CHAIN (tem))
5156     expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode, 0);
5157
5158   /* Make sure there is a line number after the function entry setup code.  */
5159   force_next_line_note ();
5160 }
5161 \f
5162 /* Generate RTL for the end of the current function.
5163    FILENAME and LINE are the current position in the source file. 
5164
5165    It is up to language-specific callers to do cleanups for parameters--
5166    or else, supply 1 for END_BINDINGS and we will call expand_end_bindings.  */
5167
5168 void
5169 expand_function_end (filename, line, end_bindings)
5170      char *filename;
5171      int line;
5172      int end_bindings;
5173 {
5174   register int i;
5175   tree link;
5176
5177   static rtx initial_trampoline;
5178
5179   if (output_bytecode)
5180     {
5181       bc_expand_function_end ();
5182       return;
5183     }
5184
5185 #ifdef NON_SAVING_SETJMP
5186   /* Don't put any variables in registers if we call setjmp
5187      on a machine that fails to restore the registers.  */
5188   if (NON_SAVING_SETJMP && current_function_calls_setjmp)
5189     {
5190       if (DECL_INITIAL (current_function_decl) != error_mark_node)
5191         setjmp_protect (DECL_INITIAL (current_function_decl));
5192
5193       setjmp_protect_args ();
5194     }
5195 #endif
5196
5197   /* Save the argument pointer if a save area was made for it.  */
5198   if (arg_pointer_save_area)
5199     {
5200       rtx x = gen_move_insn (arg_pointer_save_area, virtual_incoming_args_rtx);
5201       emit_insn_before (x, tail_recursion_reentry);
5202     }
5203
5204   /* Initialize any trampolines required by this function.  */
5205   for (link = trampoline_list; link; link = TREE_CHAIN (link))
5206     {
5207       tree function = TREE_PURPOSE (link);
5208       rtx context = lookup_static_chain (function);
5209       rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
5210       rtx seq;
5211
5212       /* First make sure this compilation has a template for
5213          initializing trampolines.  */
5214       if (initial_trampoline == 0)
5215         {
5216           end_temporary_allocation ();
5217           initial_trampoline
5218             = gen_rtx (MEM, BLKmode, assemble_trampoline_template ());
5219           resume_temporary_allocation ();
5220         }
5221
5222       /* Generate insns to initialize the trampoline.  */
5223       start_sequence ();
5224       tramp = change_address (initial_trampoline, BLKmode,
5225                               round_trampoline_addr (XEXP (tramp, 0)));
5226       emit_block_move (tramp, initial_trampoline, GEN_INT (TRAMPOLINE_SIZE),
5227                        FUNCTION_BOUNDARY / BITS_PER_UNIT);
5228       INITIALIZE_TRAMPOLINE (XEXP (tramp, 0),
5229                              XEXP (DECL_RTL (function), 0), context);
5230       seq = get_insns ();
5231       end_sequence ();
5232
5233       /* Put those insns at entry to the containing function (this one).  */
5234       emit_insns_before (seq, tail_recursion_reentry);
5235     }
5236
5237   /* Warn about unused parms if extra warnings were specified.  */
5238   if (warn_unused && extra_warnings)
5239     {
5240       tree decl;
5241
5242       for (decl = DECL_ARGUMENTS (current_function_decl);
5243            decl; decl = TREE_CHAIN (decl))
5244         if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
5245             && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
5246           warning_with_decl (decl, "unused parameter `%s'");
5247     }
5248
5249   /* Delete handlers for nonlocal gotos if nothing uses them.  */
5250   if (nonlocal_goto_handler_slot != 0 && !current_function_has_nonlocal_label)
5251     delete_handlers ();
5252
5253   /* End any sequences that failed to be closed due to syntax errors.  */
5254   while (in_sequence_p ())
5255     end_sequence ();
5256
5257   /* Outside function body, can't compute type's actual size
5258      until next function's body starts.  */
5259   immediate_size_expand--;
5260
5261   /* If doing stupid register allocation,
5262      mark register parms as dying here.  */
5263
5264   if (obey_regdecls)
5265     {
5266       rtx tem;
5267       for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
5268         use_variable (regno_reg_rtx[i]);
5269
5270       /* Likewise for the regs of all the SAVE_EXPRs in the function.  */
5271
5272       for (tem = save_expr_regs; tem; tem = XEXP (tem, 1))
5273         {
5274           use_variable (XEXP (tem, 0));
5275           use_variable_after (XEXP (tem, 0), parm_birth_insn);
5276         }
5277
5278       if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
5279         use_variable (current_function_internal_arg_pointer);
5280     }
5281
5282   clear_pending_stack_adjust ();
5283   do_pending_stack_adjust ();
5284
5285   /* Mark the end of the function body.
5286      If control reaches this insn, the function can drop through
5287      without returning a value.  */
5288   emit_note (NULL_PTR, NOTE_INSN_FUNCTION_END);
5289
5290   /* Output a linenumber for the end of the function.
5291      SDB depends on this.  */
5292   emit_line_note_force (filename, line);
5293
5294   /* Output the label for the actual return from the function,
5295      if one is expected.  This happens either because a function epilogue
5296      is used instead of a return instruction, or because a return was done
5297      with a goto in order to run local cleanups, or because of pcc-style
5298      structure returning.  */
5299
5300   if (return_label)
5301     emit_label (return_label);
5302
5303   /* C++ uses this.  */
5304   if (end_bindings)
5305     expand_end_bindings (0, 0, 0);
5306
5307   /* If we had calls to alloca, and this machine needs
5308      an accurate stack pointer to exit the function,
5309      insert some code to save and restore the stack pointer.  */
5310 #ifdef EXIT_IGNORE_STACK
5311   if (! EXIT_IGNORE_STACK)
5312 #endif
5313     if (current_function_calls_alloca)
5314       {
5315         rtx tem = 0;
5316
5317         emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
5318         emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
5319       }
5320
5321   /* If scalar return value was computed in a pseudo-reg,
5322      copy that to the hard return register.  */
5323   if (DECL_RTL (DECL_RESULT (current_function_decl)) != 0
5324       && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG
5325       && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl)))
5326           >= FIRST_PSEUDO_REGISTER))
5327     {
5328       rtx real_decl_result;
5329
5330 #ifdef FUNCTION_OUTGOING_VALUE
5331       real_decl_result
5332         = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
5333                                    current_function_decl);
5334 #else
5335       real_decl_result
5336         = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
5337                           current_function_decl);
5338 #endif
5339       REG_FUNCTION_VALUE_P (real_decl_result) = 1;
5340       emit_move_insn (real_decl_result,
5341                       DECL_RTL (DECL_RESULT (current_function_decl)));
5342       emit_insn (gen_rtx (USE, VOIDmode, real_decl_result));
5343     }
5344
5345   /* If returning a structure, arrange to return the address of the value
5346      in a place where debuggers expect to find it.
5347
5348      If returning a structure PCC style,
5349      the caller also depends on this value.
5350      And current_function_returns_pcc_struct is not necessarily set.  */
5351   if (current_function_returns_struct
5352       || current_function_returns_pcc_struct)
5353     {
5354       rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
5355       tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
5356 #ifdef FUNCTION_OUTGOING_VALUE
5357       rtx outgoing
5358         = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
5359                                    current_function_decl);
5360 #else
5361       rtx outgoing
5362         = FUNCTION_VALUE (build_pointer_type (type),
5363                           current_function_decl);
5364 #endif
5365
5366       /* Mark this as a function return value so integrate will delete the
5367          assignment and USE below when inlining this function.  */
5368       REG_FUNCTION_VALUE_P (outgoing) = 1;
5369
5370       emit_move_insn (outgoing, value_address);
5371       use_variable (outgoing);
5372     }
5373
5374   /* Output a return insn if we are using one.
5375      Otherwise, let the rtl chain end here, to drop through
5376      into the epilogue.  */
5377
5378 #ifdef HAVE_return
5379   if (HAVE_return)
5380     {
5381       emit_jump_insn (gen_return ());
5382       emit_barrier ();
5383     }
5384 #endif
5385
5386   /* Fix up any gotos that jumped out to the outermost
5387      binding level of the function.
5388      Must follow emitting RETURN_LABEL.  */
5389
5390   /* If you have any cleanups to do at this point,
5391      and they need to create temporary variables,
5392      then you will lose.  */
5393   expand_fixups (get_insns ());
5394 }
5395 \f
5396 /* These arrays record the INSN_UIDs of the prologue and epilogue insns.  */
5397
5398 static int *prologue;
5399 static int *epilogue;
5400
5401 /* Create an array that records the INSN_UIDs of INSNS (either a sequence
5402    or a single insn).  */
5403
5404 static int *
5405 record_insns (insns)
5406      rtx insns;
5407 {
5408   int *vec;
5409
5410   if (GET_CODE (insns) == SEQUENCE)
5411     {
5412       int len = XVECLEN (insns, 0);
5413       vec = (int *) oballoc ((len + 1) * sizeof (int));
5414       vec[len] = 0;
5415       while (--len >= 0)
5416         vec[len] = INSN_UID (XVECEXP (insns, 0, len));
5417     }
5418   else
5419     {
5420       vec = (int *) oballoc (2 * sizeof (int));
5421       vec[0] = INSN_UID (insns);
5422       vec[1] = 0;
5423     }
5424   return vec;
5425 }
5426
5427 /* Determine how many INSN_UIDs in VEC are part of INSN.  */
5428
5429 static int
5430 contains (insn, vec)
5431      rtx insn;
5432      int *vec;
5433 {
5434   register int i, j;
5435
5436   if (GET_CODE (insn) == INSN
5437       && GET_CODE (PATTERN (insn)) == SEQUENCE)
5438     {
5439       int count = 0;
5440       for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
5441         for (j = 0; vec[j]; j++)
5442           if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == vec[j])
5443             count++;
5444       return count;
5445     }
5446   else
5447     {
5448       for (j = 0; vec[j]; j++)
5449         if (INSN_UID (insn) == vec[j])
5450           return 1;
5451     }
5452   return 0;
5453 }
5454
5455 /* Generate the prologue and epilogue RTL if the machine supports it.  Thread
5456    this into place with notes indicating where the prologue ends and where
5457    the epilogue begins.  Update the basic block information when possible.  */
5458
5459 void
5460 thread_prologue_and_epilogue_insns (f)
5461      rtx f;
5462 {
5463 #ifdef HAVE_prologue
5464   if (HAVE_prologue)
5465     {
5466       rtx head, seq, insn;
5467
5468       /* The first insn (a NOTE_INSN_DELETED) is followed by zero or more
5469          prologue insns and a NOTE_INSN_PROLOGUE_END.  */
5470       emit_note_after (NOTE_INSN_PROLOGUE_END, f);
5471       seq = gen_prologue ();
5472       head = emit_insn_after (seq, f);
5473
5474       /* Include the new prologue insns in the first block.  Ignore them
5475          if they form a basic block unto themselves.  */
5476       if (basic_block_head && n_basic_blocks
5477           && GET_CODE (basic_block_head[0]) != CODE_LABEL)
5478         basic_block_head[0] = NEXT_INSN (f);
5479
5480       /* Retain a map of the prologue insns.  */
5481       prologue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : head);
5482     }
5483   else
5484 #endif
5485     prologue = 0;
5486
5487 #ifdef HAVE_epilogue
5488   if (HAVE_epilogue)
5489     {
5490       rtx insn = get_last_insn ();
5491       rtx prev = prev_nonnote_insn (insn);
5492
5493       /* If we end with a BARRIER, we don't need an epilogue.  */
5494       if (! (prev && GET_CODE (prev) == BARRIER))
5495         {
5496           rtx tail, seq, tem;
5497           rtx first_use = 0;
5498           rtx last_use = 0;
5499
5500           /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, the
5501              epilogue insns, the USE insns at the end of a function,
5502              the jump insn that returns, and then a BARRIER.  */
5503
5504           /* Move the USE insns at the end of a function onto a list.  */
5505           while (prev
5506                  && GET_CODE (prev) == INSN
5507                  && GET_CODE (PATTERN (prev)) == USE)
5508             {
5509               tem = prev;
5510               prev = prev_nonnote_insn (prev);
5511
5512               NEXT_INSN (PREV_INSN (tem)) = NEXT_INSN (tem);
5513               PREV_INSN (NEXT_INSN (tem)) = PREV_INSN (tem);
5514               if (first_use)
5515                 {
5516                   NEXT_INSN (tem) = first_use;
5517                   PREV_INSN (first_use) = tem;
5518                 }
5519               first_use = tem;
5520               if (!last_use)
5521                 last_use = tem;
5522             }
5523
5524           emit_barrier_after (insn);
5525
5526           seq = gen_epilogue ();
5527           tail = emit_jump_insn_after (seq, insn);
5528
5529           /* Insert the USE insns immediately before the return insn, which
5530              must be the first instruction before the final barrier.  */
5531           if (first_use)
5532             {
5533               tem = prev_nonnote_insn (get_last_insn ());
5534               NEXT_INSN (PREV_INSN (tem)) = first_use;
5535               PREV_INSN (first_use) = PREV_INSN (tem);
5536               PREV_INSN (tem) = last_use;
5537               NEXT_INSN (last_use) = tem;
5538             }
5539
5540           emit_note_after (NOTE_INSN_EPILOGUE_BEG, insn);
5541
5542           /* Include the new epilogue insns in the last block.  Ignore
5543              them if they form a basic block unto themselves.  */
5544           if (basic_block_end && n_basic_blocks
5545               && GET_CODE (basic_block_end[n_basic_blocks - 1]) != JUMP_INSN)
5546             basic_block_end[n_basic_blocks - 1] = tail;
5547
5548           /* Retain a map of the epilogue insns.  */
5549           epilogue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : tail);
5550           return;
5551         }
5552     }
5553 #endif
5554   epilogue = 0;
5555 }
5556
5557 /* Reposition the prologue-end and epilogue-begin notes after instruction
5558    scheduling and delayed branch scheduling.  */
5559
5560 void
5561 reposition_prologue_and_epilogue_notes (f)
5562      rtx f;
5563 {
5564 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
5565   /* Reposition the prologue and epilogue notes.  */
5566   if (n_basic_blocks)
5567     {
5568       rtx next, prev;
5569       int len;
5570
5571       if (prologue)
5572         {
5573           register rtx insn, note = 0;
5574
5575           /* Scan from the beginning until we reach the last prologue insn.
5576              We apparently can't depend on basic_block_{head,end} after
5577              reorg has run.  */
5578           for (len = 0; prologue[len]; len++)
5579             ;
5580           for (insn = f; len && insn; insn = NEXT_INSN (insn))
5581             {
5582               if (GET_CODE (insn) == NOTE)
5583                 {
5584                   if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
5585                     note = insn;
5586                 }
5587               else if ((len -= contains (insn, prologue)) == 0)
5588                 {
5589                   /* Find the prologue-end note if we haven't already, and
5590                      move it to just after the last prologue insn.  */
5591                   if (note == 0)
5592                     {
5593                       for (note = insn; note = NEXT_INSN (note);)
5594                         if (GET_CODE (note) == NOTE
5595                             && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
5596                           break;
5597                     }
5598                   next = NEXT_INSN (note);
5599                   prev = PREV_INSN (note);
5600                   if (prev)
5601                     NEXT_INSN (prev) = next;
5602                   if (next)
5603                     PREV_INSN (next) = prev;
5604                   add_insn_after (note, insn);
5605                 }
5606             }
5607         }
5608
5609       if (epilogue)
5610         {
5611           register rtx insn, note = 0;
5612
5613           /* Scan from the end until we reach the first epilogue insn.
5614              We apparently can't depend on basic_block_{head,end} after
5615              reorg has run.  */
5616           for (len = 0; epilogue[len]; len++)
5617             ;
5618           for (insn = get_last_insn (); len && insn; insn = PREV_INSN (insn))
5619             {
5620               if (GET_CODE (insn) == NOTE)
5621                 {
5622                   if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
5623                     note = insn;
5624                 }
5625               else if ((len -= contains (insn, epilogue)) == 0)
5626                 {
5627                   /* Find the epilogue-begin note if we haven't already, and
5628                      move it to just before the first epilogue insn.  */
5629                   if (note == 0)
5630                     {
5631                       for (note = insn; note = PREV_INSN (note);)
5632                         if (GET_CODE (note) == NOTE
5633                             && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
5634                           break;
5635                     }
5636                   next = NEXT_INSN (note);
5637                   prev = PREV_INSN (note);
5638                   if (prev)
5639                     NEXT_INSN (prev) = next;
5640                   if (next)
5641                     PREV_INSN (next) = prev;
5642                   add_insn_after (note, PREV_INSN (insn));
5643                 }
5644             }
5645         }
5646     }
5647 #endif /* HAVE_prologue or HAVE_epilogue */
5648 }