1 /* Expands front end tree to back end RTL for GNU C-Compiler
2 Copyright (C) 1987, 88, 89, 91, 92, 93, 1994 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This file handles the generation of rtl code from tree structure
22 at the level of the function as a whole.
23 It creates the rtl expressions for parameters and auto variables
24 and has full responsibility for allocating stack slots.
26 `expand_function_start' is called at the beginning of a function,
27 before the function body is parsed, and `expand_function_end' is
28 called after parsing the body.
30 Call `assign_stack_local' to allocate a stack slot for a local variable.
31 This is usually done during the RTL generation for the function body,
32 but it can also be done in the reload pass when a pseudo-register does
33 not get a hard register.
35 Call `put_var_into_stack' when you learn, belatedly, that a variable
36 previously given a pseudo-register must in fact go in the stack.
37 This function changes the DECL_RTL to be a stack slot instead of a reg
38 then scans all the RTL instructions so far generated to correct them. */
48 #include "insn-flags.h"
50 #include "insn-codes.h"
52 #include "hard-reg-set.h"
53 #include "insn-config.h"
56 #include "basic-block.h"
60 /* Some systems use __main in a way incompatible with its use in gcc, in these
61 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
62 give the same symbol without quotes for an alternative entry point. You
63 must define both, or niether. */
65 #define NAME__MAIN "__main"
66 #define SYMBOL__MAIN __main
69 /* Round a value to the lowest integer less than it that is a multiple of
70 the required alignment. Avoid using division in case the value is
71 negative. Assume the alignment is a power of two. */
72 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
74 /* Similar, but round to the next highest integer that meets the
76 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
78 /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp
79 during rtl generation. If they are different register numbers, this is
80 always true. It may also be true if
81 FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl
82 generation. See fix_lexical_addr for details. */
84 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
85 #define NEED_SEPARATE_AP
88 /* Number of bytes of args popped by function being compiled on its return.
89 Zero if no bytes are to be popped.
90 May affect compilation of return insn or of function epilogue. */
92 int current_function_pops_args;
94 /* Nonzero if function being compiled needs to be given an address
95 where the value should be stored. */
97 int current_function_returns_struct;
99 /* Nonzero if function being compiled needs to
100 return the address of where it has put a structure value. */
102 int current_function_returns_pcc_struct;
104 /* Nonzero if function being compiled needs to be passed a static chain. */
106 int current_function_needs_context;
108 /* Nonzero if function being compiled can call setjmp. */
110 int current_function_calls_setjmp;
112 /* Nonzero if function being compiled can call longjmp. */
114 int current_function_calls_longjmp;
116 /* Nonzero if function being compiled receives nonlocal gotos
117 from nested functions. */
119 int current_function_has_nonlocal_label;
121 /* Nonzero if function being compiled has nonlocal gotos to parent
124 int current_function_has_nonlocal_goto;
126 /* Nonzero if function being compiled contains nested functions. */
128 int current_function_contains_functions;
130 /* Nonzero if function being compiled can call alloca,
131 either as a subroutine or builtin. */
133 int current_function_calls_alloca;
135 /* Nonzero if the current function returns a pointer type */
137 int current_function_returns_pointer;
139 /* If some insns can be deferred to the delay slots of the epilogue, the
140 delay list for them is recorded here. */
142 rtx current_function_epilogue_delay_list;
144 /* If function's args have a fixed size, this is that size, in bytes.
146 May affect compilation of return insn or of function epilogue. */
148 int current_function_args_size;
150 /* # bytes the prologue should push and pretend that the caller pushed them.
151 The prologue must do this, but only if parms can be passed in registers. */
153 int current_function_pretend_args_size;
155 /* # of bytes of outgoing arguments required to be pushed by the prologue.
156 If this is non-zero, it means that ACCUMULATE_OUTGOING_ARGS was defined
157 and no stack adjusts will be done on function calls. */
159 int current_function_outgoing_args_size;
161 /* This is the offset from the arg pointer to the place where the first
162 anonymous arg can be found, if there is one. */
164 rtx current_function_arg_offset_rtx;
166 /* Nonzero if current function uses varargs.h or equivalent.
167 Zero for functions that use stdarg.h. */
169 int current_function_varargs;
171 /* Quantities of various kinds of registers
172 used for the current function's args. */
174 CUMULATIVE_ARGS current_function_args_info;
176 /* Name of function now being compiled. */
178 char *current_function_name;
180 /* If non-zero, an RTL expression for that location at which the current
181 function returns its result. Always equal to
182 DECL_RTL (DECL_RESULT (current_function_decl)), but provided
183 independently of the tree structures. */
185 rtx current_function_return_rtx;
187 /* Nonzero if the current function uses the constant pool. */
189 int current_function_uses_const_pool;
191 /* Nonzero if the current function uses pic_offset_table_rtx. */
192 int current_function_uses_pic_offset_table;
194 /* The arg pointer hard register, or the pseudo into which it was copied. */
195 rtx current_function_internal_arg_pointer;
197 /* The FUNCTION_DECL for an inline function currently being expanded. */
198 tree inline_function_decl;
200 /* Number of function calls seen so far in current function. */
202 int function_call_count;
204 /* List (chain of TREE_LIST) of LABEL_DECLs for all nonlocal labels
205 (labels to which there can be nonlocal gotos from nested functions)
208 tree nonlocal_labels;
210 /* RTX for stack slot that holds the current handler for nonlocal gotos.
211 Zero when function does not have nonlocal labels. */
213 rtx nonlocal_goto_handler_slot;
215 /* RTX for stack slot that holds the stack pointer value to restore
217 Zero when function does not have nonlocal labels. */
219 rtx nonlocal_goto_stack_level;
221 /* Label that will go on parm cleanup code, if any.
222 Jumping to this label runs cleanup code for parameters, if
223 such code must be run. Following this code is the logical return label. */
227 /* Label that will go on function epilogue.
228 Jumping to this label serves as a "return" instruction
229 on machines which require execution of the epilogue on all returns. */
233 /* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs.
234 So we can mark them all live at the end of the function, if nonopt. */
237 /* List (chain of EXPR_LISTs) of all stack slots in this function.
238 Made for the sake of unshare_all_rtl. */
241 /* Chain of all RTL_EXPRs that have insns in them. */
244 /* Label to jump back to for tail recursion, or 0 if we have
245 not yet needed one for this function. */
246 rtx tail_recursion_label;
248 /* Place after which to insert the tail_recursion_label if we need one. */
249 rtx tail_recursion_reentry;
251 /* Location at which to save the argument pointer if it will need to be
252 referenced. There are two cases where this is done: if nonlocal gotos
253 exist, or if vars stored at an offset from the argument pointer will be
254 needed by inner routines. */
256 rtx arg_pointer_save_area;
258 /* Offset to end of allocated area of stack frame.
259 If stack grows down, this is the address of the last stack slot allocated.
260 If stack grows up, this is the address for the next slot. */
263 /* List (chain of TREE_LISTs) of static chains for containing functions.
264 Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
265 in an RTL_EXPR in the TREE_VALUE. */
266 static tree context_display;
268 /* List (chain of TREE_LISTs) of trampolines for nested functions.
269 The trampoline sets up the static chain and jumps to the function.
270 We supply the trampoline's address when the function's address is requested.
272 Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
273 in an RTL_EXPR in the TREE_VALUE. */
274 static tree trampoline_list;
276 /* Insn after which register parms and SAVE_EXPRs are born, if nonopt. */
277 static rtx parm_birth_insn;
280 /* Nonzero if a stack slot has been generated whose address is not
281 actually valid. It means that the generated rtl must all be scanned
282 to detect and correct the invalid addresses where they occur. */
283 static int invalid_stack_slot;
286 /* Last insn of those whose job was to put parms into their nominal homes. */
287 static rtx last_parm_insn;
289 /* 1 + last pseudo register number used for loading a copy
290 of a parameter of this function. */
291 static int max_parm_reg;
293 /* Vector indexed by REGNO, containing location on stack in which
294 to put the parm which is nominally in pseudo register REGNO,
295 if we discover that that parm must go in the stack. */
296 static rtx *parm_reg_stack_loc;
298 #if 0 /* Turned off because 0 seems to work just as well. */
299 /* Cleanup lists are required for binding levels regardless of whether
300 that binding level has cleanups or not. This node serves as the
301 cleanup list whenever an empty list is required. */
302 static tree empty_cleanup_list;
305 /* Nonzero once virtual register instantiation has been done.
306 assign_stack_local uses frame_pointer_rtx when this is nonzero. */
307 static int virtuals_instantiated;
309 /* These variables hold pointers to functions to
310 save and restore machine-specific data,
311 in push_function_context and pop_function_context. */
312 void (*save_machine_status) ();
313 void (*restore_machine_status) ();
315 /* Nonzero if we need to distinguish between the return value of this function
316 and the return value of a function called by this function. This helps
319 extern int rtx_equal_function_value_matters;
320 extern tree sequence_rtl_expr;
321 extern tree bc_runtime_type_code ();
322 extern rtx bc_build_calldesc ();
323 extern char *bc_emit_trampoline ();
324 extern char *bc_end_function ();
326 /* In order to evaluate some expressions, such as function calls returning
327 structures in memory, we need to temporarily allocate stack locations.
328 We record each allocated temporary in the following structure.
330 Associated with each temporary slot is a nesting level. When we pop up
331 one level, all temporaries associated with the previous level are freed.
332 Normally, all temporaries are freed after the execution of the statement
333 in which they were created. However, if we are inside a ({...}) grouping,
334 the result may be in a temporary and hence must be preserved. If the
335 result could be in a temporary, we preserve it if we can determine which
336 one it is in. If we cannot determine which temporary may contain the
337 result, all temporaries are preserved. A temporary is preserved by
338 pretending it was allocated at the previous nesting level.
340 Automatic variables are also assigned temporary slots, at the nesting
341 level where they are defined. They are marked a "kept" so that
342 free_temp_slots will not free them. */
346 /* Points to next temporary slot. */
347 struct temp_slot *next;
348 /* The rtx to used to reference the slot. */
350 /* The rtx used to represent the address if not the address of the
351 slot above. May be an EXPR_LIST if multiple addresses exist. */
353 /* The size, in units, of the slot. */
355 /* The value of `sequence_rtl_expr' when this temporary is allocated. */
357 /* Non-zero if this temporary is currently in use. */
359 /* Nesting level at which this slot is being used. */
361 /* Non-zero if this should survive a call to free_temp_slots. */
365 /* List of all temporaries allocated, both available and in use. */
367 struct temp_slot *temp_slots;
369 /* Current nesting level for temporaries. */
373 /* The FUNCTION_DECL node for the current function. */
374 static tree this_function_decl;
376 /* Callinfo pointer for the current function. */
377 static rtx this_function_callinfo;
379 /* The label in the bytecode file of this function's actual bytecode.
381 static char *this_function_bytecode;
383 /* The call description vector for the current function. */
384 static rtx this_function_calldesc;
386 /* Size of the local variables allocated for the current function. */
389 /* Current depth of the bytecode evaluation stack. */
392 /* Maximum depth of the evaluation stack in this function. */
395 /* Current depth in statement expressions. */
396 static int stmt_expr_depth;
398 /* This structure is used to record MEMs or pseudos used to replace VAR, any
399 SUBREGs of VAR, and any MEMs containing VAR as an address. We need to
400 maintain this list in case two operands of an insn were required to match;
401 in that case we must ensure we use the same replacement. */
403 struct fixup_replacement
407 struct fixup_replacement *next;
410 /* Forward declarations. */
412 static struct temp_slot *find_temp_slot_from_address PROTO((rtx));
413 static void put_reg_into_stack PROTO((struct function *, rtx, tree,
414 enum machine_mode, enum machine_mode));
415 static void fixup_var_refs PROTO((rtx, enum machine_mode, int));
416 static struct fixup_replacement
417 *find_fixup_replacement PROTO((struct fixup_replacement **, rtx));
418 static void fixup_var_refs_insns PROTO((rtx, enum machine_mode, int,
420 static void fixup_var_refs_1 PROTO((rtx, enum machine_mode, rtx *, rtx,
421 struct fixup_replacement **));
422 static rtx fixup_memory_subreg PROTO((rtx, rtx, int));
423 static rtx walk_fixup_memory_subreg PROTO((rtx, rtx, int));
424 static rtx fixup_stack_1 PROTO((rtx, rtx));
425 static void optimize_bit_field PROTO((rtx, rtx, rtx *));
426 static void instantiate_decls PROTO((tree, int));
427 static void instantiate_decls_1 PROTO((tree, int));
428 static void instantiate_decl PROTO((rtx, int, int));
429 static int instantiate_virtual_regs_1 PROTO((rtx *, rtx, int));
430 static void delete_handlers PROTO((void));
431 static void pad_to_arg_alignment PROTO((struct args_size *, int));
432 static void pad_below PROTO((struct args_size *, enum machine_mode,
434 static tree round_down PROTO((tree, int));
435 static rtx round_trampoline_addr PROTO((rtx));
436 static tree blocks_nreverse PROTO((tree));
437 static int all_blocks PROTO((tree, tree *));
438 static int *record_insns PROTO((rtx));
439 static int contains PROTO((rtx, int *));
441 /* Pointer to chain of `struct function' for containing functions. */
442 struct function *outer_function_chain;
444 /* Given a function decl for a containing function,
445 return the `struct function' for it. */
448 find_function_data (decl)
452 for (p = outer_function_chain; p; p = p->next)
458 /* Save the current context for compilation of a nested function.
459 This is called from language-specific code.
460 The caller is responsible for saving any language-specific status,
461 since this function knows only about language-independent variables. */
464 push_function_context ()
466 struct function *p = (struct function *) xmalloc (sizeof (struct function));
468 p->next = outer_function_chain;
469 outer_function_chain = p;
471 p->name = current_function_name;
472 p->decl = current_function_decl;
473 p->pops_args = current_function_pops_args;
474 p->returns_struct = current_function_returns_struct;
475 p->returns_pcc_struct = current_function_returns_pcc_struct;
476 p->needs_context = current_function_needs_context;
477 p->calls_setjmp = current_function_calls_setjmp;
478 p->calls_longjmp = current_function_calls_longjmp;
479 p->calls_alloca = current_function_calls_alloca;
480 p->has_nonlocal_label = current_function_has_nonlocal_label;
481 p->has_nonlocal_goto = current_function_has_nonlocal_goto;
482 p->args_size = current_function_args_size;
483 p->pretend_args_size = current_function_pretend_args_size;
484 p->arg_offset_rtx = current_function_arg_offset_rtx;
485 p->varargs = current_function_varargs;
486 p->uses_const_pool = current_function_uses_const_pool;
487 p->uses_pic_offset_table = current_function_uses_pic_offset_table;
488 p->internal_arg_pointer = current_function_internal_arg_pointer;
489 p->max_parm_reg = max_parm_reg;
490 p->parm_reg_stack_loc = parm_reg_stack_loc;
491 p->outgoing_args_size = current_function_outgoing_args_size;
492 p->return_rtx = current_function_return_rtx;
493 p->nonlocal_goto_handler_slot = nonlocal_goto_handler_slot;
494 p->nonlocal_goto_stack_level = nonlocal_goto_stack_level;
495 p->nonlocal_labels = nonlocal_labels;
496 p->cleanup_label = cleanup_label;
497 p->return_label = return_label;
498 p->save_expr_regs = save_expr_regs;
499 p->stack_slot_list = stack_slot_list;
500 p->parm_birth_insn = parm_birth_insn;
501 p->frame_offset = frame_offset;
502 p->tail_recursion_label = tail_recursion_label;
503 p->tail_recursion_reentry = tail_recursion_reentry;
504 p->arg_pointer_save_area = arg_pointer_save_area;
505 p->rtl_expr_chain = rtl_expr_chain;
506 p->last_parm_insn = last_parm_insn;
507 p->context_display = context_display;
508 p->trampoline_list = trampoline_list;
509 p->function_call_count = function_call_count;
510 p->temp_slots = temp_slots;
511 p->temp_slot_level = temp_slot_level;
512 p->fixup_var_refs_queue = 0;
513 p->epilogue_delay_list = current_function_epilogue_delay_list;
515 save_tree_status (p);
516 save_storage_status (p);
517 save_emit_status (p);
519 save_expr_status (p);
520 save_stmt_status (p);
521 save_varasm_status (p);
523 if (save_machine_status)
524 (*save_machine_status) (p);
527 /* Restore the last saved context, at the end of a nested function.
528 This function is called from language-specific code. */
531 pop_function_context ()
533 struct function *p = outer_function_chain;
535 outer_function_chain = p->next;
537 current_function_name = p->name;
538 current_function_decl = p->decl;
539 current_function_pops_args = p->pops_args;
540 current_function_returns_struct = p->returns_struct;
541 current_function_returns_pcc_struct = p->returns_pcc_struct;
542 current_function_needs_context = p->needs_context;
543 current_function_calls_setjmp = p->calls_setjmp;
544 current_function_calls_longjmp = p->calls_longjmp;
545 current_function_calls_alloca = p->calls_alloca;
546 current_function_has_nonlocal_label = p->has_nonlocal_label;
547 current_function_has_nonlocal_goto = p->has_nonlocal_goto;
548 current_function_contains_functions = 1;
549 current_function_args_size = p->args_size;
550 current_function_pretend_args_size = p->pretend_args_size;
551 current_function_arg_offset_rtx = p->arg_offset_rtx;
552 current_function_varargs = p->varargs;
553 current_function_uses_const_pool = p->uses_const_pool;
554 current_function_uses_pic_offset_table = p->uses_pic_offset_table;
555 current_function_internal_arg_pointer = p->internal_arg_pointer;
556 max_parm_reg = p->max_parm_reg;
557 parm_reg_stack_loc = p->parm_reg_stack_loc;
558 current_function_outgoing_args_size = p->outgoing_args_size;
559 current_function_return_rtx = p->return_rtx;
560 nonlocal_goto_handler_slot = p->nonlocal_goto_handler_slot;
561 nonlocal_goto_stack_level = p->nonlocal_goto_stack_level;
562 nonlocal_labels = p->nonlocal_labels;
563 cleanup_label = p->cleanup_label;
564 return_label = p->return_label;
565 save_expr_regs = p->save_expr_regs;
566 stack_slot_list = p->stack_slot_list;
567 parm_birth_insn = p->parm_birth_insn;
568 frame_offset = p->frame_offset;
569 tail_recursion_label = p->tail_recursion_label;
570 tail_recursion_reentry = p->tail_recursion_reentry;
571 arg_pointer_save_area = p->arg_pointer_save_area;
572 rtl_expr_chain = p->rtl_expr_chain;
573 last_parm_insn = p->last_parm_insn;
574 context_display = p->context_display;
575 trampoline_list = p->trampoline_list;
576 function_call_count = p->function_call_count;
577 temp_slots = p->temp_slots;
578 temp_slot_level = p->temp_slot_level;
579 current_function_epilogue_delay_list = p->epilogue_delay_list;
582 restore_tree_status (p);
583 restore_storage_status (p);
584 restore_expr_status (p);
585 restore_emit_status (p);
586 restore_stmt_status (p);
587 restore_varasm_status (p);
589 if (restore_machine_status)
590 (*restore_machine_status) (p);
592 /* Finish doing put_var_into_stack for any of our variables
593 which became addressable during the nested function. */
595 struct var_refs_queue *queue = p->fixup_var_refs_queue;
596 for (; queue; queue = queue->next)
597 fixup_var_refs (queue->modified, queue->promoted_mode, queue->unsignedp);
602 /* Reset variables that have known state during rtx generation. */
603 rtx_equal_function_value_matters = 1;
604 virtuals_instantiated = 0;
607 /* Allocate fixed slots in the stack frame of the current function. */
609 /* Return size needed for stack frame based on slots so far allocated.
610 This size counts from zero. It is not rounded to STACK_BOUNDARY;
611 the caller may have to do that. */
616 #ifdef FRAME_GROWS_DOWNWARD
617 return -frame_offset;
623 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
624 with machine mode MODE.
626 ALIGN controls the amount of alignment for the address of the slot:
627 0 means according to MODE,
628 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
629 positive specifies alignment boundary in bits.
631 We do not round to stack_boundary here. */
634 assign_stack_local (mode, size, align)
635 enum machine_mode mode;
639 register rtx x, addr;
640 int bigend_correction = 0;
645 alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
647 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
649 else if (align == -1)
651 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
652 size = CEIL_ROUND (size, alignment);
655 alignment = align / BITS_PER_UNIT;
657 /* Round frame offset to that alignment.
658 We must be careful here, since FRAME_OFFSET might be negative and
659 division with a negative dividend isn't as well defined as we might
660 like. So we instead assume that ALIGNMENT is a power of two and
661 use logical operations which are unambiguous. */
662 #ifdef FRAME_GROWS_DOWNWARD
663 frame_offset = FLOOR_ROUND (frame_offset, alignment);
665 frame_offset = CEIL_ROUND (frame_offset, alignment);
668 /* On a big-endian machine, if we are allocating more space than we will use,
669 use the least significant bytes of those that are allocated. */
672 bigend_correction = size - GET_MODE_SIZE (mode);
675 #ifdef FRAME_GROWS_DOWNWARD
676 frame_offset -= size;
679 /* If we have already instantiated virtual registers, return the actual
680 address relative to the frame pointer. */
681 if (virtuals_instantiated)
682 addr = plus_constant (frame_pointer_rtx,
683 (frame_offset + bigend_correction
684 + STARTING_FRAME_OFFSET));
686 addr = plus_constant (virtual_stack_vars_rtx,
687 frame_offset + bigend_correction);
689 #ifndef FRAME_GROWS_DOWNWARD
690 frame_offset += size;
693 x = gen_rtx (MEM, mode, addr);
695 stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, x, stack_slot_list);
700 /* Assign a stack slot in a containing function.
701 First three arguments are same as in preceding function.
702 The last argument specifies the function to allocate in. */
705 assign_outer_stack_local (mode, size, align, function)
706 enum machine_mode mode;
709 struct function *function;
711 register rtx x, addr;
712 int bigend_correction = 0;
715 /* Allocate in the memory associated with the function in whose frame
717 push_obstacks (function->function_obstack,
718 function->function_maybepermanent_obstack);
722 alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
724 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
726 else if (align == -1)
728 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
729 size = CEIL_ROUND (size, alignment);
732 alignment = align / BITS_PER_UNIT;
734 /* Round frame offset to that alignment. */
735 #ifdef FRAME_GROWS_DOWNWARD
736 function->frame_offset = FLOOR_ROUND (function->frame_offset, alignment);
738 function->frame_offset = CEIL_ROUND (function->frame_offset, alignment);
741 /* On a big-endian machine, if we are allocating more space than we will use,
742 use the least significant bytes of those that are allocated. */
745 bigend_correction = size - GET_MODE_SIZE (mode);
748 #ifdef FRAME_GROWS_DOWNWARD
749 function->frame_offset -= size;
751 addr = plus_constant (virtual_stack_vars_rtx,
752 function->frame_offset + bigend_correction);
753 #ifndef FRAME_GROWS_DOWNWARD
754 function->frame_offset += size;
757 x = gen_rtx (MEM, mode, addr);
759 function->stack_slot_list
760 = gen_rtx (EXPR_LIST, VOIDmode, x, function->stack_slot_list);
767 /* Allocate a temporary stack slot and record it for possible later
770 MODE is the machine mode to be given to the returned rtx.
772 SIZE is the size in units of the space required. We do no rounding here
773 since assign_stack_local will do any required rounding.
775 KEEP is 1 if this slot is to be retained after a call to
776 free_temp_slots. Automatic variables for a block are allocated
777 with this flag. KEEP is 2, if we allocate a longer term temporary,
778 whose lifetime is controlled by CLEANUP_POINT_EXPRs. */
781 assign_stack_temp (mode, size, keep)
782 enum machine_mode mode;
786 struct temp_slot *p, *best_p = 0;
788 /* First try to find an available, already-allocated temporary that is the
789 exact size we require. */
790 for (p = temp_slots; p; p = p->next)
791 if (p->size == size && GET_MODE (p->slot) == mode && ! p->in_use)
794 /* If we didn't find, one, try one that is larger than what we want. We
795 find the smallest such. */
797 for (p = temp_slots; p; p = p->next)
798 if (p->size > size && GET_MODE (p->slot) == mode && ! p->in_use
799 && (best_p == 0 || best_p->size > p->size))
802 /* Make our best, if any, the one to use. */
805 /* If there are enough aligned bytes left over, make them into a new
806 temp_slot so that the extra bytes don't get wasted. Do this only
807 for BLKmode slots, so that we can be sure of the alignment. */
808 if (GET_MODE (best_p->slot) == BLKmode)
810 int alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
811 int rounded_size = CEIL_ROUND (size, alignment);
813 if (best_p->size - rounded_size >= alignment)
815 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
817 p->size = best_p->size - rounded_size;
818 p->slot = gen_rtx (MEM, BLKmode,
819 plus_constant (XEXP (best_p->slot, 0),
822 p->next = temp_slots;
825 stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, p->slot,
828 best_p->size = rounded_size;
835 /* If we still didn't find one, make a new temporary. */
838 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
840 /* If the temp slot mode doesn't indicate the alignment,
841 use the largest possible, so no one will be disappointed. */
842 p->slot = assign_stack_local (mode, size, mode == BLKmode ? -1 : 0);
844 p->next = temp_slots;
849 p->rtl_expr = sequence_rtl_expr;
852 p->level = target_temp_slot_level;
857 p->level = temp_slot_level;
863 /* Combine temporary stack slots which are adjacent on the stack.
865 This allows for better use of already allocated stack space. This is only
866 done for BLKmode slots because we can be sure that we won't have alignment
867 problems in this case. */
870 combine_temp_slots ()
872 struct temp_slot *p, *q;
873 struct temp_slot *prev_p, *prev_q;
874 /* Determine where to free back to after this function. */
875 rtx free_pointer = rtx_alloc (CONST_INT);
877 for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots)
880 if (! p->in_use && GET_MODE (p->slot) == BLKmode)
881 for (q = p->next, prev_q = p; q; q = prev_q->next)
884 if (! q->in_use && GET_MODE (q->slot) == BLKmode)
886 if (rtx_equal_p (plus_constant (XEXP (p->slot, 0), p->size),
889 /* Q comes after P; combine Q into P. */
893 else if (rtx_equal_p (plus_constant (XEXP (q->slot, 0), q->size),
896 /* P comes after Q; combine P into Q. */
902 /* Either delete Q or advance past it. */
904 prev_q->next = q->next;
908 /* Either delete P or advance past it. */
912 prev_p->next = p->next;
914 temp_slots = p->next;
920 /* Free all the RTL made by plus_constant. */
921 rtx_free (free_pointer);
924 /* Find the temp slot corresponding to the object at address X. */
926 static struct temp_slot *
927 find_temp_slot_from_address (x)
933 for (p = temp_slots; p; p = p->next)
937 else if (XEXP (p->slot, 0) == x
941 else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST)
942 for (next = p->address; next; next = XEXP (next, 1))
943 if (XEXP (next, 0) == x)
950 /* Indicate that NEW is an alternate way of refering to the temp slot
951 that previous was known by OLD. */
954 update_temp_slot_address (old, new)
957 struct temp_slot *p = find_temp_slot_from_address (old);
959 /* If none, return. Else add NEW as an alias. */
962 else if (p->address == 0)
966 if (GET_CODE (p->address) != EXPR_LIST)
967 p->address = gen_rtx (EXPR_LIST, VOIDmode, p->address, NULL_RTX);
969 p->address = gen_rtx (EXPR_LIST, VOIDmode, new, p->address);
973 /* If X could be a reference to a temporary slot, mark that slot as belonging
974 to the to one level higher. If X matched one of our slots, just mark that
975 one. Otherwise, we can't easily predict which it is, so upgrade all of
976 them. Kept slots need not be touched.
978 This is called when an ({...}) construct occurs and a statement
979 returns a value in memory. */
982 preserve_temp_slots (x)
990 /* If X is a register that is being used as a pointer, see if we have
991 a temporary slot we know it points to. To be consistent with
992 the code below, we really should preserve all non-kept slots
993 if we can't find a match, but that seems to be much too costly. */
994 if (GET_CODE (x) == REG && REGNO_POINTER_FLAG (REGNO (x))
995 && (p = find_temp_slot_from_address (x)) != 0)
1001 /* If X is not in memory or is at a constant address, it cannot be in
1002 a temporary slot. */
1003 if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1006 /* First see if we can find a match. */
1007 p = find_temp_slot_from_address (XEXP (x, 0));
1014 /* Otherwise, preserve all non-kept slots at this level. */
1015 for (p = temp_slots; p; p = p->next)
1016 if (p->in_use && p->level == temp_slot_level && ! p->keep)
1020 /* X is the result of an RTL_EXPR. If it is a temporary slot associated
1021 with that RTL_EXPR, promote it into a temporary slot at the present
1022 level so it will not be freed when we free slots made in the
1026 preserve_rtl_expr_result (x)
1029 struct temp_slot *p;
1031 /* If X is not in memory or is at a constant address, it cannot be in
1032 a temporary slot. */
1033 if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1036 /* If we can find a match, move it to our level. */
1037 for (p = temp_slots; p; p = p->next)
1038 if (p->in_use && rtx_equal_p (x, p->slot))
1040 p->level = temp_slot_level;
1048 /* Free all temporaries used so far. This is normally called at the end
1049 of generating code for a statement. Don't free any temporaries
1050 currently in use for an RTL_EXPR that hasn't yet been emitted.
1051 We could eventually do better than this since it can be reused while
1052 generating the same RTL_EXPR, but this is complex and probably not
1058 struct temp_slot *p;
1060 for (p = temp_slots; p; p = p->next)
1061 if (p->in_use && p->level == temp_slot_level && ! p->keep
1062 && p->rtl_expr == 0)
1065 combine_temp_slots ();
1068 /* Free all temporary slots used in T, an RTL_EXPR node. */
1071 free_temps_for_rtl_expr (t)
1074 struct temp_slot *p;
1076 for (p = temp_slots; p; p = p->next)
1077 if (p->rtl_expr == t)
1080 combine_temp_slots ();
1083 /* Push deeper into the nesting level for stack temporaries. */
1091 /* Pop a temporary nesting level. All slots in use in the current level
1097 struct temp_slot *p;
1099 for (p = temp_slots; p; p = p->next)
1100 if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0)
1103 combine_temp_slots ();
1108 /* Retroactively move an auto variable from a register to a stack slot.
1109 This is done when an address-reference to the variable is seen. */
1112 put_var_into_stack (decl)
1116 enum machine_mode promoted_mode, decl_mode;
1117 struct function *function = 0;
1120 if (output_bytecode)
1123 context = decl_function_context (decl);
1125 /* Get the current rtl used for this object and it's original mode. */
1126 reg = TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl) : DECL_RTL (decl);
1128 /* No need to do anything if decl has no rtx yet
1129 since in that case caller is setting TREE_ADDRESSABLE
1130 and a stack slot will be assigned when the rtl is made. */
1134 /* Get the declared mode for this object. */
1135 decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl))
1136 : DECL_MODE (decl));
1137 /* Get the mode it's actually stored in. */
1138 promoted_mode = GET_MODE (reg);
1140 /* If this variable comes from an outer function,
1141 find that function's saved context. */
1142 if (context != current_function_decl)
1143 for (function = outer_function_chain; function; function = function->next)
1144 if (function->decl == context)
1147 /* If this is a variable-size object with a pseudo to address it,
1148 put that pseudo into the stack, if the var is nonlocal. */
1149 if (DECL_NONLOCAL (decl)
1150 && GET_CODE (reg) == MEM
1151 && GET_CODE (XEXP (reg, 0)) == REG
1152 && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
1154 reg = XEXP (reg, 0);
1155 decl_mode = promoted_mode = GET_MODE (reg);
1158 /* Now we should have a value that resides in one or more pseudo regs. */
1160 if (GET_CODE (reg) == REG)
1161 put_reg_into_stack (function, reg, TREE_TYPE (decl),
1162 promoted_mode, decl_mode);
1163 else if (GET_CODE (reg) == CONCAT)
1165 /* A CONCAT contains two pseudos; put them both in the stack.
1166 We do it so they end up consecutive. */
1167 enum machine_mode part_mode = GET_MODE (XEXP (reg, 0));
1168 tree part_type = TREE_TYPE (TREE_TYPE (decl));
1169 #ifdef STACK_GROWS_DOWNWARD
1170 /* Since part 0 should have a lower address, do it second. */
1171 put_reg_into_stack (function, XEXP (reg, 1),
1172 part_type, part_mode, part_mode);
1173 put_reg_into_stack (function, XEXP (reg, 0),
1174 part_type, part_mode, part_mode);
1176 put_reg_into_stack (function, XEXP (reg, 0),
1177 part_type, part_mode, part_mode);
1178 put_reg_into_stack (function, XEXP (reg, 1),
1179 part_type, part_mode, part_mode);
1182 /* Change the CONCAT into a combined MEM for both parts. */
1183 PUT_CODE (reg, MEM);
1184 /* The two parts are in memory order already.
1185 Use the lower parts address as ours. */
1186 XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0);
1187 /* Prevent sharing of rtl that might lose. */
1188 if (GET_CODE (XEXP (reg, 0)) == PLUS)
1189 XEXP (reg, 0) = copy_rtx (XEXP (reg, 0));
1193 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1194 into the stack frame of FUNCTION (0 means the current function).
1195 DECL_MODE is the machine mode of the user-level data type.
1196 PROMOTED_MODE is the machine mode of the register. */
1199 put_reg_into_stack (function, reg, type, promoted_mode, decl_mode)
1200 struct function *function;
1203 enum machine_mode promoted_mode, decl_mode;
1209 if (REGNO (reg) < function->max_parm_reg)
1210 new = function->parm_reg_stack_loc[REGNO (reg)];
1212 new = assign_outer_stack_local (decl_mode, GET_MODE_SIZE (decl_mode),
1217 if (REGNO (reg) < max_parm_reg)
1218 new = parm_reg_stack_loc[REGNO (reg)];
1220 new = assign_stack_local (decl_mode, GET_MODE_SIZE (decl_mode), 0);
1223 XEXP (reg, 0) = XEXP (new, 0);
1224 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1225 REG_USERVAR_P (reg) = 0;
1226 PUT_CODE (reg, MEM);
1227 PUT_MODE (reg, decl_mode);
1229 /* If this is a memory ref that contains aggregate components,
1230 mark it as such for cse and loop optimize. */
1231 MEM_IN_STRUCT_P (reg) = AGGREGATE_TYPE_P (type);
1233 /* Now make sure that all refs to the variable, previously made
1234 when it was a register, are fixed up to be valid again. */
1237 struct var_refs_queue *temp;
1239 /* Variable is inherited; fix it up when we get back to its function. */
1240 push_obstacks (function->function_obstack,
1241 function->function_maybepermanent_obstack);
1243 /* See comment in restore_tree_status in tree.c for why this needs to be
1244 on saveable obstack. */
1246 = (struct var_refs_queue *) savealloc (sizeof (struct var_refs_queue));
1247 temp->modified = reg;
1248 temp->promoted_mode = promoted_mode;
1249 temp->unsignedp = TREE_UNSIGNED (type);
1250 temp->next = function->fixup_var_refs_queue;
1251 function->fixup_var_refs_queue = temp;
1255 /* Variable is local; fix it up now. */
1256 fixup_var_refs (reg, promoted_mode, TREE_UNSIGNED (type));
1260 fixup_var_refs (var, promoted_mode, unsignedp)
1262 enum machine_mode promoted_mode;
1266 rtx first_insn = get_insns ();
1267 struct sequence_stack *stack = sequence_stack;
1268 tree rtl_exps = rtl_expr_chain;
1270 /* Must scan all insns for stack-refs that exceed the limit. */
1271 fixup_var_refs_insns (var, promoted_mode, unsignedp, first_insn, stack == 0);
1273 /* Scan all pending sequences too. */
1274 for (; stack; stack = stack->next)
1276 push_to_sequence (stack->first);
1277 fixup_var_refs_insns (var, promoted_mode, unsignedp,
1278 stack->first, stack->next != 0);
1279 /* Update remembered end of sequence
1280 in case we added an insn at the end. */
1281 stack->last = get_last_insn ();
1285 /* Scan all waiting RTL_EXPRs too. */
1286 for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
1288 rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
1289 if (seq != const0_rtx && seq != 0)
1291 push_to_sequence (seq);
1292 fixup_var_refs_insns (var, promoted_mode, unsignedp, seq, 0);
1298 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1299 some part of an insn. Return a struct fixup_replacement whose OLD
1300 value is equal to X. Allocate a new structure if no such entry exists. */
1302 static struct fixup_replacement *
1303 find_fixup_replacement (replacements, x)
1304 struct fixup_replacement **replacements;
1307 struct fixup_replacement *p;
1309 /* See if we have already replaced this. */
1310 for (p = *replacements; p && p->old != x; p = p->next)
1315 p = (struct fixup_replacement *) oballoc (sizeof (struct fixup_replacement));
1318 p->next = *replacements;
1325 /* Scan the insn-chain starting with INSN for refs to VAR
1326 and fix them up. TOPLEVEL is nonzero if this chain is the
1327 main chain of insns for the current function. */
1330 fixup_var_refs_insns (var, promoted_mode, unsignedp, insn, toplevel)
1332 enum machine_mode promoted_mode;
1341 rtx next = NEXT_INSN (insn);
1343 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1345 /* If this is a CLOBBER of VAR, delete it.
1347 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1348 and REG_RETVAL notes too. */
1349 if (GET_CODE (PATTERN (insn)) == CLOBBER
1350 && XEXP (PATTERN (insn), 0) == var)
1352 if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0)
1353 /* The REG_LIBCALL note will go away since we are going to
1354 turn INSN into a NOTE, so just delete the
1355 corresponding REG_RETVAL note. */
1356 remove_note (XEXP (note, 0),
1357 find_reg_note (XEXP (note, 0), REG_RETVAL,
1360 /* In unoptimized compilation, we shouldn't call delete_insn
1361 except in jump.c doing warnings. */
1362 PUT_CODE (insn, NOTE);
1363 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1364 NOTE_SOURCE_FILE (insn) = 0;
1367 /* The insn to load VAR from a home in the arglist
1368 is now a no-op. When we see it, just delete it. */
1370 && GET_CODE (PATTERN (insn)) == SET
1371 && SET_DEST (PATTERN (insn)) == var
1372 /* If this represents the result of an insn group,
1373 don't delete the insn. */
1374 && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0
1375 && rtx_equal_p (SET_SRC (PATTERN (insn)), var))
1377 /* In unoptimized compilation, we shouldn't call delete_insn
1378 except in jump.c doing warnings. */
1379 PUT_CODE (insn, NOTE);
1380 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1381 NOTE_SOURCE_FILE (insn) = 0;
1382 if (insn == last_parm_insn)
1383 last_parm_insn = PREV_INSN (next);
1387 struct fixup_replacement *replacements = 0;
1388 rtx next_insn = NEXT_INSN (insn);
1390 #ifdef SMALL_REGISTER_CLASSES
1391 /* If the insn that copies the results of a CALL_INSN
1392 into a pseudo now references VAR, we have to use an
1393 intermediate pseudo since we want the life of the
1394 return value register to be only a single insn.
1396 If we don't use an intermediate pseudo, such things as
1397 address computations to make the address of VAR valid
1398 if it is not can be placed beween the CALL_INSN and INSN.
1400 To make sure this doesn't happen, we record the destination
1401 of the CALL_INSN and see if the next insn uses both that
1404 if (call_dest != 0 && GET_CODE (insn) == INSN
1405 && reg_mentioned_p (var, PATTERN (insn))
1406 && reg_mentioned_p (call_dest, PATTERN (insn)))
1408 rtx temp = gen_reg_rtx (GET_MODE (call_dest));
1410 emit_insn_before (gen_move_insn (temp, call_dest), insn);
1412 PATTERN (insn) = replace_rtx (PATTERN (insn),
1416 if (GET_CODE (insn) == CALL_INSN
1417 && GET_CODE (PATTERN (insn)) == SET)
1418 call_dest = SET_DEST (PATTERN (insn));
1419 else if (GET_CODE (insn) == CALL_INSN
1420 && GET_CODE (PATTERN (insn)) == PARALLEL
1421 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
1422 call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
1427 /* See if we have to do anything to INSN now that VAR is in
1428 memory. If it needs to be loaded into a pseudo, use a single
1429 pseudo for the entire insn in case there is a MATCH_DUP
1430 between two operands. We pass a pointer to the head of
1431 a list of struct fixup_replacements. If fixup_var_refs_1
1432 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1433 it will record them in this list.
1435 If it allocated a pseudo for any replacement, we copy into
1438 fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn,
1441 /* If this is last_parm_insn, and any instructions were output
1442 after it to fix it up, then we must set last_parm_insn to
1443 the last such instruction emitted. */
1444 if (insn == last_parm_insn)
1445 last_parm_insn = PREV_INSN (next_insn);
1447 while (replacements)
1449 if (GET_CODE (replacements->new) == REG)
1454 /* OLD might be a (subreg (mem)). */
1455 if (GET_CODE (replacements->old) == SUBREG)
1457 = fixup_memory_subreg (replacements->old, insn, 0);
1460 = fixup_stack_1 (replacements->old, insn);
1462 insert_before = insn;
1464 /* If we are changing the mode, do a conversion.
1465 This might be wasteful, but combine.c will
1466 eliminate much of the waste. */
1468 if (GET_MODE (replacements->new)
1469 != GET_MODE (replacements->old))
1472 convert_move (replacements->new,
1473 replacements->old, unsignedp);
1474 seq = gen_sequence ();
1478 seq = gen_move_insn (replacements->new,
1481 emit_insn_before (seq, insert_before);
1484 replacements = replacements->next;
1488 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1489 But don't touch other insns referred to by reg-notes;
1490 we will get them elsewhere. */
1491 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
1492 if (GET_CODE (note) != INSN_LIST)
1494 = walk_fixup_memory_subreg (XEXP (note, 0), insn, 1);
1500 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1501 See if the rtx expression at *LOC in INSN needs to be changed.
1503 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1504 contain a list of original rtx's and replacements. If we find that we need
1505 to modify this insn by replacing a memory reference with a pseudo or by
1506 making a new MEM to implement a SUBREG, we consult that list to see if
1507 we have already chosen a replacement. If none has already been allocated,
1508 we allocate it and update the list. fixup_var_refs_insns will copy VAR
1509 or the SUBREG, as appropriate, to the pseudo. */
1512 fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements)
1514 enum machine_mode promoted_mode;
1517 struct fixup_replacement **replacements;
1520 register rtx x = *loc;
1521 RTX_CODE code = GET_CODE (x);
1523 register rtx tem, tem1;
1524 struct fixup_replacement *replacement;
1531 /* If we already have a replacement, use it. Otherwise,
1532 try to fix up this address in case it is invalid. */
1534 replacement = find_fixup_replacement (replacements, var);
1535 if (replacement->new)
1537 *loc = replacement->new;
1541 *loc = replacement->new = x = fixup_stack_1 (x, insn);
1543 /* Unless we are forcing memory to register or we changed the mode,
1544 we can leave things the way they are if the insn is valid. */
1546 INSN_CODE (insn) = -1;
1547 if (! flag_force_mem && GET_MODE (x) == promoted_mode
1548 && recog_memoized (insn) >= 0)
1551 *loc = replacement->new = gen_reg_rtx (promoted_mode);
1555 /* If X contains VAR, we need to unshare it here so that we update
1556 each occurrence separately. But all identical MEMs in one insn
1557 must be replaced with the same rtx because of the possibility of
1560 if (reg_mentioned_p (var, x))
1562 replacement = find_fixup_replacement (replacements, x);
1563 if (replacement->new == 0)
1564 replacement->new = copy_most_rtx (x, var);
1566 *loc = x = replacement->new;
1582 /* Note that in some cases those types of expressions are altered
1583 by optimize_bit_field, and do not survive to get here. */
1584 if (XEXP (x, 0) == var
1585 || (GET_CODE (XEXP (x, 0)) == SUBREG
1586 && SUBREG_REG (XEXP (x, 0)) == var))
1588 /* Get TEM as a valid MEM in the mode presently in the insn.
1590 We don't worry about the possibility of MATCH_DUP here; it
1591 is highly unlikely and would be tricky to handle. */
1594 if (GET_CODE (tem) == SUBREG)
1595 tem = fixup_memory_subreg (tem, insn, 1);
1596 tem = fixup_stack_1 (tem, insn);
1598 /* Unless we want to load from memory, get TEM into the proper mode
1599 for an extract from memory. This can only be done if the
1600 extract is at a constant position and length. */
1602 if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
1603 && GET_CODE (XEXP (x, 2)) == CONST_INT
1604 && ! mode_dependent_address_p (XEXP (tem, 0))
1605 && ! MEM_VOLATILE_P (tem))
1607 enum machine_mode wanted_mode = VOIDmode;
1608 enum machine_mode is_mode = GET_MODE (tem);
1609 int width = INTVAL (XEXP (x, 1));
1610 int pos = INTVAL (XEXP (x, 2));
1613 if (GET_CODE (x) == ZERO_EXTRACT)
1614 wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
1617 if (GET_CODE (x) == SIGN_EXTRACT)
1618 wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
1620 /* If we have a narrower mode, we can do something. */
1621 if (wanted_mode != VOIDmode
1622 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
1624 int offset = pos / BITS_PER_UNIT;
1625 rtx old_pos = XEXP (x, 2);
1628 /* If the bytes and bits are counted differently, we
1629 must adjust the offset. */
1630 #if BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN
1631 offset = (GET_MODE_SIZE (is_mode)
1632 - GET_MODE_SIZE (wanted_mode) - offset);
1635 pos %= GET_MODE_BITSIZE (wanted_mode);
1637 newmem = gen_rtx (MEM, wanted_mode,
1638 plus_constant (XEXP (tem, 0), offset));
1639 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
1640 MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
1641 MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
1643 /* Make the change and see if the insn remains valid. */
1644 INSN_CODE (insn) = -1;
1645 XEXP (x, 0) = newmem;
1646 XEXP (x, 2) = GEN_INT (pos);
1648 if (recog_memoized (insn) >= 0)
1651 /* Otherwise, restore old position. XEXP (x, 0) will be
1653 XEXP (x, 2) = old_pos;
1657 /* If we get here, the bitfield extract insn can't accept a memory
1658 reference. Copy the input into a register. */
1660 tem1 = gen_reg_rtx (GET_MODE (tem));
1661 emit_insn_before (gen_move_insn (tem1, tem), insn);
1668 if (SUBREG_REG (x) == var)
1670 /* If this is a special SUBREG made because VAR was promoted
1671 from a wider mode, replace it with VAR and call ourself
1672 recursively, this time saying that the object previously
1673 had its current mode (by virtue of the SUBREG). */
1675 if (SUBREG_PROMOTED_VAR_P (x))
1678 fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements);
1682 /* If this SUBREG makes VAR wider, it has become a paradoxical
1683 SUBREG with VAR in memory, but these aren't allowed at this
1684 stage of the compilation. So load VAR into a pseudo and take
1685 a SUBREG of that pseudo. */
1686 if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
1688 replacement = find_fixup_replacement (replacements, var);
1689 if (replacement->new == 0)
1690 replacement->new = gen_reg_rtx (GET_MODE (var));
1691 SUBREG_REG (x) = replacement->new;
1695 /* See if we have already found a replacement for this SUBREG.
1696 If so, use it. Otherwise, make a MEM and see if the insn
1697 is recognized. If not, or if we should force MEM into a register,
1698 make a pseudo for this SUBREG. */
1699 replacement = find_fixup_replacement (replacements, x);
1700 if (replacement->new)
1702 *loc = replacement->new;
1706 replacement->new = *loc = fixup_memory_subreg (x, insn, 0);
1708 INSN_CODE (insn) = -1;
1709 if (! flag_force_mem && recog_memoized (insn) >= 0)
1712 *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
1718 /* First do special simplification of bit-field references. */
1719 if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
1720 || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
1721 optimize_bit_field (x, insn, 0);
1722 if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
1723 || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
1724 optimize_bit_field (x, insn, NULL_PTR);
1726 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
1727 insn into a pseudo and store the low part of the pseudo into VAR. */
1728 if (GET_CODE (SET_DEST (x)) == SUBREG
1729 && SUBREG_REG (SET_DEST (x)) == var
1730 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
1731 > GET_MODE_SIZE (GET_MODE (var))))
1733 SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
1734 emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
1741 rtx dest = SET_DEST (x);
1742 rtx src = SET_SRC (x);
1743 rtx outerdest = dest;
1745 while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
1746 || GET_CODE (dest) == SIGN_EXTRACT
1747 || GET_CODE (dest) == ZERO_EXTRACT)
1748 dest = XEXP (dest, 0);
1750 if (GET_CODE (src) == SUBREG)
1751 src = XEXP (src, 0);
1753 /* If VAR does not appear at the top level of the SET
1754 just scan the lower levels of the tree. */
1756 if (src != var && dest != var)
1759 /* We will need to rerecognize this insn. */
1760 INSN_CODE (insn) = -1;
1763 if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var)
1765 /* Since this case will return, ensure we fixup all the
1767 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1),
1768 insn, replacements);
1769 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2),
1770 insn, replacements);
1771 fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x),
1772 insn, replacements);
1774 tem = XEXP (outerdest, 0);
1776 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
1777 that may appear inside a ZERO_EXTRACT.
1778 This was legitimate when the MEM was a REG. */
1779 if (GET_CODE (tem) == SUBREG
1780 && SUBREG_REG (tem) == var)
1781 tem = fixup_memory_subreg (tem, insn, 1);
1783 tem = fixup_stack_1 (tem, insn);
1785 if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
1786 && GET_CODE (XEXP (outerdest, 2)) == CONST_INT
1787 && ! mode_dependent_address_p (XEXP (tem, 0))
1788 && ! MEM_VOLATILE_P (tem))
1790 enum machine_mode wanted_mode
1791 = insn_operand_mode[(int) CODE_FOR_insv][0];
1792 enum machine_mode is_mode = GET_MODE (tem);
1793 int width = INTVAL (XEXP (outerdest, 1));
1794 int pos = INTVAL (XEXP (outerdest, 2));
1796 /* If we have a narrower mode, we can do something. */
1797 if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
1799 int offset = pos / BITS_PER_UNIT;
1800 rtx old_pos = XEXP (outerdest, 2);
1803 #if BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN
1804 offset = (GET_MODE_SIZE (is_mode)
1805 - GET_MODE_SIZE (wanted_mode) - offset);
1808 pos %= GET_MODE_BITSIZE (wanted_mode);
1810 newmem = gen_rtx (MEM, wanted_mode,
1811 plus_constant (XEXP (tem, 0), offset));
1812 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
1813 MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
1814 MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
1816 /* Make the change and see if the insn remains valid. */
1817 INSN_CODE (insn) = -1;
1818 XEXP (outerdest, 0) = newmem;
1819 XEXP (outerdest, 2) = GEN_INT (pos);
1821 if (recog_memoized (insn) >= 0)
1824 /* Otherwise, restore old position. XEXP (x, 0) will be
1826 XEXP (outerdest, 2) = old_pos;
1830 /* If we get here, the bit-field store doesn't allow memory
1831 or isn't located at a constant position. Load the value into
1832 a register, do the store, and put it back into memory. */
1834 tem1 = gen_reg_rtx (GET_MODE (tem));
1835 emit_insn_before (gen_move_insn (tem1, tem), insn);
1836 emit_insn_after (gen_move_insn (tem, tem1), insn);
1837 XEXP (outerdest, 0) = tem1;
1842 /* STRICT_LOW_PART is a no-op on memory references
1843 and it can cause combinations to be unrecognizable,
1846 if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
1847 SET_DEST (x) = XEXP (SET_DEST (x), 0);
1849 /* A valid insn to copy VAR into or out of a register
1850 must be left alone, to avoid an infinite loop here.
1851 If the reference to VAR is by a subreg, fix that up,
1852 since SUBREG is not valid for a memref.
1853 Also fix up the address of the stack slot.
1855 Note that we must not try to recognize the insn until
1856 after we know that we have valid addresses and no
1857 (subreg (mem ...) ...) constructs, since these interfere
1858 with determining the validity of the insn. */
1860 if ((SET_SRC (x) == var
1861 || (GET_CODE (SET_SRC (x)) == SUBREG
1862 && SUBREG_REG (SET_SRC (x)) == var))
1863 && (GET_CODE (SET_DEST (x)) == REG
1864 || (GET_CODE (SET_DEST (x)) == SUBREG
1865 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
1866 && x == single_set (PATTERN (insn)))
1870 replacement = find_fixup_replacement (replacements, SET_SRC (x));
1871 if (replacement->new)
1872 SET_SRC (x) = replacement->new;
1873 else if (GET_CODE (SET_SRC (x)) == SUBREG)
1874 SET_SRC (x) = replacement->new
1875 = fixup_memory_subreg (SET_SRC (x), insn, 0);
1877 SET_SRC (x) = replacement->new
1878 = fixup_stack_1 (SET_SRC (x), insn);
1880 if (recog_memoized (insn) >= 0)
1883 /* INSN is not valid, but we know that we want to
1884 copy SET_SRC (x) to SET_DEST (x) in some way. So
1885 we generate the move and see whether it requires more
1886 than one insn. If it does, we emit those insns and
1887 delete INSN. Otherwise, we an just replace the pattern
1888 of INSN; we have already verified above that INSN has
1889 no other function that to do X. */
1891 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
1892 if (GET_CODE (pat) == SEQUENCE)
1894 emit_insn_after (pat, insn);
1895 PUT_CODE (insn, NOTE);
1896 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1897 NOTE_SOURCE_FILE (insn) = 0;
1900 PATTERN (insn) = pat;
1905 if ((SET_DEST (x) == var
1906 || (GET_CODE (SET_DEST (x)) == SUBREG
1907 && SUBREG_REG (SET_DEST (x)) == var))
1908 && (GET_CODE (SET_SRC (x)) == REG
1909 || (GET_CODE (SET_SRC (x)) == SUBREG
1910 && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
1911 && x == single_set (PATTERN (insn)))
1915 if (GET_CODE (SET_DEST (x)) == SUBREG)
1916 SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn, 0);
1918 SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
1920 if (recog_memoized (insn) >= 0)
1923 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
1924 if (GET_CODE (pat) == SEQUENCE)
1926 emit_insn_after (pat, insn);
1927 PUT_CODE (insn, NOTE);
1928 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1929 NOTE_SOURCE_FILE (insn) = 0;
1932 PATTERN (insn) = pat;
1937 /* Otherwise, storing into VAR must be handled specially
1938 by storing into a temporary and copying that into VAR
1939 with a new insn after this one. Note that this case
1940 will be used when storing into a promoted scalar since
1941 the insn will now have different modes on the input
1942 and output and hence will be invalid (except for the case
1943 of setting it to a constant, which does not need any
1944 change if it is valid). We generate extra code in that case,
1945 but combine.c will eliminate it. */
1950 rtx fixeddest = SET_DEST (x);
1952 /* STRICT_LOW_PART can be discarded, around a MEM. */
1953 if (GET_CODE (fixeddest) == STRICT_LOW_PART)
1954 fixeddest = XEXP (fixeddest, 0);
1955 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
1956 if (GET_CODE (fixeddest) == SUBREG)
1957 fixeddest = fixup_memory_subreg (fixeddest, insn, 0);
1959 fixeddest = fixup_stack_1 (fixeddest, insn);
1961 temp = gen_reg_rtx (GET_MODE (SET_SRC (x)) == VOIDmode
1962 ? GET_MODE (fixeddest)
1963 : GET_MODE (SET_SRC (x)));
1965 emit_insn_after (gen_move_insn (fixeddest,
1966 gen_lowpart (GET_MODE (fixeddest),
1970 SET_DEST (x) = temp;
1975 /* Nothing special about this RTX; fix its operands. */
1977 fmt = GET_RTX_FORMAT (code);
1978 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1981 fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements);
1985 for (j = 0; j < XVECLEN (x, i); j++)
1986 fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j),
1987 insn, replacements);
1992 /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
1993 return an rtx (MEM:m1 newaddr) which is equivalent.
1994 If any insns must be emitted to compute NEWADDR, put them before INSN.
1996 UNCRITICAL nonzero means accept paradoxical subregs.
1997 This is used for subregs found inside of ZERO_EXTRACTs and in REG_NOTES. */
2000 fixup_memory_subreg (x, insn, uncritical)
2005 int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
2006 rtx addr = XEXP (SUBREG_REG (x), 0);
2007 enum machine_mode mode = GET_MODE (x);
2010 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2011 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
2015 #if BYTES_BIG_ENDIAN
2016 offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
2017 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
2019 addr = plus_constant (addr, offset);
2020 if (!flag_force_addr && memory_address_p (mode, addr))
2021 /* Shortcut if no insns need be emitted. */
2022 return change_address (SUBREG_REG (x), mode, addr);
2024 result = change_address (SUBREG_REG (x), mode, addr);
2025 emit_insn_before (gen_sequence (), insn);
2030 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2031 Replace subexpressions of X in place.
2032 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2033 Otherwise return X, with its contents possibly altered.
2035 If any insns must be emitted to compute NEWADDR, put them before INSN.
2037 UNCRITICAL is as in fixup_memory_subreg. */
2040 walk_fixup_memory_subreg (x, insn, uncritical)
2045 register enum rtx_code code;
2052 code = GET_CODE (x);
2054 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
2055 return fixup_memory_subreg (x, insn, uncritical);
2057 /* Nothing special about this RTX; fix its operands. */
2059 fmt = GET_RTX_FORMAT (code);
2060 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2063 XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn, uncritical);
2067 for (j = 0; j < XVECLEN (x, i); j++)
2069 = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn, uncritical);
2075 /* For each memory ref within X, if it refers to a stack slot
2076 with an out of range displacement, put the address in a temp register
2077 (emitting new insns before INSN to load these registers)
2078 and alter the memory ref to use that register.
2079 Replace each such MEM rtx with a copy, to avoid clobberage. */
2082 fixup_stack_1 (x, insn)
2087 register RTX_CODE code = GET_CODE (x);
2092 register rtx ad = XEXP (x, 0);
2093 /* If we have address of a stack slot but it's not valid
2094 (displacement is too large), compute the sum in a register. */
2095 if (GET_CODE (ad) == PLUS
2096 && GET_CODE (XEXP (ad, 0)) == REG
2097 && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
2098 && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER)
2099 || XEXP (ad, 0) == current_function_internal_arg_pointer)
2100 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
2103 if (memory_address_p (GET_MODE (x), ad))
2107 temp = copy_to_reg (ad);
2108 seq = gen_sequence ();
2110 emit_insn_before (seq, insn);
2111 return change_address (x, VOIDmode, temp);
2116 fmt = GET_RTX_FORMAT (code);
2117 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2120 XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
2124 for (j = 0; j < XVECLEN (x, i); j++)
2125 XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
2131 /* Optimization: a bit-field instruction whose field
2132 happens to be a byte or halfword in memory
2133 can be changed to a move instruction.
2135 We call here when INSN is an insn to examine or store into a bit-field.
2136 BODY is the SET-rtx to be altered.
2138 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2139 (Currently this is called only from function.c, and EQUIV_MEM
2143 optimize_bit_field (body, insn, equiv_mem)
2148 register rtx bitfield;
2151 enum machine_mode mode;
2153 if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
2154 || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
2155 bitfield = SET_DEST (body), destflag = 1;
2157 bitfield = SET_SRC (body), destflag = 0;
2159 /* First check that the field being stored has constant size and position
2160 and is in fact a byte or halfword suitably aligned. */
2162 if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
2163 && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
2164 && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
2166 && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
2168 register rtx memref = 0;
2170 /* Now check that the containing word is memory, not a register,
2171 and that it is safe to change the machine mode. */
2173 if (GET_CODE (XEXP (bitfield, 0)) == MEM)
2174 memref = XEXP (bitfield, 0);
2175 else if (GET_CODE (XEXP (bitfield, 0)) == REG
2177 memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
2178 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2179 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
2180 memref = SUBREG_REG (XEXP (bitfield, 0));
2181 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2183 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
2184 memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
2187 && ! mode_dependent_address_p (XEXP (memref, 0))
2188 && ! MEM_VOLATILE_P (memref))
2190 /* Now adjust the address, first for any subreg'ing
2191 that we are now getting rid of,
2192 and then for which byte of the word is wanted. */
2194 register int offset = INTVAL (XEXP (bitfield, 2));
2197 /* Adjust OFFSET to count bits from low-address byte. */
2198 #if BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN
2199 offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
2200 - offset - INTVAL (XEXP (bitfield, 1)));
2202 /* Adjust OFFSET to count bytes from low-address byte. */
2203 offset /= BITS_PER_UNIT;
2204 if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
2206 offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD;
2207 #if BYTES_BIG_ENDIAN
2208 offset -= (MIN (UNITS_PER_WORD,
2209 GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
2210 - MIN (UNITS_PER_WORD,
2211 GET_MODE_SIZE (GET_MODE (memref))));
2216 memref = change_address (memref, mode,
2217 plus_constant (XEXP (memref, 0), offset));
2218 insns = get_insns ();
2220 emit_insns_before (insns, insn);
2222 /* Store this memory reference where
2223 we found the bit field reference. */
2227 validate_change (insn, &SET_DEST (body), memref, 1);
2228 if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
2230 rtx src = SET_SRC (body);
2231 while (GET_CODE (src) == SUBREG
2232 && SUBREG_WORD (src) == 0)
2233 src = SUBREG_REG (src);
2234 if (GET_MODE (src) != GET_MODE (memref))
2235 src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
2236 validate_change (insn, &SET_SRC (body), src, 1);
2238 else if (GET_MODE (SET_SRC (body)) != VOIDmode
2239 && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
2240 /* This shouldn't happen because anything that didn't have
2241 one of these modes should have got converted explicitly
2242 and then referenced through a subreg.
2243 This is so because the original bit-field was
2244 handled by agg_mode and so its tree structure had
2245 the same mode that memref now has. */
2250 rtx dest = SET_DEST (body);
2252 while (GET_CODE (dest) == SUBREG
2253 && SUBREG_WORD (dest) == 0)
2254 dest = SUBREG_REG (dest);
2256 validate_change (insn, &SET_DEST (body), dest, 1);
2258 if (GET_MODE (dest) == GET_MODE (memref))
2259 validate_change (insn, &SET_SRC (body), memref, 1);
2262 /* Convert the mem ref to the destination mode. */
2263 rtx newreg = gen_reg_rtx (GET_MODE (dest));
2266 convert_move (newreg, memref,
2267 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
2271 validate_change (insn, &SET_SRC (body), newreg, 1);
2275 /* See if we can convert this extraction or insertion into
2276 a simple move insn. We might not be able to do so if this
2277 was, for example, part of a PARALLEL.
2279 If we succeed, write out any needed conversions. If we fail,
2280 it is hard to guess why we failed, so don't do anything
2281 special; just let the optimization be suppressed. */
2283 if (apply_change_group () && seq)
2284 emit_insns_before (seq, insn);
2289 /* These routines are responsible for converting virtual register references
2290 to the actual hard register references once RTL generation is complete.
2292 The following four variables are used for communication between the
2293 routines. They contain the offsets of the virtual registers from their
2294 respective hard registers. */
2296 static int in_arg_offset;
2297 static int var_offset;
2298 static int dynamic_offset;
2299 static int out_arg_offset;
2301 /* In most machines, the stack pointer register is equivalent to the bottom
2304 #ifndef STACK_POINTER_OFFSET
2305 #define STACK_POINTER_OFFSET 0
2308 /* If not defined, pick an appropriate default for the offset of dynamically
2309 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2310 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2312 #ifndef STACK_DYNAMIC_OFFSET
2314 #ifdef ACCUMULATE_OUTGOING_ARGS
2315 /* The bottom of the stack points to the actual arguments. If
2316 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2317 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2318 stack space for register parameters is not pushed by the caller, but
2319 rather part of the fixed stack areas and hence not included in
2320 `current_function_outgoing_args_size'. Nevertheless, we must allow
2321 for it when allocating stack dynamic objects. */
2323 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2324 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2325 (current_function_outgoing_args_size \
2326 + REG_PARM_STACK_SPACE (FNDECL) + (STACK_POINTER_OFFSET))
2329 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2330 (current_function_outgoing_args_size + (STACK_POINTER_OFFSET))
2334 #define STACK_DYNAMIC_OFFSET(FNDECL) STACK_POINTER_OFFSET
2338 /* Pass through the INSNS of function FNDECL and convert virtual register
2339 references to hard register references. */
2342 instantiate_virtual_regs (fndecl, insns)
2348 /* Compute the offsets to use for this function. */
2349 in_arg_offset = FIRST_PARM_OFFSET (fndecl);
2350 var_offset = STARTING_FRAME_OFFSET;
2351 dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
2352 out_arg_offset = STACK_POINTER_OFFSET;
2354 /* Scan all variables and parameters of this function. For each that is
2355 in memory, instantiate all virtual registers if the result is a valid
2356 address. If not, we do it later. That will handle most uses of virtual
2357 regs on many machines. */
2358 instantiate_decls (fndecl, 1);
2360 /* Initialize recognition, indicating that volatile is OK. */
2363 /* Scan through all the insns, instantiating every virtual register still
2365 for (insn = insns; insn; insn = NEXT_INSN (insn))
2366 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
2367 || GET_CODE (insn) == CALL_INSN)
2369 instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1);
2370 instantiate_virtual_regs_1 (®_NOTES (insn), NULL_RTX, 0);
2373 /* Now instantiate the remaining register equivalences for debugging info.
2374 These will not be valid addresses. */
2375 instantiate_decls (fndecl, 0);
2377 /* Indicate that, from now on, assign_stack_local should use
2378 frame_pointer_rtx. */
2379 virtuals_instantiated = 1;
2382 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
2383 all virtual registers in their DECL_RTL's.
2385 If VALID_ONLY, do this only if the resulting address is still valid.
2386 Otherwise, always do it. */
2389 instantiate_decls (fndecl, valid_only)
2395 if (DECL_INLINE (fndecl))
2396 /* When compiling an inline function, the obstack used for
2397 rtl allocation is the maybepermanent_obstack. Calling
2398 `resume_temporary_allocation' switches us back to that
2399 obstack while we process this function's parameters. */
2400 resume_temporary_allocation ();
2402 /* Process all parameters of the function. */
2403 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
2405 instantiate_decl (DECL_RTL (decl), int_size_in_bytes (TREE_TYPE (decl)),
2407 instantiate_decl (DECL_INCOMING_RTL (decl),
2408 int_size_in_bytes (TREE_TYPE (decl)), valid_only);
2411 /* Now process all variables defined in the function or its subblocks. */
2412 instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
2414 if (DECL_INLINE (fndecl))
2416 /* Save all rtl allocated for this function by raising the
2417 high-water mark on the maybepermanent_obstack. */
2419 /* All further rtl allocation is now done in the current_obstack. */
2420 rtl_in_current_obstack ();
2424 /* Subroutine of instantiate_decls: Process all decls in the given
2425 BLOCK node and all its subblocks. */
2428 instantiate_decls_1 (let, valid_only)
2434 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
2435 instantiate_decl (DECL_RTL (t), int_size_in_bytes (TREE_TYPE (t)),
2438 /* Process all subblocks. */
2439 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
2440 instantiate_decls_1 (t, valid_only);
2443 /* Subroutine of the preceding procedures: Given RTL representing a
2444 decl and the size of the object, do any instantiation required.
2446 If VALID_ONLY is non-zero, it means that the RTL should only be
2447 changed if the new address is valid. */
2450 instantiate_decl (x, size, valid_only)
2455 enum machine_mode mode;
2458 /* If this is not a MEM, no need to do anything. Similarly if the
2459 address is a constant or a register that is not a virtual register. */
2461 if (x == 0 || GET_CODE (x) != MEM)
2465 if (CONSTANT_P (addr)
2466 || (GET_CODE (addr) == REG
2467 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
2468 || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
2471 /* If we should only do this if the address is valid, copy the address.
2472 We need to do this so we can undo any changes that might make the
2473 address invalid. This copy is unfortunate, but probably can't be
2477 addr = copy_rtx (addr);
2479 instantiate_virtual_regs_1 (&addr, NULL_RTX, 0);
2484 /* Now verify that the resulting address is valid for every integer or
2485 floating-point mode up to and including SIZE bytes long. We do this
2486 since the object might be accessed in any mode and frame addresses
2489 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2490 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
2491 mode = GET_MODE_WIDER_MODE (mode))
2492 if (! memory_address_p (mode, addr))
2495 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
2496 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
2497 mode = GET_MODE_WIDER_MODE (mode))
2498 if (! memory_address_p (mode, addr))
2501 /* Otherwise, put back the address, now that we have updated it and we
2502 know it is valid. */
2507 /* Given a pointer to a piece of rtx and an optional pointer to the
2508 containing object, instantiate any virtual registers present in it.
2510 If EXTRA_INSNS, we always do the replacement and generate
2511 any extra insns before OBJECT. If it zero, we do nothing if replacement
2514 Return 1 if we either had nothing to do or if we were able to do the
2515 needed replacement. Return 0 otherwise; we only return zero if
2516 EXTRA_INSNS is zero.
2518 We first try some simple transformations to avoid the creation of extra
2522 instantiate_virtual_regs_1 (loc, object, extra_insns)
2536 /* Re-start here to avoid recursion in common cases. */
2543 code = GET_CODE (x);
2545 /* Check for some special cases. */
2562 /* We are allowed to set the virtual registers. This means that
2563 that the actual register should receive the source minus the
2564 appropriate offset. This is used, for example, in the handling
2565 of non-local gotos. */
2566 if (SET_DEST (x) == virtual_incoming_args_rtx)
2567 new = arg_pointer_rtx, offset = - in_arg_offset;
2568 else if (SET_DEST (x) == virtual_stack_vars_rtx)
2569 new = frame_pointer_rtx, offset = - var_offset;
2570 else if (SET_DEST (x) == virtual_stack_dynamic_rtx)
2571 new = stack_pointer_rtx, offset = - dynamic_offset;
2572 else if (SET_DEST (x) == virtual_outgoing_args_rtx)
2573 new = stack_pointer_rtx, offset = - out_arg_offset;
2577 /* The only valid sources here are PLUS or REG. Just do
2578 the simplest possible thing to handle them. */
2579 if (GET_CODE (SET_SRC (x)) != REG
2580 && GET_CODE (SET_SRC (x)) != PLUS)
2584 if (GET_CODE (SET_SRC (x)) != REG)
2585 temp = force_operand (SET_SRC (x), NULL_RTX);
2588 temp = force_operand (plus_constant (temp, offset), NULL_RTX);
2592 emit_insns_before (seq, object);
2595 if (!validate_change (object, &SET_SRC (x), temp, 0)
2602 instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns);
2607 /* Handle special case of virtual register plus constant. */
2608 if (CONSTANT_P (XEXP (x, 1)))
2612 /* Check for (plus (plus VIRT foo) (const_int)) first. */
2613 if (GET_CODE (XEXP (x, 0)) == PLUS)
2615 rtx inner = XEXP (XEXP (x, 0), 0);
2617 if (inner == virtual_incoming_args_rtx)
2618 new = arg_pointer_rtx, offset = in_arg_offset;
2619 else if (inner == virtual_stack_vars_rtx)
2620 new = frame_pointer_rtx, offset = var_offset;
2621 else if (inner == virtual_stack_dynamic_rtx)
2622 new = stack_pointer_rtx, offset = dynamic_offset;
2623 else if (inner == virtual_outgoing_args_rtx)
2624 new = stack_pointer_rtx, offset = out_arg_offset;
2631 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object,
2633 new = gen_rtx (PLUS, Pmode, new, XEXP (XEXP (x, 0), 1));
2636 else if (XEXP (x, 0) == virtual_incoming_args_rtx)
2637 new = arg_pointer_rtx, offset = in_arg_offset;
2638 else if (XEXP (x, 0) == virtual_stack_vars_rtx)
2639 new = frame_pointer_rtx, offset = var_offset;
2640 else if (XEXP (x, 0) == virtual_stack_dynamic_rtx)
2641 new = stack_pointer_rtx, offset = dynamic_offset;
2642 else if (XEXP (x, 0) == virtual_outgoing_args_rtx)
2643 new = stack_pointer_rtx, offset = out_arg_offset;
2646 /* We know the second operand is a constant. Unless the
2647 first operand is a REG (which has been already checked),
2648 it needs to be checked. */
2649 if (GET_CODE (XEXP (x, 0)) != REG)
2659 new = plus_constant (XEXP (x, 1), offset);
2661 /* If the new constant is zero, try to replace the sum with its
2663 if (new == const0_rtx
2664 && validate_change (object, loc, XEXP (x, 0), 0))
2667 /* Next try to replace constant with new one. */
2668 if (!validate_change (object, &XEXP (x, 1), new, 0))
2676 /* Otherwise copy the new constant into a register and replace
2677 constant with that register. */
2678 temp = gen_reg_rtx (Pmode);
2679 if (validate_change (object, &XEXP (x, 1), temp, 0))
2680 emit_insn_before (gen_move_insn (temp, new), object);
2683 /* If that didn't work, replace this expression with a
2684 register containing the sum. */
2686 new = gen_rtx (PLUS, Pmode, XEXP (x, 0), new);
2690 temp = force_operand (new, NULL_RTX);
2694 emit_insns_before (seq, object);
2695 if (! validate_change (object, loc, temp, 0)
2696 && ! validate_replace_rtx (x, temp, object))
2704 /* Fall through to generic two-operand expression case. */
2710 case DIV: case UDIV:
2711 case MOD: case UMOD:
2712 case AND: case IOR: case XOR:
2713 case ROTATERT: case ROTATE:
2714 case ASHIFTRT: case LSHIFTRT: case ASHIFT:
2716 case GE: case GT: case GEU: case GTU:
2717 case LE: case LT: case LEU: case LTU:
2718 if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
2719 instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns);
2724 /* Most cases of MEM that convert to valid addresses have already been
2725 handled by our scan of regno_reg_rtx. The only special handling we
2726 need here is to make a copy of the rtx to ensure it isn't being
2727 shared if we have to change it to a pseudo.
2729 If the rtx is a simple reference to an address via a virtual register,
2730 it can potentially be shared. In such cases, first try to make it
2731 a valid address, which can also be shared. Otherwise, copy it and
2734 First check for common cases that need no processing. These are
2735 usually due to instantiation already being done on a previous instance
2739 if (CONSTANT_ADDRESS_P (temp)
2740 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2741 || temp == arg_pointer_rtx
2743 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2744 || temp == hard_frame_pointer_rtx
2746 || temp == frame_pointer_rtx)
2749 if (GET_CODE (temp) == PLUS
2750 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
2751 && (XEXP (temp, 0) == frame_pointer_rtx
2752 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2753 || XEXP (temp, 0) == hard_frame_pointer_rtx
2755 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2756 || XEXP (temp, 0) == arg_pointer_rtx
2761 if (temp == virtual_stack_vars_rtx
2762 || temp == virtual_incoming_args_rtx
2763 || (GET_CODE (temp) == PLUS
2764 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
2765 && (XEXP (temp, 0) == virtual_stack_vars_rtx
2766 || XEXP (temp, 0) == virtual_incoming_args_rtx)))
2768 /* This MEM may be shared. If the substitution can be done without
2769 the need to generate new pseudos, we want to do it in place
2770 so all copies of the shared rtx benefit. The call below will
2771 only make substitutions if the resulting address is still
2774 Note that we cannot pass X as the object in the recursive call
2775 since the insn being processed may not allow all valid
2776 addresses. However, if we were not passed on object, we can
2777 only modify X without copying it if X will have a valid
2780 ??? Also note that this can still lose if OBJECT is an insn that
2781 has less restrictions on an address that some other insn.
2782 In that case, we will modify the shared address. This case
2783 doesn't seem very likely, though. */
2785 if (instantiate_virtual_regs_1 (&XEXP (x, 0),
2786 object ? object : x, 0))
2789 /* Otherwise make a copy and process that copy. We copy the entire
2790 RTL expression since it might be a PLUS which could also be
2792 *loc = x = copy_rtx (x);
2795 /* Fall through to generic unary operation case. */
2799 case STRICT_LOW_PART:
2801 case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC:
2802 case SIGN_EXTEND: case ZERO_EXTEND:
2803 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE:
2804 case FLOAT: case FIX:
2805 case UNSIGNED_FIX: case UNSIGNED_FLOAT:
2809 /* These case either have just one operand or we know that we need not
2810 check the rest of the operands. */
2815 /* Try to replace with a PLUS. If that doesn't work, compute the sum
2816 in front of this insn and substitute the temporary. */
2817 if (x == virtual_incoming_args_rtx)
2818 new = arg_pointer_rtx, offset = in_arg_offset;
2819 else if (x == virtual_stack_vars_rtx)
2820 new = frame_pointer_rtx, offset = var_offset;
2821 else if (x == virtual_stack_dynamic_rtx)
2822 new = stack_pointer_rtx, offset = dynamic_offset;
2823 else if (x == virtual_outgoing_args_rtx)
2824 new = stack_pointer_rtx, offset = out_arg_offset;
2828 temp = plus_constant (new, offset);
2829 if (!validate_change (object, loc, temp, 0))
2835 temp = force_operand (temp, NULL_RTX);
2839 emit_insns_before (seq, object);
2840 if (! validate_change (object, loc, temp, 0)
2841 && ! validate_replace_rtx (x, temp, object))
2849 /* Scan all subexpressions. */
2850 fmt = GET_RTX_FORMAT (code);
2851 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
2854 if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns))
2857 else if (*fmt == 'E')
2858 for (j = 0; j < XVECLEN (x, i); j++)
2859 if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object,
2866 /* Optimization: assuming this function does not receive nonlocal gotos,
2867 delete the handlers for such, as well as the insns to establish
2868 and disestablish them. */
2874 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2876 /* Delete the handler by turning off the flag that would
2877 prevent jump_optimize from deleting it.
2878 Also permit deletion of the nonlocal labels themselves
2879 if nothing local refers to them. */
2880 if (GET_CODE (insn) == CODE_LABEL)
2881 LABEL_PRESERVE_P (insn) = 0;
2882 if (GET_CODE (insn) == INSN
2883 && ((nonlocal_goto_handler_slot != 0
2884 && reg_mentioned_p (nonlocal_goto_handler_slot, PATTERN (insn)))
2885 || (nonlocal_goto_stack_level != 0
2886 && reg_mentioned_p (nonlocal_goto_stack_level,
2892 /* Return a list (chain of EXPR_LIST nodes) for the nonlocal labels
2893 of the current function. */
2896 nonlocal_label_rtx_list ()
2901 for (t = nonlocal_labels; t; t = TREE_CHAIN (t))
2902 x = gen_rtx (EXPR_LIST, VOIDmode, label_rtx (TREE_VALUE (t)), x);
2907 /* Output a USE for any register use in RTL.
2908 This is used with -noreg to mark the extent of lifespan
2909 of any registers used in a user-visible variable's DECL_RTL. */
2915 if (GET_CODE (rtl) == REG)
2916 /* This is a register variable. */
2917 emit_insn (gen_rtx (USE, VOIDmode, rtl));
2918 else if (GET_CODE (rtl) == MEM
2919 && GET_CODE (XEXP (rtl, 0)) == REG
2920 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
2921 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
2922 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
2923 /* This is a variable-sized structure. */
2924 emit_insn (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)));
2927 /* Like use_variable except that it outputs the USEs after INSN
2928 instead of at the end of the insn-chain. */
2931 use_variable_after (rtl, insn)
2934 if (GET_CODE (rtl) == REG)
2935 /* This is a register variable. */
2936 emit_insn_after (gen_rtx (USE, VOIDmode, rtl), insn);
2937 else if (GET_CODE (rtl) == MEM
2938 && GET_CODE (XEXP (rtl, 0)) == REG
2939 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
2940 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
2941 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
2942 /* This is a variable-sized structure. */
2943 emit_insn_after (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)), insn);
2949 return max_parm_reg;
2952 /* Return the first insn following those generated by `assign_parms'. */
2955 get_first_nonparm_insn ()
2958 return NEXT_INSN (last_parm_insn);
2959 return get_insns ();
2962 /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
2963 Crash if there is none. */
2966 get_first_block_beg ()
2968 register rtx searcher;
2969 register rtx insn = get_first_nonparm_insn ();
2971 for (searcher = insn; searcher; searcher = NEXT_INSN (searcher))
2972 if (GET_CODE (searcher) == NOTE
2973 && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG)
2976 abort (); /* Invalid call to this function. (See comments above.) */
2980 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
2981 This means a type for which function calls must pass an address to the
2982 function or get an address back from the function.
2983 EXP may be a type node or an expression (whose type is tested). */
2986 aggregate_value_p (exp)
2989 int i, regno, nregs;
2992 if (TREE_CODE_CLASS (TREE_CODE (exp)) == 't')
2995 type = TREE_TYPE (exp);
2997 if (RETURN_IN_MEMORY (type))
2999 if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
3001 /* Make sure we have suitable call-clobbered regs to return
3002 the value in; if not, we must return it in memory. */
3003 reg = hard_function_value (type, 0);
3004 regno = REGNO (reg);
3005 nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type));
3006 for (i = 0; i < nregs; i++)
3007 if (! call_used_regs[regno + i])
3012 /* Assign RTL expressions to the function's parameters.
3013 This may involve copying them into registers and using
3014 those registers as the RTL for them.
3016 If SECOND_TIME is non-zero it means that this function is being
3017 called a second time. This is done by integrate.c when a function's
3018 compilation is deferred. We need to come back here in case the
3019 FUNCTION_ARG macro computes items needed for the rest of the compilation
3020 (such as changing which registers are fixed or caller-saved). But suppress
3021 writing any insns or setting DECL_RTL of anything in this case. */
3024 assign_parms (fndecl, second_time)
3029 register rtx entry_parm = 0;
3030 register rtx stack_parm = 0;
3031 CUMULATIVE_ARGS args_so_far;
3032 enum machine_mode promoted_mode, passed_mode, nominal_mode;
3034 /* Total space needed so far for args on the stack,
3035 given as a constant and a tree-expression. */
3036 struct args_size stack_args_size;
3037 tree fntype = TREE_TYPE (fndecl);
3038 tree fnargs = DECL_ARGUMENTS (fndecl);
3039 /* This is used for the arg pointer when referring to stack args. */
3040 rtx internal_arg_pointer;
3041 /* This is a dummy PARM_DECL that we used for the function result if
3042 the function returns a structure. */
3043 tree function_result_decl = 0;
3044 int nparmregs = list_length (fnargs) + LAST_VIRTUAL_REGISTER + 1;
3045 int varargs_setup = 0;
3046 rtx conversion_insns = 0;
3047 /* FUNCTION_ARG may look at this variable. Since this is not
3048 expanding a call it will always be zero in this function. */
3049 int current_call_is_indirect = 0;
3051 /* Nonzero if the last arg is named `__builtin_va_alist',
3052 which is used on some machines for old-fashioned non-ANSI varargs.h;
3053 this should be stuck onto the stack as if it had arrived there. */
3055 = (current_function_varargs
3057 && (parm = tree_last (fnargs)) != 0
3059 && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
3060 "__builtin_va_alist")));
3062 /* Nonzero if function takes extra anonymous args.
3063 This means the last named arg must be on the stack
3064 right before the anonymous ones. */
3066 = (TYPE_ARG_TYPES (fntype) != 0
3067 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3068 != void_type_node));
3070 /* If the reg that the virtual arg pointer will be translated into is
3071 not a fixed reg or is the stack pointer, make a copy of the virtual
3072 arg pointer, and address parms via the copy. The frame pointer is
3073 considered fixed even though it is not marked as such.
3075 The second time through, simply use ap to avoid generating rtx. */
3077 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
3078 || ! (fixed_regs[ARG_POINTER_REGNUM]
3079 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM))
3081 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
3083 internal_arg_pointer = virtual_incoming_args_rtx;
3084 current_function_internal_arg_pointer = internal_arg_pointer;
3086 stack_args_size.constant = 0;
3087 stack_args_size.var = 0;
3089 /* If struct value address is treated as the first argument, make it so. */
3090 if (aggregate_value_p (DECL_RESULT (fndecl))
3091 && ! current_function_returns_pcc_struct
3092 && struct_value_incoming_rtx == 0)
3094 tree type = build_pointer_type (fntype);
3096 function_result_decl = build_decl (PARM_DECL, NULL_TREE, type);
3098 DECL_ARG_TYPE (function_result_decl) = type;
3099 TREE_CHAIN (function_result_decl) = fnargs;
3100 fnargs = function_result_decl;
3103 parm_reg_stack_loc = (rtx *) oballoc (nparmregs * sizeof (rtx));
3104 bzero ((char *) parm_reg_stack_loc, nparmregs * sizeof (rtx));
3106 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
3107 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX);
3109 INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX);
3112 /* We haven't yet found an argument that we must push and pretend the
3114 current_function_pretend_args_size = 0;
3116 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
3118 int aggregate = AGGREGATE_TYPE_P (TREE_TYPE (parm));
3119 struct args_size stack_offset;
3120 struct args_size arg_size;
3121 int passed_pointer = 0;
3122 tree passed_type = DECL_ARG_TYPE (parm);
3124 /* Set LAST_NAMED if this is last named arg before some
3125 anonymous args. We treat it as if it were anonymous too. */
3126 int last_named = ((TREE_CHAIN (parm) == 0
3127 || DECL_NAME (TREE_CHAIN (parm)) == 0)
3128 && (stdarg || current_function_varargs));
3130 if (TREE_TYPE (parm) == error_mark_node
3131 /* This can happen after weird syntax errors
3132 or if an enum type is defined among the parms. */
3133 || TREE_CODE (parm) != PARM_DECL
3134 || passed_type == NULL)
3136 DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = gen_rtx (MEM, BLKmode,
3138 TREE_USED (parm) = 1;
3142 /* For varargs.h function, save info about regs and stack space
3143 used by the individual args, not including the va_alist arg. */
3144 if (hide_last_arg && last_named)
3145 current_function_args_info = args_so_far;
3147 /* Find mode of arg as it is passed, and mode of arg
3148 as it should be during execution of this function. */
3149 passed_mode = TYPE_MODE (passed_type);
3150 nominal_mode = TYPE_MODE (TREE_TYPE (parm));
3152 /* If the parm's mode is VOID, its value doesn't matter,
3153 and avoid the usual things like emit_move_insn that could crash. */
3154 if (nominal_mode == VOIDmode)
3156 DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = const0_rtx;
3160 /* If the parm is to be passed as a transparent union, use the
3161 type of the first field for the tests below. We have already
3162 verified that the modes are the same. */
3163 if (DECL_TRANSPARENT_UNION (parm)
3164 || TYPE_TRANSPARENT_UNION (passed_type))
3165 passed_type = TREE_TYPE (TYPE_FIELDS (passed_type));
3167 /* See if this arg was passed by invisible reference. It is if
3168 it is an object whose size depends on the contents of the
3169 object itself or if the machine requires these objects be passed
3172 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
3173 && contains_placeholder_p (TYPE_SIZE (passed_type)))
3174 || TYPE_NEEDS_CONSTRUCTING (passed_type)
3175 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
3176 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
3177 passed_type, ! last_named)
3181 passed_type = build_pointer_type (passed_type);
3183 passed_mode = nominal_mode = Pmode;
3186 promoted_mode = passed_mode;
3188 #ifdef PROMOTE_FUNCTION_ARGS
3189 /* Compute the mode in which the arg is actually extended to. */
3190 promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1);
3193 /* Let machine desc say which reg (if any) the parm arrives in.
3194 0 means it arrives on the stack. */
3195 #ifdef FUNCTION_INCOMING_ARG
3196 entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
3197 passed_type, ! last_named);
3199 entry_parm = FUNCTION_ARG (args_so_far, promoted_mode,
3200 passed_type, ! last_named);
3204 passed_mode = promoted_mode;
3206 #ifdef SETUP_INCOMING_VARARGS
3207 /* If this is the last named parameter, do any required setup for
3208 varargs or stdargs. We need to know about the case of this being an
3209 addressable type, in which case we skip the registers it
3210 would have arrived in.
3212 For stdargs, LAST_NAMED will be set for two parameters, the one that
3213 is actually the last named, and the dummy parameter. We only
3214 want to do this action once.
3216 Also, indicate when RTL generation is to be suppressed. */
3217 if (last_named && !varargs_setup)
3219 SETUP_INCOMING_VARARGS (args_so_far, passed_mode, passed_type,
3220 current_function_pretend_args_size,
3226 /* Determine parm's home in the stack,
3227 in case it arrives in the stack or we should pretend it did.
3229 Compute the stack position and rtx where the argument arrives
3232 There is one complexity here: If this was a parameter that would
3233 have been passed in registers, but wasn't only because it is
3234 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
3235 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
3236 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
3237 0 as it was the previous time. */
3239 locate_and_pad_parm (passed_mode, passed_type,
3240 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3243 #ifdef FUNCTION_INCOMING_ARG
3244 FUNCTION_INCOMING_ARG (args_so_far, passed_mode,
3247 || varargs_setup)) != 0,
3249 FUNCTION_ARG (args_so_far, passed_mode,
3251 ! last_named || varargs_setup) != 0,
3254 fndecl, &stack_args_size, &stack_offset, &arg_size);
3258 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
3260 if (offset_rtx == const0_rtx)
3261 stack_parm = gen_rtx (MEM, passed_mode, internal_arg_pointer);
3263 stack_parm = gen_rtx (MEM, passed_mode,
3264 gen_rtx (PLUS, Pmode,
3265 internal_arg_pointer, offset_rtx));
3267 /* If this is a memory ref that contains aggregate components,
3268 mark it as such for cse and loop optimize. */
3269 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3272 /* If this parameter was passed both in registers and in the stack,
3273 use the copy on the stack. */
3274 if (MUST_PASS_IN_STACK (passed_mode, passed_type))
3277 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3278 /* If this parm was passed part in regs and part in memory,
3279 pretend it arrived entirely in memory
3280 by pushing the register-part onto the stack.
3282 In the special case of a DImode or DFmode that is split,
3283 we could put it together in a pseudoreg directly,
3284 but for now that's not worth bothering with. */
3288 int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, passed_mode,
3289 passed_type, ! last_named);
3293 current_function_pretend_args_size
3294 = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
3295 / (PARM_BOUNDARY / BITS_PER_UNIT)
3296 * (PARM_BOUNDARY / BITS_PER_UNIT));
3299 move_block_from_reg (REGNO (entry_parm),
3300 validize_mem (stack_parm), nregs,
3301 int_size_in_bytes (TREE_TYPE (parm)));
3302 entry_parm = stack_parm;
3307 /* If we didn't decide this parm came in a register,
3308 by default it came on the stack. */
3309 if (entry_parm == 0)
3310 entry_parm = stack_parm;
3312 /* Record permanently how this parm was passed. */
3314 DECL_INCOMING_RTL (parm) = entry_parm;
3316 /* If there is actually space on the stack for this parm,
3317 count it in stack_args_size; otherwise set stack_parm to 0
3318 to indicate there is no preallocated stack slot for the parm. */
3320 if (entry_parm == stack_parm
3321 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
3322 /* On some machines, even if a parm value arrives in a register
3323 there is still an (uninitialized) stack slot allocated for it.
3325 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
3326 whether this parameter already has a stack slot allocated,
3327 because an arg block exists only if current_function_args_size
3328 is larger than some threshhold, and we haven't calculated that
3329 yet. So, for now, we just assume that stack slots never exist
3331 || REG_PARM_STACK_SPACE (fndecl) > 0
3335 stack_args_size.constant += arg_size.constant;
3337 ADD_PARM_SIZE (stack_args_size, arg_size.var);
3340 /* No stack slot was pushed for this parm. */
3343 /* Update info on where next arg arrives in registers. */
3345 FUNCTION_ARG_ADVANCE (args_so_far, passed_mode,
3346 passed_type, ! last_named);
3348 /* If this is our second time through, we are done with this parm. */
3352 /* If we can't trust the parm stack slot to be aligned enough
3353 for its ultimate type, don't use that slot after entry.
3354 We'll make another stack slot, if we need one. */
3356 int thisparm_boundary
3357 = FUNCTION_ARG_BOUNDARY (passed_mode, passed_type);
3359 if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary)
3363 /* If parm was passed in memory, and we need to convert it on entry,
3364 don't store it back in that same slot. */
3366 && nominal_mode != BLKmode && nominal_mode != passed_mode)
3370 /* Now adjust STACK_PARM to the mode and precise location
3371 where this parameter should live during execution,
3372 if we discover that it must live in the stack during execution.
3373 To make debuggers happier on big-endian machines, we store
3374 the value in the last bytes of the space available. */
3376 if (nominal_mode != BLKmode && nominal_mode != passed_mode
3381 #if BYTES_BIG_ENDIAN
3382 if (GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD)
3383 stack_offset.constant += (GET_MODE_SIZE (passed_mode)
3384 - GET_MODE_SIZE (nominal_mode));
3387 offset_rtx = ARGS_SIZE_RTX (stack_offset);
3388 if (offset_rtx == const0_rtx)
3389 stack_parm = gen_rtx (MEM, nominal_mode, internal_arg_pointer);
3391 stack_parm = gen_rtx (MEM, nominal_mode,
3392 gen_rtx (PLUS, Pmode,
3393 internal_arg_pointer, offset_rtx));
3395 /* If this is a memory ref that contains aggregate components,
3396 mark it as such for cse and loop optimize. */
3397 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3401 /* ENTRY_PARM is an RTX for the parameter as it arrives,
3402 in the mode in which it arrives.
3403 STACK_PARM is an RTX for a stack slot where the parameter can live
3404 during the function (in case we want to put it there).
3405 STACK_PARM is 0 if no stack slot was pushed for it.
3407 Now output code if necessary to convert ENTRY_PARM to
3408 the type in which this function declares it,
3409 and store that result in an appropriate place,
3410 which may be a pseudo reg, may be STACK_PARM,
3411 or may be a local stack slot if STACK_PARM is 0.
3413 Set DECL_RTL to that place. */
3415 if (nominal_mode == BLKmode)
3417 /* If a BLKmode arrives in registers, copy it to a stack slot. */
3418 if (GET_CODE (entry_parm) == REG)
3420 int size_stored = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
3423 /* Note that we will be storing an integral number of words.
3424 So we have to be careful to ensure that we allocate an
3425 integral number of words. We do this below in the
3426 assign_stack_local if space was not allocated in the argument
3427 list. If it was, this will not work if PARM_BOUNDARY is not
3428 a multiple of BITS_PER_WORD. It isn't clear how to fix this
3429 if it becomes a problem. */
3431 if (stack_parm == 0)
3434 = assign_stack_local (GET_MODE (entry_parm), size_stored, 0);
3435 /* If this is a memory ref that contains aggregate components,
3436 mark it as such for cse and loop optimize. */
3437 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3440 else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
3443 if (TREE_READONLY (parm))
3444 RTX_UNCHANGING_P (stack_parm) = 1;
3446 move_block_from_reg (REGNO (entry_parm),
3447 validize_mem (stack_parm),
3448 size_stored / UNITS_PER_WORD,
3449 int_size_in_bytes (TREE_TYPE (parm)));
3451 DECL_RTL (parm) = stack_parm;
3453 else if (! ((obey_regdecls && ! DECL_REGISTER (parm)
3454 && ! DECL_INLINE (fndecl))
3455 /* layout_decl may set this. */
3456 || TREE_ADDRESSABLE (parm)
3457 || TREE_SIDE_EFFECTS (parm)
3458 /* If -ffloat-store specified, don't put explicit
3459 float variables into registers. */
3460 || (flag_float_store
3461 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
3462 /* Always assign pseudo to structure return or item passed
3463 by invisible reference. */
3464 || passed_pointer || parm == function_result_decl)
3466 /* Store the parm in a pseudoregister during the function, but we
3467 may need to do it in a wider mode. */
3469 register rtx parmreg;
3470 int regno, regnoi, regnor;
3472 unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
3473 nominal_mode = promote_mode (TREE_TYPE (parm), nominal_mode,
3476 parmreg = gen_reg_rtx (nominal_mode);
3477 REG_USERVAR_P (parmreg) = 1;
3479 /* If this was an item that we received a pointer to, set DECL_RTL
3483 DECL_RTL (parm) = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (passed_type)), parmreg);
3484 MEM_IN_STRUCT_P (DECL_RTL (parm)) = aggregate;
3487 DECL_RTL (parm) = parmreg;
3489 /* Copy the value into the register. */
3490 if (GET_MODE (parmreg) != GET_MODE (entry_parm))
3492 /* If ENTRY_PARM is a hard register, it might be in a register
3493 not valid for operating in its mode (e.g., an odd-numbered
3494 register for a DFmode). In that case, moves are the only
3495 thing valid, so we can't do a convert from there. This
3496 occurs when the calling sequence allow such misaligned
3499 In addition, the conversion may involve a call, which could
3500 clobber parameters which haven't been copied to pseudo
3501 registers yet. Therefore, we must first copy the parm to
3502 a pseudo reg here, and save the conversion until after all
3503 parameters have been moved. */
3505 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
3507 emit_move_insn (tempreg, validize_mem (entry_parm));
3509 push_to_sequence (conversion_insns);
3510 convert_move (parmreg, tempreg, unsignedp);
3511 conversion_insns = get_insns ();
3515 emit_move_insn (parmreg, validize_mem (entry_parm));
3517 /* If we were passed a pointer but the actual value
3518 can safely live in a register, put it in one. */
3519 if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
3520 && ! ((obey_regdecls && ! DECL_REGISTER (parm)
3521 && ! DECL_INLINE (fndecl))
3522 /* layout_decl may set this. */
3523 || TREE_ADDRESSABLE (parm)
3524 || TREE_SIDE_EFFECTS (parm)
3525 /* If -ffloat-store specified, don't put explicit
3526 float variables into registers. */
3527 || (flag_float_store
3528 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))
3530 /* We can't use nominal_mode, because it will have been set to
3531 Pmode above. We must use the actual mode of the parm. */
3532 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
3533 REG_USERVAR_P (parmreg) = 1;
3534 emit_move_insn (parmreg, DECL_RTL (parm));
3535 DECL_RTL (parm) = parmreg;
3536 /* STACK_PARM is the pointer, not the parm, and PARMREG is
3540 #ifdef FUNCTION_ARG_CALLEE_COPIES
3541 /* If we are passed an arg by reference and it is our responsibility
3542 to make a copy, do it now.
3543 PASSED_TYPE and PASSED mode now refer to the pointer, not the
3544 original argument, so we must recreate them in the call to
3545 FUNCTION_ARG_CALLEE_COPIES. */
3546 /* ??? Later add code to handle the case that if the argument isn't
3547 modified, don't do the copy. */
3549 else if (passed_pointer
3550 && FUNCTION_ARG_CALLEE_COPIES (args_so_far,
3551 TYPE_MODE (DECL_ARG_TYPE (parm)),
3552 DECL_ARG_TYPE (parm),
3556 tree type = DECL_ARG_TYPE (parm);
3558 /* This sequence may involve a library call perhaps clobbering
3559 registers that haven't been copied to pseudos yet. */
3561 push_to_sequence (conversion_insns);
3563 if (TYPE_SIZE (type) == 0
3564 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
3565 /* This is a variable sized object. */
3566 copy = gen_rtx (MEM, BLKmode,
3567 allocate_dynamic_stack_space
3568 (expr_size (parm), NULL_RTX,
3569 TYPE_ALIGN (type)));
3571 copy = assign_stack_temp (TYPE_MODE (type),
3572 int_size_in_bytes (type), 1);
3574 store_expr (parm, copy, 0);
3575 emit_move_insn (parmreg, XEXP (copy, 0));
3576 conversion_insns = get_insns ();
3579 #endif /* FUNCTION_ARG_CALLEE_COPIES */
3581 /* In any case, record the parm's desired stack location
3582 in case we later discover it must live in the stack.
3584 If it is a COMPLEX value, store the stack location for both
3587 if (GET_CODE (parmreg) == CONCAT)
3588 regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1)));
3590 regno = REGNO (parmreg);
3592 if (regno >= nparmregs)
3595 int old_nparmregs = nparmregs;
3597 nparmregs = regno + 5;
3598 new = (rtx *) oballoc (nparmregs * sizeof (rtx));
3599 bcopy ((char *) parm_reg_stack_loc, (char *) new,
3600 old_nparmregs * sizeof (rtx));
3601 bzero ((char *) (new + old_nparmregs),
3602 (nparmregs - old_nparmregs) * sizeof (rtx));
3603 parm_reg_stack_loc = new;
3606 if (GET_CODE (parmreg) == CONCAT)
3608 enum machine_mode submode = GET_MODE (XEXP (parmreg, 0));
3610 regnor = REGNO (gen_realpart (submode, parmreg));
3611 regnoi = REGNO (gen_imagpart (submode, parmreg));
3613 if (stack_parm != 0)
3615 parm_reg_stack_loc[regnor]
3616 = gen_realpart (submode, stack_parm);
3617 parm_reg_stack_loc[regnoi]
3618 = gen_imagpart (submode, stack_parm);
3622 parm_reg_stack_loc[regnor] = 0;
3623 parm_reg_stack_loc[regnoi] = 0;
3627 parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
3629 /* Mark the register as eliminable if we did no conversion
3630 and it was copied from memory at a fixed offset,
3631 and the arg pointer was not copied to a pseudo-reg.
3632 If the arg pointer is a pseudo reg or the offset formed
3633 an invalid address, such memory-equivalences
3634 as we make here would screw up life analysis for it. */
3635 if (nominal_mode == passed_mode
3636 && ! conversion_insns
3637 && GET_CODE (entry_parm) == MEM
3638 && entry_parm == stack_parm
3639 && stack_offset.var == 0
3640 && reg_mentioned_p (virtual_incoming_args_rtx,
3641 XEXP (entry_parm, 0)))
3643 rtx linsn = get_last_insn ();
3645 /* Mark complex types separately. */
3646 if (GET_CODE (parmreg) == CONCAT)
3649 = gen_rtx (EXPR_LIST, REG_EQUIV,
3650 parm_reg_stack_loc[regnoi], REG_NOTES (linsn));
3652 /* Now search backward for where we set the real part. */
3654 && ! reg_referenced_p (parm_reg_stack_loc[regnor],
3656 linsn = prev_nonnote_insn (linsn))
3660 = gen_rtx (EXPR_LIST, REG_EQUIV,
3661 parm_reg_stack_loc[regnor], REG_NOTES (linsn));
3665 = gen_rtx (EXPR_LIST, REG_EQUIV,
3666 entry_parm, REG_NOTES (linsn));
3669 /* For pointer data type, suggest pointer register. */
3670 if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE)
3671 mark_reg_pointer (parmreg);
3675 /* Value must be stored in the stack slot STACK_PARM
3676 during function execution. */
3678 if (passed_mode != nominal_mode)
3680 /* Conversion is required. */
3681 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
3683 emit_move_insn (tempreg, validize_mem (entry_parm));
3685 push_to_sequence (conversion_insns);
3686 entry_parm = convert_to_mode (nominal_mode, tempreg,
3687 TREE_UNSIGNED (TREE_TYPE (parm)));
3688 conversion_insns = get_insns ();
3692 if (entry_parm != stack_parm)
3694 if (stack_parm == 0)
3697 = assign_stack_local (GET_MODE (entry_parm),
3698 GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
3699 /* If this is a memory ref that contains aggregate components,
3700 mark it as such for cse and loop optimize. */
3701 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3704 if (passed_mode != nominal_mode)
3706 push_to_sequence (conversion_insns);
3707 emit_move_insn (validize_mem (stack_parm),
3708 validize_mem (entry_parm));
3709 conversion_insns = get_insns ();
3713 emit_move_insn (validize_mem (stack_parm),
3714 validize_mem (entry_parm));
3717 DECL_RTL (parm) = stack_parm;
3720 /* If this "parameter" was the place where we are receiving the
3721 function's incoming structure pointer, set up the result. */
3722 if (parm == function_result_decl)
3724 tree result = DECL_RESULT (fndecl);
3725 tree restype = TREE_TYPE (result);
3728 = gen_rtx (MEM, DECL_MODE (result), DECL_RTL (parm));
3730 MEM_IN_STRUCT_P (DECL_RTL (result)) = AGGREGATE_TYPE_P (restype);
3733 if (TREE_THIS_VOLATILE (parm))
3734 MEM_VOLATILE_P (DECL_RTL (parm)) = 1;
3735 if (TREE_READONLY (parm))
3736 RTX_UNCHANGING_P (DECL_RTL (parm)) = 1;
3739 /* Output all parameter conversion instructions (possibly including calls)
3740 now that all parameters have been copied out of hard registers. */
3741 emit_insns (conversion_insns);
3743 max_parm_reg = max_reg_num ();
3744 last_parm_insn = get_last_insn ();
3746 current_function_args_size = stack_args_size.constant;
3748 /* Adjust function incoming argument size for alignment and
3751 #ifdef REG_PARM_STACK_SPACE
3752 #ifndef MAYBE_REG_PARM_STACK_SPACE
3753 current_function_args_size = MAX (current_function_args_size,
3754 REG_PARM_STACK_SPACE (fndecl));
3758 #ifdef STACK_BOUNDARY
3759 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
3761 current_function_args_size
3762 = ((current_function_args_size + STACK_BYTES - 1)
3763 / STACK_BYTES) * STACK_BYTES;
3766 #ifdef ARGS_GROW_DOWNWARD
3767 current_function_arg_offset_rtx
3768 = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
3769 : expand_expr (size_binop (MINUS_EXPR, stack_args_size.var,
3770 size_int (-stack_args_size.constant)),
3771 NULL_RTX, VOIDmode, 0));
3773 current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
3776 /* See how many bytes, if any, of its args a function should try to pop
3779 current_function_pops_args = RETURN_POPS_ARGS (TREE_TYPE (fndecl),
3780 current_function_args_size);
3782 /* For stdarg.h function, save info about
3783 regs and stack space used by the named args. */
3786 current_function_args_info = args_so_far;
3788 /* Set the rtx used for the function return value. Put this in its
3789 own variable so any optimizers that need this information don't have
3790 to include tree.h. Do this here so it gets done when an inlined
3791 function gets output. */
3793 current_function_return_rtx = DECL_RTL (DECL_RESULT (fndecl));
3796 /* Indicate whether REGNO is an incoming argument to the current function
3797 that was promoted to a wider mode. If so, return the RTX for the
3798 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
3799 that REGNO is promoted from and whether the promotion was signed or
3802 #ifdef PROMOTE_FUNCTION_ARGS
3805 promoted_input_arg (regno, pmode, punsignedp)
3807 enum machine_mode *pmode;
3812 for (arg = DECL_ARGUMENTS (current_function_decl); arg;
3813 arg = TREE_CHAIN (arg))
3814 if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
3815 && REGNO (DECL_INCOMING_RTL (arg)) == regno)
3817 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
3818 int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
3820 mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1);
3821 if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
3822 && mode != DECL_MODE (arg))
3824 *pmode = DECL_MODE (arg);
3825 *punsignedp = unsignedp;
3826 return DECL_INCOMING_RTL (arg);
3835 /* Compute the size and offset from the start of the stacked arguments for a
3836 parm passed in mode PASSED_MODE and with type TYPE.
3838 INITIAL_OFFSET_PTR points to the current offset into the stacked
3841 The starting offset and size for this parm are returned in *OFFSET_PTR
3842 and *ARG_SIZE_PTR, respectively.
3844 IN_REGS is non-zero if the argument will be passed in registers. It will
3845 never be set if REG_PARM_STACK_SPACE is not defined.
3847 FNDECL is the function in which the argument was defined.
3849 There are two types of rounding that are done. The first, controlled by
3850 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
3851 list to be aligned to the specific boundary (in bits). This rounding
3852 affects the initial and starting offsets, but not the argument size.
3854 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
3855 optionally rounds the size of the parm to PARM_BOUNDARY. The
3856 initial offset is not affected by this rounding, while the size always
3857 is and the starting offset may be. */
3859 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
3860 initial_offset_ptr is positive because locate_and_pad_parm's
3861 callers pass in the total size of args so far as
3862 initial_offset_ptr. arg_size_ptr is always positive.*/
3865 locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
3866 initial_offset_ptr, offset_ptr, arg_size_ptr)
3867 enum machine_mode passed_mode;
3871 struct args_size *initial_offset_ptr;
3872 struct args_size *offset_ptr;
3873 struct args_size *arg_size_ptr;
3876 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
3877 enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
3878 int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
3879 int boundary_in_bytes = boundary / BITS_PER_UNIT;
3880 int reg_parm_stack_space = 0;
3882 #ifdef REG_PARM_STACK_SPACE
3883 /* If we have found a stack parm before we reach the end of the
3884 area reserved for registers, skip that area. */
3887 #ifdef MAYBE_REG_PARM_STACK_SPACE
3888 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
3890 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
3892 if (reg_parm_stack_space > 0)
3894 if (initial_offset_ptr->var)
3896 initial_offset_ptr->var
3897 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
3898 size_int (reg_parm_stack_space));
3899 initial_offset_ptr->constant = 0;
3901 else if (initial_offset_ptr->constant < reg_parm_stack_space)
3902 initial_offset_ptr->constant = reg_parm_stack_space;
3905 #endif /* REG_PARM_STACK_SPACE */
3907 arg_size_ptr->var = 0;
3908 arg_size_ptr->constant = 0;
3910 #ifdef ARGS_GROW_DOWNWARD
3911 if (initial_offset_ptr->var)
3913 offset_ptr->constant = 0;
3914 offset_ptr->var = size_binop (MINUS_EXPR, integer_zero_node,
3915 initial_offset_ptr->var);
3919 offset_ptr->constant = - initial_offset_ptr->constant;
3920 offset_ptr->var = 0;
3922 if (where_pad != none
3923 && (TREE_CODE (sizetree) != INTEGER_CST
3924 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
3925 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
3926 SUB_PARM_SIZE (*offset_ptr, sizetree);
3927 if (where_pad != downward)
3928 pad_to_arg_alignment (offset_ptr, boundary);
3929 if (initial_offset_ptr->var)
3931 arg_size_ptr->var = size_binop (MINUS_EXPR,
3932 size_binop (MINUS_EXPR,
3934 initial_offset_ptr->var),
3939 arg_size_ptr->constant = (- initial_offset_ptr->constant -
3940 offset_ptr->constant);
3942 #else /* !ARGS_GROW_DOWNWARD */
3943 pad_to_arg_alignment (initial_offset_ptr, boundary);
3944 *offset_ptr = *initial_offset_ptr;
3946 #ifdef PUSH_ROUNDING
3947 if (passed_mode != BLKmode)
3948 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
3951 if (where_pad != none
3952 && (TREE_CODE (sizetree) != INTEGER_CST
3953 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
3954 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
3956 /* This must be done after rounding sizetree, so that it will subtract
3957 the same value that we explicitly add below. */
3958 if (where_pad == downward)
3959 pad_below (offset_ptr, passed_mode, sizetree);
3960 ADD_PARM_SIZE (*arg_size_ptr, sizetree);
3961 #endif /* ARGS_GROW_DOWNWARD */
3964 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
3965 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
3968 pad_to_arg_alignment (offset_ptr, boundary)
3969 struct args_size *offset_ptr;
3972 int boundary_in_bytes = boundary / BITS_PER_UNIT;
3974 if (boundary > BITS_PER_UNIT)
3976 if (offset_ptr->var)
3979 #ifdef ARGS_GROW_DOWNWARD
3984 (ARGS_SIZE_TREE (*offset_ptr),
3985 boundary / BITS_PER_UNIT);
3986 offset_ptr->constant = 0; /*?*/
3989 offset_ptr->constant =
3990 #ifdef ARGS_GROW_DOWNWARD
3991 FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes);
3993 CEIL_ROUND (offset_ptr->constant, boundary_in_bytes);
3999 pad_below (offset_ptr, passed_mode, sizetree)
4000 struct args_size *offset_ptr;
4001 enum machine_mode passed_mode;
4004 if (passed_mode != BLKmode)
4006 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
4007 offset_ptr->constant
4008 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
4009 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
4010 - GET_MODE_SIZE (passed_mode));
4014 if (TREE_CODE (sizetree) != INTEGER_CST
4015 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
4017 /* Round the size up to multiple of PARM_BOUNDARY bits. */
4018 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4020 ADD_PARM_SIZE (*offset_ptr, s2);
4021 SUB_PARM_SIZE (*offset_ptr, sizetree);
4027 round_down (value, divisor)
4031 return size_binop (MULT_EXPR,
4032 size_binop (FLOOR_DIV_EXPR, value, size_int (divisor)),
4033 size_int (divisor));
4036 /* Walk the tree of blocks describing the binding levels within a function
4037 and warn about uninitialized variables.
4038 This is done after calling flow_analysis and before global_alloc
4039 clobbers the pseudo-regs to hard regs. */
4042 uninitialized_vars_warning (block)
4045 register tree decl, sub;
4046 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
4048 if (TREE_CODE (decl) == VAR_DECL
4049 /* These warnings are unreliable for and aggregates
4050 because assigning the fields one by one can fail to convince
4051 flow.c that the entire aggregate was initialized.
4052 Unions are troublesome because members may be shorter. */
4053 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl))
4054 && DECL_RTL (decl) != 0
4055 && GET_CODE (DECL_RTL (decl)) == REG
4056 && regno_uninitialized (REGNO (DECL_RTL (decl))))
4057 warning_with_decl (decl,
4058 "`%s' might be used uninitialized in this function");
4059 if (TREE_CODE (decl) == VAR_DECL
4060 && DECL_RTL (decl) != 0
4061 && GET_CODE (DECL_RTL (decl)) == REG
4062 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
4063 warning_with_decl (decl,
4064 "variable `%s' might be clobbered by `longjmp' or `vfork'");
4066 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
4067 uninitialized_vars_warning (sub);
4070 /* Do the appropriate part of uninitialized_vars_warning
4071 but for arguments instead of local variables. */
4074 setjmp_args_warning (block)
4078 for (decl = DECL_ARGUMENTS (current_function_decl);
4079 decl; decl = TREE_CHAIN (decl))
4080 if (DECL_RTL (decl) != 0
4081 && GET_CODE (DECL_RTL (decl)) == REG
4082 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
4083 warning_with_decl (decl, "argument `%s' might be clobbered by `longjmp' or `vfork'");
4086 /* If this function call setjmp, put all vars into the stack
4087 unless they were declared `register'. */
4090 setjmp_protect (block)
4093 register tree decl, sub;
4094 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
4095 if ((TREE_CODE (decl) == VAR_DECL
4096 || TREE_CODE (decl) == PARM_DECL)
4097 && DECL_RTL (decl) != 0
4098 && GET_CODE (DECL_RTL (decl)) == REG
4099 /* If this variable came from an inline function, it must be
4100 that it's life doesn't overlap the setjmp. If there was a
4101 setjmp in the function, it would already be in memory. We
4102 must exclude such variable because their DECL_RTL might be
4103 set to strange things such as virtual_stack_vars_rtx. */
4104 && ! DECL_FROM_INLINE (decl)
4106 #ifdef NON_SAVING_SETJMP
4107 /* If longjmp doesn't restore the registers,
4108 don't put anything in them. */
4112 ! DECL_REGISTER (decl)))
4113 put_var_into_stack (decl);
4114 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
4115 setjmp_protect (sub);
4118 /* Like the previous function, but for args instead of local variables. */
4121 setjmp_protect_args ()
4123 register tree decl, sub;
4124 for (decl = DECL_ARGUMENTS (current_function_decl);
4125 decl; decl = TREE_CHAIN (decl))
4126 if ((TREE_CODE (decl) == VAR_DECL
4127 || TREE_CODE (decl) == PARM_DECL)
4128 && DECL_RTL (decl) != 0
4129 && GET_CODE (DECL_RTL (decl)) == REG
4131 /* If longjmp doesn't restore the registers,
4132 don't put anything in them. */
4133 #ifdef NON_SAVING_SETJMP
4137 ! DECL_REGISTER (decl)))
4138 put_var_into_stack (decl);
4141 /* Return the context-pointer register corresponding to DECL,
4142 or 0 if it does not need one. */
4145 lookup_static_chain (decl)
4148 tree context = decl_function_context (decl);
4154 /* We treat inline_function_decl as an alias for the current function
4155 because that is the inline function whose vars, types, etc.
4156 are being merged into the current function.
4157 See expand_inline_function. */
4158 if (context == current_function_decl || context == inline_function_decl)
4159 return virtual_stack_vars_rtx;
4161 for (link = context_display; link; link = TREE_CHAIN (link))
4162 if (TREE_PURPOSE (link) == context)
4163 return RTL_EXPR_RTL (TREE_VALUE (link));
4168 /* Convert a stack slot address ADDR for variable VAR
4169 (from a containing function)
4170 into an address valid in this function (using a static chain). */
4173 fix_lexical_addr (addr, var)
4179 tree context = decl_function_context (var);
4180 struct function *fp;
4183 /* If this is the present function, we need not do anything. */
4184 if (context == current_function_decl || context == inline_function_decl)
4187 for (fp = outer_function_chain; fp; fp = fp->next)
4188 if (fp->decl == context)
4194 /* Decode given address as base reg plus displacement. */
4195 if (GET_CODE (addr) == REG)
4196 basereg = addr, displacement = 0;
4197 else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
4198 basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
4202 /* We accept vars reached via the containing function's
4203 incoming arg pointer and via its stack variables pointer. */
4204 if (basereg == fp->internal_arg_pointer)
4206 /* If reached via arg pointer, get the arg pointer value
4207 out of that function's stack frame.
4209 There are two cases: If a separate ap is needed, allocate a
4210 slot in the outer function for it and dereference it that way.
4211 This is correct even if the real ap is actually a pseudo.
4212 Otherwise, just adjust the offset from the frame pointer to
4215 #ifdef NEED_SEPARATE_AP
4218 if (fp->arg_pointer_save_area == 0)
4219 fp->arg_pointer_save_area
4220 = assign_outer_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0, fp);
4222 addr = fix_lexical_addr (XEXP (fp->arg_pointer_save_area, 0), var);
4223 addr = memory_address (Pmode, addr);
4225 base = copy_to_reg (gen_rtx (MEM, Pmode, addr));
4227 displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
4228 base = lookup_static_chain (var);
4232 else if (basereg == virtual_stack_vars_rtx)
4234 /* This is the same code as lookup_static_chain, duplicated here to
4235 avoid an extra call to decl_function_context. */
4238 for (link = context_display; link; link = TREE_CHAIN (link))
4239 if (TREE_PURPOSE (link) == context)
4241 base = RTL_EXPR_RTL (TREE_VALUE (link));
4249 /* Use same offset, relative to appropriate static chain or argument
4251 return plus_constant (base, displacement);
4254 /* Return the address of the trampoline for entering nested fn FUNCTION.
4255 If necessary, allocate a trampoline (in the stack frame)
4256 and emit rtl to initialize its contents (at entry to this function). */
4259 trampoline_address (function)
4265 struct function *fp;
4268 /* Find an existing trampoline and return it. */
4269 for (link = trampoline_list; link; link = TREE_CHAIN (link))
4270 if (TREE_PURPOSE (link) == function)
4271 return XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0);
4272 for (fp = outer_function_chain; fp; fp = fp->next)
4273 for (link = fp->trampoline_list; link; link = TREE_CHAIN (link))
4274 if (TREE_PURPOSE (link) == function)
4276 tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
4278 return round_trampoline_addr (tramp);
4281 /* None exists; we must make one. */
4283 /* Find the `struct function' for the function containing FUNCTION. */
4285 fn_context = decl_function_context (function);
4286 if (fn_context != current_function_decl)
4287 for (fp = outer_function_chain; fp; fp = fp->next)
4288 if (fp->decl == fn_context)
4291 /* Allocate run-time space for this trampoline
4292 (usually in the defining function's stack frame). */
4293 #ifdef ALLOCATE_TRAMPOLINE
4294 tramp = ALLOCATE_TRAMPOLINE (fp);
4296 /* If rounding needed, allocate extra space
4297 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
4298 #ifdef TRAMPOLINE_ALIGNMENT
4299 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE + TRAMPOLINE_ALIGNMENT - 1)
4301 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
4304 tramp = assign_outer_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0, fp);
4306 tramp = assign_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0);
4309 /* Record the trampoline for reuse and note it for later initialization
4310 by expand_function_end. */
4313 push_obstacks (fp->function_maybepermanent_obstack,
4314 fp->function_maybepermanent_obstack);
4315 rtlexp = make_node (RTL_EXPR);
4316 RTL_EXPR_RTL (rtlexp) = tramp;
4317 fp->trampoline_list = tree_cons (function, rtlexp, fp->trampoline_list);
4322 /* Make the RTL_EXPR node temporary, not momentary, so that the
4323 trampoline_list doesn't become garbage. */
4324 int momentary = suspend_momentary ();
4325 rtlexp = make_node (RTL_EXPR);
4326 resume_momentary (momentary);
4328 RTL_EXPR_RTL (rtlexp) = tramp;
4329 trampoline_list = tree_cons (function, rtlexp, trampoline_list);
4332 tramp = fix_lexical_addr (XEXP (tramp, 0), function);
4333 return round_trampoline_addr (tramp);
4336 /* Given a trampoline address,
4337 round it to multiple of TRAMPOLINE_ALIGNMENT. */
4340 round_trampoline_addr (tramp)
4343 #ifdef TRAMPOLINE_ALIGNMENT
4344 /* Round address up to desired boundary. */
4345 rtx temp = gen_reg_rtx (Pmode);
4346 temp = expand_binop (Pmode, add_optab, tramp,
4347 GEN_INT (TRAMPOLINE_ALIGNMENT - 1),
4348 temp, 0, OPTAB_LIB_WIDEN);
4349 tramp = expand_binop (Pmode, and_optab, temp,
4350 GEN_INT (- TRAMPOLINE_ALIGNMENT),
4351 temp, 0, OPTAB_LIB_WIDEN);
4356 /* The functions identify_blocks and reorder_blocks provide a way to
4357 reorder the tree of BLOCK nodes, for optimizers that reshuffle or
4358 duplicate portions of the RTL code. Call identify_blocks before
4359 changing the RTL, and call reorder_blocks after. */
4361 /* Put all this function's BLOCK nodes into a vector, and return it.
4362 Also store in each NOTE for the beginning or end of a block
4363 the index of that block in the vector.
4364 The arguments are TOP_BLOCK, the top-level block of the function,
4365 and INSNS, the insn chain of the function. */
4368 identify_blocks (top_block, insns)
4376 int next_block_number = 0;
4377 int current_block_number = 0;
4383 n_blocks = all_blocks (top_block, 0);
4384 block_vector = (tree *) xmalloc (n_blocks * sizeof (tree));
4385 block_stack = (int *) alloca (n_blocks * sizeof (int));
4387 all_blocks (top_block, block_vector);
4389 for (insn = insns; insn; insn = NEXT_INSN (insn))
4390 if (GET_CODE (insn) == NOTE)
4392 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
4394 block_stack[depth++] = current_block_number;
4395 current_block_number = next_block_number;
4396 NOTE_BLOCK_NUMBER (insn) = next_block_number++;
4398 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
4400 current_block_number = block_stack[--depth];
4401 NOTE_BLOCK_NUMBER (insn) = current_block_number;
4405 return block_vector;
4408 /* Given BLOCK_VECTOR which was returned by identify_blocks,
4409 and a revised instruction chain, rebuild the tree structure
4410 of BLOCK nodes to correspond to the new order of RTL.
4411 The new block tree is inserted below TOP_BLOCK.
4412 Returns the current top-level block. */
4415 reorder_blocks (block_vector, top_block, insns)
4420 tree current_block = top_block;
4423 if (block_vector == 0)
4426 /* Prune the old tree away, so that it doesn't get in the way. */
4427 BLOCK_SUBBLOCKS (current_block) = 0;
4429 for (insn = insns; insn; insn = NEXT_INSN (insn))
4430 if (GET_CODE (insn) == NOTE)
4432 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
4434 tree block = block_vector[NOTE_BLOCK_NUMBER (insn)];
4435 /* If we have seen this block before, copy it. */
4436 if (TREE_ASM_WRITTEN (block))
4437 block = copy_node (block);
4438 BLOCK_SUBBLOCKS (block) = 0;
4439 TREE_ASM_WRITTEN (block) = 1;
4440 BLOCK_SUPERCONTEXT (block) = current_block;
4441 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
4442 BLOCK_SUBBLOCKS (current_block) = block;
4443 current_block = block;
4444 NOTE_SOURCE_FILE (insn) = 0;
4446 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
4448 BLOCK_SUBBLOCKS (current_block)
4449 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
4450 current_block = BLOCK_SUPERCONTEXT (current_block);
4451 NOTE_SOURCE_FILE (insn) = 0;
4455 return current_block;
4458 /* Reverse the order of elements in the chain T of blocks,
4459 and return the new head of the chain (old last element). */
4465 register tree prev = 0, decl, next;
4466 for (decl = t; decl; decl = next)
4468 next = BLOCK_CHAIN (decl);
4469 BLOCK_CHAIN (decl) = prev;
4475 /* Count the subblocks of BLOCK, and list them all into the vector VECTOR.
4476 Also clear TREE_ASM_WRITTEN in all blocks. */
4479 all_blocks (block, vector)
4486 TREE_ASM_WRITTEN (block) = 0;
4487 /* Record this block. */
4491 /* Record the subblocks, and their subblocks. */
4492 for (subblocks = BLOCK_SUBBLOCKS (block);
4493 subblocks; subblocks = BLOCK_CHAIN (subblocks))
4494 n_blocks += all_blocks (subblocks, vector ? vector + n_blocks : 0);
4499 /* Build bytecode call descriptor for function SUBR. */
4502 bc_build_calldesc (subr)
4505 tree calldesc = 0, arg;
4508 /* Build the argument description vector in reverse order. */
4509 DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
4512 for (arg = DECL_ARGUMENTS (subr); arg; arg = TREE_CHAIN (arg))
4516 calldesc = tree_cons ((tree) 0, size_in_bytes (TREE_TYPE (arg)), calldesc);
4517 calldesc = tree_cons ((tree) 0, bc_runtime_type_code (TREE_TYPE (arg)), calldesc);
4520 DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
4522 /* Prepend the function's return type. */
4523 calldesc = tree_cons ((tree) 0,
4524 size_in_bytes (TREE_TYPE (TREE_TYPE (subr))),
4527 calldesc = tree_cons ((tree) 0,
4528 bc_runtime_type_code (TREE_TYPE (TREE_TYPE (subr))),
4531 /* Prepend the arg count. */
4532 calldesc = tree_cons ((tree) 0, build_int_2 (nargs, 0), calldesc);
4534 /* Output the call description vector and get its address. */
4535 calldesc = build_nt (CONSTRUCTOR, (tree) 0, calldesc);
4536 TREE_TYPE (calldesc) = build_array_type (integer_type_node,
4537 build_index_type (build_int_2 (nargs * 2, 0)));
4539 return output_constant_def (calldesc);
4543 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
4544 and initialize static variables for generating RTL for the statements
4548 init_function_start (subr, filename, line)
4555 if (output_bytecode)
4557 this_function_decl = subr;
4558 this_function_calldesc = bc_build_calldesc (subr);
4559 local_vars_size = 0;
4561 max_stack_depth = 0;
4562 stmt_expr_depth = 0;
4566 init_stmt_for_function ();
4568 cse_not_expected = ! optimize;
4570 /* Caller save not needed yet. */
4571 caller_save_needed = 0;
4573 /* No stack slots have been made yet. */
4574 stack_slot_list = 0;
4576 /* There is no stack slot for handling nonlocal gotos. */
4577 nonlocal_goto_handler_slot = 0;
4578 nonlocal_goto_stack_level = 0;
4580 /* No labels have been declared for nonlocal use. */
4581 nonlocal_labels = 0;
4583 /* No function calls so far in this function. */
4584 function_call_count = 0;
4586 /* No parm regs have been allocated.
4587 (This is important for output_inline_function.) */
4588 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
4590 /* Initialize the RTL mechanism. */
4593 /* Initialize the queue of pending postincrement and postdecrements,
4594 and some other info in expr.c. */
4597 /* We haven't done register allocation yet. */
4600 init_const_rtx_hash_table ();
4602 current_function_name = (*decl_printable_name) (subr, &junk);
4604 /* Nonzero if this is a nested function that uses a static chain. */
4606 current_function_needs_context
4607 = (decl_function_context (current_function_decl) != 0);
4609 /* Set if a call to setjmp is seen. */
4610 current_function_calls_setjmp = 0;
4612 /* Set if a call to longjmp is seen. */
4613 current_function_calls_longjmp = 0;
4615 current_function_calls_alloca = 0;
4616 current_function_has_nonlocal_label = 0;
4617 current_function_has_nonlocal_goto = 0;
4618 current_function_contains_functions = 0;
4620 current_function_returns_pcc_struct = 0;
4621 current_function_returns_struct = 0;
4622 current_function_epilogue_delay_list = 0;
4623 current_function_uses_const_pool = 0;
4624 current_function_uses_pic_offset_table = 0;
4626 /* We have not yet needed to make a label to jump to for tail-recursion. */
4627 tail_recursion_label = 0;
4629 /* We haven't had a need to make a save area for ap yet. */
4631 arg_pointer_save_area = 0;
4633 /* No stack slots allocated yet. */
4636 /* No SAVE_EXPRs in this function yet. */
4639 /* No RTL_EXPRs in this function yet. */
4642 /* We have not allocated any temporaries yet. */
4644 temp_slot_level = 0;
4645 target_temp_slot_level = 0;
4647 /* Within function body, compute a type's size as soon it is laid out. */
4648 immediate_size_expand++;
4650 /* We haven't made any trampolines for this function yet. */
4651 trampoline_list = 0;
4653 init_pending_stack_adjust ();
4654 inhibit_defer_pop = 0;
4656 current_function_outgoing_args_size = 0;
4658 /* Initialize the insn lengths. */
4659 init_insn_lengths ();
4661 /* Prevent ever trying to delete the first instruction of a function.
4662 Also tell final how to output a linenum before the function prologue. */
4663 emit_line_note (filename, line);
4665 /* Make sure first insn is a note even if we don't want linenums.
4666 This makes sure the first insn will never be deleted.
4667 Also, final expects a note to appear there. */
4668 emit_note (NULL_PTR, NOTE_INSN_DELETED);
4670 /* Set flags used by final.c. */
4671 if (aggregate_value_p (DECL_RESULT (subr)))
4673 #ifdef PCC_STATIC_STRUCT_RETURN
4674 current_function_returns_pcc_struct = 1;
4676 current_function_returns_struct = 1;
4679 /* Warn if this value is an aggregate type,
4680 regardless of which calling convention we are using for it. */
4681 if (warn_aggregate_return
4682 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
4683 warning ("function returns an aggregate");
4685 current_function_returns_pointer
4686 = (TREE_CODE (TREE_TYPE (DECL_RESULT (subr))) == POINTER_TYPE);
4688 /* Indicate that we need to distinguish between the return value of the
4689 present function and the return value of a function being called. */
4690 rtx_equal_function_value_matters = 1;
4692 /* Indicate that we have not instantiated virtual registers yet. */
4693 virtuals_instantiated = 0;
4695 /* Indicate we have no need of a frame pointer yet. */
4696 frame_pointer_needed = 0;
4698 /* By default assume not varargs. */
4699 current_function_varargs = 0;
4702 /* Indicate that the current function uses extra args
4703 not explicitly mentioned in the argument list in any fashion. */
4708 current_function_varargs = 1;
4711 /* Expand a call to __main at the beginning of a possible main function. */
4713 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
4714 #undef HAS_INIT_SECTION
4715 #define HAS_INIT_SECTION
4719 expand_main_function ()
4721 if (!output_bytecode)
4723 /* The zero below avoids a possible parse error */
4725 #if !defined (HAS_INIT_SECTION)
4726 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, NAME__MAIN), 0,
4728 #endif /* not HAS_INIT_SECTION */
4732 extern struct obstack permanent_obstack;
4734 /* Expand start of bytecode function. See comment at
4735 expand_function_start below for details. */
4738 bc_expand_function_start (subr, parms_have_cleanups)
4740 int parms_have_cleanups;
4742 char label[20], *name;
4747 if (TREE_PUBLIC (subr))
4748 bc_globalize_label (IDENTIFIER_POINTER (DECL_NAME (subr)));
4750 #ifdef DEBUG_PRINT_CODE
4751 fprintf (stderr, "\n<func %s>\n", IDENTIFIER_POINTER (DECL_NAME (subr)));
4754 for (argsz = 0, thisarg = DECL_ARGUMENTS (subr); thisarg; thisarg = TREE_CHAIN (thisarg))
4756 if (DECL_RTL (thisarg))
4757 abort (); /* Should be NULL here I think. */
4758 else if (TREE_CONSTANT (DECL_SIZE (thisarg)))
4760 DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
4761 argsz += TREE_INT_CST_LOW (DECL_SIZE (thisarg));
4765 /* Variable-sized objects are pointers to their storage. */
4766 DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
4767 argsz += POINTER_SIZE;
4771 bc_begin_function (bc_xstrdup (IDENTIFIER_POINTER (DECL_NAME (subr))));
4773 ASM_GENERATE_INTERNAL_LABEL (label, "LX", nlab);
4776 name = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
4777 this_function_callinfo = bc_gen_rtx (name, 0, (struct bc_label *) 0);
4778 this_function_bytecode =
4779 bc_emit_trampoline (BYTECODE_LABEL (this_function_callinfo));
4783 /* Expand end of bytecode function. See details the comment of
4784 expand_function_end(), below. */
4787 bc_expand_function_end ()
4791 expand_null_return ();
4793 /* Emit any fixup code. This must be done before the call to
4794 to BC_END_FUNCTION (), since that will cause the bytecode
4795 segment to be finished off and closed. */
4797 expand_fixups (NULL_RTX);
4799 ptrconsts = bc_end_function ();
4801 bc_align_const (2 /* INT_ALIGN */);
4803 /* If this changes also make sure to change bc-interp.h! */
4805 bc_emit_const_labeldef (BYTECODE_LABEL (this_function_callinfo));
4806 bc_emit_const ((char *) &max_stack_depth, sizeof max_stack_depth);
4807 bc_emit_const ((char *) &local_vars_size, sizeof local_vars_size);
4808 bc_emit_const_labelref (this_function_bytecode, 0);
4809 bc_emit_const_labelref (ptrconsts, 0);
4810 bc_emit_const_labelref (BYTECODE_LABEL (this_function_calldesc), 0);
4814 /* Start the RTL for a new function, and set variables used for
4816 SUBR is the FUNCTION_DECL node.
4817 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
4818 the function's parameters, which must be run at any return statement. */
4821 expand_function_start (subr, parms_have_cleanups)
4823 int parms_have_cleanups;
4829 if (output_bytecode)
4831 bc_expand_function_start (subr, parms_have_cleanups);
4835 /* Make sure volatile mem refs aren't considered
4836 valid operands of arithmetic insns. */
4837 init_recog_no_volatile ();
4839 /* If function gets a static chain arg, store it in the stack frame.
4840 Do this first, so it gets the first stack slot offset. */
4841 if (current_function_needs_context)
4843 last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
4845 #ifdef SMALL_REGISTER_CLASSES
4846 /* Delay copying static chain if it is not a register to avoid
4847 conflicts with regs used for parameters. */
4848 if (GET_CODE (static_chain_incoming_rtx) == REG)
4850 emit_move_insn (last_ptr, static_chain_incoming_rtx);
4853 /* If the parameters of this function need cleaning up, get a label
4854 for the beginning of the code which executes those cleanups. This must
4855 be done before doing anything with return_label. */
4856 if (parms_have_cleanups)
4857 cleanup_label = gen_label_rtx ();
4861 /* Make the label for return statements to jump to, if this machine
4862 does not have a one-instruction return and uses an epilogue,
4863 or if it returns a structure, or if it has parm cleanups. */
4865 if (cleanup_label == 0 && HAVE_return
4866 && ! current_function_returns_pcc_struct
4867 && ! (current_function_returns_struct && ! optimize))
4870 return_label = gen_label_rtx ();
4872 return_label = gen_label_rtx ();
4875 /* Initialize rtx used to return the value. */
4876 /* Do this before assign_parms so that we copy the struct value address
4877 before any library calls that assign parms might generate. */
4879 /* Decide whether to return the value in memory or in a register. */
4880 if (aggregate_value_p (DECL_RESULT (subr)))
4882 /* Returning something that won't go in a register. */
4883 register rtx value_address = 0;
4885 #ifdef PCC_STATIC_STRUCT_RETURN
4886 if (current_function_returns_pcc_struct)
4888 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
4889 value_address = assemble_static_space (size);
4894 /* Expect to be passed the address of a place to store the value.
4895 If it is passed as an argument, assign_parms will take care of
4897 if (struct_value_incoming_rtx)
4899 value_address = gen_reg_rtx (Pmode);
4900 emit_move_insn (value_address, struct_value_incoming_rtx);
4905 DECL_RTL (DECL_RESULT (subr))
4906 = gen_rtx (MEM, DECL_MODE (DECL_RESULT (subr)), value_address);
4907 MEM_IN_STRUCT_P (DECL_RTL (DECL_RESULT (subr)))
4908 = AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
4911 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
4912 /* If return mode is void, this decl rtl should not be used. */
4913 DECL_RTL (DECL_RESULT (subr)) = 0;
4914 else if (parms_have_cleanups)
4916 /* If function will end with cleanup code for parms,
4917 compute the return values into a pseudo reg,
4918 which we will copy into the true return register
4919 after the cleanups are done. */
4921 enum machine_mode mode = DECL_MODE (DECL_RESULT (subr));
4923 #ifdef PROMOTE_FUNCTION_RETURN
4924 tree type = TREE_TYPE (DECL_RESULT (subr));
4925 int unsignedp = TREE_UNSIGNED (type);
4927 mode = promote_mode (type, mode, &unsignedp, 1);
4930 DECL_RTL (DECL_RESULT (subr)) = gen_reg_rtx (mode);
4933 /* Scalar, returned in a register. */
4935 #ifdef FUNCTION_OUTGOING_VALUE
4936 DECL_RTL (DECL_RESULT (subr))
4937 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
4939 DECL_RTL (DECL_RESULT (subr))
4940 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
4943 /* Mark this reg as the function's return value. */
4944 if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG)
4946 REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1;
4947 /* Needed because we may need to move this to memory
4948 in case it's a named return value whose address is taken. */
4949 DECL_REGISTER (DECL_RESULT (subr)) = 1;
4953 /* Initialize rtx for parameters and local variables.
4954 In some cases this requires emitting insns. */
4956 assign_parms (subr, 0);
4958 #ifdef SMALL_REGISTER_CLASSES
4959 /* Copy the static chain now if it wasn't a register. The delay is to
4960 avoid conflicts with the parameter passing registers. */
4962 if (current_function_needs_context)
4963 if (GET_CODE (static_chain_incoming_rtx) != REG)
4964 emit_move_insn (last_ptr, static_chain_incoming_rtx);
4967 /* The following was moved from init_function_start.
4968 The move is supposed to make sdb output more accurate. */
4969 /* Indicate the beginning of the function body,
4970 as opposed to parm setup. */
4971 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_BEG);
4973 /* If doing stupid allocation, mark parms as born here. */
4975 if (GET_CODE (get_last_insn ()) != NOTE)
4976 emit_note (NULL_PTR, NOTE_INSN_DELETED);
4977 parm_birth_insn = get_last_insn ();
4981 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
4982 use_variable (regno_reg_rtx[i]);
4984 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
4985 use_variable (current_function_internal_arg_pointer);
4988 /* Fetch static chain values for containing functions. */
4989 tem = decl_function_context (current_function_decl);
4990 /* If not doing stupid register allocation copy the static chain
4991 pointer into a psuedo. If we have small register classes, copy the
4992 value from memory if static_chain_incoming_rtx is a REG. If we do
4993 stupid register allocation, we use the stack address generated above. */
4994 if (tem && ! obey_regdecls)
4996 #ifdef SMALL_REGISTER_CLASSES
4997 /* If the static chain originally came in a register, put it back
4998 there, then move it out in the next insn. The reason for
4999 this peculiar code is to satisfy function integration. */
5000 if (GET_CODE (static_chain_incoming_rtx) == REG)
5001 emit_move_insn (static_chain_incoming_rtx, last_ptr);
5004 last_ptr = copy_to_reg (static_chain_incoming_rtx);
5007 context_display = 0;
5010 tree rtlexp = make_node (RTL_EXPR);
5012 RTL_EXPR_RTL (rtlexp) = last_ptr;
5013 context_display = tree_cons (tem, rtlexp, context_display);
5014 tem = decl_function_context (tem);
5017 /* Chain thru stack frames, assuming pointer to next lexical frame
5018 is found at the place we always store it. */
5019 #ifdef FRAME_GROWS_DOWNWARD
5020 last_ptr = plus_constant (last_ptr, - GET_MODE_SIZE (Pmode));
5022 last_ptr = copy_to_reg (gen_rtx (MEM, Pmode,
5023 memory_address (Pmode, last_ptr)));
5025 /* If we are not optimizing, ensure that we know that this
5026 piece of context is live over the entire function. */
5028 save_expr_regs = gen_rtx (EXPR_LIST, VOIDmode, last_ptr,
5032 /* After the display initializations is where the tail-recursion label
5033 should go, if we end up needing one. Ensure we have a NOTE here
5034 since some things (like trampolines) get placed before this. */
5035 tail_recursion_reentry = emit_note (NULL_PTR, NOTE_INSN_DELETED);
5037 /* Evaluate now the sizes of any types declared among the arguments. */
5038 for (tem = nreverse (get_pending_sizes ()); tem; tem = TREE_CHAIN (tem))
5039 expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode, 0);
5041 /* Make sure there is a line number after the function entry setup code. */
5042 force_next_line_note ();
5045 /* Generate RTL for the end of the current function.
5046 FILENAME and LINE are the current position in the source file.
5048 It is up to language-specific callers to do cleanups for parameters--
5049 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */
5052 expand_function_end (filename, line, end_bindings)
5060 static rtx initial_trampoline;
5062 if (output_bytecode)
5064 bc_expand_function_end ();
5068 #ifdef NON_SAVING_SETJMP
5069 /* Don't put any variables in registers if we call setjmp
5070 on a machine that fails to restore the registers. */
5071 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
5073 if (DECL_INITIAL (current_function_decl) != error_mark_node)
5074 setjmp_protect (DECL_INITIAL (current_function_decl));
5076 setjmp_protect_args ();
5080 /* Save the argument pointer if a save area was made for it. */
5081 if (arg_pointer_save_area)
5083 rtx x = gen_move_insn (arg_pointer_save_area, virtual_incoming_args_rtx);
5084 emit_insn_before (x, tail_recursion_reentry);
5087 /* Initialize any trampolines required by this function. */
5088 for (link = trampoline_list; link; link = TREE_CHAIN (link))
5090 tree function = TREE_PURPOSE (link);
5091 rtx context = lookup_static_chain (function);
5092 rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
5095 /* First make sure this compilation has a template for
5096 initializing trampolines. */
5097 if (initial_trampoline == 0)
5099 end_temporary_allocation ();
5101 = gen_rtx (MEM, BLKmode, assemble_trampoline_template ());
5102 resume_temporary_allocation ();
5105 /* Generate insns to initialize the trampoline. */
5107 tramp = change_address (initial_trampoline, BLKmode,
5108 round_trampoline_addr (XEXP (tramp, 0)));
5109 emit_block_move (tramp, initial_trampoline, GEN_INT (TRAMPOLINE_SIZE),
5110 FUNCTION_BOUNDARY / BITS_PER_UNIT);
5111 INITIALIZE_TRAMPOLINE (XEXP (tramp, 0),
5112 XEXP (DECL_RTL (function), 0), context);
5116 /* Put those insns at entry to the containing function (this one). */
5117 emit_insns_before (seq, tail_recursion_reentry);
5120 #if 0 /* I think unused parms are legitimate enough. */
5121 /* Warn about unused parms. */
5126 for (decl = DECL_ARGUMENTS (current_function_decl);
5127 decl; decl = TREE_CHAIN (decl))
5128 if (! TREE_USED (decl) && TREE_CODE (decl) == VAR_DECL)
5129 warning_with_decl (decl, "unused parameter `%s'");
5133 /* Delete handlers for nonlocal gotos if nothing uses them. */
5134 if (nonlocal_goto_handler_slot != 0 && !current_function_has_nonlocal_label)
5137 /* End any sequences that failed to be closed due to syntax errors. */
5138 while (in_sequence_p ())
5141 /* Outside function body, can't compute type's actual size
5142 until next function's body starts. */
5143 immediate_size_expand--;
5145 /* If doing stupid register allocation,
5146 mark register parms as dying here. */
5151 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
5152 use_variable (regno_reg_rtx[i]);
5154 /* Likewise for the regs of all the SAVE_EXPRs in the function. */
5156 for (tem = save_expr_regs; tem; tem = XEXP (tem, 1))
5158 use_variable (XEXP (tem, 0));
5159 use_variable_after (XEXP (tem, 0), parm_birth_insn);
5162 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
5163 use_variable (current_function_internal_arg_pointer);
5166 clear_pending_stack_adjust ();
5167 do_pending_stack_adjust ();
5169 /* Mark the end of the function body.
5170 If control reaches this insn, the function can drop through
5171 without returning a value. */
5172 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_END);
5174 /* Output a linenumber for the end of the function.
5175 SDB depends on this. */
5176 emit_line_note_force (filename, line);
5178 /* Output the label for the actual return from the function,
5179 if one is expected. This happens either because a function epilogue
5180 is used instead of a return instruction, or because a return was done
5181 with a goto in order to run local cleanups, or because of pcc-style
5182 structure returning. */
5185 emit_label (return_label);
5187 /* C++ uses this. */
5189 expand_end_bindings (0, 0, 0);
5191 /* If we had calls to alloca, and this machine needs
5192 an accurate stack pointer to exit the function,
5193 insert some code to save and restore the stack pointer. */
5194 #ifdef EXIT_IGNORE_STACK
5195 if (! EXIT_IGNORE_STACK)
5197 if (current_function_calls_alloca)
5201 emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
5202 emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
5205 /* If scalar return value was computed in a pseudo-reg,
5206 copy that to the hard return register. */
5207 if (DECL_RTL (DECL_RESULT (current_function_decl)) != 0
5208 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG
5209 && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl)))
5210 >= FIRST_PSEUDO_REGISTER))
5212 rtx real_decl_result;
5214 #ifdef FUNCTION_OUTGOING_VALUE
5216 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
5217 current_function_decl);
5220 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
5221 current_function_decl);
5223 REG_FUNCTION_VALUE_P (real_decl_result) = 1;
5224 emit_move_insn (real_decl_result,
5225 DECL_RTL (DECL_RESULT (current_function_decl)));
5226 emit_insn (gen_rtx (USE, VOIDmode, real_decl_result));
5229 /* If returning a structure, arrange to return the address of the value
5230 in a place where debuggers expect to find it.
5232 If returning a structure PCC style,
5233 the caller also depends on this value.
5234 And current_function_returns_pcc_struct is not necessarily set. */
5235 if (current_function_returns_struct
5236 || current_function_returns_pcc_struct)
5238 rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
5239 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
5240 #ifdef FUNCTION_OUTGOING_VALUE
5242 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
5243 current_function_decl);
5246 = FUNCTION_VALUE (build_pointer_type (type),
5247 current_function_decl);
5250 /* Mark this as a function return value so integrate will delete the
5251 assignment and USE below when inlining this function. */
5252 REG_FUNCTION_VALUE_P (outgoing) = 1;
5254 emit_move_insn (outgoing, value_address);
5255 use_variable (outgoing);
5258 /* Output a return insn if we are using one.
5259 Otherwise, let the rtl chain end here, to drop through
5260 into the epilogue. */
5265 emit_jump_insn (gen_return ());
5270 /* Fix up any gotos that jumped out to the outermost
5271 binding level of the function.
5272 Must follow emitting RETURN_LABEL. */
5274 /* If you have any cleanups to do at this point,
5275 and they need to create temporary variables,
5276 then you will lose. */
5277 expand_fixups (get_insns ());
5280 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
5282 static int *prologue;
5283 static int *epilogue;
5285 /* Create an array that records the INSN_UIDs of INSNS (either a sequence
5286 or a single insn). */
5289 record_insns (insns)
5294 if (GET_CODE (insns) == SEQUENCE)
5296 int len = XVECLEN (insns, 0);
5297 vec = (int *) oballoc ((len + 1) * sizeof (int));
5300 vec[len] = INSN_UID (XVECEXP (insns, 0, len));
5304 vec = (int *) oballoc (2 * sizeof (int));
5305 vec[0] = INSN_UID (insns);
5311 /* Determine how many INSN_UIDs in VEC are part of INSN. */
5314 contains (insn, vec)
5320 if (GET_CODE (insn) == INSN
5321 && GET_CODE (PATTERN (insn)) == SEQUENCE)
5324 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
5325 for (j = 0; vec[j]; j++)
5326 if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == vec[j])
5332 for (j = 0; vec[j]; j++)
5333 if (INSN_UID (insn) == vec[j])
5339 /* Generate the prologe and epilogue RTL if the machine supports it. Thread
5340 this into place with notes indicating where the prologue ends and where
5341 the epilogue begins. Update the basic block information when possible. */
5344 thread_prologue_and_epilogue_insns (f)
5347 #ifdef HAVE_prologue
5350 rtx head, seq, insn;
5352 /* The first insn (a NOTE_INSN_DELETED) is followed by zero or more
5353 prologue insns and a NOTE_INSN_PROLOGUE_END. */
5354 emit_note_after (NOTE_INSN_PROLOGUE_END, f);
5355 seq = gen_prologue ();
5356 head = emit_insn_after (seq, f);
5358 /* Include the new prologue insns in the first block. Ignore them
5359 if they form a basic block unto themselves. */
5360 if (basic_block_head && n_basic_blocks
5361 && GET_CODE (basic_block_head[0]) != CODE_LABEL)
5362 basic_block_head[0] = NEXT_INSN (f);
5364 /* Retain a map of the prologue insns. */
5365 prologue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : head);
5371 #ifdef HAVE_epilogue
5374 rtx insn = get_last_insn ();
5375 rtx prev = prev_nonnote_insn (insn);
5377 /* If we end with a BARRIER, we don't need an epilogue. */
5378 if (! (prev && GET_CODE (prev) == BARRIER))
5384 /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, the
5385 epilogue insns, the USE insns at the end of a function,
5386 the jump insn that returns, and then a BARRIER. */
5388 /* Move the USE insns at the end of a function onto a list. */
5390 && GET_CODE (prev) == INSN
5391 && GET_CODE (PATTERN (prev)) == USE)
5394 prev = prev_nonnote_insn (prev);
5396 NEXT_INSN (PREV_INSN (tem)) = NEXT_INSN (tem);
5397 PREV_INSN (NEXT_INSN (tem)) = PREV_INSN (tem);
5400 NEXT_INSN (tem) = first_use;
5401 PREV_INSN (first_use) = tem;
5408 emit_barrier_after (insn);
5410 seq = gen_epilogue ();
5411 tail = emit_jump_insn_after (seq, insn);
5413 /* Insert the USE insns immediately before the return insn, which
5414 must be the first instruction before the final barrier. */
5417 tem = prev_nonnote_insn (get_last_insn ());
5418 NEXT_INSN (PREV_INSN (tem)) = first_use;
5419 PREV_INSN (first_use) = PREV_INSN (tem);
5420 PREV_INSN (tem) = last_use;
5421 NEXT_INSN (last_use) = tem;
5424 emit_note_after (NOTE_INSN_EPILOGUE_BEG, insn);
5426 /* Include the new epilogue insns in the last block. Ignore
5427 them if they form a basic block unto themselves. */
5428 if (basic_block_end && n_basic_blocks
5429 && GET_CODE (basic_block_end[n_basic_blocks - 1]) != JUMP_INSN)
5430 basic_block_end[n_basic_blocks - 1] = tail;
5432 /* Retain a map of the epilogue insns. */
5433 epilogue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : tail);
5441 /* Reposition the prologue-end and epilogue-begin notes after instruction
5442 scheduling and delayed branch scheduling. */
5445 reposition_prologue_and_epilogue_notes (f)
5448 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
5449 /* Reposition the prologue and epilogue notes. */
5457 register rtx insn, note = 0;
5459 /* Scan from the beginning until we reach the last prologue insn.
5460 We apparently can't depend on basic_block_{head,end} after
5462 for (len = 0; prologue[len]; len++)
5464 for (insn = f; len && insn; insn = NEXT_INSN (insn))
5466 if (GET_CODE (insn) == NOTE)
5468 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
5471 else if ((len -= contains (insn, prologue)) == 0)
5473 /* Find the prologue-end note if we haven't already, and
5474 move it to just after the last prologue insn. */
5477 for (note = insn; note = NEXT_INSN (note);)
5478 if (GET_CODE (note) == NOTE
5479 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
5482 next = NEXT_INSN (note);
5483 prev = PREV_INSN (note);
5485 NEXT_INSN (prev) = next;
5487 PREV_INSN (next) = prev;
5488 add_insn_after (note, insn);
5495 register rtx insn, note = 0;
5497 /* Scan from the end until we reach the first epilogue insn.
5498 We apparently can't depend on basic_block_{head,end} after
5500 for (len = 0; epilogue[len]; len++)
5502 for (insn = get_last_insn (); len && insn; insn = PREV_INSN (insn))
5504 if (GET_CODE (insn) == NOTE)
5506 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
5509 else if ((len -= contains (insn, epilogue)) == 0)
5511 /* Find the epilogue-begin note if we haven't already, and
5512 move it to just before the first epilogue insn. */
5515 for (note = insn; note = PREV_INSN (note);)
5516 if (GET_CODE (note) == NOTE
5517 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
5520 next = NEXT_INSN (note);
5521 prev = PREV_INSN (note);
5523 NEXT_INSN (prev) = next;
5525 PREV_INSN (next) = prev;
5526 add_insn_after (note, PREV_INSN (insn));
5531 #endif /* HAVE_prologue or HAVE_epilogue */