OSDN Git Service

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