OSDN Git Service

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