1 /* Expands front end tree to back end RTL for GNU C-Compiler
2 Copyright (C) 1987, 88, 89, 91, 92, 1993 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 /* Nonzero if we need to distinguish between the return value of this function
310 and the return value of a function called by this function. This helps
313 extern int rtx_equal_function_value_matters;
314 extern tree bc_runtime_type_code ();
315 extern rtx bc_build_calldesc ();
316 extern char *bc_emit_trampoline ();
317 extern char *bc_end_function ();
321 static tree round_down ();
322 static rtx round_trampoline_addr ();
323 static rtx fixup_stack_1 ();
324 static void put_reg_into_stack ();
325 static void fixup_var_refs ();
326 static void fixup_var_refs_insns ();
327 static void fixup_var_refs_1 ();
328 static void optimize_bit_field ();
329 static void instantiate_decls ();
330 static void instantiate_decls_1 ();
331 static void instantiate_decl ();
332 static int instantiate_virtual_regs_1 ();
333 static rtx fixup_memory_subreg ();
334 static rtx walk_fixup_memory_subreg ();
336 /* In order to evaluate some expressions, such as function calls returning
337 structures in memory, we need to temporarily allocate stack locations.
338 We record each allocated temporary in the following structure.
340 Associated with each temporary slot is a nesting level. When we pop up
341 one level, all temporaries associated with the previous level are freed.
342 Normally, all temporaries are freed after the execution of the statement
343 in which they were created. However, if we are inside a ({...}) grouping,
344 the result may be in a temporary and hence must be preserved. If the
345 result could be in a temporary, we preserve it if we can determine which
346 one it is in. If we cannot determine which temporary may contain the
347 result, all temporaries are preserved. A temporary is preserved by
348 pretending it was allocated at the previous nesting level.
350 Automatic variables are also assigned temporary slots, at the nesting
351 level where they are defined. They are marked a "kept" so that
352 free_temp_slots will not free them. */
356 /* Points to next temporary slot. */
357 struct temp_slot *next;
358 /* The rtx to used to reference the slot. */
360 /* The size, in units, of the slot. */
362 /* Non-zero if this temporary is currently in use. */
364 /* Nesting level at which this slot is being used. */
366 /* Non-zero if this should survive a call to free_temp_slots. */
370 /* List of all temporaries allocated, both available and in use. */
372 struct temp_slot *temp_slots;
374 /* Current nesting level for temporaries. */
378 /* The FUNCTION_DECL node for the current function. */
379 static tree this_function_decl;
381 /* Callinfo pointer for the current function. */
382 static rtx this_function_callinfo;
384 /* The label in the bytecode file of this function's actual bytecode.
386 static char *this_function_bytecode;
388 /* The call description vector for the current function. */
389 static rtx this_function_calldesc;
391 /* Size of the local variables allocated for the current function. */
394 /* Current depth of the bytecode evaluation stack. */
397 /* Maximum depth of the evaluation stack in this function. */
400 /* Current depth in statement expressions. */
401 static int stmt_expr_depth;
403 /* Pointer to chain of `struct function' for containing functions. */
404 struct function *outer_function_chain;
406 /* Given a function decl for a containing function,
407 return the `struct function' for it. */
410 find_function_data (decl)
414 for (p = outer_function_chain; p; p = p->next)
420 /* Save the current context for compilation of a nested function.
421 This is called from language-specific code.
422 The caller is responsible for saving any language-specific status,
423 since this function knows only about language-independent variables. */
426 push_function_context ()
428 struct function *p = (struct function *) xmalloc (sizeof (struct function));
430 p->next = outer_function_chain;
431 outer_function_chain = p;
433 p->name = current_function_name;
434 p->decl = current_function_decl;
435 p->pops_args = current_function_pops_args;
436 p->returns_struct = current_function_returns_struct;
437 p->returns_pcc_struct = current_function_returns_pcc_struct;
438 p->needs_context = current_function_needs_context;
439 p->calls_setjmp = current_function_calls_setjmp;
440 p->calls_longjmp = current_function_calls_longjmp;
441 p->calls_alloca = current_function_calls_alloca;
442 p->has_nonlocal_label = current_function_has_nonlocal_label;
443 p->has_nonlocal_goto = current_function_has_nonlocal_goto;
444 p->args_size = current_function_args_size;
445 p->pretend_args_size = current_function_pretend_args_size;
446 p->arg_offset_rtx = current_function_arg_offset_rtx;
447 p->uses_const_pool = current_function_uses_const_pool;
448 p->uses_pic_offset_table = current_function_uses_pic_offset_table;
449 p->internal_arg_pointer = current_function_internal_arg_pointer;
450 p->max_parm_reg = max_parm_reg;
451 p->parm_reg_stack_loc = parm_reg_stack_loc;
452 p->outgoing_args_size = current_function_outgoing_args_size;
453 p->return_rtx = current_function_return_rtx;
454 p->nonlocal_goto_handler_slot = nonlocal_goto_handler_slot;
455 p->nonlocal_goto_stack_level = nonlocal_goto_stack_level;
456 p->nonlocal_labels = nonlocal_labels;
457 p->cleanup_label = cleanup_label;
458 p->return_label = return_label;
459 p->save_expr_regs = save_expr_regs;
460 p->stack_slot_list = stack_slot_list;
461 p->parm_birth_insn = parm_birth_insn;
462 p->frame_offset = frame_offset;
463 p->tail_recursion_label = tail_recursion_label;
464 p->tail_recursion_reentry = tail_recursion_reentry;
465 p->arg_pointer_save_area = arg_pointer_save_area;
466 p->rtl_expr_chain = rtl_expr_chain;
467 p->last_parm_insn = last_parm_insn;
468 p->context_display = context_display;
469 p->trampoline_list = trampoline_list;
470 p->function_call_count = function_call_count;
471 p->temp_slots = temp_slots;
472 p->temp_slot_level = temp_slot_level;
473 p->fixup_var_refs_queue = 0;
474 p->epilogue_delay_list = current_function_epilogue_delay_list;
476 save_tree_status (p);
477 save_storage_status (p);
478 save_emit_status (p);
480 save_expr_status (p);
481 save_stmt_status (p);
482 save_varasm_status (p);
485 /* Restore the last saved context, at the end of a nested function.
486 This function is called from language-specific code. */
489 pop_function_context ()
491 struct function *p = outer_function_chain;
493 outer_function_chain = p->next;
495 current_function_name = p->name;
496 current_function_decl = p->decl;
497 current_function_pops_args = p->pops_args;
498 current_function_returns_struct = p->returns_struct;
499 current_function_returns_pcc_struct = p->returns_pcc_struct;
500 current_function_needs_context = p->needs_context;
501 current_function_calls_setjmp = p->calls_setjmp;
502 current_function_calls_longjmp = p->calls_longjmp;
503 current_function_calls_alloca = p->calls_alloca;
504 current_function_has_nonlocal_label = p->has_nonlocal_label;
505 current_function_has_nonlocal_goto = p->has_nonlocal_goto;
506 current_function_contains_functions = 1;
507 current_function_args_size = p->args_size;
508 current_function_pretend_args_size = p->pretend_args_size;
509 current_function_arg_offset_rtx = p->arg_offset_rtx;
510 current_function_uses_const_pool = p->uses_const_pool;
511 current_function_uses_pic_offset_table = p->uses_pic_offset_table;
512 current_function_internal_arg_pointer = p->internal_arg_pointer;
513 max_parm_reg = p->max_parm_reg;
514 parm_reg_stack_loc = p->parm_reg_stack_loc;
515 current_function_outgoing_args_size = p->outgoing_args_size;
516 current_function_return_rtx = p->return_rtx;
517 nonlocal_goto_handler_slot = p->nonlocal_goto_handler_slot;
518 nonlocal_goto_stack_level = p->nonlocal_goto_stack_level;
519 nonlocal_labels = p->nonlocal_labels;
520 cleanup_label = p->cleanup_label;
521 return_label = p->return_label;
522 save_expr_regs = p->save_expr_regs;
523 stack_slot_list = p->stack_slot_list;
524 parm_birth_insn = p->parm_birth_insn;
525 frame_offset = p->frame_offset;
526 tail_recursion_label = p->tail_recursion_label;
527 tail_recursion_reentry = p->tail_recursion_reentry;
528 arg_pointer_save_area = p->arg_pointer_save_area;
529 rtl_expr_chain = p->rtl_expr_chain;
530 last_parm_insn = p->last_parm_insn;
531 context_display = p->context_display;
532 trampoline_list = p->trampoline_list;
533 function_call_count = p->function_call_count;
534 temp_slots = p->temp_slots;
535 temp_slot_level = p->temp_slot_level;
536 current_function_epilogue_delay_list = p->epilogue_delay_list;
538 restore_tree_status (p);
539 restore_storage_status (p);
540 restore_expr_status (p);
541 restore_emit_status (p);
542 restore_stmt_status (p);
543 restore_varasm_status (p);
545 /* Finish doing put_var_into_stack for any of our variables
546 which became addressable during the nested function. */
548 struct var_refs_queue *queue = p->fixup_var_refs_queue;
549 for (; queue; queue = queue->next)
550 fixup_var_refs (queue->modified, queue->promoted_mode, queue->unsignedp);
555 /* Reset variables that have known state during rtx generation. */
556 rtx_equal_function_value_matters = 1;
557 virtuals_instantiated = 0;
560 /* Allocate fixed slots in the stack frame of the current function. */
562 /* Return size needed for stack frame based on slots so far allocated.
563 This size counts from zero. It is not rounded to STACK_BOUNDARY;
564 the caller may have to do that. */
569 #ifdef FRAME_GROWS_DOWNWARD
570 return -frame_offset;
576 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
577 with machine mode MODE.
579 ALIGN controls the amount of alignment for the address of the slot:
580 0 means according to MODE,
581 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
582 positive specifies alignment boundary in bits.
584 We do not round to stack_boundary here. */
587 assign_stack_local (mode, size, align)
588 enum machine_mode mode;
592 register rtx x, addr;
593 int bigend_correction = 0;
598 alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
600 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
602 else if (align == -1)
604 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
605 size = CEIL_ROUND (size, alignment);
608 alignment = align / BITS_PER_UNIT;
610 /* Round frame offset to that alignment.
611 We must be careful here, since FRAME_OFFSET might be negative and
612 division with a negative dividend isn't as well defined as we might
613 like. So we instead assume that ALIGNMENT is a power of two and
614 use logical operations which are unambiguous. */
615 #ifdef FRAME_GROWS_DOWNWARD
616 frame_offset = FLOOR_ROUND (frame_offset, alignment);
618 frame_offset = CEIL_ROUND (frame_offset, alignment);
621 /* On a big-endian machine, if we are allocating more space than we will use,
622 use the least significant bytes of those that are allocated. */
625 bigend_correction = size - GET_MODE_SIZE (mode);
628 #ifdef FRAME_GROWS_DOWNWARD
629 frame_offset -= size;
632 /* If we have already instantiated virtual registers, return the actual
633 address relative to the frame pointer. */
634 if (virtuals_instantiated)
635 addr = plus_constant (frame_pointer_rtx,
636 (frame_offset + bigend_correction
637 + STARTING_FRAME_OFFSET));
639 addr = plus_constant (virtual_stack_vars_rtx,
640 frame_offset + bigend_correction);
642 #ifndef FRAME_GROWS_DOWNWARD
643 frame_offset += size;
646 x = gen_rtx (MEM, mode, addr);
648 stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, x, stack_slot_list);
653 /* Assign a stack slot in a containing function.
654 First three arguments are same as in preceding function.
655 The last argument specifies the function to allocate in. */
658 assign_outer_stack_local (mode, size, align, function)
659 enum machine_mode mode;
662 struct function *function;
664 register rtx x, addr;
665 int bigend_correction = 0;
668 /* Allocate in the memory associated with the function in whose frame
670 push_obstacks (function->function_obstack,
671 function->function_maybepermanent_obstack);
675 alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
677 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
679 else if (align == -1)
681 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
682 size = CEIL_ROUND (size, alignment);
685 alignment = align / BITS_PER_UNIT;
687 /* Round frame offset to that alignment. */
688 #ifdef FRAME_GROWS_DOWNWARD
689 function->frame_offset = FLOOR_ROUND (function->frame_offset, alignment);
691 function->frame_offset = CEIL_ROUND (function->frame_offset, alignment);
694 /* On a big-endian machine, if we are allocating more space than we will use,
695 use the least significant bytes of those that are allocated. */
698 bigend_correction = size - GET_MODE_SIZE (mode);
701 #ifdef FRAME_GROWS_DOWNWARD
702 function->frame_offset -= size;
704 addr = plus_constant (virtual_stack_vars_rtx,
705 function->frame_offset + bigend_correction);
706 #ifndef FRAME_GROWS_DOWNWARD
707 function->frame_offset += size;
710 x = gen_rtx (MEM, mode, addr);
712 function->stack_slot_list
713 = gen_rtx (EXPR_LIST, VOIDmode, x, function->stack_slot_list);
720 /* Allocate a temporary stack slot and record it for possible later
723 MODE is the machine mode to be given to the returned rtx.
725 SIZE is the size in units of the space required. We do no rounding here
726 since assign_stack_local will do any required rounding.
728 KEEP is non-zero if this slot is to be retained after a call to
729 free_temp_slots. Automatic variables for a block are allocated with this
733 assign_stack_temp (mode, size, keep)
734 enum machine_mode mode;
738 struct temp_slot *p, *best_p = 0;
740 /* First try to find an available, already-allocated temporary that is the
741 exact size we require. */
742 for (p = temp_slots; p; p = p->next)
743 if (p->size == size && GET_MODE (p->slot) == mode && ! p->in_use)
746 /* If we didn't find, one, try one that is larger than what we want. We
747 find the smallest such. */
749 for (p = temp_slots; p; p = p->next)
750 if (p->size > size && GET_MODE (p->slot) == mode && ! p->in_use
751 && (best_p == 0 || best_p->size > p->size))
754 /* Make our best, if any, the one to use. */
757 /* If there are enough aligned bytes left over, make them into a new
758 temp_slot so that the extra bytes don't get wasted. Do this only
759 for BLKmode slots, so that we can be sure of the alignment. */
760 if (GET_MODE (best_p->slot) == BLKmode)
762 int alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
763 int rounded_size = CEIL_ROUND (size, alignment);
765 if (best_p->size - rounded_size >= alignment)
767 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
769 p->size = best_p->size - rounded_size;
770 p->slot = gen_rtx (MEM, BLKmode,
771 plus_constant (XEXP (best_p->slot, 0),
773 p->next = temp_slots;
776 stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, p->slot,
779 best_p->size = rounded_size;
787 /* If we still didn't find one, make a new temporary. */
790 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
792 /* If the temp slot mode doesn't indicate the alignment,
793 use the largest possible, so no one will be disappointed. */
794 p->slot = assign_stack_local (mode, size, mode == BLKmode ? -1 : 0);
795 p->next = temp_slots;
800 p->level = temp_slot_level;
805 /* Combine temporary stack slots which are adjacent on the stack.
807 This allows for better use of already allocated stack space. This is only
808 done for BLKmode slots because we can be sure that we won't have alignment
809 problems in this case. */
812 combine_temp_slots ()
814 struct temp_slot *p, *q;
815 struct temp_slot *prev_p, *prev_q;
816 /* Determine where to free back to after this function. */
817 rtx free_pointer = rtx_alloc (CONST_INT);
819 for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots)
822 if (! p->in_use && GET_MODE (p->slot) == BLKmode)
823 for (q = p->next, prev_q = p; q; q = prev_q->next)
826 if (! q->in_use && GET_MODE (q->slot) == BLKmode)
828 if (rtx_equal_p (plus_constant (XEXP (p->slot, 0), p->size),
831 /* Q comes after P; combine Q into P. */
835 else if (rtx_equal_p (plus_constant (XEXP (q->slot, 0), q->size),
838 /* P comes after Q; combine P into Q. */
844 /* Either delete Q or advance past it. */
846 prev_q->next = q->next;
850 /* Either delete P or advance past it. */
854 prev_p->next = p->next;
856 temp_slots = p->next;
862 /* Free all the RTL made by plus_constant. */
863 rtx_free (free_pointer);
866 /* If X could be a reference to a temporary slot, mark that slot as belonging
867 to the to one level higher. If X matched one of our slots, just mark that
868 one. Otherwise, we can't easily predict which it is, so upgrade all of
869 them. Kept slots need not be touched.
871 This is called when an ({...}) construct occurs and a statement
872 returns a value in memory. */
875 preserve_temp_slots (x)
880 /* If X is not in memory or is at a constant address, it cannot be in
882 if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
885 /* First see if we can find a match. */
886 for (p = temp_slots; p; p = p->next)
887 if (p->in_use && x == p->slot)
893 /* Otherwise, preserve all non-kept slots at this level. */
894 for (p = temp_slots; p; p = p->next)
895 if (p->in_use && p->level == temp_slot_level && ! p->keep)
899 /* Free all temporaries used so far. This is normally called at the end
900 of generating code for a statement. */
907 for (p = temp_slots; p; p = p->next)
908 if (p->in_use && p->level == temp_slot_level && ! p->keep)
911 combine_temp_slots ();
914 /* Push deeper into the nesting level for stack temporaries. */
922 /* Pop a temporary nesting level. All slots in use in the current level
930 for (p = temp_slots; p; p = p->next)
931 if (p->in_use && p->level == temp_slot_level)
934 combine_temp_slots ();
939 /* Retroactively move an auto variable from a register to a stack slot.
940 This is done when an address-reference to the variable is seen. */
943 put_var_into_stack (decl)
947 enum machine_mode promoted_mode, decl_mode;
948 struct function *function = 0;
954 context = decl_function_context (decl);
956 /* Get the current rtl used for this object and it's original mode. */
957 reg = TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl) : DECL_RTL (decl);
959 /* No need to do anything if decl has no rtx yet
960 since in that case caller is setting TREE_ADDRESSABLE
961 and a stack slot will be assigned when the rtl is made. */
965 /* Get the declared mode for this object. */
966 decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl))
968 /* Get the mode it's actually stored in. */
969 promoted_mode = GET_MODE (reg);
971 /* If this variable comes from an outer function,
972 find that function's saved context. */
973 if (context != current_function_decl)
974 for (function = outer_function_chain; function; function = function->next)
975 if (function->decl == context)
978 /* If this is a variable-size object with a pseudo to address it,
979 put that pseudo into the stack, if the var is nonlocal. */
980 if (DECL_NONLOCAL (decl)
981 && GET_CODE (reg) == MEM
982 && GET_CODE (XEXP (reg, 0)) == REG
983 && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
986 decl_mode = promoted_mode = GET_MODE (reg);
989 /* Now we should have a value that resides in one or more pseudo regs. */
991 if (GET_CODE (reg) == REG)
992 put_reg_into_stack (function, reg, TREE_TYPE (decl),
993 promoted_mode, decl_mode);
994 else if (GET_CODE (reg) == CONCAT)
996 /* A CONCAT contains two pseudos; put them both in the stack.
997 We do it so they end up consecutive. */
998 enum machine_mode part_mode = GET_MODE (XEXP (reg, 0));
999 tree part_type = TREE_TYPE (TREE_TYPE (decl));
1000 #ifdef STACK_GROWS_DOWNWARD
1001 /* Since part 0 should have a lower address, do it second. */
1002 put_reg_into_stack (function, XEXP (reg, 1),
1003 part_type, part_mode, part_mode);
1004 put_reg_into_stack (function, XEXP (reg, 0),
1005 part_type, part_mode, part_mode);
1007 put_reg_into_stack (function, XEXP (reg, 0),
1008 part_type, part_mode, part_mode);
1009 put_reg_into_stack (function, XEXP (reg, 1),
1010 part_type, part_mode, part_mode);
1013 /* Change the CONCAT into a combined MEM for both parts. */
1014 PUT_CODE (reg, MEM);
1015 /* The two parts are in memory order already.
1016 Use the lower parts address as ours. */
1017 XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0);
1018 /* Prevent sharing of rtl that might lose. */
1019 if (GET_CODE (XEXP (reg, 0)) == PLUS)
1020 XEXP (reg, 0) = copy_rtx (XEXP (reg, 0));
1024 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1025 into the stack frame of FUNCTION (0 means the current function).
1026 DECL_MODE is the machine mode of the user-level data type.
1027 PROMOTED_MODE is the machine mode of the register. */
1030 put_reg_into_stack (function, reg, type, promoted_mode, decl_mode)
1031 struct function *function;
1034 enum machine_mode promoted_mode, decl_mode;
1040 if (REGNO (reg) < function->max_parm_reg)
1041 new = function->parm_reg_stack_loc[REGNO (reg)];
1043 new = assign_outer_stack_local (decl_mode, GET_MODE_SIZE (decl_mode),
1048 if (REGNO (reg) < max_parm_reg)
1049 new = parm_reg_stack_loc[REGNO (reg)];
1051 new = assign_stack_local (decl_mode, GET_MODE_SIZE (decl_mode), 0);
1054 XEXP (reg, 0) = XEXP (new, 0);
1055 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1056 REG_USERVAR_P (reg) = 0;
1057 PUT_CODE (reg, MEM);
1058 PUT_MODE (reg, decl_mode);
1060 /* If this is a memory ref that contains aggregate components,
1061 mark it as such for cse and loop optimize. */
1062 MEM_IN_STRUCT_P (reg)
1063 = (TREE_CODE (type) == ARRAY_TYPE
1064 || TREE_CODE (type) == RECORD_TYPE
1065 || TREE_CODE (type) == UNION_TYPE
1066 || TREE_CODE (type) == QUAL_UNION_TYPE);
1068 /* Now make sure that all refs to the variable, previously made
1069 when it was a register, are fixed up to be valid again. */
1072 struct var_refs_queue *temp;
1074 /* Variable is inherited; fix it up when we get back to its function. */
1075 push_obstacks (function->function_obstack,
1076 function->function_maybepermanent_obstack);
1078 /* See comment in restore_tree_status in tree.c for why this needs to be
1079 on saveable obstack. */
1081 = (struct var_refs_queue *) savealloc (sizeof (struct var_refs_queue));
1082 temp->modified = reg;
1083 temp->promoted_mode = promoted_mode;
1084 temp->unsignedp = TREE_UNSIGNED (type);
1085 temp->next = function->fixup_var_refs_queue;
1086 function->fixup_var_refs_queue = temp;
1090 /* Variable is local; fix it up now. */
1091 fixup_var_refs (reg, promoted_mode, TREE_UNSIGNED (type));
1095 fixup_var_refs (var, promoted_mode, unsignedp)
1097 enum machine_mode promoted_mode;
1101 rtx first_insn = get_insns ();
1102 struct sequence_stack *stack = sequence_stack;
1103 tree rtl_exps = rtl_expr_chain;
1105 /* Must scan all insns for stack-refs that exceed the limit. */
1106 fixup_var_refs_insns (var, promoted_mode, unsignedp, first_insn, stack == 0);
1108 /* Scan all pending sequences too. */
1109 for (; stack; stack = stack->next)
1111 push_to_sequence (stack->first);
1112 fixup_var_refs_insns (var, promoted_mode, unsignedp,
1113 stack->first, stack->next != 0);
1114 /* Update remembered end of sequence
1115 in case we added an insn at the end. */
1116 stack->last = get_last_insn ();
1120 /* Scan all waiting RTL_EXPRs too. */
1121 for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
1123 rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
1124 if (seq != const0_rtx && seq != 0)
1126 push_to_sequence (seq);
1127 fixup_var_refs_insns (var, promoted_mode, unsignedp, seq, 0);
1133 /* This structure is used by the following two functions to record MEMs or
1134 pseudos used to replace VAR, any SUBREGs of VAR, and any MEMs containing
1135 VAR as an address. We need to maintain this list in case two operands of
1136 an insn were required to match; in that case we must ensure we use the
1137 same replacement. */
1139 struct fixup_replacement
1143 struct fixup_replacement *next;
1146 /* REPLACEMENTS is a pointer to a list of the above structures and X is
1147 some part of an insn. Return a struct fixup_replacement whose OLD
1148 value is equal to X. Allocate a new structure if no such entry exists. */
1150 static struct fixup_replacement *
1151 find_fixup_replacement (replacements, x)
1152 struct fixup_replacement **replacements;
1155 struct fixup_replacement *p;
1157 /* See if we have already replaced this. */
1158 for (p = *replacements; p && p->old != x; p = p->next)
1163 p = (struct fixup_replacement *) oballoc (sizeof (struct fixup_replacement));
1166 p->next = *replacements;
1173 /* Scan the insn-chain starting with INSN for refs to VAR
1174 and fix them up. TOPLEVEL is nonzero if this chain is the
1175 main chain of insns for the current function. */
1178 fixup_var_refs_insns (var, promoted_mode, unsignedp, insn, toplevel)
1180 enum machine_mode promoted_mode;
1189 rtx next = NEXT_INSN (insn);
1191 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1193 /* The insn to load VAR from a home in the arglist
1194 is now a no-op. When we see it, just delete it. */
1196 && GET_CODE (PATTERN (insn)) == SET
1197 && SET_DEST (PATTERN (insn)) == var
1198 /* If this represents the result of an insn group,
1199 don't delete the insn. */
1200 && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0
1201 && rtx_equal_p (SET_SRC (PATTERN (insn)), var))
1203 /* In unoptimized compilation, we shouldn't call delete_insn
1204 except in jump.c doing warnings. */
1205 PUT_CODE (insn, NOTE);
1206 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1207 NOTE_SOURCE_FILE (insn) = 0;
1208 if (insn == last_parm_insn)
1209 last_parm_insn = PREV_INSN (next);
1213 struct fixup_replacement *replacements = 0;
1214 rtx next_insn = NEXT_INSN (insn);
1216 #ifdef SMALL_REGISTER_CLASSES
1217 /* If the insn that copies the results of a CALL_INSN
1218 into a pseudo now references VAR, we have to use an
1219 intermediate pseudo since we want the life of the
1220 return value register to be only a single insn.
1222 If we don't use an intermediate pseudo, such things as
1223 address computations to make the address of VAR valid
1224 if it is not can be placed beween the CALL_INSN and INSN.
1226 To make sure this doesn't happen, we record the destination
1227 of the CALL_INSN and see if the next insn uses both that
1230 if (call_dest != 0 && GET_CODE (insn) == INSN
1231 && reg_mentioned_p (var, PATTERN (insn))
1232 && reg_mentioned_p (call_dest, PATTERN (insn)))
1234 rtx temp = gen_reg_rtx (GET_MODE (call_dest));
1236 emit_insn_before (gen_move_insn (temp, call_dest), insn);
1238 PATTERN (insn) = replace_rtx (PATTERN (insn),
1242 if (GET_CODE (insn) == CALL_INSN
1243 && GET_CODE (PATTERN (insn)) == SET)
1244 call_dest = SET_DEST (PATTERN (insn));
1245 else if (GET_CODE (insn) == CALL_INSN
1246 && GET_CODE (PATTERN (insn)) == PARALLEL
1247 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
1248 call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
1253 /* See if we have to do anything to INSN now that VAR is in
1254 memory. If it needs to be loaded into a pseudo, use a single
1255 pseudo for the entire insn in case there is a MATCH_DUP
1256 between two operands. We pass a pointer to the head of
1257 a list of struct fixup_replacements. If fixup_var_refs_1
1258 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1259 it will record them in this list.
1261 If it allocated a pseudo for any replacement, we copy into
1264 fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn,
1267 /* If this is last_parm_insn, and any instructions were output
1268 after it to fix it up, then we must set last_parm_insn to
1269 the last such instruction emitted. */
1270 if (insn == last_parm_insn)
1271 last_parm_insn = PREV_INSN (next_insn);
1273 while (replacements)
1275 if (GET_CODE (replacements->new) == REG)
1280 /* OLD might be a (subreg (mem)). */
1281 if (GET_CODE (replacements->old) == SUBREG)
1283 = fixup_memory_subreg (replacements->old, insn, 0);
1286 = fixup_stack_1 (replacements->old, insn);
1288 /* We can not separate USE insns from the CALL_INSN
1289 that they belong to. If this is a CALL_INSN, insert
1290 the move insn before the USE insns preceding it
1291 instead of immediately before the insn. */
1292 if (GET_CODE (insn) == CALL_INSN)
1294 insert_before = insn;
1295 while (GET_CODE (PREV_INSN (insert_before)) == INSN
1296 && GET_CODE (PATTERN (PREV_INSN (insert_before))) == USE)
1297 insert_before = PREV_INSN (insert_before);
1300 insert_before = insn;
1302 /* If we are changing the mode, do a conversion.
1303 This might be wasteful, but combine.c will
1304 eliminate much of the waste. */
1306 if (GET_MODE (replacements->new)
1307 != GET_MODE (replacements->old))
1310 convert_move (replacements->new,
1311 replacements->old, unsignedp);
1312 seq = gen_sequence ();
1316 seq = gen_move_insn (replacements->new,
1319 emit_insn_before (seq, insert_before);
1322 replacements = replacements->next;
1326 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1327 But don't touch other insns referred to by reg-notes;
1328 we will get them elsewhere. */
1329 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
1330 if (GET_CODE (note) != INSN_LIST)
1332 = walk_fixup_memory_subreg (XEXP (note, 0), insn, 1);
1338 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1339 See if the rtx expression at *LOC in INSN needs to be changed.
1341 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1342 contain a list of original rtx's and replacements. If we find that we need
1343 to modify this insn by replacing a memory reference with a pseudo or by
1344 making a new MEM to implement a SUBREG, we consult that list to see if
1345 we have already chosen a replacement. If none has already been allocated,
1346 we allocate it and update the list. fixup_var_refs_insns will copy VAR
1347 or the SUBREG, as appropriate, to the pseudo. */
1350 fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements)
1352 enum machine_mode promoted_mode;
1355 struct fixup_replacement **replacements;
1358 register rtx x = *loc;
1359 RTX_CODE code = GET_CODE (x);
1361 register rtx tem, tem1;
1362 struct fixup_replacement *replacement;
1369 /* If we already have a replacement, use it. Otherwise,
1370 try to fix up this address in case it is invalid. */
1372 replacement = find_fixup_replacement (replacements, var);
1373 if (replacement->new)
1375 *loc = replacement->new;
1379 *loc = replacement->new = x = fixup_stack_1 (x, insn);
1381 /* Unless we are forcing memory to register or we changed the mode,
1382 we can leave things the way they are if the insn is valid. */
1384 INSN_CODE (insn) = -1;
1385 if (! flag_force_mem && GET_MODE (x) == promoted_mode
1386 && recog_memoized (insn) >= 0)
1389 *loc = replacement->new = gen_reg_rtx (promoted_mode);
1393 /* If X contains VAR, we need to unshare it here so that we update
1394 each occurrence separately. But all identical MEMs in one insn
1395 must be replaced with the same rtx because of the possibility of
1398 if (reg_mentioned_p (var, x))
1400 replacement = find_fixup_replacement (replacements, x);
1401 if (replacement->new == 0)
1402 replacement->new = copy_most_rtx (x, var);
1404 *loc = x = replacement->new;
1420 /* Note that in some cases those types of expressions are altered
1421 by optimize_bit_field, and do not survive to get here. */
1422 if (XEXP (x, 0) == var
1423 || (GET_CODE (XEXP (x, 0)) == SUBREG
1424 && SUBREG_REG (XEXP (x, 0)) == var))
1426 /* Get TEM as a valid MEM in the mode presently in the insn.
1428 We don't worry about the possibility of MATCH_DUP here; it
1429 is highly unlikely and would be tricky to handle. */
1432 if (GET_CODE (tem) == SUBREG)
1433 tem = fixup_memory_subreg (tem, insn, 1);
1434 tem = fixup_stack_1 (tem, insn);
1436 /* Unless we want to load from memory, get TEM into the proper mode
1437 for an extract from memory. This can only be done if the
1438 extract is at a constant position and length. */
1440 if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
1441 && GET_CODE (XEXP (x, 2)) == CONST_INT
1442 && ! mode_dependent_address_p (XEXP (tem, 0))
1443 && ! MEM_VOLATILE_P (tem))
1445 enum machine_mode wanted_mode = VOIDmode;
1446 enum machine_mode is_mode = GET_MODE (tem);
1447 int width = INTVAL (XEXP (x, 1));
1448 int pos = INTVAL (XEXP (x, 2));
1451 if (GET_CODE (x) == ZERO_EXTRACT)
1452 wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
1455 if (GET_CODE (x) == SIGN_EXTRACT)
1456 wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
1458 /* If we have a narrower mode, we can do something. */
1459 if (wanted_mode != VOIDmode
1460 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
1462 int offset = pos / BITS_PER_UNIT;
1463 rtx old_pos = XEXP (x, 2);
1466 /* If the bytes and bits are counted differently, we
1467 must adjust the offset. */
1468 #if BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN
1469 offset = (GET_MODE_SIZE (is_mode)
1470 - GET_MODE_SIZE (wanted_mode) - offset);
1473 pos %= GET_MODE_BITSIZE (wanted_mode);
1475 newmem = gen_rtx (MEM, wanted_mode,
1476 plus_constant (XEXP (tem, 0), offset));
1477 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
1478 MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
1479 MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
1481 /* Make the change and see if the insn remains valid. */
1482 INSN_CODE (insn) = -1;
1483 XEXP (x, 0) = newmem;
1484 XEXP (x, 2) = GEN_INT (pos);
1486 if (recog_memoized (insn) >= 0)
1489 /* Otherwise, restore old position. XEXP (x, 0) will be
1491 XEXP (x, 2) = old_pos;
1495 /* If we get here, the bitfield extract insn can't accept a memory
1496 reference. Copy the input into a register. */
1498 tem1 = gen_reg_rtx (GET_MODE (tem));
1499 emit_insn_before (gen_move_insn (tem1, tem), insn);
1506 if (SUBREG_REG (x) == var)
1508 /* If this is a special SUBREG made because VAR was promoted
1509 from a wider mode, replace it with VAR and call ourself
1510 recursively, this time saying that the object previously
1511 had its current mode (by virtue of the SUBREG). */
1513 if (SUBREG_PROMOTED_VAR_P (x))
1516 fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements);
1520 /* If this SUBREG makes VAR wider, it has become a paradoxical
1521 SUBREG with VAR in memory, but these aren't allowed at this
1522 stage of the compilation. So load VAR into a pseudo and take
1523 a SUBREG of that pseudo. */
1524 if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
1526 replacement = find_fixup_replacement (replacements, var);
1527 if (replacement->new == 0)
1528 replacement->new = gen_reg_rtx (GET_MODE (var));
1529 SUBREG_REG (x) = replacement->new;
1533 /* See if we have already found a replacement for this SUBREG.
1534 If so, use it. Otherwise, make a MEM and see if the insn
1535 is recognized. If not, or if we should force MEM into a register,
1536 make a pseudo for this SUBREG. */
1537 replacement = find_fixup_replacement (replacements, x);
1538 if (replacement->new)
1540 *loc = replacement->new;
1544 replacement->new = *loc = fixup_memory_subreg (x, insn, 0);
1546 INSN_CODE (insn) = -1;
1547 if (! flag_force_mem && recog_memoized (insn) >= 0)
1550 *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
1556 /* First do special simplification of bit-field references. */
1557 if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
1558 || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
1559 optimize_bit_field (x, insn, 0);
1560 if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
1561 || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
1562 optimize_bit_field (x, insn, NULL_PTR);
1564 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
1565 insn into a pseudo and store the low part of the pseudo into VAR. */
1566 if (GET_CODE (SET_DEST (x)) == SUBREG
1567 && SUBREG_REG (SET_DEST (x)) == var
1568 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
1569 > GET_MODE_SIZE (GET_MODE (var))))
1571 SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
1572 emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
1579 rtx dest = SET_DEST (x);
1580 rtx src = SET_SRC (x);
1581 rtx outerdest = dest;
1583 while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
1584 || GET_CODE (dest) == SIGN_EXTRACT
1585 || GET_CODE (dest) == ZERO_EXTRACT)
1586 dest = XEXP (dest, 0);
1588 if (GET_CODE (src) == SUBREG)
1589 src = XEXP (src, 0);
1591 /* If VAR does not appear at the top level of the SET
1592 just scan the lower levels of the tree. */
1594 if (src != var && dest != var)
1597 /* We will need to rerecognize this insn. */
1598 INSN_CODE (insn) = -1;
1601 if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var)
1603 /* Since this case will return, ensure we fixup all the
1605 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1),
1606 insn, replacements);
1607 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2),
1608 insn, replacements);
1609 fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x),
1610 insn, replacements);
1612 tem = XEXP (outerdest, 0);
1614 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
1615 that may appear inside a ZERO_EXTRACT.
1616 This was legitimate when the MEM was a REG. */
1617 if (GET_CODE (tem) == SUBREG
1618 && SUBREG_REG (tem) == var)
1619 tem = fixup_memory_subreg (tem, insn, 1);
1621 tem = fixup_stack_1 (tem, insn);
1623 if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
1624 && GET_CODE (XEXP (outerdest, 2)) == CONST_INT
1625 && ! mode_dependent_address_p (XEXP (tem, 0))
1626 && ! MEM_VOLATILE_P (tem))
1628 enum machine_mode wanted_mode
1629 = insn_operand_mode[(int) CODE_FOR_insv][0];
1630 enum machine_mode is_mode = GET_MODE (tem);
1631 int width = INTVAL (XEXP (outerdest, 1));
1632 int pos = INTVAL (XEXP (outerdest, 2));
1634 /* If we have a narrower mode, we can do something. */
1635 if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
1637 int offset = pos / BITS_PER_UNIT;
1638 rtx old_pos = XEXP (outerdest, 2);
1641 #if BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN
1642 offset = (GET_MODE_SIZE (is_mode)
1643 - GET_MODE_SIZE (wanted_mode) - offset);
1646 pos %= GET_MODE_BITSIZE (wanted_mode);
1648 newmem = gen_rtx (MEM, wanted_mode,
1649 plus_constant (XEXP (tem, 0), offset));
1650 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
1651 MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
1652 MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
1654 /* Make the change and see if the insn remains valid. */
1655 INSN_CODE (insn) = -1;
1656 XEXP (outerdest, 0) = newmem;
1657 XEXP (outerdest, 2) = GEN_INT (pos);
1659 if (recog_memoized (insn) >= 0)
1662 /* Otherwise, restore old position. XEXP (x, 0) will be
1664 XEXP (outerdest, 2) = old_pos;
1668 /* If we get here, the bit-field store doesn't allow memory
1669 or isn't located at a constant position. Load the value into
1670 a register, do the store, and put it back into memory. */
1672 tem1 = gen_reg_rtx (GET_MODE (tem));
1673 emit_insn_before (gen_move_insn (tem1, tem), insn);
1674 emit_insn_after (gen_move_insn (tem, tem1), insn);
1675 XEXP (outerdest, 0) = tem1;
1680 /* STRICT_LOW_PART is a no-op on memory references
1681 and it can cause combinations to be unrecognizable,
1684 if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
1685 SET_DEST (x) = XEXP (SET_DEST (x), 0);
1687 /* A valid insn to copy VAR into or out of a register
1688 must be left alone, to avoid an infinite loop here.
1689 If the reference to VAR is by a subreg, fix that up,
1690 since SUBREG is not valid for a memref.
1691 Also fix up the address of the stack slot.
1693 Note that we must not try to recognize the insn until
1694 after we know that we have valid addresses and no
1695 (subreg (mem ...) ...) constructs, since these interfere
1696 with determining the validity of the insn. */
1698 if ((SET_SRC (x) == var
1699 || (GET_CODE (SET_SRC (x)) == SUBREG
1700 && SUBREG_REG (SET_SRC (x)) == var))
1701 && (GET_CODE (SET_DEST (x)) == REG
1702 || (GET_CODE (SET_DEST (x)) == SUBREG
1703 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
1704 && x == single_set (PATTERN (insn)))
1708 replacement = find_fixup_replacement (replacements, SET_SRC (x));
1709 if (replacement->new)
1710 SET_SRC (x) = replacement->new;
1711 else if (GET_CODE (SET_SRC (x)) == SUBREG)
1712 SET_SRC (x) = replacement->new
1713 = fixup_memory_subreg (SET_SRC (x), insn, 0);
1715 SET_SRC (x) = replacement->new
1716 = fixup_stack_1 (SET_SRC (x), insn);
1718 if (recog_memoized (insn) >= 0)
1721 /* INSN is not valid, but we know that we want to
1722 copy SET_SRC (x) to SET_DEST (x) in some way. So
1723 we generate the move and see whether it requires more
1724 than one insn. If it does, we emit those insns and
1725 delete INSN. Otherwise, we an just replace the pattern
1726 of INSN; we have already verified above that INSN has
1727 no other function that to do X. */
1729 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
1730 if (GET_CODE (pat) == SEQUENCE)
1732 emit_insn_after (pat, insn);
1733 PUT_CODE (insn, NOTE);
1734 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1735 NOTE_SOURCE_FILE (insn) = 0;
1738 PATTERN (insn) = pat;
1743 if ((SET_DEST (x) == var
1744 || (GET_CODE (SET_DEST (x)) == SUBREG
1745 && SUBREG_REG (SET_DEST (x)) == var))
1746 && (GET_CODE (SET_SRC (x)) == REG
1747 || (GET_CODE (SET_SRC (x)) == SUBREG
1748 && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
1749 && x == single_set (PATTERN (insn)))
1753 if (GET_CODE (SET_DEST (x)) == SUBREG)
1754 SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn, 0);
1756 SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
1758 if (recog_memoized (insn) >= 0)
1761 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
1762 if (GET_CODE (pat) == SEQUENCE)
1764 emit_insn_after (pat, insn);
1765 PUT_CODE (insn, NOTE);
1766 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1767 NOTE_SOURCE_FILE (insn) = 0;
1770 PATTERN (insn) = pat;
1775 /* Otherwise, storing into VAR must be handled specially
1776 by storing into a temporary and copying that into VAR
1777 with a new insn after this one. Note that this case
1778 will be used when storing into a promoted scalar since
1779 the insn will now have different modes on the input
1780 and output and hence will be invalid (except for the case
1781 of setting it to a constant, which does not need any
1782 change if it is valid). We generate extra code in that case,
1783 but combine.c will eliminate it. */
1788 rtx fixeddest = SET_DEST (x);
1790 /* STRICT_LOW_PART can be discarded, around a MEM. */
1791 if (GET_CODE (fixeddest) == STRICT_LOW_PART)
1792 fixeddest = XEXP (fixeddest, 0);
1793 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
1794 if (GET_CODE (fixeddest) == SUBREG)
1795 fixeddest = fixup_memory_subreg (fixeddest, insn, 0);
1797 fixeddest = fixup_stack_1 (fixeddest, insn);
1799 temp = gen_reg_rtx (GET_MODE (SET_SRC (x)) == VOIDmode
1800 ? GET_MODE (fixeddest)
1801 : GET_MODE (SET_SRC (x)));
1803 emit_insn_after (gen_move_insn (fixeddest,
1804 gen_lowpart (GET_MODE (fixeddest),
1808 SET_DEST (x) = temp;
1813 /* Nothing special about this RTX; fix its operands. */
1815 fmt = GET_RTX_FORMAT (code);
1816 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1819 fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements);
1823 for (j = 0; j < XVECLEN (x, i); j++)
1824 fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j),
1825 insn, replacements);
1830 /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
1831 return an rtx (MEM:m1 newaddr) which is equivalent.
1832 If any insns must be emitted to compute NEWADDR, put them before INSN.
1834 UNCRITICAL nonzero means accept paradoxical subregs.
1835 This is used for subregs found inside of ZERO_EXTRACTs and in REG_NOTES. */
1838 fixup_memory_subreg (x, insn, uncritical)
1843 int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
1844 rtx addr = XEXP (SUBREG_REG (x), 0);
1845 enum machine_mode mode = GET_MODE (x);
1848 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
1849 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
1853 #if BYTES_BIG_ENDIAN
1854 offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
1855 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
1857 addr = plus_constant (addr, offset);
1858 if (!flag_force_addr && memory_address_p (mode, addr))
1859 /* Shortcut if no insns need be emitted. */
1860 return change_address (SUBREG_REG (x), mode, addr);
1862 result = change_address (SUBREG_REG (x), mode, addr);
1863 emit_insn_before (gen_sequence (), insn);
1868 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
1869 Replace subexpressions of X in place.
1870 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
1871 Otherwise return X, with its contents possibly altered.
1873 If any insns must be emitted to compute NEWADDR, put them before INSN.
1875 UNCRITICAL is as in fixup_memory_subreg. */
1878 walk_fixup_memory_subreg (x, insn, uncritical)
1883 register enum rtx_code code;
1890 code = GET_CODE (x);
1892 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
1893 return fixup_memory_subreg (x, insn, uncritical);
1895 /* Nothing special about this RTX; fix its operands. */
1897 fmt = GET_RTX_FORMAT (code);
1898 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1901 XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn, uncritical);
1905 for (j = 0; j < XVECLEN (x, i); j++)
1907 = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn, uncritical);
1914 /* Fix up any references to stack slots that are invalid memory addresses
1915 because they exceed the maximum range of a displacement. */
1918 fixup_stack_slots ()
1922 /* Did we generate a stack slot that is out of range
1923 or otherwise has an invalid address? */
1924 if (invalid_stack_slot)
1926 /* Yes. Must scan all insns for stack-refs that exceed the limit. */
1927 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
1928 if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
1929 || GET_CODE (insn) == JUMP_INSN)
1930 fixup_stack_1 (PATTERN (insn), insn);
1935 /* For each memory ref within X, if it refers to a stack slot
1936 with an out of range displacement, put the address in a temp register
1937 (emitting new insns before INSN to load these registers)
1938 and alter the memory ref to use that register.
1939 Replace each such MEM rtx with a copy, to avoid clobberage. */
1942 fixup_stack_1 (x, insn)
1947 register RTX_CODE code = GET_CODE (x);
1952 register rtx ad = XEXP (x, 0);
1953 /* If we have address of a stack slot but it's not valid
1954 (displacement is too large), compute the sum in a register. */
1955 if (GET_CODE (ad) == PLUS
1956 && GET_CODE (XEXP (ad, 0)) == REG
1957 && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
1958 && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER)
1959 || XEXP (ad, 0) == current_function_internal_arg_pointer)
1960 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
1963 if (memory_address_p (GET_MODE (x), ad))
1967 temp = copy_to_reg (ad);
1968 seq = gen_sequence ();
1970 emit_insn_before (seq, insn);
1971 return change_address (x, VOIDmode, temp);
1976 fmt = GET_RTX_FORMAT (code);
1977 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1980 XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
1984 for (j = 0; j < XVECLEN (x, i); j++)
1985 XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
1991 /* Optimization: a bit-field instruction whose field
1992 happens to be a byte or halfword in memory
1993 can be changed to a move instruction.
1995 We call here when INSN is an insn to examine or store into a bit-field.
1996 BODY is the SET-rtx to be altered.
1998 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
1999 (Currently this is called only from function.c, and EQUIV_MEM
2003 optimize_bit_field (body, insn, equiv_mem)
2008 register rtx bitfield;
2011 enum machine_mode mode;
2013 if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
2014 || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
2015 bitfield = SET_DEST (body), destflag = 1;
2017 bitfield = SET_SRC (body), destflag = 0;
2019 /* First check that the field being stored has constant size and position
2020 and is in fact a byte or halfword suitably aligned. */
2022 if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
2023 && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
2024 && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
2026 && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
2028 register rtx memref = 0;
2030 /* Now check that the containing word is memory, not a register,
2031 and that it is safe to change the machine mode. */
2033 if (GET_CODE (XEXP (bitfield, 0)) == MEM)
2034 memref = XEXP (bitfield, 0);
2035 else if (GET_CODE (XEXP (bitfield, 0)) == REG
2037 memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
2038 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2039 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
2040 memref = SUBREG_REG (XEXP (bitfield, 0));
2041 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2043 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
2044 memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
2047 && ! mode_dependent_address_p (XEXP (memref, 0))
2048 && ! MEM_VOLATILE_P (memref))
2050 /* Now adjust the address, first for any subreg'ing
2051 that we are now getting rid of,
2052 and then for which byte of the word is wanted. */
2054 register int offset = INTVAL (XEXP (bitfield, 2));
2055 /* Adjust OFFSET to count bits from low-address byte. */
2056 #if BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN
2057 offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
2058 - offset - INTVAL (XEXP (bitfield, 1)));
2060 /* Adjust OFFSET to count bytes from low-address byte. */
2061 offset /= BITS_PER_UNIT;
2062 if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
2064 offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD;
2065 #if BYTES_BIG_ENDIAN
2066 offset -= (MIN (UNITS_PER_WORD,
2067 GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
2068 - MIN (UNITS_PER_WORD,
2069 GET_MODE_SIZE (GET_MODE (memref))));
2073 memref = change_address (memref, mode,
2074 plus_constant (XEXP (memref, 0), offset));
2076 /* Store this memory reference where
2077 we found the bit field reference. */
2081 validate_change (insn, &SET_DEST (body), memref, 1);
2082 if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
2084 rtx src = SET_SRC (body);
2085 while (GET_CODE (src) == SUBREG
2086 && SUBREG_WORD (src) == 0)
2087 src = SUBREG_REG (src);
2088 if (GET_MODE (src) != GET_MODE (memref))
2089 src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
2090 validate_change (insn, &SET_SRC (body), src, 1);
2092 else if (GET_MODE (SET_SRC (body)) != VOIDmode
2093 && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
2094 /* This shouldn't happen because anything that didn't have
2095 one of these modes should have got converted explicitly
2096 and then referenced through a subreg.
2097 This is so because the original bit-field was
2098 handled by agg_mode and so its tree structure had
2099 the same mode that memref now has. */
2104 rtx dest = SET_DEST (body);
2106 while (GET_CODE (dest) == SUBREG
2107 && SUBREG_WORD (dest) == 0)
2108 dest = SUBREG_REG (dest);
2110 validate_change (insn, &SET_DEST (body), dest, 1);
2112 if (GET_MODE (dest) == GET_MODE (memref))
2113 validate_change (insn, &SET_SRC (body), memref, 1);
2116 /* Convert the mem ref to the destination mode. */
2117 rtx newreg = gen_reg_rtx (GET_MODE (dest));
2120 convert_move (newreg, memref,
2121 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
2125 validate_change (insn, &SET_SRC (body), newreg, 1);
2129 /* See if we can convert this extraction or insertion into
2130 a simple move insn. We might not be able to do so if this
2131 was, for example, part of a PARALLEL.
2133 If we succeed, write out any needed conversions. If we fail,
2134 it is hard to guess why we failed, so don't do anything
2135 special; just let the optimization be suppressed. */
2137 if (apply_change_group () && seq)
2138 emit_insns_before (seq, insn);
2143 /* These routines are responsible for converting virtual register references
2144 to the actual hard register references once RTL generation is complete.
2146 The following four variables are used for communication between the
2147 routines. They contain the offsets of the virtual registers from their
2148 respective hard registers. */
2150 static int in_arg_offset;
2151 static int var_offset;
2152 static int dynamic_offset;
2153 static int out_arg_offset;
2155 /* In most machines, the stack pointer register is equivalent to the bottom
2158 #ifndef STACK_POINTER_OFFSET
2159 #define STACK_POINTER_OFFSET 0
2162 /* If not defined, pick an appropriate default for the offset of dynamically
2163 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2164 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2166 #ifndef STACK_DYNAMIC_OFFSET
2168 #ifdef ACCUMULATE_OUTGOING_ARGS
2169 /* The bottom of the stack points to the actual arguments. If
2170 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2171 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2172 stack space for register parameters is not pushed by the caller, but
2173 rather part of the fixed stack areas and hence not included in
2174 `current_function_outgoing_args_size'. Nevertheless, we must allow
2175 for it when allocating stack dynamic objects. */
2177 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2178 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2179 (current_function_outgoing_args_size \
2180 + REG_PARM_STACK_SPACE (FNDECL) + (STACK_POINTER_OFFSET))
2183 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2184 (current_function_outgoing_args_size + (STACK_POINTER_OFFSET))
2188 #define STACK_DYNAMIC_OFFSET(FNDECL) STACK_POINTER_OFFSET
2192 /* Pass through the INSNS of function FNDECL and convert virtual register
2193 references to hard register references. */
2196 instantiate_virtual_regs (fndecl, insns)
2202 /* Compute the offsets to use for this function. */
2203 in_arg_offset = FIRST_PARM_OFFSET (fndecl);
2204 var_offset = STARTING_FRAME_OFFSET;
2205 dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
2206 out_arg_offset = STACK_POINTER_OFFSET;
2208 /* Scan all variables and parameters of this function. For each that is
2209 in memory, instantiate all virtual registers if the result is a valid
2210 address. If not, we do it later. That will handle most uses of virtual
2211 regs on many machines. */
2212 instantiate_decls (fndecl, 1);
2214 /* Initialize recognition, indicating that volatile is OK. */
2217 /* Scan through all the insns, instantiating every virtual register still
2219 for (insn = insns; insn; insn = NEXT_INSN (insn))
2220 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
2221 || GET_CODE (insn) == CALL_INSN)
2223 instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1);
2224 instantiate_virtual_regs_1 (®_NOTES (insn), NULL_RTX, 0);
2227 /* Now instantiate the remaining register equivalences for debugging info.
2228 These will not be valid addresses. */
2229 instantiate_decls (fndecl, 0);
2231 /* Indicate that, from now on, assign_stack_local should use
2232 frame_pointer_rtx. */
2233 virtuals_instantiated = 1;
2236 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
2237 all virtual registers in their DECL_RTL's.
2239 If VALID_ONLY, do this only if the resulting address is still valid.
2240 Otherwise, always do it. */
2243 instantiate_decls (fndecl, valid_only)
2249 if (DECL_INLINE (fndecl))
2250 /* When compiling an inline function, the obstack used for
2251 rtl allocation is the maybepermanent_obstack. Calling
2252 `resume_temporary_allocation' switches us back to that
2253 obstack while we process this function's parameters. */
2254 resume_temporary_allocation ();
2256 /* Process all parameters of the function. */
2257 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
2259 instantiate_decl (DECL_RTL (decl), int_size_in_bytes (TREE_TYPE (decl)),
2261 instantiate_decl (DECL_INCOMING_RTL (decl),
2262 int_size_in_bytes (TREE_TYPE (decl)), valid_only);
2265 /* Now process all variables defined in the function or its subblocks. */
2266 instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
2268 if (DECL_INLINE (fndecl))
2270 /* Save all rtl allocated for this function by raising the
2271 high-water mark on the maybepermanent_obstack. */
2273 /* All further rtl allocation is now done in the current_obstack. */
2274 rtl_in_current_obstack ();
2278 /* Subroutine of instantiate_decls: Process all decls in the given
2279 BLOCK node and all its subblocks. */
2282 instantiate_decls_1 (let, valid_only)
2288 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
2289 instantiate_decl (DECL_RTL (t), int_size_in_bytes (TREE_TYPE (t)),
2292 /* Process all subblocks. */
2293 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
2294 instantiate_decls_1 (t, valid_only);
2297 /* Subroutine of the preceding procedures: Given RTL representing a
2298 decl and the size of the object, do any instantiation required.
2300 If VALID_ONLY is non-zero, it means that the RTL should only be
2301 changed if the new address is valid. */
2304 instantiate_decl (x, size, valid_only)
2309 enum machine_mode mode;
2312 /* If this is not a MEM, no need to do anything. Similarly if the
2313 address is a constant or a register that is not a virtual register. */
2315 if (x == 0 || GET_CODE (x) != MEM)
2319 if (CONSTANT_P (addr)
2320 || (GET_CODE (addr) == REG
2321 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
2322 || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
2325 /* If we should only do this if the address is valid, copy the address.
2326 We need to do this so we can undo any changes that might make the
2327 address invalid. This copy is unfortunate, but probably can't be
2331 addr = copy_rtx (addr);
2333 instantiate_virtual_regs_1 (&addr, NULL_RTX, 0);
2338 /* Now verify that the resulting address is valid for every integer or
2339 floating-point mode up to and including SIZE bytes long. We do this
2340 since the object might be accessed in any mode and frame addresses
2343 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2344 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
2345 mode = GET_MODE_WIDER_MODE (mode))
2346 if (! memory_address_p (mode, addr))
2349 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
2350 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
2351 mode = GET_MODE_WIDER_MODE (mode))
2352 if (! memory_address_p (mode, addr))
2355 /* Otherwise, put back the address, now that we have updated it and we
2356 know it is valid. */
2361 /* Given a pointer to a piece of rtx and an optional pointer to the
2362 containing object, instantiate any virtual registers present in it.
2364 If EXTRA_INSNS, we always do the replacement and generate
2365 any extra insns before OBJECT. If it zero, we do nothing if replacement
2368 Return 1 if we either had nothing to do or if we were able to do the
2369 needed replacement. Return 0 otherwise; we only return zero if
2370 EXTRA_INSNS is zero.
2372 We first try some simple transformations to avoid the creation of extra
2376 instantiate_virtual_regs_1 (loc, object, extra_insns)
2390 /* Re-start here to avoid recursion in common cases. */
2397 code = GET_CODE (x);
2399 /* Check for some special cases. */
2416 /* We are allowed to set the virtual registers. This means that
2417 that the actual register should receive the source minus the
2418 appropriate offset. This is used, for example, in the handling
2419 of non-local gotos. */
2420 if (SET_DEST (x) == virtual_incoming_args_rtx)
2421 new = arg_pointer_rtx, offset = - in_arg_offset;
2422 else if (SET_DEST (x) == virtual_stack_vars_rtx)
2423 new = frame_pointer_rtx, offset = - var_offset;
2424 else if (SET_DEST (x) == virtual_stack_dynamic_rtx)
2425 new = stack_pointer_rtx, offset = - dynamic_offset;
2426 else if (SET_DEST (x) == virtual_outgoing_args_rtx)
2427 new = stack_pointer_rtx, offset = - out_arg_offset;
2431 /* The only valid sources here are PLUS or REG. Just do
2432 the simplest possible thing to handle them. */
2433 if (GET_CODE (SET_SRC (x)) != REG
2434 && GET_CODE (SET_SRC (x)) != PLUS)
2438 if (GET_CODE (SET_SRC (x)) != REG)
2439 temp = force_operand (SET_SRC (x), NULL_RTX);
2442 temp = force_operand (plus_constant (temp, offset), NULL_RTX);
2446 emit_insns_before (seq, object);
2449 if (!validate_change (object, &SET_SRC (x), temp, 0)
2456 instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns);
2461 /* Handle special case of virtual register plus constant. */
2462 if (CONSTANT_P (XEXP (x, 1)))
2466 /* Check for (plus (plus VIRT foo) (const_int)) first. */
2467 if (GET_CODE (XEXP (x, 0)) == PLUS)
2469 rtx inner = XEXP (XEXP (x, 0), 0);
2471 if (inner == virtual_incoming_args_rtx)
2472 new = arg_pointer_rtx, offset = in_arg_offset;
2473 else if (inner == virtual_stack_vars_rtx)
2474 new = frame_pointer_rtx, offset = var_offset;
2475 else if (inner == virtual_stack_dynamic_rtx)
2476 new = stack_pointer_rtx, offset = dynamic_offset;
2477 else if (inner == virtual_outgoing_args_rtx)
2478 new = stack_pointer_rtx, offset = out_arg_offset;
2485 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object,
2487 new = gen_rtx (PLUS, Pmode, new, XEXP (XEXP (x, 0), 1));
2490 else if (XEXP (x, 0) == virtual_incoming_args_rtx)
2491 new = arg_pointer_rtx, offset = in_arg_offset;
2492 else if (XEXP (x, 0) == virtual_stack_vars_rtx)
2493 new = frame_pointer_rtx, offset = var_offset;
2494 else if (XEXP (x, 0) == virtual_stack_dynamic_rtx)
2495 new = stack_pointer_rtx, offset = dynamic_offset;
2496 else if (XEXP (x, 0) == virtual_outgoing_args_rtx)
2497 new = stack_pointer_rtx, offset = out_arg_offset;
2500 /* We know the second operand is a constant. Unless the
2501 first operand is a REG (which has been already checked),
2502 it needs to be checked. */
2503 if (GET_CODE (XEXP (x, 0)) != REG)
2513 new = plus_constant (XEXP (x, 1), offset);
2515 /* If the new constant is zero, try to replace the sum with its
2517 if (new == const0_rtx
2518 && validate_change (object, loc, XEXP (x, 0), 0))
2521 /* Next try to replace constant with new one. */
2522 if (!validate_change (object, &XEXP (x, 1), new, 0))
2530 /* Otherwise copy the new constant into a register and replace
2531 constant with that register. */
2532 temp = gen_reg_rtx (Pmode);
2533 if (validate_change (object, &XEXP (x, 1), temp, 0))
2534 emit_insn_before (gen_move_insn (temp, new), object);
2537 /* If that didn't work, replace this expression with a
2538 register containing the sum. */
2540 new = gen_rtx (PLUS, Pmode, XEXP (x, 0), new);
2544 temp = force_operand (new, NULL_RTX);
2548 emit_insns_before (seq, object);
2549 if (! validate_change (object, loc, temp, 0)
2550 && ! validate_replace_rtx (x, temp, object))
2558 /* Fall through to generic two-operand expression case. */
2564 case DIV: case UDIV:
2565 case MOD: case UMOD:
2566 case AND: case IOR: case XOR:
2567 case LSHIFT: case ASHIFT: case ROTATE:
2568 case ASHIFTRT: case LSHIFTRT: case ROTATERT:
2570 case GE: case GT: case GEU: case GTU:
2571 case LE: case LT: case LEU: case LTU:
2572 if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
2573 instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns);
2578 /* Most cases of MEM that convert to valid addresses have already been
2579 handled by our scan of regno_reg_rtx. The only special handling we
2580 need here is to make a copy of the rtx to ensure it isn't being
2581 shared if we have to change it to a pseudo.
2583 If the rtx is a simple reference to an address via a virtual register,
2584 it can potentially be shared. In such cases, first try to make it
2585 a valid address, which can also be shared. Otherwise, copy it and
2588 First check for common cases that need no processing. These are
2589 usually due to instantiation already being done on a previous instance
2593 if (CONSTANT_ADDRESS_P (temp)
2594 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2595 || temp == arg_pointer_rtx
2597 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2598 || temp == hard_frame_pointer_rtx
2600 || temp == frame_pointer_rtx)
2603 if (GET_CODE (temp) == PLUS
2604 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
2605 && (XEXP (temp, 0) == frame_pointer_rtx
2606 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2607 || XEXP (temp, 0) == hard_frame_pointer_rtx
2609 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2610 || XEXP (temp, 0) == arg_pointer_rtx
2615 if (temp == virtual_stack_vars_rtx
2616 || temp == virtual_incoming_args_rtx
2617 || (GET_CODE (temp) == PLUS
2618 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
2619 && (XEXP (temp, 0) == virtual_stack_vars_rtx
2620 || XEXP (temp, 0) == virtual_incoming_args_rtx)))
2622 /* This MEM may be shared. If the substitution can be done without
2623 the need to generate new pseudos, we want to do it in place
2624 so all copies of the shared rtx benefit. The call below will
2625 only make substitutions if the resulting address is still
2628 Note that we cannot pass X as the object in the recursive call
2629 since the insn being processed may not allow all valid
2630 addresses. However, if we were not passed on object, we can
2631 only modify X without copying it if X will have a valid
2634 ??? Also note that this can still lose if OBJECT is an insn that
2635 has less restrictions on an address that some other insn.
2636 In that case, we will modify the shared address. This case
2637 doesn't seem very likely, though. */
2639 if (instantiate_virtual_regs_1 (&XEXP (x, 0),
2640 object ? object : x, 0))
2643 /* Otherwise make a copy and process that copy. We copy the entire
2644 RTL expression since it might be a PLUS which could also be
2646 *loc = x = copy_rtx (x);
2649 /* Fall through to generic unary operation case. */
2653 case STRICT_LOW_PART:
2655 case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC:
2656 case SIGN_EXTEND: case ZERO_EXTEND:
2657 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE:
2658 case FLOAT: case FIX:
2659 case UNSIGNED_FIX: case UNSIGNED_FLOAT:
2663 /* These case either have just one operand or we know that we need not
2664 check the rest of the operands. */
2669 /* Try to replace with a PLUS. If that doesn't work, compute the sum
2670 in front of this insn and substitute the temporary. */
2671 if (x == virtual_incoming_args_rtx)
2672 new = arg_pointer_rtx, offset = in_arg_offset;
2673 else if (x == virtual_stack_vars_rtx)
2674 new = frame_pointer_rtx, offset = var_offset;
2675 else if (x == virtual_stack_dynamic_rtx)
2676 new = stack_pointer_rtx, offset = dynamic_offset;
2677 else if (x == virtual_outgoing_args_rtx)
2678 new = stack_pointer_rtx, offset = out_arg_offset;
2682 temp = plus_constant (new, offset);
2683 if (!validate_change (object, loc, temp, 0))
2689 temp = force_operand (temp, NULL_RTX);
2693 emit_insns_before (seq, object);
2694 if (! validate_change (object, loc, temp, 0)
2695 && ! validate_replace_rtx (x, temp, object))
2703 /* Scan all subexpressions. */
2704 fmt = GET_RTX_FORMAT (code);
2705 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
2708 if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns))
2711 else if (*fmt == 'E')
2712 for (j = 0; j < XVECLEN (x, i); j++)
2713 if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object,
2720 /* Optimization: assuming this function does not receive nonlocal gotos,
2721 delete the handlers for such, as well as the insns to establish
2722 and disestablish them. */
2728 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2730 /* Delete the handler by turning off the flag that would
2731 prevent jump_optimize from deleting it.
2732 Also permit deletion of the nonlocal labels themselves
2733 if nothing local refers to them. */
2734 if (GET_CODE (insn) == CODE_LABEL)
2735 LABEL_PRESERVE_P (insn) = 0;
2736 if (GET_CODE (insn) == INSN
2737 && ((nonlocal_goto_handler_slot != 0
2738 && reg_mentioned_p (nonlocal_goto_handler_slot, PATTERN (insn)))
2739 || (nonlocal_goto_stack_level != 0
2740 && reg_mentioned_p (nonlocal_goto_stack_level,
2746 /* Return a list (chain of EXPR_LIST nodes) for the nonlocal labels
2747 of the current function. */
2750 nonlocal_label_rtx_list ()
2755 for (t = nonlocal_labels; t; t = TREE_CHAIN (t))
2756 x = gen_rtx (EXPR_LIST, VOIDmode, label_rtx (TREE_VALUE (t)), x);
2761 /* Output a USE for any register use in RTL.
2762 This is used with -noreg to mark the extent of lifespan
2763 of any registers used in a user-visible variable's DECL_RTL. */
2769 if (GET_CODE (rtl) == REG)
2770 /* This is a register variable. */
2771 emit_insn (gen_rtx (USE, VOIDmode, rtl));
2772 else if (GET_CODE (rtl) == MEM
2773 && GET_CODE (XEXP (rtl, 0)) == REG
2774 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
2775 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
2776 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
2777 /* This is a variable-sized structure. */
2778 emit_insn (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)));
2781 /* Like use_variable except that it outputs the USEs after INSN
2782 instead of at the end of the insn-chain. */
2785 use_variable_after (rtl, insn)
2788 if (GET_CODE (rtl) == REG)
2789 /* This is a register variable. */
2790 emit_insn_after (gen_rtx (USE, VOIDmode, rtl), insn);
2791 else if (GET_CODE (rtl) == MEM
2792 && GET_CODE (XEXP (rtl, 0)) == REG
2793 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
2794 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
2795 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
2796 /* This is a variable-sized structure. */
2797 emit_insn_after (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)), insn);
2803 return max_parm_reg;
2806 /* Return the first insn following those generated by `assign_parms'. */
2809 get_first_nonparm_insn ()
2812 return NEXT_INSN (last_parm_insn);
2813 return get_insns ();
2816 /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
2817 Crash if there is none. */
2820 get_first_block_beg ()
2822 register rtx searcher;
2823 register rtx insn = get_first_nonparm_insn ();
2825 for (searcher = insn; searcher; searcher = NEXT_INSN (searcher))
2826 if (GET_CODE (searcher) == NOTE
2827 && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG)
2830 abort (); /* Invalid call to this function. (See comments above.) */
2834 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
2835 This means a type for which function calls must pass an address to the
2836 function or get an address back from the function.
2837 EXP may be a type node or an expression (whose type is tested). */
2840 aggregate_value_p (exp)
2843 int i, regno, nregs;
2846 if (TREE_CODE_CLASS (TREE_CODE (exp)) == 't')
2849 type = TREE_TYPE (exp);
2851 if (RETURN_IN_MEMORY (type))
2853 if (flag_pcc_struct_return
2854 && (TREE_CODE (type) == RECORD_TYPE
2855 || TREE_CODE (type) == UNION_TYPE
2856 || TREE_CODE (type) == QUAL_UNION_TYPE
2857 || TREE_CODE (type) == ARRAY_TYPE))
2859 /* Make sure we have suitable call-clobbered regs to return
2860 the value in; if not, we must return it in memory. */
2861 reg = hard_function_value (type, 0);
2862 regno = REGNO (reg);
2863 nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type));
2864 for (i = 0; i < nregs; i++)
2865 if (! call_used_regs[regno + i])
2870 /* Assign RTL expressions to the function's parameters.
2871 This may involve copying them into registers and using
2872 those registers as the RTL for them.
2874 If SECOND_TIME is non-zero it means that this function is being
2875 called a second time. This is done by integrate.c when a function's
2876 compilation is deferred. We need to come back here in case the
2877 FUNCTION_ARG macro computes items needed for the rest of the compilation
2878 (such as changing which registers are fixed or caller-saved). But suppress
2879 writing any insns or setting DECL_RTL of anything in this case. */
2882 assign_parms (fndecl, second_time)
2887 register rtx entry_parm = 0;
2888 register rtx stack_parm = 0;
2889 CUMULATIVE_ARGS args_so_far;
2890 enum machine_mode promoted_mode, passed_mode, nominal_mode;
2892 /* Total space needed so far for args on the stack,
2893 given as a constant and a tree-expression. */
2894 struct args_size stack_args_size;
2895 tree fntype = TREE_TYPE (fndecl);
2896 tree fnargs = DECL_ARGUMENTS (fndecl);
2897 /* This is used for the arg pointer when referring to stack args. */
2898 rtx internal_arg_pointer;
2899 /* This is a dummy PARM_DECL that we used for the function result if
2900 the function returns a structure. */
2901 tree function_result_decl = 0;
2902 int nparmregs = list_length (fnargs) + LAST_VIRTUAL_REGISTER + 1;
2903 int varargs_setup = 0;
2904 rtx conversion_insns = 0;
2905 /* FUNCTION_ARG may look at this variable. Since this is not
2906 expanding a call it will always be zero in this function. */
2907 int current_call_is_indirect = 0;
2909 /* Nonzero if the last arg is named `__builtin_va_alist',
2910 which is used on some machines for old-fashioned non-ANSI varargs.h;
2911 this should be stuck onto the stack as if it had arrived there. */
2914 && (parm = tree_last (fnargs)) != 0
2916 && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
2917 "__builtin_va_alist")));
2919 /* Nonzero if function takes extra anonymous args.
2920 This means the last named arg must be on the stack
2921 right before the anonymous ones. */
2923 = (TYPE_ARG_TYPES (fntype) != 0
2924 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
2925 != void_type_node));
2927 /* If the reg that the virtual arg pointer will be translated into is
2928 not a fixed reg or is the stack pointer, make a copy of the virtual
2929 arg pointer, and address parms via the copy. The frame pointer is
2930 considered fixed even though it is not marked as such.
2932 The second time through, simply use ap to avoid generating rtx. */
2934 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
2935 || ! (fixed_regs[ARG_POINTER_REGNUM]
2936 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM))
2938 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
2940 internal_arg_pointer = virtual_incoming_args_rtx;
2941 current_function_internal_arg_pointer = internal_arg_pointer;
2943 stack_args_size.constant = 0;
2944 stack_args_size.var = 0;
2946 /* If struct value address is treated as the first argument, make it so. */
2947 if (aggregate_value_p (DECL_RESULT (fndecl))
2948 && ! current_function_returns_pcc_struct
2949 && struct_value_incoming_rtx == 0)
2951 tree type = build_pointer_type (fntype);
2953 function_result_decl = build_decl (PARM_DECL, NULL_TREE, type);
2955 DECL_ARG_TYPE (function_result_decl) = type;
2956 TREE_CHAIN (function_result_decl) = fnargs;
2957 fnargs = function_result_decl;
2960 parm_reg_stack_loc = (rtx *) oballoc (nparmregs * sizeof (rtx));
2961 bzero (parm_reg_stack_loc, nparmregs * sizeof (rtx));
2963 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
2964 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX);
2966 INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX);
2969 /* We haven't yet found an argument that we must push and pretend the
2971 current_function_pretend_args_size = 0;
2973 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
2976 = (TREE_CODE (TREE_TYPE (parm)) == ARRAY_TYPE
2977 || TREE_CODE (TREE_TYPE (parm)) == RECORD_TYPE
2978 || TREE_CODE (TREE_TYPE (parm)) == UNION_TYPE
2979 || TREE_CODE (TREE_TYPE (parm)) == QUAL_UNION_TYPE);
2980 struct args_size stack_offset;
2981 struct args_size arg_size;
2982 int passed_pointer = 0;
2983 tree passed_type = DECL_ARG_TYPE (parm);
2985 /* Set LAST_NAMED if this is last named arg before some
2986 anonymous args. We treat it as if it were anonymous too. */
2987 int last_named = ((TREE_CHAIN (parm) == 0
2988 || DECL_NAME (TREE_CHAIN (parm)) == 0)
2989 && (vararg || stdarg));
2991 if (TREE_TYPE (parm) == error_mark_node
2992 /* This can happen after weird syntax errors
2993 or if an enum type is defined among the parms. */
2994 || TREE_CODE (parm) != PARM_DECL
2995 || passed_type == NULL)
2997 DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = gen_rtx (MEM, BLKmode,
2999 TREE_USED (parm) = 1;
3003 /* For varargs.h function, save info about regs and stack space
3004 used by the individual args, not including the va_alist arg. */
3005 if (vararg && last_named)
3006 current_function_args_info = args_so_far;
3008 /* Find mode of arg as it is passed, and mode of arg
3009 as it should be during execution of this function. */
3010 passed_mode = TYPE_MODE (passed_type);
3011 nominal_mode = TYPE_MODE (TREE_TYPE (parm));
3013 /* If the parm's mode is VOID, its value doesn't matter,
3014 and avoid the usual things like emit_move_insn that could crash. */
3015 if (nominal_mode == VOIDmode)
3017 DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = const0_rtx;
3021 /* See if this arg was passed by invisible reference. It is if
3022 it is an object whose size depends on the contents of the
3023 object itself or if the machine requires these objects be passed
3026 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
3027 && contains_placeholder_p (TYPE_SIZE (passed_type)))
3028 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
3029 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
3030 passed_type, ! last_named)
3034 passed_type = build_pointer_type (passed_type);
3036 passed_mode = nominal_mode = Pmode;
3039 promoted_mode = passed_mode;
3041 #ifdef PROMOTE_FUNCTION_ARGS
3042 /* Compute the mode in which the arg is actually extended to. */
3043 if (TREE_CODE (passed_type) == INTEGER_TYPE
3044 || TREE_CODE (passed_type) == ENUMERAL_TYPE
3045 || TREE_CODE (passed_type) == BOOLEAN_TYPE
3046 || TREE_CODE (passed_type) == CHAR_TYPE
3047 || TREE_CODE (passed_type) == REAL_TYPE
3048 || TREE_CODE (passed_type) == POINTER_TYPE
3049 || TREE_CODE (passed_type) == OFFSET_TYPE)
3051 unsignedp = TREE_UNSIGNED (passed_type);
3052 PROMOTE_MODE (promoted_mode, unsignedp, passed_type);
3056 /* Let machine desc say which reg (if any) the parm arrives in.
3057 0 means it arrives on the stack. */
3058 #ifdef FUNCTION_INCOMING_ARG
3059 entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
3060 passed_type, ! last_named);
3062 entry_parm = FUNCTION_ARG (args_so_far, promoted_mode,
3063 passed_type, ! last_named);
3067 passed_mode = promoted_mode;
3069 #ifdef SETUP_INCOMING_VARARGS
3070 /* If this is the last named parameter, do any required setup for
3071 varargs or stdargs. We need to know about the case of this being an
3072 addressable type, in which case we skip the registers it
3073 would have arrived in.
3075 For stdargs, LAST_NAMED will be set for two parameters, the one that
3076 is actually the last named, and the dummy parameter. We only
3077 want to do this action once.
3079 Also, indicate when RTL generation is to be suppressed. */
3080 if (last_named && !varargs_setup)
3082 SETUP_INCOMING_VARARGS (args_so_far, passed_mode, passed_type,
3083 current_function_pretend_args_size,
3089 /* Determine parm's home in the stack,
3090 in case it arrives in the stack or we should pretend it did.
3092 Compute the stack position and rtx where the argument arrives
3095 There is one complexity here: If this was a parameter that would
3096 have been passed in registers, but wasn't only because it is
3097 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
3098 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
3099 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
3100 0 as it was the previous time. */
3102 locate_and_pad_parm (passed_mode, passed_type,
3103 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3106 #ifdef FUNCTION_INCOMING_ARG
3107 FUNCTION_INCOMING_ARG (args_so_far, passed_mode,
3110 || varargs_setup)) != 0,
3112 FUNCTION_ARG (args_so_far, passed_mode,
3114 ! last_named || varargs_setup) != 0,
3117 fndecl, &stack_args_size, &stack_offset, &arg_size);
3121 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
3123 if (offset_rtx == const0_rtx)
3124 stack_parm = gen_rtx (MEM, passed_mode, internal_arg_pointer);
3126 stack_parm = gen_rtx (MEM, passed_mode,
3127 gen_rtx (PLUS, Pmode,
3128 internal_arg_pointer, offset_rtx));
3130 /* If this is a memory ref that contains aggregate components,
3131 mark it as such for cse and loop optimize. */
3132 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3135 /* If this parameter was passed both in registers and in the stack,
3136 use the copy on the stack. */
3137 if (MUST_PASS_IN_STACK (passed_mode, passed_type))
3140 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3141 /* If this parm was passed part in regs and part in memory,
3142 pretend it arrived entirely in memory
3143 by pushing the register-part onto the stack.
3145 In the special case of a DImode or DFmode that is split,
3146 we could put it together in a pseudoreg directly,
3147 but for now that's not worth bothering with. */
3151 int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, passed_mode,
3152 passed_type, ! last_named);
3156 current_function_pretend_args_size
3157 = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
3158 / (PARM_BOUNDARY / BITS_PER_UNIT)
3159 * (PARM_BOUNDARY / BITS_PER_UNIT));
3162 move_block_from_reg (REGNO (entry_parm),
3163 validize_mem (stack_parm), nregs,
3164 int_size_in_bytes (TREE_TYPE (parm)));
3165 entry_parm = stack_parm;
3170 /* If we didn't decide this parm came in a register,
3171 by default it came on the stack. */
3172 if (entry_parm == 0)
3173 entry_parm = stack_parm;
3175 /* Record permanently how this parm was passed. */
3177 DECL_INCOMING_RTL (parm) = entry_parm;
3179 /* If there is actually space on the stack for this parm,
3180 count it in stack_args_size; otherwise set stack_parm to 0
3181 to indicate there is no preallocated stack slot for the parm. */
3183 if (entry_parm == stack_parm
3184 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
3185 /* On some machines, even if a parm value arrives in a register
3186 there is still an (uninitialized) stack slot allocated for it.
3188 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
3189 whether this parameter already has a stack slot allocated,
3190 because an arg block exists only if current_function_args_size
3191 is larger than some threshhold, and we haven't calculated that
3192 yet. So, for now, we just assume that stack slots never exist
3194 || REG_PARM_STACK_SPACE (fndecl) > 0
3198 stack_args_size.constant += arg_size.constant;
3200 ADD_PARM_SIZE (stack_args_size, arg_size.var);
3203 /* No stack slot was pushed for this parm. */
3206 /* Update info on where next arg arrives in registers. */
3208 FUNCTION_ARG_ADVANCE (args_so_far, passed_mode,
3209 passed_type, ! last_named);
3211 /* If this is our second time through, we are done with this parm. */
3215 /* If we can't trust the parm stack slot to be aligned enough
3216 for its ultimate type, don't use that slot after entry.
3217 We'll make another stack slot, if we need one. */
3219 int thisparm_boundary
3220 = FUNCTION_ARG_BOUNDARY (passed_mode, passed_type);
3222 if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary)
3226 /* If parm was passed in memory, and we need to convert it on entry,
3227 don't store it back in that same slot. */
3229 && nominal_mode != BLKmode && nominal_mode != passed_mode)
3233 /* Now adjust STACK_PARM to the mode and precise location
3234 where this parameter should live during execution,
3235 if we discover that it must live in the stack during execution.
3236 To make debuggers happier on big-endian machines, we store
3237 the value in the last bytes of the space available. */
3239 if (nominal_mode != BLKmode && nominal_mode != passed_mode
3244 #if BYTES_BIG_ENDIAN
3245 if (GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD)
3246 stack_offset.constant += (GET_MODE_SIZE (passed_mode)
3247 - GET_MODE_SIZE (nominal_mode));
3250 offset_rtx = ARGS_SIZE_RTX (stack_offset);
3251 if (offset_rtx == const0_rtx)
3252 stack_parm = gen_rtx (MEM, nominal_mode, internal_arg_pointer);
3254 stack_parm = gen_rtx (MEM, nominal_mode,
3255 gen_rtx (PLUS, Pmode,
3256 internal_arg_pointer, offset_rtx));
3258 /* If this is a memory ref that contains aggregate components,
3259 mark it as such for cse and loop optimize. */
3260 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3264 /* ENTRY_PARM is an RTX for the parameter as it arrives,
3265 in the mode in which it arrives.
3266 STACK_PARM is an RTX for a stack slot where the parameter can live
3267 during the function (in case we want to put it there).
3268 STACK_PARM is 0 if no stack slot was pushed for it.
3270 Now output code if necessary to convert ENTRY_PARM to
3271 the type in which this function declares it,
3272 and store that result in an appropriate place,
3273 which may be a pseudo reg, may be STACK_PARM,
3274 or may be a local stack slot if STACK_PARM is 0.
3276 Set DECL_RTL to that place. */
3278 if (nominal_mode == BLKmode)
3280 /* If a BLKmode arrives in registers, copy it to a stack slot. */
3281 if (GET_CODE (entry_parm) == REG)
3283 int size_stored = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
3286 /* Note that we will be storing an integral number of words.
3287 So we have to be careful to ensure that we allocate an
3288 integral number of words. We do this below in the
3289 assign_stack_local if space was not allocated in the argument
3290 list. If it was, this will not work if PARM_BOUNDARY is not
3291 a multiple of BITS_PER_WORD. It isn't clear how to fix this
3292 if it becomes a problem. */
3294 if (stack_parm == 0)
3297 = assign_stack_local (GET_MODE (entry_parm), size_stored, 0);
3298 /* If this is a memory ref that contains aggregate components,
3299 mark it as such for cse and loop optimize. */
3300 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3303 else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
3306 move_block_from_reg (REGNO (entry_parm),
3307 validize_mem (stack_parm),
3308 size_stored / UNITS_PER_WORD,
3309 int_size_in_bytes (TREE_TYPE (parm)));
3311 DECL_RTL (parm) = stack_parm;
3313 else if (! ((obey_regdecls && ! DECL_REGISTER (parm)
3314 && ! DECL_INLINE (fndecl))
3315 /* layout_decl may set this. */
3316 || TREE_ADDRESSABLE (parm)
3317 || TREE_SIDE_EFFECTS (parm)
3318 /* If -ffloat-store specified, don't put explicit
3319 float variables into registers. */
3320 || (flag_float_store
3321 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
3322 /* Always assign pseudo to structure return or item passed
3323 by invisible reference. */
3324 || passed_pointer || parm == function_result_decl)
3326 /* Store the parm in a pseudoregister during the function, but we
3327 may need to do it in a wider mode. */
3329 register rtx parmreg;
3331 unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
3332 if (TREE_CODE (TREE_TYPE (parm)) == INTEGER_TYPE
3333 || TREE_CODE (TREE_TYPE (parm)) == ENUMERAL_TYPE
3334 || TREE_CODE (TREE_TYPE (parm)) == BOOLEAN_TYPE
3335 || TREE_CODE (TREE_TYPE (parm)) == CHAR_TYPE
3336 || TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE
3337 || TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE
3338 || TREE_CODE (TREE_TYPE (parm)) == OFFSET_TYPE)
3340 PROMOTE_MODE (nominal_mode, unsignedp, TREE_TYPE (parm));
3343 parmreg = gen_reg_rtx (nominal_mode);
3344 REG_USERVAR_P (parmreg) = 1;
3346 /* If this was an item that we received a pointer to, set DECL_RTL
3350 DECL_RTL (parm) = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (passed_type)), parmreg);
3351 MEM_IN_STRUCT_P (DECL_RTL (parm)) = aggregate;
3354 DECL_RTL (parm) = parmreg;
3356 /* Copy the value into the register. */
3357 if (GET_MODE (parmreg) != GET_MODE (entry_parm))
3359 /* If ENTRY_PARM is a hard register, it might be in a register
3360 not valid for operating in its mode (e.g., an odd-numbered
3361 register for a DFmode). In that case, moves are the only
3362 thing valid, so we can't do a convert from there. This
3363 occurs when the calling sequence allow such misaligned
3366 In addition, the conversion may involve a call, which could
3367 clobber parameters which haven't been copied to pseudo
3368 registers yet. Therefore, we must first copy the parm to
3369 a pseudo reg here, and save the conversion until after all
3370 parameters have been moved. */
3372 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
3374 emit_move_insn (tempreg, validize_mem (entry_parm));
3376 push_to_sequence (conversion_insns);
3377 convert_move (parmreg, tempreg, unsignedp);
3378 conversion_insns = get_insns ();
3382 emit_move_insn (parmreg, validize_mem (entry_parm));
3384 /* If we were passed a pointer but the actual value
3385 can safely live in a register, put it in one. */
3386 if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
3387 && ! ((obey_regdecls && ! DECL_REGISTER (parm)
3388 && ! DECL_INLINE (fndecl))
3389 /* layout_decl may set this. */
3390 || TREE_ADDRESSABLE (parm)
3391 || TREE_SIDE_EFFECTS (parm)
3392 /* If -ffloat-store specified, don't put explicit
3393 float variables into registers. */
3394 || (flag_float_store
3395 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))
3397 /* We can't use nominal_mode, because it will have been set to
3398 Pmode above. We must use the actual mode of the parm. */
3399 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
3400 emit_move_insn (parmreg, DECL_RTL (parm));
3401 DECL_RTL (parm) = parmreg;
3403 #ifdef FUNCTION_ARG_CALLEE_COPIES
3404 /* If we are passed an arg by reference and it is our responsibility
3405 to make a copy, do it now.
3406 PASSED_TYPE and PASSED mode now refer to the pointer, not the
3407 original argument, so we must recreate them in the call to
3408 FUNCTION_ARG_CALLEE_COPIES. */
3409 /* ??? Later add code to handle the case that if the argument isn't
3410 modified, don't do the copy. */
3412 else if (passed_pointer
3413 && FUNCTION_ARG_CALLEE_COPIES (args_so_far,
3414 TYPE_MODE (DECL_ARG_TYPE (parm)),
3415 DECL_ARG_TYPE (parm),
3419 tree type = DECL_ARG_TYPE (parm);
3421 /* This sequence may involve a library call perhaps clobbering
3422 registers that haven't been copied to pseudos yet. */
3424 push_to_sequence (conversion_insns);
3426 if (TYPE_SIZE (type) == 0
3427 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
3429 /* This is a variable sized object. */
3430 /* ??? Can we use expr_size here? */
3431 rtx size_rtx = expand_expr (size_in_bytes (type), NULL_RTX,
3432 TYPE_MODE (sizetype), 0);
3434 copy = gen_rtx (MEM, BLKmode,
3435 allocate_dynamic_stack_space (size_rtx, NULL_RTX,
3436 TYPE_ALIGN (type)));
3440 int size = int_size_in_bytes (type);
3441 copy = assign_stack_temp (TYPE_MODE (type), size, 1);
3444 store_expr (parm, copy, 0);
3445 emit_move_insn (parmreg, XEXP (copy, 0));
3446 conversion_insns = get_insns ();
3449 #endif /* FUNCTION_ARG_CALLEE_COPIES */
3451 /* In any case, record the parm's desired stack location
3452 in case we later discover it must live in the stack. */
3453 if (REGNO (parmreg) >= nparmregs)
3456 int old_nparmregs = nparmregs;
3457 nparmregs = REGNO (parmreg) + 5;
3458 new = (rtx *) oballoc (nparmregs * sizeof (rtx));
3459 bcopy (parm_reg_stack_loc, new, old_nparmregs * sizeof (rtx));
3460 bzero (new + old_nparmregs, (nparmregs - old_nparmregs) * sizeof (rtx));
3461 parm_reg_stack_loc = new;
3463 parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
3465 /* Mark the register as eliminable if we did no conversion
3466 and it was copied from memory at a fixed offset,
3467 and the arg pointer was not copied to a pseudo-reg.
3468 If the arg pointer is a pseudo reg or the offset formed
3469 an invalid address, such memory-equivalences
3470 as we make here would screw up life analysis for it. */
3471 if (nominal_mode == passed_mode
3472 && GET_CODE (entry_parm) == MEM
3473 && entry_parm == stack_parm
3474 && stack_offset.var == 0
3475 && reg_mentioned_p (virtual_incoming_args_rtx,
3476 XEXP (entry_parm, 0)))
3477 REG_NOTES (get_last_insn ())
3478 = gen_rtx (EXPR_LIST, REG_EQUIV,
3479 entry_parm, REG_NOTES (get_last_insn ()));
3481 /* For pointer data type, suggest pointer register. */
3482 if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE)
3483 mark_reg_pointer (parmreg);
3487 /* Value must be stored in the stack slot STACK_PARM
3488 during function execution. */
3490 if (passed_mode != nominal_mode)
3492 /* Conversion is required. */
3493 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
3495 emit_move_insn (tempreg, validize_mem (entry_parm));
3497 push_to_sequence (conversion_insns);
3498 entry_parm = convert_to_mode (nominal_mode, tempreg,
3499 TREE_UNSIGNED (TREE_TYPE (parm)));
3500 conversion_insns = get_insns ();
3504 if (entry_parm != stack_parm)
3506 if (stack_parm == 0)
3509 = assign_stack_local (GET_MODE (entry_parm),
3510 GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
3511 /* If this is a memory ref that contains aggregate components,
3512 mark it as such for cse and loop optimize. */
3513 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3516 if (passed_mode != nominal_mode)
3518 push_to_sequence (conversion_insns);
3519 emit_move_insn (validize_mem (stack_parm),
3520 validize_mem (entry_parm));
3521 conversion_insns = get_insns ();
3525 emit_move_insn (validize_mem (stack_parm),
3526 validize_mem (entry_parm));
3529 DECL_RTL (parm) = stack_parm;
3532 /* If this "parameter" was the place where we are receiving the
3533 function's incoming structure pointer, set up the result. */
3534 if (parm == function_result_decl)
3535 DECL_RTL (DECL_RESULT (fndecl))
3536 = gen_rtx (MEM, DECL_MODE (DECL_RESULT (fndecl)), DECL_RTL (parm));
3538 if (TREE_THIS_VOLATILE (parm))
3539 MEM_VOLATILE_P (DECL_RTL (parm)) = 1;
3540 if (TREE_READONLY (parm))
3541 RTX_UNCHANGING_P (DECL_RTL (parm)) = 1;
3544 /* Output all parameter conversion instructions (possibly including calls)
3545 now that all parameters have been copied out of hard registers. */
3546 emit_insns (conversion_insns);
3548 max_parm_reg = max_reg_num ();
3549 last_parm_insn = get_last_insn ();
3551 current_function_args_size = stack_args_size.constant;
3553 /* Adjust function incoming argument size for alignment and
3556 #ifdef REG_PARM_STACK_SPACE
3557 #ifndef MAYBE_REG_PARM_STACK_SPACE
3558 current_function_args_size = MAX (current_function_args_size,
3559 REG_PARM_STACK_SPACE (fndecl));
3563 #ifdef STACK_BOUNDARY
3564 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
3566 current_function_args_size
3567 = ((current_function_args_size + STACK_BYTES - 1)
3568 / STACK_BYTES) * STACK_BYTES;
3571 #ifdef ARGS_GROW_DOWNWARD
3572 current_function_arg_offset_rtx
3573 = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
3574 : expand_expr (size_binop (MINUS_EXPR, stack_args_size.var,
3575 size_int (-stack_args_size.constant)),
3576 NULL_RTX, VOIDmode, 0));
3578 current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
3581 /* See how many bytes, if any, of its args a function should try to pop
3584 current_function_pops_args = RETURN_POPS_ARGS (TREE_TYPE (fndecl),
3585 current_function_args_size);
3587 /* For stdarg.h function, save info about regs and stack space
3588 used by the named args. */
3591 current_function_args_info = args_so_far;
3593 /* Set the rtx used for the function return value. Put this in its
3594 own variable so any optimizers that need this information don't have
3595 to include tree.h. Do this here so it gets done when an inlined
3596 function gets output. */
3598 current_function_return_rtx = DECL_RTL (DECL_RESULT (fndecl));
3601 /* Indicate whether REGNO is an incoming argument to the current function
3602 that was promoted to a wider mode. If so, return the RTX for the
3603 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
3604 that REGNO is promoted from and whether the promotion was signed or
3607 #ifdef PROMOTE_FUNCTION_ARGS
3610 promoted_input_arg (regno, pmode, punsignedp)
3612 enum machine_mode *pmode;
3617 for (arg = DECL_ARGUMENTS (current_function_decl); arg;
3618 arg = TREE_CHAIN (arg))
3619 if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
3620 && REGNO (DECL_INCOMING_RTL (arg)) == regno
3621 && (TREE_CODE (TREE_TYPE (arg)) == INTEGER_TYPE
3622 || TREE_CODE (TREE_TYPE (arg)) == ENUMERAL_TYPE
3623 || TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE
3624 || TREE_CODE (TREE_TYPE (arg)) == CHAR_TYPE
3625 || TREE_CODE (TREE_TYPE (arg)) == REAL_TYPE
3626 || TREE_CODE (TREE_TYPE (arg)) == POINTER_TYPE
3627 || TREE_CODE (TREE_TYPE (arg)) == OFFSET_TYPE))
3629 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
3630 int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
3632 PROMOTE_MODE (mode, unsignedp, TREE_TYPE (arg));
3633 if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
3634 && mode != DECL_MODE (arg))
3636 *pmode = DECL_MODE (arg);
3637 *punsignedp = unsignedp;
3638 return DECL_INCOMING_RTL (arg);
3647 /* Compute the size and offset from the start of the stacked arguments for a
3648 parm passed in mode PASSED_MODE and with type TYPE.
3650 INITIAL_OFFSET_PTR points to the current offset into the stacked
3653 The starting offset and size for this parm are returned in *OFFSET_PTR
3654 and *ARG_SIZE_PTR, respectively.
3656 IN_REGS is non-zero if the argument will be passed in registers. It will
3657 never be set if REG_PARM_STACK_SPACE is not defined.
3659 FNDECL is the function in which the argument was defined.
3661 There are two types of rounding that are done. The first, controlled by
3662 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
3663 list to be aligned to the specific boundary (in bits). This rounding
3664 affects the initial and starting offsets, but not the argument size.
3666 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
3667 optionally rounds the size of the parm to PARM_BOUNDARY. The
3668 initial offset is not affected by this rounding, while the size always
3669 is and the starting offset may be. */
3671 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
3672 initial_offset_ptr is positive because locate_and_pad_parm's
3673 callers pass in the total size of args so far as
3674 initial_offset_ptr. arg_size_ptr is always positive.*/
3676 static void pad_to_arg_alignment (), pad_below ();
3679 locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
3680 initial_offset_ptr, offset_ptr, arg_size_ptr)
3681 enum machine_mode passed_mode;
3685 struct args_size *initial_offset_ptr;
3686 struct args_size *offset_ptr;
3687 struct args_size *arg_size_ptr;
3690 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
3691 enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
3692 int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
3693 int boundary_in_bytes = boundary / BITS_PER_UNIT;
3694 int reg_parm_stack_space = 0;
3696 #ifdef REG_PARM_STACK_SPACE
3697 /* If we have found a stack parm before we reach the end of the
3698 area reserved for registers, skip that area. */
3701 #ifdef MAYBE_REG_PARM_STACK_SPACE
3702 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
3704 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
3706 if (reg_parm_stack_space > 0)
3708 if (initial_offset_ptr->var)
3710 initial_offset_ptr->var
3711 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
3712 size_int (reg_parm_stack_space));
3713 initial_offset_ptr->constant = 0;
3715 else if (initial_offset_ptr->constant < reg_parm_stack_space)
3716 initial_offset_ptr->constant = reg_parm_stack_space;
3719 #endif /* REG_PARM_STACK_SPACE */
3721 arg_size_ptr->var = 0;
3722 arg_size_ptr->constant = 0;
3724 #ifdef ARGS_GROW_DOWNWARD
3725 if (initial_offset_ptr->var)
3727 offset_ptr->constant = 0;
3728 offset_ptr->var = size_binop (MINUS_EXPR, integer_zero_node,
3729 initial_offset_ptr->var);
3733 offset_ptr->constant = - initial_offset_ptr->constant;
3734 offset_ptr->var = 0;
3736 if (where_pad == upward
3737 && (TREE_CODE (sizetree) != INTEGER_CST
3738 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
3739 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
3740 SUB_PARM_SIZE (*offset_ptr, sizetree);
3741 if (where_pad != downward)
3742 pad_to_arg_alignment (offset_ptr, boundary);
3743 if (initial_offset_ptr->var)
3745 arg_size_ptr->var = size_binop (MINUS_EXPR,
3746 size_binop (MINUS_EXPR,
3748 initial_offset_ptr->var),
3753 arg_size_ptr->constant = (- initial_offset_ptr->constant -
3754 offset_ptr->constant);
3756 /* ADD_PARM_SIZE (*arg_size_ptr, sizetree); */
3757 if (where_pad == downward)
3758 pad_below (arg_size_ptr, passed_mode, sizetree);
3759 #else /* !ARGS_GROW_DOWNWARD */
3760 pad_to_arg_alignment (initial_offset_ptr, boundary);
3761 *offset_ptr = *initial_offset_ptr;
3763 #ifdef PUSH_ROUNDING
3764 if (passed_mode != BLKmode)
3765 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
3768 if (where_pad != none
3769 && (TREE_CODE (sizetree) != INTEGER_CST
3770 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
3771 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
3773 /* This must be done after rounding sizetree, so that it will subtract
3774 the same value that we explicitly add below. */
3775 if (where_pad == downward)
3776 pad_below (offset_ptr, passed_mode, sizetree);
3777 ADD_PARM_SIZE (*arg_size_ptr, sizetree);
3778 #endif /* ARGS_GROW_DOWNWARD */
3781 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
3782 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
3785 pad_to_arg_alignment (offset_ptr, boundary)
3786 struct args_size *offset_ptr;
3789 int boundary_in_bytes = boundary / BITS_PER_UNIT;
3791 if (boundary > BITS_PER_UNIT)
3793 if (offset_ptr->var)
3796 #ifdef ARGS_GROW_DOWNWARD
3801 (ARGS_SIZE_TREE (*offset_ptr),
3802 boundary / BITS_PER_UNIT);
3803 offset_ptr->constant = 0; /*?*/
3806 offset_ptr->constant =
3807 #ifdef ARGS_GROW_DOWNWARD
3808 FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes);
3810 CEIL_ROUND (offset_ptr->constant, boundary_in_bytes);
3816 pad_below (offset_ptr, passed_mode, sizetree)
3817 struct args_size *offset_ptr;
3818 enum machine_mode passed_mode;
3821 if (passed_mode != BLKmode)
3823 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
3824 offset_ptr->constant
3825 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
3826 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
3827 - GET_MODE_SIZE (passed_mode));
3831 if (TREE_CODE (sizetree) != INTEGER_CST
3832 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
3834 /* Round the size up to multiple of PARM_BOUNDARY bits. */
3835 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
3837 ADD_PARM_SIZE (*offset_ptr, s2);
3838 SUB_PARM_SIZE (*offset_ptr, sizetree);
3844 round_down (value, divisor)
3848 return size_binop (MULT_EXPR,
3849 size_binop (FLOOR_DIV_EXPR, value, size_int (divisor)),
3850 size_int (divisor));
3853 /* Walk the tree of blocks describing the binding levels within a function
3854 and warn about uninitialized variables.
3855 This is done after calling flow_analysis and before global_alloc
3856 clobbers the pseudo-regs to hard regs. */
3859 uninitialized_vars_warning (block)
3862 register tree decl, sub;
3863 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
3865 if (TREE_CODE (decl) == VAR_DECL
3866 /* These warnings are unreliable for and aggregates
3867 because assigning the fields one by one can fail to convince
3868 flow.c that the entire aggregate was initialized.
3869 Unions are troublesome because members may be shorter. */
3870 && TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE
3871 && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE
3872 && TREE_CODE (TREE_TYPE (decl)) != QUAL_UNION_TYPE
3873 && TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE
3874 && DECL_RTL (decl) != 0
3875 && GET_CODE (DECL_RTL (decl)) == REG
3876 && regno_uninitialized (REGNO (DECL_RTL (decl))))
3877 warning_with_decl (decl,
3878 "`%s' may be used uninitialized in this function");
3879 if (TREE_CODE (decl) == VAR_DECL
3880 && DECL_RTL (decl) != 0
3881 && GET_CODE (DECL_RTL (decl)) == REG
3882 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
3883 warning_with_decl (decl,
3884 "variable `%s' may be clobbered by `longjmp' or `vfork'");
3886 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
3887 uninitialized_vars_warning (sub);
3890 /* Do the appropriate part of uninitialized_vars_warning
3891 but for arguments instead of local variables. */
3894 setjmp_args_warning (block)
3898 for (decl = DECL_ARGUMENTS (current_function_decl);
3899 decl; decl = TREE_CHAIN (decl))
3900 if (DECL_RTL (decl) != 0
3901 && GET_CODE (DECL_RTL (decl)) == REG
3902 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
3903 warning_with_decl (decl, "argument `%s' may be clobbered by `longjmp' or `vfork'");
3906 /* If this function call setjmp, put all vars into the stack
3907 unless they were declared `register'. */
3910 setjmp_protect (block)
3913 register tree decl, sub;
3914 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
3915 if ((TREE_CODE (decl) == VAR_DECL
3916 || TREE_CODE (decl) == PARM_DECL)
3917 && DECL_RTL (decl) != 0
3918 && GET_CODE (DECL_RTL (decl)) == REG
3919 /* If this variable came from an inline function, it must be
3920 that it's life doesn't overlap the setjmp. If there was a
3921 setjmp in the function, it would already be in memory. We
3922 must exclude such variable because their DECL_RTL might be
3923 set to strange things such as virtual_stack_vars_rtx. */
3924 && ! DECL_FROM_INLINE (decl)
3926 #ifdef NON_SAVING_SETJMP
3927 /* If longjmp doesn't restore the registers,
3928 don't put anything in them. */
3932 ! DECL_REGISTER (decl)))
3933 put_var_into_stack (decl);
3934 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
3935 setjmp_protect (sub);
3938 /* Like the previous function, but for args instead of local variables. */
3941 setjmp_protect_args ()
3943 register tree decl, sub;
3944 for (decl = DECL_ARGUMENTS (current_function_decl);
3945 decl; decl = TREE_CHAIN (decl))
3946 if ((TREE_CODE (decl) == VAR_DECL
3947 || TREE_CODE (decl) == PARM_DECL)
3948 && DECL_RTL (decl) != 0
3949 && GET_CODE (DECL_RTL (decl)) == REG
3951 /* If longjmp doesn't restore the registers,
3952 don't put anything in them. */
3953 #ifdef NON_SAVING_SETJMP
3957 ! DECL_REGISTER (decl)))
3958 put_var_into_stack (decl);
3961 /* Return the context-pointer register corresponding to DECL,
3962 or 0 if it does not need one. */
3965 lookup_static_chain (decl)
3968 tree context = decl_function_context (decl);
3974 /* We treat inline_function_decl as an alias for the current function
3975 because that is the inline function whose vars, types, etc.
3976 are being merged into the current function.
3977 See expand_inline_function. */
3978 if (context == current_function_decl || context == inline_function_decl)
3979 return virtual_stack_vars_rtx;
3981 for (link = context_display; link; link = TREE_CHAIN (link))
3982 if (TREE_PURPOSE (link) == context)
3983 return RTL_EXPR_RTL (TREE_VALUE (link));
3988 /* Convert a stack slot address ADDR for variable VAR
3989 (from a containing function)
3990 into an address valid in this function (using a static chain). */
3993 fix_lexical_addr (addr, var)
3999 tree context = decl_function_context (var);
4000 struct function *fp;
4003 /* If this is the present function, we need not do anything. */
4004 if (context == current_function_decl || context == inline_function_decl)
4007 for (fp = outer_function_chain; fp; fp = fp->next)
4008 if (fp->decl == context)
4014 /* Decode given address as base reg plus displacement. */
4015 if (GET_CODE (addr) == REG)
4016 basereg = addr, displacement = 0;
4017 else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
4018 basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
4022 /* We accept vars reached via the containing function's
4023 incoming arg pointer and via its stack variables pointer. */
4024 if (basereg == fp->internal_arg_pointer)
4026 /* If reached via arg pointer, get the arg pointer value
4027 out of that function's stack frame.
4029 There are two cases: If a separate ap is needed, allocate a
4030 slot in the outer function for it and dereference it that way.
4031 This is correct even if the real ap is actually a pseudo.
4032 Otherwise, just adjust the offset from the frame pointer to
4035 #ifdef NEED_SEPARATE_AP
4038 if (fp->arg_pointer_save_area == 0)
4039 fp->arg_pointer_save_area
4040 = assign_outer_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0, fp);
4042 addr = fix_lexical_addr (XEXP (fp->arg_pointer_save_area, 0), var);
4043 addr = memory_address (Pmode, addr);
4045 base = copy_to_reg (gen_rtx (MEM, Pmode, addr));
4047 displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
4048 base = lookup_static_chain (var);
4052 else if (basereg == virtual_stack_vars_rtx)
4054 /* This is the same code as lookup_static_chain, duplicated here to
4055 avoid an extra call to decl_function_context. */
4058 for (link = context_display; link; link = TREE_CHAIN (link))
4059 if (TREE_PURPOSE (link) == context)
4061 base = RTL_EXPR_RTL (TREE_VALUE (link));
4069 /* Use same offset, relative to appropriate static chain or argument
4071 return plus_constant (base, displacement);
4074 /* Return the address of the trampoline for entering nested fn FUNCTION.
4075 If necessary, allocate a trampoline (in the stack frame)
4076 and emit rtl to initialize its contents (at entry to this function). */
4079 trampoline_address (function)
4085 struct function *fp;
4088 /* Find an existing trampoline and return it. */
4089 for (link = trampoline_list; link; link = TREE_CHAIN (link))
4090 if (TREE_PURPOSE (link) == function)
4091 return XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0);
4092 for (fp = outer_function_chain; fp; fp = fp->next)
4093 for (link = fp->trampoline_list; link; link = TREE_CHAIN (link))
4094 if (TREE_PURPOSE (link) == function)
4096 tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
4098 return round_trampoline_addr (tramp);
4101 /* None exists; we must make one. */
4103 /* Find the `struct function' for the function containing FUNCTION. */
4105 fn_context = decl_function_context (function);
4106 if (fn_context != current_function_decl)
4107 for (fp = outer_function_chain; fp; fp = fp->next)
4108 if (fp->decl == fn_context)
4111 /* Allocate run-time space for this trampoline
4112 (usually in the defining function's stack frame). */
4113 #ifdef ALLOCATE_TRAMPOLINE
4114 tramp = ALLOCATE_TRAMPOLINE (fp);
4116 /* If rounding needed, allocate extra space
4117 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
4118 #ifdef TRAMPOLINE_ALIGNMENT
4119 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE + TRAMPOLINE_ALIGNMENT - 1)
4121 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
4124 tramp = assign_outer_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0, fp);
4126 tramp = assign_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0);
4129 /* Record the trampoline for reuse and note it for later initialization
4130 by expand_function_end. */
4133 push_obstacks (fp->current_obstack, fp->function_maybepermanent_obstack);
4134 rtlexp = make_node (RTL_EXPR);
4135 RTL_EXPR_RTL (rtlexp) = tramp;
4136 fp->trampoline_list = tree_cons (function, rtlexp, fp->trampoline_list);
4141 /* Make the RTL_EXPR node temporary, not momentary, so that the
4142 trampoline_list doesn't become garbage. */
4143 int momentary = suspend_momentary ();
4144 rtlexp = make_node (RTL_EXPR);
4145 resume_momentary (momentary);
4147 RTL_EXPR_RTL (rtlexp) = tramp;
4148 trampoline_list = tree_cons (function, rtlexp, trampoline_list);
4151 tramp = fix_lexical_addr (XEXP (tramp, 0), function);
4152 return round_trampoline_addr (tramp);
4155 /* Given a trampoline address,
4156 round it to multiple of TRAMPOLINE_ALIGNMENT. */
4159 round_trampoline_addr (tramp)
4162 #ifdef TRAMPOLINE_ALIGNMENT
4163 /* Round address up to desired boundary. */
4164 rtx temp = gen_reg_rtx (Pmode);
4165 temp = expand_binop (Pmode, add_optab, tramp,
4166 GEN_INT (TRAMPOLINE_ALIGNMENT - 1),
4167 temp, 0, OPTAB_LIB_WIDEN);
4168 tramp = expand_binop (Pmode, and_optab, temp,
4169 GEN_INT (- TRAMPOLINE_ALIGNMENT),
4170 temp, 0, OPTAB_LIB_WIDEN);
4175 /* The functions identify_blocks and reorder_blocks provide a way to
4176 reorder the tree of BLOCK nodes, for optimizers that reshuffle or
4177 duplicate portions of the RTL code. Call identify_blocks before
4178 changing the RTL, and call reorder_blocks after. */
4180 static int all_blocks ();
4181 static tree blocks_nreverse ();
4183 /* Put all this function's BLOCK nodes into a vector, and return it.
4184 Also store in each NOTE for the beginning or end of a block
4185 the index of that block in the vector.
4186 The arguments are TOP_BLOCK, the top-level block of the function,
4187 and INSNS, the insn chain of the function. */
4190 identify_blocks (top_block, insns)
4198 int next_block_number = 0;
4199 int current_block_number = 0;
4205 n_blocks = all_blocks (top_block, 0);
4206 block_vector = (tree *) xmalloc (n_blocks * sizeof (tree));
4207 block_stack = (int *) alloca (n_blocks * sizeof (int));
4209 all_blocks (top_block, block_vector);
4211 for (insn = insns; insn; insn = NEXT_INSN (insn))
4212 if (GET_CODE (insn) == NOTE)
4214 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
4216 block_stack[depth++] = current_block_number;
4217 current_block_number = next_block_number;
4218 NOTE_BLOCK_NUMBER (insn) = next_block_number++;
4220 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
4222 current_block_number = block_stack[--depth];
4223 NOTE_BLOCK_NUMBER (insn) = current_block_number;
4227 return block_vector;
4230 /* Given BLOCK_VECTOR which was returned by identify_blocks,
4231 and a revised instruction chain, rebuild the tree structure
4232 of BLOCK nodes to correspond to the new order of RTL.
4233 The new block tree is inserted below TOP_BLOCK.
4234 Returns the current top-level block. */
4237 reorder_blocks (block_vector, top_block, insns)
4242 tree current_block = top_block;
4245 if (block_vector == 0)
4248 /* Prune the old tree away, so that it doesn't get in the way. */
4249 BLOCK_SUBBLOCKS (current_block) = 0;
4251 for (insn = insns; insn; insn = NEXT_INSN (insn))
4252 if (GET_CODE (insn) == NOTE)
4254 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
4256 tree block = block_vector[NOTE_BLOCK_NUMBER (insn)];
4257 /* If we have seen this block before, copy it. */
4258 if (TREE_ASM_WRITTEN (block))
4259 block = copy_node (block);
4260 BLOCK_SUBBLOCKS (block) = 0;
4261 TREE_ASM_WRITTEN (block) = 1;
4262 BLOCK_SUPERCONTEXT (block) = current_block;
4263 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
4264 BLOCK_SUBBLOCKS (current_block) = block;
4265 current_block = block;
4266 NOTE_SOURCE_FILE (insn) = 0;
4268 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
4270 BLOCK_SUBBLOCKS (current_block)
4271 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
4272 current_block = BLOCK_SUPERCONTEXT (current_block);
4273 NOTE_SOURCE_FILE (insn) = 0;
4277 return current_block;
4280 /* Reverse the order of elements in the chain T of blocks,
4281 and return the new head of the chain (old last element). */
4287 register tree prev = 0, decl, next;
4288 for (decl = t; decl; decl = next)
4290 next = BLOCK_CHAIN (decl);
4291 BLOCK_CHAIN (decl) = prev;
4297 /* Count the subblocks of BLOCK, and list them all into the vector VECTOR.
4298 Also clear TREE_ASM_WRITTEN in all blocks. */
4301 all_blocks (block, vector)
4308 TREE_ASM_WRITTEN (block) = 0;
4309 /* Record this block. */
4313 /* Record the subblocks, and their subblocks. */
4314 for (subblocks = BLOCK_SUBBLOCKS (block);
4315 subblocks; subblocks = BLOCK_CHAIN (subblocks))
4316 n_blocks += all_blocks (subblocks, vector ? vector + n_blocks : 0);
4321 /* Build bytecode call descriptor for function SUBR. */
4323 bc_build_calldesc (subr)
4326 tree calldesc = 0, arg;
4329 /* Build the argument description vector in reverse order. */
4330 DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
4333 for (arg = DECL_ARGUMENTS (subr); arg; arg = TREE_CHAIN (arg))
4337 calldesc = tree_cons ((tree) 0, size_in_bytes (TREE_TYPE (arg)), calldesc);
4338 calldesc = tree_cons ((tree) 0, bc_runtime_type_code (TREE_TYPE (arg)), calldesc);
4341 DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
4343 /* Prepend the function's return type. */
4344 calldesc = tree_cons ((tree) 0,
4345 size_in_bytes (TREE_TYPE (TREE_TYPE (subr))),
4348 calldesc = tree_cons ((tree) 0,
4349 bc_runtime_type_code (TREE_TYPE (TREE_TYPE (subr))),
4352 /* Prepend the arg count. */
4353 calldesc = tree_cons ((tree) 0, build_int_2 (nargs, 0), calldesc);
4355 /* Output the call description vector and get its address. */
4356 calldesc = build_nt (CONSTRUCTOR, (tree) 0, calldesc);
4357 TREE_TYPE (calldesc) = build_array_type (integer_type_node,
4358 build_index_type (build_int_2 (nargs * 2, 0)));
4360 return output_constant_def (calldesc);
4364 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
4365 and initialize static variables for generating RTL for the statements
4369 init_function_start (subr, filename, line)
4376 if (output_bytecode)
4378 this_function_decl = subr;
4379 this_function_calldesc = bc_build_calldesc (subr);
4380 local_vars_size = 0;
4382 max_stack_depth = 0;
4383 stmt_expr_depth = 0;
4387 init_stmt_for_function ();
4389 cse_not_expected = ! optimize;
4391 /* Caller save not needed yet. */
4392 caller_save_needed = 0;
4394 /* No stack slots have been made yet. */
4395 stack_slot_list = 0;
4397 /* There is no stack slot for handling nonlocal gotos. */
4398 nonlocal_goto_handler_slot = 0;
4399 nonlocal_goto_stack_level = 0;
4401 /* No labels have been declared for nonlocal use. */
4402 nonlocal_labels = 0;
4404 /* No function calls so far in this function. */
4405 function_call_count = 0;
4407 /* No parm regs have been allocated.
4408 (This is important for output_inline_function.) */
4409 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
4411 /* Initialize the RTL mechanism. */
4414 /* Initialize the queue of pending postincrement and postdecrements,
4415 and some other info in expr.c. */
4418 /* We haven't done register allocation yet. */
4421 init_const_rtx_hash_table ();
4423 current_function_name = (*decl_printable_name) (subr, &junk);
4425 /* Nonzero if this is a nested function that uses a static chain. */
4427 current_function_needs_context
4428 = (decl_function_context (current_function_decl) != 0);
4430 /* Set if a call to setjmp is seen. */
4431 current_function_calls_setjmp = 0;
4433 /* Set if a call to longjmp is seen. */
4434 current_function_calls_longjmp = 0;
4436 current_function_calls_alloca = 0;
4437 current_function_has_nonlocal_label = 0;
4438 current_function_has_nonlocal_goto = 0;
4439 current_function_contains_functions = 0;
4441 current_function_returns_pcc_struct = 0;
4442 current_function_returns_struct = 0;
4443 current_function_epilogue_delay_list = 0;
4444 current_function_uses_const_pool = 0;
4445 current_function_uses_pic_offset_table = 0;
4447 /* We have not yet needed to make a label to jump to for tail-recursion. */
4448 tail_recursion_label = 0;
4450 /* We haven't had a need to make a save area for ap yet. */
4452 arg_pointer_save_area = 0;
4454 /* No stack slots allocated yet. */
4457 /* No SAVE_EXPRs in this function yet. */
4460 /* No RTL_EXPRs in this function yet. */
4463 /* We have not allocated any temporaries yet. */
4465 temp_slot_level = 0;
4467 /* Within function body, compute a type's size as soon it is laid out. */
4468 immediate_size_expand++;
4470 /* We haven't made any trampolines for this function yet. */
4471 trampoline_list = 0;
4473 init_pending_stack_adjust ();
4474 inhibit_defer_pop = 0;
4476 current_function_outgoing_args_size = 0;
4478 /* Initialize the insn lengths. */
4479 init_insn_lengths ();
4481 /* Prevent ever trying to delete the first instruction of a function.
4482 Also tell final how to output a linenum before the function prologue. */
4483 emit_line_note (filename, line);
4485 /* Make sure first insn is a note even if we don't want linenums.
4486 This makes sure the first insn will never be deleted.
4487 Also, final expects a note to appear there. */
4488 emit_note (NULL_PTR, NOTE_INSN_DELETED);
4490 /* Set flags used by final.c. */
4491 if (aggregate_value_p (DECL_RESULT (subr)))
4493 #ifdef PCC_STATIC_STRUCT_RETURN
4494 current_function_returns_pcc_struct = 1;
4496 current_function_returns_struct = 1;
4499 /* Warn if this value is an aggregate type,
4500 regardless of which calling convention we are using for it. */
4501 if (warn_aggregate_return
4502 && (TREE_CODE (TREE_TYPE (DECL_RESULT (subr))) == RECORD_TYPE
4503 || TREE_CODE (TREE_TYPE (DECL_RESULT (subr))) == UNION_TYPE
4504 || TREE_CODE (TREE_TYPE (DECL_RESULT (subr))) == QUAL_UNION_TYPE
4505 || TREE_CODE (TREE_TYPE (DECL_RESULT (subr))) == ARRAY_TYPE))
4506 warning ("function returns an aggregate");
4508 current_function_returns_pointer
4509 = (TREE_CODE (TREE_TYPE (DECL_RESULT (subr))) == POINTER_TYPE);
4511 /* Indicate that we need to distinguish between the return value of the
4512 present function and the return value of a function being called. */
4513 rtx_equal_function_value_matters = 1;
4515 /* Indicate that we have not instantiated virtual registers yet. */
4516 virtuals_instantiated = 0;
4518 /* Indicate we have no need of a frame pointer yet. */
4519 frame_pointer_needed = 0;
4521 /* By default assume not varargs. */
4522 current_function_varargs = 0;
4525 /* Indicate that the current function uses extra args
4526 not explicitly mentioned in the argument list in any fashion. */
4531 current_function_varargs = 1;
4534 /* Expand a call to __main at the beginning of a possible main function. */
4537 expand_main_function ()
4539 if (!output_bytecode)
4541 /* The zero below avoids a possible parse error */
4543 #if !defined (INIT_SECTION_ASM_OP) || defined (INVOKE__main)
4544 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, NAME__MAIN), 0,
4546 #endif /* not INIT_SECTION_ASM_OP or INVOKE__main */
4550 extern struct obstack permanent_obstack;
4552 /* Expand start of bytecode function. See comment at
4553 expand_function_start below for details. */
4556 bc_expand_function_start (subr, parms_have_cleanups)
4558 int parms_have_cleanups;
4560 char label[20], *name;
4565 if (TREE_PUBLIC (subr))
4566 bc_globalize_label (IDENTIFIER_POINTER (DECL_NAME (subr)));
4568 #ifdef DEBUG_PRINT_CODE
4569 fprintf (stderr, "\n<func %s>\n", IDENTIFIER_POINTER (DECL_NAME (subr)));
4572 for (argsz = 0, thisarg = DECL_ARGUMENTS (subr); thisarg; thisarg = TREE_CHAIN (thisarg))
4574 if (DECL_RTL (thisarg))
4575 abort (); /* Should be NULL here I think. */
4576 else if (TREE_CONSTANT (DECL_SIZE (thisarg)))
4578 DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
4579 argsz += TREE_INT_CST_LOW (DECL_SIZE (thisarg));
4583 /* Variable-sized objects are pointers to their storage. */
4584 DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
4585 argsz += POINTER_SIZE;
4589 bc_begin_function (bc_xstrdup (IDENTIFIER_POINTER (DECL_NAME (subr))));
4591 ASM_GENERATE_INTERNAL_LABEL (label, "LX", nlab);
4594 name = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
4595 this_function_callinfo = bc_gen_rtx (name, 0, (struct bc_label *) 0);
4596 this_function_bytecode =
4597 bc_emit_trampoline (BYTECODE_LABEL (this_function_callinfo));
4601 /* Expand end of bytecode function. See details the comment of
4602 expand_function_end(), below. */
4605 bc_expand_function_end ()
4609 expand_null_return ();
4611 /* Emit any fixup code. This must be done before the call to
4612 to BC_END_FUNCTION (), since that will cause the bytecode
4613 segment to be finished off and closed. */
4615 fixup_gotos (0, 0, 0, 0, 0);
4617 ptrconsts = bc_end_function ();
4619 bc_align_const (2 /* INT_ALIGN */);
4621 /* If this changes also make sure to change bc-interp.h! */
4623 bc_emit_const_labeldef (BYTECODE_LABEL (this_function_callinfo));
4624 bc_emit_const ((char *) &max_stack_depth, sizeof max_stack_depth);
4625 bc_emit_const ((char *) &local_vars_size, sizeof local_vars_size);
4626 bc_emit_const_labelref (this_function_bytecode, 0);
4627 bc_emit_const_labelref (ptrconsts, 0);
4628 bc_emit_const_labelref (BYTECODE_LABEL (this_function_calldesc), 0);
4632 /* Start the RTL for a new function, and set variables used for
4634 SUBR is the FUNCTION_DECL node.
4635 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
4636 the function's parameters, which must be run at any return statement. */
4639 expand_function_start (subr, parms_have_cleanups)
4641 int parms_have_cleanups;
4647 if (output_bytecode)
4649 bc_expand_function_start (subr, parms_have_cleanups);
4653 /* Make sure volatile mem refs aren't considered
4654 valid operands of arithmetic insns. */
4655 init_recog_no_volatile ();
4657 /* If function gets a static chain arg, store it in the stack frame.
4658 Do this first, so it gets the first stack slot offset. */
4659 if (current_function_needs_context)
4661 last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
4662 emit_move_insn (last_ptr, static_chain_incoming_rtx);
4665 /* If the parameters of this function need cleaning up, get a label
4666 for the beginning of the code which executes those cleanups. This must
4667 be done before doing anything with return_label. */
4668 if (parms_have_cleanups)
4669 cleanup_label = gen_label_rtx ();
4673 /* Make the label for return statements to jump to, if this machine
4674 does not have a one-instruction return and uses an epilogue,
4675 or if it returns a structure, or if it has parm cleanups. */
4677 if (cleanup_label == 0 && HAVE_return
4678 && ! current_function_returns_pcc_struct
4679 && ! (current_function_returns_struct && ! optimize))
4682 return_label = gen_label_rtx ();
4684 return_label = gen_label_rtx ();
4687 /* Initialize rtx used to return the value. */
4688 /* Do this before assign_parms so that we copy the struct value address
4689 before any library calls that assign parms might generate. */
4691 /* Decide whether to return the value in memory or in a register. */
4692 if (aggregate_value_p (DECL_RESULT (subr)))
4694 /* Returning something that won't go in a register. */
4695 register rtx value_address;
4697 #ifdef PCC_STATIC_STRUCT_RETURN
4698 if (current_function_returns_pcc_struct)
4700 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
4701 value_address = assemble_static_space (size);
4706 /* Expect to be passed the address of a place to store the value.
4707 If it is passed as an argument, assign_parms will take care of
4709 if (struct_value_incoming_rtx)
4711 value_address = gen_reg_rtx (Pmode);
4712 emit_move_insn (value_address, struct_value_incoming_rtx);
4716 DECL_RTL (DECL_RESULT (subr))
4717 = gen_rtx (MEM, DECL_MODE (DECL_RESULT (subr)),
4720 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
4721 /* If return mode is void, this decl rtl should not be used. */
4722 DECL_RTL (DECL_RESULT (subr)) = 0;
4723 else if (parms_have_cleanups)
4725 /* If function will end with cleanup code for parms,
4726 compute the return values into a pseudo reg,
4727 which we will copy into the true return register
4728 after the cleanups are done. */
4730 enum machine_mode mode = DECL_MODE (DECL_RESULT (subr));
4731 #ifdef PROMOTE_FUNCTION_RETURN
4732 tree type = TREE_TYPE (DECL_RESULT (subr));
4733 int unsignedp = TREE_UNSIGNED (type);
4735 if (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == ENUMERAL_TYPE
4736 || TREE_CODE (type) == BOOLEAN_TYPE || TREE_CODE (type) == CHAR_TYPE
4737 || TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == POINTER_TYPE
4738 || TREE_CODE (type) == OFFSET_TYPE)
4740 PROMOTE_MODE (mode, unsignedp, type);
4744 DECL_RTL (DECL_RESULT (subr)) = gen_reg_rtx (mode);
4747 /* Scalar, returned in a register. */
4749 #ifdef FUNCTION_OUTGOING_VALUE
4750 DECL_RTL (DECL_RESULT (subr))
4751 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
4753 DECL_RTL (DECL_RESULT (subr))
4754 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
4757 /* Mark this reg as the function's return value. */
4758 if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG)
4760 REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1;
4761 /* Needed because we may need to move this to memory
4762 in case it's a named return value whose address is taken. */
4763 DECL_REGISTER (DECL_RESULT (subr)) = 1;
4767 /* Initialize rtx for parameters and local variables.
4768 In some cases this requires emitting insns. */
4770 assign_parms (subr, 0);
4772 /* The following was moved from init_function_start.
4773 The move is supposed to make sdb output more accurate. */
4774 /* Indicate the beginning of the function body,
4775 as opposed to parm setup. */
4776 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_BEG);
4778 /* If doing stupid allocation, mark parms as born here. */
4780 if (GET_CODE (get_last_insn ()) != NOTE)
4781 emit_note (NULL_PTR, NOTE_INSN_DELETED);
4782 parm_birth_insn = get_last_insn ();
4786 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
4787 use_variable (regno_reg_rtx[i]);
4789 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
4790 use_variable (current_function_internal_arg_pointer);
4793 /* Fetch static chain values for containing functions. */
4794 tem = decl_function_context (current_function_decl);
4795 /* If not doing stupid register allocation, then start off with the static
4796 chain pointer in a pseudo register. Otherwise, we use the stack
4797 address that was generated above. */
4798 if (tem && ! obey_regdecls)
4799 last_ptr = copy_to_reg (static_chain_incoming_rtx);
4800 context_display = 0;
4803 tree rtlexp = make_node (RTL_EXPR);
4805 RTL_EXPR_RTL (rtlexp) = last_ptr;
4806 context_display = tree_cons (tem, rtlexp, context_display);
4807 tem = decl_function_context (tem);
4810 /* Chain thru stack frames, assuming pointer to next lexical frame
4811 is found at the place we always store it. */
4812 #ifdef FRAME_GROWS_DOWNWARD
4813 last_ptr = plus_constant (last_ptr, - GET_MODE_SIZE (Pmode));
4815 last_ptr = copy_to_reg (gen_rtx (MEM, Pmode,
4816 memory_address (Pmode, last_ptr)));
4819 /* After the display initializations is where the tail-recursion label
4820 should go, if we end up needing one. Ensure we have a NOTE here
4821 since some things (like trampolines) get placed before this. */
4822 tail_recursion_reentry = emit_note (NULL_PTR, NOTE_INSN_DELETED);
4824 /* Evaluate now the sizes of any types declared among the arguments. */
4825 for (tem = nreverse (get_pending_sizes ()); tem; tem = TREE_CHAIN (tem))
4826 expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode, 0);
4828 /* Make sure there is a line number after the function entry setup code. */
4829 force_next_line_note ();
4832 /* Generate RTL for the end of the current function.
4833 FILENAME and LINE are the current position in the source file. */
4835 /* It is up to language-specific callers to do cleanups for parameters. */
4838 expand_function_end (filename, line)
4845 static rtx initial_trampoline;
4847 if (output_bytecode)
4849 bc_expand_function_end ();
4853 #ifdef NON_SAVING_SETJMP
4854 /* Don't put any variables in registers if we call setjmp
4855 on a machine that fails to restore the registers. */
4856 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
4858 setjmp_protect (DECL_INITIAL (current_function_decl));
4859 setjmp_protect_args ();
4863 /* Save the argument pointer if a save area was made for it. */
4864 if (arg_pointer_save_area)
4866 rtx x = gen_move_insn (arg_pointer_save_area, virtual_incoming_args_rtx);
4867 emit_insn_before (x, tail_recursion_reentry);
4870 /* Initialize any trampolines required by this function. */
4871 for (link = trampoline_list; link; link = TREE_CHAIN (link))
4873 tree function = TREE_PURPOSE (link);
4874 rtx context = lookup_static_chain (function);
4875 rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
4878 /* First make sure this compilation has a template for
4879 initializing trampolines. */
4880 if (initial_trampoline == 0)
4882 end_temporary_allocation ();
4884 = gen_rtx (MEM, BLKmode, assemble_trampoline_template ());
4885 resume_temporary_allocation ();
4888 /* Generate insns to initialize the trampoline. */
4890 tramp = change_address (initial_trampoline, BLKmode,
4891 round_trampoline_addr (XEXP (tramp, 0)));
4892 emit_block_move (tramp, initial_trampoline, GEN_INT (TRAMPOLINE_SIZE),
4893 FUNCTION_BOUNDARY / BITS_PER_UNIT);
4894 INITIALIZE_TRAMPOLINE (XEXP (tramp, 0),
4895 XEXP (DECL_RTL (function), 0), context);
4899 /* Put those insns at entry to the containing function (this one). */
4900 emit_insns_before (seq, tail_recursion_reentry);
4903 #if 0 /* I think unused parms are legitimate enough. */
4904 /* Warn about unused parms. */
4909 for (decl = DECL_ARGUMENTS (current_function_decl);
4910 decl; decl = TREE_CHAIN (decl))
4911 if (! TREE_USED (decl) && TREE_CODE (decl) == VAR_DECL)
4912 warning_with_decl (decl, "unused parameter `%s'");
4916 /* Delete handlers for nonlocal gotos if nothing uses them. */
4917 if (nonlocal_goto_handler_slot != 0 && !current_function_has_nonlocal_label)
4920 /* End any sequences that failed to be closed due to syntax errors. */
4921 while (in_sequence_p ())
4924 /* Outside function body, can't compute type's actual size
4925 until next function's body starts. */
4926 immediate_size_expand--;
4928 /* If doing stupid register allocation,
4929 mark register parms as dying here. */
4934 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
4935 use_variable (regno_reg_rtx[i]);
4937 /* Likewise for the regs of all the SAVE_EXPRs in the function. */
4939 for (tem = save_expr_regs; tem; tem = XEXP (tem, 1))
4941 use_variable (XEXP (tem, 0));
4942 use_variable_after (XEXP (tem, 0), parm_birth_insn);
4945 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
4946 use_variable (current_function_internal_arg_pointer);
4949 clear_pending_stack_adjust ();
4950 do_pending_stack_adjust ();
4952 /* Mark the end of the function body.
4953 If control reaches this insn, the function can drop through
4954 without returning a value. */
4955 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_END);
4957 /* Output a linenumber for the end of the function.
4958 SDB depends on this. */
4959 emit_line_note_force (filename, line);
4961 /* Output the label for the actual return from the function,
4962 if one is expected. This happens either because a function epilogue
4963 is used instead of a return instruction, or because a return was done
4964 with a goto in order to run local cleanups, or because of pcc-style
4965 structure returning. */
4968 emit_label (return_label);
4970 /* If we had calls to alloca, and this machine needs
4971 an accurate stack pointer to exit the function,
4972 insert some code to save and restore the stack pointer. */
4973 #ifdef EXIT_IGNORE_STACK
4974 if (! EXIT_IGNORE_STACK)
4976 if (current_function_calls_alloca)
4980 emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
4981 emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
4984 /* If scalar return value was computed in a pseudo-reg,
4985 copy that to the hard return register. */
4986 if (DECL_RTL (DECL_RESULT (current_function_decl)) != 0
4987 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG
4988 && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl)))
4989 >= FIRST_PSEUDO_REGISTER))
4991 rtx real_decl_result;
4993 #ifdef FUNCTION_OUTGOING_VALUE
4995 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
4996 current_function_decl);
4999 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
5000 current_function_decl);
5002 REG_FUNCTION_VALUE_P (real_decl_result) = 1;
5003 emit_move_insn (real_decl_result,
5004 DECL_RTL (DECL_RESULT (current_function_decl)));
5005 emit_insn (gen_rtx (USE, VOIDmode, real_decl_result));
5008 /* If returning a structure, arrange to return the address of the value
5009 in a place where debuggers expect to find it.
5011 If returning a structure PCC style,
5012 the caller also depends on this value.
5013 And current_function_returns_pcc_struct is not necessarily set. */
5014 if (current_function_returns_struct
5015 || current_function_returns_pcc_struct)
5017 rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
5018 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
5019 #ifdef FUNCTION_OUTGOING_VALUE
5021 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
5022 current_function_decl);
5025 = FUNCTION_VALUE (build_pointer_type (type),
5026 current_function_decl);
5029 /* Mark this as a function return value so integrate will delete the
5030 assignment and USE below when inlining this function. */
5031 REG_FUNCTION_VALUE_P (outgoing) = 1;
5033 emit_move_insn (outgoing, value_address);
5034 use_variable (outgoing);
5037 /* Output a return insn if we are using one.
5038 Otherwise, let the rtl chain end here, to drop through
5039 into the epilogue. */
5044 emit_jump_insn (gen_return ());
5049 /* Fix up any gotos that jumped out to the outermost
5050 binding level of the function.
5051 Must follow emitting RETURN_LABEL. */
5053 /* If you have any cleanups to do at this point,
5054 and they need to create temporary variables,
5055 then you will lose. */
5056 fixup_gotos (NULL_PTR, NULL_RTX, NULL_TREE, get_insns (), 0);
5059 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
5061 static int *prologue;
5062 static int *epilogue;
5064 /* Create an array that records the INSN_UIDs of INSNS (either a sequence
5065 or a single insn). */
5068 record_insns (insns)
5073 if (GET_CODE (insns) == SEQUENCE)
5075 int len = XVECLEN (insns, 0);
5076 vec = (int *) oballoc ((len + 1) * sizeof (int));
5079 vec[len] = INSN_UID (XVECEXP (insns, 0, len));
5083 vec = (int *) oballoc (2 * sizeof (int));
5084 vec[0] = INSN_UID (insns);
5090 /* Determine how many INSN_UIDs in VEC are part of INSN. */
5093 contains (insn, vec)
5099 if (GET_CODE (insn) == INSN
5100 && GET_CODE (PATTERN (insn)) == SEQUENCE)
5103 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
5104 for (j = 0; vec[j]; j++)
5105 if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == vec[j])
5111 for (j = 0; vec[j]; j++)
5112 if (INSN_UID (insn) == vec[j])
5118 /* Generate the prologe and epilogue RTL if the machine supports it. Thread
5119 this into place with notes indicating where the prologue ends and where
5120 the epilogue begins. Update the basic block information when possible. */
5123 thread_prologue_and_epilogue_insns (f)
5126 #ifdef HAVE_prologue
5129 rtx head, seq, insn;
5131 /* The first insn (a NOTE_INSN_DELETED) is followed by zero or more
5132 prologue insns and a NOTE_INSN_PROLOGUE_END. */
5133 emit_note_after (NOTE_INSN_PROLOGUE_END, f);
5134 seq = gen_prologue ();
5135 head = emit_insn_after (seq, f);
5137 /* Include the new prologue insns in the first block. Ignore them
5138 if they form a basic block unto themselves. */
5139 if (basic_block_head && n_basic_blocks
5140 && GET_CODE (basic_block_head[0]) != CODE_LABEL)
5141 basic_block_head[0] = NEXT_INSN (f);
5143 /* Retain a map of the prologue insns. */
5144 prologue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : head);
5150 #ifdef HAVE_epilogue
5153 rtx insn = get_last_insn ();
5154 rtx prev = prev_nonnote_insn (insn);
5156 /* If we end with a BARRIER, we don't need an epilogue. */
5157 if (! (prev && GET_CODE (prev) == BARRIER))
5163 /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, the
5164 epilogue insns, the USE insns at the end of a function,
5165 the jump insn that returns, and then a BARRIER. */
5167 /* Move the USE insns at the end of a function onto a list. */
5169 && GET_CODE (prev) == INSN
5170 && GET_CODE (PATTERN (prev)) == USE)
5173 prev = prev_nonnote_insn (prev);
5175 NEXT_INSN (PREV_INSN (tem)) = NEXT_INSN (tem);
5176 PREV_INSN (NEXT_INSN (tem)) = PREV_INSN (tem);
5180 NEXT_INSN (last_use) = tem;
5185 emit_barrier_after (insn);
5187 seq = gen_epilogue ();
5188 tail = emit_jump_insn_after (seq, insn);
5190 /* Insert the USE insns immediately before the return insn, which
5191 must be the first instruction before the final barrier. */
5194 tem = prev_nonnote_insn (get_last_insn ());
5195 NEXT_INSN (PREV_INSN (tem)) = first_use;
5196 PREV_INSN (first_use) = PREV_INSN (tem);
5197 PREV_INSN (tem) = last_use;
5198 NEXT_INSN (last_use) = tem;
5201 emit_note_after (NOTE_INSN_EPILOGUE_BEG, insn);
5203 /* Include the new epilogue insns in the last block. Ignore
5204 them if they form a basic block unto themselves. */
5205 if (basic_block_end && n_basic_blocks
5206 && GET_CODE (basic_block_end[n_basic_blocks - 1]) != JUMP_INSN)
5207 basic_block_end[n_basic_blocks - 1] = tail;
5209 /* Retain a map of the epilogue insns. */
5210 epilogue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : tail);
5218 /* Reposition the prologue-end and epilogue-begin notes after instruction
5219 scheduling and delayed branch scheduling. */
5222 reposition_prologue_and_epilogue_notes (f)
5225 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
5226 /* Reposition the prologue and epilogue notes. */
5234 register rtx insn, note = 0;
5236 /* Scan from the beginning until we reach the last prologue insn.
5237 We apparently can't depend on basic_block_{head,end} after
5239 for (len = 0; prologue[len]; len++)
5241 for (insn = f; len && insn; insn = NEXT_INSN (insn))
5243 if (GET_CODE (insn) == NOTE)
5245 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
5248 else if ((len -= contains (insn, prologue)) == 0)
5250 /* Find the prologue-end note if we haven't already, and
5251 move it to just after the last prologue insn. */
5254 for (note = insn; note = NEXT_INSN (note);)
5255 if (GET_CODE (note) == NOTE
5256 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
5259 next = NEXT_INSN (note);
5260 prev = PREV_INSN (note);
5262 NEXT_INSN (prev) = next;
5264 PREV_INSN (next) = prev;
5265 add_insn_after (note, insn);
5272 register rtx insn, note = 0;
5274 /* Scan from the end until we reach the first epilogue insn.
5275 We apparently can't depend on basic_block_{head,end} after
5277 for (len = 0; epilogue[len]; len++)
5279 for (insn = get_last_insn (); len && insn; insn = PREV_INSN (insn))
5281 if (GET_CODE (insn) == NOTE)
5283 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
5286 else if ((len -= contains (insn, epilogue)) == 0)
5288 /* Find the epilogue-begin note if we haven't already, and
5289 move it to just before the first epilogue insn. */
5292 for (note = insn; note = PREV_INSN (note);)
5293 if (GET_CODE (note) == NOTE
5294 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
5297 next = NEXT_INSN (note);
5298 prev = PREV_INSN (note);
5300 NEXT_INSN (prev) = next;
5302 PREV_INSN (next) = prev;
5303 add_insn_after (note, PREV_INSN (insn));
5308 #endif /* HAVE_prologue or HAVE_epilogue */