OSDN Git Service

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