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. If ACCUMULATE_OUTGOING_ARGS is
156 defined, the needed space is pushed by the prologue. */
158 int current_function_outgoing_args_size;
160 /* This is the offset from the arg pointer to the place where the first
161 anonymous arg can be found, if there is one. */
163 rtx current_function_arg_offset_rtx;
165 /* Nonzero if current function uses varargs.h or equivalent.
166 Zero for functions that use stdarg.h. */
168 int current_function_varargs;
170 /* Quantities of various kinds of registers
171 used for the current function's args. */
173 CUMULATIVE_ARGS current_function_args_info;
175 /* Name of function now being compiled. */
177 char *current_function_name;
179 /* If non-zero, an RTL expression for that location at which the current
180 function returns its result. Always equal to
181 DECL_RTL (DECL_RESULT (current_function_decl)), but provided
182 independently of the tree structures. */
184 rtx current_function_return_rtx;
186 /* Nonzero if the current function uses the constant pool. */
188 int current_function_uses_const_pool;
190 /* Nonzero if the current function uses pic_offset_table_rtx. */
191 int current_function_uses_pic_offset_table;
193 /* The arg pointer hard register, or the pseudo into which it was copied. */
194 rtx current_function_internal_arg_pointer;
196 /* The FUNCTION_DECL for an inline function currently being expanded. */
197 tree inline_function_decl;
199 /* Number of function calls seen so far in current function. */
201 int function_call_count;
203 /* List (chain of TREE_LIST) of LABEL_DECLs for all nonlocal labels
204 (labels to which there can be nonlocal gotos from nested functions)
207 tree nonlocal_labels;
209 /* RTX for stack slot that holds the current handler for nonlocal gotos.
210 Zero when function does not have nonlocal labels. */
212 rtx nonlocal_goto_handler_slot;
214 /* RTX for stack slot that holds the stack pointer value to restore
216 Zero when function does not have nonlocal labels. */
218 rtx nonlocal_goto_stack_level;
220 /* Label that will go on parm cleanup code, if any.
221 Jumping to this label runs cleanup code for parameters, if
222 such code must be run. Following this code is the logical return label. */
226 /* Label that will go on function epilogue.
227 Jumping to this label serves as a "return" instruction
228 on machines which require execution of the epilogue on all returns. */
232 /* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs.
233 So we can mark them all live at the end of the function, if nonopt. */
236 /* List (chain of EXPR_LISTs) of all stack slots in this function.
237 Made for the sake of unshare_all_rtl. */
240 /* Chain of all RTL_EXPRs that have insns in them. */
243 /* Label to jump back to for tail recursion, or 0 if we have
244 not yet needed one for this function. */
245 rtx tail_recursion_label;
247 /* Place after which to insert the tail_recursion_label if we need one. */
248 rtx tail_recursion_reentry;
250 /* Location at which to save the argument pointer if it will need to be
251 referenced. There are two cases where this is done: if nonlocal gotos
252 exist, or if vars stored at an offset from the argument pointer will be
253 needed by inner routines. */
255 rtx arg_pointer_save_area;
257 /* Offset to end of allocated area of stack frame.
258 If stack grows down, this is the address of the last stack slot allocated.
259 If stack grows up, this is the address for the next slot. */
262 /* List (chain of TREE_LISTs) of static chains for containing functions.
263 Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
264 in an RTL_EXPR in the TREE_VALUE. */
265 static tree context_display;
267 /* List (chain of TREE_LISTs) of trampolines for nested functions.
268 The trampoline sets up the static chain and jumps to the function.
269 We supply the trampoline's address when the function's address is requested.
271 Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
272 in an RTL_EXPR in the TREE_VALUE. */
273 static tree trampoline_list;
275 /* Insn after which register parms and SAVE_EXPRs are born, if nonopt. */
276 static rtx parm_birth_insn;
279 /* Nonzero if a stack slot has been generated whose address is not
280 actually valid. It means that the generated rtl must all be scanned
281 to detect and correct the invalid addresses where they occur. */
282 static int invalid_stack_slot;
285 /* Last insn of those whose job was to put parms into their nominal homes. */
286 static rtx last_parm_insn;
288 /* 1 + last pseudo register number used for loading a copy
289 of a parameter of this function. */
290 static int max_parm_reg;
292 /* Vector indexed by REGNO, containing location on stack in which
293 to put the parm which is nominally in pseudo register REGNO,
294 if we discover that that parm must go in the stack. */
295 static rtx *parm_reg_stack_loc;
297 #if 0 /* Turned off because 0 seems to work just as well. */
298 /* Cleanup lists are required for binding levels regardless of whether
299 that binding level has cleanups or not. This node serves as the
300 cleanup list whenever an empty list is required. */
301 static tree empty_cleanup_list;
304 /* Nonzero once virtual register instantiation has been done.
305 assign_stack_local uses frame_pointer_rtx when this is nonzero. */
306 static int virtuals_instantiated;
308 /* These variables hold pointers to functions to
309 save and restore machine-specific data,
310 in push_function_context and pop_function_context. */
311 void (*save_machine_status) ();
312 void (*restore_machine_status) ();
314 /* Nonzero if we need to distinguish between the return value of this function
315 and the return value of a function called by this function. This helps
318 extern int rtx_equal_function_value_matters;
319 extern tree sequence_rtl_expr;
320 extern tree bc_runtime_type_code ();
321 extern rtx bc_build_calldesc ();
322 extern char *bc_emit_trampoline ();
323 extern char *bc_end_function ();
325 /* In order to evaluate some expressions, such as function calls returning
326 structures in memory, we need to temporarily allocate stack locations.
327 We record each allocated temporary in the following structure.
329 Associated with each temporary slot is a nesting level. When we pop up
330 one level, all temporaries associated with the previous level are freed.
331 Normally, all temporaries are freed after the execution of the statement
332 in which they were created. However, if we are inside a ({...}) grouping,
333 the result may be in a temporary and hence must be preserved. If the
334 result could be in a temporary, we preserve it if we can determine which
335 one it is in. If we cannot determine which temporary may contain the
336 result, all temporaries are preserved. A temporary is preserved by
337 pretending it was allocated at the previous nesting level.
339 Automatic variables are also assigned temporary slots, at the nesting
340 level where they are defined. They are marked a "kept" so that
341 free_temp_slots will not free them. */
345 /* Points to next temporary slot. */
346 struct temp_slot *next;
347 /* The rtx to used to reference the slot. */
349 /* The rtx used to represent the address if not the address of the
350 slot above. May be an EXPR_LIST if multiple addresses exist. */
352 /* The size, in units, of the slot. */
354 /* The value of `sequence_rtl_expr' when this temporary is allocated. */
356 /* Non-zero if this temporary is currently in use. */
358 /* Non-zero if this temporary has its address taken. */
360 /* Nesting level at which this slot is being used. */
362 /* Non-zero if this should survive a call to free_temp_slots. */
366 /* List of all temporaries allocated, both available and in use. */
368 struct temp_slot *temp_slots;
370 /* Current nesting level for temporaries. */
374 /* The FUNCTION_DECL node for the current function. */
375 static tree this_function_decl;
377 /* Callinfo pointer for the current function. */
378 static rtx this_function_callinfo;
380 /* The label in the bytecode file of this function's actual bytecode.
382 static char *this_function_bytecode;
384 /* The call description vector for the current function. */
385 static rtx this_function_calldesc;
387 /* Size of the local variables allocated for the current function. */
390 /* Current depth of the bytecode evaluation stack. */
393 /* Maximum depth of the evaluation stack in this function. */
396 /* Current depth in statement expressions. */
397 static int stmt_expr_depth;
399 /* This structure is used to record MEMs or pseudos used to replace VAR, any
400 SUBREGs of VAR, and any MEMs containing VAR as an address. We need to
401 maintain this list in case two operands of an insn were required to match;
402 in that case we must ensure we use the same replacement. */
404 struct fixup_replacement
408 struct fixup_replacement *next;
411 /* Forward declarations. */
413 static struct temp_slot *find_temp_slot_from_address PROTO((rtx));
414 static void put_reg_into_stack PROTO((struct function *, rtx, tree,
415 enum machine_mode, enum machine_mode));
416 static void fixup_var_refs PROTO((rtx, enum machine_mode, int));
417 static struct fixup_replacement
418 *find_fixup_replacement PROTO((struct fixup_replacement **, rtx));
419 static void fixup_var_refs_insns PROTO((rtx, enum machine_mode, int,
421 static void fixup_var_refs_1 PROTO((rtx, enum machine_mode, rtx *, rtx,
422 struct fixup_replacement **));
423 static rtx fixup_memory_subreg PROTO((rtx, rtx, int));
424 static rtx walk_fixup_memory_subreg PROTO((rtx, rtx, int));
425 static rtx fixup_stack_1 PROTO((rtx, rtx));
426 static void optimize_bit_field PROTO((rtx, rtx, rtx *));
427 static void instantiate_decls PROTO((tree, int));
428 static void instantiate_decls_1 PROTO((tree, int));
429 static void instantiate_decl PROTO((rtx, int, int));
430 static int instantiate_virtual_regs_1 PROTO((rtx *, rtx, int));
431 static void delete_handlers PROTO((void));
432 static void pad_to_arg_alignment PROTO((struct args_size *, int));
433 static void pad_below PROTO((struct args_size *, enum machine_mode,
435 static tree round_down PROTO((tree, int));
436 static rtx round_trampoline_addr PROTO((rtx));
437 static tree blocks_nreverse PROTO((tree));
438 static int all_blocks PROTO((tree, tree *));
439 static int *record_insns PROTO((rtx));
440 static int contains PROTO((rtx, int *));
442 /* Pointer to chain of `struct function' for containing functions. */
443 struct function *outer_function_chain;
445 /* Given a function decl for a containing function,
446 return the `struct function' for it. */
449 find_function_data (decl)
453 for (p = outer_function_chain; p; p = p->next)
459 /* Save the current context for compilation of a nested function.
460 This is called from language-specific code.
461 The caller is responsible for saving any language-specific status,
462 since this function knows only about language-independent variables. */
465 push_function_context_to (toplevel)
468 struct function *p = (struct function *) xmalloc (sizeof (struct function));
470 p->next = outer_function_chain;
471 outer_function_chain = p;
473 p->name = current_function_name;
474 p->decl = current_function_decl;
475 p->pops_args = current_function_pops_args;
476 p->returns_struct = current_function_returns_struct;
477 p->returns_pcc_struct = current_function_returns_pcc_struct;
478 p->needs_context = current_function_needs_context;
479 p->calls_setjmp = current_function_calls_setjmp;
480 p->calls_longjmp = current_function_calls_longjmp;
481 p->calls_alloca = current_function_calls_alloca;
482 p->has_nonlocal_label = current_function_has_nonlocal_label;
483 p->has_nonlocal_goto = current_function_has_nonlocal_goto;
484 p->args_size = current_function_args_size;
485 p->pretend_args_size = current_function_pretend_args_size;
486 p->arg_offset_rtx = current_function_arg_offset_rtx;
487 p->varargs = current_function_varargs;
488 p->uses_const_pool = current_function_uses_const_pool;
489 p->uses_pic_offset_table = current_function_uses_pic_offset_table;
490 p->internal_arg_pointer = current_function_internal_arg_pointer;
491 p->max_parm_reg = max_parm_reg;
492 p->parm_reg_stack_loc = parm_reg_stack_loc;
493 p->outgoing_args_size = current_function_outgoing_args_size;
494 p->return_rtx = current_function_return_rtx;
495 p->nonlocal_goto_handler_slot = nonlocal_goto_handler_slot;
496 p->nonlocal_goto_stack_level = nonlocal_goto_stack_level;
497 p->nonlocal_labels = nonlocal_labels;
498 p->cleanup_label = cleanup_label;
499 p->return_label = return_label;
500 p->save_expr_regs = save_expr_regs;
501 p->stack_slot_list = stack_slot_list;
502 p->parm_birth_insn = parm_birth_insn;
503 p->frame_offset = frame_offset;
504 p->tail_recursion_label = tail_recursion_label;
505 p->tail_recursion_reentry = tail_recursion_reentry;
506 p->arg_pointer_save_area = arg_pointer_save_area;
507 p->rtl_expr_chain = rtl_expr_chain;
508 p->last_parm_insn = last_parm_insn;
509 p->context_display = context_display;
510 p->trampoline_list = trampoline_list;
511 p->function_call_count = function_call_count;
512 p->temp_slots = temp_slots;
513 p->temp_slot_level = temp_slot_level;
514 p->fixup_var_refs_queue = 0;
515 p->epilogue_delay_list = current_function_epilogue_delay_list;
517 save_tree_status (p, toplevel);
518 save_storage_status (p);
519 save_emit_status (p);
521 save_expr_status (p);
522 save_stmt_status (p);
523 save_varasm_status (p);
525 if (save_machine_status)
526 (*save_machine_status) (p);
530 push_function_context ()
532 push_function_context_to (0);
535 /* Restore the last saved context, at the end of a nested function.
536 This function is called from language-specific code. */
539 pop_function_context_from (toplevel)
542 struct function *p = outer_function_chain;
544 outer_function_chain = p->next;
546 current_function_name = p->name;
547 current_function_decl = p->decl;
548 current_function_pops_args = p->pops_args;
549 current_function_returns_struct = p->returns_struct;
550 current_function_returns_pcc_struct = p->returns_pcc_struct;
551 current_function_needs_context = p->needs_context;
552 current_function_calls_setjmp = p->calls_setjmp;
553 current_function_calls_longjmp = p->calls_longjmp;
554 current_function_calls_alloca = p->calls_alloca;
555 current_function_has_nonlocal_label = p->has_nonlocal_label;
556 current_function_has_nonlocal_goto = p->has_nonlocal_goto;
558 current_function_contains_functions = 1;
559 current_function_args_size = p->args_size;
560 current_function_pretend_args_size = p->pretend_args_size;
561 current_function_arg_offset_rtx = p->arg_offset_rtx;
562 current_function_varargs = p->varargs;
563 current_function_uses_const_pool = p->uses_const_pool;
564 current_function_uses_pic_offset_table = p->uses_pic_offset_table;
565 current_function_internal_arg_pointer = p->internal_arg_pointer;
566 max_parm_reg = p->max_parm_reg;
567 parm_reg_stack_loc = p->parm_reg_stack_loc;
568 current_function_outgoing_args_size = p->outgoing_args_size;
569 current_function_return_rtx = p->return_rtx;
570 nonlocal_goto_handler_slot = p->nonlocal_goto_handler_slot;
571 nonlocal_goto_stack_level = p->nonlocal_goto_stack_level;
572 nonlocal_labels = p->nonlocal_labels;
573 cleanup_label = p->cleanup_label;
574 return_label = p->return_label;
575 save_expr_regs = p->save_expr_regs;
576 stack_slot_list = p->stack_slot_list;
577 parm_birth_insn = p->parm_birth_insn;
578 frame_offset = p->frame_offset;
579 tail_recursion_label = p->tail_recursion_label;
580 tail_recursion_reentry = p->tail_recursion_reentry;
581 arg_pointer_save_area = p->arg_pointer_save_area;
582 rtl_expr_chain = p->rtl_expr_chain;
583 last_parm_insn = p->last_parm_insn;
584 context_display = p->context_display;
585 trampoline_list = p->trampoline_list;
586 function_call_count = p->function_call_count;
587 temp_slots = p->temp_slots;
588 temp_slot_level = p->temp_slot_level;
589 current_function_epilogue_delay_list = p->epilogue_delay_list;
592 restore_tree_status (p, toplevel);
593 restore_storage_status (p);
594 restore_expr_status (p);
595 restore_emit_status (p);
596 restore_stmt_status (p);
597 restore_varasm_status (p);
599 if (restore_machine_status)
600 (*restore_machine_status) (p);
602 /* Finish doing put_var_into_stack for any of our variables
603 which became addressable during the nested function. */
605 struct var_refs_queue *queue = p->fixup_var_refs_queue;
606 for (; queue; queue = queue->next)
607 fixup_var_refs (queue->modified, queue->promoted_mode, queue->unsignedp);
612 /* Reset variables that have known state during rtx generation. */
613 rtx_equal_function_value_matters = 1;
614 virtuals_instantiated = 0;
617 void pop_function_context ()
619 pop_function_context_from (0);
622 /* Allocate fixed slots in the stack frame of the current function. */
624 /* Return size needed for stack frame based on slots so far allocated.
625 This size counts from zero. It is not rounded to STACK_BOUNDARY;
626 the caller may have to do that. */
631 #ifdef FRAME_GROWS_DOWNWARD
632 return -frame_offset;
638 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
639 with machine mode MODE.
641 ALIGN controls the amount of alignment for the address of the slot:
642 0 means according to MODE,
643 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
644 positive specifies alignment boundary in bits.
646 We do not round to stack_boundary here. */
649 assign_stack_local (mode, size, align)
650 enum machine_mode mode;
654 register rtx x, addr;
655 int bigend_correction = 0;
660 alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
662 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
664 else if (align == -1)
666 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
667 size = CEIL_ROUND (size, alignment);
670 alignment = align / BITS_PER_UNIT;
672 /* Round frame offset to that alignment.
673 We must be careful here, since FRAME_OFFSET might be negative and
674 division with a negative dividend isn't as well defined as we might
675 like. So we instead assume that ALIGNMENT is a power of two and
676 use logical operations which are unambiguous. */
677 #ifdef FRAME_GROWS_DOWNWARD
678 frame_offset = FLOOR_ROUND (frame_offset, alignment);
680 frame_offset = CEIL_ROUND (frame_offset, alignment);
683 /* On a big-endian machine, if we are allocating more space than we will use,
684 use the least significant bytes of those that are allocated. */
687 bigend_correction = size - GET_MODE_SIZE (mode);
690 #ifdef FRAME_GROWS_DOWNWARD
691 frame_offset -= size;
694 /* If we have already instantiated virtual registers, return the actual
695 address relative to the frame pointer. */
696 if (virtuals_instantiated)
697 addr = plus_constant (frame_pointer_rtx,
698 (frame_offset + bigend_correction
699 + STARTING_FRAME_OFFSET));
701 addr = plus_constant (virtual_stack_vars_rtx,
702 frame_offset + bigend_correction);
704 #ifndef FRAME_GROWS_DOWNWARD
705 frame_offset += size;
708 x = gen_rtx (MEM, mode, addr);
710 stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, x, stack_slot_list);
715 /* Assign a stack slot in a containing function.
716 First three arguments are same as in preceding function.
717 The last argument specifies the function to allocate in. */
720 assign_outer_stack_local (mode, size, align, function)
721 enum machine_mode mode;
724 struct function *function;
726 register rtx x, addr;
727 int bigend_correction = 0;
730 /* Allocate in the memory associated with the function in whose frame
732 push_obstacks (function->function_obstack,
733 function->function_maybepermanent_obstack);
737 alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
739 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
741 else if (align == -1)
743 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
744 size = CEIL_ROUND (size, alignment);
747 alignment = align / BITS_PER_UNIT;
749 /* Round frame offset to that alignment. */
750 #ifdef FRAME_GROWS_DOWNWARD
751 function->frame_offset = FLOOR_ROUND (function->frame_offset, alignment);
753 function->frame_offset = CEIL_ROUND (function->frame_offset, alignment);
756 /* On a big-endian machine, if we are allocating more space than we will use,
757 use the least significant bytes of those that are allocated. */
760 bigend_correction = size - GET_MODE_SIZE (mode);
763 #ifdef FRAME_GROWS_DOWNWARD
764 function->frame_offset -= size;
766 addr = plus_constant (virtual_stack_vars_rtx,
767 function->frame_offset + bigend_correction);
768 #ifndef FRAME_GROWS_DOWNWARD
769 function->frame_offset += size;
772 x = gen_rtx (MEM, mode, addr);
774 function->stack_slot_list
775 = gen_rtx (EXPR_LIST, VOIDmode, x, function->stack_slot_list);
782 /* Allocate a temporary stack slot and record it for possible later
785 MODE is the machine mode to be given to the returned rtx.
787 SIZE is the size in units of the space required. We do no rounding here
788 since assign_stack_local will do any required rounding.
790 KEEP is 1 if this slot is to be retained after a call to
791 free_temp_slots. Automatic variables for a block are allocated
792 with this flag. KEEP is 2, if we allocate a longer term temporary,
793 whose lifetime is controlled by CLEANUP_POINT_EXPRs. */
796 assign_stack_temp (mode, size, keep)
797 enum machine_mode mode;
801 struct temp_slot *p, *best_p = 0;
803 /* If SIZE is -1 it means that somebody tried to allocate a temporary
804 of a variable size. */
808 /* First try to find an available, already-allocated temporary that is the
809 exact size we require. */
810 for (p = temp_slots; p; p = p->next)
811 if (p->size == size && GET_MODE (p->slot) == mode && ! p->in_use)
814 /* If we didn't find, one, try one that is larger than what we want. We
815 find the smallest such. */
817 for (p = temp_slots; p; p = p->next)
818 if (p->size > size && GET_MODE (p->slot) == mode && ! p->in_use
819 && (best_p == 0 || best_p->size > p->size))
822 /* Make our best, if any, the one to use. */
825 /* If there are enough aligned bytes left over, make them into a new
826 temp_slot so that the extra bytes don't get wasted. Do this only
827 for BLKmode slots, so that we can be sure of the alignment. */
828 if (GET_MODE (best_p->slot) == BLKmode)
830 int alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
831 int rounded_size = CEIL_ROUND (size, alignment);
833 if (best_p->size - rounded_size >= alignment)
835 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
836 p->in_use = p->addr_taken = 0;
837 p->size = best_p->size - rounded_size;
838 p->slot = gen_rtx (MEM, BLKmode,
839 plus_constant (XEXP (best_p->slot, 0),
842 p->next = temp_slots;
845 stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, p->slot,
848 best_p->size = rounded_size;
855 /* If we still didn't find one, make a new temporary. */
858 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
860 /* If the temp slot mode doesn't indicate the alignment,
861 use the largest possible, so no one will be disappointed. */
862 p->slot = assign_stack_local (mode, size, mode == BLKmode ? -1 : 0);
864 p->next = temp_slots;
870 p->rtl_expr = sequence_rtl_expr;
874 p->level = target_temp_slot_level;
879 p->level = temp_slot_level;
885 /* Combine temporary stack slots which are adjacent on the stack.
887 This allows for better use of already allocated stack space. This is only
888 done for BLKmode slots because we can be sure that we won't have alignment
889 problems in this case. */
892 combine_temp_slots ()
894 struct temp_slot *p, *q;
895 struct temp_slot *prev_p, *prev_q;
896 /* Determine where to free back to after this function. */
897 rtx free_pointer = rtx_alloc (CONST_INT);
899 for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots)
902 if (! p->in_use && GET_MODE (p->slot) == BLKmode)
903 for (q = p->next, prev_q = p; q; q = prev_q->next)
906 if (! q->in_use && GET_MODE (q->slot) == BLKmode)
908 if (rtx_equal_p (plus_constant (XEXP (p->slot, 0), p->size),
911 /* Q comes after P; combine Q into P. */
915 else if (rtx_equal_p (plus_constant (XEXP (q->slot, 0), q->size),
918 /* P comes after Q; combine P into Q. */
924 /* Either delete Q or advance past it. */
926 prev_q->next = q->next;
930 /* Either delete P or advance past it. */
934 prev_p->next = p->next;
936 temp_slots = p->next;
942 /* Free all the RTL made by plus_constant. */
943 rtx_free (free_pointer);
946 /* Find the temp slot corresponding to the object at address X. */
948 static struct temp_slot *
949 find_temp_slot_from_address (x)
955 for (p = temp_slots; p; p = p->next)
959 else if (XEXP (p->slot, 0) == x
963 else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST)
964 for (next = p->address; next; next = XEXP (next, 1))
965 if (XEXP (next, 0) == x)
972 /* Indicate that NEW is an alternate way of refering to the temp slot
973 that previous was known by OLD. */
976 update_temp_slot_address (old, new)
979 struct temp_slot *p = find_temp_slot_from_address (old);
981 /* If none, return. Else add NEW as an alias. */
984 else if (p->address == 0)
988 if (GET_CODE (p->address) != EXPR_LIST)
989 p->address = gen_rtx (EXPR_LIST, VOIDmode, p->address, NULL_RTX);
991 p->address = gen_rtx (EXPR_LIST, VOIDmode, new, p->address);
995 /* If X could be a reference to a temporary slot, mark the fact that its
996 adddress was taken. */
999 mark_temp_addr_taken (x)
1002 struct temp_slot *p;
1007 /* If X is not in memory or is at a constant address, it cannot be in
1008 a temporary slot. */
1009 if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1012 p = find_temp_slot_from_address (XEXP (x, 0));
1017 /* If X could be a reference to a temporary slot, mark that slot as belonging
1018 to the to one level higher. If X matched one of our slots, just mark that
1019 one. Otherwise, we can't easily predict which it is, so upgrade all of
1020 them. Kept slots need not be touched.
1022 This is called when an ({...}) construct occurs and a statement
1023 returns a value in memory. */
1026 preserve_temp_slots (x)
1029 struct temp_slot *p = 0;
1031 /* If there is no result, we still might have some objects whose address
1032 were taken, so we need to make sure they stay around. */
1035 for (p = temp_slots; p; p = p->next)
1036 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1042 /* If X is a register that is being used as a pointer, see if we have
1043 a temporary slot we know it points to. To be consistent with
1044 the code below, we really should preserve all non-kept slots
1045 if we can't find a match, but that seems to be much too costly. */
1046 if (GET_CODE (x) == REG && REGNO_POINTER_FLAG (REGNO (x)))
1047 p = find_temp_slot_from_address (x);
1049 /* If X is not in memory or is at a constant address, it cannot be in
1050 a temporary slot, but it can contain something whose address was
1052 if (p == 0 && (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))))
1054 for (p = temp_slots; p; p = p->next)
1055 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1061 /* First see if we can find a match. */
1063 p = find_temp_slot_from_address (XEXP (x, 0));
1067 /* Move everything at our level whose address was taken to our new
1068 level in case we used its address. */
1069 struct temp_slot *q;
1071 for (q = temp_slots; q; q = q->next)
1072 if (q != p && q->addr_taken && q->level == p->level)
1079 /* Otherwise, preserve all non-kept slots at this level. */
1080 for (p = temp_slots; p; p = p->next)
1081 if (p->in_use && p->level == temp_slot_level && ! p->keep)
1085 /* X is the result of an RTL_EXPR. If it is a temporary slot associated
1086 with that RTL_EXPR, promote it into a temporary slot at the present
1087 level so it will not be freed when we free slots made in the
1091 preserve_rtl_expr_result (x)
1094 struct temp_slot *p;
1096 /* If X is not in memory or is at a constant address, it cannot be in
1097 a temporary slot. */
1098 if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1101 /* If we can find a match, move it to our level unless it is already at
1103 p = find_temp_slot_from_address (XEXP (x, 0));
1106 p->level = MIN (p->level, temp_slot_level);
1113 /* Free all temporaries used so far. This is normally called at the end
1114 of generating code for a statement. Don't free any temporaries
1115 currently in use for an RTL_EXPR that hasn't yet been emitted.
1116 We could eventually do better than this since it can be reused while
1117 generating the same RTL_EXPR, but this is complex and probably not
1123 struct temp_slot *p;
1125 for (p = temp_slots; p; p = p->next)
1126 if (p->in_use && p->level == temp_slot_level && ! p->keep
1127 && p->rtl_expr == 0)
1130 combine_temp_slots ();
1133 /* Free all temporary slots used in T, an RTL_EXPR node. */
1136 free_temps_for_rtl_expr (t)
1139 struct temp_slot *p;
1141 for (p = temp_slots; p; p = p->next)
1142 if (p->rtl_expr == t)
1145 combine_temp_slots ();
1148 /* Push deeper into the nesting level for stack temporaries. */
1156 /* Pop a temporary nesting level. All slots in use in the current level
1162 struct temp_slot *p;
1164 for (p = temp_slots; p; p = p->next)
1165 if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0)
1168 combine_temp_slots ();
1173 /* Retroactively move an auto variable from a register to a stack slot.
1174 This is done when an address-reference to the variable is seen. */
1177 put_var_into_stack (decl)
1181 enum machine_mode promoted_mode, decl_mode;
1182 struct function *function = 0;
1185 if (output_bytecode)
1188 context = decl_function_context (decl);
1190 /* Get the current rtl used for this object and it's original mode. */
1191 reg = TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl) : DECL_RTL (decl);
1193 /* No need to do anything if decl has no rtx yet
1194 since in that case caller is setting TREE_ADDRESSABLE
1195 and a stack slot will be assigned when the rtl is made. */
1199 /* Get the declared mode for this object. */
1200 decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl))
1201 : DECL_MODE (decl));
1202 /* Get the mode it's actually stored in. */
1203 promoted_mode = GET_MODE (reg);
1205 /* If this variable comes from an outer function,
1206 find that function's saved context. */
1207 if (context != current_function_decl)
1208 for (function = outer_function_chain; function; function = function->next)
1209 if (function->decl == context)
1212 /* If this is a variable-size object with a pseudo to address it,
1213 put that pseudo into the stack, if the var is nonlocal. */
1214 if (DECL_NONLOCAL (decl)
1215 && GET_CODE (reg) == MEM
1216 && GET_CODE (XEXP (reg, 0)) == REG
1217 && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
1219 reg = XEXP (reg, 0);
1220 decl_mode = promoted_mode = GET_MODE (reg);
1223 /* Now we should have a value that resides in one or more pseudo regs. */
1225 if (GET_CODE (reg) == REG)
1226 put_reg_into_stack (function, reg, TREE_TYPE (decl),
1227 promoted_mode, decl_mode);
1228 else if (GET_CODE (reg) == CONCAT)
1230 /* A CONCAT contains two pseudos; put them both in the stack.
1231 We do it so they end up consecutive. */
1232 enum machine_mode part_mode = GET_MODE (XEXP (reg, 0));
1233 tree part_type = TREE_TYPE (TREE_TYPE (decl));
1234 #ifdef STACK_GROWS_DOWNWARD
1235 /* Since part 0 should have a lower address, do it second. */
1236 put_reg_into_stack (function, XEXP (reg, 1),
1237 part_type, part_mode, part_mode);
1238 put_reg_into_stack (function, XEXP (reg, 0),
1239 part_type, part_mode, part_mode);
1241 put_reg_into_stack (function, XEXP (reg, 0),
1242 part_type, part_mode, part_mode);
1243 put_reg_into_stack (function, XEXP (reg, 1),
1244 part_type, part_mode, part_mode);
1247 /* Change the CONCAT into a combined MEM for both parts. */
1248 PUT_CODE (reg, MEM);
1249 /* The two parts are in memory order already.
1250 Use the lower parts address as ours. */
1251 XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0);
1252 /* Prevent sharing of rtl that might lose. */
1253 if (GET_CODE (XEXP (reg, 0)) == PLUS)
1254 XEXP (reg, 0) = copy_rtx (XEXP (reg, 0));
1258 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1259 into the stack frame of FUNCTION (0 means the current function).
1260 DECL_MODE is the machine mode of the user-level data type.
1261 PROMOTED_MODE is the machine mode of the register. */
1264 put_reg_into_stack (function, reg, type, promoted_mode, decl_mode)
1265 struct function *function;
1268 enum machine_mode promoted_mode, decl_mode;
1274 if (REGNO (reg) < function->max_parm_reg)
1275 new = function->parm_reg_stack_loc[REGNO (reg)];
1277 new = assign_outer_stack_local (decl_mode, GET_MODE_SIZE (decl_mode),
1282 if (REGNO (reg) < max_parm_reg)
1283 new = parm_reg_stack_loc[REGNO (reg)];
1285 new = assign_stack_local (decl_mode, GET_MODE_SIZE (decl_mode), 0);
1288 XEXP (reg, 0) = XEXP (new, 0);
1289 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1290 REG_USERVAR_P (reg) = 0;
1291 PUT_CODE (reg, MEM);
1292 PUT_MODE (reg, decl_mode);
1294 /* If this is a memory ref that contains aggregate components,
1295 mark it as such for cse and loop optimize. */
1296 MEM_IN_STRUCT_P (reg) = AGGREGATE_TYPE_P (type);
1298 /* Now make sure that all refs to the variable, previously made
1299 when it was a register, are fixed up to be valid again. */
1302 struct var_refs_queue *temp;
1304 /* Variable is inherited; fix it up when we get back to its function. */
1305 push_obstacks (function->function_obstack,
1306 function->function_maybepermanent_obstack);
1308 /* See comment in restore_tree_status in tree.c for why this needs to be
1309 on saveable obstack. */
1311 = (struct var_refs_queue *) savealloc (sizeof (struct var_refs_queue));
1312 temp->modified = reg;
1313 temp->promoted_mode = promoted_mode;
1314 temp->unsignedp = TREE_UNSIGNED (type);
1315 temp->next = function->fixup_var_refs_queue;
1316 function->fixup_var_refs_queue = temp;
1320 /* Variable is local; fix it up now. */
1321 fixup_var_refs (reg, promoted_mode, TREE_UNSIGNED (type));
1325 fixup_var_refs (var, promoted_mode, unsignedp)
1327 enum machine_mode promoted_mode;
1331 rtx first_insn = get_insns ();
1332 struct sequence_stack *stack = sequence_stack;
1333 tree rtl_exps = rtl_expr_chain;
1335 /* Must scan all insns for stack-refs that exceed the limit. */
1336 fixup_var_refs_insns (var, promoted_mode, unsignedp, first_insn, stack == 0);
1338 /* Scan all pending sequences too. */
1339 for (; stack; stack = stack->next)
1341 push_to_sequence (stack->first);
1342 fixup_var_refs_insns (var, promoted_mode, unsignedp,
1343 stack->first, stack->next != 0);
1344 /* Update remembered end of sequence
1345 in case we added an insn at the end. */
1346 stack->last = get_last_insn ();
1350 /* Scan all waiting RTL_EXPRs too. */
1351 for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
1353 rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
1354 if (seq != const0_rtx && seq != 0)
1356 push_to_sequence (seq);
1357 fixup_var_refs_insns (var, promoted_mode, unsignedp, seq, 0);
1363 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1364 some part of an insn. Return a struct fixup_replacement whose OLD
1365 value is equal to X. Allocate a new structure if no such entry exists. */
1367 static struct fixup_replacement *
1368 find_fixup_replacement (replacements, x)
1369 struct fixup_replacement **replacements;
1372 struct fixup_replacement *p;
1374 /* See if we have already replaced this. */
1375 for (p = *replacements; p && p->old != x; p = p->next)
1380 p = (struct fixup_replacement *) oballoc (sizeof (struct fixup_replacement));
1383 p->next = *replacements;
1390 /* Scan the insn-chain starting with INSN for refs to VAR
1391 and fix them up. TOPLEVEL is nonzero if this chain is the
1392 main chain of insns for the current function. */
1395 fixup_var_refs_insns (var, promoted_mode, unsignedp, insn, toplevel)
1397 enum machine_mode promoted_mode;
1406 rtx next = NEXT_INSN (insn);
1408 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1410 /* If this is a CLOBBER of VAR, delete it.
1412 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1413 and REG_RETVAL notes too. */
1414 if (GET_CODE (PATTERN (insn)) == CLOBBER
1415 && XEXP (PATTERN (insn), 0) == var)
1417 if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0)
1418 /* The REG_LIBCALL note will go away since we are going to
1419 turn INSN into a NOTE, so just delete the
1420 corresponding REG_RETVAL note. */
1421 remove_note (XEXP (note, 0),
1422 find_reg_note (XEXP (note, 0), REG_RETVAL,
1425 /* In unoptimized compilation, we shouldn't call delete_insn
1426 except in jump.c doing warnings. */
1427 PUT_CODE (insn, NOTE);
1428 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1429 NOTE_SOURCE_FILE (insn) = 0;
1432 /* The insn to load VAR from a home in the arglist
1433 is now a no-op. When we see it, just delete it. */
1435 && GET_CODE (PATTERN (insn)) == SET
1436 && SET_DEST (PATTERN (insn)) == var
1437 /* If this represents the result of an insn group,
1438 don't delete the insn. */
1439 && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0
1440 && rtx_equal_p (SET_SRC (PATTERN (insn)), var))
1442 /* In unoptimized compilation, we shouldn't call delete_insn
1443 except in jump.c doing warnings. */
1444 PUT_CODE (insn, NOTE);
1445 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1446 NOTE_SOURCE_FILE (insn) = 0;
1447 if (insn == last_parm_insn)
1448 last_parm_insn = PREV_INSN (next);
1452 struct fixup_replacement *replacements = 0;
1453 rtx next_insn = NEXT_INSN (insn);
1455 #ifdef SMALL_REGISTER_CLASSES
1456 /* If the insn that copies the results of a CALL_INSN
1457 into a pseudo now references VAR, we have to use an
1458 intermediate pseudo since we want the life of the
1459 return value register to be only a single insn.
1461 If we don't use an intermediate pseudo, such things as
1462 address computations to make the address of VAR valid
1463 if it is not can be placed beween the CALL_INSN and INSN.
1465 To make sure this doesn't happen, we record the destination
1466 of the CALL_INSN and see if the next insn uses both that
1469 if (call_dest != 0 && GET_CODE (insn) == INSN
1470 && reg_mentioned_p (var, PATTERN (insn))
1471 && reg_mentioned_p (call_dest, PATTERN (insn)))
1473 rtx temp = gen_reg_rtx (GET_MODE (call_dest));
1475 emit_insn_before (gen_move_insn (temp, call_dest), insn);
1477 PATTERN (insn) = replace_rtx (PATTERN (insn),
1481 if (GET_CODE (insn) == CALL_INSN
1482 && GET_CODE (PATTERN (insn)) == SET)
1483 call_dest = SET_DEST (PATTERN (insn));
1484 else if (GET_CODE (insn) == CALL_INSN
1485 && GET_CODE (PATTERN (insn)) == PARALLEL
1486 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
1487 call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
1492 /* See if we have to do anything to INSN now that VAR is in
1493 memory. If it needs to be loaded into a pseudo, use a single
1494 pseudo for the entire insn in case there is a MATCH_DUP
1495 between two operands. We pass a pointer to the head of
1496 a list of struct fixup_replacements. If fixup_var_refs_1
1497 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1498 it will record them in this list.
1500 If it allocated a pseudo for any replacement, we copy into
1503 fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn,
1506 /* If this is last_parm_insn, and any instructions were output
1507 after it to fix it up, then we must set last_parm_insn to
1508 the last such instruction emitted. */
1509 if (insn == last_parm_insn)
1510 last_parm_insn = PREV_INSN (next_insn);
1512 while (replacements)
1514 if (GET_CODE (replacements->new) == REG)
1519 /* OLD might be a (subreg (mem)). */
1520 if (GET_CODE (replacements->old) == SUBREG)
1522 = fixup_memory_subreg (replacements->old, insn, 0);
1525 = fixup_stack_1 (replacements->old, insn);
1527 insert_before = insn;
1529 /* If we are changing the mode, do a conversion.
1530 This might be wasteful, but combine.c will
1531 eliminate much of the waste. */
1533 if (GET_MODE (replacements->new)
1534 != GET_MODE (replacements->old))
1537 convert_move (replacements->new,
1538 replacements->old, unsignedp);
1539 seq = gen_sequence ();
1543 seq = gen_move_insn (replacements->new,
1546 emit_insn_before (seq, insert_before);
1549 replacements = replacements->next;
1553 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1554 But don't touch other insns referred to by reg-notes;
1555 we will get them elsewhere. */
1556 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
1557 if (GET_CODE (note) != INSN_LIST)
1559 = walk_fixup_memory_subreg (XEXP (note, 0), insn, 1);
1565 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1566 See if the rtx expression at *LOC in INSN needs to be changed.
1568 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1569 contain a list of original rtx's and replacements. If we find that we need
1570 to modify this insn by replacing a memory reference with a pseudo or by
1571 making a new MEM to implement a SUBREG, we consult that list to see if
1572 we have already chosen a replacement. If none has already been allocated,
1573 we allocate it and update the list. fixup_var_refs_insns will copy VAR
1574 or the SUBREG, as appropriate, to the pseudo. */
1577 fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements)
1579 enum machine_mode promoted_mode;
1582 struct fixup_replacement **replacements;
1585 register rtx x = *loc;
1586 RTX_CODE code = GET_CODE (x);
1588 register rtx tem, tem1;
1589 struct fixup_replacement *replacement;
1596 /* If we already have a replacement, use it. Otherwise,
1597 try to fix up this address in case it is invalid. */
1599 replacement = find_fixup_replacement (replacements, var);
1600 if (replacement->new)
1602 *loc = replacement->new;
1606 *loc = replacement->new = x = fixup_stack_1 (x, insn);
1608 /* Unless we are forcing memory to register or we changed the mode,
1609 we can leave things the way they are if the insn is valid. */
1611 INSN_CODE (insn) = -1;
1612 if (! flag_force_mem && GET_MODE (x) == promoted_mode
1613 && recog_memoized (insn) >= 0)
1616 *loc = replacement->new = gen_reg_rtx (promoted_mode);
1620 /* If X contains VAR, we need to unshare it here so that we update
1621 each occurrence separately. But all identical MEMs in one insn
1622 must be replaced with the same rtx because of the possibility of
1625 if (reg_mentioned_p (var, x))
1627 replacement = find_fixup_replacement (replacements, x);
1628 if (replacement->new == 0)
1629 replacement->new = copy_most_rtx (x, var);
1631 *loc = x = replacement->new;
1647 /* Note that in some cases those types of expressions are altered
1648 by optimize_bit_field, and do not survive to get here. */
1649 if (XEXP (x, 0) == var
1650 || (GET_CODE (XEXP (x, 0)) == SUBREG
1651 && SUBREG_REG (XEXP (x, 0)) == var))
1653 /* Get TEM as a valid MEM in the mode presently in the insn.
1655 We don't worry about the possibility of MATCH_DUP here; it
1656 is highly unlikely and would be tricky to handle. */
1659 if (GET_CODE (tem) == SUBREG)
1660 tem = fixup_memory_subreg (tem, insn, 1);
1661 tem = fixup_stack_1 (tem, insn);
1663 /* Unless we want to load from memory, get TEM into the proper mode
1664 for an extract from memory. This can only be done if the
1665 extract is at a constant position and length. */
1667 if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
1668 && GET_CODE (XEXP (x, 2)) == CONST_INT
1669 && ! mode_dependent_address_p (XEXP (tem, 0))
1670 && ! MEM_VOLATILE_P (tem))
1672 enum machine_mode wanted_mode = VOIDmode;
1673 enum machine_mode is_mode = GET_MODE (tem);
1674 int width = INTVAL (XEXP (x, 1));
1675 int pos = INTVAL (XEXP (x, 2));
1678 if (GET_CODE (x) == ZERO_EXTRACT)
1679 wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
1682 if (GET_CODE (x) == SIGN_EXTRACT)
1683 wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
1685 /* If we have a narrower mode, we can do something. */
1686 if (wanted_mode != VOIDmode
1687 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
1689 int offset = pos / BITS_PER_UNIT;
1690 rtx old_pos = XEXP (x, 2);
1693 /* If the bytes and bits are counted differently, we
1694 must adjust the offset. */
1695 #if BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN
1696 offset = (GET_MODE_SIZE (is_mode)
1697 - GET_MODE_SIZE (wanted_mode) - offset);
1700 pos %= GET_MODE_BITSIZE (wanted_mode);
1702 newmem = gen_rtx (MEM, wanted_mode,
1703 plus_constant (XEXP (tem, 0), offset));
1704 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
1705 MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
1706 MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
1708 /* Make the change and see if the insn remains valid. */
1709 INSN_CODE (insn) = -1;
1710 XEXP (x, 0) = newmem;
1711 XEXP (x, 2) = GEN_INT (pos);
1713 if (recog_memoized (insn) >= 0)
1716 /* Otherwise, restore old position. XEXP (x, 0) will be
1718 XEXP (x, 2) = old_pos;
1722 /* If we get here, the bitfield extract insn can't accept a memory
1723 reference. Copy the input into a register. */
1725 tem1 = gen_reg_rtx (GET_MODE (tem));
1726 emit_insn_before (gen_move_insn (tem1, tem), insn);
1733 if (SUBREG_REG (x) == var)
1735 /* If this is a special SUBREG made because VAR was promoted
1736 from a wider mode, replace it with VAR and call ourself
1737 recursively, this time saying that the object previously
1738 had its current mode (by virtue of the SUBREG). */
1740 if (SUBREG_PROMOTED_VAR_P (x))
1743 fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements);
1747 /* If this SUBREG makes VAR wider, it has become a paradoxical
1748 SUBREG with VAR in memory, but these aren't allowed at this
1749 stage of the compilation. So load VAR into a pseudo and take
1750 a SUBREG of that pseudo. */
1751 if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
1753 replacement = find_fixup_replacement (replacements, var);
1754 if (replacement->new == 0)
1755 replacement->new = gen_reg_rtx (GET_MODE (var));
1756 SUBREG_REG (x) = replacement->new;
1760 /* See if we have already found a replacement for this SUBREG.
1761 If so, use it. Otherwise, make a MEM and see if the insn
1762 is recognized. If not, or if we should force MEM into a register,
1763 make a pseudo for this SUBREG. */
1764 replacement = find_fixup_replacement (replacements, x);
1765 if (replacement->new)
1767 *loc = replacement->new;
1771 replacement->new = *loc = fixup_memory_subreg (x, insn, 0);
1773 INSN_CODE (insn) = -1;
1774 if (! flag_force_mem && recog_memoized (insn) >= 0)
1777 *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
1783 /* First do special simplification of bit-field references. */
1784 if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
1785 || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
1786 optimize_bit_field (x, insn, 0);
1787 if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
1788 || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
1789 optimize_bit_field (x, insn, NULL_PTR);
1791 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
1792 insn into a pseudo and store the low part of the pseudo into VAR. */
1793 if (GET_CODE (SET_DEST (x)) == SUBREG
1794 && SUBREG_REG (SET_DEST (x)) == var
1795 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
1796 > GET_MODE_SIZE (GET_MODE (var))))
1798 SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
1799 emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
1806 rtx dest = SET_DEST (x);
1807 rtx src = SET_SRC (x);
1808 rtx outerdest = dest;
1810 while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
1811 || GET_CODE (dest) == SIGN_EXTRACT
1812 || GET_CODE (dest) == ZERO_EXTRACT)
1813 dest = XEXP (dest, 0);
1815 if (GET_CODE (src) == SUBREG)
1816 src = XEXP (src, 0);
1818 /* If VAR does not appear at the top level of the SET
1819 just scan the lower levels of the tree. */
1821 if (src != var && dest != var)
1824 /* We will need to rerecognize this insn. */
1825 INSN_CODE (insn) = -1;
1828 if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var)
1830 /* Since this case will return, ensure we fixup all the
1832 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1),
1833 insn, replacements);
1834 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2),
1835 insn, replacements);
1836 fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x),
1837 insn, replacements);
1839 tem = XEXP (outerdest, 0);
1841 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
1842 that may appear inside a ZERO_EXTRACT.
1843 This was legitimate when the MEM was a REG. */
1844 if (GET_CODE (tem) == SUBREG
1845 && SUBREG_REG (tem) == var)
1846 tem = fixup_memory_subreg (tem, insn, 1);
1848 tem = fixup_stack_1 (tem, insn);
1850 if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
1851 && GET_CODE (XEXP (outerdest, 2)) == CONST_INT
1852 && ! mode_dependent_address_p (XEXP (tem, 0))
1853 && ! MEM_VOLATILE_P (tem))
1855 enum machine_mode wanted_mode
1856 = insn_operand_mode[(int) CODE_FOR_insv][0];
1857 enum machine_mode is_mode = GET_MODE (tem);
1858 int width = INTVAL (XEXP (outerdest, 1));
1859 int pos = INTVAL (XEXP (outerdest, 2));
1861 /* If we have a narrower mode, we can do something. */
1862 if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
1864 int offset = pos / BITS_PER_UNIT;
1865 rtx old_pos = XEXP (outerdest, 2);
1868 #if BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN
1869 offset = (GET_MODE_SIZE (is_mode)
1870 - GET_MODE_SIZE (wanted_mode) - offset);
1873 pos %= GET_MODE_BITSIZE (wanted_mode);
1875 newmem = gen_rtx (MEM, wanted_mode,
1876 plus_constant (XEXP (tem, 0), offset));
1877 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
1878 MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
1879 MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
1881 /* Make the change and see if the insn remains valid. */
1882 INSN_CODE (insn) = -1;
1883 XEXP (outerdest, 0) = newmem;
1884 XEXP (outerdest, 2) = GEN_INT (pos);
1886 if (recog_memoized (insn) >= 0)
1889 /* Otherwise, restore old position. XEXP (x, 0) will be
1891 XEXP (outerdest, 2) = old_pos;
1895 /* If we get here, the bit-field store doesn't allow memory
1896 or isn't located at a constant position. Load the value into
1897 a register, do the store, and put it back into memory. */
1899 tem1 = gen_reg_rtx (GET_MODE (tem));
1900 emit_insn_before (gen_move_insn (tem1, tem), insn);
1901 emit_insn_after (gen_move_insn (tem, tem1), insn);
1902 XEXP (outerdest, 0) = tem1;
1907 /* STRICT_LOW_PART is a no-op on memory references
1908 and it can cause combinations to be unrecognizable,
1911 if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
1912 SET_DEST (x) = XEXP (SET_DEST (x), 0);
1914 /* A valid insn to copy VAR into or out of a register
1915 must be left alone, to avoid an infinite loop here.
1916 If the reference to VAR is by a subreg, fix that up,
1917 since SUBREG is not valid for a memref.
1918 Also fix up the address of the stack slot.
1920 Note that we must not try to recognize the insn until
1921 after we know that we have valid addresses and no
1922 (subreg (mem ...) ...) constructs, since these interfere
1923 with determining the validity of the insn. */
1925 if ((SET_SRC (x) == var
1926 || (GET_CODE (SET_SRC (x)) == SUBREG
1927 && SUBREG_REG (SET_SRC (x)) == var))
1928 && (GET_CODE (SET_DEST (x)) == REG
1929 || (GET_CODE (SET_DEST (x)) == SUBREG
1930 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
1931 && x == single_set (PATTERN (insn)))
1935 replacement = find_fixup_replacement (replacements, SET_SRC (x));
1936 if (replacement->new)
1937 SET_SRC (x) = replacement->new;
1938 else if (GET_CODE (SET_SRC (x)) == SUBREG)
1939 SET_SRC (x) = replacement->new
1940 = fixup_memory_subreg (SET_SRC (x), insn, 0);
1942 SET_SRC (x) = replacement->new
1943 = fixup_stack_1 (SET_SRC (x), insn);
1945 if (recog_memoized (insn) >= 0)
1948 /* INSN is not valid, but we know that we want to
1949 copy SET_SRC (x) to SET_DEST (x) in some way. So
1950 we generate the move and see whether it requires more
1951 than one insn. If it does, we emit those insns and
1952 delete INSN. Otherwise, we an just replace the pattern
1953 of INSN; we have already verified above that INSN has
1954 no other function that to do X. */
1956 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
1957 if (GET_CODE (pat) == SEQUENCE)
1959 emit_insn_after (pat, insn);
1960 PUT_CODE (insn, NOTE);
1961 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1962 NOTE_SOURCE_FILE (insn) = 0;
1965 PATTERN (insn) = pat;
1970 if ((SET_DEST (x) == var
1971 || (GET_CODE (SET_DEST (x)) == SUBREG
1972 && SUBREG_REG (SET_DEST (x)) == var))
1973 && (GET_CODE (SET_SRC (x)) == REG
1974 || (GET_CODE (SET_SRC (x)) == SUBREG
1975 && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
1976 && x == single_set (PATTERN (insn)))
1980 if (GET_CODE (SET_DEST (x)) == SUBREG)
1981 SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn, 0);
1983 SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
1985 if (recog_memoized (insn) >= 0)
1988 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
1989 if (GET_CODE (pat) == SEQUENCE)
1991 emit_insn_after (pat, insn);
1992 PUT_CODE (insn, NOTE);
1993 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1994 NOTE_SOURCE_FILE (insn) = 0;
1997 PATTERN (insn) = pat;
2002 /* Otherwise, storing into VAR must be handled specially
2003 by storing into a temporary and copying that into VAR
2004 with a new insn after this one. Note that this case
2005 will be used when storing into a promoted scalar since
2006 the insn will now have different modes on the input
2007 and output and hence will be invalid (except for the case
2008 of setting it to a constant, which does not need any
2009 change if it is valid). We generate extra code in that case,
2010 but combine.c will eliminate it. */
2015 rtx fixeddest = SET_DEST (x);
2017 /* STRICT_LOW_PART can be discarded, around a MEM. */
2018 if (GET_CODE (fixeddest) == STRICT_LOW_PART)
2019 fixeddest = XEXP (fixeddest, 0);
2020 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
2021 if (GET_CODE (fixeddest) == SUBREG)
2022 fixeddest = fixup_memory_subreg (fixeddest, insn, 0);
2024 fixeddest = fixup_stack_1 (fixeddest, insn);
2026 temp = gen_reg_rtx (GET_MODE (SET_SRC (x)) == VOIDmode
2027 ? GET_MODE (fixeddest)
2028 : GET_MODE (SET_SRC (x)));
2030 emit_insn_after (gen_move_insn (fixeddest,
2031 gen_lowpart (GET_MODE (fixeddest),
2035 SET_DEST (x) = temp;
2040 /* Nothing special about this RTX; fix its operands. */
2042 fmt = GET_RTX_FORMAT (code);
2043 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2046 fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements);
2050 for (j = 0; j < XVECLEN (x, i); j++)
2051 fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j),
2052 insn, replacements);
2057 /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
2058 return an rtx (MEM:m1 newaddr) which is equivalent.
2059 If any insns must be emitted to compute NEWADDR, put them before INSN.
2061 UNCRITICAL nonzero means accept paradoxical subregs.
2062 This is used for subregs found inside of ZERO_EXTRACTs and in REG_NOTES. */
2065 fixup_memory_subreg (x, insn, uncritical)
2070 int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
2071 rtx addr = XEXP (SUBREG_REG (x), 0);
2072 enum machine_mode mode = GET_MODE (x);
2075 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2076 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
2080 #if BYTES_BIG_ENDIAN
2081 offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
2082 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
2084 addr = plus_constant (addr, offset);
2085 if (!flag_force_addr && memory_address_p (mode, addr))
2086 /* Shortcut if no insns need be emitted. */
2087 return change_address (SUBREG_REG (x), mode, addr);
2089 result = change_address (SUBREG_REG (x), mode, addr);
2090 emit_insn_before (gen_sequence (), insn);
2095 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2096 Replace subexpressions of X in place.
2097 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2098 Otherwise return X, with its contents possibly altered.
2100 If any insns must be emitted to compute NEWADDR, put them before INSN.
2102 UNCRITICAL is as in fixup_memory_subreg. */
2105 walk_fixup_memory_subreg (x, insn, uncritical)
2110 register enum rtx_code code;
2117 code = GET_CODE (x);
2119 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
2120 return fixup_memory_subreg (x, insn, uncritical);
2122 /* Nothing special about this RTX; fix its operands. */
2124 fmt = GET_RTX_FORMAT (code);
2125 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2128 XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn, uncritical);
2132 for (j = 0; j < XVECLEN (x, i); j++)
2134 = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn, uncritical);
2140 /* For each memory ref within X, if it refers to a stack slot
2141 with an out of range displacement, put the address in a temp register
2142 (emitting new insns before INSN to load these registers)
2143 and alter the memory ref to use that register.
2144 Replace each such MEM rtx with a copy, to avoid clobberage. */
2147 fixup_stack_1 (x, insn)
2152 register RTX_CODE code = GET_CODE (x);
2157 register rtx ad = XEXP (x, 0);
2158 /* If we have address of a stack slot but it's not valid
2159 (displacement is too large), compute the sum in a register. */
2160 if (GET_CODE (ad) == PLUS
2161 && GET_CODE (XEXP (ad, 0)) == REG
2162 && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
2163 && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER)
2164 || XEXP (ad, 0) == current_function_internal_arg_pointer)
2165 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
2168 if (memory_address_p (GET_MODE (x), ad))
2172 temp = copy_to_reg (ad);
2173 seq = gen_sequence ();
2175 emit_insn_before (seq, insn);
2176 return change_address (x, VOIDmode, temp);
2181 fmt = GET_RTX_FORMAT (code);
2182 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2185 XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
2189 for (j = 0; j < XVECLEN (x, i); j++)
2190 XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
2196 /* Optimization: a bit-field instruction whose field
2197 happens to be a byte or halfword in memory
2198 can be changed to a move instruction.
2200 We call here when INSN is an insn to examine or store into a bit-field.
2201 BODY is the SET-rtx to be altered.
2203 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2204 (Currently this is called only from function.c, and EQUIV_MEM
2208 optimize_bit_field (body, insn, equiv_mem)
2213 register rtx bitfield;
2216 enum machine_mode mode;
2218 if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
2219 || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
2220 bitfield = SET_DEST (body), destflag = 1;
2222 bitfield = SET_SRC (body), destflag = 0;
2224 /* First check that the field being stored has constant size and position
2225 and is in fact a byte or halfword suitably aligned. */
2227 if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
2228 && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
2229 && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
2231 && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
2233 register rtx memref = 0;
2235 /* Now check that the containing word is memory, not a register,
2236 and that it is safe to change the machine mode. */
2238 if (GET_CODE (XEXP (bitfield, 0)) == MEM)
2239 memref = XEXP (bitfield, 0);
2240 else if (GET_CODE (XEXP (bitfield, 0)) == REG
2242 memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
2243 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2244 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
2245 memref = SUBREG_REG (XEXP (bitfield, 0));
2246 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2248 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
2249 memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
2252 && ! mode_dependent_address_p (XEXP (memref, 0))
2253 && ! MEM_VOLATILE_P (memref))
2255 /* Now adjust the address, first for any subreg'ing
2256 that we are now getting rid of,
2257 and then for which byte of the word is wanted. */
2259 register int offset = INTVAL (XEXP (bitfield, 2));
2262 /* Adjust OFFSET to count bits from low-address byte. */
2263 #if BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN
2264 offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
2265 - offset - INTVAL (XEXP (bitfield, 1)));
2267 /* Adjust OFFSET to count bytes from low-address byte. */
2268 offset /= BITS_PER_UNIT;
2269 if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
2271 offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD;
2272 #if BYTES_BIG_ENDIAN
2273 offset -= (MIN (UNITS_PER_WORD,
2274 GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
2275 - MIN (UNITS_PER_WORD,
2276 GET_MODE_SIZE (GET_MODE (memref))));
2281 memref = change_address (memref, mode,
2282 plus_constant (XEXP (memref, 0), offset));
2283 insns = get_insns ();
2285 emit_insns_before (insns, insn);
2287 /* Store this memory reference where
2288 we found the bit field reference. */
2292 validate_change (insn, &SET_DEST (body), memref, 1);
2293 if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
2295 rtx src = SET_SRC (body);
2296 while (GET_CODE (src) == SUBREG
2297 && SUBREG_WORD (src) == 0)
2298 src = SUBREG_REG (src);
2299 if (GET_MODE (src) != GET_MODE (memref))
2300 src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
2301 validate_change (insn, &SET_SRC (body), src, 1);
2303 else if (GET_MODE (SET_SRC (body)) != VOIDmode
2304 && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
2305 /* This shouldn't happen because anything that didn't have
2306 one of these modes should have got converted explicitly
2307 and then referenced through a subreg.
2308 This is so because the original bit-field was
2309 handled by agg_mode and so its tree structure had
2310 the same mode that memref now has. */
2315 rtx dest = SET_DEST (body);
2317 while (GET_CODE (dest) == SUBREG
2318 && SUBREG_WORD (dest) == 0)
2319 dest = SUBREG_REG (dest);
2321 validate_change (insn, &SET_DEST (body), dest, 1);
2323 if (GET_MODE (dest) == GET_MODE (memref))
2324 validate_change (insn, &SET_SRC (body), memref, 1);
2327 /* Convert the mem ref to the destination mode. */
2328 rtx newreg = gen_reg_rtx (GET_MODE (dest));
2331 convert_move (newreg, memref,
2332 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
2336 validate_change (insn, &SET_SRC (body), newreg, 1);
2340 /* See if we can convert this extraction or insertion into
2341 a simple move insn. We might not be able to do so if this
2342 was, for example, part of a PARALLEL.
2344 If we succeed, write out any needed conversions. If we fail,
2345 it is hard to guess why we failed, so don't do anything
2346 special; just let the optimization be suppressed. */
2348 if (apply_change_group () && seq)
2349 emit_insns_before (seq, insn);
2354 /* These routines are responsible for converting virtual register references
2355 to the actual hard register references once RTL generation is complete.
2357 The following four variables are used for communication between the
2358 routines. They contain the offsets of the virtual registers from their
2359 respective hard registers. */
2361 static int in_arg_offset;
2362 static int var_offset;
2363 static int dynamic_offset;
2364 static int out_arg_offset;
2366 /* In most machines, the stack pointer register is equivalent to the bottom
2369 #ifndef STACK_POINTER_OFFSET
2370 #define STACK_POINTER_OFFSET 0
2373 /* If not defined, pick an appropriate default for the offset of dynamically
2374 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2375 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2377 #ifndef STACK_DYNAMIC_OFFSET
2379 #ifdef ACCUMULATE_OUTGOING_ARGS
2380 /* The bottom of the stack points to the actual arguments. If
2381 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2382 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2383 stack space for register parameters is not pushed by the caller, but
2384 rather part of the fixed stack areas and hence not included in
2385 `current_function_outgoing_args_size'. Nevertheless, we must allow
2386 for it when allocating stack dynamic objects. */
2388 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2389 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2390 (current_function_outgoing_args_size \
2391 + REG_PARM_STACK_SPACE (FNDECL) + (STACK_POINTER_OFFSET))
2394 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2395 (current_function_outgoing_args_size + (STACK_POINTER_OFFSET))
2399 #define STACK_DYNAMIC_OFFSET(FNDECL) STACK_POINTER_OFFSET
2403 /* Pass through the INSNS of function FNDECL and convert virtual register
2404 references to hard register references. */
2407 instantiate_virtual_regs (fndecl, insns)
2413 /* Compute the offsets to use for this function. */
2414 in_arg_offset = FIRST_PARM_OFFSET (fndecl);
2415 var_offset = STARTING_FRAME_OFFSET;
2416 dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
2417 out_arg_offset = STACK_POINTER_OFFSET;
2419 /* Scan all variables and parameters of this function. For each that is
2420 in memory, instantiate all virtual registers if the result is a valid
2421 address. If not, we do it later. That will handle most uses of virtual
2422 regs on many machines. */
2423 instantiate_decls (fndecl, 1);
2425 /* Initialize recognition, indicating that volatile is OK. */
2428 /* Scan through all the insns, instantiating every virtual register still
2430 for (insn = insns; insn; insn = NEXT_INSN (insn))
2431 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
2432 || GET_CODE (insn) == CALL_INSN)
2434 instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1);
2435 instantiate_virtual_regs_1 (®_NOTES (insn), NULL_RTX, 0);
2438 /* Now instantiate the remaining register equivalences for debugging info.
2439 These will not be valid addresses. */
2440 instantiate_decls (fndecl, 0);
2442 /* Indicate that, from now on, assign_stack_local should use
2443 frame_pointer_rtx. */
2444 virtuals_instantiated = 1;
2447 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
2448 all virtual registers in their DECL_RTL's.
2450 If VALID_ONLY, do this only if the resulting address is still valid.
2451 Otherwise, always do it. */
2454 instantiate_decls (fndecl, valid_only)
2460 if (DECL_INLINE (fndecl))
2461 /* When compiling an inline function, the obstack used for
2462 rtl allocation is the maybepermanent_obstack. Calling
2463 `resume_temporary_allocation' switches us back to that
2464 obstack while we process this function's parameters. */
2465 resume_temporary_allocation ();
2467 /* Process all parameters of the function. */
2468 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
2470 instantiate_decl (DECL_RTL (decl), int_size_in_bytes (TREE_TYPE (decl)),
2472 instantiate_decl (DECL_INCOMING_RTL (decl),
2473 int_size_in_bytes (TREE_TYPE (decl)), valid_only);
2476 /* Now process all variables defined in the function or its subblocks. */
2477 instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
2479 if (DECL_INLINE (fndecl))
2481 /* Save all rtl allocated for this function by raising the
2482 high-water mark on the maybepermanent_obstack. */
2484 /* All further rtl allocation is now done in the current_obstack. */
2485 rtl_in_current_obstack ();
2489 /* Subroutine of instantiate_decls: Process all decls in the given
2490 BLOCK node and all its subblocks. */
2493 instantiate_decls_1 (let, valid_only)
2499 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
2500 instantiate_decl (DECL_RTL (t), int_size_in_bytes (TREE_TYPE (t)),
2503 /* Process all subblocks. */
2504 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
2505 instantiate_decls_1 (t, valid_only);
2508 /* Subroutine of the preceding procedures: Given RTL representing a
2509 decl and the size of the object, do any instantiation required.
2511 If VALID_ONLY is non-zero, it means that the RTL should only be
2512 changed if the new address is valid. */
2515 instantiate_decl (x, size, valid_only)
2520 enum machine_mode mode;
2523 /* If this is not a MEM, no need to do anything. Similarly if the
2524 address is a constant or a register that is not a virtual register. */
2526 if (x == 0 || GET_CODE (x) != MEM)
2530 if (CONSTANT_P (addr)
2531 || (GET_CODE (addr) == REG
2532 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
2533 || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
2536 /* If we should only do this if the address is valid, copy the address.
2537 We need to do this so we can undo any changes that might make the
2538 address invalid. This copy is unfortunate, but probably can't be
2542 addr = copy_rtx (addr);
2544 instantiate_virtual_regs_1 (&addr, NULL_RTX, 0);
2549 /* Now verify that the resulting address is valid for every integer or
2550 floating-point mode up to and including SIZE bytes long. We do this
2551 since the object might be accessed in any mode and frame addresses
2554 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2555 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
2556 mode = GET_MODE_WIDER_MODE (mode))
2557 if (! memory_address_p (mode, addr))
2560 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
2561 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
2562 mode = GET_MODE_WIDER_MODE (mode))
2563 if (! memory_address_p (mode, addr))
2566 /* Otherwise, put back the address, now that we have updated it and we
2567 know it is valid. */
2572 /* Given a pointer to a piece of rtx and an optional pointer to the
2573 containing object, instantiate any virtual registers present in it.
2575 If EXTRA_INSNS, we always do the replacement and generate
2576 any extra insns before OBJECT. If it zero, we do nothing if replacement
2579 Return 1 if we either had nothing to do or if we were able to do the
2580 needed replacement. Return 0 otherwise; we only return zero if
2581 EXTRA_INSNS is zero.
2583 We first try some simple transformations to avoid the creation of extra
2587 instantiate_virtual_regs_1 (loc, object, extra_insns)
2601 /* Re-start here to avoid recursion in common cases. */
2608 code = GET_CODE (x);
2610 /* Check for some special cases. */
2627 /* We are allowed to set the virtual registers. This means that
2628 that the actual register should receive the source minus the
2629 appropriate offset. This is used, for example, in the handling
2630 of non-local gotos. */
2631 if (SET_DEST (x) == virtual_incoming_args_rtx)
2632 new = arg_pointer_rtx, offset = - in_arg_offset;
2633 else if (SET_DEST (x) == virtual_stack_vars_rtx)
2634 new = frame_pointer_rtx, offset = - var_offset;
2635 else if (SET_DEST (x) == virtual_stack_dynamic_rtx)
2636 new = stack_pointer_rtx, offset = - dynamic_offset;
2637 else if (SET_DEST (x) == virtual_outgoing_args_rtx)
2638 new = stack_pointer_rtx, offset = - out_arg_offset;
2642 /* The only valid sources here are PLUS or REG. Just do
2643 the simplest possible thing to handle them. */
2644 if (GET_CODE (SET_SRC (x)) != REG
2645 && GET_CODE (SET_SRC (x)) != PLUS)
2649 if (GET_CODE (SET_SRC (x)) != REG)
2650 temp = force_operand (SET_SRC (x), NULL_RTX);
2653 temp = force_operand (plus_constant (temp, offset), NULL_RTX);
2657 emit_insns_before (seq, object);
2660 if (!validate_change (object, &SET_SRC (x), temp, 0)
2667 instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns);
2672 /* Handle special case of virtual register plus constant. */
2673 if (CONSTANT_P (XEXP (x, 1)))
2677 /* Check for (plus (plus VIRT foo) (const_int)) first. */
2678 if (GET_CODE (XEXP (x, 0)) == PLUS)
2680 rtx inner = XEXP (XEXP (x, 0), 0);
2682 if (inner == virtual_incoming_args_rtx)
2683 new = arg_pointer_rtx, offset = in_arg_offset;
2684 else if (inner == virtual_stack_vars_rtx)
2685 new = frame_pointer_rtx, offset = var_offset;
2686 else if (inner == virtual_stack_dynamic_rtx)
2687 new = stack_pointer_rtx, offset = dynamic_offset;
2688 else if (inner == virtual_outgoing_args_rtx)
2689 new = stack_pointer_rtx, offset = out_arg_offset;
2696 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object,
2698 new = gen_rtx (PLUS, Pmode, new, XEXP (XEXP (x, 0), 1));
2701 else if (XEXP (x, 0) == virtual_incoming_args_rtx)
2702 new = arg_pointer_rtx, offset = in_arg_offset;
2703 else if (XEXP (x, 0) == virtual_stack_vars_rtx)
2704 new = frame_pointer_rtx, offset = var_offset;
2705 else if (XEXP (x, 0) == virtual_stack_dynamic_rtx)
2706 new = stack_pointer_rtx, offset = dynamic_offset;
2707 else if (XEXP (x, 0) == virtual_outgoing_args_rtx)
2708 new = stack_pointer_rtx, offset = out_arg_offset;
2711 /* We know the second operand is a constant. Unless the
2712 first operand is a REG (which has been already checked),
2713 it needs to be checked. */
2714 if (GET_CODE (XEXP (x, 0)) != REG)
2724 new = plus_constant (XEXP (x, 1), offset);
2726 /* If the new constant is zero, try to replace the sum with its
2728 if (new == const0_rtx
2729 && validate_change (object, loc, XEXP (x, 0), 0))
2732 /* Next try to replace constant with new one. */
2733 if (!validate_change (object, &XEXP (x, 1), new, 0))
2741 /* Otherwise copy the new constant into a register and replace
2742 constant with that register. */
2743 temp = gen_reg_rtx (Pmode);
2744 if (validate_change (object, &XEXP (x, 1), temp, 0))
2745 emit_insn_before (gen_move_insn (temp, new), object);
2748 /* If that didn't work, replace this expression with a
2749 register containing the sum. */
2751 new = gen_rtx (PLUS, Pmode, XEXP (x, 0), new);
2755 temp = force_operand (new, NULL_RTX);
2759 emit_insns_before (seq, object);
2760 if (! validate_change (object, loc, temp, 0)
2761 && ! validate_replace_rtx (x, temp, object))
2769 /* Fall through to generic two-operand expression case. */
2775 case DIV: case UDIV:
2776 case MOD: case UMOD:
2777 case AND: case IOR: case XOR:
2778 case ROTATERT: case ROTATE:
2779 case ASHIFTRT: case LSHIFTRT: case ASHIFT:
2781 case GE: case GT: case GEU: case GTU:
2782 case LE: case LT: case LEU: case LTU:
2783 if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
2784 instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns);
2789 /* Most cases of MEM that convert to valid addresses have already been
2790 handled by our scan of regno_reg_rtx. The only special handling we
2791 need here is to make a copy of the rtx to ensure it isn't being
2792 shared if we have to change it to a pseudo.
2794 If the rtx is a simple reference to an address via a virtual register,
2795 it can potentially be shared. In such cases, first try to make it
2796 a valid address, which can also be shared. Otherwise, copy it and
2799 First check for common cases that need no processing. These are
2800 usually due to instantiation already being done on a previous instance
2804 if (CONSTANT_ADDRESS_P (temp)
2805 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2806 || temp == arg_pointer_rtx
2808 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2809 || temp == hard_frame_pointer_rtx
2811 || temp == frame_pointer_rtx)
2814 if (GET_CODE (temp) == PLUS
2815 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
2816 && (XEXP (temp, 0) == frame_pointer_rtx
2817 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2818 || XEXP (temp, 0) == hard_frame_pointer_rtx
2820 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2821 || XEXP (temp, 0) == arg_pointer_rtx
2826 if (temp == virtual_stack_vars_rtx
2827 || temp == virtual_incoming_args_rtx
2828 || (GET_CODE (temp) == PLUS
2829 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
2830 && (XEXP (temp, 0) == virtual_stack_vars_rtx
2831 || XEXP (temp, 0) == virtual_incoming_args_rtx)))
2833 /* This MEM may be shared. If the substitution can be done without
2834 the need to generate new pseudos, we want to do it in place
2835 so all copies of the shared rtx benefit. The call below will
2836 only make substitutions if the resulting address is still
2839 Note that we cannot pass X as the object in the recursive call
2840 since the insn being processed may not allow all valid
2841 addresses. However, if we were not passed on object, we can
2842 only modify X without copying it if X will have a valid
2845 ??? Also note that this can still lose if OBJECT is an insn that
2846 has less restrictions on an address that some other insn.
2847 In that case, we will modify the shared address. This case
2848 doesn't seem very likely, though. */
2850 if (instantiate_virtual_regs_1 (&XEXP (x, 0),
2851 object ? object : x, 0))
2854 /* Otherwise make a copy and process that copy. We copy the entire
2855 RTL expression since it might be a PLUS which could also be
2857 *loc = x = copy_rtx (x);
2860 /* Fall through to generic unary operation case. */
2864 case STRICT_LOW_PART:
2866 case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC:
2867 case SIGN_EXTEND: case ZERO_EXTEND:
2868 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE:
2869 case FLOAT: case FIX:
2870 case UNSIGNED_FIX: case UNSIGNED_FLOAT:
2874 /* These case either have just one operand or we know that we need not
2875 check the rest of the operands. */
2880 /* Try to replace with a PLUS. If that doesn't work, compute the sum
2881 in front of this insn and substitute the temporary. */
2882 if (x == virtual_incoming_args_rtx)
2883 new = arg_pointer_rtx, offset = in_arg_offset;
2884 else if (x == virtual_stack_vars_rtx)
2885 new = frame_pointer_rtx, offset = var_offset;
2886 else if (x == virtual_stack_dynamic_rtx)
2887 new = stack_pointer_rtx, offset = dynamic_offset;
2888 else if (x == virtual_outgoing_args_rtx)
2889 new = stack_pointer_rtx, offset = out_arg_offset;
2893 temp = plus_constant (new, offset);
2894 if (!validate_change (object, loc, temp, 0))
2900 temp = force_operand (temp, NULL_RTX);
2904 emit_insns_before (seq, object);
2905 if (! validate_change (object, loc, temp, 0)
2906 && ! validate_replace_rtx (x, temp, object))
2914 /* Scan all subexpressions. */
2915 fmt = GET_RTX_FORMAT (code);
2916 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
2919 if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns))
2922 else if (*fmt == 'E')
2923 for (j = 0; j < XVECLEN (x, i); j++)
2924 if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object,
2931 /* Optimization: assuming this function does not receive nonlocal gotos,
2932 delete the handlers for such, as well as the insns to establish
2933 and disestablish them. */
2939 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2941 /* Delete the handler by turning off the flag that would
2942 prevent jump_optimize from deleting it.
2943 Also permit deletion of the nonlocal labels themselves
2944 if nothing local refers to them. */
2945 if (GET_CODE (insn) == CODE_LABEL)
2946 LABEL_PRESERVE_P (insn) = 0;
2947 if (GET_CODE (insn) == INSN
2948 && ((nonlocal_goto_handler_slot != 0
2949 && reg_mentioned_p (nonlocal_goto_handler_slot, PATTERN (insn)))
2950 || (nonlocal_goto_stack_level != 0
2951 && reg_mentioned_p (nonlocal_goto_stack_level,
2957 /* Return a list (chain of EXPR_LIST nodes) for the nonlocal labels
2958 of the current function. */
2961 nonlocal_label_rtx_list ()
2966 for (t = nonlocal_labels; t; t = TREE_CHAIN (t))
2967 x = gen_rtx (EXPR_LIST, VOIDmode, label_rtx (TREE_VALUE (t)), x);
2972 /* Output a USE for any register use in RTL.
2973 This is used with -noreg to mark the extent of lifespan
2974 of any registers used in a user-visible variable's DECL_RTL. */
2980 if (GET_CODE (rtl) == REG)
2981 /* This is a register variable. */
2982 emit_insn (gen_rtx (USE, VOIDmode, rtl));
2983 else if (GET_CODE (rtl) == MEM
2984 && GET_CODE (XEXP (rtl, 0)) == REG
2985 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
2986 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
2987 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
2988 /* This is a variable-sized structure. */
2989 emit_insn (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)));
2992 /* Like use_variable except that it outputs the USEs after INSN
2993 instead of at the end of the insn-chain. */
2996 use_variable_after (rtl, insn)
2999 if (GET_CODE (rtl) == REG)
3000 /* This is a register variable. */
3001 emit_insn_after (gen_rtx (USE, VOIDmode, rtl), insn);
3002 else if (GET_CODE (rtl) == MEM
3003 && GET_CODE (XEXP (rtl, 0)) == REG
3004 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
3005 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
3006 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
3007 /* This is a variable-sized structure. */
3008 emit_insn_after (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)), insn);
3014 return max_parm_reg;
3017 /* Return the first insn following those generated by `assign_parms'. */
3020 get_first_nonparm_insn ()
3023 return NEXT_INSN (last_parm_insn);
3024 return get_insns ();
3027 /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
3028 Crash if there is none. */
3031 get_first_block_beg ()
3033 register rtx searcher;
3034 register rtx insn = get_first_nonparm_insn ();
3036 for (searcher = insn; searcher; searcher = NEXT_INSN (searcher))
3037 if (GET_CODE (searcher) == NOTE
3038 && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG)
3041 abort (); /* Invalid call to this function. (See comments above.) */
3045 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
3046 This means a type for which function calls must pass an address to the
3047 function or get an address back from the function.
3048 EXP may be a type node or an expression (whose type is tested). */
3051 aggregate_value_p (exp)
3054 int i, regno, nregs;
3057 if (TREE_CODE_CLASS (TREE_CODE (exp)) == 't')
3060 type = TREE_TYPE (exp);
3062 if (RETURN_IN_MEMORY (type))
3064 if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
3066 /* Make sure we have suitable call-clobbered regs to return
3067 the value in; if not, we must return it in memory. */
3068 reg = hard_function_value (type, 0);
3069 regno = REGNO (reg);
3070 nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type));
3071 for (i = 0; i < nregs; i++)
3072 if (! call_used_regs[regno + i])
3077 /* Assign RTL expressions to the function's parameters.
3078 This may involve copying them into registers and using
3079 those registers as the RTL for them.
3081 If SECOND_TIME is non-zero it means that this function is being
3082 called a second time. This is done by integrate.c when a function's
3083 compilation is deferred. We need to come back here in case the
3084 FUNCTION_ARG macro computes items needed for the rest of the compilation
3085 (such as changing which registers are fixed or caller-saved). But suppress
3086 writing any insns or setting DECL_RTL of anything in this case. */
3089 assign_parms (fndecl, second_time)
3094 register rtx entry_parm = 0;
3095 register rtx stack_parm = 0;
3096 CUMULATIVE_ARGS args_so_far;
3097 enum machine_mode promoted_mode, passed_mode, nominal_mode;
3099 /* Total space needed so far for args on the stack,
3100 given as a constant and a tree-expression. */
3101 struct args_size stack_args_size;
3102 tree fntype = TREE_TYPE (fndecl);
3103 tree fnargs = DECL_ARGUMENTS (fndecl);
3104 /* This is used for the arg pointer when referring to stack args. */
3105 rtx internal_arg_pointer;
3106 /* This is a dummy PARM_DECL that we used for the function result if
3107 the function returns a structure. */
3108 tree function_result_decl = 0;
3109 int nparmregs = list_length (fnargs) + LAST_VIRTUAL_REGISTER + 1;
3110 int varargs_setup = 0;
3111 rtx conversion_insns = 0;
3112 /* FUNCTION_ARG may look at this variable. Since this is not
3113 expanding a call it will always be zero in this function. */
3114 int current_call_is_indirect = 0;
3116 /* Nonzero if the last arg is named `__builtin_va_alist',
3117 which is used on some machines for old-fashioned non-ANSI varargs.h;
3118 this should be stuck onto the stack as if it had arrived there. */
3120 = (current_function_varargs
3122 && (parm = tree_last (fnargs)) != 0
3124 && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
3125 "__builtin_va_alist")));
3127 /* Nonzero if function takes extra anonymous args.
3128 This means the last named arg must be on the stack
3129 right before the anonymous ones. */
3131 = (TYPE_ARG_TYPES (fntype) != 0
3132 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3133 != void_type_node));
3135 /* If the reg that the virtual arg pointer will be translated into is
3136 not a fixed reg or is the stack pointer, make a copy of the virtual
3137 arg pointer, and address parms via the copy. The frame pointer is
3138 considered fixed even though it is not marked as such.
3140 The second time through, simply use ap to avoid generating rtx. */
3142 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
3143 || ! (fixed_regs[ARG_POINTER_REGNUM]
3144 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM))
3146 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
3148 internal_arg_pointer = virtual_incoming_args_rtx;
3149 current_function_internal_arg_pointer = internal_arg_pointer;
3151 stack_args_size.constant = 0;
3152 stack_args_size.var = 0;
3154 /* If struct value address is treated as the first argument, make it so. */
3155 if (aggregate_value_p (DECL_RESULT (fndecl))
3156 && ! current_function_returns_pcc_struct
3157 && struct_value_incoming_rtx == 0)
3159 tree type = build_pointer_type (fntype);
3161 function_result_decl = build_decl (PARM_DECL, NULL_TREE, type);
3163 DECL_ARG_TYPE (function_result_decl) = type;
3164 TREE_CHAIN (function_result_decl) = fnargs;
3165 fnargs = function_result_decl;
3168 parm_reg_stack_loc = (rtx *) oballoc (nparmregs * sizeof (rtx));
3169 bzero ((char *) parm_reg_stack_loc, nparmregs * sizeof (rtx));
3171 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
3172 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX);
3174 INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX);
3177 /* We haven't yet found an argument that we must push and pretend the
3179 current_function_pretend_args_size = 0;
3181 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
3183 int aggregate = AGGREGATE_TYPE_P (TREE_TYPE (parm));
3184 struct args_size stack_offset;
3185 struct args_size arg_size;
3186 int passed_pointer = 0;
3187 tree passed_type = DECL_ARG_TYPE (parm);
3189 /* Set LAST_NAMED if this is last named arg before some
3190 anonymous args. We treat it as if it were anonymous too. */
3191 int last_named = ((TREE_CHAIN (parm) == 0
3192 || DECL_NAME (TREE_CHAIN (parm)) == 0)
3193 && (stdarg || current_function_varargs));
3195 if (TREE_TYPE (parm) == error_mark_node
3196 /* This can happen after weird syntax errors
3197 or if an enum type is defined among the parms. */
3198 || TREE_CODE (parm) != PARM_DECL
3199 || passed_type == NULL)
3201 DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = gen_rtx (MEM, BLKmode,
3203 TREE_USED (parm) = 1;
3207 /* For varargs.h function, save info about regs and stack space
3208 used by the individual args, not including the va_alist arg. */
3209 if (hide_last_arg && last_named)
3210 current_function_args_info = args_so_far;
3212 /* Find mode of arg as it is passed, and mode of arg
3213 as it should be during execution of this function. */
3214 passed_mode = TYPE_MODE (passed_type);
3215 nominal_mode = TYPE_MODE (TREE_TYPE (parm));
3217 /* If the parm's mode is VOID, its value doesn't matter,
3218 and avoid the usual things like emit_move_insn that could crash. */
3219 if (nominal_mode == VOIDmode)
3221 DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = const0_rtx;
3225 /* If the parm is to be passed as a transparent union, use the
3226 type of the first field for the tests below. We have already
3227 verified that the modes are the same. */
3228 if (DECL_TRANSPARENT_UNION (parm)
3229 || TYPE_TRANSPARENT_UNION (passed_type))
3230 passed_type = TREE_TYPE (TYPE_FIELDS (passed_type));
3232 /* See if this arg was passed by invisible reference. It is if
3233 it is an object whose size depends on the contents of the
3234 object itself or if the machine requires these objects be passed
3237 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
3238 && contains_placeholder_p (TYPE_SIZE (passed_type)))
3239 || TYPE_NEEDS_CONSTRUCTING (passed_type)
3240 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
3241 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
3242 passed_type, ! last_named)
3246 passed_type = build_pointer_type (passed_type);
3248 passed_mode = nominal_mode = Pmode;
3251 promoted_mode = passed_mode;
3253 #ifdef PROMOTE_FUNCTION_ARGS
3254 /* Compute the mode in which the arg is actually extended to. */
3255 promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1);
3258 /* Let machine desc say which reg (if any) the parm arrives in.
3259 0 means it arrives on the stack. */
3260 #ifdef FUNCTION_INCOMING_ARG
3261 entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
3262 passed_type, ! last_named);
3264 entry_parm = FUNCTION_ARG (args_so_far, promoted_mode,
3265 passed_type, ! last_named);
3269 passed_mode = promoted_mode;
3271 #ifdef SETUP_INCOMING_VARARGS
3272 /* If this is the last named parameter, do any required setup for
3273 varargs or stdargs. We need to know about the case of this being an
3274 addressable type, in which case we skip the registers it
3275 would have arrived in.
3277 For stdargs, LAST_NAMED will be set for two parameters, the one that
3278 is actually the last named, and the dummy parameter. We only
3279 want to do this action once.
3281 Also, indicate when RTL generation is to be suppressed. */
3282 if (last_named && !varargs_setup)
3284 SETUP_INCOMING_VARARGS (args_so_far, passed_mode, passed_type,
3285 current_function_pretend_args_size,
3291 /* Determine parm's home in the stack,
3292 in case it arrives in the stack or we should pretend it did.
3294 Compute the stack position and rtx where the argument arrives
3297 There is one complexity here: If this was a parameter that would
3298 have been passed in registers, but wasn't only because it is
3299 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
3300 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
3301 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
3302 0 as it was the previous time. */
3304 locate_and_pad_parm (passed_mode, passed_type,
3305 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3308 #ifdef FUNCTION_INCOMING_ARG
3309 FUNCTION_INCOMING_ARG (args_so_far, passed_mode,
3312 || varargs_setup)) != 0,
3314 FUNCTION_ARG (args_so_far, passed_mode,
3316 ! last_named || varargs_setup) != 0,
3319 fndecl, &stack_args_size, &stack_offset, &arg_size);
3323 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
3325 if (offset_rtx == const0_rtx)
3326 stack_parm = gen_rtx (MEM, passed_mode, internal_arg_pointer);
3328 stack_parm = gen_rtx (MEM, passed_mode,
3329 gen_rtx (PLUS, Pmode,
3330 internal_arg_pointer, offset_rtx));
3332 /* If this is a memory ref that contains aggregate components,
3333 mark it as such for cse and loop optimize. */
3334 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3337 /* If this parameter was passed both in registers and in the stack,
3338 use the copy on the stack. */
3339 if (MUST_PASS_IN_STACK (passed_mode, passed_type))
3342 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3343 /* If this parm was passed part in regs and part in memory,
3344 pretend it arrived entirely in memory
3345 by pushing the register-part onto the stack.
3347 In the special case of a DImode or DFmode that is split,
3348 we could put it together in a pseudoreg directly,
3349 but for now that's not worth bothering with. */
3353 int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, passed_mode,
3354 passed_type, ! last_named);
3358 current_function_pretend_args_size
3359 = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
3360 / (PARM_BOUNDARY / BITS_PER_UNIT)
3361 * (PARM_BOUNDARY / BITS_PER_UNIT));
3364 move_block_from_reg (REGNO (entry_parm),
3365 validize_mem (stack_parm), nregs,
3366 int_size_in_bytes (TREE_TYPE (parm)));
3367 entry_parm = stack_parm;
3372 /* If we didn't decide this parm came in a register,
3373 by default it came on the stack. */
3374 if (entry_parm == 0)
3375 entry_parm = stack_parm;
3377 /* Record permanently how this parm was passed. */
3379 DECL_INCOMING_RTL (parm) = entry_parm;
3381 /* If there is actually space on the stack for this parm,
3382 count it in stack_args_size; otherwise set stack_parm to 0
3383 to indicate there is no preallocated stack slot for the parm. */
3385 if (entry_parm == stack_parm
3386 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
3387 /* On some machines, even if a parm value arrives in a register
3388 there is still an (uninitialized) stack slot allocated for it.
3390 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
3391 whether this parameter already has a stack slot allocated,
3392 because an arg block exists only if current_function_args_size
3393 is larger than some threshhold, and we haven't calculated that
3394 yet. So, for now, we just assume that stack slots never exist
3396 || REG_PARM_STACK_SPACE (fndecl) > 0
3400 stack_args_size.constant += arg_size.constant;
3402 ADD_PARM_SIZE (stack_args_size, arg_size.var);
3405 /* No stack slot was pushed for this parm. */
3408 /* Update info on where next arg arrives in registers. */
3410 FUNCTION_ARG_ADVANCE (args_so_far, passed_mode,
3411 passed_type, ! last_named);
3413 /* If this is our second time through, we are done with this parm. */
3417 /* If we can't trust the parm stack slot to be aligned enough
3418 for its ultimate type, don't use that slot after entry.
3419 We'll make another stack slot, if we need one. */
3421 int thisparm_boundary
3422 = FUNCTION_ARG_BOUNDARY (passed_mode, passed_type);
3424 if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary)
3428 /* If parm was passed in memory, and we need to convert it on entry,
3429 don't store it back in that same slot. */
3431 && nominal_mode != BLKmode && nominal_mode != passed_mode)
3435 /* Now adjust STACK_PARM to the mode and precise location
3436 where this parameter should live during execution,
3437 if we discover that it must live in the stack during execution.
3438 To make debuggers happier on big-endian machines, we store
3439 the value in the last bytes of the space available. */
3441 if (nominal_mode != BLKmode && nominal_mode != passed_mode
3446 #if BYTES_BIG_ENDIAN
3447 if (GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD)
3448 stack_offset.constant += (GET_MODE_SIZE (passed_mode)
3449 - GET_MODE_SIZE (nominal_mode));
3452 offset_rtx = ARGS_SIZE_RTX (stack_offset);
3453 if (offset_rtx == const0_rtx)
3454 stack_parm = gen_rtx (MEM, nominal_mode, internal_arg_pointer);
3456 stack_parm = gen_rtx (MEM, nominal_mode,
3457 gen_rtx (PLUS, Pmode,
3458 internal_arg_pointer, offset_rtx));
3460 /* If this is a memory ref that contains aggregate components,
3461 mark it as such for cse and loop optimize. */
3462 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3466 /* ENTRY_PARM is an RTX for the parameter as it arrives,
3467 in the mode in which it arrives.
3468 STACK_PARM is an RTX for a stack slot where the parameter can live
3469 during the function (in case we want to put it there).
3470 STACK_PARM is 0 if no stack slot was pushed for it.
3472 Now output code if necessary to convert ENTRY_PARM to
3473 the type in which this function declares it,
3474 and store that result in an appropriate place,
3475 which may be a pseudo reg, may be STACK_PARM,
3476 or may be a local stack slot if STACK_PARM is 0.
3478 Set DECL_RTL to that place. */
3480 if (nominal_mode == BLKmode)
3482 /* If a BLKmode arrives in registers, copy it to a stack slot. */
3483 if (GET_CODE (entry_parm) == REG)
3485 int size_stored = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
3488 /* Note that we will be storing an integral number of words.
3489 So we have to be careful to ensure that we allocate an
3490 integral number of words. We do this below in the
3491 assign_stack_local if space was not allocated in the argument
3492 list. If it was, this will not work if PARM_BOUNDARY is not
3493 a multiple of BITS_PER_WORD. It isn't clear how to fix this
3494 if it becomes a problem. */
3496 if (stack_parm == 0)
3499 = assign_stack_local (GET_MODE (entry_parm), size_stored, 0);
3500 /* If this is a memory ref that contains aggregate components,
3501 mark it as such for cse and loop optimize. */
3502 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3505 else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
3508 if (TREE_READONLY (parm))
3509 RTX_UNCHANGING_P (stack_parm) = 1;
3511 move_block_from_reg (REGNO (entry_parm),
3512 validize_mem (stack_parm),
3513 size_stored / UNITS_PER_WORD,
3514 int_size_in_bytes (TREE_TYPE (parm)));
3516 DECL_RTL (parm) = stack_parm;
3518 else if (! ((obey_regdecls && ! DECL_REGISTER (parm)
3519 && ! DECL_INLINE (fndecl))
3520 /* layout_decl may set this. */
3521 || TREE_ADDRESSABLE (parm)
3522 || TREE_SIDE_EFFECTS (parm)
3523 /* If -ffloat-store specified, don't put explicit
3524 float variables into registers. */
3525 || (flag_float_store
3526 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
3527 /* Always assign pseudo to structure return or item passed
3528 by invisible reference. */
3529 || passed_pointer || parm == function_result_decl)
3531 /* Store the parm in a pseudoregister during the function, but we
3532 may need to do it in a wider mode. */
3534 register rtx parmreg;
3535 int regno, regnoi, regnor;
3537 unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
3538 nominal_mode = promote_mode (TREE_TYPE (parm), nominal_mode,
3541 parmreg = gen_reg_rtx (nominal_mode);
3542 REG_USERVAR_P (parmreg) = 1;
3544 /* If this was an item that we received a pointer to, set DECL_RTL
3548 DECL_RTL (parm) = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (passed_type)), parmreg);
3549 MEM_IN_STRUCT_P (DECL_RTL (parm)) = aggregate;
3552 DECL_RTL (parm) = parmreg;
3554 /* Copy the value into the register. */
3555 if (GET_MODE (parmreg) != GET_MODE (entry_parm))
3557 /* If ENTRY_PARM is a hard register, it might be in a register
3558 not valid for operating in its mode (e.g., an odd-numbered
3559 register for a DFmode). In that case, moves are the only
3560 thing valid, so we can't do a convert from there. This
3561 occurs when the calling sequence allow such misaligned
3564 In addition, the conversion may involve a call, which could
3565 clobber parameters which haven't been copied to pseudo
3566 registers yet. Therefore, we must first copy the parm to
3567 a pseudo reg here, and save the conversion until after all
3568 parameters have been moved. */
3570 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
3572 emit_move_insn (tempreg, validize_mem (entry_parm));
3574 push_to_sequence (conversion_insns);
3575 convert_move (parmreg, tempreg, unsignedp);
3576 conversion_insns = get_insns ();
3580 emit_move_insn (parmreg, validize_mem (entry_parm));
3582 /* If we were passed a pointer but the actual value
3583 can safely live in a register, put it in one. */
3584 if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
3585 && ! ((obey_regdecls && ! DECL_REGISTER (parm)
3586 && ! DECL_INLINE (fndecl))
3587 /* layout_decl may set this. */
3588 || TREE_ADDRESSABLE (parm)
3589 || TREE_SIDE_EFFECTS (parm)
3590 /* If -ffloat-store specified, don't put explicit
3591 float variables into registers. */
3592 || (flag_float_store
3593 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))
3595 /* We can't use nominal_mode, because it will have been set to
3596 Pmode above. We must use the actual mode of the parm. */
3597 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
3598 REG_USERVAR_P (parmreg) = 1;
3599 emit_move_insn (parmreg, DECL_RTL (parm));
3600 DECL_RTL (parm) = parmreg;
3601 /* STACK_PARM is the pointer, not the parm, and PARMREG is
3605 #ifdef FUNCTION_ARG_CALLEE_COPIES
3606 /* If we are passed an arg by reference and it is our responsibility
3607 to make a copy, do it now.
3608 PASSED_TYPE and PASSED mode now refer to the pointer, not the
3609 original argument, so we must recreate them in the call to
3610 FUNCTION_ARG_CALLEE_COPIES. */
3611 /* ??? Later add code to handle the case that if the argument isn't
3612 modified, don't do the copy. */
3614 else if (passed_pointer
3615 && FUNCTION_ARG_CALLEE_COPIES (args_so_far,
3616 TYPE_MODE (DECL_ARG_TYPE (parm)),
3617 DECL_ARG_TYPE (parm),
3621 tree type = DECL_ARG_TYPE (parm);
3623 /* This sequence may involve a library call perhaps clobbering
3624 registers that haven't been copied to pseudos yet. */
3626 push_to_sequence (conversion_insns);
3628 if (TYPE_SIZE (type) == 0
3629 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
3630 /* This is a variable sized object. */
3631 copy = gen_rtx (MEM, BLKmode,
3632 allocate_dynamic_stack_space
3633 (expr_size (parm), NULL_RTX,
3634 TYPE_ALIGN (type)));
3636 copy = assign_stack_temp (TYPE_MODE (type),
3637 int_size_in_bytes (type), 1);
3639 store_expr (parm, copy, 0);
3640 emit_move_insn (parmreg, XEXP (copy, 0));
3641 conversion_insns = get_insns ();
3644 #endif /* FUNCTION_ARG_CALLEE_COPIES */
3646 /* In any case, record the parm's desired stack location
3647 in case we later discover it must live in the stack.
3649 If it is a COMPLEX value, store the stack location for both
3652 if (GET_CODE (parmreg) == CONCAT)
3653 regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1)));
3655 regno = REGNO (parmreg);
3657 if (regno >= nparmregs)
3660 int old_nparmregs = nparmregs;
3662 nparmregs = regno + 5;
3663 new = (rtx *) oballoc (nparmregs * sizeof (rtx));
3664 bcopy ((char *) parm_reg_stack_loc, (char *) new,
3665 old_nparmregs * sizeof (rtx));
3666 bzero ((char *) (new + old_nparmregs),
3667 (nparmregs - old_nparmregs) * sizeof (rtx));
3668 parm_reg_stack_loc = new;
3671 if (GET_CODE (parmreg) == CONCAT)
3673 enum machine_mode submode = GET_MODE (XEXP (parmreg, 0));
3675 regnor = REGNO (gen_realpart (submode, parmreg));
3676 regnoi = REGNO (gen_imagpart (submode, parmreg));
3678 if (stack_parm != 0)
3680 parm_reg_stack_loc[regnor]
3681 = gen_realpart (submode, stack_parm);
3682 parm_reg_stack_loc[regnoi]
3683 = gen_imagpart (submode, stack_parm);
3687 parm_reg_stack_loc[regnor] = 0;
3688 parm_reg_stack_loc[regnoi] = 0;
3692 parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
3694 /* Mark the register as eliminable if we did no conversion
3695 and it was copied from memory at a fixed offset,
3696 and the arg pointer was not copied to a pseudo-reg.
3697 If the arg pointer is a pseudo reg or the offset formed
3698 an invalid address, such memory-equivalences
3699 as we make here would screw up life analysis for it. */
3700 if (nominal_mode == passed_mode
3701 && ! conversion_insns
3702 && GET_CODE (entry_parm) == MEM
3703 && entry_parm == stack_parm
3704 && stack_offset.var == 0
3705 && reg_mentioned_p (virtual_incoming_args_rtx,
3706 XEXP (entry_parm, 0)))
3708 rtx linsn = get_last_insn ();
3710 /* Mark complex types separately. */
3711 if (GET_CODE (parmreg) == CONCAT)
3714 = gen_rtx (EXPR_LIST, REG_EQUIV,
3715 parm_reg_stack_loc[regnoi], REG_NOTES (linsn));
3717 /* Now search backward for where we set the real part. */
3719 && ! reg_referenced_p (parm_reg_stack_loc[regnor],
3721 linsn = prev_nonnote_insn (linsn))
3725 = gen_rtx (EXPR_LIST, REG_EQUIV,
3726 parm_reg_stack_loc[regnor], REG_NOTES (linsn));
3730 = gen_rtx (EXPR_LIST, REG_EQUIV,
3731 entry_parm, REG_NOTES (linsn));
3734 /* For pointer data type, suggest pointer register. */
3735 if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE)
3736 mark_reg_pointer (parmreg);
3740 /* Value must be stored in the stack slot STACK_PARM
3741 during function execution. */
3743 if (passed_mode != nominal_mode)
3745 /* Conversion is required. */
3746 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
3748 emit_move_insn (tempreg, validize_mem (entry_parm));
3750 push_to_sequence (conversion_insns);
3751 entry_parm = convert_to_mode (nominal_mode, tempreg,
3752 TREE_UNSIGNED (TREE_TYPE (parm)));
3753 conversion_insns = get_insns ();
3757 if (entry_parm != stack_parm)
3759 if (stack_parm == 0)
3762 = assign_stack_local (GET_MODE (entry_parm),
3763 GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
3764 /* If this is a memory ref that contains aggregate components,
3765 mark it as such for cse and loop optimize. */
3766 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3769 if (passed_mode != nominal_mode)
3771 push_to_sequence (conversion_insns);
3772 emit_move_insn (validize_mem (stack_parm),
3773 validize_mem (entry_parm));
3774 conversion_insns = get_insns ();
3778 emit_move_insn (validize_mem (stack_parm),
3779 validize_mem (entry_parm));
3782 DECL_RTL (parm) = stack_parm;
3785 /* If this "parameter" was the place where we are receiving the
3786 function's incoming structure pointer, set up the result. */
3787 if (parm == function_result_decl)
3789 tree result = DECL_RESULT (fndecl);
3790 tree restype = TREE_TYPE (result);
3793 = gen_rtx (MEM, DECL_MODE (result), DECL_RTL (parm));
3795 MEM_IN_STRUCT_P (DECL_RTL (result)) = AGGREGATE_TYPE_P (restype);
3798 if (TREE_THIS_VOLATILE (parm))
3799 MEM_VOLATILE_P (DECL_RTL (parm)) = 1;
3800 if (TREE_READONLY (parm))
3801 RTX_UNCHANGING_P (DECL_RTL (parm)) = 1;
3804 /* Output all parameter conversion instructions (possibly including calls)
3805 now that all parameters have been copied out of hard registers. */
3806 emit_insns (conversion_insns);
3808 max_parm_reg = max_reg_num ();
3809 last_parm_insn = get_last_insn ();
3811 current_function_args_size = stack_args_size.constant;
3813 /* Adjust function incoming argument size for alignment and
3816 #ifdef REG_PARM_STACK_SPACE
3817 #ifndef MAYBE_REG_PARM_STACK_SPACE
3818 current_function_args_size = MAX (current_function_args_size,
3819 REG_PARM_STACK_SPACE (fndecl));
3823 #ifdef STACK_BOUNDARY
3824 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
3826 current_function_args_size
3827 = ((current_function_args_size + STACK_BYTES - 1)
3828 / STACK_BYTES) * STACK_BYTES;
3831 #ifdef ARGS_GROW_DOWNWARD
3832 current_function_arg_offset_rtx
3833 = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
3834 : expand_expr (size_binop (MINUS_EXPR, stack_args_size.var,
3835 size_int (-stack_args_size.constant)),
3836 NULL_RTX, VOIDmode, 0));
3838 current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
3841 /* See how many bytes, if any, of its args a function should try to pop
3844 current_function_pops_args = RETURN_POPS_ARGS (TREE_TYPE (fndecl),
3845 current_function_args_size);
3847 /* For stdarg.h function, save info about
3848 regs and stack space used by the named args. */
3851 current_function_args_info = args_so_far;
3853 /* Set the rtx used for the function return value. Put this in its
3854 own variable so any optimizers that need this information don't have
3855 to include tree.h. Do this here so it gets done when an inlined
3856 function gets output. */
3858 current_function_return_rtx = DECL_RTL (DECL_RESULT (fndecl));
3861 /* Indicate whether REGNO is an incoming argument to the current function
3862 that was promoted to a wider mode. If so, return the RTX for the
3863 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
3864 that REGNO is promoted from and whether the promotion was signed or
3867 #ifdef PROMOTE_FUNCTION_ARGS
3870 promoted_input_arg (regno, pmode, punsignedp)
3872 enum machine_mode *pmode;
3877 for (arg = DECL_ARGUMENTS (current_function_decl); arg;
3878 arg = TREE_CHAIN (arg))
3879 if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
3880 && REGNO (DECL_INCOMING_RTL (arg)) == regno)
3882 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
3883 int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
3885 mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1);
3886 if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
3887 && mode != DECL_MODE (arg))
3889 *pmode = DECL_MODE (arg);
3890 *punsignedp = unsignedp;
3891 return DECL_INCOMING_RTL (arg);
3900 /* Compute the size and offset from the start of the stacked arguments for a
3901 parm passed in mode PASSED_MODE and with type TYPE.
3903 INITIAL_OFFSET_PTR points to the current offset into the stacked
3906 The starting offset and size for this parm are returned in *OFFSET_PTR
3907 and *ARG_SIZE_PTR, respectively.
3909 IN_REGS is non-zero if the argument will be passed in registers. It will
3910 never be set if REG_PARM_STACK_SPACE is not defined.
3912 FNDECL is the function in which the argument was defined.
3914 There are two types of rounding that are done. The first, controlled by
3915 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
3916 list to be aligned to the specific boundary (in bits). This rounding
3917 affects the initial and starting offsets, but not the argument size.
3919 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
3920 optionally rounds the size of the parm to PARM_BOUNDARY. The
3921 initial offset is not affected by this rounding, while the size always
3922 is and the starting offset may be. */
3924 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
3925 initial_offset_ptr is positive because locate_and_pad_parm's
3926 callers pass in the total size of args so far as
3927 initial_offset_ptr. arg_size_ptr is always positive.*/
3930 locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
3931 initial_offset_ptr, offset_ptr, arg_size_ptr)
3932 enum machine_mode passed_mode;
3936 struct args_size *initial_offset_ptr;
3937 struct args_size *offset_ptr;
3938 struct args_size *arg_size_ptr;
3941 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
3942 enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
3943 int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
3944 int boundary_in_bytes = boundary / BITS_PER_UNIT;
3945 int reg_parm_stack_space = 0;
3947 #ifdef REG_PARM_STACK_SPACE
3948 /* If we have found a stack parm before we reach the end of the
3949 area reserved for registers, skip that area. */
3952 #ifdef MAYBE_REG_PARM_STACK_SPACE
3953 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
3955 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
3957 if (reg_parm_stack_space > 0)
3959 if (initial_offset_ptr->var)
3961 initial_offset_ptr->var
3962 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
3963 size_int (reg_parm_stack_space));
3964 initial_offset_ptr->constant = 0;
3966 else if (initial_offset_ptr->constant < reg_parm_stack_space)
3967 initial_offset_ptr->constant = reg_parm_stack_space;
3970 #endif /* REG_PARM_STACK_SPACE */
3972 arg_size_ptr->var = 0;
3973 arg_size_ptr->constant = 0;
3975 #ifdef ARGS_GROW_DOWNWARD
3976 if (initial_offset_ptr->var)
3978 offset_ptr->constant = 0;
3979 offset_ptr->var = size_binop (MINUS_EXPR, integer_zero_node,
3980 initial_offset_ptr->var);
3984 offset_ptr->constant = - initial_offset_ptr->constant;
3985 offset_ptr->var = 0;
3987 if (where_pad != none
3988 && (TREE_CODE (sizetree) != INTEGER_CST
3989 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
3990 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
3991 SUB_PARM_SIZE (*offset_ptr, sizetree);
3992 if (where_pad != downward)
3993 pad_to_arg_alignment (offset_ptr, boundary);
3994 if (initial_offset_ptr->var)
3996 arg_size_ptr->var = size_binop (MINUS_EXPR,
3997 size_binop (MINUS_EXPR,
3999 initial_offset_ptr->var),
4004 arg_size_ptr->constant = (- initial_offset_ptr->constant -
4005 offset_ptr->constant);
4007 #else /* !ARGS_GROW_DOWNWARD */
4008 pad_to_arg_alignment (initial_offset_ptr, boundary);
4009 *offset_ptr = *initial_offset_ptr;
4011 #ifdef PUSH_ROUNDING
4012 if (passed_mode != BLKmode)
4013 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
4016 if (where_pad != none
4017 && (TREE_CODE (sizetree) != INTEGER_CST
4018 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
4019 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4021 /* This must be done after rounding sizetree, so that it will subtract
4022 the same value that we explicitly add below. */
4023 if (where_pad == downward)
4024 pad_below (offset_ptr, passed_mode, sizetree);
4025 ADD_PARM_SIZE (*arg_size_ptr, sizetree);
4026 #endif /* ARGS_GROW_DOWNWARD */
4029 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
4030 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
4033 pad_to_arg_alignment (offset_ptr, boundary)
4034 struct args_size *offset_ptr;
4037 int boundary_in_bytes = boundary / BITS_PER_UNIT;
4039 if (boundary > BITS_PER_UNIT)
4041 if (offset_ptr->var)
4044 #ifdef ARGS_GROW_DOWNWARD
4049 (ARGS_SIZE_TREE (*offset_ptr),
4050 boundary / BITS_PER_UNIT);
4051 offset_ptr->constant = 0; /*?*/
4054 offset_ptr->constant =
4055 #ifdef ARGS_GROW_DOWNWARD
4056 FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes);
4058 CEIL_ROUND (offset_ptr->constant, boundary_in_bytes);
4064 pad_below (offset_ptr, passed_mode, sizetree)
4065 struct args_size *offset_ptr;
4066 enum machine_mode passed_mode;
4069 if (passed_mode != BLKmode)
4071 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
4072 offset_ptr->constant
4073 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
4074 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
4075 - GET_MODE_SIZE (passed_mode));
4079 if (TREE_CODE (sizetree) != INTEGER_CST
4080 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
4082 /* Round the size up to multiple of PARM_BOUNDARY bits. */
4083 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4085 ADD_PARM_SIZE (*offset_ptr, s2);
4086 SUB_PARM_SIZE (*offset_ptr, sizetree);
4092 round_down (value, divisor)
4096 return size_binop (MULT_EXPR,
4097 size_binop (FLOOR_DIV_EXPR, value, size_int (divisor)),
4098 size_int (divisor));
4101 /* Walk the tree of blocks describing the binding levels within a function
4102 and warn about uninitialized variables.
4103 This is done after calling flow_analysis and before global_alloc
4104 clobbers the pseudo-regs to hard regs. */
4107 uninitialized_vars_warning (block)
4110 register tree decl, sub;
4111 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
4113 if (TREE_CODE (decl) == VAR_DECL
4114 /* These warnings are unreliable for and aggregates
4115 because assigning the fields one by one can fail to convince
4116 flow.c that the entire aggregate was initialized.
4117 Unions are troublesome because members may be shorter. */
4118 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl))
4119 && DECL_RTL (decl) != 0
4120 && GET_CODE (DECL_RTL (decl)) == REG
4121 && regno_uninitialized (REGNO (DECL_RTL (decl))))
4122 warning_with_decl (decl,
4123 "`%s' might be used uninitialized in this function");
4124 if (TREE_CODE (decl) == VAR_DECL
4125 && DECL_RTL (decl) != 0
4126 && GET_CODE (DECL_RTL (decl)) == REG
4127 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
4128 warning_with_decl (decl,
4129 "variable `%s' might be clobbered by `longjmp' or `vfork'");
4131 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
4132 uninitialized_vars_warning (sub);
4135 /* Do the appropriate part of uninitialized_vars_warning
4136 but for arguments instead of local variables. */
4139 setjmp_args_warning (block)
4143 for (decl = DECL_ARGUMENTS (current_function_decl);
4144 decl; decl = TREE_CHAIN (decl))
4145 if (DECL_RTL (decl) != 0
4146 && GET_CODE (DECL_RTL (decl)) == REG
4147 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
4148 warning_with_decl (decl, "argument `%s' might be clobbered by `longjmp' or `vfork'");
4151 /* If this function call setjmp, put all vars into the stack
4152 unless they were declared `register'. */
4155 setjmp_protect (block)
4158 register tree decl, sub;
4159 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
4160 if ((TREE_CODE (decl) == VAR_DECL
4161 || TREE_CODE (decl) == PARM_DECL)
4162 && DECL_RTL (decl) != 0
4163 && GET_CODE (DECL_RTL (decl)) == REG
4164 /* If this variable came from an inline function, it must be
4165 that it's life doesn't overlap the setjmp. If there was a
4166 setjmp in the function, it would already be in memory. We
4167 must exclude such variable because their DECL_RTL might be
4168 set to strange things such as virtual_stack_vars_rtx. */
4169 && ! DECL_FROM_INLINE (decl)
4171 #ifdef NON_SAVING_SETJMP
4172 /* If longjmp doesn't restore the registers,
4173 don't put anything in them. */
4177 ! DECL_REGISTER (decl)))
4178 put_var_into_stack (decl);
4179 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
4180 setjmp_protect (sub);
4183 /* Like the previous function, but for args instead of local variables. */
4186 setjmp_protect_args ()
4188 register tree decl, sub;
4189 for (decl = DECL_ARGUMENTS (current_function_decl);
4190 decl; decl = TREE_CHAIN (decl))
4191 if ((TREE_CODE (decl) == VAR_DECL
4192 || TREE_CODE (decl) == PARM_DECL)
4193 && DECL_RTL (decl) != 0
4194 && GET_CODE (DECL_RTL (decl)) == REG
4196 /* If longjmp doesn't restore the registers,
4197 don't put anything in them. */
4198 #ifdef NON_SAVING_SETJMP
4202 ! DECL_REGISTER (decl)))
4203 put_var_into_stack (decl);
4206 /* Return the context-pointer register corresponding to DECL,
4207 or 0 if it does not need one. */
4210 lookup_static_chain (decl)
4213 tree context = decl_function_context (decl);
4219 /* We treat inline_function_decl as an alias for the current function
4220 because that is the inline function whose vars, types, etc.
4221 are being merged into the current function.
4222 See expand_inline_function. */
4223 if (context == current_function_decl || context == inline_function_decl)
4224 return virtual_stack_vars_rtx;
4226 for (link = context_display; link; link = TREE_CHAIN (link))
4227 if (TREE_PURPOSE (link) == context)
4228 return RTL_EXPR_RTL (TREE_VALUE (link));
4233 /* Convert a stack slot address ADDR for variable VAR
4234 (from a containing function)
4235 into an address valid in this function (using a static chain). */
4238 fix_lexical_addr (addr, var)
4244 tree context = decl_function_context (var);
4245 struct function *fp;
4248 /* If this is the present function, we need not do anything. */
4249 if (context == current_function_decl || context == inline_function_decl)
4252 for (fp = outer_function_chain; fp; fp = fp->next)
4253 if (fp->decl == context)
4259 /* Decode given address as base reg plus displacement. */
4260 if (GET_CODE (addr) == REG)
4261 basereg = addr, displacement = 0;
4262 else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
4263 basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
4267 /* We accept vars reached via the containing function's
4268 incoming arg pointer and via its stack variables pointer. */
4269 if (basereg == fp->internal_arg_pointer)
4271 /* If reached via arg pointer, get the arg pointer value
4272 out of that function's stack frame.
4274 There are two cases: If a separate ap is needed, allocate a
4275 slot in the outer function for it and dereference it that way.
4276 This is correct even if the real ap is actually a pseudo.
4277 Otherwise, just adjust the offset from the frame pointer to
4280 #ifdef NEED_SEPARATE_AP
4283 if (fp->arg_pointer_save_area == 0)
4284 fp->arg_pointer_save_area
4285 = assign_outer_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0, fp);
4287 addr = fix_lexical_addr (XEXP (fp->arg_pointer_save_area, 0), var);
4288 addr = memory_address (Pmode, addr);
4290 base = copy_to_reg (gen_rtx (MEM, Pmode, addr));
4292 displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
4293 base = lookup_static_chain (var);
4297 else if (basereg == virtual_stack_vars_rtx)
4299 /* This is the same code as lookup_static_chain, duplicated here to
4300 avoid an extra call to decl_function_context. */
4303 for (link = context_display; link; link = TREE_CHAIN (link))
4304 if (TREE_PURPOSE (link) == context)
4306 base = RTL_EXPR_RTL (TREE_VALUE (link));
4314 /* Use same offset, relative to appropriate static chain or argument
4316 return plus_constant (base, displacement);
4319 /* Return the address of the trampoline for entering nested fn FUNCTION.
4320 If necessary, allocate a trampoline (in the stack frame)
4321 and emit rtl to initialize its contents (at entry to this function). */
4324 trampoline_address (function)
4330 struct function *fp;
4333 /* Find an existing trampoline and return it. */
4334 for (link = trampoline_list; link; link = TREE_CHAIN (link))
4335 if (TREE_PURPOSE (link) == function)
4337 round_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0));
4339 for (fp = outer_function_chain; fp; fp = fp->next)
4340 for (link = fp->trampoline_list; link; link = TREE_CHAIN (link))
4341 if (TREE_PURPOSE (link) == function)
4343 tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
4345 return round_trampoline_addr (tramp);
4348 /* None exists; we must make one. */
4350 /* Find the `struct function' for the function containing FUNCTION. */
4352 fn_context = decl_function_context (function);
4353 if (fn_context != current_function_decl)
4354 for (fp = outer_function_chain; fp; fp = fp->next)
4355 if (fp->decl == fn_context)
4358 /* Allocate run-time space for this trampoline
4359 (usually in the defining function's stack frame). */
4360 #ifdef ALLOCATE_TRAMPOLINE
4361 tramp = ALLOCATE_TRAMPOLINE (fp);
4363 /* If rounding needed, allocate extra space
4364 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
4365 #ifdef TRAMPOLINE_ALIGNMENT
4366 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE + TRAMPOLINE_ALIGNMENT - 1)
4368 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
4371 tramp = assign_outer_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0, fp);
4373 tramp = assign_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0);
4376 /* Record the trampoline for reuse and note it for later initialization
4377 by expand_function_end. */
4380 push_obstacks (fp->function_maybepermanent_obstack,
4381 fp->function_maybepermanent_obstack);
4382 rtlexp = make_node (RTL_EXPR);
4383 RTL_EXPR_RTL (rtlexp) = tramp;
4384 fp->trampoline_list = tree_cons (function, rtlexp, fp->trampoline_list);
4389 /* Make the RTL_EXPR node temporary, not momentary, so that the
4390 trampoline_list doesn't become garbage. */
4391 int momentary = suspend_momentary ();
4392 rtlexp = make_node (RTL_EXPR);
4393 resume_momentary (momentary);
4395 RTL_EXPR_RTL (rtlexp) = tramp;
4396 trampoline_list = tree_cons (function, rtlexp, trampoline_list);
4399 tramp = fix_lexical_addr (XEXP (tramp, 0), function);
4400 return round_trampoline_addr (tramp);
4403 /* Given a trampoline address,
4404 round it to multiple of TRAMPOLINE_ALIGNMENT. */
4407 round_trampoline_addr (tramp)
4410 #ifdef TRAMPOLINE_ALIGNMENT
4411 /* Round address up to desired boundary. */
4412 rtx temp = gen_reg_rtx (Pmode);
4413 temp = expand_binop (Pmode, add_optab, tramp,
4414 GEN_INT (TRAMPOLINE_ALIGNMENT - 1),
4415 temp, 0, OPTAB_LIB_WIDEN);
4416 tramp = expand_binop (Pmode, and_optab, temp,
4417 GEN_INT (- TRAMPOLINE_ALIGNMENT),
4418 temp, 0, OPTAB_LIB_WIDEN);
4423 /* The functions identify_blocks and reorder_blocks provide a way to
4424 reorder the tree of BLOCK nodes, for optimizers that reshuffle or
4425 duplicate portions of the RTL code. Call identify_blocks before
4426 changing the RTL, and call reorder_blocks after. */
4428 /* Put all this function's BLOCK nodes into a vector, and return it.
4429 Also store in each NOTE for the beginning or end of a block
4430 the index of that block in the vector.
4431 The arguments are TOP_BLOCK, the top-level block of the function,
4432 and INSNS, the insn chain of the function. */
4435 identify_blocks (top_block, insns)
4443 int next_block_number = 0;
4444 int current_block_number = 0;
4450 n_blocks = all_blocks (top_block, 0);
4451 block_vector = (tree *) xmalloc (n_blocks * sizeof (tree));
4452 block_stack = (int *) alloca (n_blocks * sizeof (int));
4454 all_blocks (top_block, block_vector);
4456 for (insn = insns; insn; insn = NEXT_INSN (insn))
4457 if (GET_CODE (insn) == NOTE)
4459 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
4461 block_stack[depth++] = current_block_number;
4462 current_block_number = next_block_number;
4463 NOTE_BLOCK_NUMBER (insn) = next_block_number++;
4465 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
4467 current_block_number = block_stack[--depth];
4468 NOTE_BLOCK_NUMBER (insn) = current_block_number;
4472 return block_vector;
4475 /* Given BLOCK_VECTOR which was returned by identify_blocks,
4476 and a revised instruction chain, rebuild the tree structure
4477 of BLOCK nodes to correspond to the new order of RTL.
4478 The new block tree is inserted below TOP_BLOCK.
4479 Returns the current top-level block. */
4482 reorder_blocks (block_vector, top_block, insns)
4487 tree current_block = top_block;
4490 if (block_vector == 0)
4493 /* Prune the old tree away, so that it doesn't get in the way. */
4494 BLOCK_SUBBLOCKS (current_block) = 0;
4496 for (insn = insns; insn; insn = NEXT_INSN (insn))
4497 if (GET_CODE (insn) == NOTE)
4499 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
4501 tree block = block_vector[NOTE_BLOCK_NUMBER (insn)];
4502 /* If we have seen this block before, copy it. */
4503 if (TREE_ASM_WRITTEN (block))
4504 block = copy_node (block);
4505 BLOCK_SUBBLOCKS (block) = 0;
4506 TREE_ASM_WRITTEN (block) = 1;
4507 BLOCK_SUPERCONTEXT (block) = current_block;
4508 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
4509 BLOCK_SUBBLOCKS (current_block) = block;
4510 current_block = block;
4511 NOTE_SOURCE_FILE (insn) = 0;
4513 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
4515 BLOCK_SUBBLOCKS (current_block)
4516 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
4517 current_block = BLOCK_SUPERCONTEXT (current_block);
4518 NOTE_SOURCE_FILE (insn) = 0;
4522 return current_block;
4525 /* Reverse the order of elements in the chain T of blocks,
4526 and return the new head of the chain (old last element). */
4532 register tree prev = 0, decl, next;
4533 for (decl = t; decl; decl = next)
4535 next = BLOCK_CHAIN (decl);
4536 BLOCK_CHAIN (decl) = prev;
4542 /* Count the subblocks of BLOCK, and list them all into the vector VECTOR.
4543 Also clear TREE_ASM_WRITTEN in all blocks. */
4546 all_blocks (block, vector)
4553 TREE_ASM_WRITTEN (block) = 0;
4554 /* Record this block. */
4558 /* Record the subblocks, and their subblocks. */
4559 for (subblocks = BLOCK_SUBBLOCKS (block);
4560 subblocks; subblocks = BLOCK_CHAIN (subblocks))
4561 n_blocks += all_blocks (subblocks, vector ? vector + n_blocks : 0);
4566 /* Build bytecode call descriptor for function SUBR. */
4569 bc_build_calldesc (subr)
4572 tree calldesc = 0, arg;
4575 /* Build the argument description vector in reverse order. */
4576 DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
4579 for (arg = DECL_ARGUMENTS (subr); arg; arg = TREE_CHAIN (arg))
4583 calldesc = tree_cons ((tree) 0, size_in_bytes (TREE_TYPE (arg)), calldesc);
4584 calldesc = tree_cons ((tree) 0, bc_runtime_type_code (TREE_TYPE (arg)), calldesc);
4587 DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
4589 /* Prepend the function's return type. */
4590 calldesc = tree_cons ((tree) 0,
4591 size_in_bytes (TREE_TYPE (TREE_TYPE (subr))),
4594 calldesc = tree_cons ((tree) 0,
4595 bc_runtime_type_code (TREE_TYPE (TREE_TYPE (subr))),
4598 /* Prepend the arg count. */
4599 calldesc = tree_cons ((tree) 0, build_int_2 (nargs, 0), calldesc);
4601 /* Output the call description vector and get its address. */
4602 calldesc = build_nt (CONSTRUCTOR, (tree) 0, calldesc);
4603 TREE_TYPE (calldesc) = build_array_type (integer_type_node,
4604 build_index_type (build_int_2 (nargs * 2, 0)));
4606 return output_constant_def (calldesc);
4610 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
4611 and initialize static variables for generating RTL for the statements
4615 init_function_start (subr, filename, line)
4622 if (output_bytecode)
4624 this_function_decl = subr;
4625 this_function_calldesc = bc_build_calldesc (subr);
4626 local_vars_size = 0;
4628 max_stack_depth = 0;
4629 stmt_expr_depth = 0;
4633 init_stmt_for_function ();
4635 cse_not_expected = ! optimize;
4637 /* Caller save not needed yet. */
4638 caller_save_needed = 0;
4640 /* No stack slots have been made yet. */
4641 stack_slot_list = 0;
4643 /* There is no stack slot for handling nonlocal gotos. */
4644 nonlocal_goto_handler_slot = 0;
4645 nonlocal_goto_stack_level = 0;
4647 /* No labels have been declared for nonlocal use. */
4648 nonlocal_labels = 0;
4650 /* No function calls so far in this function. */
4651 function_call_count = 0;
4653 /* No parm regs have been allocated.
4654 (This is important for output_inline_function.) */
4655 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
4657 /* Initialize the RTL mechanism. */
4660 /* Initialize the queue of pending postincrement and postdecrements,
4661 and some other info in expr.c. */
4664 /* We haven't done register allocation yet. */
4667 init_const_rtx_hash_table ();
4669 current_function_name = (*decl_printable_name) (subr, &junk);
4671 /* Nonzero if this is a nested function that uses a static chain. */
4673 current_function_needs_context
4674 = (decl_function_context (current_function_decl) != 0);
4676 /* Set if a call to setjmp is seen. */
4677 current_function_calls_setjmp = 0;
4679 /* Set if a call to longjmp is seen. */
4680 current_function_calls_longjmp = 0;
4682 current_function_calls_alloca = 0;
4683 current_function_has_nonlocal_label = 0;
4684 current_function_has_nonlocal_goto = 0;
4685 current_function_contains_functions = 0;
4687 current_function_returns_pcc_struct = 0;
4688 current_function_returns_struct = 0;
4689 current_function_epilogue_delay_list = 0;
4690 current_function_uses_const_pool = 0;
4691 current_function_uses_pic_offset_table = 0;
4693 /* We have not yet needed to make a label to jump to for tail-recursion. */
4694 tail_recursion_label = 0;
4696 /* We haven't had a need to make a save area for ap yet. */
4698 arg_pointer_save_area = 0;
4700 /* No stack slots allocated yet. */
4703 /* No SAVE_EXPRs in this function yet. */
4706 /* No RTL_EXPRs in this function yet. */
4709 /* We have not allocated any temporaries yet. */
4711 temp_slot_level = 0;
4712 target_temp_slot_level = 0;
4714 /* Within function body, compute a type's size as soon it is laid out. */
4715 immediate_size_expand++;
4717 /* We haven't made any trampolines for this function yet. */
4718 trampoline_list = 0;
4720 init_pending_stack_adjust ();
4721 inhibit_defer_pop = 0;
4723 current_function_outgoing_args_size = 0;
4725 /* Initialize the insn lengths. */
4726 init_insn_lengths ();
4728 /* Prevent ever trying to delete the first instruction of a function.
4729 Also tell final how to output a linenum before the function prologue. */
4730 emit_line_note (filename, line);
4732 /* Make sure first insn is a note even if we don't want linenums.
4733 This makes sure the first insn will never be deleted.
4734 Also, final expects a note to appear there. */
4735 emit_note (NULL_PTR, NOTE_INSN_DELETED);
4737 /* Set flags used by final.c. */
4738 if (aggregate_value_p (DECL_RESULT (subr)))
4740 #ifdef PCC_STATIC_STRUCT_RETURN
4741 current_function_returns_pcc_struct = 1;
4743 current_function_returns_struct = 1;
4746 /* Warn if this value is an aggregate type,
4747 regardless of which calling convention we are using for it. */
4748 if (warn_aggregate_return
4749 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
4750 warning ("function returns an aggregate");
4752 current_function_returns_pointer
4753 = (TREE_CODE (TREE_TYPE (DECL_RESULT (subr))) == POINTER_TYPE);
4755 /* Indicate that we need to distinguish between the return value of the
4756 present function and the return value of a function being called. */
4757 rtx_equal_function_value_matters = 1;
4759 /* Indicate that we have not instantiated virtual registers yet. */
4760 virtuals_instantiated = 0;
4762 /* Indicate we have no need of a frame pointer yet. */
4763 frame_pointer_needed = 0;
4765 /* By default assume not varargs. */
4766 current_function_varargs = 0;
4769 /* Indicate that the current function uses extra args
4770 not explicitly mentioned in the argument list in any fashion. */
4775 current_function_varargs = 1;
4778 /* Expand a call to __main at the beginning of a possible main function. */
4780 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
4781 #undef HAS_INIT_SECTION
4782 #define HAS_INIT_SECTION
4786 expand_main_function ()
4788 if (!output_bytecode)
4790 /* The zero below avoids a possible parse error */
4792 #if !defined (HAS_INIT_SECTION)
4793 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, NAME__MAIN), 0,
4795 #endif /* not HAS_INIT_SECTION */
4799 extern struct obstack permanent_obstack;
4801 /* Expand start of bytecode function. See comment at
4802 expand_function_start below for details. */
4805 bc_expand_function_start (subr, parms_have_cleanups)
4807 int parms_have_cleanups;
4809 char label[20], *name;
4814 if (TREE_PUBLIC (subr))
4815 bc_globalize_label (IDENTIFIER_POINTER (DECL_NAME (subr)));
4817 #ifdef DEBUG_PRINT_CODE
4818 fprintf (stderr, "\n<func %s>\n", IDENTIFIER_POINTER (DECL_NAME (subr)));
4821 for (argsz = 0, thisarg = DECL_ARGUMENTS (subr); thisarg; thisarg = TREE_CHAIN (thisarg))
4823 if (DECL_RTL (thisarg))
4824 abort (); /* Should be NULL here I think. */
4825 else if (TREE_CONSTANT (DECL_SIZE (thisarg)))
4827 DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
4828 argsz += TREE_INT_CST_LOW (DECL_SIZE (thisarg));
4832 /* Variable-sized objects are pointers to their storage. */
4833 DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
4834 argsz += POINTER_SIZE;
4838 bc_begin_function (bc_xstrdup (IDENTIFIER_POINTER (DECL_NAME (subr))));
4840 ASM_GENERATE_INTERNAL_LABEL (label, "LX", nlab);
4843 name = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
4844 this_function_callinfo = bc_gen_rtx (name, 0, (struct bc_label *) 0);
4845 this_function_bytecode =
4846 bc_emit_trampoline (BYTECODE_LABEL (this_function_callinfo));
4850 /* Expand end of bytecode function. See details the comment of
4851 expand_function_end(), below. */
4854 bc_expand_function_end ()
4858 expand_null_return ();
4860 /* Emit any fixup code. This must be done before the call to
4861 to BC_END_FUNCTION (), since that will cause the bytecode
4862 segment to be finished off and closed. */
4864 expand_fixups (NULL_RTX);
4866 ptrconsts = bc_end_function ();
4868 bc_align_const (2 /* INT_ALIGN */);
4870 /* If this changes also make sure to change bc-interp.h! */
4872 bc_emit_const_labeldef (BYTECODE_LABEL (this_function_callinfo));
4873 bc_emit_const ((char *) &max_stack_depth, sizeof max_stack_depth);
4874 bc_emit_const ((char *) &local_vars_size, sizeof local_vars_size);
4875 bc_emit_const_labelref (this_function_bytecode, 0);
4876 bc_emit_const_labelref (ptrconsts, 0);
4877 bc_emit_const_labelref (BYTECODE_LABEL (this_function_calldesc), 0);
4881 /* Start the RTL for a new function, and set variables used for
4883 SUBR is the FUNCTION_DECL node.
4884 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
4885 the function's parameters, which must be run at any return statement. */
4888 expand_function_start (subr, parms_have_cleanups)
4890 int parms_have_cleanups;
4896 if (output_bytecode)
4898 bc_expand_function_start (subr, parms_have_cleanups);
4902 /* Make sure volatile mem refs aren't considered
4903 valid operands of arithmetic insns. */
4904 init_recog_no_volatile ();
4906 /* If function gets a static chain arg, store it in the stack frame.
4907 Do this first, so it gets the first stack slot offset. */
4908 if (current_function_needs_context)
4910 last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
4912 #ifdef SMALL_REGISTER_CLASSES
4913 /* Delay copying static chain if it is not a register to avoid
4914 conflicts with regs used for parameters. */
4915 if (GET_CODE (static_chain_incoming_rtx) == REG)
4917 emit_move_insn (last_ptr, static_chain_incoming_rtx);
4920 /* If the parameters of this function need cleaning up, get a label
4921 for the beginning of the code which executes those cleanups. This must
4922 be done before doing anything with return_label. */
4923 if (parms_have_cleanups)
4924 cleanup_label = gen_label_rtx ();
4928 /* Make the label for return statements to jump to, if this machine
4929 does not have a one-instruction return and uses an epilogue,
4930 or if it returns a structure, or if it has parm cleanups. */
4932 if (cleanup_label == 0 && HAVE_return
4933 && ! current_function_returns_pcc_struct
4934 && ! (current_function_returns_struct && ! optimize))
4937 return_label = gen_label_rtx ();
4939 return_label = gen_label_rtx ();
4942 /* Initialize rtx used to return the value. */
4943 /* Do this before assign_parms so that we copy the struct value address
4944 before any library calls that assign parms might generate. */
4946 /* Decide whether to return the value in memory or in a register. */
4947 if (aggregate_value_p (DECL_RESULT (subr)))
4949 /* Returning something that won't go in a register. */
4950 register rtx value_address = 0;
4952 #ifdef PCC_STATIC_STRUCT_RETURN
4953 if (current_function_returns_pcc_struct)
4955 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
4956 value_address = assemble_static_space (size);
4961 /* Expect to be passed the address of a place to store the value.
4962 If it is passed as an argument, assign_parms will take care of
4964 if (struct_value_incoming_rtx)
4966 value_address = gen_reg_rtx (Pmode);
4967 emit_move_insn (value_address, struct_value_incoming_rtx);
4972 DECL_RTL (DECL_RESULT (subr))
4973 = gen_rtx (MEM, DECL_MODE (DECL_RESULT (subr)), value_address);
4974 MEM_IN_STRUCT_P (DECL_RTL (DECL_RESULT (subr)))
4975 = AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
4978 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
4979 /* If return mode is void, this decl rtl should not be used. */
4980 DECL_RTL (DECL_RESULT (subr)) = 0;
4981 else if (parms_have_cleanups)
4983 /* If function will end with cleanup code for parms,
4984 compute the return values into a pseudo reg,
4985 which we will copy into the true return register
4986 after the cleanups are done. */
4988 enum machine_mode mode = DECL_MODE (DECL_RESULT (subr));
4990 #ifdef PROMOTE_FUNCTION_RETURN
4991 tree type = TREE_TYPE (DECL_RESULT (subr));
4992 int unsignedp = TREE_UNSIGNED (type);
4994 mode = promote_mode (type, mode, &unsignedp, 1);
4997 DECL_RTL (DECL_RESULT (subr)) = gen_reg_rtx (mode);
5000 /* Scalar, returned in a register. */
5002 #ifdef FUNCTION_OUTGOING_VALUE
5003 DECL_RTL (DECL_RESULT (subr))
5004 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
5006 DECL_RTL (DECL_RESULT (subr))
5007 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
5010 /* Mark this reg as the function's return value. */
5011 if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG)
5013 REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1;
5014 /* Needed because we may need to move this to memory
5015 in case it's a named return value whose address is taken. */
5016 DECL_REGISTER (DECL_RESULT (subr)) = 1;
5020 /* Initialize rtx for parameters and local variables.
5021 In some cases this requires emitting insns. */
5023 assign_parms (subr, 0);
5025 #ifdef SMALL_REGISTER_CLASSES
5026 /* Copy the static chain now if it wasn't a register. The delay is to
5027 avoid conflicts with the parameter passing registers. */
5029 if (current_function_needs_context)
5030 if (GET_CODE (static_chain_incoming_rtx) != REG)
5031 emit_move_insn (last_ptr, static_chain_incoming_rtx);
5034 /* The following was moved from init_function_start.
5035 The move is supposed to make sdb output more accurate. */
5036 /* Indicate the beginning of the function body,
5037 as opposed to parm setup. */
5038 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_BEG);
5040 /* If doing stupid allocation, mark parms as born here. */
5042 if (GET_CODE (get_last_insn ()) != NOTE)
5043 emit_note (NULL_PTR, NOTE_INSN_DELETED);
5044 parm_birth_insn = get_last_insn ();
5048 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
5049 use_variable (regno_reg_rtx[i]);
5051 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
5052 use_variable (current_function_internal_arg_pointer);
5055 /* Fetch static chain values for containing functions. */
5056 tem = decl_function_context (current_function_decl);
5057 /* If not doing stupid register allocation copy the static chain
5058 pointer into a psuedo. If we have small register classes, copy the
5059 value from memory if static_chain_incoming_rtx is a REG. If we do
5060 stupid register allocation, we use the stack address generated above. */
5061 if (tem && ! obey_regdecls)
5063 #ifdef SMALL_REGISTER_CLASSES
5064 /* If the static chain originally came in a register, put it back
5065 there, then move it out in the next insn. The reason for
5066 this peculiar code is to satisfy function integration. */
5067 if (GET_CODE (static_chain_incoming_rtx) == REG)
5068 emit_move_insn (static_chain_incoming_rtx, last_ptr);
5071 last_ptr = copy_to_reg (static_chain_incoming_rtx);
5074 context_display = 0;
5077 tree rtlexp = make_node (RTL_EXPR);
5079 RTL_EXPR_RTL (rtlexp) = last_ptr;
5080 context_display = tree_cons (tem, rtlexp, context_display);
5081 tem = decl_function_context (tem);
5084 /* Chain thru stack frames, assuming pointer to next lexical frame
5085 is found at the place we always store it. */
5086 #ifdef FRAME_GROWS_DOWNWARD
5087 last_ptr = plus_constant (last_ptr, - GET_MODE_SIZE (Pmode));
5089 last_ptr = copy_to_reg (gen_rtx (MEM, Pmode,
5090 memory_address (Pmode, last_ptr)));
5092 /* If we are not optimizing, ensure that we know that this
5093 piece of context is live over the entire function. */
5095 save_expr_regs = gen_rtx (EXPR_LIST, VOIDmode, last_ptr,
5099 /* After the display initializations is where the tail-recursion label
5100 should go, if we end up needing one. Ensure we have a NOTE here
5101 since some things (like trampolines) get placed before this. */
5102 tail_recursion_reentry = emit_note (NULL_PTR, NOTE_INSN_DELETED);
5104 /* Evaluate now the sizes of any types declared among the arguments. */
5105 for (tem = nreverse (get_pending_sizes ()); tem; tem = TREE_CHAIN (tem))
5106 expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode, 0);
5108 /* Make sure there is a line number after the function entry setup code. */
5109 force_next_line_note ();
5112 /* Generate RTL for the end of the current function.
5113 FILENAME and LINE are the current position in the source file.
5115 It is up to language-specific callers to do cleanups for parameters--
5116 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */
5119 expand_function_end (filename, line, end_bindings)
5127 static rtx initial_trampoline;
5129 if (output_bytecode)
5131 bc_expand_function_end ();
5135 #ifdef NON_SAVING_SETJMP
5136 /* Don't put any variables in registers if we call setjmp
5137 on a machine that fails to restore the registers. */
5138 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
5140 if (DECL_INITIAL (current_function_decl) != error_mark_node)
5141 setjmp_protect (DECL_INITIAL (current_function_decl));
5143 setjmp_protect_args ();
5147 /* Save the argument pointer if a save area was made for it. */
5148 if (arg_pointer_save_area)
5150 rtx x = gen_move_insn (arg_pointer_save_area, virtual_incoming_args_rtx);
5151 emit_insn_before (x, tail_recursion_reentry);
5154 /* Initialize any trampolines required by this function. */
5155 for (link = trampoline_list; link; link = TREE_CHAIN (link))
5157 tree function = TREE_PURPOSE (link);
5158 rtx context = lookup_static_chain (function);
5159 rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
5162 /* First make sure this compilation has a template for
5163 initializing trampolines. */
5164 if (initial_trampoline == 0)
5166 end_temporary_allocation ();
5168 = gen_rtx (MEM, BLKmode, assemble_trampoline_template ());
5169 resume_temporary_allocation ();
5172 /* Generate insns to initialize the trampoline. */
5174 tramp = change_address (initial_trampoline, BLKmode,
5175 round_trampoline_addr (XEXP (tramp, 0)));
5176 emit_block_move (tramp, initial_trampoline, GEN_INT (TRAMPOLINE_SIZE),
5177 FUNCTION_BOUNDARY / BITS_PER_UNIT);
5178 INITIALIZE_TRAMPOLINE (XEXP (tramp, 0),
5179 XEXP (DECL_RTL (function), 0), context);
5183 /* Put those insns at entry to the containing function (this one). */
5184 emit_insns_before (seq, tail_recursion_reentry);
5187 #if 0 /* I think unused parms are legitimate enough. */
5188 /* Warn about unused parms. */
5193 for (decl = DECL_ARGUMENTS (current_function_decl);
5194 decl; decl = TREE_CHAIN (decl))
5195 if (! TREE_USED (decl) && TREE_CODE (decl) == VAR_DECL)
5196 warning_with_decl (decl, "unused parameter `%s'");
5200 /* Delete handlers for nonlocal gotos if nothing uses them. */
5201 if (nonlocal_goto_handler_slot != 0 && !current_function_has_nonlocal_label)
5204 /* End any sequences that failed to be closed due to syntax errors. */
5205 while (in_sequence_p ())
5208 /* Outside function body, can't compute type's actual size
5209 until next function's body starts. */
5210 immediate_size_expand--;
5212 /* If doing stupid register allocation,
5213 mark register parms as dying here. */
5218 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
5219 use_variable (regno_reg_rtx[i]);
5221 /* Likewise for the regs of all the SAVE_EXPRs in the function. */
5223 for (tem = save_expr_regs; tem; tem = XEXP (tem, 1))
5225 use_variable (XEXP (tem, 0));
5226 use_variable_after (XEXP (tem, 0), parm_birth_insn);
5229 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
5230 use_variable (current_function_internal_arg_pointer);
5233 clear_pending_stack_adjust ();
5234 do_pending_stack_adjust ();
5236 /* Mark the end of the function body.
5237 If control reaches this insn, the function can drop through
5238 without returning a value. */
5239 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_END);
5241 /* Output a linenumber for the end of the function.
5242 SDB depends on this. */
5243 emit_line_note_force (filename, line);
5245 /* Output the label for the actual return from the function,
5246 if one is expected. This happens either because a function epilogue
5247 is used instead of a return instruction, or because a return was done
5248 with a goto in order to run local cleanups, or because of pcc-style
5249 structure returning. */
5252 emit_label (return_label);
5254 /* C++ uses this. */
5256 expand_end_bindings (0, 0, 0);
5258 /* If we had calls to alloca, and this machine needs
5259 an accurate stack pointer to exit the function,
5260 insert some code to save and restore the stack pointer. */
5261 #ifdef EXIT_IGNORE_STACK
5262 if (! EXIT_IGNORE_STACK)
5264 if (current_function_calls_alloca)
5268 emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
5269 emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
5272 /* If scalar return value was computed in a pseudo-reg,
5273 copy that to the hard return register. */
5274 if (DECL_RTL (DECL_RESULT (current_function_decl)) != 0
5275 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG
5276 && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl)))
5277 >= FIRST_PSEUDO_REGISTER))
5279 rtx real_decl_result;
5281 #ifdef FUNCTION_OUTGOING_VALUE
5283 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
5284 current_function_decl);
5287 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
5288 current_function_decl);
5290 REG_FUNCTION_VALUE_P (real_decl_result) = 1;
5291 emit_move_insn (real_decl_result,
5292 DECL_RTL (DECL_RESULT (current_function_decl)));
5293 emit_insn (gen_rtx (USE, VOIDmode, real_decl_result));
5296 /* If returning a structure, arrange to return the address of the value
5297 in a place where debuggers expect to find it.
5299 If returning a structure PCC style,
5300 the caller also depends on this value.
5301 And current_function_returns_pcc_struct is not necessarily set. */
5302 if (current_function_returns_struct
5303 || current_function_returns_pcc_struct)
5305 rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
5306 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
5307 #ifdef FUNCTION_OUTGOING_VALUE
5309 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
5310 current_function_decl);
5313 = FUNCTION_VALUE (build_pointer_type (type),
5314 current_function_decl);
5317 /* Mark this as a function return value so integrate will delete the
5318 assignment and USE below when inlining this function. */
5319 REG_FUNCTION_VALUE_P (outgoing) = 1;
5321 emit_move_insn (outgoing, value_address);
5322 use_variable (outgoing);
5325 /* Output a return insn if we are using one.
5326 Otherwise, let the rtl chain end here, to drop through
5327 into the epilogue. */
5332 emit_jump_insn (gen_return ());
5337 /* Fix up any gotos that jumped out to the outermost
5338 binding level of the function.
5339 Must follow emitting RETURN_LABEL. */
5341 /* If you have any cleanups to do at this point,
5342 and they need to create temporary variables,
5343 then you will lose. */
5344 expand_fixups (get_insns ());
5347 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
5349 static int *prologue;
5350 static int *epilogue;
5352 /* Create an array that records the INSN_UIDs of INSNS (either a sequence
5353 or a single insn). */
5356 record_insns (insns)
5361 if (GET_CODE (insns) == SEQUENCE)
5363 int len = XVECLEN (insns, 0);
5364 vec = (int *) oballoc ((len + 1) * sizeof (int));
5367 vec[len] = INSN_UID (XVECEXP (insns, 0, len));
5371 vec = (int *) oballoc (2 * sizeof (int));
5372 vec[0] = INSN_UID (insns);
5378 /* Determine how many INSN_UIDs in VEC are part of INSN. */
5381 contains (insn, vec)
5387 if (GET_CODE (insn) == INSN
5388 && GET_CODE (PATTERN (insn)) == SEQUENCE)
5391 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
5392 for (j = 0; vec[j]; j++)
5393 if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == vec[j])
5399 for (j = 0; vec[j]; j++)
5400 if (INSN_UID (insn) == vec[j])
5406 /* Generate the prologe and epilogue RTL if the machine supports it. Thread
5407 this into place with notes indicating where the prologue ends and where
5408 the epilogue begins. Update the basic block information when possible. */
5411 thread_prologue_and_epilogue_insns (f)
5414 #ifdef HAVE_prologue
5417 rtx head, seq, insn;
5419 /* The first insn (a NOTE_INSN_DELETED) is followed by zero or more
5420 prologue insns and a NOTE_INSN_PROLOGUE_END. */
5421 emit_note_after (NOTE_INSN_PROLOGUE_END, f);
5422 seq = gen_prologue ();
5423 head = emit_insn_after (seq, f);
5425 /* Include the new prologue insns in the first block. Ignore them
5426 if they form a basic block unto themselves. */
5427 if (basic_block_head && n_basic_blocks
5428 && GET_CODE (basic_block_head[0]) != CODE_LABEL)
5429 basic_block_head[0] = NEXT_INSN (f);
5431 /* Retain a map of the prologue insns. */
5432 prologue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : head);
5438 #ifdef HAVE_epilogue
5441 rtx insn = get_last_insn ();
5442 rtx prev = prev_nonnote_insn (insn);
5444 /* If we end with a BARRIER, we don't need an epilogue. */
5445 if (! (prev && GET_CODE (prev) == BARRIER))
5451 /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, the
5452 epilogue insns, the USE insns at the end of a function,
5453 the jump insn that returns, and then a BARRIER. */
5455 /* Move the USE insns at the end of a function onto a list. */
5457 && GET_CODE (prev) == INSN
5458 && GET_CODE (PATTERN (prev)) == USE)
5461 prev = prev_nonnote_insn (prev);
5463 NEXT_INSN (PREV_INSN (tem)) = NEXT_INSN (tem);
5464 PREV_INSN (NEXT_INSN (tem)) = PREV_INSN (tem);
5467 NEXT_INSN (tem) = first_use;
5468 PREV_INSN (first_use) = tem;
5475 emit_barrier_after (insn);
5477 seq = gen_epilogue ();
5478 tail = emit_jump_insn_after (seq, insn);
5480 /* Insert the USE insns immediately before the return insn, which
5481 must be the first instruction before the final barrier. */
5484 tem = prev_nonnote_insn (get_last_insn ());
5485 NEXT_INSN (PREV_INSN (tem)) = first_use;
5486 PREV_INSN (first_use) = PREV_INSN (tem);
5487 PREV_INSN (tem) = last_use;
5488 NEXT_INSN (last_use) = tem;
5491 emit_note_after (NOTE_INSN_EPILOGUE_BEG, insn);
5493 /* Include the new epilogue insns in the last block. Ignore
5494 them if they form a basic block unto themselves. */
5495 if (basic_block_end && n_basic_blocks
5496 && GET_CODE (basic_block_end[n_basic_blocks - 1]) != JUMP_INSN)
5497 basic_block_end[n_basic_blocks - 1] = tail;
5499 /* Retain a map of the epilogue insns. */
5500 epilogue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : tail);
5508 /* Reposition the prologue-end and epilogue-begin notes after instruction
5509 scheduling and delayed branch scheduling. */
5512 reposition_prologue_and_epilogue_notes (f)
5515 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
5516 /* Reposition the prologue and epilogue notes. */
5524 register rtx insn, note = 0;
5526 /* Scan from the beginning until we reach the last prologue insn.
5527 We apparently can't depend on basic_block_{head,end} after
5529 for (len = 0; prologue[len]; len++)
5531 for (insn = f; len && insn; insn = NEXT_INSN (insn))
5533 if (GET_CODE (insn) == NOTE)
5535 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
5538 else if ((len -= contains (insn, prologue)) == 0)
5540 /* Find the prologue-end note if we haven't already, and
5541 move it to just after the last prologue insn. */
5544 for (note = insn; note = NEXT_INSN (note);)
5545 if (GET_CODE (note) == NOTE
5546 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
5549 next = NEXT_INSN (note);
5550 prev = PREV_INSN (note);
5552 NEXT_INSN (prev) = next;
5554 PREV_INSN (next) = prev;
5555 add_insn_after (note, insn);
5562 register rtx insn, note = 0;
5564 /* Scan from the end until we reach the first epilogue insn.
5565 We apparently can't depend on basic_block_{head,end} after
5567 for (len = 0; epilogue[len]; len++)
5569 for (insn = get_last_insn (); len && insn; insn = PREV_INSN (insn))
5571 if (GET_CODE (insn) == NOTE)
5573 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
5576 else if ((len -= contains (insn, epilogue)) == 0)
5578 /* Find the epilogue-begin note if we haven't already, and
5579 move it to just before the first epilogue insn. */
5582 for (note = insn; note = PREV_INSN (note);)
5583 if (GET_CODE (note) == NOTE
5584 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
5587 next = NEXT_INSN (note);
5588 prev = PREV_INSN (note);
5590 NEXT_INSN (prev) = next;
5592 PREV_INSN (next) = prev;
5593 add_insn_after (note, PREV_INSN (insn));
5598 #endif /* HAVE_prologue or HAVE_epilogue */