1 /* Expands front end tree to back end RTL for GNU C-Compiler
2 Copyright (C) 1987, 88, 89, 91, 92, 93, 1994 Free Software Foundation, Inc.
4 This file is part of GNU CC.
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)
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.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This file handles the generation of rtl code from tree structure
22 at the level of the function as a whole.
23 It creates the rtl expressions for parameters and auto variables
24 and has full responsibility for allocating stack slots.
26 `expand_function_start' is called at the beginning of a function,
27 before the function body is parsed, and `expand_function_end' is
28 called after parsing the body.
30 Call `assign_stack_local' to allocate a stack slot for a local variable.
31 This is usually done during the RTL generation for the function body,
32 but it can also be done in the reload pass when a pseudo-register does
33 not get a hard register.
35 Call `put_var_into_stack' when you learn, belatedly, that a variable
36 previously given a pseudo-register must in fact go in the stack.
37 This function changes the DECL_RTL to be a stack slot instead of a reg
38 then scans all the RTL instructions so far generated to correct them. */
48 #include "insn-flags.h"
50 #include "insn-codes.h"
52 #include "hard-reg-set.h"
53 #include "insn-config.h"
56 #include "basic-block.h"
60 /* Some systems use __main in a way incompatible with its use in gcc, in these
61 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
62 give the same symbol without quotes for an alternative entry point. You
63 must define both, or niether. */
65 #define NAME__MAIN "__main"
66 #define SYMBOL__MAIN __main
69 /* Round a value to the lowest integer less than it that is a multiple of
70 the required alignment. Avoid using division in case the value is
71 negative. Assume the alignment is a power of two. */
72 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
74 /* Similar, but round to the next highest integer that meets the
76 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
78 /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp
79 during rtl generation. If they are different register numbers, this is
80 always true. It may also be true if
81 FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl
82 generation. See fix_lexical_addr for details. */
84 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
85 #define NEED_SEPARATE_AP
88 /* Number of bytes of args popped by function being compiled on its return.
89 Zero if no bytes are to be popped.
90 May affect compilation of return insn or of function epilogue. */
92 int current_function_pops_args;
94 /* Nonzero if function being compiled needs to be given an address
95 where the value should be stored. */
97 int current_function_returns_struct;
99 /* Nonzero if function being compiled needs to
100 return the address of where it has put a structure value. */
102 int current_function_returns_pcc_struct;
104 /* Nonzero if function being compiled needs to be passed a static chain. */
106 int current_function_needs_context;
108 /* Nonzero if function being compiled can call setjmp. */
110 int current_function_calls_setjmp;
112 /* Nonzero if function being compiled can call longjmp. */
114 int current_function_calls_longjmp;
116 /* Nonzero if function being compiled receives nonlocal gotos
117 from nested functions. */
119 int current_function_has_nonlocal_label;
121 /* Nonzero if function being compiled has nonlocal gotos to parent
124 int current_function_has_nonlocal_goto;
126 /* Nonzero if function being compiled contains nested functions. */
128 int current_function_contains_functions;
130 /* Nonzero if function being compiled can call alloca,
131 either as a subroutine or builtin. */
133 int current_function_calls_alloca;
135 /* Nonzero if the current function returns a pointer type */
137 int current_function_returns_pointer;
139 /* If some insns can be deferred to the delay slots of the epilogue, the
140 delay list for them is recorded here. */
142 rtx current_function_epilogue_delay_list;
144 /* If function's args have a fixed size, this is that size, in bytes.
146 May affect compilation of return insn or of function epilogue. */
148 int current_function_args_size;
150 /* # bytes the prologue should push and pretend that the caller pushed them.
151 The prologue must do this, but only if parms can be passed in registers. */
153 int current_function_pretend_args_size;
155 /* # of bytes of outgoing arguments required to be pushed by the prologue.
156 If this is non-zero, it means that ACCUMULATE_OUTGOING_ARGS was defined
157 and no stack adjusts will be done on function calls. */
159 int current_function_outgoing_args_size;
161 /* This is the offset from the arg pointer to the place where the first
162 anonymous arg can be found, if there is one. */
164 rtx current_function_arg_offset_rtx;
166 /* Nonzero if current function uses varargs.h or equivalent.
167 Zero for functions that use stdarg.h. */
169 int current_function_varargs;
171 /* Quantities of various kinds of registers
172 used for the current function's args. */
174 CUMULATIVE_ARGS current_function_args_info;
176 /* Name of function now being compiled. */
178 char *current_function_name;
180 /* If non-zero, an RTL expression for that location at which the current
181 function returns its result. Always equal to
182 DECL_RTL (DECL_RESULT (current_function_decl)), but provided
183 independently of the tree structures. */
185 rtx current_function_return_rtx;
187 /* Nonzero if the current function uses the constant pool. */
189 int current_function_uses_const_pool;
191 /* Nonzero if the current function uses pic_offset_table_rtx. */
192 int current_function_uses_pic_offset_table;
194 /* The arg pointer hard register, or the pseudo into which it was copied. */
195 rtx current_function_internal_arg_pointer;
197 /* The FUNCTION_DECL for an inline function currently being expanded. */
198 tree inline_function_decl;
200 /* Number of function calls seen so far in current function. */
202 int function_call_count;
204 /* List (chain of TREE_LIST) of LABEL_DECLs for all nonlocal labels
205 (labels to which there can be nonlocal gotos from nested functions)
208 tree nonlocal_labels;
210 /* RTX for stack slot that holds the current handler for nonlocal gotos.
211 Zero when function does not have nonlocal labels. */
213 rtx nonlocal_goto_handler_slot;
215 /* RTX for stack slot that holds the stack pointer value to restore
217 Zero when function does not have nonlocal labels. */
219 rtx nonlocal_goto_stack_level;
221 /* Label that will go on parm cleanup code, if any.
222 Jumping to this label runs cleanup code for parameters, if
223 such code must be run. Following this code is the logical return label. */
227 /* Label that will go on function epilogue.
228 Jumping to this label serves as a "return" instruction
229 on machines which require execution of the epilogue on all returns. */
233 /* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs.
234 So we can mark them all live at the end of the function, if nonopt. */
237 /* List (chain of EXPR_LISTs) of all stack slots in this function.
238 Made for the sake of unshare_all_rtl. */
241 /* Chain of all RTL_EXPRs that have insns in them. */
244 /* Label to jump back to for tail recursion, or 0 if we have
245 not yet needed one for this function. */
246 rtx tail_recursion_label;
248 /* Place after which to insert the tail_recursion_label if we need one. */
249 rtx tail_recursion_reentry;
251 /* Location at which to save the argument pointer if it will need to be
252 referenced. There are two cases where this is done: if nonlocal gotos
253 exist, or if vars stored at an offset from the argument pointer will be
254 needed by inner routines. */
256 rtx arg_pointer_save_area;
258 /* Offset to end of allocated area of stack frame.
259 If stack grows down, this is the address of the last stack slot allocated.
260 If stack grows up, this is the address for the next slot. */
263 /* List (chain of TREE_LISTs) of static chains for containing functions.
264 Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
265 in an RTL_EXPR in the TREE_VALUE. */
266 static tree context_display;
268 /* List (chain of TREE_LISTs) of trampolines for nested functions.
269 The trampoline sets up the static chain and jumps to the function.
270 We supply the trampoline's address when the function's address is requested.
272 Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
273 in an RTL_EXPR in the TREE_VALUE. */
274 static tree trampoline_list;
276 /* Insn after which register parms and SAVE_EXPRs are born, if nonopt. */
277 static rtx parm_birth_insn;
280 /* Nonzero if a stack slot has been generated whose address is not
281 actually valid. It means that the generated rtl must all be scanned
282 to detect and correct the invalid addresses where they occur. */
283 static int invalid_stack_slot;
286 /* Last insn of those whose job was to put parms into their nominal homes. */
287 static rtx last_parm_insn;
289 /* 1 + last pseudo register number used for loading a copy
290 of a parameter of this function. */
291 static int max_parm_reg;
293 /* Vector indexed by REGNO, containing location on stack in which
294 to put the parm which is nominally in pseudo register REGNO,
295 if we discover that that parm must go in the stack. */
296 static rtx *parm_reg_stack_loc;
298 #if 0 /* Turned off because 0 seems to work just as well. */
299 /* Cleanup lists are required for binding levels regardless of whether
300 that binding level has cleanups or not. This node serves as the
301 cleanup list whenever an empty list is required. */
302 static tree empty_cleanup_list;
305 /* Nonzero once virtual register instantiation has been done.
306 assign_stack_local uses frame_pointer_rtx when this is nonzero. */
307 static int virtuals_instantiated;
309 /* These variables hold pointers to functions to
310 save and restore machine-specific data,
311 in push_function_context and pop_function_context. */
312 void (*save_machine_status) ();
313 void (*restore_machine_status) ();
315 /* Nonzero if we need to distinguish between the return value of this function
316 and the return value of a function called by this function. This helps
319 extern int rtx_equal_function_value_matters;
320 extern tree sequence_rtl_expr;
321 extern tree bc_runtime_type_code ();
322 extern rtx bc_build_calldesc ();
323 extern char *bc_emit_trampoline ();
324 extern char *bc_end_function ();
326 /* In order to evaluate some expressions, such as function calls returning
327 structures in memory, we need to temporarily allocate stack locations.
328 We record each allocated temporary in the following structure.
330 Associated with each temporary slot is a nesting level. When we pop up
331 one level, all temporaries associated with the previous level are freed.
332 Normally, all temporaries are freed after the execution of the statement
333 in which they were created. However, if we are inside a ({...}) grouping,
334 the result may be in a temporary and hence must be preserved. If the
335 result could be in a temporary, we preserve it if we can determine which
336 one it is in. If we cannot determine which temporary may contain the
337 result, all temporaries are preserved. A temporary is preserved by
338 pretending it was allocated at the previous nesting level.
340 Automatic variables are also assigned temporary slots, at the nesting
341 level where they are defined. They are marked a "kept" so that
342 free_temp_slots will not free them. */
346 /* Points to next temporary slot. */
347 struct temp_slot *next;
348 /* The rtx to used to reference the slot. */
350 /* The rtx used to represent the address if not the address of the
351 slot above. May be an EXPR_LIST if multiple addresses exist. */
353 /* The size, in units, of the slot. */
355 /* The value of `sequence_rtl_expr' when this temporary is allocated. */
357 /* Non-zero if this temporary is currently in use. */
359 /* Nesting level at which this slot is being used. */
361 /* Non-zero if this should survive a call to free_temp_slots. */
365 /* List of all temporaries allocated, both available and in use. */
367 struct temp_slot *temp_slots;
369 /* Current nesting level for temporaries. */
373 /* The FUNCTION_DECL node for the current function. */
374 static tree this_function_decl;
376 /* Callinfo pointer for the current function. */
377 static rtx this_function_callinfo;
379 /* The label in the bytecode file of this function's actual bytecode.
381 static char *this_function_bytecode;
383 /* The call description vector for the current function. */
384 static rtx this_function_calldesc;
386 /* Size of the local variables allocated for the current function. */
389 /* Current depth of the bytecode evaluation stack. */
392 /* Maximum depth of the evaluation stack in this function. */
395 /* Current depth in statement expressions. */
396 static int stmt_expr_depth;
398 /* This structure is used to record MEMs or pseudos used to replace VAR, any
399 SUBREGs of VAR, and any MEMs containing VAR as an address. We need to
400 maintain this list in case two operands of an insn were required to match;
401 in that case we must ensure we use the same replacement. */
403 struct fixup_replacement
407 struct fixup_replacement *next;
410 /* Forward declarations. */
412 static struct temp_slot *find_temp_slot_from_address PROTO((rtx));
413 static void put_reg_into_stack PROTO((struct function *, rtx, tree,
414 enum machine_mode, enum machine_mode));
415 static void fixup_var_refs PROTO((rtx, enum machine_mode, int));
416 static struct fixup_replacement
417 *find_fixup_replacement PROTO((struct fixup_replacement **, rtx));
418 static void fixup_var_refs_insns PROTO((rtx, enum machine_mode, int,
420 static void fixup_var_refs_1 PROTO((rtx, enum machine_mode, rtx *, rtx,
421 struct fixup_replacement **));
422 static rtx fixup_memory_subreg PROTO((rtx, rtx, int));
423 static rtx walk_fixup_memory_subreg PROTO((rtx, rtx, int));
424 static rtx fixup_stack_1 PROTO((rtx, rtx));
425 static void optimize_bit_field PROTO((rtx, rtx, rtx *));
426 static void instantiate_decls PROTO((tree, int));
427 static void instantiate_decls_1 PROTO((tree, int));
428 static void instantiate_decl PROTO((rtx, int, int));
429 static int instantiate_virtual_regs_1 PROTO((rtx *, rtx, int));
430 static void delete_handlers PROTO((void));
431 static void pad_to_arg_alignment PROTO((struct args_size *, int));
432 static void pad_below PROTO((struct args_size *, enum machine_mode,
434 static tree round_down PROTO((tree, int));
435 static rtx round_trampoline_addr PROTO((rtx));
436 static tree blocks_nreverse PROTO((tree));
437 static int all_blocks PROTO((tree, tree *));
438 static int *record_insns PROTO((rtx));
439 static int contains PROTO((rtx, int *));
441 /* Pointer to chain of `struct function' for containing functions. */
442 struct function *outer_function_chain;
444 /* Given a function decl for a containing function,
445 return the `struct function' for it. */
448 find_function_data (decl)
452 for (p = outer_function_chain; p; p = p->next)
458 /* Save the current context for compilation of a nested function.
459 This is called from language-specific code.
460 The caller is responsible for saving any language-specific status,
461 since this function knows only about language-independent variables. */
464 push_function_context ()
466 struct function *p = (struct function *) xmalloc (sizeof (struct function));
468 p->next = outer_function_chain;
469 outer_function_chain = p;
471 p->name = current_function_name;
472 p->decl = current_function_decl;
473 p->pops_args = current_function_pops_args;
474 p->returns_struct = current_function_returns_struct;
475 p->returns_pcc_struct = current_function_returns_pcc_struct;
476 p->needs_context = current_function_needs_context;
477 p->calls_setjmp = current_function_calls_setjmp;
478 p->calls_longjmp = current_function_calls_longjmp;
479 p->calls_alloca = current_function_calls_alloca;
480 p->has_nonlocal_label = current_function_has_nonlocal_label;
481 p->has_nonlocal_goto = current_function_has_nonlocal_goto;
482 p->args_size = current_function_args_size;
483 p->pretend_args_size = current_function_pretend_args_size;
484 p->arg_offset_rtx = current_function_arg_offset_rtx;
485 p->varargs = current_function_varargs;
486 p->uses_const_pool = current_function_uses_const_pool;
487 p->uses_pic_offset_table = current_function_uses_pic_offset_table;
488 p->internal_arg_pointer = current_function_internal_arg_pointer;
489 p->max_parm_reg = max_parm_reg;
490 p->parm_reg_stack_loc = parm_reg_stack_loc;
491 p->outgoing_args_size = current_function_outgoing_args_size;
492 p->return_rtx = current_function_return_rtx;
493 p->nonlocal_goto_handler_slot = nonlocal_goto_handler_slot;
494 p->nonlocal_goto_stack_level = nonlocal_goto_stack_level;
495 p->nonlocal_labels = nonlocal_labels;
496 p->cleanup_label = cleanup_label;
497 p->return_label = return_label;
498 p->save_expr_regs = save_expr_regs;
499 p->stack_slot_list = stack_slot_list;
500 p->parm_birth_insn = parm_birth_insn;
501 p->frame_offset = frame_offset;
502 p->tail_recursion_label = tail_recursion_label;
503 p->tail_recursion_reentry = tail_recursion_reentry;
504 p->arg_pointer_save_area = arg_pointer_save_area;
505 p->rtl_expr_chain = rtl_expr_chain;
506 p->last_parm_insn = last_parm_insn;
507 p->context_display = context_display;
508 p->trampoline_list = trampoline_list;
509 p->function_call_count = function_call_count;
510 p->temp_slots = temp_slots;
511 p->temp_slot_level = temp_slot_level;
512 p->fixup_var_refs_queue = 0;
513 p->epilogue_delay_list = current_function_epilogue_delay_list;
515 save_tree_status (p);
516 save_storage_status (p);
517 save_emit_status (p);
519 save_expr_status (p);
520 save_stmt_status (p);
521 save_varasm_status (p);
523 if (save_machine_status)
524 (*save_machine_status) (p);
527 /* Restore the last saved context, at the end of a nested function.
528 This function is called from language-specific code. */
531 pop_function_context ()
533 struct function *p = outer_function_chain;
535 outer_function_chain = p->next;
537 current_function_name = p->name;
538 current_function_decl = p->decl;
539 current_function_pops_args = p->pops_args;
540 current_function_returns_struct = p->returns_struct;
541 current_function_returns_pcc_struct = p->returns_pcc_struct;
542 current_function_needs_context = p->needs_context;
543 current_function_calls_setjmp = p->calls_setjmp;
544 current_function_calls_longjmp = p->calls_longjmp;
545 current_function_calls_alloca = p->calls_alloca;
546 current_function_has_nonlocal_label = p->has_nonlocal_label;
547 current_function_has_nonlocal_goto = p->has_nonlocal_goto;
548 current_function_contains_functions = 1;
549 current_function_args_size = p->args_size;
550 current_function_pretend_args_size = p->pretend_args_size;
551 current_function_arg_offset_rtx = p->arg_offset_rtx;
552 current_function_varargs = p->varargs;
553 current_function_uses_const_pool = p->uses_const_pool;
554 current_function_uses_pic_offset_table = p->uses_pic_offset_table;
555 current_function_internal_arg_pointer = p->internal_arg_pointer;
556 max_parm_reg = p->max_parm_reg;
557 parm_reg_stack_loc = p->parm_reg_stack_loc;
558 current_function_outgoing_args_size = p->outgoing_args_size;
559 current_function_return_rtx = p->return_rtx;
560 nonlocal_goto_handler_slot = p->nonlocal_goto_handler_slot;
561 nonlocal_goto_stack_level = p->nonlocal_goto_stack_level;
562 nonlocal_labels = p->nonlocal_labels;
563 cleanup_label = p->cleanup_label;
564 return_label = p->return_label;
565 save_expr_regs = p->save_expr_regs;
566 stack_slot_list = p->stack_slot_list;
567 parm_birth_insn = p->parm_birth_insn;
568 frame_offset = p->frame_offset;
569 tail_recursion_label = p->tail_recursion_label;
570 tail_recursion_reentry = p->tail_recursion_reentry;
571 arg_pointer_save_area = p->arg_pointer_save_area;
572 rtl_expr_chain = p->rtl_expr_chain;
573 last_parm_insn = p->last_parm_insn;
574 context_display = p->context_display;
575 trampoline_list = p->trampoline_list;
576 function_call_count = p->function_call_count;
577 temp_slots = p->temp_slots;
578 temp_slot_level = p->temp_slot_level;
579 current_function_epilogue_delay_list = p->epilogue_delay_list;
581 restore_tree_status (p);
582 restore_storage_status (p);
583 restore_expr_status (p);
584 restore_emit_status (p);
585 restore_stmt_status (p);
586 restore_varasm_status (p);
588 if (restore_machine_status)
589 (*restore_machine_status) (p);
591 /* Finish doing put_var_into_stack for any of our variables
592 which became addressable during the nested function. */
594 struct var_refs_queue *queue = p->fixup_var_refs_queue;
595 for (; queue; queue = queue->next)
596 fixup_var_refs (queue->modified, queue->promoted_mode, queue->unsignedp);
601 /* Reset variables that have known state during rtx generation. */
602 rtx_equal_function_value_matters = 1;
603 virtuals_instantiated = 0;
606 /* Allocate fixed slots in the stack frame of the current function. */
608 /* Return size needed for stack frame based on slots so far allocated.
609 This size counts from zero. It is not rounded to STACK_BOUNDARY;
610 the caller may have to do that. */
615 #ifdef FRAME_GROWS_DOWNWARD
616 return -frame_offset;
622 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
623 with machine mode MODE.
625 ALIGN controls the amount of alignment for the address of the slot:
626 0 means according to MODE,
627 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
628 positive specifies alignment boundary in bits.
630 We do not round to stack_boundary here. */
633 assign_stack_local (mode, size, align)
634 enum machine_mode mode;
638 register rtx x, addr;
639 int bigend_correction = 0;
644 alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
646 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
648 else if (align == -1)
650 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
651 size = CEIL_ROUND (size, alignment);
654 alignment = align / BITS_PER_UNIT;
656 /* Round frame offset to that alignment.
657 We must be careful here, since FRAME_OFFSET might be negative and
658 division with a negative dividend isn't as well defined as we might
659 like. So we instead assume that ALIGNMENT is a power of two and
660 use logical operations which are unambiguous. */
661 #ifdef FRAME_GROWS_DOWNWARD
662 frame_offset = FLOOR_ROUND (frame_offset, alignment);
664 frame_offset = CEIL_ROUND (frame_offset, alignment);
667 /* On a big-endian machine, if we are allocating more space than we will use,
668 use the least significant bytes of those that are allocated. */
671 bigend_correction = size - GET_MODE_SIZE (mode);
674 #ifdef FRAME_GROWS_DOWNWARD
675 frame_offset -= size;
678 /* If we have already instantiated virtual registers, return the actual
679 address relative to the frame pointer. */
680 if (virtuals_instantiated)
681 addr = plus_constant (frame_pointer_rtx,
682 (frame_offset + bigend_correction
683 + STARTING_FRAME_OFFSET));
685 addr = plus_constant (virtual_stack_vars_rtx,
686 frame_offset + bigend_correction);
688 #ifndef FRAME_GROWS_DOWNWARD
689 frame_offset += size;
692 x = gen_rtx (MEM, mode, addr);
694 stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, x, stack_slot_list);
699 /* Assign a stack slot in a containing function.
700 First three arguments are same as in preceding function.
701 The last argument specifies the function to allocate in. */
704 assign_outer_stack_local (mode, size, align, function)
705 enum machine_mode mode;
708 struct function *function;
710 register rtx x, addr;
711 int bigend_correction = 0;
714 /* Allocate in the memory associated with the function in whose frame
716 push_obstacks (function->function_obstack,
717 function->function_maybepermanent_obstack);
721 alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
723 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
725 else if (align == -1)
727 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
728 size = CEIL_ROUND (size, alignment);
731 alignment = align / BITS_PER_UNIT;
733 /* Round frame offset to that alignment. */
734 #ifdef FRAME_GROWS_DOWNWARD
735 function->frame_offset = FLOOR_ROUND (function->frame_offset, alignment);
737 function->frame_offset = CEIL_ROUND (function->frame_offset, alignment);
740 /* On a big-endian machine, if we are allocating more space than we will use,
741 use the least significant bytes of those that are allocated. */
744 bigend_correction = size - GET_MODE_SIZE (mode);
747 #ifdef FRAME_GROWS_DOWNWARD
748 function->frame_offset -= size;
750 addr = plus_constant (virtual_stack_vars_rtx,
751 function->frame_offset + bigend_correction);
752 #ifndef FRAME_GROWS_DOWNWARD
753 function->frame_offset += size;
756 x = gen_rtx (MEM, mode, addr);
758 function->stack_slot_list
759 = gen_rtx (EXPR_LIST, VOIDmode, x, function->stack_slot_list);
766 /* Allocate a temporary stack slot and record it for possible later
769 MODE is the machine mode to be given to the returned rtx.
771 SIZE is the size in units of the space required. We do no rounding here
772 since assign_stack_local will do any required rounding.
774 KEEP is 1 if this slot is to be retained after a call to
775 free_temp_slots. Automatic variables for a block are allocated
776 with this flag. KEEP is 2, if we allocate a longer term temporary,
777 whose lifetime is controlled by CLEANUP_POINT_EXPRs. */
780 assign_stack_temp (mode, size, keep)
781 enum machine_mode mode;
785 struct temp_slot *p, *best_p = 0;
787 /* First try to find an available, already-allocated temporary that is the
788 exact size we require. */
789 for (p = temp_slots; p; p = p->next)
790 if (p->size == size && GET_MODE (p->slot) == mode && ! p->in_use)
793 /* If we didn't find, one, try one that is larger than what we want. We
794 find the smallest such. */
796 for (p = temp_slots; p; p = p->next)
797 if (p->size > size && GET_MODE (p->slot) == mode && ! p->in_use
798 && (best_p == 0 || best_p->size > p->size))
801 /* Make our best, if any, the one to use. */
804 /* If there are enough aligned bytes left over, make them into a new
805 temp_slot so that the extra bytes don't get wasted. Do this only
806 for BLKmode slots, so that we can be sure of the alignment. */
807 if (GET_MODE (best_p->slot) == BLKmode)
809 int alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
810 int rounded_size = CEIL_ROUND (size, alignment);
812 if (best_p->size - rounded_size >= alignment)
814 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
816 p->size = best_p->size - rounded_size;
817 p->slot = gen_rtx (MEM, BLKmode,
818 plus_constant (XEXP (best_p->slot, 0),
821 p->next = temp_slots;
824 stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, p->slot,
827 best_p->size = rounded_size;
834 /* If we still didn't find one, make a new temporary. */
837 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
839 /* If the temp slot mode doesn't indicate the alignment,
840 use the largest possible, so no one will be disappointed. */
841 p->slot = assign_stack_local (mode, size, mode == BLKmode ? -1 : 0);
843 p->next = temp_slots;
848 p->rtl_expr = sequence_rtl_expr;
851 p->level = target_temp_slot_level;
856 p->level = temp_slot_level;
862 /* Combine temporary stack slots which are adjacent on the stack.
864 This allows for better use of already allocated stack space. This is only
865 done for BLKmode slots because we can be sure that we won't have alignment
866 problems in this case. */
869 combine_temp_slots ()
871 struct temp_slot *p, *q;
872 struct temp_slot *prev_p, *prev_q;
873 /* Determine where to free back to after this function. */
874 rtx free_pointer = rtx_alloc (CONST_INT);
876 for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots)
879 if (! p->in_use && GET_MODE (p->slot) == BLKmode)
880 for (q = p->next, prev_q = p; q; q = prev_q->next)
883 if (! q->in_use && GET_MODE (q->slot) == BLKmode)
885 if (rtx_equal_p (plus_constant (XEXP (p->slot, 0), p->size),
888 /* Q comes after P; combine Q into P. */
892 else if (rtx_equal_p (plus_constant (XEXP (q->slot, 0), q->size),
895 /* P comes after Q; combine P into Q. */
901 /* Either delete Q or advance past it. */
903 prev_q->next = q->next;
907 /* Either delete P or advance past it. */
911 prev_p->next = p->next;
913 temp_slots = p->next;
919 /* Free all the RTL made by plus_constant. */
920 rtx_free (free_pointer);
923 /* Find the temp slot corresponding to the object at address X. */
925 static struct temp_slot *
926 find_temp_slot_from_address (x)
932 for (p = temp_slots; p; p = p->next)
936 else if (XEXP (p->slot, 0) == x
940 else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST)
941 for (next = p->address; next; next = XEXP (next, 1))
942 if (XEXP (next, 0) == x)
949 /* Indicate that NEW is an alternate way of refering to the temp slot
950 that previous was known by OLD. */
953 update_temp_slot_address (old, new)
956 struct temp_slot *p = find_temp_slot_from_address (old);
958 /* If none, return. Else add NEW as an alias. */
961 else if (p->address == 0)
965 if (GET_CODE (p->address) != EXPR_LIST)
966 p->address = gen_rtx (EXPR_LIST, VOIDmode, p->address, NULL_RTX);
968 p->address = gen_rtx (EXPR_LIST, VOIDmode, new, p->address);
972 /* If X could be a reference to a temporary slot, mark that slot as belonging
973 to the to one level higher. If X matched one of our slots, just mark that
974 one. Otherwise, we can't easily predict which it is, so upgrade all of
975 them. Kept slots need not be touched.
977 This is called when an ({...}) construct occurs and a statement
978 returns a value in memory. */
981 preserve_temp_slots (x)
989 /* If X is a register that is being used as a pointer, see if we have
990 a temporary slot we know it points to. To be consistent with
991 the code below, we really should preserve all non-kept slots
992 if we can't find a match, but that seems to be much too costly. */
993 if (GET_CODE (x) == REG && REGNO_POINTER_FLAG (REGNO (x))
994 && (p = find_temp_slot_from_address (x)) != 0)
1000 /* If X is not in memory or is at a constant address, it cannot be in
1001 a temporary slot. */
1002 if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1005 /* First see if we can find a match. */
1006 p = find_temp_slot_from_address (XEXP (x, 0));
1013 /* Otherwise, preserve all non-kept slots at this level. */
1014 for (p = temp_slots; p; p = p->next)
1015 if (p->in_use && p->level == temp_slot_level && ! p->keep)
1019 /* X is the result of an RTL_EXPR. If it is a temporary slot associated
1020 with that RTL_EXPR, promote it into a temporary slot at the present
1021 level so it will not be freed when we free slots made in the
1025 preserve_rtl_expr_result (x)
1028 struct temp_slot *p;
1030 /* If X is not in memory or is at a constant address, it cannot be in
1031 a temporary slot. */
1032 if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1035 /* If we can find a match, move it to our level. */
1036 for (p = temp_slots; p; p = p->next)
1037 if (p->in_use && rtx_equal_p (x, p->slot))
1039 p->level = temp_slot_level;
1047 /* Free all temporaries used so far. This is normally called at the end
1048 of generating code for a statement. Don't free any temporaries
1049 currently in use for an RTL_EXPR that hasn't yet been emitted.
1050 We could eventually do better than this since it can be reused while
1051 generating the same RTL_EXPR, but this is complex and probably not
1057 struct temp_slot *p;
1059 for (p = temp_slots; p; p = p->next)
1060 if (p->in_use && p->level == temp_slot_level && ! p->keep
1061 && p->rtl_expr == 0)
1064 combine_temp_slots ();
1067 /* Free all temporary slots used in T, an RTL_EXPR node. */
1070 free_temps_for_rtl_expr (t)
1073 struct temp_slot *p;
1075 for (p = temp_slots; p; p = p->next)
1076 if (p->rtl_expr == t)
1079 combine_temp_slots ();
1082 /* Push deeper into the nesting level for stack temporaries. */
1090 /* Pop a temporary nesting level. All slots in use in the current level
1096 struct temp_slot *p;
1098 for (p = temp_slots; p; p = p->next)
1099 if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0)
1102 combine_temp_slots ();
1107 /* Retroactively move an auto variable from a register to a stack slot.
1108 This is done when an address-reference to the variable is seen. */
1111 put_var_into_stack (decl)
1115 enum machine_mode promoted_mode, decl_mode;
1116 struct function *function = 0;
1119 if (output_bytecode)
1122 context = decl_function_context (decl);
1124 /* Get the current rtl used for this object and it's original mode. */
1125 reg = TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl) : DECL_RTL (decl);
1127 /* No need to do anything if decl has no rtx yet
1128 since in that case caller is setting TREE_ADDRESSABLE
1129 and a stack slot will be assigned when the rtl is made. */
1133 /* Get the declared mode for this object. */
1134 decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl))
1135 : DECL_MODE (decl));
1136 /* Get the mode it's actually stored in. */
1137 promoted_mode = GET_MODE (reg);
1139 /* If this variable comes from an outer function,
1140 find that function's saved context. */
1141 if (context != current_function_decl)
1142 for (function = outer_function_chain; function; function = function->next)
1143 if (function->decl == context)
1146 /* If this is a variable-size object with a pseudo to address it,
1147 put that pseudo into the stack, if the var is nonlocal. */
1148 if (DECL_NONLOCAL (decl)
1149 && GET_CODE (reg) == MEM
1150 && GET_CODE (XEXP (reg, 0)) == REG
1151 && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
1153 reg = XEXP (reg, 0);
1154 decl_mode = promoted_mode = GET_MODE (reg);
1157 /* Now we should have a value that resides in one or more pseudo regs. */
1159 if (GET_CODE (reg) == REG)
1160 put_reg_into_stack (function, reg, TREE_TYPE (decl),
1161 promoted_mode, decl_mode);
1162 else if (GET_CODE (reg) == CONCAT)
1164 /* A CONCAT contains two pseudos; put them both in the stack.
1165 We do it so they end up consecutive. */
1166 enum machine_mode part_mode = GET_MODE (XEXP (reg, 0));
1167 tree part_type = TREE_TYPE (TREE_TYPE (decl));
1168 #ifdef STACK_GROWS_DOWNWARD
1169 /* Since part 0 should have a lower address, do it second. */
1170 put_reg_into_stack (function, XEXP (reg, 1),
1171 part_type, part_mode, part_mode);
1172 put_reg_into_stack (function, XEXP (reg, 0),
1173 part_type, part_mode, part_mode);
1175 put_reg_into_stack (function, XEXP (reg, 0),
1176 part_type, part_mode, part_mode);
1177 put_reg_into_stack (function, XEXP (reg, 1),
1178 part_type, part_mode, part_mode);
1181 /* Change the CONCAT into a combined MEM for both parts. */
1182 PUT_CODE (reg, MEM);
1183 /* The two parts are in memory order already.
1184 Use the lower parts address as ours. */
1185 XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0);
1186 /* Prevent sharing of rtl that might lose. */
1187 if (GET_CODE (XEXP (reg, 0)) == PLUS)
1188 XEXP (reg, 0) = copy_rtx (XEXP (reg, 0));
1192 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1193 into the stack frame of FUNCTION (0 means the current function).
1194 DECL_MODE is the machine mode of the user-level data type.
1195 PROMOTED_MODE is the machine mode of the register. */
1198 put_reg_into_stack (function, reg, type, promoted_mode, decl_mode)
1199 struct function *function;
1202 enum machine_mode promoted_mode, decl_mode;
1208 if (REGNO (reg) < function->max_parm_reg)
1209 new = function->parm_reg_stack_loc[REGNO (reg)];
1211 new = assign_outer_stack_local (decl_mode, GET_MODE_SIZE (decl_mode),
1216 if (REGNO (reg) < max_parm_reg)
1217 new = parm_reg_stack_loc[REGNO (reg)];
1219 new = assign_stack_local (decl_mode, GET_MODE_SIZE (decl_mode), 0);
1222 XEXP (reg, 0) = XEXP (new, 0);
1223 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1224 REG_USERVAR_P (reg) = 0;
1225 PUT_CODE (reg, MEM);
1226 PUT_MODE (reg, decl_mode);
1228 /* If this is a memory ref that contains aggregate components,
1229 mark it as such for cse and loop optimize. */
1230 MEM_IN_STRUCT_P (reg) = AGGREGATE_TYPE_P (type);
1232 /* Now make sure that all refs to the variable, previously made
1233 when it was a register, are fixed up to be valid again. */
1236 struct var_refs_queue *temp;
1238 /* Variable is inherited; fix it up when we get back to its function. */
1239 push_obstacks (function->function_obstack,
1240 function->function_maybepermanent_obstack);
1242 /* See comment in restore_tree_status in tree.c for why this needs to be
1243 on saveable obstack. */
1245 = (struct var_refs_queue *) savealloc (sizeof (struct var_refs_queue));
1246 temp->modified = reg;
1247 temp->promoted_mode = promoted_mode;
1248 temp->unsignedp = TREE_UNSIGNED (type);
1249 temp->next = function->fixup_var_refs_queue;
1250 function->fixup_var_refs_queue = temp;
1254 /* Variable is local; fix it up now. */
1255 fixup_var_refs (reg, promoted_mode, TREE_UNSIGNED (type));
1259 fixup_var_refs (var, promoted_mode, unsignedp)
1261 enum machine_mode promoted_mode;
1265 rtx first_insn = get_insns ();
1266 struct sequence_stack *stack = sequence_stack;
1267 tree rtl_exps = rtl_expr_chain;
1269 /* Must scan all insns for stack-refs that exceed the limit. */
1270 fixup_var_refs_insns (var, promoted_mode, unsignedp, first_insn, stack == 0);
1272 /* Scan all pending sequences too. */
1273 for (; stack; stack = stack->next)
1275 push_to_sequence (stack->first);
1276 fixup_var_refs_insns (var, promoted_mode, unsignedp,
1277 stack->first, stack->next != 0);
1278 /* Update remembered end of sequence
1279 in case we added an insn at the end. */
1280 stack->last = get_last_insn ();
1284 /* Scan all waiting RTL_EXPRs too. */
1285 for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
1287 rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
1288 if (seq != const0_rtx && seq != 0)
1290 push_to_sequence (seq);
1291 fixup_var_refs_insns (var, promoted_mode, unsignedp, seq, 0);
1297 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1298 some part of an insn. Return a struct fixup_replacement whose OLD
1299 value is equal to X. Allocate a new structure if no such entry exists. */
1301 static struct fixup_replacement *
1302 find_fixup_replacement (replacements, x)
1303 struct fixup_replacement **replacements;
1306 struct fixup_replacement *p;
1308 /* See if we have already replaced this. */
1309 for (p = *replacements; p && p->old != x; p = p->next)
1314 p = (struct fixup_replacement *) oballoc (sizeof (struct fixup_replacement));
1317 p->next = *replacements;
1324 /* Scan the insn-chain starting with INSN for refs to VAR
1325 and fix them up. TOPLEVEL is nonzero if this chain is the
1326 main chain of insns for the current function. */
1329 fixup_var_refs_insns (var, promoted_mode, unsignedp, insn, toplevel)
1331 enum machine_mode promoted_mode;
1340 rtx next = NEXT_INSN (insn);
1342 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1344 /* If this is a CLOBBER of VAR, delete it.
1346 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1347 and REG_RETVAL notes too. */
1348 if (GET_CODE (PATTERN (insn)) == CLOBBER
1349 && XEXP (PATTERN (insn), 0) == var)
1351 if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0)
1352 /* The REG_LIBCALL note will go away since we are going to
1353 turn INSN into a NOTE, so just delete the
1354 corresponding REG_RETVAL note. */
1355 remove_note (XEXP (note, 0),
1356 find_reg_note (XEXP (note, 0), REG_RETVAL,
1359 /* In unoptimized compilation, we shouldn't call delete_insn
1360 except in jump.c doing warnings. */
1361 PUT_CODE (insn, NOTE);
1362 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1363 NOTE_SOURCE_FILE (insn) = 0;
1366 /* The insn to load VAR from a home in the arglist
1367 is now a no-op. When we see it, just delete it. */
1369 && GET_CODE (PATTERN (insn)) == SET
1370 && SET_DEST (PATTERN (insn)) == var
1371 /* If this represents the result of an insn group,
1372 don't delete the insn. */
1373 && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0
1374 && rtx_equal_p (SET_SRC (PATTERN (insn)), var))
1376 /* In unoptimized compilation, we shouldn't call delete_insn
1377 except in jump.c doing warnings. */
1378 PUT_CODE (insn, NOTE);
1379 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1380 NOTE_SOURCE_FILE (insn) = 0;
1381 if (insn == last_parm_insn)
1382 last_parm_insn = PREV_INSN (next);
1386 struct fixup_replacement *replacements = 0;
1387 rtx next_insn = NEXT_INSN (insn);
1389 #ifdef SMALL_REGISTER_CLASSES
1390 /* If the insn that copies the results of a CALL_INSN
1391 into a pseudo now references VAR, we have to use an
1392 intermediate pseudo since we want the life of the
1393 return value register to be only a single insn.
1395 If we don't use an intermediate pseudo, such things as
1396 address computations to make the address of VAR valid
1397 if it is not can be placed beween the CALL_INSN and INSN.
1399 To make sure this doesn't happen, we record the destination
1400 of the CALL_INSN and see if the next insn uses both that
1403 if (call_dest != 0 && GET_CODE (insn) == INSN
1404 && reg_mentioned_p (var, PATTERN (insn))
1405 && reg_mentioned_p (call_dest, PATTERN (insn)))
1407 rtx temp = gen_reg_rtx (GET_MODE (call_dest));
1409 emit_insn_before (gen_move_insn (temp, call_dest), insn);
1411 PATTERN (insn) = replace_rtx (PATTERN (insn),
1415 if (GET_CODE (insn) == CALL_INSN
1416 && GET_CODE (PATTERN (insn)) == SET)
1417 call_dest = SET_DEST (PATTERN (insn));
1418 else if (GET_CODE (insn) == CALL_INSN
1419 && GET_CODE (PATTERN (insn)) == PARALLEL
1420 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
1421 call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
1426 /* See if we have to do anything to INSN now that VAR is in
1427 memory. If it needs to be loaded into a pseudo, use a single
1428 pseudo for the entire insn in case there is a MATCH_DUP
1429 between two operands. We pass a pointer to the head of
1430 a list of struct fixup_replacements. If fixup_var_refs_1
1431 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1432 it will record them in this list.
1434 If it allocated a pseudo for any replacement, we copy into
1437 fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn,
1440 /* If this is last_parm_insn, and any instructions were output
1441 after it to fix it up, then we must set last_parm_insn to
1442 the last such instruction emitted. */
1443 if (insn == last_parm_insn)
1444 last_parm_insn = PREV_INSN (next_insn);
1446 while (replacements)
1448 if (GET_CODE (replacements->new) == REG)
1453 /* OLD might be a (subreg (mem)). */
1454 if (GET_CODE (replacements->old) == SUBREG)
1456 = fixup_memory_subreg (replacements->old, insn, 0);
1459 = fixup_stack_1 (replacements->old, insn);
1461 insert_before = insn;
1463 /* If we are changing the mode, do a conversion.
1464 This might be wasteful, but combine.c will
1465 eliminate much of the waste. */
1467 if (GET_MODE (replacements->new)
1468 != GET_MODE (replacements->old))
1471 convert_move (replacements->new,
1472 replacements->old, unsignedp);
1473 seq = gen_sequence ();
1477 seq = gen_move_insn (replacements->new,
1480 emit_insn_before (seq, insert_before);
1483 replacements = replacements->next;
1487 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1488 But don't touch other insns referred to by reg-notes;
1489 we will get them elsewhere. */
1490 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
1491 if (GET_CODE (note) != INSN_LIST)
1493 = walk_fixup_memory_subreg (XEXP (note, 0), insn, 1);
1499 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1500 See if the rtx expression at *LOC in INSN needs to be changed.
1502 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1503 contain a list of original rtx's and replacements. If we find that we need
1504 to modify this insn by replacing a memory reference with a pseudo or by
1505 making a new MEM to implement a SUBREG, we consult that list to see if
1506 we have already chosen a replacement. If none has already been allocated,
1507 we allocate it and update the list. fixup_var_refs_insns will copy VAR
1508 or the SUBREG, as appropriate, to the pseudo. */
1511 fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements)
1513 enum machine_mode promoted_mode;
1516 struct fixup_replacement **replacements;
1519 register rtx x = *loc;
1520 RTX_CODE code = GET_CODE (x);
1522 register rtx tem, tem1;
1523 struct fixup_replacement *replacement;
1530 /* If we already have a replacement, use it. Otherwise,
1531 try to fix up this address in case it is invalid. */
1533 replacement = find_fixup_replacement (replacements, var);
1534 if (replacement->new)
1536 *loc = replacement->new;
1540 *loc = replacement->new = x = fixup_stack_1 (x, insn);
1542 /* Unless we are forcing memory to register or we changed the mode,
1543 we can leave things the way they are if the insn is valid. */
1545 INSN_CODE (insn) = -1;
1546 if (! flag_force_mem && GET_MODE (x) == promoted_mode
1547 && recog_memoized (insn) >= 0)
1550 *loc = replacement->new = gen_reg_rtx (promoted_mode);
1554 /* If X contains VAR, we need to unshare it here so that we update
1555 each occurrence separately. But all identical MEMs in one insn
1556 must be replaced with the same rtx because of the possibility of
1559 if (reg_mentioned_p (var, x))
1561 replacement = find_fixup_replacement (replacements, x);
1562 if (replacement->new == 0)
1563 replacement->new = copy_most_rtx (x, var);
1565 *loc = x = replacement->new;
1581 /* Note that in some cases those types of expressions are altered
1582 by optimize_bit_field, and do not survive to get here. */
1583 if (XEXP (x, 0) == var
1584 || (GET_CODE (XEXP (x, 0)) == SUBREG
1585 && SUBREG_REG (XEXP (x, 0)) == var))
1587 /* Get TEM as a valid MEM in the mode presently in the insn.
1589 We don't worry about the possibility of MATCH_DUP here; it
1590 is highly unlikely and would be tricky to handle. */
1593 if (GET_CODE (tem) == SUBREG)
1594 tem = fixup_memory_subreg (tem, insn, 1);
1595 tem = fixup_stack_1 (tem, insn);
1597 /* Unless we want to load from memory, get TEM into the proper mode
1598 for an extract from memory. This can only be done if the
1599 extract is at a constant position and length. */
1601 if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
1602 && GET_CODE (XEXP (x, 2)) == CONST_INT
1603 && ! mode_dependent_address_p (XEXP (tem, 0))
1604 && ! MEM_VOLATILE_P (tem))
1606 enum machine_mode wanted_mode = VOIDmode;
1607 enum machine_mode is_mode = GET_MODE (tem);
1608 int width = INTVAL (XEXP (x, 1));
1609 int pos = INTVAL (XEXP (x, 2));
1612 if (GET_CODE (x) == ZERO_EXTRACT)
1613 wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
1616 if (GET_CODE (x) == SIGN_EXTRACT)
1617 wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
1619 /* If we have a narrower mode, we can do something. */
1620 if (wanted_mode != VOIDmode
1621 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
1623 int offset = pos / BITS_PER_UNIT;
1624 rtx old_pos = XEXP (x, 2);
1627 /* If the bytes and bits are counted differently, we
1628 must adjust the offset. */
1629 #if BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN
1630 offset = (GET_MODE_SIZE (is_mode)
1631 - GET_MODE_SIZE (wanted_mode) - offset);
1634 pos %= GET_MODE_BITSIZE (wanted_mode);
1636 newmem = gen_rtx (MEM, wanted_mode,
1637 plus_constant (XEXP (tem, 0), offset));
1638 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
1639 MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
1640 MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
1642 /* Make the change and see if the insn remains valid. */
1643 INSN_CODE (insn) = -1;
1644 XEXP (x, 0) = newmem;
1645 XEXP (x, 2) = GEN_INT (pos);
1647 if (recog_memoized (insn) >= 0)
1650 /* Otherwise, restore old position. XEXP (x, 0) will be
1652 XEXP (x, 2) = old_pos;
1656 /* If we get here, the bitfield extract insn can't accept a memory
1657 reference. Copy the input into a register. */
1659 tem1 = gen_reg_rtx (GET_MODE (tem));
1660 emit_insn_before (gen_move_insn (tem1, tem), insn);
1667 if (SUBREG_REG (x) == var)
1669 /* If this is a special SUBREG made because VAR was promoted
1670 from a wider mode, replace it with VAR and call ourself
1671 recursively, this time saying that the object previously
1672 had its current mode (by virtue of the SUBREG). */
1674 if (SUBREG_PROMOTED_VAR_P (x))
1677 fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements);
1681 /* If this SUBREG makes VAR wider, it has become a paradoxical
1682 SUBREG with VAR in memory, but these aren't allowed at this
1683 stage of the compilation. So load VAR into a pseudo and take
1684 a SUBREG of that pseudo. */
1685 if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
1687 replacement = find_fixup_replacement (replacements, var);
1688 if (replacement->new == 0)
1689 replacement->new = gen_reg_rtx (GET_MODE (var));
1690 SUBREG_REG (x) = replacement->new;
1694 /* See if we have already found a replacement for this SUBREG.
1695 If so, use it. Otherwise, make a MEM and see if the insn
1696 is recognized. If not, or if we should force MEM into a register,
1697 make a pseudo for this SUBREG. */
1698 replacement = find_fixup_replacement (replacements, x);
1699 if (replacement->new)
1701 *loc = replacement->new;
1705 replacement->new = *loc = fixup_memory_subreg (x, insn, 0);
1707 INSN_CODE (insn) = -1;
1708 if (! flag_force_mem && recog_memoized (insn) >= 0)
1711 *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
1717 /* First do special simplification of bit-field references. */
1718 if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
1719 || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
1720 optimize_bit_field (x, insn, 0);
1721 if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
1722 || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
1723 optimize_bit_field (x, insn, NULL_PTR);
1725 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
1726 insn into a pseudo and store the low part of the pseudo into VAR. */
1727 if (GET_CODE (SET_DEST (x)) == SUBREG
1728 && SUBREG_REG (SET_DEST (x)) == var
1729 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
1730 > GET_MODE_SIZE (GET_MODE (var))))
1732 SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
1733 emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
1740 rtx dest = SET_DEST (x);
1741 rtx src = SET_SRC (x);
1742 rtx outerdest = dest;
1744 while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
1745 || GET_CODE (dest) == SIGN_EXTRACT
1746 || GET_CODE (dest) == ZERO_EXTRACT)
1747 dest = XEXP (dest, 0);
1749 if (GET_CODE (src) == SUBREG)
1750 src = XEXP (src, 0);
1752 /* If VAR does not appear at the top level of the SET
1753 just scan the lower levels of the tree. */
1755 if (src != var && dest != var)
1758 /* We will need to rerecognize this insn. */
1759 INSN_CODE (insn) = -1;
1762 if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var)
1764 /* Since this case will return, ensure we fixup all the
1766 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1),
1767 insn, replacements);
1768 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2),
1769 insn, replacements);
1770 fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x),
1771 insn, replacements);
1773 tem = XEXP (outerdest, 0);
1775 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
1776 that may appear inside a ZERO_EXTRACT.
1777 This was legitimate when the MEM was a REG. */
1778 if (GET_CODE (tem) == SUBREG
1779 && SUBREG_REG (tem) == var)
1780 tem = fixup_memory_subreg (tem, insn, 1);
1782 tem = fixup_stack_1 (tem, insn);
1784 if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
1785 && GET_CODE (XEXP (outerdest, 2)) == CONST_INT
1786 && ! mode_dependent_address_p (XEXP (tem, 0))
1787 && ! MEM_VOLATILE_P (tem))
1789 enum machine_mode wanted_mode
1790 = insn_operand_mode[(int) CODE_FOR_insv][0];
1791 enum machine_mode is_mode = GET_MODE (tem);
1792 int width = INTVAL (XEXP (outerdest, 1));
1793 int pos = INTVAL (XEXP (outerdest, 2));
1795 /* If we have a narrower mode, we can do something. */
1796 if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
1798 int offset = pos / BITS_PER_UNIT;
1799 rtx old_pos = XEXP (outerdest, 2);
1802 #if BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN
1803 offset = (GET_MODE_SIZE (is_mode)
1804 - GET_MODE_SIZE (wanted_mode) - offset);
1807 pos %= GET_MODE_BITSIZE (wanted_mode);
1809 newmem = gen_rtx (MEM, wanted_mode,
1810 plus_constant (XEXP (tem, 0), offset));
1811 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
1812 MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
1813 MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
1815 /* Make the change and see if the insn remains valid. */
1816 INSN_CODE (insn) = -1;
1817 XEXP (outerdest, 0) = newmem;
1818 XEXP (outerdest, 2) = GEN_INT (pos);
1820 if (recog_memoized (insn) >= 0)
1823 /* Otherwise, restore old position. XEXP (x, 0) will be
1825 XEXP (outerdest, 2) = old_pos;
1829 /* If we get here, the bit-field store doesn't allow memory
1830 or isn't located at a constant position. Load the value into
1831 a register, do the store, and put it back into memory. */
1833 tem1 = gen_reg_rtx (GET_MODE (tem));
1834 emit_insn_before (gen_move_insn (tem1, tem), insn);
1835 emit_insn_after (gen_move_insn (tem, tem1), insn);
1836 XEXP (outerdest, 0) = tem1;
1841 /* STRICT_LOW_PART is a no-op on memory references
1842 and it can cause combinations to be unrecognizable,
1845 if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
1846 SET_DEST (x) = XEXP (SET_DEST (x), 0);
1848 /* A valid insn to copy VAR into or out of a register
1849 must be left alone, to avoid an infinite loop here.
1850 If the reference to VAR is by a subreg, fix that up,
1851 since SUBREG is not valid for a memref.
1852 Also fix up the address of the stack slot.
1854 Note that we must not try to recognize the insn until
1855 after we know that we have valid addresses and no
1856 (subreg (mem ...) ...) constructs, since these interfere
1857 with determining the validity of the insn. */
1859 if ((SET_SRC (x) == var
1860 || (GET_CODE (SET_SRC (x)) == SUBREG
1861 && SUBREG_REG (SET_SRC (x)) == var))
1862 && (GET_CODE (SET_DEST (x)) == REG
1863 || (GET_CODE (SET_DEST (x)) == SUBREG
1864 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
1865 && x == single_set (PATTERN (insn)))
1869 replacement = find_fixup_replacement (replacements, SET_SRC (x));
1870 if (replacement->new)
1871 SET_SRC (x) = replacement->new;
1872 else if (GET_CODE (SET_SRC (x)) == SUBREG)
1873 SET_SRC (x) = replacement->new
1874 = fixup_memory_subreg (SET_SRC (x), insn, 0);
1876 SET_SRC (x) = replacement->new
1877 = fixup_stack_1 (SET_SRC (x), insn);
1879 if (recog_memoized (insn) >= 0)
1882 /* INSN is not valid, but we know that we want to
1883 copy SET_SRC (x) to SET_DEST (x) in some way. So
1884 we generate the move and see whether it requires more
1885 than one insn. If it does, we emit those insns and
1886 delete INSN. Otherwise, we an just replace the pattern
1887 of INSN; we have already verified above that INSN has
1888 no other function that to do X. */
1890 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
1891 if (GET_CODE (pat) == SEQUENCE)
1893 emit_insn_after (pat, insn);
1894 PUT_CODE (insn, NOTE);
1895 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1896 NOTE_SOURCE_FILE (insn) = 0;
1899 PATTERN (insn) = pat;
1904 if ((SET_DEST (x) == var
1905 || (GET_CODE (SET_DEST (x)) == SUBREG
1906 && SUBREG_REG (SET_DEST (x)) == var))
1907 && (GET_CODE (SET_SRC (x)) == REG
1908 || (GET_CODE (SET_SRC (x)) == SUBREG
1909 && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
1910 && x == single_set (PATTERN (insn)))
1914 if (GET_CODE (SET_DEST (x)) == SUBREG)
1915 SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn, 0);
1917 SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
1919 if (recog_memoized (insn) >= 0)
1922 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
1923 if (GET_CODE (pat) == SEQUENCE)
1925 emit_insn_after (pat, insn);
1926 PUT_CODE (insn, NOTE);
1927 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1928 NOTE_SOURCE_FILE (insn) = 0;
1931 PATTERN (insn) = pat;
1936 /* Otherwise, storing into VAR must be handled specially
1937 by storing into a temporary and copying that into VAR
1938 with a new insn after this one. Note that this case
1939 will be used when storing into a promoted scalar since
1940 the insn will now have different modes on the input
1941 and output and hence will be invalid (except for the case
1942 of setting it to a constant, which does not need any
1943 change if it is valid). We generate extra code in that case,
1944 but combine.c will eliminate it. */
1949 rtx fixeddest = SET_DEST (x);
1951 /* STRICT_LOW_PART can be discarded, around a MEM. */
1952 if (GET_CODE (fixeddest) == STRICT_LOW_PART)
1953 fixeddest = XEXP (fixeddest, 0);
1954 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
1955 if (GET_CODE (fixeddest) == SUBREG)
1956 fixeddest = fixup_memory_subreg (fixeddest, insn, 0);
1958 fixeddest = fixup_stack_1 (fixeddest, insn);
1960 temp = gen_reg_rtx (GET_MODE (SET_SRC (x)) == VOIDmode
1961 ? GET_MODE (fixeddest)
1962 : GET_MODE (SET_SRC (x)));
1964 emit_insn_after (gen_move_insn (fixeddest,
1965 gen_lowpart (GET_MODE (fixeddest),
1969 SET_DEST (x) = temp;
1974 /* Nothing special about this RTX; fix its operands. */
1976 fmt = GET_RTX_FORMAT (code);
1977 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1980 fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements);
1984 for (j = 0; j < XVECLEN (x, i); j++)
1985 fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j),
1986 insn, replacements);
1991 /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
1992 return an rtx (MEM:m1 newaddr) which is equivalent.
1993 If any insns must be emitted to compute NEWADDR, put them before INSN.
1995 UNCRITICAL nonzero means accept paradoxical subregs.
1996 This is used for subregs found inside of ZERO_EXTRACTs and in REG_NOTES. */
1999 fixup_memory_subreg (x, insn, uncritical)
2004 int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
2005 rtx addr = XEXP (SUBREG_REG (x), 0);
2006 enum machine_mode mode = GET_MODE (x);
2009 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2010 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
2014 #if BYTES_BIG_ENDIAN
2015 offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
2016 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
2018 addr = plus_constant (addr, offset);
2019 if (!flag_force_addr && memory_address_p (mode, addr))
2020 /* Shortcut if no insns need be emitted. */
2021 return change_address (SUBREG_REG (x), mode, addr);
2023 result = change_address (SUBREG_REG (x), mode, addr);
2024 emit_insn_before (gen_sequence (), insn);
2029 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2030 Replace subexpressions of X in place.
2031 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2032 Otherwise return X, with its contents possibly altered.
2034 If any insns must be emitted to compute NEWADDR, put them before INSN.
2036 UNCRITICAL is as in fixup_memory_subreg. */
2039 walk_fixup_memory_subreg (x, insn, uncritical)
2044 register enum rtx_code code;
2051 code = GET_CODE (x);
2053 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
2054 return fixup_memory_subreg (x, insn, uncritical);
2056 /* Nothing special about this RTX; fix its operands. */
2058 fmt = GET_RTX_FORMAT (code);
2059 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2062 XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn, uncritical);
2066 for (j = 0; j < XVECLEN (x, i); j++)
2068 = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn, uncritical);
2074 /* For each memory ref within X, if it refers to a stack slot
2075 with an out of range displacement, put the address in a temp register
2076 (emitting new insns before INSN to load these registers)
2077 and alter the memory ref to use that register.
2078 Replace each such MEM rtx with a copy, to avoid clobberage. */
2081 fixup_stack_1 (x, insn)
2086 register RTX_CODE code = GET_CODE (x);
2091 register rtx ad = XEXP (x, 0);
2092 /* If we have address of a stack slot but it's not valid
2093 (displacement is too large), compute the sum in a register. */
2094 if (GET_CODE (ad) == PLUS
2095 && GET_CODE (XEXP (ad, 0)) == REG
2096 && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
2097 && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER)
2098 || XEXP (ad, 0) == current_function_internal_arg_pointer)
2099 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
2102 if (memory_address_p (GET_MODE (x), ad))
2106 temp = copy_to_reg (ad);
2107 seq = gen_sequence ();
2109 emit_insn_before (seq, insn);
2110 return change_address (x, VOIDmode, temp);
2115 fmt = GET_RTX_FORMAT (code);
2116 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2119 XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
2123 for (j = 0; j < XVECLEN (x, i); j++)
2124 XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
2130 /* Optimization: a bit-field instruction whose field
2131 happens to be a byte or halfword in memory
2132 can be changed to a move instruction.
2134 We call here when INSN is an insn to examine or store into a bit-field.
2135 BODY is the SET-rtx to be altered.
2137 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2138 (Currently this is called only from function.c, and EQUIV_MEM
2142 optimize_bit_field (body, insn, equiv_mem)
2147 register rtx bitfield;
2150 enum machine_mode mode;
2152 if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
2153 || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
2154 bitfield = SET_DEST (body), destflag = 1;
2156 bitfield = SET_SRC (body), destflag = 0;
2158 /* First check that the field being stored has constant size and position
2159 and is in fact a byte or halfword suitably aligned. */
2161 if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
2162 && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
2163 && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
2165 && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
2167 register rtx memref = 0;
2169 /* Now check that the containing word is memory, not a register,
2170 and that it is safe to change the machine mode. */
2172 if (GET_CODE (XEXP (bitfield, 0)) == MEM)
2173 memref = XEXP (bitfield, 0);
2174 else if (GET_CODE (XEXP (bitfield, 0)) == REG
2176 memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
2177 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2178 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
2179 memref = SUBREG_REG (XEXP (bitfield, 0));
2180 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2182 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
2183 memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
2186 && ! mode_dependent_address_p (XEXP (memref, 0))
2187 && ! MEM_VOLATILE_P (memref))
2189 /* Now adjust the address, first for any subreg'ing
2190 that we are now getting rid of,
2191 and then for which byte of the word is wanted. */
2193 register int offset = INTVAL (XEXP (bitfield, 2));
2194 /* Adjust OFFSET to count bits from low-address byte. */
2195 #if BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN
2196 offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
2197 - offset - INTVAL (XEXP (bitfield, 1)));
2199 /* Adjust OFFSET to count bytes from low-address byte. */
2200 offset /= BITS_PER_UNIT;
2201 if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
2203 offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD;
2204 #if BYTES_BIG_ENDIAN
2205 offset -= (MIN (UNITS_PER_WORD,
2206 GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
2207 - MIN (UNITS_PER_WORD,
2208 GET_MODE_SIZE (GET_MODE (memref))));
2212 memref = change_address (memref, mode,
2213 plus_constant (XEXP (memref, 0), offset));
2215 /* Store this memory reference where
2216 we found the bit field reference. */
2220 validate_change (insn, &SET_DEST (body), memref, 1);
2221 if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
2223 rtx src = SET_SRC (body);
2224 while (GET_CODE (src) == SUBREG
2225 && SUBREG_WORD (src) == 0)
2226 src = SUBREG_REG (src);
2227 if (GET_MODE (src) != GET_MODE (memref))
2228 src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
2229 validate_change (insn, &SET_SRC (body), src, 1);
2231 else if (GET_MODE (SET_SRC (body)) != VOIDmode
2232 && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
2233 /* This shouldn't happen because anything that didn't have
2234 one of these modes should have got converted explicitly
2235 and then referenced through a subreg.
2236 This is so because the original bit-field was
2237 handled by agg_mode and so its tree structure had
2238 the same mode that memref now has. */
2243 rtx dest = SET_DEST (body);
2245 while (GET_CODE (dest) == SUBREG
2246 && SUBREG_WORD (dest) == 0)
2247 dest = SUBREG_REG (dest);
2249 validate_change (insn, &SET_DEST (body), dest, 1);
2251 if (GET_MODE (dest) == GET_MODE (memref))
2252 validate_change (insn, &SET_SRC (body), memref, 1);
2255 /* Convert the mem ref to the destination mode. */
2256 rtx newreg = gen_reg_rtx (GET_MODE (dest));
2259 convert_move (newreg, memref,
2260 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
2264 validate_change (insn, &SET_SRC (body), newreg, 1);
2268 /* See if we can convert this extraction or insertion into
2269 a simple move insn. We might not be able to do so if this
2270 was, for example, part of a PARALLEL.
2272 If we succeed, write out any needed conversions. If we fail,
2273 it is hard to guess why we failed, so don't do anything
2274 special; just let the optimization be suppressed. */
2276 if (apply_change_group () && seq)
2277 emit_insns_before (seq, insn);
2282 /* These routines are responsible for converting virtual register references
2283 to the actual hard register references once RTL generation is complete.
2285 The following four variables are used for communication between the
2286 routines. They contain the offsets of the virtual registers from their
2287 respective hard registers. */
2289 static int in_arg_offset;
2290 static int var_offset;
2291 static int dynamic_offset;
2292 static int out_arg_offset;
2294 /* In most machines, the stack pointer register is equivalent to the bottom
2297 #ifndef STACK_POINTER_OFFSET
2298 #define STACK_POINTER_OFFSET 0
2301 /* If not defined, pick an appropriate default for the offset of dynamically
2302 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2303 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2305 #ifndef STACK_DYNAMIC_OFFSET
2307 #ifdef ACCUMULATE_OUTGOING_ARGS
2308 /* The bottom of the stack points to the actual arguments. If
2309 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2310 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2311 stack space for register parameters is not pushed by the caller, but
2312 rather part of the fixed stack areas and hence not included in
2313 `current_function_outgoing_args_size'. Nevertheless, we must allow
2314 for it when allocating stack dynamic objects. */
2316 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2317 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2318 (current_function_outgoing_args_size \
2319 + REG_PARM_STACK_SPACE (FNDECL) + (STACK_POINTER_OFFSET))
2322 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2323 (current_function_outgoing_args_size + (STACK_POINTER_OFFSET))
2327 #define STACK_DYNAMIC_OFFSET(FNDECL) STACK_POINTER_OFFSET
2331 /* Pass through the INSNS of function FNDECL and convert virtual register
2332 references to hard register references. */
2335 instantiate_virtual_regs (fndecl, insns)
2341 /* Compute the offsets to use for this function. */
2342 in_arg_offset = FIRST_PARM_OFFSET (fndecl);
2343 var_offset = STARTING_FRAME_OFFSET;
2344 dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
2345 out_arg_offset = STACK_POINTER_OFFSET;
2347 /* Scan all variables and parameters of this function. For each that is
2348 in memory, instantiate all virtual registers if the result is a valid
2349 address. If not, we do it later. That will handle most uses of virtual
2350 regs on many machines. */
2351 instantiate_decls (fndecl, 1);
2353 /* Initialize recognition, indicating that volatile is OK. */
2356 /* Scan through all the insns, instantiating every virtual register still
2358 for (insn = insns; insn; insn = NEXT_INSN (insn))
2359 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
2360 || GET_CODE (insn) == CALL_INSN)
2362 instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1);
2363 instantiate_virtual_regs_1 (®_NOTES (insn), NULL_RTX, 0);
2366 /* Now instantiate the remaining register equivalences for debugging info.
2367 These will not be valid addresses. */
2368 instantiate_decls (fndecl, 0);
2370 /* Indicate that, from now on, assign_stack_local should use
2371 frame_pointer_rtx. */
2372 virtuals_instantiated = 1;
2375 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
2376 all virtual registers in their DECL_RTL's.
2378 If VALID_ONLY, do this only if the resulting address is still valid.
2379 Otherwise, always do it. */
2382 instantiate_decls (fndecl, valid_only)
2388 if (DECL_INLINE (fndecl))
2389 /* When compiling an inline function, the obstack used for
2390 rtl allocation is the maybepermanent_obstack. Calling
2391 `resume_temporary_allocation' switches us back to that
2392 obstack while we process this function's parameters. */
2393 resume_temporary_allocation ();
2395 /* Process all parameters of the function. */
2396 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
2398 instantiate_decl (DECL_RTL (decl), int_size_in_bytes (TREE_TYPE (decl)),
2400 instantiate_decl (DECL_INCOMING_RTL (decl),
2401 int_size_in_bytes (TREE_TYPE (decl)), valid_only);
2404 /* Now process all variables defined in the function or its subblocks. */
2405 instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
2407 if (DECL_INLINE (fndecl))
2409 /* Save all rtl allocated for this function by raising the
2410 high-water mark on the maybepermanent_obstack. */
2412 /* All further rtl allocation is now done in the current_obstack. */
2413 rtl_in_current_obstack ();
2417 /* Subroutine of instantiate_decls: Process all decls in the given
2418 BLOCK node and all its subblocks. */
2421 instantiate_decls_1 (let, valid_only)
2427 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
2428 instantiate_decl (DECL_RTL (t), int_size_in_bytes (TREE_TYPE (t)),
2431 /* Process all subblocks. */
2432 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
2433 instantiate_decls_1 (t, valid_only);
2436 /* Subroutine of the preceding procedures: Given RTL representing a
2437 decl and the size of the object, do any instantiation required.
2439 If VALID_ONLY is non-zero, it means that the RTL should only be
2440 changed if the new address is valid. */
2443 instantiate_decl (x, size, valid_only)
2448 enum machine_mode mode;
2451 /* If this is not a MEM, no need to do anything. Similarly if the
2452 address is a constant or a register that is not a virtual register. */
2454 if (x == 0 || GET_CODE (x) != MEM)
2458 if (CONSTANT_P (addr)
2459 || (GET_CODE (addr) == REG
2460 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
2461 || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
2464 /* If we should only do this if the address is valid, copy the address.
2465 We need to do this so we can undo any changes that might make the
2466 address invalid. This copy is unfortunate, but probably can't be
2470 addr = copy_rtx (addr);
2472 instantiate_virtual_regs_1 (&addr, NULL_RTX, 0);
2477 /* Now verify that the resulting address is valid for every integer or
2478 floating-point mode up to and including SIZE bytes long. We do this
2479 since the object might be accessed in any mode and frame addresses
2482 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2483 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
2484 mode = GET_MODE_WIDER_MODE (mode))
2485 if (! memory_address_p (mode, addr))
2488 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
2489 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
2490 mode = GET_MODE_WIDER_MODE (mode))
2491 if (! memory_address_p (mode, addr))
2494 /* Otherwise, put back the address, now that we have updated it and we
2495 know it is valid. */
2500 /* Given a pointer to a piece of rtx and an optional pointer to the
2501 containing object, instantiate any virtual registers present in it.
2503 If EXTRA_INSNS, we always do the replacement and generate
2504 any extra insns before OBJECT. If it zero, we do nothing if replacement
2507 Return 1 if we either had nothing to do or if we were able to do the
2508 needed replacement. Return 0 otherwise; we only return zero if
2509 EXTRA_INSNS is zero.
2511 We first try some simple transformations to avoid the creation of extra
2515 instantiate_virtual_regs_1 (loc, object, extra_insns)
2529 /* Re-start here to avoid recursion in common cases. */
2536 code = GET_CODE (x);
2538 /* Check for some special cases. */
2555 /* We are allowed to set the virtual registers. This means that
2556 that the actual register should receive the source minus the
2557 appropriate offset. This is used, for example, in the handling
2558 of non-local gotos. */
2559 if (SET_DEST (x) == virtual_incoming_args_rtx)
2560 new = arg_pointer_rtx, offset = - in_arg_offset;
2561 else if (SET_DEST (x) == virtual_stack_vars_rtx)
2562 new = frame_pointer_rtx, offset = - var_offset;
2563 else if (SET_DEST (x) == virtual_stack_dynamic_rtx)
2564 new = stack_pointer_rtx, offset = - dynamic_offset;
2565 else if (SET_DEST (x) == virtual_outgoing_args_rtx)
2566 new = stack_pointer_rtx, offset = - out_arg_offset;
2570 /* The only valid sources here are PLUS or REG. Just do
2571 the simplest possible thing to handle them. */
2572 if (GET_CODE (SET_SRC (x)) != REG
2573 && GET_CODE (SET_SRC (x)) != PLUS)
2577 if (GET_CODE (SET_SRC (x)) != REG)
2578 temp = force_operand (SET_SRC (x), NULL_RTX);
2581 temp = force_operand (plus_constant (temp, offset), NULL_RTX);
2585 emit_insns_before (seq, object);
2588 if (!validate_change (object, &SET_SRC (x), temp, 0)
2595 instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns);
2600 /* Handle special case of virtual register plus constant. */
2601 if (CONSTANT_P (XEXP (x, 1)))
2605 /* Check for (plus (plus VIRT foo) (const_int)) first. */
2606 if (GET_CODE (XEXP (x, 0)) == PLUS)
2608 rtx inner = XEXP (XEXP (x, 0), 0);
2610 if (inner == virtual_incoming_args_rtx)
2611 new = arg_pointer_rtx, offset = in_arg_offset;
2612 else if (inner == virtual_stack_vars_rtx)
2613 new = frame_pointer_rtx, offset = var_offset;
2614 else if (inner == virtual_stack_dynamic_rtx)
2615 new = stack_pointer_rtx, offset = dynamic_offset;
2616 else if (inner == virtual_outgoing_args_rtx)
2617 new = stack_pointer_rtx, offset = out_arg_offset;
2624 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object,
2626 new = gen_rtx (PLUS, Pmode, new, XEXP (XEXP (x, 0), 1));
2629 else if (XEXP (x, 0) == virtual_incoming_args_rtx)
2630 new = arg_pointer_rtx, offset = in_arg_offset;
2631 else if (XEXP (x, 0) == virtual_stack_vars_rtx)
2632 new = frame_pointer_rtx, offset = var_offset;
2633 else if (XEXP (x, 0) == virtual_stack_dynamic_rtx)
2634 new = stack_pointer_rtx, offset = dynamic_offset;
2635 else if (XEXP (x, 0) == virtual_outgoing_args_rtx)
2636 new = stack_pointer_rtx, offset = out_arg_offset;
2639 /* We know the second operand is a constant. Unless the
2640 first operand is a REG (which has been already checked),
2641 it needs to be checked. */
2642 if (GET_CODE (XEXP (x, 0)) != REG)
2652 new = plus_constant (XEXP (x, 1), offset);
2654 /* If the new constant is zero, try to replace the sum with its
2656 if (new == const0_rtx
2657 && validate_change (object, loc, XEXP (x, 0), 0))
2660 /* Next try to replace constant with new one. */
2661 if (!validate_change (object, &XEXP (x, 1), new, 0))
2669 /* Otherwise copy the new constant into a register and replace
2670 constant with that register. */
2671 temp = gen_reg_rtx (Pmode);
2672 if (validate_change (object, &XEXP (x, 1), temp, 0))
2673 emit_insn_before (gen_move_insn (temp, new), object);
2676 /* If that didn't work, replace this expression with a
2677 register containing the sum. */
2679 new = gen_rtx (PLUS, Pmode, XEXP (x, 0), new);
2683 temp = force_operand (new, NULL_RTX);
2687 emit_insns_before (seq, object);
2688 if (! validate_change (object, loc, temp, 0)
2689 && ! validate_replace_rtx (x, temp, object))
2697 /* Fall through to generic two-operand expression case. */
2703 case DIV: case UDIV:
2704 case MOD: case UMOD:
2705 case AND: case IOR: case XOR:
2706 case ROTATERT: case ROTATE:
2707 case ASHIFTRT: case LSHIFTRT: case ASHIFT:
2709 case GE: case GT: case GEU: case GTU:
2710 case LE: case LT: case LEU: case LTU:
2711 if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
2712 instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns);
2717 /* Most cases of MEM that convert to valid addresses have already been
2718 handled by our scan of regno_reg_rtx. The only special handling we
2719 need here is to make a copy of the rtx to ensure it isn't being
2720 shared if we have to change it to a pseudo.
2722 If the rtx is a simple reference to an address via a virtual register,
2723 it can potentially be shared. In such cases, first try to make it
2724 a valid address, which can also be shared. Otherwise, copy it and
2727 First check for common cases that need no processing. These are
2728 usually due to instantiation already being done on a previous instance
2732 if (CONSTANT_ADDRESS_P (temp)
2733 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2734 || temp == arg_pointer_rtx
2736 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2737 || temp == hard_frame_pointer_rtx
2739 || temp == frame_pointer_rtx)
2742 if (GET_CODE (temp) == PLUS
2743 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
2744 && (XEXP (temp, 0) == frame_pointer_rtx
2745 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2746 || XEXP (temp, 0) == hard_frame_pointer_rtx
2748 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2749 || XEXP (temp, 0) == arg_pointer_rtx
2754 if (temp == virtual_stack_vars_rtx
2755 || temp == virtual_incoming_args_rtx
2756 || (GET_CODE (temp) == PLUS
2757 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
2758 && (XEXP (temp, 0) == virtual_stack_vars_rtx
2759 || XEXP (temp, 0) == virtual_incoming_args_rtx)))
2761 /* This MEM may be shared. If the substitution can be done without
2762 the need to generate new pseudos, we want to do it in place
2763 so all copies of the shared rtx benefit. The call below will
2764 only make substitutions if the resulting address is still
2767 Note that we cannot pass X as the object in the recursive call
2768 since the insn being processed may not allow all valid
2769 addresses. However, if we were not passed on object, we can
2770 only modify X without copying it if X will have a valid
2773 ??? Also note that this can still lose if OBJECT is an insn that
2774 has less restrictions on an address that some other insn.
2775 In that case, we will modify the shared address. This case
2776 doesn't seem very likely, though. */
2778 if (instantiate_virtual_regs_1 (&XEXP (x, 0),
2779 object ? object : x, 0))
2782 /* Otherwise make a copy and process that copy. We copy the entire
2783 RTL expression since it might be a PLUS which could also be
2785 *loc = x = copy_rtx (x);
2788 /* Fall through to generic unary operation case. */
2792 case STRICT_LOW_PART:
2794 case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC:
2795 case SIGN_EXTEND: case ZERO_EXTEND:
2796 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE:
2797 case FLOAT: case FIX:
2798 case UNSIGNED_FIX: case UNSIGNED_FLOAT:
2802 /* These case either have just one operand or we know that we need not
2803 check the rest of the operands. */
2808 /* Try to replace with a PLUS. If that doesn't work, compute the sum
2809 in front of this insn and substitute the temporary. */
2810 if (x == virtual_incoming_args_rtx)
2811 new = arg_pointer_rtx, offset = in_arg_offset;
2812 else if (x == virtual_stack_vars_rtx)
2813 new = frame_pointer_rtx, offset = var_offset;
2814 else if (x == virtual_stack_dynamic_rtx)
2815 new = stack_pointer_rtx, offset = dynamic_offset;
2816 else if (x == virtual_outgoing_args_rtx)
2817 new = stack_pointer_rtx, offset = out_arg_offset;
2821 temp = plus_constant (new, offset);
2822 if (!validate_change (object, loc, temp, 0))
2828 temp = force_operand (temp, NULL_RTX);
2832 emit_insns_before (seq, object);
2833 if (! validate_change (object, loc, temp, 0)
2834 && ! validate_replace_rtx (x, temp, object))
2842 /* Scan all subexpressions. */
2843 fmt = GET_RTX_FORMAT (code);
2844 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
2847 if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns))
2850 else if (*fmt == 'E')
2851 for (j = 0; j < XVECLEN (x, i); j++)
2852 if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object,
2859 /* Optimization: assuming this function does not receive nonlocal gotos,
2860 delete the handlers for such, as well as the insns to establish
2861 and disestablish them. */
2867 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2869 /* Delete the handler by turning off the flag that would
2870 prevent jump_optimize from deleting it.
2871 Also permit deletion of the nonlocal labels themselves
2872 if nothing local refers to them. */
2873 if (GET_CODE (insn) == CODE_LABEL)
2874 LABEL_PRESERVE_P (insn) = 0;
2875 if (GET_CODE (insn) == INSN
2876 && ((nonlocal_goto_handler_slot != 0
2877 && reg_mentioned_p (nonlocal_goto_handler_slot, PATTERN (insn)))
2878 || (nonlocal_goto_stack_level != 0
2879 && reg_mentioned_p (nonlocal_goto_stack_level,
2885 /* Return a list (chain of EXPR_LIST nodes) for the nonlocal labels
2886 of the current function. */
2889 nonlocal_label_rtx_list ()
2894 for (t = nonlocal_labels; t; t = TREE_CHAIN (t))
2895 x = gen_rtx (EXPR_LIST, VOIDmode, label_rtx (TREE_VALUE (t)), x);
2900 /* Output a USE for any register use in RTL.
2901 This is used with -noreg to mark the extent of lifespan
2902 of any registers used in a user-visible variable's DECL_RTL. */
2908 if (GET_CODE (rtl) == REG)
2909 /* This is a register variable. */
2910 emit_insn (gen_rtx (USE, VOIDmode, rtl));
2911 else if (GET_CODE (rtl) == MEM
2912 && GET_CODE (XEXP (rtl, 0)) == REG
2913 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
2914 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
2915 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
2916 /* This is a variable-sized structure. */
2917 emit_insn (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)));
2920 /* Like use_variable except that it outputs the USEs after INSN
2921 instead of at the end of the insn-chain. */
2924 use_variable_after (rtl, insn)
2927 if (GET_CODE (rtl) == REG)
2928 /* This is a register variable. */
2929 emit_insn_after (gen_rtx (USE, VOIDmode, rtl), insn);
2930 else if (GET_CODE (rtl) == MEM
2931 && GET_CODE (XEXP (rtl, 0)) == REG
2932 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
2933 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
2934 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
2935 /* This is a variable-sized structure. */
2936 emit_insn_after (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)), insn);
2942 return max_parm_reg;
2945 /* Return the first insn following those generated by `assign_parms'. */
2948 get_first_nonparm_insn ()
2951 return NEXT_INSN (last_parm_insn);
2952 return get_insns ();
2955 /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
2956 Crash if there is none. */
2959 get_first_block_beg ()
2961 register rtx searcher;
2962 register rtx insn = get_first_nonparm_insn ();
2964 for (searcher = insn; searcher; searcher = NEXT_INSN (searcher))
2965 if (GET_CODE (searcher) == NOTE
2966 && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG)
2969 abort (); /* Invalid call to this function. (See comments above.) */
2973 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
2974 This means a type for which function calls must pass an address to the
2975 function or get an address back from the function.
2976 EXP may be a type node or an expression (whose type is tested). */
2979 aggregate_value_p (exp)
2982 int i, regno, nregs;
2985 if (TREE_CODE_CLASS (TREE_CODE (exp)) == 't')
2988 type = TREE_TYPE (exp);
2990 if (RETURN_IN_MEMORY (type))
2992 if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
2994 /* Make sure we have suitable call-clobbered regs to return
2995 the value in; if not, we must return it in memory. */
2996 reg = hard_function_value (type, 0);
2997 regno = REGNO (reg);
2998 nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type));
2999 for (i = 0; i < nregs; i++)
3000 if (! call_used_regs[regno + i])
3005 /* Assign RTL expressions to the function's parameters.
3006 This may involve copying them into registers and using
3007 those registers as the RTL for them.
3009 If SECOND_TIME is non-zero it means that this function is being
3010 called a second time. This is done by integrate.c when a function's
3011 compilation is deferred. We need to come back here in case the
3012 FUNCTION_ARG macro computes items needed for the rest of the compilation
3013 (such as changing which registers are fixed or caller-saved). But suppress
3014 writing any insns or setting DECL_RTL of anything in this case. */
3017 assign_parms (fndecl, second_time)
3022 register rtx entry_parm = 0;
3023 register rtx stack_parm = 0;
3024 CUMULATIVE_ARGS args_so_far;
3025 enum machine_mode promoted_mode, passed_mode, nominal_mode;
3027 /* Total space needed so far for args on the stack,
3028 given as a constant and a tree-expression. */
3029 struct args_size stack_args_size;
3030 tree fntype = TREE_TYPE (fndecl);
3031 tree fnargs = DECL_ARGUMENTS (fndecl);
3032 /* This is used for the arg pointer when referring to stack args. */
3033 rtx internal_arg_pointer;
3034 /* This is a dummy PARM_DECL that we used for the function result if
3035 the function returns a structure. */
3036 tree function_result_decl = 0;
3037 int nparmregs = list_length (fnargs) + LAST_VIRTUAL_REGISTER + 1;
3038 int varargs_setup = 0;
3039 rtx conversion_insns = 0;
3040 /* FUNCTION_ARG may look at this variable. Since this is not
3041 expanding a call it will always be zero in this function. */
3042 int current_call_is_indirect = 0;
3044 /* Nonzero if the last arg is named `__builtin_va_alist',
3045 which is used on some machines for old-fashioned non-ANSI varargs.h;
3046 this should be stuck onto the stack as if it had arrived there. */
3048 = (current_function_varargs
3050 && (parm = tree_last (fnargs)) != 0
3052 && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
3053 "__builtin_va_alist")));
3055 /* Nonzero if function takes extra anonymous args.
3056 This means the last named arg must be on the stack
3057 right before the anonymous ones. */
3059 = (TYPE_ARG_TYPES (fntype) != 0
3060 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3061 != void_type_node));
3063 /* If the reg that the virtual arg pointer will be translated into is
3064 not a fixed reg or is the stack pointer, make a copy of the virtual
3065 arg pointer, and address parms via the copy. The frame pointer is
3066 considered fixed even though it is not marked as such.
3068 The second time through, simply use ap to avoid generating rtx. */
3070 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
3071 || ! (fixed_regs[ARG_POINTER_REGNUM]
3072 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM))
3074 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
3076 internal_arg_pointer = virtual_incoming_args_rtx;
3077 current_function_internal_arg_pointer = internal_arg_pointer;
3079 stack_args_size.constant = 0;
3080 stack_args_size.var = 0;
3082 /* If struct value address is treated as the first argument, make it so. */
3083 if (aggregate_value_p (DECL_RESULT (fndecl))
3084 && ! current_function_returns_pcc_struct
3085 && struct_value_incoming_rtx == 0)
3087 tree type = build_pointer_type (fntype);
3089 function_result_decl = build_decl (PARM_DECL, NULL_TREE, type);
3091 DECL_ARG_TYPE (function_result_decl) = type;
3092 TREE_CHAIN (function_result_decl) = fnargs;
3093 fnargs = function_result_decl;
3096 parm_reg_stack_loc = (rtx *) oballoc (nparmregs * sizeof (rtx));
3097 bzero ((char *) parm_reg_stack_loc, nparmregs * sizeof (rtx));
3099 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
3100 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX);
3102 INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX);
3105 /* We haven't yet found an argument that we must push and pretend the
3107 current_function_pretend_args_size = 0;
3109 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
3111 int aggregate = AGGREGATE_TYPE_P (TREE_TYPE (parm));
3112 struct args_size stack_offset;
3113 struct args_size arg_size;
3114 int passed_pointer = 0;
3115 tree passed_type = DECL_ARG_TYPE (parm);
3117 /* Set LAST_NAMED if this is last named arg before some
3118 anonymous args. We treat it as if it were anonymous too. */
3119 int last_named = ((TREE_CHAIN (parm) == 0
3120 || DECL_NAME (TREE_CHAIN (parm)) == 0)
3121 && (stdarg || current_function_varargs));
3123 if (TREE_TYPE (parm) == error_mark_node
3124 /* This can happen after weird syntax errors
3125 or if an enum type is defined among the parms. */
3126 || TREE_CODE (parm) != PARM_DECL
3127 || passed_type == NULL)
3129 DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = gen_rtx (MEM, BLKmode,
3131 TREE_USED (parm) = 1;
3135 /* For varargs.h function, save info about regs and stack space
3136 used by the individual args, not including the va_alist arg. */
3137 if (hide_last_arg && last_named)
3138 current_function_args_info = args_so_far;
3140 /* Find mode of arg as it is passed, and mode of arg
3141 as it should be during execution of this function. */
3142 passed_mode = TYPE_MODE (passed_type);
3143 nominal_mode = TYPE_MODE (TREE_TYPE (parm));
3145 /* If the parm's mode is VOID, its value doesn't matter,
3146 and avoid the usual things like emit_move_insn that could crash. */
3147 if (nominal_mode == VOIDmode)
3149 DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = const0_rtx;
3153 /* See if this arg was passed by invisible reference. It is if
3154 it is an object whose size depends on the contents of the
3155 object itself or if the machine requires these objects be passed
3158 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
3159 && contains_placeholder_p (TYPE_SIZE (passed_type)))
3160 || TYPE_NEEDS_CONSTRUCTING (passed_type)
3161 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
3162 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
3163 passed_type, ! last_named)
3167 passed_type = build_pointer_type (passed_type);
3169 passed_mode = nominal_mode = Pmode;
3172 promoted_mode = passed_mode;
3174 #ifdef PROMOTE_FUNCTION_ARGS
3175 /* Compute the mode in which the arg is actually extended to. */
3176 promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1);
3179 /* Let machine desc say which reg (if any) the parm arrives in.
3180 0 means it arrives on the stack. */
3181 #ifdef FUNCTION_INCOMING_ARG
3182 entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
3183 passed_type, ! last_named);
3185 entry_parm = FUNCTION_ARG (args_so_far, promoted_mode,
3186 passed_type, ! last_named);
3190 passed_mode = promoted_mode;
3192 #ifdef SETUP_INCOMING_VARARGS
3193 /* If this is the last named parameter, do any required setup for
3194 varargs or stdargs. We need to know about the case of this being an
3195 addressable type, in which case we skip the registers it
3196 would have arrived in.
3198 For stdargs, LAST_NAMED will be set for two parameters, the one that
3199 is actually the last named, and the dummy parameter. We only
3200 want to do this action once.
3202 Also, indicate when RTL generation is to be suppressed. */
3203 if (last_named && !varargs_setup)
3205 SETUP_INCOMING_VARARGS (args_so_far, passed_mode, passed_type,
3206 current_function_pretend_args_size,
3212 /* Determine parm's home in the stack,
3213 in case it arrives in the stack or we should pretend it did.
3215 Compute the stack position and rtx where the argument arrives
3218 There is one complexity here: If this was a parameter that would
3219 have been passed in registers, but wasn't only because it is
3220 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
3221 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
3222 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
3223 0 as it was the previous time. */
3225 locate_and_pad_parm (passed_mode, passed_type,
3226 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3229 #ifdef FUNCTION_INCOMING_ARG
3230 FUNCTION_INCOMING_ARG (args_so_far, passed_mode,
3233 || varargs_setup)) != 0,
3235 FUNCTION_ARG (args_so_far, passed_mode,
3237 ! last_named || varargs_setup) != 0,
3240 fndecl, &stack_args_size, &stack_offset, &arg_size);
3244 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
3246 if (offset_rtx == const0_rtx)
3247 stack_parm = gen_rtx (MEM, passed_mode, internal_arg_pointer);
3249 stack_parm = gen_rtx (MEM, passed_mode,
3250 gen_rtx (PLUS, Pmode,
3251 internal_arg_pointer, offset_rtx));
3253 /* If this is a memory ref that contains aggregate components,
3254 mark it as such for cse and loop optimize. */
3255 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3258 /* If this parameter was passed both in registers and in the stack,
3259 use the copy on the stack. */
3260 if (MUST_PASS_IN_STACK (passed_mode, passed_type))
3263 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3264 /* If this parm was passed part in regs and part in memory,
3265 pretend it arrived entirely in memory
3266 by pushing the register-part onto the stack.
3268 In the special case of a DImode or DFmode that is split,
3269 we could put it together in a pseudoreg directly,
3270 but for now that's not worth bothering with. */
3274 int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, passed_mode,
3275 passed_type, ! last_named);
3279 current_function_pretend_args_size
3280 = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
3281 / (PARM_BOUNDARY / BITS_PER_UNIT)
3282 * (PARM_BOUNDARY / BITS_PER_UNIT));
3285 move_block_from_reg (REGNO (entry_parm),
3286 validize_mem (stack_parm), nregs,
3287 int_size_in_bytes (TREE_TYPE (parm)));
3288 entry_parm = stack_parm;
3293 /* If we didn't decide this parm came in a register,
3294 by default it came on the stack. */
3295 if (entry_parm == 0)
3296 entry_parm = stack_parm;
3298 /* Record permanently how this parm was passed. */
3300 DECL_INCOMING_RTL (parm) = entry_parm;
3302 /* If there is actually space on the stack for this parm,
3303 count it in stack_args_size; otherwise set stack_parm to 0
3304 to indicate there is no preallocated stack slot for the parm. */
3306 if (entry_parm == stack_parm
3307 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
3308 /* On some machines, even if a parm value arrives in a register
3309 there is still an (uninitialized) stack slot allocated for it.
3311 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
3312 whether this parameter already has a stack slot allocated,
3313 because an arg block exists only if current_function_args_size
3314 is larger than some threshhold, and we haven't calculated that
3315 yet. So, for now, we just assume that stack slots never exist
3317 || REG_PARM_STACK_SPACE (fndecl) > 0
3321 stack_args_size.constant += arg_size.constant;
3323 ADD_PARM_SIZE (stack_args_size, arg_size.var);
3326 /* No stack slot was pushed for this parm. */
3329 /* Update info on where next arg arrives in registers. */
3331 FUNCTION_ARG_ADVANCE (args_so_far, passed_mode,
3332 passed_type, ! last_named);
3334 /* If this is our second time through, we are done with this parm. */
3338 /* If we can't trust the parm stack slot to be aligned enough
3339 for its ultimate type, don't use that slot after entry.
3340 We'll make another stack slot, if we need one. */
3342 int thisparm_boundary
3343 = FUNCTION_ARG_BOUNDARY (passed_mode, passed_type);
3345 if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary)
3349 /* If parm was passed in memory, and we need to convert it on entry,
3350 don't store it back in that same slot. */
3352 && nominal_mode != BLKmode && nominal_mode != passed_mode)
3356 /* Now adjust STACK_PARM to the mode and precise location
3357 where this parameter should live during execution,
3358 if we discover that it must live in the stack during execution.
3359 To make debuggers happier on big-endian machines, we store
3360 the value in the last bytes of the space available. */
3362 if (nominal_mode != BLKmode && nominal_mode != passed_mode
3367 #if BYTES_BIG_ENDIAN
3368 if (GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD)
3369 stack_offset.constant += (GET_MODE_SIZE (passed_mode)
3370 - GET_MODE_SIZE (nominal_mode));
3373 offset_rtx = ARGS_SIZE_RTX (stack_offset);
3374 if (offset_rtx == const0_rtx)
3375 stack_parm = gen_rtx (MEM, nominal_mode, internal_arg_pointer);
3377 stack_parm = gen_rtx (MEM, nominal_mode,
3378 gen_rtx (PLUS, Pmode,
3379 internal_arg_pointer, offset_rtx));
3381 /* If this is a memory ref that contains aggregate components,
3382 mark it as such for cse and loop optimize. */
3383 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3387 /* ENTRY_PARM is an RTX for the parameter as it arrives,
3388 in the mode in which it arrives.
3389 STACK_PARM is an RTX for a stack slot where the parameter can live
3390 during the function (in case we want to put it there).
3391 STACK_PARM is 0 if no stack slot was pushed for it.
3393 Now output code if necessary to convert ENTRY_PARM to
3394 the type in which this function declares it,
3395 and store that result in an appropriate place,
3396 which may be a pseudo reg, may be STACK_PARM,
3397 or may be a local stack slot if STACK_PARM is 0.
3399 Set DECL_RTL to that place. */
3401 if (nominal_mode == BLKmode)
3403 /* If a BLKmode arrives in registers, copy it to a stack slot. */
3404 if (GET_CODE (entry_parm) == REG)
3406 int size_stored = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
3409 /* Note that we will be storing an integral number of words.
3410 So we have to be careful to ensure that we allocate an
3411 integral number of words. We do this below in the
3412 assign_stack_local if space was not allocated in the argument
3413 list. If it was, this will not work if PARM_BOUNDARY is not
3414 a multiple of BITS_PER_WORD. It isn't clear how to fix this
3415 if it becomes a problem. */
3417 if (stack_parm == 0)
3420 = assign_stack_local (GET_MODE (entry_parm), size_stored, 0);
3421 /* If this is a memory ref that contains aggregate components,
3422 mark it as such for cse and loop optimize. */
3423 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3426 else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
3429 move_block_from_reg (REGNO (entry_parm),
3430 validize_mem (stack_parm),
3431 size_stored / UNITS_PER_WORD,
3432 int_size_in_bytes (TREE_TYPE (parm)));
3434 DECL_RTL (parm) = stack_parm;
3436 else if (! ((obey_regdecls && ! DECL_REGISTER (parm)
3437 && ! DECL_INLINE (fndecl))
3438 /* layout_decl may set this. */
3439 || TREE_ADDRESSABLE (parm)
3440 || TREE_SIDE_EFFECTS (parm)
3441 /* If -ffloat-store specified, don't put explicit
3442 float variables into registers. */
3443 || (flag_float_store
3444 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
3445 /* Always assign pseudo to structure return or item passed
3446 by invisible reference. */
3447 || passed_pointer || parm == function_result_decl)
3449 /* Store the parm in a pseudoregister during the function, but we
3450 may need to do it in a wider mode. */
3452 register rtx parmreg;
3453 int regno, regnoi, regnor;
3455 unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
3456 nominal_mode = promote_mode (TREE_TYPE (parm), nominal_mode,
3459 parmreg = gen_reg_rtx (nominal_mode);
3460 REG_USERVAR_P (parmreg) = 1;
3462 /* If this was an item that we received a pointer to, set DECL_RTL
3466 DECL_RTL (parm) = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (passed_type)), parmreg);
3467 MEM_IN_STRUCT_P (DECL_RTL (parm)) = aggregate;
3470 DECL_RTL (parm) = parmreg;
3472 /* Copy the value into the register. */
3473 if (GET_MODE (parmreg) != GET_MODE (entry_parm))
3475 /* If ENTRY_PARM is a hard register, it might be in a register
3476 not valid for operating in its mode (e.g., an odd-numbered
3477 register for a DFmode). In that case, moves are the only
3478 thing valid, so we can't do a convert from there. This
3479 occurs when the calling sequence allow such misaligned
3482 In addition, the conversion may involve a call, which could
3483 clobber parameters which haven't been copied to pseudo
3484 registers yet. Therefore, we must first copy the parm to
3485 a pseudo reg here, and save the conversion until after all
3486 parameters have been moved. */
3488 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
3490 emit_move_insn (tempreg, validize_mem (entry_parm));
3492 push_to_sequence (conversion_insns);
3493 convert_move (parmreg, tempreg, unsignedp);
3494 conversion_insns = get_insns ();
3498 emit_move_insn (parmreg, validize_mem (entry_parm));
3500 /* If we were passed a pointer but the actual value
3501 can safely live in a register, put it in one. */
3502 if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
3503 && ! ((obey_regdecls && ! DECL_REGISTER (parm)
3504 && ! DECL_INLINE (fndecl))
3505 /* layout_decl may set this. */
3506 || TREE_ADDRESSABLE (parm)
3507 || TREE_SIDE_EFFECTS (parm)
3508 /* If -ffloat-store specified, don't put explicit
3509 float variables into registers. */
3510 || (flag_float_store
3511 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))
3513 /* We can't use nominal_mode, because it will have been set to
3514 Pmode above. We must use the actual mode of the parm. */
3515 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
3516 REG_USERVAR_P (parmreg) = 1;
3517 emit_move_insn (parmreg, DECL_RTL (parm));
3518 DECL_RTL (parm) = parmreg;
3519 /* STACK_PARM is the pointer, not the parm, and PARMREG is
3523 #ifdef FUNCTION_ARG_CALLEE_COPIES
3524 /* If we are passed an arg by reference and it is our responsibility
3525 to make a copy, do it now.
3526 PASSED_TYPE and PASSED mode now refer to the pointer, not the
3527 original argument, so we must recreate them in the call to
3528 FUNCTION_ARG_CALLEE_COPIES. */
3529 /* ??? Later add code to handle the case that if the argument isn't
3530 modified, don't do the copy. */
3532 else if (passed_pointer
3533 && FUNCTION_ARG_CALLEE_COPIES (args_so_far,
3534 TYPE_MODE (DECL_ARG_TYPE (parm)),
3535 DECL_ARG_TYPE (parm),
3539 tree type = DECL_ARG_TYPE (parm);
3541 /* This sequence may involve a library call perhaps clobbering
3542 registers that haven't been copied to pseudos yet. */
3544 push_to_sequence (conversion_insns);
3546 if (TYPE_SIZE (type) == 0
3547 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
3548 /* This is a variable sized object. */
3549 copy = gen_rtx (MEM, BLKmode,
3550 allocate_dynamic_stack_space
3551 (expr_size (parm), NULL_RTX,
3552 TYPE_ALIGN (type)));
3554 copy = assign_stack_temp (TYPE_MODE (type),
3555 int_size_in_bytes (type), 1);
3557 store_expr (parm, copy, 0);
3558 emit_move_insn (parmreg, XEXP (copy, 0));
3559 conversion_insns = get_insns ();
3562 #endif /* FUNCTION_ARG_CALLEE_COPIES */
3564 /* In any case, record the parm's desired stack location
3565 in case we later discover it must live in the stack.
3567 If it is a COMPLEX value, store the stack location for both
3570 if (GET_CODE (parmreg) == CONCAT)
3571 regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1)));
3573 regno = REGNO (parmreg);
3575 if (regno >= nparmregs)
3578 int old_nparmregs = nparmregs;
3580 nparmregs = regno + 5;
3581 new = (rtx *) oballoc (nparmregs * sizeof (rtx));
3582 bcopy ((char *) parm_reg_stack_loc, (char *) new,
3583 old_nparmregs * sizeof (rtx));
3584 bzero ((char *) (new + old_nparmregs),
3585 (nparmregs - old_nparmregs) * sizeof (rtx));
3586 parm_reg_stack_loc = new;
3589 if (GET_CODE (parmreg) == CONCAT)
3591 enum machine_mode submode = GET_MODE (XEXP (parmreg, 0));
3593 regnor = REGNO (gen_realpart (submode, parmreg));
3594 regnoi = REGNO (gen_imagpart (submode, parmreg));
3596 if (stack_parm != 0)
3598 parm_reg_stack_loc[regnor]
3599 = gen_realpart (submode, stack_parm);
3600 parm_reg_stack_loc[regnoi]
3601 = gen_imagpart (submode, stack_parm);
3605 parm_reg_stack_loc[regnor] = 0;
3606 parm_reg_stack_loc[regnoi] = 0;
3610 parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
3612 /* Mark the register as eliminable if we did no conversion
3613 and it was copied from memory at a fixed offset,
3614 and the arg pointer was not copied to a pseudo-reg.
3615 If the arg pointer is a pseudo reg or the offset formed
3616 an invalid address, such memory-equivalences
3617 as we make here would screw up life analysis for it. */
3618 if (nominal_mode == passed_mode
3619 && ! conversion_insns
3620 && GET_CODE (entry_parm) == MEM
3621 && entry_parm == stack_parm
3622 && stack_offset.var == 0
3623 && reg_mentioned_p (virtual_incoming_args_rtx,
3624 XEXP (entry_parm, 0)))
3626 rtx linsn = get_last_insn ();
3628 /* Mark complex types separately. */
3629 if (GET_CODE (parmreg) == CONCAT)
3632 = gen_rtx (EXPR_LIST, REG_EQUIV,
3633 parm_reg_stack_loc[regnoi], REG_NOTES (linsn));
3635 /* Now search backward for where we set the real part. */
3637 && ! reg_referenced_p (parm_reg_stack_loc[regnor],
3639 linsn = prev_nonnote_insn (linsn))
3643 = gen_rtx (EXPR_LIST, REG_EQUIV,
3644 parm_reg_stack_loc[regnor], REG_NOTES (linsn));
3648 = gen_rtx (EXPR_LIST, REG_EQUIV,
3649 entry_parm, REG_NOTES (linsn));
3652 /* For pointer data type, suggest pointer register. */
3653 if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE)
3654 mark_reg_pointer (parmreg);
3658 /* Value must be stored in the stack slot STACK_PARM
3659 during function execution. */
3661 if (passed_mode != nominal_mode)
3663 /* Conversion is required. */
3664 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
3666 emit_move_insn (tempreg, validize_mem (entry_parm));
3668 push_to_sequence (conversion_insns);
3669 entry_parm = convert_to_mode (nominal_mode, tempreg,
3670 TREE_UNSIGNED (TREE_TYPE (parm)));
3671 conversion_insns = get_insns ();
3675 if (entry_parm != stack_parm)
3677 if (stack_parm == 0)
3680 = assign_stack_local (GET_MODE (entry_parm),
3681 GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
3682 /* If this is a memory ref that contains aggregate components,
3683 mark it as such for cse and loop optimize. */
3684 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3687 if (passed_mode != nominal_mode)
3689 push_to_sequence (conversion_insns);
3690 emit_move_insn (validize_mem (stack_parm),
3691 validize_mem (entry_parm));
3692 conversion_insns = get_insns ();
3696 emit_move_insn (validize_mem (stack_parm),
3697 validize_mem (entry_parm));
3700 DECL_RTL (parm) = stack_parm;
3703 /* If this "parameter" was the place where we are receiving the
3704 function's incoming structure pointer, set up the result. */
3705 if (parm == function_result_decl)
3707 tree result = DECL_RESULT (fndecl);
3708 tree restype = TREE_TYPE (result);
3711 = gen_rtx (MEM, DECL_MODE (result), DECL_RTL (parm));
3713 MEM_IN_STRUCT_P (DECL_RTL (result)) = AGGREGATE_TYPE_P (restype);
3716 if (TREE_THIS_VOLATILE (parm))
3717 MEM_VOLATILE_P (DECL_RTL (parm)) = 1;
3718 if (TREE_READONLY (parm))
3719 RTX_UNCHANGING_P (DECL_RTL (parm)) = 1;
3722 /* Output all parameter conversion instructions (possibly including calls)
3723 now that all parameters have been copied out of hard registers. */
3724 emit_insns (conversion_insns);
3726 max_parm_reg = max_reg_num ();
3727 last_parm_insn = get_last_insn ();
3729 current_function_args_size = stack_args_size.constant;
3731 /* Adjust function incoming argument size for alignment and
3734 #ifdef REG_PARM_STACK_SPACE
3735 #ifndef MAYBE_REG_PARM_STACK_SPACE
3736 current_function_args_size = MAX (current_function_args_size,
3737 REG_PARM_STACK_SPACE (fndecl));
3741 #ifdef STACK_BOUNDARY
3742 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
3744 current_function_args_size
3745 = ((current_function_args_size + STACK_BYTES - 1)
3746 / STACK_BYTES) * STACK_BYTES;
3749 #ifdef ARGS_GROW_DOWNWARD
3750 current_function_arg_offset_rtx
3751 = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
3752 : expand_expr (size_binop (MINUS_EXPR, stack_args_size.var,
3753 size_int (-stack_args_size.constant)),
3754 NULL_RTX, VOIDmode, 0));
3756 current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
3759 /* See how many bytes, if any, of its args a function should try to pop
3762 current_function_pops_args = RETURN_POPS_ARGS (TREE_TYPE (fndecl),
3763 current_function_args_size);
3765 /* For stdarg.h function, save info about
3766 regs and stack space used by the named args. */
3769 current_function_args_info = args_so_far;
3771 /* Set the rtx used for the function return value. Put this in its
3772 own variable so any optimizers that need this information don't have
3773 to include tree.h. Do this here so it gets done when an inlined
3774 function gets output. */
3776 current_function_return_rtx = DECL_RTL (DECL_RESULT (fndecl));
3779 /* Indicate whether REGNO is an incoming argument to the current function
3780 that was promoted to a wider mode. If so, return the RTX for the
3781 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
3782 that REGNO is promoted from and whether the promotion was signed or
3785 #ifdef PROMOTE_FUNCTION_ARGS
3788 promoted_input_arg (regno, pmode, punsignedp)
3790 enum machine_mode *pmode;
3795 for (arg = DECL_ARGUMENTS (current_function_decl); arg;
3796 arg = TREE_CHAIN (arg))
3797 if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
3798 && REGNO (DECL_INCOMING_RTL (arg)) == regno)
3800 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
3801 int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
3803 mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1);
3804 if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
3805 && mode != DECL_MODE (arg))
3807 *pmode = DECL_MODE (arg);
3808 *punsignedp = unsignedp;
3809 return DECL_INCOMING_RTL (arg);
3818 /* Compute the size and offset from the start of the stacked arguments for a
3819 parm passed in mode PASSED_MODE and with type TYPE.
3821 INITIAL_OFFSET_PTR points to the current offset into the stacked
3824 The starting offset and size for this parm are returned in *OFFSET_PTR
3825 and *ARG_SIZE_PTR, respectively.
3827 IN_REGS is non-zero if the argument will be passed in registers. It will
3828 never be set if REG_PARM_STACK_SPACE is not defined.
3830 FNDECL is the function in which the argument was defined.
3832 There are two types of rounding that are done. The first, controlled by
3833 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
3834 list to be aligned to the specific boundary (in bits). This rounding
3835 affects the initial and starting offsets, but not the argument size.
3837 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
3838 optionally rounds the size of the parm to PARM_BOUNDARY. The
3839 initial offset is not affected by this rounding, while the size always
3840 is and the starting offset may be. */
3842 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
3843 initial_offset_ptr is positive because locate_and_pad_parm's
3844 callers pass in the total size of args so far as
3845 initial_offset_ptr. arg_size_ptr is always positive.*/
3848 locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
3849 initial_offset_ptr, offset_ptr, arg_size_ptr)
3850 enum machine_mode passed_mode;
3854 struct args_size *initial_offset_ptr;
3855 struct args_size *offset_ptr;
3856 struct args_size *arg_size_ptr;
3859 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
3860 enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
3861 int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
3862 int boundary_in_bytes = boundary / BITS_PER_UNIT;
3863 int reg_parm_stack_space = 0;
3865 #ifdef REG_PARM_STACK_SPACE
3866 /* If we have found a stack parm before we reach the end of the
3867 area reserved for registers, skip that area. */
3870 #ifdef MAYBE_REG_PARM_STACK_SPACE
3871 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
3873 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
3875 if (reg_parm_stack_space > 0)
3877 if (initial_offset_ptr->var)
3879 initial_offset_ptr->var
3880 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
3881 size_int (reg_parm_stack_space));
3882 initial_offset_ptr->constant = 0;
3884 else if (initial_offset_ptr->constant < reg_parm_stack_space)
3885 initial_offset_ptr->constant = reg_parm_stack_space;
3888 #endif /* REG_PARM_STACK_SPACE */
3890 arg_size_ptr->var = 0;
3891 arg_size_ptr->constant = 0;
3893 #ifdef ARGS_GROW_DOWNWARD
3894 if (initial_offset_ptr->var)
3896 offset_ptr->constant = 0;
3897 offset_ptr->var = size_binop (MINUS_EXPR, integer_zero_node,
3898 initial_offset_ptr->var);
3902 offset_ptr->constant = - initial_offset_ptr->constant;
3903 offset_ptr->var = 0;
3905 if (where_pad != none
3906 && (TREE_CODE (sizetree) != INTEGER_CST
3907 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
3908 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
3909 SUB_PARM_SIZE (*offset_ptr, sizetree);
3910 if (where_pad != downward)
3911 pad_to_arg_alignment (offset_ptr, boundary);
3912 if (initial_offset_ptr->var)
3914 arg_size_ptr->var = size_binop (MINUS_EXPR,
3915 size_binop (MINUS_EXPR,
3917 initial_offset_ptr->var),
3922 arg_size_ptr->constant = (- initial_offset_ptr->constant -
3923 offset_ptr->constant);
3925 #else /* !ARGS_GROW_DOWNWARD */
3926 pad_to_arg_alignment (initial_offset_ptr, boundary);
3927 *offset_ptr = *initial_offset_ptr;
3929 #ifdef PUSH_ROUNDING
3930 if (passed_mode != BLKmode)
3931 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
3934 if (where_pad != none
3935 && (TREE_CODE (sizetree) != INTEGER_CST
3936 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
3937 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
3939 /* This must be done after rounding sizetree, so that it will subtract
3940 the same value that we explicitly add below. */
3941 if (where_pad == downward)
3942 pad_below (offset_ptr, passed_mode, sizetree);
3943 ADD_PARM_SIZE (*arg_size_ptr, sizetree);
3944 #endif /* ARGS_GROW_DOWNWARD */
3947 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
3948 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
3951 pad_to_arg_alignment (offset_ptr, boundary)
3952 struct args_size *offset_ptr;
3955 int boundary_in_bytes = boundary / BITS_PER_UNIT;
3957 if (boundary > BITS_PER_UNIT)
3959 if (offset_ptr->var)
3962 #ifdef ARGS_GROW_DOWNWARD
3967 (ARGS_SIZE_TREE (*offset_ptr),
3968 boundary / BITS_PER_UNIT);
3969 offset_ptr->constant = 0; /*?*/
3972 offset_ptr->constant =
3973 #ifdef ARGS_GROW_DOWNWARD
3974 FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes);
3976 CEIL_ROUND (offset_ptr->constant, boundary_in_bytes);
3982 pad_below (offset_ptr, passed_mode, sizetree)
3983 struct args_size *offset_ptr;
3984 enum machine_mode passed_mode;
3987 if (passed_mode != BLKmode)
3989 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
3990 offset_ptr->constant
3991 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
3992 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
3993 - GET_MODE_SIZE (passed_mode));
3997 if (TREE_CODE (sizetree) != INTEGER_CST
3998 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
4000 /* Round the size up to multiple of PARM_BOUNDARY bits. */
4001 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4003 ADD_PARM_SIZE (*offset_ptr, s2);
4004 SUB_PARM_SIZE (*offset_ptr, sizetree);
4010 round_down (value, divisor)
4014 return size_binop (MULT_EXPR,
4015 size_binop (FLOOR_DIV_EXPR, value, size_int (divisor)),
4016 size_int (divisor));
4019 /* Walk the tree of blocks describing the binding levels within a function
4020 and warn about uninitialized variables.
4021 This is done after calling flow_analysis and before global_alloc
4022 clobbers the pseudo-regs to hard regs. */
4025 uninitialized_vars_warning (block)
4028 register tree decl, sub;
4029 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
4031 if (TREE_CODE (decl) == VAR_DECL
4032 /* These warnings are unreliable for and aggregates
4033 because assigning the fields one by one can fail to convince
4034 flow.c that the entire aggregate was initialized.
4035 Unions are troublesome because members may be shorter. */
4036 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl))
4037 && DECL_RTL (decl) != 0
4038 && GET_CODE (DECL_RTL (decl)) == REG
4039 && regno_uninitialized (REGNO (DECL_RTL (decl))))
4040 warning_with_decl (decl,
4041 "`%s' might be used uninitialized in this function");
4042 if (TREE_CODE (decl) == VAR_DECL
4043 && DECL_RTL (decl) != 0
4044 && GET_CODE (DECL_RTL (decl)) == REG
4045 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
4046 warning_with_decl (decl,
4047 "variable `%s' might be clobbered by `longjmp' or `vfork'");
4049 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
4050 uninitialized_vars_warning (sub);
4053 /* Do the appropriate part of uninitialized_vars_warning
4054 but for arguments instead of local variables. */
4057 setjmp_args_warning (block)
4061 for (decl = DECL_ARGUMENTS (current_function_decl);
4062 decl; decl = TREE_CHAIN (decl))
4063 if (DECL_RTL (decl) != 0
4064 && GET_CODE (DECL_RTL (decl)) == REG
4065 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
4066 warning_with_decl (decl, "argument `%s' might be clobbered by `longjmp' or `vfork'");
4069 /* If this function call setjmp, put all vars into the stack
4070 unless they were declared `register'. */
4073 setjmp_protect (block)
4076 register tree decl, sub;
4077 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
4078 if ((TREE_CODE (decl) == VAR_DECL
4079 || TREE_CODE (decl) == PARM_DECL)
4080 && DECL_RTL (decl) != 0
4081 && GET_CODE (DECL_RTL (decl)) == REG
4082 /* If this variable came from an inline function, it must be
4083 that it's life doesn't overlap the setjmp. If there was a
4084 setjmp in the function, it would already be in memory. We
4085 must exclude such variable because their DECL_RTL might be
4086 set to strange things such as virtual_stack_vars_rtx. */
4087 && ! DECL_FROM_INLINE (decl)
4089 #ifdef NON_SAVING_SETJMP
4090 /* If longjmp doesn't restore the registers,
4091 don't put anything in them. */
4095 ! DECL_REGISTER (decl)))
4096 put_var_into_stack (decl);
4097 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
4098 setjmp_protect (sub);
4101 /* Like the previous function, but for args instead of local variables. */
4104 setjmp_protect_args ()
4106 register tree decl, sub;
4107 for (decl = DECL_ARGUMENTS (current_function_decl);
4108 decl; decl = TREE_CHAIN (decl))
4109 if ((TREE_CODE (decl) == VAR_DECL
4110 || TREE_CODE (decl) == PARM_DECL)
4111 && DECL_RTL (decl) != 0
4112 && GET_CODE (DECL_RTL (decl)) == REG
4114 /* If longjmp doesn't restore the registers,
4115 don't put anything in them. */
4116 #ifdef NON_SAVING_SETJMP
4120 ! DECL_REGISTER (decl)))
4121 put_var_into_stack (decl);
4124 /* Return the context-pointer register corresponding to DECL,
4125 or 0 if it does not need one. */
4128 lookup_static_chain (decl)
4131 tree context = decl_function_context (decl);
4137 /* We treat inline_function_decl as an alias for the current function
4138 because that is the inline function whose vars, types, etc.
4139 are being merged into the current function.
4140 See expand_inline_function. */
4141 if (context == current_function_decl || context == inline_function_decl)
4142 return virtual_stack_vars_rtx;
4144 for (link = context_display; link; link = TREE_CHAIN (link))
4145 if (TREE_PURPOSE (link) == context)
4146 return RTL_EXPR_RTL (TREE_VALUE (link));
4151 /* Convert a stack slot address ADDR for variable VAR
4152 (from a containing function)
4153 into an address valid in this function (using a static chain). */
4156 fix_lexical_addr (addr, var)
4162 tree context = decl_function_context (var);
4163 struct function *fp;
4166 /* If this is the present function, we need not do anything. */
4167 if (context == current_function_decl || context == inline_function_decl)
4170 for (fp = outer_function_chain; fp; fp = fp->next)
4171 if (fp->decl == context)
4177 /* Decode given address as base reg plus displacement. */
4178 if (GET_CODE (addr) == REG)
4179 basereg = addr, displacement = 0;
4180 else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
4181 basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
4185 /* We accept vars reached via the containing function's
4186 incoming arg pointer and via its stack variables pointer. */
4187 if (basereg == fp->internal_arg_pointer)
4189 /* If reached via arg pointer, get the arg pointer value
4190 out of that function's stack frame.
4192 There are two cases: If a separate ap is needed, allocate a
4193 slot in the outer function for it and dereference it that way.
4194 This is correct even if the real ap is actually a pseudo.
4195 Otherwise, just adjust the offset from the frame pointer to
4198 #ifdef NEED_SEPARATE_AP
4201 if (fp->arg_pointer_save_area == 0)
4202 fp->arg_pointer_save_area
4203 = assign_outer_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0, fp);
4205 addr = fix_lexical_addr (XEXP (fp->arg_pointer_save_area, 0), var);
4206 addr = memory_address (Pmode, addr);
4208 base = copy_to_reg (gen_rtx (MEM, Pmode, addr));
4210 displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
4211 base = lookup_static_chain (var);
4215 else if (basereg == virtual_stack_vars_rtx)
4217 /* This is the same code as lookup_static_chain, duplicated here to
4218 avoid an extra call to decl_function_context. */
4221 for (link = context_display; link; link = TREE_CHAIN (link))
4222 if (TREE_PURPOSE (link) == context)
4224 base = RTL_EXPR_RTL (TREE_VALUE (link));
4232 /* Use same offset, relative to appropriate static chain or argument
4234 return plus_constant (base, displacement);
4237 /* Return the address of the trampoline for entering nested fn FUNCTION.
4238 If necessary, allocate a trampoline (in the stack frame)
4239 and emit rtl to initialize its contents (at entry to this function). */
4242 trampoline_address (function)
4248 struct function *fp;
4251 /* Find an existing trampoline and return it. */
4252 for (link = trampoline_list; link; link = TREE_CHAIN (link))
4253 if (TREE_PURPOSE (link) == function)
4254 return XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0);
4255 for (fp = outer_function_chain; fp; fp = fp->next)
4256 for (link = fp->trampoline_list; link; link = TREE_CHAIN (link))
4257 if (TREE_PURPOSE (link) == function)
4259 tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
4261 return round_trampoline_addr (tramp);
4264 /* None exists; we must make one. */
4266 /* Find the `struct function' for the function containing FUNCTION. */
4268 fn_context = decl_function_context (function);
4269 if (fn_context != current_function_decl)
4270 for (fp = outer_function_chain; fp; fp = fp->next)
4271 if (fp->decl == fn_context)
4274 /* Allocate run-time space for this trampoline
4275 (usually in the defining function's stack frame). */
4276 #ifdef ALLOCATE_TRAMPOLINE
4277 tramp = ALLOCATE_TRAMPOLINE (fp);
4279 /* If rounding needed, allocate extra space
4280 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
4281 #ifdef TRAMPOLINE_ALIGNMENT
4282 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE + TRAMPOLINE_ALIGNMENT - 1)
4284 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
4287 tramp = assign_outer_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0, fp);
4289 tramp = assign_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0);
4292 /* Record the trampoline for reuse and note it for later initialization
4293 by expand_function_end. */
4296 push_obstacks (fp->function_maybepermanent_obstack,
4297 fp->function_maybepermanent_obstack);
4298 rtlexp = make_node (RTL_EXPR);
4299 RTL_EXPR_RTL (rtlexp) = tramp;
4300 fp->trampoline_list = tree_cons (function, rtlexp, fp->trampoline_list);
4305 /* Make the RTL_EXPR node temporary, not momentary, so that the
4306 trampoline_list doesn't become garbage. */
4307 int momentary = suspend_momentary ();
4308 rtlexp = make_node (RTL_EXPR);
4309 resume_momentary (momentary);
4311 RTL_EXPR_RTL (rtlexp) = tramp;
4312 trampoline_list = tree_cons (function, rtlexp, trampoline_list);
4315 tramp = fix_lexical_addr (XEXP (tramp, 0), function);
4316 return round_trampoline_addr (tramp);
4319 /* Given a trampoline address,
4320 round it to multiple of TRAMPOLINE_ALIGNMENT. */
4323 round_trampoline_addr (tramp)
4326 #ifdef TRAMPOLINE_ALIGNMENT
4327 /* Round address up to desired boundary. */
4328 rtx temp = gen_reg_rtx (Pmode);
4329 temp = expand_binop (Pmode, add_optab, tramp,
4330 GEN_INT (TRAMPOLINE_ALIGNMENT - 1),
4331 temp, 0, OPTAB_LIB_WIDEN);
4332 tramp = expand_binop (Pmode, and_optab, temp,
4333 GEN_INT (- TRAMPOLINE_ALIGNMENT),
4334 temp, 0, OPTAB_LIB_WIDEN);
4339 /* The functions identify_blocks and reorder_blocks provide a way to
4340 reorder the tree of BLOCK nodes, for optimizers that reshuffle or
4341 duplicate portions of the RTL code. Call identify_blocks before
4342 changing the RTL, and call reorder_blocks after. */
4344 /* Put all this function's BLOCK nodes into a vector, and return it.
4345 Also store in each NOTE for the beginning or end of a block
4346 the index of that block in the vector.
4347 The arguments are TOP_BLOCK, the top-level block of the function,
4348 and INSNS, the insn chain of the function. */
4351 identify_blocks (top_block, insns)
4359 int next_block_number = 0;
4360 int current_block_number = 0;
4366 n_blocks = all_blocks (top_block, 0);
4367 block_vector = (tree *) xmalloc (n_blocks * sizeof (tree));
4368 block_stack = (int *) alloca (n_blocks * sizeof (int));
4370 all_blocks (top_block, block_vector);
4372 for (insn = insns; insn; insn = NEXT_INSN (insn))
4373 if (GET_CODE (insn) == NOTE)
4375 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
4377 block_stack[depth++] = current_block_number;
4378 current_block_number = next_block_number;
4379 NOTE_BLOCK_NUMBER (insn) = next_block_number++;
4381 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
4383 current_block_number = block_stack[--depth];
4384 NOTE_BLOCK_NUMBER (insn) = current_block_number;
4388 return block_vector;
4391 /* Given BLOCK_VECTOR which was returned by identify_blocks,
4392 and a revised instruction chain, rebuild the tree structure
4393 of BLOCK nodes to correspond to the new order of RTL.
4394 The new block tree is inserted below TOP_BLOCK.
4395 Returns the current top-level block. */
4398 reorder_blocks (block_vector, top_block, insns)
4403 tree current_block = top_block;
4406 if (block_vector == 0)
4409 /* Prune the old tree away, so that it doesn't get in the way. */
4410 BLOCK_SUBBLOCKS (current_block) = 0;
4412 for (insn = insns; insn; insn = NEXT_INSN (insn))
4413 if (GET_CODE (insn) == NOTE)
4415 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
4417 tree block = block_vector[NOTE_BLOCK_NUMBER (insn)];
4418 /* If we have seen this block before, copy it. */
4419 if (TREE_ASM_WRITTEN (block))
4420 block = copy_node (block);
4421 BLOCK_SUBBLOCKS (block) = 0;
4422 TREE_ASM_WRITTEN (block) = 1;
4423 BLOCK_SUPERCONTEXT (block) = current_block;
4424 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
4425 BLOCK_SUBBLOCKS (current_block) = block;
4426 current_block = block;
4427 NOTE_SOURCE_FILE (insn) = 0;
4429 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
4431 BLOCK_SUBBLOCKS (current_block)
4432 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
4433 current_block = BLOCK_SUPERCONTEXT (current_block);
4434 NOTE_SOURCE_FILE (insn) = 0;
4438 return current_block;
4441 /* Reverse the order of elements in the chain T of blocks,
4442 and return the new head of the chain (old last element). */
4448 register tree prev = 0, decl, next;
4449 for (decl = t; decl; decl = next)
4451 next = BLOCK_CHAIN (decl);
4452 BLOCK_CHAIN (decl) = prev;
4458 /* Count the subblocks of BLOCK, and list them all into the vector VECTOR.
4459 Also clear TREE_ASM_WRITTEN in all blocks. */
4462 all_blocks (block, vector)
4469 TREE_ASM_WRITTEN (block) = 0;
4470 /* Record this block. */
4474 /* Record the subblocks, and their subblocks. */
4475 for (subblocks = BLOCK_SUBBLOCKS (block);
4476 subblocks; subblocks = BLOCK_CHAIN (subblocks))
4477 n_blocks += all_blocks (subblocks, vector ? vector + n_blocks : 0);
4482 /* Build bytecode call descriptor for function SUBR. */
4485 bc_build_calldesc (subr)
4488 tree calldesc = 0, arg;
4491 /* Build the argument description vector in reverse order. */
4492 DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
4495 for (arg = DECL_ARGUMENTS (subr); arg; arg = TREE_CHAIN (arg))
4499 calldesc = tree_cons ((tree) 0, size_in_bytes (TREE_TYPE (arg)), calldesc);
4500 calldesc = tree_cons ((tree) 0, bc_runtime_type_code (TREE_TYPE (arg)), calldesc);
4503 DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
4505 /* Prepend the function's return type. */
4506 calldesc = tree_cons ((tree) 0,
4507 size_in_bytes (TREE_TYPE (TREE_TYPE (subr))),
4510 calldesc = tree_cons ((tree) 0,
4511 bc_runtime_type_code (TREE_TYPE (TREE_TYPE (subr))),
4514 /* Prepend the arg count. */
4515 calldesc = tree_cons ((tree) 0, build_int_2 (nargs, 0), calldesc);
4517 /* Output the call description vector and get its address. */
4518 calldesc = build_nt (CONSTRUCTOR, (tree) 0, calldesc);
4519 TREE_TYPE (calldesc) = build_array_type (integer_type_node,
4520 build_index_type (build_int_2 (nargs * 2, 0)));
4522 return output_constant_def (calldesc);
4526 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
4527 and initialize static variables for generating RTL for the statements
4531 init_function_start (subr, filename, line)
4538 if (output_bytecode)
4540 this_function_decl = subr;
4541 this_function_calldesc = bc_build_calldesc (subr);
4542 local_vars_size = 0;
4544 max_stack_depth = 0;
4545 stmt_expr_depth = 0;
4549 init_stmt_for_function ();
4551 cse_not_expected = ! optimize;
4553 /* Caller save not needed yet. */
4554 caller_save_needed = 0;
4556 /* No stack slots have been made yet. */
4557 stack_slot_list = 0;
4559 /* There is no stack slot for handling nonlocal gotos. */
4560 nonlocal_goto_handler_slot = 0;
4561 nonlocal_goto_stack_level = 0;
4563 /* No labels have been declared for nonlocal use. */
4564 nonlocal_labels = 0;
4566 /* No function calls so far in this function. */
4567 function_call_count = 0;
4569 /* No parm regs have been allocated.
4570 (This is important for output_inline_function.) */
4571 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
4573 /* Initialize the RTL mechanism. */
4576 /* Initialize the queue of pending postincrement and postdecrements,
4577 and some other info in expr.c. */
4580 /* We haven't done register allocation yet. */
4583 init_const_rtx_hash_table ();
4585 current_function_name = (*decl_printable_name) (subr, &junk);
4587 /* Nonzero if this is a nested function that uses a static chain. */
4589 current_function_needs_context
4590 = (decl_function_context (current_function_decl) != 0);
4592 /* Set if a call to setjmp is seen. */
4593 current_function_calls_setjmp = 0;
4595 /* Set if a call to longjmp is seen. */
4596 current_function_calls_longjmp = 0;
4598 current_function_calls_alloca = 0;
4599 current_function_has_nonlocal_label = 0;
4600 current_function_has_nonlocal_goto = 0;
4601 current_function_contains_functions = 0;
4603 current_function_returns_pcc_struct = 0;
4604 current_function_returns_struct = 0;
4605 current_function_epilogue_delay_list = 0;
4606 current_function_uses_const_pool = 0;
4607 current_function_uses_pic_offset_table = 0;
4609 /* We have not yet needed to make a label to jump to for tail-recursion. */
4610 tail_recursion_label = 0;
4612 /* We haven't had a need to make a save area for ap yet. */
4614 arg_pointer_save_area = 0;
4616 /* No stack slots allocated yet. */
4619 /* No SAVE_EXPRs in this function yet. */
4622 /* No RTL_EXPRs in this function yet. */
4625 /* We have not allocated any temporaries yet. */
4627 temp_slot_level = 0;
4628 target_temp_slot_level = 0;
4630 /* Within function body, compute a type's size as soon it is laid out. */
4631 immediate_size_expand++;
4633 /* We haven't made any trampolines for this function yet. */
4634 trampoline_list = 0;
4636 init_pending_stack_adjust ();
4637 inhibit_defer_pop = 0;
4639 current_function_outgoing_args_size = 0;
4641 /* Initialize the insn lengths. */
4642 init_insn_lengths ();
4644 /* Prevent ever trying to delete the first instruction of a function.
4645 Also tell final how to output a linenum before the function prologue. */
4646 emit_line_note (filename, line);
4648 /* Make sure first insn is a note even if we don't want linenums.
4649 This makes sure the first insn will never be deleted.
4650 Also, final expects a note to appear there. */
4651 emit_note (NULL_PTR, NOTE_INSN_DELETED);
4653 /* Set flags used by final.c. */
4654 if (aggregate_value_p (DECL_RESULT (subr)))
4656 #ifdef PCC_STATIC_STRUCT_RETURN
4657 current_function_returns_pcc_struct = 1;
4659 current_function_returns_struct = 1;
4662 /* Warn if this value is an aggregate type,
4663 regardless of which calling convention we are using for it. */
4664 if (warn_aggregate_return
4665 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
4666 warning ("function returns an aggregate");
4668 current_function_returns_pointer
4669 = (TREE_CODE (TREE_TYPE (DECL_RESULT (subr))) == POINTER_TYPE);
4671 /* Indicate that we need to distinguish between the return value of the
4672 present function and the return value of a function being called. */
4673 rtx_equal_function_value_matters = 1;
4675 /* Indicate that we have not instantiated virtual registers yet. */
4676 virtuals_instantiated = 0;
4678 /* Indicate we have no need of a frame pointer yet. */
4679 frame_pointer_needed = 0;
4681 /* By default assume not varargs. */
4682 current_function_varargs = 0;
4685 /* Indicate that the current function uses extra args
4686 not explicitly mentioned in the argument list in any fashion. */
4691 current_function_varargs = 1;
4694 /* Expand a call to __main at the beginning of a possible main function. */
4697 expand_main_function ()
4699 if (!output_bytecode)
4701 /* The zero below avoids a possible parse error */
4703 #if !defined (INIT_SECTION_ASM_OP) || defined (INVOKE__main)
4704 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, NAME__MAIN), 0,
4706 #endif /* not INIT_SECTION_ASM_OP or INVOKE__main */
4710 extern struct obstack permanent_obstack;
4712 /* Expand start of bytecode function. See comment at
4713 expand_function_start below for details. */
4716 bc_expand_function_start (subr, parms_have_cleanups)
4718 int parms_have_cleanups;
4720 char label[20], *name;
4725 if (TREE_PUBLIC (subr))
4726 bc_globalize_label (IDENTIFIER_POINTER (DECL_NAME (subr)));
4728 #ifdef DEBUG_PRINT_CODE
4729 fprintf (stderr, "\n<func %s>\n", IDENTIFIER_POINTER (DECL_NAME (subr)));
4732 for (argsz = 0, thisarg = DECL_ARGUMENTS (subr); thisarg; thisarg = TREE_CHAIN (thisarg))
4734 if (DECL_RTL (thisarg))
4735 abort (); /* Should be NULL here I think. */
4736 else if (TREE_CONSTANT (DECL_SIZE (thisarg)))
4738 DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
4739 argsz += TREE_INT_CST_LOW (DECL_SIZE (thisarg));
4743 /* Variable-sized objects are pointers to their storage. */
4744 DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
4745 argsz += POINTER_SIZE;
4749 bc_begin_function (bc_xstrdup (IDENTIFIER_POINTER (DECL_NAME (subr))));
4751 ASM_GENERATE_INTERNAL_LABEL (label, "LX", nlab);
4754 name = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
4755 this_function_callinfo = bc_gen_rtx (name, 0, (struct bc_label *) 0);
4756 this_function_bytecode =
4757 bc_emit_trampoline (BYTECODE_LABEL (this_function_callinfo));
4761 /* Expand end of bytecode function. See details the comment of
4762 expand_function_end(), below. */
4765 bc_expand_function_end ()
4769 expand_null_return ();
4771 /* Emit any fixup code. This must be done before the call to
4772 to BC_END_FUNCTION (), since that will cause the bytecode
4773 segment to be finished off and closed. */
4775 expand_fixups (NULL_RTX);
4777 ptrconsts = bc_end_function ();
4779 bc_align_const (2 /* INT_ALIGN */);
4781 /* If this changes also make sure to change bc-interp.h! */
4783 bc_emit_const_labeldef (BYTECODE_LABEL (this_function_callinfo));
4784 bc_emit_const ((char *) &max_stack_depth, sizeof max_stack_depth);
4785 bc_emit_const ((char *) &local_vars_size, sizeof local_vars_size);
4786 bc_emit_const_labelref (this_function_bytecode, 0);
4787 bc_emit_const_labelref (ptrconsts, 0);
4788 bc_emit_const_labelref (BYTECODE_LABEL (this_function_calldesc), 0);
4792 /* Start the RTL for a new function, and set variables used for
4794 SUBR is the FUNCTION_DECL node.
4795 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
4796 the function's parameters, which must be run at any return statement. */
4799 expand_function_start (subr, parms_have_cleanups)
4801 int parms_have_cleanups;
4807 if (output_bytecode)
4809 bc_expand_function_start (subr, parms_have_cleanups);
4813 /* Make sure volatile mem refs aren't considered
4814 valid operands of arithmetic insns. */
4815 init_recog_no_volatile ();
4817 /* If function gets a static chain arg, store it in the stack frame.
4818 Do this first, so it gets the first stack slot offset. */
4819 if (current_function_needs_context)
4821 last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
4823 #ifdef SMALL_REGISTER_CLASSES
4824 /* Delay copying static chain if it is not a register to avoid
4825 conflicts with regs used for parameters. */
4826 if (GET_CODE (static_chain_incoming_rtx) == REG)
4828 emit_move_insn (last_ptr, static_chain_incoming_rtx);
4831 /* If the parameters of this function need cleaning up, get a label
4832 for the beginning of the code which executes those cleanups. This must
4833 be done before doing anything with return_label. */
4834 if (parms_have_cleanups)
4835 cleanup_label = gen_label_rtx ();
4839 /* Make the label for return statements to jump to, if this machine
4840 does not have a one-instruction return and uses an epilogue,
4841 or if it returns a structure, or if it has parm cleanups. */
4843 if (cleanup_label == 0 && HAVE_return
4844 && ! current_function_returns_pcc_struct
4845 && ! (current_function_returns_struct && ! optimize))
4848 return_label = gen_label_rtx ();
4850 return_label = gen_label_rtx ();
4853 /* Initialize rtx used to return the value. */
4854 /* Do this before assign_parms so that we copy the struct value address
4855 before any library calls that assign parms might generate. */
4857 /* Decide whether to return the value in memory or in a register. */
4858 if (aggregate_value_p (DECL_RESULT (subr)))
4860 /* Returning something that won't go in a register. */
4861 register rtx value_address = 0;
4863 #ifdef PCC_STATIC_STRUCT_RETURN
4864 if (current_function_returns_pcc_struct)
4866 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
4867 value_address = assemble_static_space (size);
4872 /* Expect to be passed the address of a place to store the value.
4873 If it is passed as an argument, assign_parms will take care of
4875 if (struct_value_incoming_rtx)
4877 value_address = gen_reg_rtx (Pmode);
4878 emit_move_insn (value_address, struct_value_incoming_rtx);
4883 DECL_RTL (DECL_RESULT (subr))
4884 = gen_rtx (MEM, DECL_MODE (DECL_RESULT (subr)), value_address);
4885 MEM_IN_STRUCT_P (DECL_RTL (DECL_RESULT (subr)))
4886 = AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
4889 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
4890 /* If return mode is void, this decl rtl should not be used. */
4891 DECL_RTL (DECL_RESULT (subr)) = 0;
4892 else if (parms_have_cleanups)
4894 /* If function will end with cleanup code for parms,
4895 compute the return values into a pseudo reg,
4896 which we will copy into the true return register
4897 after the cleanups are done. */
4899 enum machine_mode mode = DECL_MODE (DECL_RESULT (subr));
4901 #ifdef PROMOTE_FUNCTION_RETURN
4902 tree type = TREE_TYPE (DECL_RESULT (subr));
4903 int unsignedp = TREE_UNSIGNED (type);
4905 mode = promote_mode (type, mode, &unsignedp, 1);
4908 DECL_RTL (DECL_RESULT (subr)) = gen_reg_rtx (mode);
4911 /* Scalar, returned in a register. */
4913 #ifdef FUNCTION_OUTGOING_VALUE
4914 DECL_RTL (DECL_RESULT (subr))
4915 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
4917 DECL_RTL (DECL_RESULT (subr))
4918 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
4921 /* Mark this reg as the function's return value. */
4922 if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG)
4924 REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1;
4925 /* Needed because we may need to move this to memory
4926 in case it's a named return value whose address is taken. */
4927 DECL_REGISTER (DECL_RESULT (subr)) = 1;
4931 /* Initialize rtx for parameters and local variables.
4932 In some cases this requires emitting insns. */
4934 assign_parms (subr, 0);
4936 #ifdef SMALL_REGISTER_CLASSES
4937 /* Copy the static chain now if it wasn't a register. The delay is to
4938 avoid conflicts with the parameter passing registers. */
4940 if (current_function_needs_context)
4941 if (GET_CODE (static_chain_incoming_rtx) != REG)
4942 emit_move_insn (last_ptr, static_chain_incoming_rtx);
4945 /* The following was moved from init_function_start.
4946 The move is supposed to make sdb output more accurate. */
4947 /* Indicate the beginning of the function body,
4948 as opposed to parm setup. */
4949 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_BEG);
4951 /* If doing stupid allocation, mark parms as born here. */
4953 if (GET_CODE (get_last_insn ()) != NOTE)
4954 emit_note (NULL_PTR, NOTE_INSN_DELETED);
4955 parm_birth_insn = get_last_insn ();
4959 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
4960 use_variable (regno_reg_rtx[i]);
4962 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
4963 use_variable (current_function_internal_arg_pointer);
4966 /* Fetch static chain values for containing functions. */
4967 tem = decl_function_context (current_function_decl);
4968 /* If not doing stupid register allocation copy the static chain
4969 pointer into a psuedo. If we have small register classes, copy the
4970 value from memory if static_chain_incoming_rtx is a REG. If we do
4971 stupid register allocation, we use the stack address generated above. */
4972 if (tem && ! obey_regdecls)
4974 #ifdef SMALL_REGISTER_CLASSES
4975 if (GET_CODE (static_chain_incoming_rtx) == REG)
4976 last_ptr = copy_to_reg (last_ptr);
4979 last_ptr = copy_to_reg (static_chain_incoming_rtx);
4982 context_display = 0;
4985 tree rtlexp = make_node (RTL_EXPR);
4987 RTL_EXPR_RTL (rtlexp) = last_ptr;
4988 context_display = tree_cons (tem, rtlexp, context_display);
4989 tem = decl_function_context (tem);
4992 /* Chain thru stack frames, assuming pointer to next lexical frame
4993 is found at the place we always store it. */
4994 #ifdef FRAME_GROWS_DOWNWARD
4995 last_ptr = plus_constant (last_ptr, - GET_MODE_SIZE (Pmode));
4997 last_ptr = copy_to_reg (gen_rtx (MEM, Pmode,
4998 memory_address (Pmode, last_ptr)));
5000 /* If we are not optimizing, ensure that we know that this
5001 piece of context is live over the entire function. */
5003 save_expr_regs = gen_rtx (EXPR_LIST, VOIDmode, last_ptr,
5007 /* After the display initializations is where the tail-recursion label
5008 should go, if we end up needing one. Ensure we have a NOTE here
5009 since some things (like trampolines) get placed before this. */
5010 tail_recursion_reentry = emit_note (NULL_PTR, NOTE_INSN_DELETED);
5012 /* Evaluate now the sizes of any types declared among the arguments. */
5013 for (tem = nreverse (get_pending_sizes ()); tem; tem = TREE_CHAIN (tem))
5014 expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode, 0);
5016 /* Make sure there is a line number after the function entry setup code. */
5017 force_next_line_note ();
5020 /* Generate RTL for the end of the current function.
5021 FILENAME and LINE are the current position in the source file.
5023 It is up to language-specific callers to do cleanups for parameters--
5024 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */
5027 expand_function_end (filename, line, end_bindings)
5035 static rtx initial_trampoline;
5037 if (output_bytecode)
5039 bc_expand_function_end ();
5043 #ifdef NON_SAVING_SETJMP
5044 /* Don't put any variables in registers if we call setjmp
5045 on a machine that fails to restore the registers. */
5046 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
5048 setjmp_protect (DECL_INITIAL (current_function_decl));
5049 setjmp_protect_args ();
5053 /* Save the argument pointer if a save area was made for it. */
5054 if (arg_pointer_save_area)
5056 rtx x = gen_move_insn (arg_pointer_save_area, virtual_incoming_args_rtx);
5057 emit_insn_before (x, tail_recursion_reentry);
5060 /* Initialize any trampolines required by this function. */
5061 for (link = trampoline_list; link; link = TREE_CHAIN (link))
5063 tree function = TREE_PURPOSE (link);
5064 rtx context = lookup_static_chain (function);
5065 rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
5068 /* First make sure this compilation has a template for
5069 initializing trampolines. */
5070 if (initial_trampoline == 0)
5072 end_temporary_allocation ();
5074 = gen_rtx (MEM, BLKmode, assemble_trampoline_template ());
5075 resume_temporary_allocation ();
5078 /* Generate insns to initialize the trampoline. */
5080 tramp = change_address (initial_trampoline, BLKmode,
5081 round_trampoline_addr (XEXP (tramp, 0)));
5082 emit_block_move (tramp, initial_trampoline, GEN_INT (TRAMPOLINE_SIZE),
5083 FUNCTION_BOUNDARY / BITS_PER_UNIT);
5084 INITIALIZE_TRAMPOLINE (XEXP (tramp, 0),
5085 XEXP (DECL_RTL (function), 0), context);
5089 /* Put those insns at entry to the containing function (this one). */
5090 emit_insns_before (seq, tail_recursion_reentry);
5093 #if 0 /* I think unused parms are legitimate enough. */
5094 /* Warn about unused parms. */
5099 for (decl = DECL_ARGUMENTS (current_function_decl);
5100 decl; decl = TREE_CHAIN (decl))
5101 if (! TREE_USED (decl) && TREE_CODE (decl) == VAR_DECL)
5102 warning_with_decl (decl, "unused parameter `%s'");
5106 /* Delete handlers for nonlocal gotos if nothing uses them. */
5107 if (nonlocal_goto_handler_slot != 0 && !current_function_has_nonlocal_label)
5110 /* End any sequences that failed to be closed due to syntax errors. */
5111 while (in_sequence_p ())
5114 /* Outside function body, can't compute type's actual size
5115 until next function's body starts. */
5116 immediate_size_expand--;
5118 /* If doing stupid register allocation,
5119 mark register parms as dying here. */
5124 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
5125 use_variable (regno_reg_rtx[i]);
5127 /* Likewise for the regs of all the SAVE_EXPRs in the function. */
5129 for (tem = save_expr_regs; tem; tem = XEXP (tem, 1))
5131 use_variable (XEXP (tem, 0));
5132 use_variable_after (XEXP (tem, 0), parm_birth_insn);
5135 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
5136 use_variable (current_function_internal_arg_pointer);
5139 clear_pending_stack_adjust ();
5140 do_pending_stack_adjust ();
5142 /* Mark the end of the function body.
5143 If control reaches this insn, the function can drop through
5144 without returning a value. */
5145 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_END);
5147 /* Output a linenumber for the end of the function.
5148 SDB depends on this. */
5149 emit_line_note_force (filename, line);
5151 /* Output the label for the actual return from the function,
5152 if one is expected. This happens either because a function epilogue
5153 is used instead of a return instruction, or because a return was done
5154 with a goto in order to run local cleanups, or because of pcc-style
5155 structure returning. */
5158 emit_label (return_label);
5160 /* C++ uses this. */
5162 expand_end_bindings (0, 0, 0);
5164 /* If we had calls to alloca, and this machine needs
5165 an accurate stack pointer to exit the function,
5166 insert some code to save and restore the stack pointer. */
5167 #ifdef EXIT_IGNORE_STACK
5168 if (! EXIT_IGNORE_STACK)
5170 if (current_function_calls_alloca)
5174 emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
5175 emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
5178 /* If scalar return value was computed in a pseudo-reg,
5179 copy that to the hard return register. */
5180 if (DECL_RTL (DECL_RESULT (current_function_decl)) != 0
5181 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG
5182 && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl)))
5183 >= FIRST_PSEUDO_REGISTER))
5185 rtx real_decl_result;
5187 #ifdef FUNCTION_OUTGOING_VALUE
5189 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
5190 current_function_decl);
5193 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
5194 current_function_decl);
5196 REG_FUNCTION_VALUE_P (real_decl_result) = 1;
5197 emit_move_insn (real_decl_result,
5198 DECL_RTL (DECL_RESULT (current_function_decl)));
5199 emit_insn (gen_rtx (USE, VOIDmode, real_decl_result));
5202 /* If returning a structure, arrange to return the address of the value
5203 in a place where debuggers expect to find it.
5205 If returning a structure PCC style,
5206 the caller also depends on this value.
5207 And current_function_returns_pcc_struct is not necessarily set. */
5208 if (current_function_returns_struct
5209 || current_function_returns_pcc_struct)
5211 rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
5212 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
5213 #ifdef FUNCTION_OUTGOING_VALUE
5215 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
5216 current_function_decl);
5219 = FUNCTION_VALUE (build_pointer_type (type),
5220 current_function_decl);
5223 /* Mark this as a function return value so integrate will delete the
5224 assignment and USE below when inlining this function. */
5225 REG_FUNCTION_VALUE_P (outgoing) = 1;
5227 emit_move_insn (outgoing, value_address);
5228 use_variable (outgoing);
5231 /* Output a return insn if we are using one.
5232 Otherwise, let the rtl chain end here, to drop through
5233 into the epilogue. */
5238 emit_jump_insn (gen_return ());
5243 /* Fix up any gotos that jumped out to the outermost
5244 binding level of the function.
5245 Must follow emitting RETURN_LABEL. */
5247 /* If you have any cleanups to do at this point,
5248 and they need to create temporary variables,
5249 then you will lose. */
5250 expand_fixups (get_insns ());
5253 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
5255 static int *prologue;
5256 static int *epilogue;
5258 /* Create an array that records the INSN_UIDs of INSNS (either a sequence
5259 or a single insn). */
5262 record_insns (insns)
5267 if (GET_CODE (insns) == SEQUENCE)
5269 int len = XVECLEN (insns, 0);
5270 vec = (int *) oballoc ((len + 1) * sizeof (int));
5273 vec[len] = INSN_UID (XVECEXP (insns, 0, len));
5277 vec = (int *) oballoc (2 * sizeof (int));
5278 vec[0] = INSN_UID (insns);
5284 /* Determine how many INSN_UIDs in VEC are part of INSN. */
5287 contains (insn, vec)
5293 if (GET_CODE (insn) == INSN
5294 && GET_CODE (PATTERN (insn)) == SEQUENCE)
5297 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
5298 for (j = 0; vec[j]; j++)
5299 if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == vec[j])
5305 for (j = 0; vec[j]; j++)
5306 if (INSN_UID (insn) == vec[j])
5312 /* Generate the prologe and epilogue RTL if the machine supports it. Thread
5313 this into place with notes indicating where the prologue ends and where
5314 the epilogue begins. Update the basic block information when possible. */
5317 thread_prologue_and_epilogue_insns (f)
5320 #ifdef HAVE_prologue
5323 rtx head, seq, insn;
5325 /* The first insn (a NOTE_INSN_DELETED) is followed by zero or more
5326 prologue insns and a NOTE_INSN_PROLOGUE_END. */
5327 emit_note_after (NOTE_INSN_PROLOGUE_END, f);
5328 seq = gen_prologue ();
5329 head = emit_insn_after (seq, f);
5331 /* Include the new prologue insns in the first block. Ignore them
5332 if they form a basic block unto themselves. */
5333 if (basic_block_head && n_basic_blocks
5334 && GET_CODE (basic_block_head[0]) != CODE_LABEL)
5335 basic_block_head[0] = NEXT_INSN (f);
5337 /* Retain a map of the prologue insns. */
5338 prologue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : head);
5344 #ifdef HAVE_epilogue
5347 rtx insn = get_last_insn ();
5348 rtx prev = prev_nonnote_insn (insn);
5350 /* If we end with a BARRIER, we don't need an epilogue. */
5351 if (! (prev && GET_CODE (prev) == BARRIER))
5357 /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, the
5358 epilogue insns, the USE insns at the end of a function,
5359 the jump insn that returns, and then a BARRIER. */
5361 /* Move the USE insns at the end of a function onto a list. */
5363 && GET_CODE (prev) == INSN
5364 && GET_CODE (PATTERN (prev)) == USE)
5367 prev = prev_nonnote_insn (prev);
5369 NEXT_INSN (PREV_INSN (tem)) = NEXT_INSN (tem);
5370 PREV_INSN (NEXT_INSN (tem)) = PREV_INSN (tem);
5373 NEXT_INSN (tem) = first_use;
5374 PREV_INSN (first_use) = tem;
5381 emit_barrier_after (insn);
5383 seq = gen_epilogue ();
5384 tail = emit_jump_insn_after (seq, insn);
5386 /* Insert the USE insns immediately before the return insn, which
5387 must be the first instruction before the final barrier. */
5390 tem = prev_nonnote_insn (get_last_insn ());
5391 NEXT_INSN (PREV_INSN (tem)) = first_use;
5392 PREV_INSN (first_use) = PREV_INSN (tem);
5393 PREV_INSN (tem) = last_use;
5394 NEXT_INSN (last_use) = tem;
5397 emit_note_after (NOTE_INSN_EPILOGUE_BEG, insn);
5399 /* Include the new epilogue insns in the last block. Ignore
5400 them if they form a basic block unto themselves. */
5401 if (basic_block_end && n_basic_blocks
5402 && GET_CODE (basic_block_end[n_basic_blocks - 1]) != JUMP_INSN)
5403 basic_block_end[n_basic_blocks - 1] = tail;
5405 /* Retain a map of the epilogue insns. */
5406 epilogue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : tail);
5414 /* Reposition the prologue-end and epilogue-begin notes after instruction
5415 scheduling and delayed branch scheduling. */
5418 reposition_prologue_and_epilogue_notes (f)
5421 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
5422 /* Reposition the prologue and epilogue notes. */
5430 register rtx insn, note = 0;
5432 /* Scan from the beginning until we reach the last prologue insn.
5433 We apparently can't depend on basic_block_{head,end} after
5435 for (len = 0; prologue[len]; len++)
5437 for (insn = f; len && insn; insn = NEXT_INSN (insn))
5439 if (GET_CODE (insn) == NOTE)
5441 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
5444 else if ((len -= contains (insn, prologue)) == 0)
5446 /* Find the prologue-end note if we haven't already, and
5447 move it to just after the last prologue insn. */
5450 for (note = insn; note = NEXT_INSN (note);)
5451 if (GET_CODE (note) == NOTE
5452 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
5455 next = NEXT_INSN (note);
5456 prev = PREV_INSN (note);
5458 NEXT_INSN (prev) = next;
5460 PREV_INSN (next) = prev;
5461 add_insn_after (note, insn);
5468 register rtx insn, note = 0;
5470 /* Scan from the end until we reach the first epilogue insn.
5471 We apparently can't depend on basic_block_{head,end} after
5473 for (len = 0; epilogue[len]; len++)
5475 for (insn = get_last_insn (); len && insn; insn = PREV_INSN (insn))
5477 if (GET_CODE (insn) == NOTE)
5479 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
5482 else if ((len -= contains (insn, epilogue)) == 0)
5484 /* Find the epilogue-begin note if we haven't already, and
5485 move it to just before the first epilogue insn. */
5488 for (note = insn; note = PREV_INSN (note);)
5489 if (GET_CODE (note) == NOTE
5490 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
5493 next = NEXT_INSN (note);
5494 prev = PREV_INSN (note);
5496 NEXT_INSN (prev) = next;
5498 PREV_INSN (next) = prev;
5499 add_insn_after (note, PREV_INSN (insn));
5504 #endif /* HAVE_prologue or HAVE_epilogue */