1 /* Expands front end tree to back end RTL for GNU C-Compiler
2 Copyright (C) 1987, 88, 89, 91-94, 1995 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 (context)
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->contains_functions = current_function_contains_functions;
485 p->args_size = current_function_args_size;
486 p->pretend_args_size = current_function_pretend_args_size;
487 p->arg_offset_rtx = current_function_arg_offset_rtx;
488 p->varargs = current_function_varargs;
489 p->uses_const_pool = current_function_uses_const_pool;
490 p->uses_pic_offset_table = current_function_uses_pic_offset_table;
491 p->internal_arg_pointer = current_function_internal_arg_pointer;
492 p->max_parm_reg = max_parm_reg;
493 p->parm_reg_stack_loc = parm_reg_stack_loc;
494 p->outgoing_args_size = current_function_outgoing_args_size;
495 p->return_rtx = current_function_return_rtx;
496 p->nonlocal_goto_handler_slot = nonlocal_goto_handler_slot;
497 p->nonlocal_goto_stack_level = nonlocal_goto_stack_level;
498 p->nonlocal_labels = nonlocal_labels;
499 p->cleanup_label = cleanup_label;
500 p->return_label = return_label;
501 p->save_expr_regs = save_expr_regs;
502 p->stack_slot_list = stack_slot_list;
503 p->parm_birth_insn = parm_birth_insn;
504 p->frame_offset = frame_offset;
505 p->tail_recursion_label = tail_recursion_label;
506 p->tail_recursion_reentry = tail_recursion_reentry;
507 p->arg_pointer_save_area = arg_pointer_save_area;
508 p->rtl_expr_chain = rtl_expr_chain;
509 p->last_parm_insn = last_parm_insn;
510 p->context_display = context_display;
511 p->trampoline_list = trampoline_list;
512 p->function_call_count = function_call_count;
513 p->temp_slots = temp_slots;
514 p->temp_slot_level = temp_slot_level;
515 p->fixup_var_refs_queue = 0;
516 p->epilogue_delay_list = current_function_epilogue_delay_list;
518 save_tree_status (p, context);
519 save_storage_status (p);
520 save_emit_status (p);
522 save_expr_status (p);
523 save_stmt_status (p);
524 save_varasm_status (p);
526 if (save_machine_status)
527 (*save_machine_status) (p);
531 push_function_context ()
533 push_function_context_to (current_function_decl);
536 /* Restore the last saved context, at the end of a nested function.
537 This function is called from language-specific code. */
540 pop_function_context_from (context)
543 struct function *p = outer_function_chain;
545 outer_function_chain = p->next;
547 current_function_contains_functions
548 = p->contains_functions || p->inline_obstacks
549 || context == current_function_decl;
550 current_function_name = p->name;
551 current_function_decl = p->decl;
552 current_function_pops_args = p->pops_args;
553 current_function_returns_struct = p->returns_struct;
554 current_function_returns_pcc_struct = p->returns_pcc_struct;
555 current_function_needs_context = p->needs_context;
556 current_function_calls_setjmp = p->calls_setjmp;
557 current_function_calls_longjmp = p->calls_longjmp;
558 current_function_calls_alloca = p->calls_alloca;
559 current_function_has_nonlocal_label = p->has_nonlocal_label;
560 current_function_has_nonlocal_goto = p->has_nonlocal_goto;
561 current_function_args_size = p->args_size;
562 current_function_pretend_args_size = p->pretend_args_size;
563 current_function_arg_offset_rtx = p->arg_offset_rtx;
564 current_function_varargs = p->varargs;
565 current_function_uses_const_pool = p->uses_const_pool;
566 current_function_uses_pic_offset_table = p->uses_pic_offset_table;
567 current_function_internal_arg_pointer = p->internal_arg_pointer;
568 max_parm_reg = p->max_parm_reg;
569 parm_reg_stack_loc = p->parm_reg_stack_loc;
570 current_function_outgoing_args_size = p->outgoing_args_size;
571 current_function_return_rtx = p->return_rtx;
572 nonlocal_goto_handler_slot = p->nonlocal_goto_handler_slot;
573 nonlocal_goto_stack_level = p->nonlocal_goto_stack_level;
574 nonlocal_labels = p->nonlocal_labels;
575 cleanup_label = p->cleanup_label;
576 return_label = p->return_label;
577 save_expr_regs = p->save_expr_regs;
578 stack_slot_list = p->stack_slot_list;
579 parm_birth_insn = p->parm_birth_insn;
580 frame_offset = p->frame_offset;
581 tail_recursion_label = p->tail_recursion_label;
582 tail_recursion_reentry = p->tail_recursion_reentry;
583 arg_pointer_save_area = p->arg_pointer_save_area;
584 rtl_expr_chain = p->rtl_expr_chain;
585 last_parm_insn = p->last_parm_insn;
586 context_display = p->context_display;
587 trampoline_list = p->trampoline_list;
588 function_call_count = p->function_call_count;
589 temp_slots = p->temp_slots;
590 temp_slot_level = p->temp_slot_level;
591 current_function_epilogue_delay_list = p->epilogue_delay_list;
594 restore_tree_status (p);
595 restore_storage_status (p);
596 restore_expr_status (p);
597 restore_emit_status (p);
598 restore_stmt_status (p);
599 restore_varasm_status (p);
601 if (restore_machine_status)
602 (*restore_machine_status) (p);
604 /* Finish doing put_var_into_stack for any of our variables
605 which became addressable during the nested function. */
607 struct var_refs_queue *queue = p->fixup_var_refs_queue;
608 for (; queue; queue = queue->next)
609 fixup_var_refs (queue->modified, queue->promoted_mode, queue->unsignedp);
614 /* Reset variables that have known state during rtx generation. */
615 rtx_equal_function_value_matters = 1;
616 virtuals_instantiated = 0;
619 void pop_function_context ()
621 pop_function_context_from (current_function_decl);
624 /* Allocate fixed slots in the stack frame of the current function. */
626 /* Return size needed for stack frame based on slots so far allocated.
627 This size counts from zero. It is not rounded to STACK_BOUNDARY;
628 the caller may have to do that. */
633 #ifdef FRAME_GROWS_DOWNWARD
634 return -frame_offset;
640 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
641 with machine mode MODE.
643 ALIGN controls the amount of alignment for the address of the slot:
644 0 means according to MODE,
645 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
646 positive specifies alignment boundary in bits.
648 We do not round to stack_boundary here. */
651 assign_stack_local (mode, size, align)
652 enum machine_mode mode;
656 register rtx x, addr;
657 int bigend_correction = 0;
662 alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
664 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
666 else if (align == -1)
668 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
669 size = CEIL_ROUND (size, alignment);
672 alignment = align / BITS_PER_UNIT;
674 /* Round frame offset to that alignment.
675 We must be careful here, since FRAME_OFFSET might be negative and
676 division with a negative dividend isn't as well defined as we might
677 like. So we instead assume that ALIGNMENT is a power of two and
678 use logical operations which are unambiguous. */
679 #ifdef FRAME_GROWS_DOWNWARD
680 frame_offset = FLOOR_ROUND (frame_offset, alignment);
682 frame_offset = CEIL_ROUND (frame_offset, alignment);
685 /* On a big-endian machine, if we are allocating more space than we will use,
686 use the least significant bytes of those that are allocated. */
687 if (BYTES_BIG_ENDIAN && mode != BLKmode)
688 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. */
758 if (BYTES_BIG_ENDIAN && mode != BLKmode)
759 bigend_correction = size - GET_MODE_SIZE (mode);
761 #ifdef FRAME_GROWS_DOWNWARD
762 function->frame_offset -= size;
764 addr = plus_constant (virtual_stack_vars_rtx,
765 function->frame_offset + bigend_correction);
766 #ifndef FRAME_GROWS_DOWNWARD
767 function->frame_offset += size;
770 x = gen_rtx (MEM, mode, addr);
772 function->stack_slot_list
773 = gen_rtx (EXPR_LIST, VOIDmode, x, function->stack_slot_list);
780 /* Allocate a temporary stack slot and record it for possible later
783 MODE is the machine mode to be given to the returned rtx.
785 SIZE is the size in units of the space required. We do no rounding here
786 since assign_stack_local will do any required rounding.
788 KEEP is 1 if this slot is to be retained after a call to
789 free_temp_slots. Automatic variables for a block are allocated
790 with this flag. KEEP is 2, if we allocate a longer term temporary,
791 whose lifetime is controlled by CLEANUP_POINT_EXPRs. */
794 assign_stack_temp (mode, size, keep)
795 enum machine_mode mode;
799 struct temp_slot *p, *best_p = 0;
801 /* If SIZE is -1 it means that somebody tried to allocate a temporary
802 of a variable size. */
806 /* First try to find an available, already-allocated temporary that is the
807 exact size we require. */
808 for (p = temp_slots; p; p = p->next)
809 if (p->size == size && GET_MODE (p->slot) == mode && ! p->in_use)
812 /* If we didn't find, one, try one that is larger than what we want. We
813 find the smallest such. */
815 for (p = temp_slots; p; p = p->next)
816 if (p->size > size && GET_MODE (p->slot) == mode && ! p->in_use
817 && (best_p == 0 || best_p->size > p->size))
820 /* Make our best, if any, the one to use. */
823 /* If there are enough aligned bytes left over, make them into a new
824 temp_slot so that the extra bytes don't get wasted. Do this only
825 for BLKmode slots, so that we can be sure of the alignment. */
826 if (GET_MODE (best_p->slot) == BLKmode)
828 int alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
829 int rounded_size = CEIL_ROUND (size, alignment);
831 if (best_p->size - rounded_size >= alignment)
833 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
834 p->in_use = p->addr_taken = 0;
835 p->size = best_p->size - rounded_size;
836 p->slot = gen_rtx (MEM, BLKmode,
837 plus_constant (XEXP (best_p->slot, 0),
841 p->next = temp_slots;
844 stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, p->slot,
847 best_p->size = rounded_size;
854 /* If we still didn't find one, make a new temporary. */
857 int frame_offset_old = frame_offset;
858 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
859 /* If the temp slot mode doesn't indicate the alignment,
860 use the largest possible, so no one will be disappointed. */
861 p->slot = assign_stack_local (mode, size, mode == BLKmode ? -1 : 0);
862 /* The following slot size computation is necessary because we don't
863 know the actual size of the temporary slot until assign_stack_local
864 has performed all the frame alignment and size rounding for the
865 requested temporary. Otherwise combine_temp_slots won't think that
866 adjacent slots really are adjacent. */
867 #ifdef FRAME_GROWS_DOWNWARD
868 p->size = frame_offset_old - frame_offset;
870 p->size = frame_offset - frame_offset_old;
873 p->next = temp_slots;
879 p->rtl_expr = sequence_rtl_expr;
883 p->level = target_temp_slot_level;
888 p->level = temp_slot_level;
894 /* Combine temporary stack slots which are adjacent on the stack.
896 This allows for better use of already allocated stack space. This is only
897 done for BLKmode slots because we can be sure that we won't have alignment
898 problems in this case. */
901 combine_temp_slots ()
903 struct temp_slot *p, *q;
904 struct temp_slot *prev_p, *prev_q;
905 /* Determine where to free back to after this function. */
906 rtx free_pointer = rtx_alloc (CONST_INT);
908 for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots)
911 if (! p->in_use && GET_MODE (p->slot) == BLKmode)
912 for (q = p->next, prev_q = p; q; q = prev_q->next)
915 if (! q->in_use && GET_MODE (q->slot) == BLKmode)
917 if (rtx_equal_p (plus_constant (XEXP (p->slot, 0), p->size),
920 /* Q comes after P; combine Q into P. */
924 else if (rtx_equal_p (plus_constant (XEXP (q->slot, 0), q->size),
927 /* P comes after Q; combine P into Q. */
933 /* Either delete Q or advance past it. */
935 prev_q->next = q->next;
939 /* Either delete P or advance past it. */
943 prev_p->next = p->next;
945 temp_slots = p->next;
951 /* Free all the RTL made by plus_constant. */
952 rtx_free (free_pointer);
955 /* Find the temp slot corresponding to the object at address X. */
957 static struct temp_slot *
958 find_temp_slot_from_address (x)
964 for (p = temp_slots; p; p = p->next)
968 else if (XEXP (p->slot, 0) == x
972 else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST)
973 for (next = p->address; next; next = XEXP (next, 1))
974 if (XEXP (next, 0) == x)
981 /* Indicate that NEW is an alternate way of refering to the temp slot
982 that previous was known by OLD. */
985 update_temp_slot_address (old, new)
988 struct temp_slot *p = find_temp_slot_from_address (old);
990 /* If none, return. Else add NEW as an alias. */
993 else if (p->address == 0)
997 if (GET_CODE (p->address) != EXPR_LIST)
998 p->address = gen_rtx (EXPR_LIST, VOIDmode, p->address, NULL_RTX);
1000 p->address = gen_rtx (EXPR_LIST, VOIDmode, new, p->address);
1004 /* If X could be a reference to a temporary slot, mark the fact that its
1005 adddress was taken. */
1008 mark_temp_addr_taken (x)
1011 struct temp_slot *p;
1016 /* If X is not in memory or is at a constant address, it cannot be in
1017 a temporary slot. */
1018 if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1021 p = find_temp_slot_from_address (XEXP (x, 0));
1026 /* If X could be a reference to a temporary slot, mark that slot as belonging
1027 to the to one level higher. If X matched one of our slots, just mark that
1028 one. Otherwise, we can't easily predict which it is, so upgrade all of
1029 them. Kept slots need not be touched.
1031 This is called when an ({...}) construct occurs and a statement
1032 returns a value in memory. */
1035 preserve_temp_slots (x)
1038 struct temp_slot *p = 0;
1040 /* If there is no result, we still might have some objects whose address
1041 were taken, so we need to make sure they stay around. */
1044 for (p = temp_slots; p; p = p->next)
1045 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1051 /* If X is a register that is being used as a pointer, see if we have
1052 a temporary slot we know it points to. To be consistent with
1053 the code below, we really should preserve all non-kept slots
1054 if we can't find a match, but that seems to be much too costly. */
1055 if (GET_CODE (x) == REG && REGNO_POINTER_FLAG (REGNO (x)))
1056 p = find_temp_slot_from_address (x);
1058 /* If X is not in memory or is at a constant address, it cannot be in
1059 a temporary slot, but it can contain something whose address was
1061 if (p == 0 && (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))))
1063 for (p = temp_slots; p; p = p->next)
1064 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1070 /* First see if we can find a match. */
1072 p = find_temp_slot_from_address (XEXP (x, 0));
1076 /* Move everything at our level whose address was taken to our new
1077 level in case we used its address. */
1078 struct temp_slot *q;
1080 for (q = temp_slots; q; q = q->next)
1081 if (q != p && q->addr_taken && q->level == p->level)
1089 /* Otherwise, preserve all non-kept slots at this level. */
1090 for (p = temp_slots; p; p = p->next)
1091 if (p->in_use && p->level == temp_slot_level && ! p->keep)
1095 /* X is the result of an RTL_EXPR. If it is a temporary slot associated
1096 with that RTL_EXPR, promote it into a temporary slot at the present
1097 level so it will not be freed when we free slots made in the
1101 preserve_rtl_expr_result (x)
1104 struct temp_slot *p;
1106 /* If X is not in memory or is at a constant address, it cannot be in
1107 a temporary slot. */
1108 if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1111 /* If we can find a match, move it to our level unless it is already at
1113 p = find_temp_slot_from_address (XEXP (x, 0));
1116 p->level = MIN (p->level, temp_slot_level);
1123 /* Free all temporaries used so far. This is normally called at the end
1124 of generating code for a statement. Don't free any temporaries
1125 currently in use for an RTL_EXPR that hasn't yet been emitted.
1126 We could eventually do better than this since it can be reused while
1127 generating the same RTL_EXPR, but this is complex and probably not
1133 struct temp_slot *p;
1135 for (p = temp_slots; p; p = p->next)
1136 if (p->in_use && p->level == temp_slot_level && ! p->keep
1137 && p->rtl_expr == 0)
1140 combine_temp_slots ();
1143 /* Free all temporary slots used in T, an RTL_EXPR node. */
1146 free_temps_for_rtl_expr (t)
1149 struct temp_slot *p;
1151 for (p = temp_slots; p; p = p->next)
1152 if (p->rtl_expr == t)
1155 combine_temp_slots ();
1158 /* Push deeper into the nesting level for stack temporaries. */
1166 /* Pop a temporary nesting level. All slots in use in the current level
1172 struct temp_slot *p;
1174 for (p = temp_slots; p; p = p->next)
1175 if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0)
1178 combine_temp_slots ();
1183 /* Retroactively move an auto variable from a register to a stack slot.
1184 This is done when an address-reference to the variable is seen. */
1187 put_var_into_stack (decl)
1191 enum machine_mode promoted_mode, decl_mode;
1192 struct function *function = 0;
1195 if (output_bytecode)
1198 context = decl_function_context (decl);
1200 /* Get the current rtl used for this object and it's original mode. */
1201 reg = TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl) : DECL_RTL (decl);
1203 /* No need to do anything if decl has no rtx yet
1204 since in that case caller is setting TREE_ADDRESSABLE
1205 and a stack slot will be assigned when the rtl is made. */
1209 /* Get the declared mode for this object. */
1210 decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl))
1211 : DECL_MODE (decl));
1212 /* Get the mode it's actually stored in. */
1213 promoted_mode = GET_MODE (reg);
1215 /* If this variable comes from an outer function,
1216 find that function's saved context. */
1217 if (context != current_function_decl)
1218 for (function = outer_function_chain; function; function = function->next)
1219 if (function->decl == context)
1222 /* If this is a variable-size object with a pseudo to address it,
1223 put that pseudo into the stack, if the var is nonlocal. */
1224 if (DECL_NONLOCAL (decl)
1225 && GET_CODE (reg) == MEM
1226 && GET_CODE (XEXP (reg, 0)) == REG
1227 && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
1229 reg = XEXP (reg, 0);
1230 decl_mode = promoted_mode = GET_MODE (reg);
1233 /* Now we should have a value that resides in one or more pseudo regs. */
1235 if (GET_CODE (reg) == REG)
1236 put_reg_into_stack (function, reg, TREE_TYPE (decl),
1237 promoted_mode, decl_mode);
1238 else if (GET_CODE (reg) == CONCAT)
1240 /* A CONCAT contains two pseudos; put them both in the stack.
1241 We do it so they end up consecutive. */
1242 enum machine_mode part_mode = GET_MODE (XEXP (reg, 0));
1243 tree part_type = TREE_TYPE (TREE_TYPE (decl));
1244 #ifdef STACK_GROWS_DOWNWARD
1245 /* Since part 0 should have a lower address, do it second. */
1246 put_reg_into_stack (function, XEXP (reg, 1),
1247 part_type, part_mode, part_mode);
1248 put_reg_into_stack (function, XEXP (reg, 0),
1249 part_type, part_mode, part_mode);
1251 put_reg_into_stack (function, XEXP (reg, 0),
1252 part_type, part_mode, part_mode);
1253 put_reg_into_stack (function, XEXP (reg, 1),
1254 part_type, part_mode, part_mode);
1257 /* Change the CONCAT into a combined MEM for both parts. */
1258 PUT_CODE (reg, MEM);
1259 /* The two parts are in memory order already.
1260 Use the lower parts address as ours. */
1261 XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0);
1262 /* Prevent sharing of rtl that might lose. */
1263 if (GET_CODE (XEXP (reg, 0)) == PLUS)
1264 XEXP (reg, 0) = copy_rtx (XEXP (reg, 0));
1268 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1269 into the stack frame of FUNCTION (0 means the current function).
1270 DECL_MODE is the machine mode of the user-level data type.
1271 PROMOTED_MODE is the machine mode of the register. */
1274 put_reg_into_stack (function, reg, type, promoted_mode, decl_mode)
1275 struct function *function;
1278 enum machine_mode promoted_mode, decl_mode;
1284 if (REGNO (reg) < function->max_parm_reg)
1285 new = function->parm_reg_stack_loc[REGNO (reg)];
1287 new = assign_outer_stack_local (decl_mode, GET_MODE_SIZE (decl_mode),
1292 if (REGNO (reg) < max_parm_reg)
1293 new = parm_reg_stack_loc[REGNO (reg)];
1295 new = assign_stack_local (decl_mode, GET_MODE_SIZE (decl_mode), 0);
1298 XEXP (reg, 0) = XEXP (new, 0);
1299 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1300 REG_USERVAR_P (reg) = 0;
1301 PUT_CODE (reg, MEM);
1302 PUT_MODE (reg, decl_mode);
1304 /* If this is a memory ref that contains aggregate components,
1305 mark it as such for cse and loop optimize. */
1306 MEM_IN_STRUCT_P (reg) = AGGREGATE_TYPE_P (type);
1308 /* Now make sure that all refs to the variable, previously made
1309 when it was a register, are fixed up to be valid again. */
1312 struct var_refs_queue *temp;
1314 /* Variable is inherited; fix it up when we get back to its function. */
1315 push_obstacks (function->function_obstack,
1316 function->function_maybepermanent_obstack);
1318 /* See comment in restore_tree_status in tree.c for why this needs to be
1319 on saveable obstack. */
1321 = (struct var_refs_queue *) savealloc (sizeof (struct var_refs_queue));
1322 temp->modified = reg;
1323 temp->promoted_mode = promoted_mode;
1324 temp->unsignedp = TREE_UNSIGNED (type);
1325 temp->next = function->fixup_var_refs_queue;
1326 function->fixup_var_refs_queue = temp;
1330 /* Variable is local; fix it up now. */
1331 fixup_var_refs (reg, promoted_mode, TREE_UNSIGNED (type));
1335 fixup_var_refs (var, promoted_mode, unsignedp)
1337 enum machine_mode promoted_mode;
1341 rtx first_insn = get_insns ();
1342 struct sequence_stack *stack = sequence_stack;
1343 tree rtl_exps = rtl_expr_chain;
1345 /* Must scan all insns for stack-refs that exceed the limit. */
1346 fixup_var_refs_insns (var, promoted_mode, unsignedp, first_insn, stack == 0);
1348 /* Scan all pending sequences too. */
1349 for (; stack; stack = stack->next)
1351 push_to_sequence (stack->first);
1352 fixup_var_refs_insns (var, promoted_mode, unsignedp,
1353 stack->first, stack->next != 0);
1354 /* Update remembered end of sequence
1355 in case we added an insn at the end. */
1356 stack->last = get_last_insn ();
1360 /* Scan all waiting RTL_EXPRs too. */
1361 for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
1363 rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
1364 if (seq != const0_rtx && seq != 0)
1366 push_to_sequence (seq);
1367 fixup_var_refs_insns (var, promoted_mode, unsignedp, seq, 0);
1373 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1374 some part of an insn. Return a struct fixup_replacement whose OLD
1375 value is equal to X. Allocate a new structure if no such entry exists. */
1377 static struct fixup_replacement *
1378 find_fixup_replacement (replacements, x)
1379 struct fixup_replacement **replacements;
1382 struct fixup_replacement *p;
1384 /* See if we have already replaced this. */
1385 for (p = *replacements; p && p->old != x; p = p->next)
1390 p = (struct fixup_replacement *) oballoc (sizeof (struct fixup_replacement));
1393 p->next = *replacements;
1400 /* Scan the insn-chain starting with INSN for refs to VAR
1401 and fix them up. TOPLEVEL is nonzero if this chain is the
1402 main chain of insns for the current function. */
1405 fixup_var_refs_insns (var, promoted_mode, unsignedp, insn, toplevel)
1407 enum machine_mode promoted_mode;
1416 rtx next = NEXT_INSN (insn);
1418 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1420 /* If this is a CLOBBER of VAR, delete it.
1422 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1423 and REG_RETVAL notes too. */
1424 if (GET_CODE (PATTERN (insn)) == CLOBBER
1425 && XEXP (PATTERN (insn), 0) == var)
1427 if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0)
1428 /* The REG_LIBCALL note will go away since we are going to
1429 turn INSN into a NOTE, so just delete the
1430 corresponding REG_RETVAL note. */
1431 remove_note (XEXP (note, 0),
1432 find_reg_note (XEXP (note, 0), REG_RETVAL,
1435 /* In unoptimized compilation, we shouldn't call delete_insn
1436 except in jump.c doing warnings. */
1437 PUT_CODE (insn, NOTE);
1438 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1439 NOTE_SOURCE_FILE (insn) = 0;
1442 /* The insn to load VAR from a home in the arglist
1443 is now a no-op. When we see it, just delete it. */
1445 && GET_CODE (PATTERN (insn)) == SET
1446 && SET_DEST (PATTERN (insn)) == var
1447 /* If this represents the result of an insn group,
1448 don't delete the insn. */
1449 && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0
1450 && rtx_equal_p (SET_SRC (PATTERN (insn)), var))
1452 /* In unoptimized compilation, we shouldn't call delete_insn
1453 except in jump.c doing warnings. */
1454 PUT_CODE (insn, NOTE);
1455 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1456 NOTE_SOURCE_FILE (insn) = 0;
1457 if (insn == last_parm_insn)
1458 last_parm_insn = PREV_INSN (next);
1462 struct fixup_replacement *replacements = 0;
1463 rtx next_insn = NEXT_INSN (insn);
1465 #ifdef SMALL_REGISTER_CLASSES
1466 /* If the insn that copies the results of a CALL_INSN
1467 into a pseudo now references VAR, we have to use an
1468 intermediate pseudo since we want the life of the
1469 return value register to be only a single insn.
1471 If we don't use an intermediate pseudo, such things as
1472 address computations to make the address of VAR valid
1473 if it is not can be placed beween the CALL_INSN and INSN.
1475 To make sure this doesn't happen, we record the destination
1476 of the CALL_INSN and see if the next insn uses both that
1479 if (call_dest != 0 && GET_CODE (insn) == INSN
1480 && reg_mentioned_p (var, PATTERN (insn))
1481 && reg_mentioned_p (call_dest, PATTERN (insn)))
1483 rtx temp = gen_reg_rtx (GET_MODE (call_dest));
1485 emit_insn_before (gen_move_insn (temp, call_dest), insn);
1487 PATTERN (insn) = replace_rtx (PATTERN (insn),
1491 if (GET_CODE (insn) == CALL_INSN
1492 && GET_CODE (PATTERN (insn)) == SET)
1493 call_dest = SET_DEST (PATTERN (insn));
1494 else if (GET_CODE (insn) == CALL_INSN
1495 && GET_CODE (PATTERN (insn)) == PARALLEL
1496 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
1497 call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
1502 /* See if we have to do anything to INSN now that VAR is in
1503 memory. If it needs to be loaded into a pseudo, use a single
1504 pseudo for the entire insn in case there is a MATCH_DUP
1505 between two operands. We pass a pointer to the head of
1506 a list of struct fixup_replacements. If fixup_var_refs_1
1507 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1508 it will record them in this list.
1510 If it allocated a pseudo for any replacement, we copy into
1513 fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn,
1516 /* If this is last_parm_insn, and any instructions were output
1517 after it to fix it up, then we must set last_parm_insn to
1518 the last such instruction emitted. */
1519 if (insn == last_parm_insn)
1520 last_parm_insn = PREV_INSN (next_insn);
1522 while (replacements)
1524 if (GET_CODE (replacements->new) == REG)
1529 /* OLD might be a (subreg (mem)). */
1530 if (GET_CODE (replacements->old) == SUBREG)
1532 = fixup_memory_subreg (replacements->old, insn, 0);
1535 = fixup_stack_1 (replacements->old, insn);
1537 insert_before = insn;
1539 /* If we are changing the mode, do a conversion.
1540 This might be wasteful, but combine.c will
1541 eliminate much of the waste. */
1543 if (GET_MODE (replacements->new)
1544 != GET_MODE (replacements->old))
1547 convert_move (replacements->new,
1548 replacements->old, unsignedp);
1549 seq = gen_sequence ();
1553 seq = gen_move_insn (replacements->new,
1556 emit_insn_before (seq, insert_before);
1559 replacements = replacements->next;
1563 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1564 But don't touch other insns referred to by reg-notes;
1565 we will get them elsewhere. */
1566 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
1567 if (GET_CODE (note) != INSN_LIST)
1569 = walk_fixup_memory_subreg (XEXP (note, 0), insn, 1);
1575 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1576 See if the rtx expression at *LOC in INSN needs to be changed.
1578 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1579 contain a list of original rtx's and replacements. If we find that we need
1580 to modify this insn by replacing a memory reference with a pseudo or by
1581 making a new MEM to implement a SUBREG, we consult that list to see if
1582 we have already chosen a replacement. If none has already been allocated,
1583 we allocate it and update the list. fixup_var_refs_insns will copy VAR
1584 or the SUBREG, as appropriate, to the pseudo. */
1587 fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements)
1589 enum machine_mode promoted_mode;
1592 struct fixup_replacement **replacements;
1595 register rtx x = *loc;
1596 RTX_CODE code = GET_CODE (x);
1598 register rtx tem, tem1;
1599 struct fixup_replacement *replacement;
1606 /* If we already have a replacement, use it. Otherwise,
1607 try to fix up this address in case it is invalid. */
1609 replacement = find_fixup_replacement (replacements, var);
1610 if (replacement->new)
1612 *loc = replacement->new;
1616 *loc = replacement->new = x = fixup_stack_1 (x, insn);
1618 /* Unless we are forcing memory to register or we changed the mode,
1619 we can leave things the way they are if the insn is valid. */
1621 INSN_CODE (insn) = -1;
1622 if (! flag_force_mem && GET_MODE (x) == promoted_mode
1623 && recog_memoized (insn) >= 0)
1626 *loc = replacement->new = gen_reg_rtx (promoted_mode);
1630 /* If X contains VAR, we need to unshare it here so that we update
1631 each occurrence separately. But all identical MEMs in one insn
1632 must be replaced with the same rtx because of the possibility of
1635 if (reg_mentioned_p (var, x))
1637 replacement = find_fixup_replacement (replacements, x);
1638 if (replacement->new == 0)
1639 replacement->new = copy_most_rtx (x, var);
1641 *loc = x = replacement->new;
1657 /* Note that in some cases those types of expressions are altered
1658 by optimize_bit_field, and do not survive to get here. */
1659 if (XEXP (x, 0) == var
1660 || (GET_CODE (XEXP (x, 0)) == SUBREG
1661 && SUBREG_REG (XEXP (x, 0)) == var))
1663 /* Get TEM as a valid MEM in the mode presently in the insn.
1665 We don't worry about the possibility of MATCH_DUP here; it
1666 is highly unlikely and would be tricky to handle. */
1669 if (GET_CODE (tem) == SUBREG)
1670 tem = fixup_memory_subreg (tem, insn, 1);
1671 tem = fixup_stack_1 (tem, insn);
1673 /* Unless we want to load from memory, get TEM into the proper mode
1674 for an extract from memory. This can only be done if the
1675 extract is at a constant position and length. */
1677 if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
1678 && GET_CODE (XEXP (x, 2)) == CONST_INT
1679 && ! mode_dependent_address_p (XEXP (tem, 0))
1680 && ! MEM_VOLATILE_P (tem))
1682 enum machine_mode wanted_mode = VOIDmode;
1683 enum machine_mode is_mode = GET_MODE (tem);
1684 int width = INTVAL (XEXP (x, 1));
1685 int pos = INTVAL (XEXP (x, 2));
1688 if (GET_CODE (x) == ZERO_EXTRACT)
1689 wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
1692 if (GET_CODE (x) == SIGN_EXTRACT)
1693 wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
1695 /* If we have a narrower mode, we can do something. */
1696 if (wanted_mode != VOIDmode
1697 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
1699 int offset = pos / BITS_PER_UNIT;
1700 rtx old_pos = XEXP (x, 2);
1703 /* If the bytes and bits are counted differently, we
1704 must adjust the offset. */
1705 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
1706 offset = (GET_MODE_SIZE (is_mode)
1707 - GET_MODE_SIZE (wanted_mode) - offset);
1709 pos %= GET_MODE_BITSIZE (wanted_mode);
1711 newmem = gen_rtx (MEM, wanted_mode,
1712 plus_constant (XEXP (tem, 0), offset));
1713 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
1714 MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
1715 MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
1717 /* Make the change and see if the insn remains valid. */
1718 INSN_CODE (insn) = -1;
1719 XEXP (x, 0) = newmem;
1720 XEXP (x, 2) = GEN_INT (pos);
1722 if (recog_memoized (insn) >= 0)
1725 /* Otherwise, restore old position. XEXP (x, 0) will be
1727 XEXP (x, 2) = old_pos;
1731 /* If we get here, the bitfield extract insn can't accept a memory
1732 reference. Copy the input into a register. */
1734 tem1 = gen_reg_rtx (GET_MODE (tem));
1735 emit_insn_before (gen_move_insn (tem1, tem), insn);
1742 if (SUBREG_REG (x) == var)
1744 /* If this is a special SUBREG made because VAR was promoted
1745 from a wider mode, replace it with VAR and call ourself
1746 recursively, this time saying that the object previously
1747 had its current mode (by virtue of the SUBREG). */
1749 if (SUBREG_PROMOTED_VAR_P (x))
1752 fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements);
1756 /* If this SUBREG makes VAR wider, it has become a paradoxical
1757 SUBREG with VAR in memory, but these aren't allowed at this
1758 stage of the compilation. So load VAR into a pseudo and take
1759 a SUBREG of that pseudo. */
1760 if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
1762 replacement = find_fixup_replacement (replacements, var);
1763 if (replacement->new == 0)
1764 replacement->new = gen_reg_rtx (GET_MODE (var));
1765 SUBREG_REG (x) = replacement->new;
1769 /* See if we have already found a replacement for this SUBREG.
1770 If so, use it. Otherwise, make a MEM and see if the insn
1771 is recognized. If not, or if we should force MEM into a register,
1772 make a pseudo for this SUBREG. */
1773 replacement = find_fixup_replacement (replacements, x);
1774 if (replacement->new)
1776 *loc = replacement->new;
1780 replacement->new = *loc = fixup_memory_subreg (x, insn, 0);
1782 INSN_CODE (insn) = -1;
1783 if (! flag_force_mem && recog_memoized (insn) >= 0)
1786 *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
1792 /* First do special simplification of bit-field references. */
1793 if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
1794 || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
1795 optimize_bit_field (x, insn, 0);
1796 if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
1797 || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
1798 optimize_bit_field (x, insn, NULL_PTR);
1800 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
1801 insn into a pseudo and store the low part of the pseudo into VAR. */
1802 if (GET_CODE (SET_DEST (x)) == SUBREG
1803 && SUBREG_REG (SET_DEST (x)) == var
1804 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
1805 > GET_MODE_SIZE (GET_MODE (var))))
1807 SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
1808 emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
1815 rtx dest = SET_DEST (x);
1816 rtx src = SET_SRC (x);
1817 rtx outerdest = dest;
1819 while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
1820 || GET_CODE (dest) == SIGN_EXTRACT
1821 || GET_CODE (dest) == ZERO_EXTRACT)
1822 dest = XEXP (dest, 0);
1824 if (GET_CODE (src) == SUBREG)
1825 src = XEXP (src, 0);
1827 /* If VAR does not appear at the top level of the SET
1828 just scan the lower levels of the tree. */
1830 if (src != var && dest != var)
1833 /* We will need to rerecognize this insn. */
1834 INSN_CODE (insn) = -1;
1837 if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var)
1839 /* Since this case will return, ensure we fixup all the
1841 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1),
1842 insn, replacements);
1843 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2),
1844 insn, replacements);
1845 fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x),
1846 insn, replacements);
1848 tem = XEXP (outerdest, 0);
1850 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
1851 that may appear inside a ZERO_EXTRACT.
1852 This was legitimate when the MEM was a REG. */
1853 if (GET_CODE (tem) == SUBREG
1854 && SUBREG_REG (tem) == var)
1855 tem = fixup_memory_subreg (tem, insn, 1);
1857 tem = fixup_stack_1 (tem, insn);
1859 if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
1860 && GET_CODE (XEXP (outerdest, 2)) == CONST_INT
1861 && ! mode_dependent_address_p (XEXP (tem, 0))
1862 && ! MEM_VOLATILE_P (tem))
1864 enum machine_mode wanted_mode
1865 = insn_operand_mode[(int) CODE_FOR_insv][0];
1866 enum machine_mode is_mode = GET_MODE (tem);
1867 int width = INTVAL (XEXP (outerdest, 1));
1868 int pos = INTVAL (XEXP (outerdest, 2));
1870 /* If we have a narrower mode, we can do something. */
1871 if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
1873 int offset = pos / BITS_PER_UNIT;
1874 rtx old_pos = XEXP (outerdest, 2);
1877 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
1878 offset = (GET_MODE_SIZE (is_mode)
1879 - GET_MODE_SIZE (wanted_mode) - offset);
1881 pos %= GET_MODE_BITSIZE (wanted_mode);
1883 newmem = gen_rtx (MEM, wanted_mode,
1884 plus_constant (XEXP (tem, 0), offset));
1885 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
1886 MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
1887 MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
1889 /* Make the change and see if the insn remains valid. */
1890 INSN_CODE (insn) = -1;
1891 XEXP (outerdest, 0) = newmem;
1892 XEXP (outerdest, 2) = GEN_INT (pos);
1894 if (recog_memoized (insn) >= 0)
1897 /* Otherwise, restore old position. XEXP (x, 0) will be
1899 XEXP (outerdest, 2) = old_pos;
1903 /* If we get here, the bit-field store doesn't allow memory
1904 or isn't located at a constant position. Load the value into
1905 a register, do the store, and put it back into memory. */
1907 tem1 = gen_reg_rtx (GET_MODE (tem));
1908 emit_insn_before (gen_move_insn (tem1, tem), insn);
1909 emit_insn_after (gen_move_insn (tem, tem1), insn);
1910 XEXP (outerdest, 0) = tem1;
1915 /* STRICT_LOW_PART is a no-op on memory references
1916 and it can cause combinations to be unrecognizable,
1919 if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
1920 SET_DEST (x) = XEXP (SET_DEST (x), 0);
1922 /* A valid insn to copy VAR into or out of a register
1923 must be left alone, to avoid an infinite loop here.
1924 If the reference to VAR is by a subreg, fix that up,
1925 since SUBREG is not valid for a memref.
1926 Also fix up the address of the stack slot.
1928 Note that we must not try to recognize the insn until
1929 after we know that we have valid addresses and no
1930 (subreg (mem ...) ...) constructs, since these interfere
1931 with determining the validity of the insn. */
1933 if ((SET_SRC (x) == var
1934 || (GET_CODE (SET_SRC (x)) == SUBREG
1935 && SUBREG_REG (SET_SRC (x)) == var))
1936 && (GET_CODE (SET_DEST (x)) == REG
1937 || (GET_CODE (SET_DEST (x)) == SUBREG
1938 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
1939 && x == single_set (PATTERN (insn)))
1943 replacement = find_fixup_replacement (replacements, SET_SRC (x));
1944 if (replacement->new)
1945 SET_SRC (x) = replacement->new;
1946 else if (GET_CODE (SET_SRC (x)) == SUBREG)
1947 SET_SRC (x) = replacement->new
1948 = fixup_memory_subreg (SET_SRC (x), insn, 0);
1950 SET_SRC (x) = replacement->new
1951 = fixup_stack_1 (SET_SRC (x), insn);
1953 if (recog_memoized (insn) >= 0)
1956 /* INSN is not valid, but we know that we want to
1957 copy SET_SRC (x) to SET_DEST (x) in some way. So
1958 we generate the move and see whether it requires more
1959 than one insn. If it does, we emit those insns and
1960 delete INSN. Otherwise, we an just replace the pattern
1961 of INSN; we have already verified above that INSN has
1962 no other function that to do X. */
1964 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
1965 if (GET_CODE (pat) == SEQUENCE)
1967 emit_insn_after (pat, insn);
1968 PUT_CODE (insn, NOTE);
1969 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1970 NOTE_SOURCE_FILE (insn) = 0;
1973 PATTERN (insn) = pat;
1978 if ((SET_DEST (x) == var
1979 || (GET_CODE (SET_DEST (x)) == SUBREG
1980 && SUBREG_REG (SET_DEST (x)) == var))
1981 && (GET_CODE (SET_SRC (x)) == REG
1982 || (GET_CODE (SET_SRC (x)) == SUBREG
1983 && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
1984 && x == single_set (PATTERN (insn)))
1988 if (GET_CODE (SET_DEST (x)) == SUBREG)
1989 SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn, 0);
1991 SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
1993 if (recog_memoized (insn) >= 0)
1996 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
1997 if (GET_CODE (pat) == SEQUENCE)
1999 emit_insn_after (pat, insn);
2000 PUT_CODE (insn, NOTE);
2001 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2002 NOTE_SOURCE_FILE (insn) = 0;
2005 PATTERN (insn) = pat;
2010 /* Otherwise, storing into VAR must be handled specially
2011 by storing into a temporary and copying that into VAR
2012 with a new insn after this one. Note that this case
2013 will be used when storing into a promoted scalar since
2014 the insn will now have different modes on the input
2015 and output and hence will be invalid (except for the case
2016 of setting it to a constant, which does not need any
2017 change if it is valid). We generate extra code in that case,
2018 but combine.c will eliminate it. */
2023 rtx fixeddest = SET_DEST (x);
2025 /* STRICT_LOW_PART can be discarded, around a MEM. */
2026 if (GET_CODE (fixeddest) == STRICT_LOW_PART)
2027 fixeddest = XEXP (fixeddest, 0);
2028 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
2029 if (GET_CODE (fixeddest) == SUBREG)
2030 fixeddest = fixup_memory_subreg (fixeddest, insn, 0);
2032 fixeddest = fixup_stack_1 (fixeddest, insn);
2034 temp = gen_reg_rtx (GET_MODE (SET_SRC (x)) == VOIDmode
2035 ? GET_MODE (fixeddest)
2036 : GET_MODE (SET_SRC (x)));
2038 emit_insn_after (gen_move_insn (fixeddest,
2039 gen_lowpart (GET_MODE (fixeddest),
2043 SET_DEST (x) = temp;
2048 /* Nothing special about this RTX; fix its operands. */
2050 fmt = GET_RTX_FORMAT (code);
2051 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2054 fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements);
2058 for (j = 0; j < XVECLEN (x, i); j++)
2059 fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j),
2060 insn, replacements);
2065 /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
2066 return an rtx (MEM:m1 newaddr) which is equivalent.
2067 If any insns must be emitted to compute NEWADDR, put them before INSN.
2069 UNCRITICAL nonzero means accept paradoxical subregs.
2070 This is used for subregs found inside of ZERO_EXTRACTs and in REG_NOTES. */
2073 fixup_memory_subreg (x, insn, uncritical)
2078 int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
2079 rtx addr = XEXP (SUBREG_REG (x), 0);
2080 enum machine_mode mode = GET_MODE (x);
2083 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2084 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
2088 if (BYTES_BIG_ENDIAN)
2089 offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
2090 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
2091 addr = plus_constant (addr, offset);
2092 if (!flag_force_addr && memory_address_p (mode, addr))
2093 /* Shortcut if no insns need be emitted. */
2094 return change_address (SUBREG_REG (x), mode, addr);
2096 result = change_address (SUBREG_REG (x), mode, addr);
2097 emit_insn_before (gen_sequence (), insn);
2102 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2103 Replace subexpressions of X in place.
2104 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2105 Otherwise return X, with its contents possibly altered.
2107 If any insns must be emitted to compute NEWADDR, put them before INSN.
2109 UNCRITICAL is as in fixup_memory_subreg. */
2112 walk_fixup_memory_subreg (x, insn, uncritical)
2117 register enum rtx_code code;
2124 code = GET_CODE (x);
2126 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
2127 return fixup_memory_subreg (x, insn, uncritical);
2129 /* Nothing special about this RTX; fix its operands. */
2131 fmt = GET_RTX_FORMAT (code);
2132 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2135 XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn, uncritical);
2139 for (j = 0; j < XVECLEN (x, i); j++)
2141 = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn, uncritical);
2147 /* For each memory ref within X, if it refers to a stack slot
2148 with an out of range displacement, put the address in a temp register
2149 (emitting new insns before INSN to load these registers)
2150 and alter the memory ref to use that register.
2151 Replace each such MEM rtx with a copy, to avoid clobberage. */
2154 fixup_stack_1 (x, insn)
2159 register RTX_CODE code = GET_CODE (x);
2164 register rtx ad = XEXP (x, 0);
2165 /* If we have address of a stack slot but it's not valid
2166 (displacement is too large), compute the sum in a register. */
2167 if (GET_CODE (ad) == PLUS
2168 && GET_CODE (XEXP (ad, 0)) == REG
2169 && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
2170 && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER)
2171 || XEXP (ad, 0) == current_function_internal_arg_pointer)
2172 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
2175 if (memory_address_p (GET_MODE (x), ad))
2179 temp = copy_to_reg (ad);
2180 seq = gen_sequence ();
2182 emit_insn_before (seq, insn);
2183 return change_address (x, VOIDmode, temp);
2188 fmt = GET_RTX_FORMAT (code);
2189 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2192 XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
2196 for (j = 0; j < XVECLEN (x, i); j++)
2197 XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
2203 /* Optimization: a bit-field instruction whose field
2204 happens to be a byte or halfword in memory
2205 can be changed to a move instruction.
2207 We call here when INSN is an insn to examine or store into a bit-field.
2208 BODY is the SET-rtx to be altered.
2210 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2211 (Currently this is called only from function.c, and EQUIV_MEM
2215 optimize_bit_field (body, insn, equiv_mem)
2220 register rtx bitfield;
2223 enum machine_mode mode;
2225 if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
2226 || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
2227 bitfield = SET_DEST (body), destflag = 1;
2229 bitfield = SET_SRC (body), destflag = 0;
2231 /* First check that the field being stored has constant size and position
2232 and is in fact a byte or halfword suitably aligned. */
2234 if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
2235 && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
2236 && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
2238 && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
2240 register rtx memref = 0;
2242 /* Now check that the containing word is memory, not a register,
2243 and that it is safe to change the machine mode. */
2245 if (GET_CODE (XEXP (bitfield, 0)) == MEM)
2246 memref = XEXP (bitfield, 0);
2247 else if (GET_CODE (XEXP (bitfield, 0)) == REG
2249 memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
2250 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2251 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
2252 memref = SUBREG_REG (XEXP (bitfield, 0));
2253 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2255 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
2256 memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
2259 && ! mode_dependent_address_p (XEXP (memref, 0))
2260 && ! MEM_VOLATILE_P (memref))
2262 /* Now adjust the address, first for any subreg'ing
2263 that we are now getting rid of,
2264 and then for which byte of the word is wanted. */
2266 register int offset = INTVAL (XEXP (bitfield, 2));
2269 /* Adjust OFFSET to count bits from low-address byte. */
2270 if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN)
2271 offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
2272 - offset - INTVAL (XEXP (bitfield, 1)));
2274 /* Adjust OFFSET to count bytes from low-address byte. */
2275 offset /= BITS_PER_UNIT;
2276 if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
2278 offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD;
2279 if (BYTES_BIG_ENDIAN)
2280 offset -= (MIN (UNITS_PER_WORD,
2281 GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
2282 - MIN (UNITS_PER_WORD,
2283 GET_MODE_SIZE (GET_MODE (memref))));
2287 memref = change_address (memref, mode,
2288 plus_constant (XEXP (memref, 0), offset));
2289 insns = get_insns ();
2291 emit_insns_before (insns, insn);
2293 /* Store this memory reference where
2294 we found the bit field reference. */
2298 validate_change (insn, &SET_DEST (body), memref, 1);
2299 if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
2301 rtx src = SET_SRC (body);
2302 while (GET_CODE (src) == SUBREG
2303 && SUBREG_WORD (src) == 0)
2304 src = SUBREG_REG (src);
2305 if (GET_MODE (src) != GET_MODE (memref))
2306 src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
2307 validate_change (insn, &SET_SRC (body), src, 1);
2309 else if (GET_MODE (SET_SRC (body)) != VOIDmode
2310 && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
2311 /* This shouldn't happen because anything that didn't have
2312 one of these modes should have got converted explicitly
2313 and then referenced through a subreg.
2314 This is so because the original bit-field was
2315 handled by agg_mode and so its tree structure had
2316 the same mode that memref now has. */
2321 rtx dest = SET_DEST (body);
2323 while (GET_CODE (dest) == SUBREG
2324 && SUBREG_WORD (dest) == 0
2325 && (GET_MODE_CLASS (GET_MODE (dest))
2326 == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest)))))
2327 dest = SUBREG_REG (dest);
2329 validate_change (insn, &SET_DEST (body), dest, 1);
2331 if (GET_MODE (dest) == GET_MODE (memref))
2332 validate_change (insn, &SET_SRC (body), memref, 1);
2335 /* Convert the mem ref to the destination mode. */
2336 rtx newreg = gen_reg_rtx (GET_MODE (dest));
2339 convert_move (newreg, memref,
2340 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
2344 validate_change (insn, &SET_SRC (body), newreg, 1);
2348 /* See if we can convert this extraction or insertion into
2349 a simple move insn. We might not be able to do so if this
2350 was, for example, part of a PARALLEL.
2352 If we succeed, write out any needed conversions. If we fail,
2353 it is hard to guess why we failed, so don't do anything
2354 special; just let the optimization be suppressed. */
2356 if (apply_change_group () && seq)
2357 emit_insns_before (seq, insn);
2362 /* These routines are responsible for converting virtual register references
2363 to the actual hard register references once RTL generation is complete.
2365 The following four variables are used for communication between the
2366 routines. They contain the offsets of the virtual registers from their
2367 respective hard registers. */
2369 static int in_arg_offset;
2370 static int var_offset;
2371 static int dynamic_offset;
2372 static int out_arg_offset;
2374 /* In most machines, the stack pointer register is equivalent to the bottom
2377 #ifndef STACK_POINTER_OFFSET
2378 #define STACK_POINTER_OFFSET 0
2381 /* If not defined, pick an appropriate default for the offset of dynamically
2382 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2383 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2385 #ifndef STACK_DYNAMIC_OFFSET
2387 #ifdef ACCUMULATE_OUTGOING_ARGS
2388 /* The bottom of the stack points to the actual arguments. If
2389 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2390 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2391 stack space for register parameters is not pushed by the caller, but
2392 rather part of the fixed stack areas and hence not included in
2393 `current_function_outgoing_args_size'. Nevertheless, we must allow
2394 for it when allocating stack dynamic objects. */
2396 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2397 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2398 (current_function_outgoing_args_size \
2399 + REG_PARM_STACK_SPACE (FNDECL) + (STACK_POINTER_OFFSET))
2402 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2403 (current_function_outgoing_args_size + (STACK_POINTER_OFFSET))
2407 #define STACK_DYNAMIC_OFFSET(FNDECL) STACK_POINTER_OFFSET
2411 /* Pass through the INSNS of function FNDECL and convert virtual register
2412 references to hard register references. */
2415 instantiate_virtual_regs (fndecl, insns)
2421 /* Compute the offsets to use for this function. */
2422 in_arg_offset = FIRST_PARM_OFFSET (fndecl);
2423 var_offset = STARTING_FRAME_OFFSET;
2424 dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
2425 out_arg_offset = STACK_POINTER_OFFSET;
2427 /* Scan all variables and parameters of this function. For each that is
2428 in memory, instantiate all virtual registers if the result is a valid
2429 address. If not, we do it later. That will handle most uses of virtual
2430 regs on many machines. */
2431 instantiate_decls (fndecl, 1);
2433 /* Initialize recognition, indicating that volatile is OK. */
2436 /* Scan through all the insns, instantiating every virtual register still
2438 for (insn = insns; insn; insn = NEXT_INSN (insn))
2439 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
2440 || GET_CODE (insn) == CALL_INSN)
2442 instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1);
2443 instantiate_virtual_regs_1 (®_NOTES (insn), NULL_RTX, 0);
2446 /* Now instantiate the remaining register equivalences for debugging info.
2447 These will not be valid addresses. */
2448 instantiate_decls (fndecl, 0);
2450 /* Indicate that, from now on, assign_stack_local should use
2451 frame_pointer_rtx. */
2452 virtuals_instantiated = 1;
2455 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
2456 all virtual registers in their DECL_RTL's.
2458 If VALID_ONLY, do this only if the resulting address is still valid.
2459 Otherwise, always do it. */
2462 instantiate_decls (fndecl, valid_only)
2468 if (DECL_INLINE (fndecl))
2469 /* When compiling an inline function, the obstack used for
2470 rtl allocation is the maybepermanent_obstack. Calling
2471 `resume_temporary_allocation' switches us back to that
2472 obstack while we process this function's parameters. */
2473 resume_temporary_allocation ();
2475 /* Process all parameters of the function. */
2476 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
2478 instantiate_decl (DECL_RTL (decl), int_size_in_bytes (TREE_TYPE (decl)),
2480 instantiate_decl (DECL_INCOMING_RTL (decl),
2481 int_size_in_bytes (TREE_TYPE (decl)), valid_only);
2484 /* Now process all variables defined in the function or its subblocks. */
2485 instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
2487 if (DECL_INLINE (fndecl))
2489 /* Save all rtl allocated for this function by raising the
2490 high-water mark on the maybepermanent_obstack. */
2492 /* All further rtl allocation is now done in the current_obstack. */
2493 rtl_in_current_obstack ();
2497 /* Subroutine of instantiate_decls: Process all decls in the given
2498 BLOCK node and all its subblocks. */
2501 instantiate_decls_1 (let, valid_only)
2507 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
2508 instantiate_decl (DECL_RTL (t), int_size_in_bytes (TREE_TYPE (t)),
2511 /* Process all subblocks. */
2512 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
2513 instantiate_decls_1 (t, valid_only);
2516 /* Subroutine of the preceding procedures: Given RTL representing a
2517 decl and the size of the object, do any instantiation required.
2519 If VALID_ONLY is non-zero, it means that the RTL should only be
2520 changed if the new address is valid. */
2523 instantiate_decl (x, size, valid_only)
2528 enum machine_mode mode;
2531 /* If this is not a MEM, no need to do anything. Similarly if the
2532 address is a constant or a register that is not a virtual register. */
2534 if (x == 0 || GET_CODE (x) != MEM)
2538 if (CONSTANT_P (addr)
2539 || (GET_CODE (addr) == REG
2540 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
2541 || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
2544 /* If we should only do this if the address is valid, copy the address.
2545 We need to do this so we can undo any changes that might make the
2546 address invalid. This copy is unfortunate, but probably can't be
2550 addr = copy_rtx (addr);
2552 instantiate_virtual_regs_1 (&addr, NULL_RTX, 0);
2557 /* Now verify that the resulting address is valid for every integer or
2558 floating-point mode up to and including SIZE bytes long. We do this
2559 since the object might be accessed in any mode and frame addresses
2562 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2563 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
2564 mode = GET_MODE_WIDER_MODE (mode))
2565 if (! memory_address_p (mode, addr))
2568 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
2569 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
2570 mode = GET_MODE_WIDER_MODE (mode))
2571 if (! memory_address_p (mode, addr))
2574 /* Otherwise, put back the address, now that we have updated it and we
2575 know it is valid. */
2580 /* Given a pointer to a piece of rtx and an optional pointer to the
2581 containing object, instantiate any virtual registers present in it.
2583 If EXTRA_INSNS, we always do the replacement and generate
2584 any extra insns before OBJECT. If it zero, we do nothing if replacement
2587 Return 1 if we either had nothing to do or if we were able to do the
2588 needed replacement. Return 0 otherwise; we only return zero if
2589 EXTRA_INSNS is zero.
2591 We first try some simple transformations to avoid the creation of extra
2595 instantiate_virtual_regs_1 (loc, object, extra_insns)
2609 /* Re-start here to avoid recursion in common cases. */
2616 code = GET_CODE (x);
2618 /* Check for some special cases. */
2635 /* We are allowed to set the virtual registers. This means that
2636 that the actual register should receive the source minus the
2637 appropriate offset. This is used, for example, in the handling
2638 of non-local gotos. */
2639 if (SET_DEST (x) == virtual_incoming_args_rtx)
2640 new = arg_pointer_rtx, offset = - in_arg_offset;
2641 else if (SET_DEST (x) == virtual_stack_vars_rtx)
2642 new = frame_pointer_rtx, offset = - var_offset;
2643 else if (SET_DEST (x) == virtual_stack_dynamic_rtx)
2644 new = stack_pointer_rtx, offset = - dynamic_offset;
2645 else if (SET_DEST (x) == virtual_outgoing_args_rtx)
2646 new = stack_pointer_rtx, offset = - out_arg_offset;
2650 /* The only valid sources here are PLUS or REG. Just do
2651 the simplest possible thing to handle them. */
2652 if (GET_CODE (SET_SRC (x)) != REG
2653 && GET_CODE (SET_SRC (x)) != PLUS)
2657 if (GET_CODE (SET_SRC (x)) != REG)
2658 temp = force_operand (SET_SRC (x), NULL_RTX);
2661 temp = force_operand (plus_constant (temp, offset), NULL_RTX);
2665 emit_insns_before (seq, object);
2668 if (!validate_change (object, &SET_SRC (x), temp, 0)
2675 instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns);
2680 /* Handle special case of virtual register plus constant. */
2681 if (CONSTANT_P (XEXP (x, 1)))
2683 rtx old, new_offset;
2685 /* Check for (plus (plus VIRT foo) (const_int)) first. */
2686 if (GET_CODE (XEXP (x, 0)) == PLUS)
2688 rtx inner = XEXP (XEXP (x, 0), 0);
2690 if (inner == virtual_incoming_args_rtx)
2691 new = arg_pointer_rtx, offset = in_arg_offset;
2692 else if (inner == virtual_stack_vars_rtx)
2693 new = frame_pointer_rtx, offset = var_offset;
2694 else if (inner == virtual_stack_dynamic_rtx)
2695 new = stack_pointer_rtx, offset = dynamic_offset;
2696 else if (inner == virtual_outgoing_args_rtx)
2697 new = stack_pointer_rtx, offset = out_arg_offset;
2704 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object,
2706 new = gen_rtx (PLUS, Pmode, new, XEXP (XEXP (x, 0), 1));
2709 else if (XEXP (x, 0) == virtual_incoming_args_rtx)
2710 new = arg_pointer_rtx, offset = in_arg_offset;
2711 else if (XEXP (x, 0) == virtual_stack_vars_rtx)
2712 new = frame_pointer_rtx, offset = var_offset;
2713 else if (XEXP (x, 0) == virtual_stack_dynamic_rtx)
2714 new = stack_pointer_rtx, offset = dynamic_offset;
2715 else if (XEXP (x, 0) == virtual_outgoing_args_rtx)
2716 new = stack_pointer_rtx, offset = out_arg_offset;
2719 /* We know the second operand is a constant. Unless the
2720 first operand is a REG (which has been already checked),
2721 it needs to be checked. */
2722 if (GET_CODE (XEXP (x, 0)) != REG)
2730 new_offset = plus_constant (XEXP (x, 1), offset);
2732 /* If the new constant is zero, try to replace the sum with just
2734 if (new_offset == const0_rtx
2735 && validate_change (object, loc, new, 0))
2738 /* Next try to replace the register and new offset.
2739 There are two changes to validate here and we can't assume that
2740 in the case of old offset equals new just changing the register
2741 will yield a valid insn. In the interests of a little efficiency,
2742 however, we only call validate change once (we don't queue up the
2743 changes and then call apply_change_group). */
2747 ? ! validate_change (object, &XEXP (x, 0), new, 0)
2748 : (XEXP (x, 0) = new,
2749 ! validate_change (object, &XEXP (x, 1), new_offset, 0)))
2757 /* Otherwise copy the new constant into a register and replace
2758 constant with that register. */
2759 temp = gen_reg_rtx (Pmode);
2761 if (validate_change (object, &XEXP (x, 1), temp, 0))
2762 emit_insn_before (gen_move_insn (temp, new_offset), object);
2765 /* If that didn't work, replace this expression with a
2766 register containing the sum. */
2769 new = gen_rtx (PLUS, Pmode, new, new_offset);
2772 temp = force_operand (new, NULL_RTX);
2776 emit_insns_before (seq, object);
2777 if (! validate_change (object, loc, temp, 0)
2778 && ! validate_replace_rtx (x, temp, object))
2786 /* Fall through to generic two-operand expression case. */
2792 case DIV: case UDIV:
2793 case MOD: case UMOD:
2794 case AND: case IOR: case XOR:
2795 case ROTATERT: case ROTATE:
2796 case ASHIFTRT: case LSHIFTRT: case ASHIFT:
2798 case GE: case GT: case GEU: case GTU:
2799 case LE: case LT: case LEU: case LTU:
2800 if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
2801 instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns);
2806 /* Most cases of MEM that convert to valid addresses have already been
2807 handled by our scan of regno_reg_rtx. The only special handling we
2808 need here is to make a copy of the rtx to ensure it isn't being
2809 shared if we have to change it to a pseudo.
2811 If the rtx is a simple reference to an address via a virtual register,
2812 it can potentially be shared. In such cases, first try to make it
2813 a valid address, which can also be shared. Otherwise, copy it and
2816 First check for common cases that need no processing. These are
2817 usually due to instantiation already being done on a previous instance
2821 if (CONSTANT_ADDRESS_P (temp)
2822 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2823 || temp == arg_pointer_rtx
2825 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2826 || temp == hard_frame_pointer_rtx
2828 || temp == frame_pointer_rtx)
2831 if (GET_CODE (temp) == PLUS
2832 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
2833 && (XEXP (temp, 0) == frame_pointer_rtx
2834 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2835 || XEXP (temp, 0) == hard_frame_pointer_rtx
2837 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2838 || XEXP (temp, 0) == arg_pointer_rtx
2843 if (temp == virtual_stack_vars_rtx
2844 || temp == virtual_incoming_args_rtx
2845 || (GET_CODE (temp) == PLUS
2846 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
2847 && (XEXP (temp, 0) == virtual_stack_vars_rtx
2848 || XEXP (temp, 0) == virtual_incoming_args_rtx)))
2850 /* This MEM may be shared. If the substitution can be done without
2851 the need to generate new pseudos, we want to do it in place
2852 so all copies of the shared rtx benefit. The call below will
2853 only make substitutions if the resulting address is still
2856 Note that we cannot pass X as the object in the recursive call
2857 since the insn being processed may not allow all valid
2858 addresses. However, if we were not passed on object, we can
2859 only modify X without copying it if X will have a valid
2862 ??? Also note that this can still lose if OBJECT is an insn that
2863 has less restrictions on an address that some other insn.
2864 In that case, we will modify the shared address. This case
2865 doesn't seem very likely, though. */
2867 if (instantiate_virtual_regs_1 (&XEXP (x, 0),
2868 object ? object : x, 0))
2871 /* Otherwise make a copy and process that copy. We copy the entire
2872 RTL expression since it might be a PLUS which could also be
2874 *loc = x = copy_rtx (x);
2877 /* Fall through to generic unary operation case. */
2881 case STRICT_LOW_PART:
2883 case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC:
2884 case SIGN_EXTEND: case ZERO_EXTEND:
2885 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE:
2886 case FLOAT: case FIX:
2887 case UNSIGNED_FIX: case UNSIGNED_FLOAT:
2891 /* These case either have just one operand or we know that we need not
2892 check the rest of the operands. */
2897 /* Try to replace with a PLUS. If that doesn't work, compute the sum
2898 in front of this insn and substitute the temporary. */
2899 if (x == virtual_incoming_args_rtx)
2900 new = arg_pointer_rtx, offset = in_arg_offset;
2901 else if (x == virtual_stack_vars_rtx)
2902 new = frame_pointer_rtx, offset = var_offset;
2903 else if (x == virtual_stack_dynamic_rtx)
2904 new = stack_pointer_rtx, offset = dynamic_offset;
2905 else if (x == virtual_outgoing_args_rtx)
2906 new = stack_pointer_rtx, offset = out_arg_offset;
2910 temp = plus_constant (new, offset);
2911 if (!validate_change (object, loc, temp, 0))
2917 temp = force_operand (temp, NULL_RTX);
2921 emit_insns_before (seq, object);
2922 if (! validate_change (object, loc, temp, 0)
2923 && ! validate_replace_rtx (x, temp, object))
2931 /* Scan all subexpressions. */
2932 fmt = GET_RTX_FORMAT (code);
2933 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
2936 if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns))
2939 else if (*fmt == 'E')
2940 for (j = 0; j < XVECLEN (x, i); j++)
2941 if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object,
2948 /* Optimization: assuming this function does not receive nonlocal gotos,
2949 delete the handlers for such, as well as the insns to establish
2950 and disestablish them. */
2956 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2958 /* Delete the handler by turning off the flag that would
2959 prevent jump_optimize from deleting it.
2960 Also permit deletion of the nonlocal labels themselves
2961 if nothing local refers to them. */
2962 if (GET_CODE (insn) == CODE_LABEL)
2966 LABEL_PRESERVE_P (insn) = 0;
2968 /* Remove it from the nonlocal_label list, to avoid confusing
2970 for (t = nonlocal_labels, last_t = 0; t;
2971 last_t = t, t = TREE_CHAIN (t))
2972 if (DECL_RTL (TREE_VALUE (t)) == insn)
2977 nonlocal_labels = TREE_CHAIN (nonlocal_labels);
2979 TREE_CHAIN (last_t) = TREE_CHAIN (t);
2982 if (GET_CODE (insn) == INSN
2983 && ((nonlocal_goto_handler_slot != 0
2984 && reg_mentioned_p (nonlocal_goto_handler_slot, PATTERN (insn)))
2985 || (nonlocal_goto_stack_level != 0
2986 && reg_mentioned_p (nonlocal_goto_stack_level,
2992 /* Return a list (chain of EXPR_LIST nodes) for the nonlocal labels
2993 of the current function. */
2996 nonlocal_label_rtx_list ()
3001 for (t = nonlocal_labels; t; t = TREE_CHAIN (t))
3002 x = gen_rtx (EXPR_LIST, VOIDmode, label_rtx (TREE_VALUE (t)), x);
3007 /* Output a USE for any register use in RTL.
3008 This is used with -noreg to mark the extent of lifespan
3009 of any registers used in a user-visible variable's DECL_RTL. */
3015 if (GET_CODE (rtl) == REG)
3016 /* This is a register variable. */
3017 emit_insn (gen_rtx (USE, VOIDmode, rtl));
3018 else if (GET_CODE (rtl) == MEM
3019 && GET_CODE (XEXP (rtl, 0)) == REG
3020 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
3021 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
3022 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
3023 /* This is a variable-sized structure. */
3024 emit_insn (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)));
3027 /* Like use_variable except that it outputs the USEs after INSN
3028 instead of at the end of the insn-chain. */
3031 use_variable_after (rtl, insn)
3034 if (GET_CODE (rtl) == REG)
3035 /* This is a register variable. */
3036 emit_insn_after (gen_rtx (USE, VOIDmode, rtl), insn);
3037 else if (GET_CODE (rtl) == MEM
3038 && GET_CODE (XEXP (rtl, 0)) == REG
3039 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
3040 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
3041 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
3042 /* This is a variable-sized structure. */
3043 emit_insn_after (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)), insn);
3049 return max_parm_reg;
3052 /* Return the first insn following those generated by `assign_parms'. */
3055 get_first_nonparm_insn ()
3058 return NEXT_INSN (last_parm_insn);
3059 return get_insns ();
3062 /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
3063 Crash if there is none. */
3066 get_first_block_beg ()
3068 register rtx searcher;
3069 register rtx insn = get_first_nonparm_insn ();
3071 for (searcher = insn; searcher; searcher = NEXT_INSN (searcher))
3072 if (GET_CODE (searcher) == NOTE
3073 && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG)
3076 abort (); /* Invalid call to this function. (See comments above.) */
3080 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
3081 This means a type for which function calls must pass an address to the
3082 function or get an address back from the function.
3083 EXP may be a type node or an expression (whose type is tested). */
3086 aggregate_value_p (exp)
3089 int i, regno, nregs;
3092 if (TREE_CODE_CLASS (TREE_CODE (exp)) == 't')
3095 type = TREE_TYPE (exp);
3097 if (RETURN_IN_MEMORY (type))
3099 if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
3101 /* Make sure we have suitable call-clobbered regs to return
3102 the value in; if not, we must return it in memory. */
3103 reg = hard_function_value (type, 0);
3104 regno = REGNO (reg);
3105 nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type));
3106 for (i = 0; i < nregs; i++)
3107 if (! call_used_regs[regno + i])
3112 /* Assign RTL expressions to the function's parameters.
3113 This may involve copying them into registers and using
3114 those registers as the RTL for them.
3116 If SECOND_TIME is non-zero it means that this function is being
3117 called a second time. This is done by integrate.c when a function's
3118 compilation is deferred. We need to come back here in case the
3119 FUNCTION_ARG macro computes items needed for the rest of the compilation
3120 (such as changing which registers are fixed or caller-saved). But suppress
3121 writing any insns or setting DECL_RTL of anything in this case. */
3124 assign_parms (fndecl, second_time)
3129 register rtx entry_parm = 0;
3130 register rtx stack_parm = 0;
3131 CUMULATIVE_ARGS args_so_far;
3132 enum machine_mode promoted_mode, passed_mode, nominal_mode;
3134 /* Total space needed so far for args on the stack,
3135 given as a constant and a tree-expression. */
3136 struct args_size stack_args_size;
3137 tree fntype = TREE_TYPE (fndecl);
3138 tree fnargs = DECL_ARGUMENTS (fndecl);
3139 /* This is used for the arg pointer when referring to stack args. */
3140 rtx internal_arg_pointer;
3141 /* This is a dummy PARM_DECL that we used for the function result if
3142 the function returns a structure. */
3143 tree function_result_decl = 0;
3144 int nparmregs = list_length (fnargs) + LAST_VIRTUAL_REGISTER + 1;
3145 int varargs_setup = 0;
3146 rtx conversion_insns = 0;
3147 /* FUNCTION_ARG may look at this variable. Since this is not
3148 expanding a call it will always be zero in this function. */
3149 int current_call_is_indirect = 0;
3151 /* Nonzero if the last arg is named `__builtin_va_alist',
3152 which is used on some machines for old-fashioned non-ANSI varargs.h;
3153 this should be stuck onto the stack as if it had arrived there. */
3155 = (current_function_varargs
3157 && (parm = tree_last (fnargs)) != 0
3159 && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
3160 "__builtin_va_alist")));
3162 /* Nonzero if function takes extra anonymous args.
3163 This means the last named arg must be on the stack
3164 right before the anonymous ones. */
3166 = (TYPE_ARG_TYPES (fntype) != 0
3167 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3168 != void_type_node));
3170 /* If the reg that the virtual arg pointer will be translated into is
3171 not a fixed reg or is the stack pointer, make a copy of the virtual
3172 arg pointer, and address parms via the copy. The frame pointer is
3173 considered fixed even though it is not marked as such.
3175 The second time through, simply use ap to avoid generating rtx. */
3177 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
3178 || ! (fixed_regs[ARG_POINTER_REGNUM]
3179 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM))
3181 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
3183 internal_arg_pointer = virtual_incoming_args_rtx;
3184 current_function_internal_arg_pointer = internal_arg_pointer;
3186 stack_args_size.constant = 0;
3187 stack_args_size.var = 0;
3189 /* If struct value address is treated as the first argument, make it so. */
3190 if (aggregate_value_p (DECL_RESULT (fndecl))
3191 && ! current_function_returns_pcc_struct
3192 && struct_value_incoming_rtx == 0)
3194 tree type = build_pointer_type (fntype);
3196 function_result_decl = build_decl (PARM_DECL, NULL_TREE, type);
3198 DECL_ARG_TYPE (function_result_decl) = type;
3199 TREE_CHAIN (function_result_decl) = fnargs;
3200 fnargs = function_result_decl;
3203 parm_reg_stack_loc = (rtx *) oballoc (nparmregs * sizeof (rtx));
3204 bzero ((char *) parm_reg_stack_loc, nparmregs * sizeof (rtx));
3206 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
3207 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX);
3209 INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX);
3212 /* We haven't yet found an argument that we must push and pretend the
3214 current_function_pretend_args_size = 0;
3216 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
3218 int aggregate = AGGREGATE_TYPE_P (TREE_TYPE (parm));
3219 struct args_size stack_offset;
3220 struct args_size arg_size;
3221 int passed_pointer = 0;
3222 tree passed_type = DECL_ARG_TYPE (parm);
3224 /* Set LAST_NAMED if this is last named arg before some
3225 anonymous args. We treat it as if it were anonymous too. */
3226 int last_named = ((TREE_CHAIN (parm) == 0
3227 || DECL_NAME (TREE_CHAIN (parm)) == 0)
3228 && (stdarg || current_function_varargs));
3230 if (TREE_TYPE (parm) == error_mark_node
3231 /* This can happen after weird syntax errors
3232 or if an enum type is defined among the parms. */
3233 || TREE_CODE (parm) != PARM_DECL
3234 || passed_type == NULL)
3236 DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = gen_rtx (MEM, BLKmode,
3238 TREE_USED (parm) = 1;
3242 /* For varargs.h function, save info about regs and stack space
3243 used by the individual args, not including the va_alist arg. */
3244 if (hide_last_arg && last_named)
3245 current_function_args_info = args_so_far;
3247 /* Find mode of arg as it is passed, and mode of arg
3248 as it should be during execution of this function. */
3249 passed_mode = TYPE_MODE (passed_type);
3250 nominal_mode = TYPE_MODE (TREE_TYPE (parm));
3252 /* If the parm's mode is VOID, its value doesn't matter,
3253 and avoid the usual things like emit_move_insn that could crash. */
3254 if (nominal_mode == VOIDmode)
3256 DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = const0_rtx;
3260 /* If the parm is to be passed as a transparent union, use the
3261 type of the first field for the tests below. We have already
3262 verified that the modes are the same. */
3263 if (DECL_TRANSPARENT_UNION (parm)
3264 || TYPE_TRANSPARENT_UNION (passed_type))
3265 passed_type = TREE_TYPE (TYPE_FIELDS (passed_type));
3267 /* See if this arg was passed by invisible reference. It is if
3268 it is an object whose size depends on the contents of the
3269 object itself or if the machine requires these objects be passed
3272 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
3273 && contains_placeholder_p (TYPE_SIZE (passed_type)))
3274 || TYPE_NEEDS_CONSTRUCTING (passed_type)
3275 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
3276 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
3277 passed_type, ! last_named)
3281 passed_type = build_pointer_type (passed_type);
3283 passed_mode = nominal_mode = Pmode;
3286 promoted_mode = passed_mode;
3288 #ifdef PROMOTE_FUNCTION_ARGS
3289 /* Compute the mode in which the arg is actually extended to. */
3290 promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1);
3293 /* Let machine desc say which reg (if any) the parm arrives in.
3294 0 means it arrives on the stack. */
3295 #ifdef FUNCTION_INCOMING_ARG
3296 entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
3297 passed_type, ! last_named);
3299 entry_parm = FUNCTION_ARG (args_so_far, promoted_mode,
3300 passed_type, ! last_named);
3304 passed_mode = promoted_mode;
3306 #ifdef SETUP_INCOMING_VARARGS
3307 /* If this is the last named parameter, do any required setup for
3308 varargs or stdargs. We need to know about the case of this being an
3309 addressable type, in which case we skip the registers it
3310 would have arrived in.
3312 For stdargs, LAST_NAMED will be set for two parameters, the one that
3313 is actually the last named, and the dummy parameter. We only
3314 want to do this action once.
3316 Also, indicate when RTL generation is to be suppressed. */
3317 if (last_named && !varargs_setup)
3319 SETUP_INCOMING_VARARGS (args_so_far, passed_mode, passed_type,
3320 current_function_pretend_args_size,
3326 /* Determine parm's home in the stack,
3327 in case it arrives in the stack or we should pretend it did.
3329 Compute the stack position and rtx where the argument arrives
3332 There is one complexity here: If this was a parameter that would
3333 have been passed in registers, but wasn't only because it is
3334 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
3335 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
3336 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
3337 0 as it was the previous time. */
3339 locate_and_pad_parm (passed_mode, passed_type,
3340 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3343 #ifdef FUNCTION_INCOMING_ARG
3344 FUNCTION_INCOMING_ARG (args_so_far, passed_mode,
3347 || varargs_setup)) != 0,
3349 FUNCTION_ARG (args_so_far, passed_mode,
3351 ! last_named || varargs_setup) != 0,
3354 fndecl, &stack_args_size, &stack_offset, &arg_size);
3358 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
3360 if (offset_rtx == const0_rtx)
3361 stack_parm = gen_rtx (MEM, passed_mode, internal_arg_pointer);
3363 stack_parm = gen_rtx (MEM, passed_mode,
3364 gen_rtx (PLUS, Pmode,
3365 internal_arg_pointer, offset_rtx));
3367 /* If this is a memory ref that contains aggregate components,
3368 mark it as such for cse and loop optimize. */
3369 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3372 /* If this parameter was passed both in registers and in the stack,
3373 use the copy on the stack. */
3374 if (MUST_PASS_IN_STACK (passed_mode, passed_type))
3377 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3378 /* If this parm was passed part in regs and part in memory,
3379 pretend it arrived entirely in memory
3380 by pushing the register-part onto the stack.
3382 In the special case of a DImode or DFmode that is split,
3383 we could put it together in a pseudoreg directly,
3384 but for now that's not worth bothering with. */
3388 int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, passed_mode,
3389 passed_type, ! last_named);
3393 current_function_pretend_args_size
3394 = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
3395 / (PARM_BOUNDARY / BITS_PER_UNIT)
3396 * (PARM_BOUNDARY / BITS_PER_UNIT));
3399 move_block_from_reg (REGNO (entry_parm),
3400 validize_mem (stack_parm), nregs,
3401 int_size_in_bytes (TREE_TYPE (parm)));
3402 entry_parm = stack_parm;
3407 /* If we didn't decide this parm came in a register,
3408 by default it came on the stack. */
3409 if (entry_parm == 0)
3410 entry_parm = stack_parm;
3412 /* Record permanently how this parm was passed. */
3414 DECL_INCOMING_RTL (parm) = entry_parm;
3416 /* If there is actually space on the stack for this parm,
3417 count it in stack_args_size; otherwise set stack_parm to 0
3418 to indicate there is no preallocated stack slot for the parm. */
3420 if (entry_parm == stack_parm
3421 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
3422 /* On some machines, even if a parm value arrives in a register
3423 there is still an (uninitialized) stack slot allocated for it.
3425 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
3426 whether this parameter already has a stack slot allocated,
3427 because an arg block exists only if current_function_args_size
3428 is larger than some threshhold, and we haven't calculated that
3429 yet. So, for now, we just assume that stack slots never exist
3431 || REG_PARM_STACK_SPACE (fndecl) > 0
3435 stack_args_size.constant += arg_size.constant;
3437 ADD_PARM_SIZE (stack_args_size, arg_size.var);
3440 /* No stack slot was pushed for this parm. */
3443 /* Update info on where next arg arrives in registers. */
3445 FUNCTION_ARG_ADVANCE (args_so_far, passed_mode,
3446 passed_type, ! last_named);
3448 /* If this is our second time through, we are done with this parm. */
3452 /* If we can't trust the parm stack slot to be aligned enough
3453 for its ultimate type, don't use that slot after entry.
3454 We'll make another stack slot, if we need one. */
3456 int thisparm_boundary
3457 = FUNCTION_ARG_BOUNDARY (passed_mode, passed_type);
3459 if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary)
3463 /* If parm was passed in memory, and we need to convert it on entry,
3464 don't store it back in that same slot. */
3466 && nominal_mode != BLKmode && nominal_mode != passed_mode)
3470 /* Now adjust STACK_PARM to the mode and precise location
3471 where this parameter should live during execution,
3472 if we discover that it must live in the stack during execution.
3473 To make debuggers happier on big-endian machines, we store
3474 the value in the last bytes of the space available. */
3476 if (nominal_mode != BLKmode && nominal_mode != passed_mode
3481 if (BYTES_BIG_ENDIAN
3482 && GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD)
3483 stack_offset.constant += (GET_MODE_SIZE (passed_mode)
3484 - GET_MODE_SIZE (nominal_mode));
3486 offset_rtx = ARGS_SIZE_RTX (stack_offset);
3487 if (offset_rtx == const0_rtx)
3488 stack_parm = gen_rtx (MEM, nominal_mode, internal_arg_pointer);
3490 stack_parm = gen_rtx (MEM, nominal_mode,
3491 gen_rtx (PLUS, Pmode,
3492 internal_arg_pointer, offset_rtx));
3494 /* If this is a memory ref that contains aggregate components,
3495 mark it as such for cse and loop optimize. */
3496 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3500 /* ENTRY_PARM is an RTX for the parameter as it arrives,
3501 in the mode in which it arrives.
3502 STACK_PARM is an RTX for a stack slot where the parameter can live
3503 during the function (in case we want to put it there).
3504 STACK_PARM is 0 if no stack slot was pushed for it.
3506 Now output code if necessary to convert ENTRY_PARM to
3507 the type in which this function declares it,
3508 and store that result in an appropriate place,
3509 which may be a pseudo reg, may be STACK_PARM,
3510 or may be a local stack slot if STACK_PARM is 0.
3512 Set DECL_RTL to that place. */
3514 if (nominal_mode == BLKmode)
3516 /* If a BLKmode arrives in registers, copy it to a stack slot. */
3517 if (GET_CODE (entry_parm) == REG)
3519 int size_stored = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
3522 /* Note that we will be storing an integral number of words.
3523 So we have to be careful to ensure that we allocate an
3524 integral number of words. We do this below in the
3525 assign_stack_local if space was not allocated in the argument
3526 list. If it was, this will not work if PARM_BOUNDARY is not
3527 a multiple of BITS_PER_WORD. It isn't clear how to fix this
3528 if it becomes a problem. */
3530 if (stack_parm == 0)
3533 = assign_stack_local (GET_MODE (entry_parm), size_stored, 0);
3534 /* If this is a memory ref that contains aggregate components,
3535 mark it as such for cse and loop optimize. */
3536 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3539 else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
3542 if (TREE_READONLY (parm))
3543 RTX_UNCHANGING_P (stack_parm) = 1;
3545 move_block_from_reg (REGNO (entry_parm),
3546 validize_mem (stack_parm),
3547 size_stored / UNITS_PER_WORD,
3548 int_size_in_bytes (TREE_TYPE (parm)));
3550 DECL_RTL (parm) = stack_parm;
3552 else if (! ((obey_regdecls && ! DECL_REGISTER (parm)
3553 && ! DECL_INLINE (fndecl))
3554 /* layout_decl may set this. */
3555 || TREE_ADDRESSABLE (parm)
3556 || TREE_SIDE_EFFECTS (parm)
3557 /* If -ffloat-store specified, don't put explicit
3558 float variables into registers. */
3559 || (flag_float_store
3560 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
3561 /* Always assign pseudo to structure return or item passed
3562 by invisible reference. */
3563 || passed_pointer || parm == function_result_decl)
3565 /* Store the parm in a pseudoregister during the function, but we
3566 may need to do it in a wider mode. */
3568 register rtx parmreg;
3569 int regno, regnoi, regnor;
3571 unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
3572 nominal_mode = promote_mode (TREE_TYPE (parm), nominal_mode,
3575 parmreg = gen_reg_rtx (nominal_mode);
3576 REG_USERVAR_P (parmreg) = 1;
3578 /* If this was an item that we received a pointer to, set DECL_RTL
3582 DECL_RTL (parm) = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (passed_type)), parmreg);
3583 MEM_IN_STRUCT_P (DECL_RTL (parm)) = aggregate;
3586 DECL_RTL (parm) = parmreg;
3588 /* Copy the value into the register. */
3589 if (GET_MODE (parmreg) != GET_MODE (entry_parm))
3591 /* If ENTRY_PARM is a hard register, it might be in a register
3592 not valid for operating in its mode (e.g., an odd-numbered
3593 register for a DFmode). In that case, moves are the only
3594 thing valid, so we can't do a convert from there. This
3595 occurs when the calling sequence allow such misaligned
3598 In addition, the conversion may involve a call, which could
3599 clobber parameters which haven't been copied to pseudo
3600 registers yet. Therefore, we must first copy the parm to
3601 a pseudo reg here, and save the conversion until after all
3602 parameters have been moved. */
3604 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
3606 emit_move_insn (tempreg, validize_mem (entry_parm));
3608 push_to_sequence (conversion_insns);
3609 convert_move (parmreg, tempreg, unsignedp);
3610 conversion_insns = get_insns ();
3614 emit_move_insn (parmreg, validize_mem (entry_parm));
3616 /* If we were passed a pointer but the actual value
3617 can safely live in a register, put it in one. */
3618 if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
3619 && ! ((obey_regdecls && ! DECL_REGISTER (parm)
3620 && ! DECL_INLINE (fndecl))
3621 /* layout_decl may set this. */
3622 || TREE_ADDRESSABLE (parm)
3623 || TREE_SIDE_EFFECTS (parm)
3624 /* If -ffloat-store specified, don't put explicit
3625 float variables into registers. */
3626 || (flag_float_store
3627 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))
3629 /* We can't use nominal_mode, because it will have been set to
3630 Pmode above. We must use the actual mode of the parm. */
3631 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
3632 REG_USERVAR_P (parmreg) = 1;
3633 emit_move_insn (parmreg, DECL_RTL (parm));
3634 DECL_RTL (parm) = parmreg;
3635 /* STACK_PARM is the pointer, not the parm, and PARMREG is
3639 #ifdef FUNCTION_ARG_CALLEE_COPIES
3640 /* If we are passed an arg by reference and it is our responsibility
3641 to make a copy, do it now.
3642 PASSED_TYPE and PASSED mode now refer to the pointer, not the
3643 original argument, so we must recreate them in the call to
3644 FUNCTION_ARG_CALLEE_COPIES. */
3645 /* ??? Later add code to handle the case that if the argument isn't
3646 modified, don't do the copy. */
3648 else if (passed_pointer
3649 && FUNCTION_ARG_CALLEE_COPIES (args_so_far,
3650 TYPE_MODE (DECL_ARG_TYPE (parm)),
3651 DECL_ARG_TYPE (parm),
3655 tree type = DECL_ARG_TYPE (parm);
3657 /* This sequence may involve a library call perhaps clobbering
3658 registers that haven't been copied to pseudos yet. */
3660 push_to_sequence (conversion_insns);
3662 if (TYPE_SIZE (type) == 0
3663 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
3664 /* This is a variable sized object. */
3665 copy = gen_rtx (MEM, BLKmode,
3666 allocate_dynamic_stack_space
3667 (expr_size (parm), NULL_RTX,
3668 TYPE_ALIGN (type)));
3670 copy = assign_stack_temp (TYPE_MODE (type),
3671 int_size_in_bytes (type), 1);
3672 MEM_IN_STRUCT_P (copy) = AGGREGATE_TYPE_P (type);
3674 store_expr (parm, copy, 0);
3675 emit_move_insn (parmreg, XEXP (copy, 0));
3676 conversion_insns = get_insns ();
3679 #endif /* FUNCTION_ARG_CALLEE_COPIES */
3681 /* In any case, record the parm's desired stack location
3682 in case we later discover it must live in the stack.
3684 If it is a COMPLEX value, store the stack location for both
3687 if (GET_CODE (parmreg) == CONCAT)
3688 regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1)));
3690 regno = REGNO (parmreg);
3692 if (regno >= nparmregs)
3695 int old_nparmregs = nparmregs;
3697 nparmregs = regno + 5;
3698 new = (rtx *) oballoc (nparmregs * sizeof (rtx));
3699 bcopy ((char *) parm_reg_stack_loc, (char *) new,
3700 old_nparmregs * sizeof (rtx));
3701 bzero ((char *) (new + old_nparmregs),
3702 (nparmregs - old_nparmregs) * sizeof (rtx));
3703 parm_reg_stack_loc = new;
3706 if (GET_CODE (parmreg) == CONCAT)
3708 enum machine_mode submode = GET_MODE (XEXP (parmreg, 0));
3710 regnor = REGNO (gen_realpart (submode, parmreg));
3711 regnoi = REGNO (gen_imagpart (submode, parmreg));
3713 if (stack_parm != 0)
3715 parm_reg_stack_loc[regnor]
3716 = gen_realpart (submode, stack_parm);
3717 parm_reg_stack_loc[regnoi]
3718 = gen_imagpart (submode, stack_parm);
3722 parm_reg_stack_loc[regnor] = 0;
3723 parm_reg_stack_loc[regnoi] = 0;
3727 parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
3729 /* Mark the register as eliminable if we did no conversion
3730 and it was copied from memory at a fixed offset,
3731 and the arg pointer was not copied to a pseudo-reg.
3732 If the arg pointer is a pseudo reg or the offset formed
3733 an invalid address, such memory-equivalences
3734 as we make here would screw up life analysis for it. */
3735 if (nominal_mode == passed_mode
3736 && ! conversion_insns
3737 && GET_CODE (entry_parm) == MEM
3738 && entry_parm == stack_parm
3739 && stack_offset.var == 0
3740 && reg_mentioned_p (virtual_incoming_args_rtx,
3741 XEXP (entry_parm, 0)))
3743 rtx linsn = get_last_insn ();
3745 /* Mark complex types separately. */
3746 if (GET_CODE (parmreg) == CONCAT)
3749 = gen_rtx (EXPR_LIST, REG_EQUIV,
3750 parm_reg_stack_loc[regnoi], REG_NOTES (linsn));
3752 /* Now search backward for where we set the real part. */
3754 && ! reg_referenced_p (parm_reg_stack_loc[regnor],
3756 linsn = prev_nonnote_insn (linsn))
3760 = gen_rtx (EXPR_LIST, REG_EQUIV,
3761 parm_reg_stack_loc[regnor], REG_NOTES (linsn));
3765 = gen_rtx (EXPR_LIST, REG_EQUIV,
3766 entry_parm, REG_NOTES (linsn));
3769 /* For pointer data type, suggest pointer register. */
3770 if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE)
3771 mark_reg_pointer (parmreg);
3775 /* Value must be stored in the stack slot STACK_PARM
3776 during function execution. */
3778 if (passed_mode != nominal_mode)
3780 /* Conversion is required. */
3781 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
3783 emit_move_insn (tempreg, validize_mem (entry_parm));
3785 push_to_sequence (conversion_insns);
3786 entry_parm = convert_to_mode (nominal_mode, tempreg,
3787 TREE_UNSIGNED (TREE_TYPE (parm)));
3788 conversion_insns = get_insns ();
3792 if (entry_parm != stack_parm)
3794 if (stack_parm == 0)
3797 = assign_stack_local (GET_MODE (entry_parm),
3798 GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
3799 /* If this is a memory ref that contains aggregate components,
3800 mark it as such for cse and loop optimize. */
3801 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3804 if (passed_mode != nominal_mode)
3806 push_to_sequence (conversion_insns);
3807 emit_move_insn (validize_mem (stack_parm),
3808 validize_mem (entry_parm));
3809 conversion_insns = get_insns ();
3813 emit_move_insn (validize_mem (stack_parm),
3814 validize_mem (entry_parm));
3817 DECL_RTL (parm) = stack_parm;
3820 /* If this "parameter" was the place where we are receiving the
3821 function's incoming structure pointer, set up the result. */
3822 if (parm == function_result_decl)
3824 tree result = DECL_RESULT (fndecl);
3825 tree restype = TREE_TYPE (result);
3828 = gen_rtx (MEM, DECL_MODE (result), DECL_RTL (parm));
3830 MEM_IN_STRUCT_P (DECL_RTL (result)) = AGGREGATE_TYPE_P (restype);
3833 if (TREE_THIS_VOLATILE (parm))
3834 MEM_VOLATILE_P (DECL_RTL (parm)) = 1;
3835 if (TREE_READONLY (parm))
3836 RTX_UNCHANGING_P (DECL_RTL (parm)) = 1;
3839 /* Output all parameter conversion instructions (possibly including calls)
3840 now that all parameters have been copied out of hard registers. */
3841 emit_insns (conversion_insns);
3843 max_parm_reg = max_reg_num ();
3844 last_parm_insn = get_last_insn ();
3846 current_function_args_size = stack_args_size.constant;
3848 /* Adjust function incoming argument size for alignment and
3851 #ifdef REG_PARM_STACK_SPACE
3852 #ifndef MAYBE_REG_PARM_STACK_SPACE
3853 current_function_args_size = MAX (current_function_args_size,
3854 REG_PARM_STACK_SPACE (fndecl));
3858 #ifdef STACK_BOUNDARY
3859 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
3861 current_function_args_size
3862 = ((current_function_args_size + STACK_BYTES - 1)
3863 / STACK_BYTES) * STACK_BYTES;
3866 #ifdef ARGS_GROW_DOWNWARD
3867 current_function_arg_offset_rtx
3868 = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
3869 : expand_expr (size_binop (MINUS_EXPR, stack_args_size.var,
3870 size_int (-stack_args_size.constant)),
3871 NULL_RTX, VOIDmode, 0));
3873 current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
3876 /* See how many bytes, if any, of its args a function should try to pop
3879 current_function_pops_args = RETURN_POPS_ARGS (fndecl, TREE_TYPE (fndecl),
3880 current_function_args_size);
3882 /* For stdarg.h function, save info about
3883 regs and stack space used by the named args. */
3886 current_function_args_info = args_so_far;
3888 /* Set the rtx used for the function return value. Put this in its
3889 own variable so any optimizers that need this information don't have
3890 to include tree.h. Do this here so it gets done when an inlined
3891 function gets output. */
3893 current_function_return_rtx = DECL_RTL (DECL_RESULT (fndecl));
3896 /* Indicate whether REGNO is an incoming argument to the current function
3897 that was promoted to a wider mode. If so, return the RTX for the
3898 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
3899 that REGNO is promoted from and whether the promotion was signed or
3902 #ifdef PROMOTE_FUNCTION_ARGS
3905 promoted_input_arg (regno, pmode, punsignedp)
3907 enum machine_mode *pmode;
3912 for (arg = DECL_ARGUMENTS (current_function_decl); arg;
3913 arg = TREE_CHAIN (arg))
3914 if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
3915 && REGNO (DECL_INCOMING_RTL (arg)) == regno)
3917 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
3918 int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
3920 mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1);
3921 if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
3922 && mode != DECL_MODE (arg))
3924 *pmode = DECL_MODE (arg);
3925 *punsignedp = unsignedp;
3926 return DECL_INCOMING_RTL (arg);
3935 /* Compute the size and offset from the start of the stacked arguments for a
3936 parm passed in mode PASSED_MODE and with type TYPE.
3938 INITIAL_OFFSET_PTR points to the current offset into the stacked
3941 The starting offset and size for this parm are returned in *OFFSET_PTR
3942 and *ARG_SIZE_PTR, respectively.
3944 IN_REGS is non-zero if the argument will be passed in registers. It will
3945 never be set if REG_PARM_STACK_SPACE is not defined.
3947 FNDECL is the function in which the argument was defined.
3949 There are two types of rounding that are done. The first, controlled by
3950 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
3951 list to be aligned to the specific boundary (in bits). This rounding
3952 affects the initial and starting offsets, but not the argument size.
3954 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
3955 optionally rounds the size of the parm to PARM_BOUNDARY. The
3956 initial offset is not affected by this rounding, while the size always
3957 is and the starting offset may be. */
3959 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
3960 initial_offset_ptr is positive because locate_and_pad_parm's
3961 callers pass in the total size of args so far as
3962 initial_offset_ptr. arg_size_ptr is always positive.*/
3965 locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
3966 initial_offset_ptr, offset_ptr, arg_size_ptr)
3967 enum machine_mode passed_mode;
3971 struct args_size *initial_offset_ptr;
3972 struct args_size *offset_ptr;
3973 struct args_size *arg_size_ptr;
3976 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
3977 enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
3978 int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
3979 int boundary_in_bytes = boundary / BITS_PER_UNIT;
3980 int reg_parm_stack_space = 0;
3982 #ifdef REG_PARM_STACK_SPACE
3983 /* If we have found a stack parm before we reach the end of the
3984 area reserved for registers, skip that area. */
3987 #ifdef MAYBE_REG_PARM_STACK_SPACE
3988 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
3990 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
3992 if (reg_parm_stack_space > 0)
3994 if (initial_offset_ptr->var)
3996 initial_offset_ptr->var
3997 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
3998 size_int (reg_parm_stack_space));
3999 initial_offset_ptr->constant = 0;
4001 else if (initial_offset_ptr->constant < reg_parm_stack_space)
4002 initial_offset_ptr->constant = reg_parm_stack_space;
4005 #endif /* REG_PARM_STACK_SPACE */
4007 arg_size_ptr->var = 0;
4008 arg_size_ptr->constant = 0;
4010 #ifdef ARGS_GROW_DOWNWARD
4011 if (initial_offset_ptr->var)
4013 offset_ptr->constant = 0;
4014 offset_ptr->var = size_binop (MINUS_EXPR, integer_zero_node,
4015 initial_offset_ptr->var);
4019 offset_ptr->constant = - initial_offset_ptr->constant;
4020 offset_ptr->var = 0;
4022 if (where_pad != none
4023 && (TREE_CODE (sizetree) != INTEGER_CST
4024 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
4025 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4026 SUB_PARM_SIZE (*offset_ptr, sizetree);
4027 if (where_pad != downward)
4028 pad_to_arg_alignment (offset_ptr, boundary);
4029 if (initial_offset_ptr->var)
4031 arg_size_ptr->var = size_binop (MINUS_EXPR,
4032 size_binop (MINUS_EXPR,
4034 initial_offset_ptr->var),
4039 arg_size_ptr->constant = (- initial_offset_ptr->constant -
4040 offset_ptr->constant);
4042 #else /* !ARGS_GROW_DOWNWARD */
4043 pad_to_arg_alignment (initial_offset_ptr, boundary);
4044 *offset_ptr = *initial_offset_ptr;
4046 #ifdef PUSH_ROUNDING
4047 if (passed_mode != BLKmode)
4048 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
4051 /* Pad_below needs the pre-rounded size to know how much to pad below
4052 so this must be done before rounding up. */
4053 if (where_pad == downward
4054 /* However, BLKmode args passed in regs have their padding done elsewhere.
4055 The stack slot must be able to hold the entire register. */
4056 && !(in_regs && passed_mode == BLKmode))
4057 pad_below (offset_ptr, passed_mode, sizetree);
4059 if (where_pad != none
4060 && (TREE_CODE (sizetree) != INTEGER_CST
4061 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
4062 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4064 ADD_PARM_SIZE (*arg_size_ptr, sizetree);
4065 #endif /* ARGS_GROW_DOWNWARD */
4068 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
4069 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
4072 pad_to_arg_alignment (offset_ptr, boundary)
4073 struct args_size *offset_ptr;
4076 int boundary_in_bytes = boundary / BITS_PER_UNIT;
4078 if (boundary > BITS_PER_UNIT)
4080 if (offset_ptr->var)
4083 #ifdef ARGS_GROW_DOWNWARD
4088 (ARGS_SIZE_TREE (*offset_ptr),
4089 boundary / BITS_PER_UNIT);
4090 offset_ptr->constant = 0; /*?*/
4093 offset_ptr->constant =
4094 #ifdef ARGS_GROW_DOWNWARD
4095 FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes);
4097 CEIL_ROUND (offset_ptr->constant, boundary_in_bytes);
4103 pad_below (offset_ptr, passed_mode, sizetree)
4104 struct args_size *offset_ptr;
4105 enum machine_mode passed_mode;
4108 if (passed_mode != BLKmode)
4110 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
4111 offset_ptr->constant
4112 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
4113 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
4114 - GET_MODE_SIZE (passed_mode));
4118 if (TREE_CODE (sizetree) != INTEGER_CST
4119 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
4121 /* Round the size up to multiple of PARM_BOUNDARY bits. */
4122 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4124 ADD_PARM_SIZE (*offset_ptr, s2);
4125 SUB_PARM_SIZE (*offset_ptr, sizetree);
4131 round_down (value, divisor)
4135 return size_binop (MULT_EXPR,
4136 size_binop (FLOOR_DIV_EXPR, value, size_int (divisor)),
4137 size_int (divisor));
4140 /* Walk the tree of blocks describing the binding levels within a function
4141 and warn about uninitialized variables.
4142 This is done after calling flow_analysis and before global_alloc
4143 clobbers the pseudo-regs to hard regs. */
4146 uninitialized_vars_warning (block)
4149 register tree decl, sub;
4150 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
4152 if (TREE_CODE (decl) == VAR_DECL
4153 /* These warnings are unreliable for and aggregates
4154 because assigning the fields one by one can fail to convince
4155 flow.c that the entire aggregate was initialized.
4156 Unions are troublesome because members may be shorter. */
4157 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl))
4158 && DECL_RTL (decl) != 0
4159 && GET_CODE (DECL_RTL (decl)) == REG
4160 && regno_uninitialized (REGNO (DECL_RTL (decl))))
4161 warning_with_decl (decl,
4162 "`%s' might be used uninitialized in this function");
4163 if (TREE_CODE (decl) == VAR_DECL
4164 && DECL_RTL (decl) != 0
4165 && GET_CODE (DECL_RTL (decl)) == REG
4166 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
4167 warning_with_decl (decl,
4168 "variable `%s' might be clobbered by `longjmp' or `vfork'");
4170 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
4171 uninitialized_vars_warning (sub);
4174 /* Do the appropriate part of uninitialized_vars_warning
4175 but for arguments instead of local variables. */
4178 setjmp_args_warning (block)
4182 for (decl = DECL_ARGUMENTS (current_function_decl);
4183 decl; decl = TREE_CHAIN (decl))
4184 if (DECL_RTL (decl) != 0
4185 && GET_CODE (DECL_RTL (decl)) == REG
4186 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
4187 warning_with_decl (decl, "argument `%s' might be clobbered by `longjmp' or `vfork'");
4190 /* If this function call setjmp, put all vars into the stack
4191 unless they were declared `register'. */
4194 setjmp_protect (block)
4197 register tree decl, sub;
4198 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
4199 if ((TREE_CODE (decl) == VAR_DECL
4200 || TREE_CODE (decl) == PARM_DECL)
4201 && DECL_RTL (decl) != 0
4202 && GET_CODE (DECL_RTL (decl)) == REG
4203 /* If this variable came from an inline function, it must be
4204 that it's life doesn't overlap the setjmp. If there was a
4205 setjmp in the function, it would already be in memory. We
4206 must exclude such variable because their DECL_RTL might be
4207 set to strange things such as virtual_stack_vars_rtx. */
4208 && ! DECL_FROM_INLINE (decl)
4210 #ifdef NON_SAVING_SETJMP
4211 /* If longjmp doesn't restore the registers,
4212 don't put anything in them. */
4216 ! DECL_REGISTER (decl)))
4217 put_var_into_stack (decl);
4218 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
4219 setjmp_protect (sub);
4222 /* Like the previous function, but for args instead of local variables. */
4225 setjmp_protect_args ()
4227 register tree decl, sub;
4228 for (decl = DECL_ARGUMENTS (current_function_decl);
4229 decl; decl = TREE_CHAIN (decl))
4230 if ((TREE_CODE (decl) == VAR_DECL
4231 || TREE_CODE (decl) == PARM_DECL)
4232 && DECL_RTL (decl) != 0
4233 && GET_CODE (DECL_RTL (decl)) == REG
4235 /* If longjmp doesn't restore the registers,
4236 don't put anything in them. */
4237 #ifdef NON_SAVING_SETJMP
4241 ! DECL_REGISTER (decl)))
4242 put_var_into_stack (decl);
4245 /* Return the context-pointer register corresponding to DECL,
4246 or 0 if it does not need one. */
4249 lookup_static_chain (decl)
4252 tree context = decl_function_context (decl);
4258 /* We treat inline_function_decl as an alias for the current function
4259 because that is the inline function whose vars, types, etc.
4260 are being merged into the current function.
4261 See expand_inline_function. */
4262 if (context == current_function_decl || context == inline_function_decl)
4263 return virtual_stack_vars_rtx;
4265 for (link = context_display; link; link = TREE_CHAIN (link))
4266 if (TREE_PURPOSE (link) == context)
4267 return RTL_EXPR_RTL (TREE_VALUE (link));
4272 /* Convert a stack slot address ADDR for variable VAR
4273 (from a containing function)
4274 into an address valid in this function (using a static chain). */
4277 fix_lexical_addr (addr, var)
4283 tree context = decl_function_context (var);
4284 struct function *fp;
4287 /* If this is the present function, we need not do anything. */
4288 if (context == current_function_decl || context == inline_function_decl)
4291 for (fp = outer_function_chain; fp; fp = fp->next)
4292 if (fp->decl == context)
4298 /* Decode given address as base reg plus displacement. */
4299 if (GET_CODE (addr) == REG)
4300 basereg = addr, displacement = 0;
4301 else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
4302 basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
4306 /* We accept vars reached via the containing function's
4307 incoming arg pointer and via its stack variables pointer. */
4308 if (basereg == fp->internal_arg_pointer)
4310 /* If reached via arg pointer, get the arg pointer value
4311 out of that function's stack frame.
4313 There are two cases: If a separate ap is needed, allocate a
4314 slot in the outer function for it and dereference it that way.
4315 This is correct even if the real ap is actually a pseudo.
4316 Otherwise, just adjust the offset from the frame pointer to
4319 #ifdef NEED_SEPARATE_AP
4322 if (fp->arg_pointer_save_area == 0)
4323 fp->arg_pointer_save_area
4324 = assign_outer_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0, fp);
4326 addr = fix_lexical_addr (XEXP (fp->arg_pointer_save_area, 0), var);
4327 addr = memory_address (Pmode, addr);
4329 base = copy_to_reg (gen_rtx (MEM, Pmode, addr));
4331 displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
4332 base = lookup_static_chain (var);
4336 else if (basereg == virtual_stack_vars_rtx)
4338 /* This is the same code as lookup_static_chain, duplicated here to
4339 avoid an extra call to decl_function_context. */
4342 for (link = context_display; link; link = TREE_CHAIN (link))
4343 if (TREE_PURPOSE (link) == context)
4345 base = RTL_EXPR_RTL (TREE_VALUE (link));
4353 /* Use same offset, relative to appropriate static chain or argument
4355 return plus_constant (base, displacement);
4358 /* Return the address of the trampoline for entering nested fn FUNCTION.
4359 If necessary, allocate a trampoline (in the stack frame)
4360 and emit rtl to initialize its contents (at entry to this function). */
4363 trampoline_address (function)
4369 struct function *fp;
4372 /* Find an existing trampoline and return it. */
4373 for (link = trampoline_list; link; link = TREE_CHAIN (link))
4374 if (TREE_PURPOSE (link) == function)
4376 round_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0));
4378 for (fp = outer_function_chain; fp; fp = fp->next)
4379 for (link = fp->trampoline_list; link; link = TREE_CHAIN (link))
4380 if (TREE_PURPOSE (link) == function)
4382 tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
4384 return round_trampoline_addr (tramp);
4387 /* None exists; we must make one. */
4389 /* Find the `struct function' for the function containing FUNCTION. */
4391 fn_context = decl_function_context (function);
4392 if (fn_context != current_function_decl)
4393 for (fp = outer_function_chain; fp; fp = fp->next)
4394 if (fp->decl == fn_context)
4397 /* Allocate run-time space for this trampoline
4398 (usually in the defining function's stack frame). */
4399 #ifdef ALLOCATE_TRAMPOLINE
4400 tramp = ALLOCATE_TRAMPOLINE (fp);
4402 /* If rounding needed, allocate extra space
4403 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
4404 #ifdef TRAMPOLINE_ALIGNMENT
4405 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE + TRAMPOLINE_ALIGNMENT - 1)
4407 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
4410 tramp = assign_outer_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0, fp);
4412 tramp = assign_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0);
4415 /* Record the trampoline for reuse and note it for later initialization
4416 by expand_function_end. */
4419 push_obstacks (fp->function_maybepermanent_obstack,
4420 fp->function_maybepermanent_obstack);
4421 rtlexp = make_node (RTL_EXPR);
4422 RTL_EXPR_RTL (rtlexp) = tramp;
4423 fp->trampoline_list = tree_cons (function, rtlexp, fp->trampoline_list);
4428 /* Make the RTL_EXPR node temporary, not momentary, so that the
4429 trampoline_list doesn't become garbage. */
4430 int momentary = suspend_momentary ();
4431 rtlexp = make_node (RTL_EXPR);
4432 resume_momentary (momentary);
4434 RTL_EXPR_RTL (rtlexp) = tramp;
4435 trampoline_list = tree_cons (function, rtlexp, trampoline_list);
4438 tramp = fix_lexical_addr (XEXP (tramp, 0), function);
4439 return round_trampoline_addr (tramp);
4442 /* Given a trampoline address,
4443 round it to multiple of TRAMPOLINE_ALIGNMENT. */
4446 round_trampoline_addr (tramp)
4449 #ifdef TRAMPOLINE_ALIGNMENT
4450 /* Round address up to desired boundary. */
4451 rtx temp = gen_reg_rtx (Pmode);
4452 temp = expand_binop (Pmode, add_optab, tramp,
4453 GEN_INT (TRAMPOLINE_ALIGNMENT - 1),
4454 temp, 0, OPTAB_LIB_WIDEN);
4455 tramp = expand_binop (Pmode, and_optab, temp,
4456 GEN_INT (- TRAMPOLINE_ALIGNMENT),
4457 temp, 0, OPTAB_LIB_WIDEN);
4462 /* The functions identify_blocks and reorder_blocks provide a way to
4463 reorder the tree of BLOCK nodes, for optimizers that reshuffle or
4464 duplicate portions of the RTL code. Call identify_blocks before
4465 changing the RTL, and call reorder_blocks after. */
4467 /* Put all this function's BLOCK nodes into a vector, and return it.
4468 Also store in each NOTE for the beginning or end of a block
4469 the index of that block in the vector.
4470 The arguments are TOP_BLOCK, the top-level block of the function,
4471 and INSNS, the insn chain of the function. */
4474 identify_blocks (top_block, insns)
4482 int next_block_number = 0;
4483 int current_block_number = 0;
4489 n_blocks = all_blocks (top_block, 0);
4490 block_vector = (tree *) xmalloc (n_blocks * sizeof (tree));
4491 block_stack = (int *) alloca (n_blocks * sizeof (int));
4493 all_blocks (top_block, block_vector);
4495 for (insn = insns; insn; insn = NEXT_INSN (insn))
4496 if (GET_CODE (insn) == NOTE)
4498 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
4500 block_stack[depth++] = current_block_number;
4501 current_block_number = next_block_number;
4502 NOTE_BLOCK_NUMBER (insn) = next_block_number++;
4504 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
4506 current_block_number = block_stack[--depth];
4507 NOTE_BLOCK_NUMBER (insn) = current_block_number;
4511 return block_vector;
4514 /* Given BLOCK_VECTOR which was returned by identify_blocks,
4515 and a revised instruction chain, rebuild the tree structure
4516 of BLOCK nodes to correspond to the new order of RTL.
4517 The new block tree is inserted below TOP_BLOCK.
4518 Returns the current top-level block. */
4521 reorder_blocks (block_vector, top_block, insns)
4526 tree current_block = top_block;
4529 if (block_vector == 0)
4532 /* Prune the old tree away, so that it doesn't get in the way. */
4533 BLOCK_SUBBLOCKS (current_block) = 0;
4535 for (insn = insns; insn; insn = NEXT_INSN (insn))
4536 if (GET_CODE (insn) == NOTE)
4538 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
4540 tree block = block_vector[NOTE_BLOCK_NUMBER (insn)];
4541 /* If we have seen this block before, copy it. */
4542 if (TREE_ASM_WRITTEN (block))
4543 block = copy_node (block);
4544 BLOCK_SUBBLOCKS (block) = 0;
4545 TREE_ASM_WRITTEN (block) = 1;
4546 BLOCK_SUPERCONTEXT (block) = current_block;
4547 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
4548 BLOCK_SUBBLOCKS (current_block) = block;
4549 current_block = block;
4550 NOTE_SOURCE_FILE (insn) = 0;
4552 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
4554 BLOCK_SUBBLOCKS (current_block)
4555 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
4556 current_block = BLOCK_SUPERCONTEXT (current_block);
4557 NOTE_SOURCE_FILE (insn) = 0;
4561 return current_block;
4564 /* Reverse the order of elements in the chain T of blocks,
4565 and return the new head of the chain (old last element). */
4571 register tree prev = 0, decl, next;
4572 for (decl = t; decl; decl = next)
4574 next = BLOCK_CHAIN (decl);
4575 BLOCK_CHAIN (decl) = prev;
4581 /* Count the subblocks of BLOCK, and list them all into the vector VECTOR.
4582 Also clear TREE_ASM_WRITTEN in all blocks. */
4585 all_blocks (block, vector)
4592 TREE_ASM_WRITTEN (block) = 0;
4593 /* Record this block. */
4597 /* Record the subblocks, and their subblocks. */
4598 for (subblocks = BLOCK_SUBBLOCKS (block);
4599 subblocks; subblocks = BLOCK_CHAIN (subblocks))
4600 n_blocks += all_blocks (subblocks, vector ? vector + n_blocks : 0);
4605 /* Build bytecode call descriptor for function SUBR. */
4608 bc_build_calldesc (subr)
4611 tree calldesc = 0, arg;
4614 /* Build the argument description vector in reverse order. */
4615 DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
4618 for (arg = DECL_ARGUMENTS (subr); arg; arg = TREE_CHAIN (arg))
4622 calldesc = tree_cons ((tree) 0, size_in_bytes (TREE_TYPE (arg)), calldesc);
4623 calldesc = tree_cons ((tree) 0, bc_runtime_type_code (TREE_TYPE (arg)), calldesc);
4626 DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
4628 /* Prepend the function's return type. */
4629 calldesc = tree_cons ((tree) 0,
4630 size_in_bytes (TREE_TYPE (TREE_TYPE (subr))),
4633 calldesc = tree_cons ((tree) 0,
4634 bc_runtime_type_code (TREE_TYPE (TREE_TYPE (subr))),
4637 /* Prepend the arg count. */
4638 calldesc = tree_cons ((tree) 0, build_int_2 (nargs, 0), calldesc);
4640 /* Output the call description vector and get its address. */
4641 calldesc = build_nt (CONSTRUCTOR, (tree) 0, calldesc);
4642 TREE_TYPE (calldesc) = build_array_type (integer_type_node,
4643 build_index_type (build_int_2 (nargs * 2, 0)));
4645 return output_constant_def (calldesc);
4649 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
4650 and initialize static variables for generating RTL for the statements
4654 init_function_start (subr, filename, line)
4661 if (output_bytecode)
4663 this_function_decl = subr;
4664 this_function_calldesc = bc_build_calldesc (subr);
4665 local_vars_size = 0;
4667 max_stack_depth = 0;
4668 stmt_expr_depth = 0;
4672 init_stmt_for_function ();
4674 cse_not_expected = ! optimize;
4676 /* Caller save not needed yet. */
4677 caller_save_needed = 0;
4679 /* No stack slots have been made yet. */
4680 stack_slot_list = 0;
4682 /* There is no stack slot for handling nonlocal gotos. */
4683 nonlocal_goto_handler_slot = 0;
4684 nonlocal_goto_stack_level = 0;
4686 /* No labels have been declared for nonlocal use. */
4687 nonlocal_labels = 0;
4689 /* No function calls so far in this function. */
4690 function_call_count = 0;
4692 /* No parm regs have been allocated.
4693 (This is important for output_inline_function.) */
4694 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
4696 /* Initialize the RTL mechanism. */
4699 /* Initialize the queue of pending postincrement and postdecrements,
4700 and some other info in expr.c. */
4703 /* We haven't done register allocation yet. */
4706 init_const_rtx_hash_table ();
4708 current_function_name = (*decl_printable_name) (subr, &junk);
4710 /* Nonzero if this is a nested function that uses a static chain. */
4712 current_function_needs_context
4713 = (decl_function_context (current_function_decl) != 0);
4715 /* Set if a call to setjmp is seen. */
4716 current_function_calls_setjmp = 0;
4718 /* Set if a call to longjmp is seen. */
4719 current_function_calls_longjmp = 0;
4721 current_function_calls_alloca = 0;
4722 current_function_has_nonlocal_label = 0;
4723 current_function_has_nonlocal_goto = 0;
4724 current_function_contains_functions = 0;
4726 current_function_returns_pcc_struct = 0;
4727 current_function_returns_struct = 0;
4728 current_function_epilogue_delay_list = 0;
4729 current_function_uses_const_pool = 0;
4730 current_function_uses_pic_offset_table = 0;
4732 /* We have not yet needed to make a label to jump to for tail-recursion. */
4733 tail_recursion_label = 0;
4735 /* We haven't had a need to make a save area for ap yet. */
4737 arg_pointer_save_area = 0;
4739 /* No stack slots allocated yet. */
4742 /* No SAVE_EXPRs in this function yet. */
4745 /* No RTL_EXPRs in this function yet. */
4748 /* We have not allocated any temporaries yet. */
4750 temp_slot_level = 0;
4751 target_temp_slot_level = 0;
4753 /* Within function body, compute a type's size as soon it is laid out. */
4754 immediate_size_expand++;
4756 /* We haven't made any trampolines for this function yet. */
4757 trampoline_list = 0;
4759 init_pending_stack_adjust ();
4760 inhibit_defer_pop = 0;
4762 current_function_outgoing_args_size = 0;
4764 /* Initialize the insn lengths. */
4765 init_insn_lengths ();
4767 /* Prevent ever trying to delete the first instruction of a function.
4768 Also tell final how to output a linenum before the function prologue. */
4769 emit_line_note (filename, line);
4771 /* Make sure first insn is a note even if we don't want linenums.
4772 This makes sure the first insn will never be deleted.
4773 Also, final expects a note to appear there. */
4774 emit_note (NULL_PTR, NOTE_INSN_DELETED);
4776 /* Set flags used by final.c. */
4777 if (aggregate_value_p (DECL_RESULT (subr)))
4779 #ifdef PCC_STATIC_STRUCT_RETURN
4780 current_function_returns_pcc_struct = 1;
4782 current_function_returns_struct = 1;
4785 /* Warn if this value is an aggregate type,
4786 regardless of which calling convention we are using for it. */
4787 if (warn_aggregate_return
4788 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
4789 warning ("function returns an aggregate");
4791 current_function_returns_pointer
4792 = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
4794 /* Indicate that we need to distinguish between the return value of the
4795 present function and the return value of a function being called. */
4796 rtx_equal_function_value_matters = 1;
4798 /* Indicate that we have not instantiated virtual registers yet. */
4799 virtuals_instantiated = 0;
4801 /* Indicate we have no need of a frame pointer yet. */
4802 frame_pointer_needed = 0;
4804 /* By default assume not varargs. */
4805 current_function_varargs = 0;
4808 /* Indicate that the current function uses extra args
4809 not explicitly mentioned in the argument list in any fashion. */
4814 current_function_varargs = 1;
4817 /* Expand a call to __main at the beginning of a possible main function. */
4819 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
4820 #undef HAS_INIT_SECTION
4821 #define HAS_INIT_SECTION
4825 expand_main_function ()
4827 if (!output_bytecode)
4829 /* The zero below avoids a possible parse error */
4831 #if !defined (HAS_INIT_SECTION)
4832 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, NAME__MAIN), 0,
4834 #endif /* not HAS_INIT_SECTION */
4838 extern struct obstack permanent_obstack;
4840 /* Expand start of bytecode function. See comment at
4841 expand_function_start below for details. */
4844 bc_expand_function_start (subr, parms_have_cleanups)
4846 int parms_have_cleanups;
4848 char label[20], *name;
4853 if (TREE_PUBLIC (subr))
4854 bc_globalize_label (IDENTIFIER_POINTER (DECL_NAME (subr)));
4856 #ifdef DEBUG_PRINT_CODE
4857 fprintf (stderr, "\n<func %s>\n", IDENTIFIER_POINTER (DECL_NAME (subr)));
4860 for (argsz = 0, thisarg = DECL_ARGUMENTS (subr); thisarg; thisarg = TREE_CHAIN (thisarg))
4862 if (DECL_RTL (thisarg))
4863 abort (); /* Should be NULL here I think. */
4864 else if (TREE_CONSTANT (DECL_SIZE (thisarg)))
4866 DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
4867 argsz += TREE_INT_CST_LOW (DECL_SIZE (thisarg));
4871 /* Variable-sized objects are pointers to their storage. */
4872 DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
4873 argsz += POINTER_SIZE;
4877 bc_begin_function (bc_xstrdup (IDENTIFIER_POINTER (DECL_NAME (subr))));
4879 ASM_GENERATE_INTERNAL_LABEL (label, "LX", nlab);
4882 name = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
4883 this_function_callinfo = bc_gen_rtx (name, 0, (struct bc_label *) 0);
4884 this_function_bytecode =
4885 bc_emit_trampoline (BYTECODE_LABEL (this_function_callinfo));
4889 /* Expand end of bytecode function. See details the comment of
4890 expand_function_end(), below. */
4893 bc_expand_function_end ()
4897 expand_null_return ();
4899 /* Emit any fixup code. This must be done before the call to
4900 to BC_END_FUNCTION (), since that will cause the bytecode
4901 segment to be finished off and closed. */
4903 expand_fixups (NULL_RTX);
4905 ptrconsts = bc_end_function ();
4907 bc_align_const (2 /* INT_ALIGN */);
4909 /* If this changes also make sure to change bc-interp.h! */
4911 bc_emit_const_labeldef (BYTECODE_LABEL (this_function_callinfo));
4912 bc_emit_const ((char *) &max_stack_depth, sizeof max_stack_depth);
4913 bc_emit_const ((char *) &local_vars_size, sizeof local_vars_size);
4914 bc_emit_const_labelref (this_function_bytecode, 0);
4915 bc_emit_const_labelref (ptrconsts, 0);
4916 bc_emit_const_labelref (BYTECODE_LABEL (this_function_calldesc), 0);
4920 /* Start the RTL for a new function, and set variables used for
4922 SUBR is the FUNCTION_DECL node.
4923 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
4924 the function's parameters, which must be run at any return statement. */
4927 expand_function_start (subr, parms_have_cleanups)
4929 int parms_have_cleanups;
4935 if (output_bytecode)
4937 bc_expand_function_start (subr, parms_have_cleanups);
4941 /* Make sure volatile mem refs aren't considered
4942 valid operands of arithmetic insns. */
4943 init_recog_no_volatile ();
4945 /* If function gets a static chain arg, store it in the stack frame.
4946 Do this first, so it gets the first stack slot offset. */
4947 if (current_function_needs_context)
4949 last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
4951 #ifdef SMALL_REGISTER_CLASSES
4952 /* Delay copying static chain if it is not a register to avoid
4953 conflicts with regs used for parameters. */
4954 if (GET_CODE (static_chain_incoming_rtx) == REG)
4956 emit_move_insn (last_ptr, static_chain_incoming_rtx);
4959 /* If the parameters of this function need cleaning up, get a label
4960 for the beginning of the code which executes those cleanups. This must
4961 be done before doing anything with return_label. */
4962 if (parms_have_cleanups)
4963 cleanup_label = gen_label_rtx ();
4967 /* Make the label for return statements to jump to, if this machine
4968 does not have a one-instruction return and uses an epilogue,
4969 or if it returns a structure, or if it has parm cleanups. */
4971 if (cleanup_label == 0 && HAVE_return
4972 && ! current_function_returns_pcc_struct
4973 && ! (current_function_returns_struct && ! optimize))
4976 return_label = gen_label_rtx ();
4978 return_label = gen_label_rtx ();
4981 /* Initialize rtx used to return the value. */
4982 /* Do this before assign_parms so that we copy the struct value address
4983 before any library calls that assign parms might generate. */
4985 /* Decide whether to return the value in memory or in a register. */
4986 if (aggregate_value_p (DECL_RESULT (subr)))
4988 /* Returning something that won't go in a register. */
4989 register rtx value_address = 0;
4991 #ifdef PCC_STATIC_STRUCT_RETURN
4992 if (current_function_returns_pcc_struct)
4994 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
4995 value_address = assemble_static_space (size);
5000 /* Expect to be passed the address of a place to store the value.
5001 If it is passed as an argument, assign_parms will take care of
5003 if (struct_value_incoming_rtx)
5005 value_address = gen_reg_rtx (Pmode);
5006 emit_move_insn (value_address, struct_value_incoming_rtx);
5011 DECL_RTL (DECL_RESULT (subr))
5012 = gen_rtx (MEM, DECL_MODE (DECL_RESULT (subr)), value_address);
5013 MEM_IN_STRUCT_P (DECL_RTL (DECL_RESULT (subr)))
5014 = AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
5017 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
5018 /* If return mode is void, this decl rtl should not be used. */
5019 DECL_RTL (DECL_RESULT (subr)) = 0;
5020 else if (parms_have_cleanups)
5022 /* If function will end with cleanup code for parms,
5023 compute the return values into a pseudo reg,
5024 which we will copy into the true return register
5025 after the cleanups are done. */
5027 enum machine_mode mode = DECL_MODE (DECL_RESULT (subr));
5029 #ifdef PROMOTE_FUNCTION_RETURN
5030 tree type = TREE_TYPE (DECL_RESULT (subr));
5031 int unsignedp = TREE_UNSIGNED (type);
5033 mode = promote_mode (type, mode, &unsignedp, 1);
5036 DECL_RTL (DECL_RESULT (subr)) = gen_reg_rtx (mode);
5039 /* Scalar, returned in a register. */
5041 #ifdef FUNCTION_OUTGOING_VALUE
5042 DECL_RTL (DECL_RESULT (subr))
5043 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
5045 DECL_RTL (DECL_RESULT (subr))
5046 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
5049 /* Mark this reg as the function's return value. */
5050 if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG)
5052 REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1;
5053 /* Needed because we may need to move this to memory
5054 in case it's a named return value whose address is taken. */
5055 DECL_REGISTER (DECL_RESULT (subr)) = 1;
5059 /* Initialize rtx for parameters and local variables.
5060 In some cases this requires emitting insns. */
5062 assign_parms (subr, 0);
5064 #ifdef SMALL_REGISTER_CLASSES
5065 /* Copy the static chain now if it wasn't a register. The delay is to
5066 avoid conflicts with the parameter passing registers. */
5068 if (current_function_needs_context)
5069 if (GET_CODE (static_chain_incoming_rtx) != REG)
5070 emit_move_insn (last_ptr, static_chain_incoming_rtx);
5073 /* The following was moved from init_function_start.
5074 The move is supposed to make sdb output more accurate. */
5075 /* Indicate the beginning of the function body,
5076 as opposed to parm setup. */
5077 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_BEG);
5079 /* If doing stupid allocation, mark parms as born here. */
5081 if (GET_CODE (get_last_insn ()) != NOTE)
5082 emit_note (NULL_PTR, NOTE_INSN_DELETED);
5083 parm_birth_insn = get_last_insn ();
5087 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
5088 use_variable (regno_reg_rtx[i]);
5090 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
5091 use_variable (current_function_internal_arg_pointer);
5094 /* Fetch static chain values for containing functions. */
5095 tem = decl_function_context (current_function_decl);
5096 /* If not doing stupid register allocation copy the static chain
5097 pointer into a psuedo. If we have small register classes, copy the
5098 value from memory if static_chain_incoming_rtx is a REG. If we do
5099 stupid register allocation, we use the stack address generated above. */
5100 if (tem && ! obey_regdecls)
5102 #ifdef SMALL_REGISTER_CLASSES
5103 /* If the static chain originally came in a register, put it back
5104 there, then move it out in the next insn. The reason for
5105 this peculiar code is to satisfy function integration. */
5106 if (GET_CODE (static_chain_incoming_rtx) == REG)
5107 emit_move_insn (static_chain_incoming_rtx, last_ptr);
5110 last_ptr = copy_to_reg (static_chain_incoming_rtx);
5113 context_display = 0;
5116 tree rtlexp = make_node (RTL_EXPR);
5118 RTL_EXPR_RTL (rtlexp) = last_ptr;
5119 context_display = tree_cons (tem, rtlexp, context_display);
5120 tem = decl_function_context (tem);
5123 /* Chain thru stack frames, assuming pointer to next lexical frame
5124 is found at the place we always store it. */
5125 #ifdef FRAME_GROWS_DOWNWARD
5126 last_ptr = plus_constant (last_ptr, - GET_MODE_SIZE (Pmode));
5128 last_ptr = copy_to_reg (gen_rtx (MEM, Pmode,
5129 memory_address (Pmode, last_ptr)));
5131 /* If we are not optimizing, ensure that we know that this
5132 piece of context is live over the entire function. */
5134 save_expr_regs = gen_rtx (EXPR_LIST, VOIDmode, last_ptr,
5138 /* After the display initializations is where the tail-recursion label
5139 should go, if we end up needing one. Ensure we have a NOTE here
5140 since some things (like trampolines) get placed before this. */
5141 tail_recursion_reentry = emit_note (NULL_PTR, NOTE_INSN_DELETED);
5143 /* Evaluate now the sizes of any types declared among the arguments. */
5144 for (tem = nreverse (get_pending_sizes ()); tem; tem = TREE_CHAIN (tem))
5145 expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode, 0);
5147 /* Make sure there is a line number after the function entry setup code. */
5148 force_next_line_note ();
5151 /* Generate RTL for the end of the current function.
5152 FILENAME and LINE are the current position in the source file.
5154 It is up to language-specific callers to do cleanups for parameters--
5155 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */
5158 expand_function_end (filename, line, end_bindings)
5166 static rtx initial_trampoline;
5168 if (output_bytecode)
5170 bc_expand_function_end ();
5174 #ifdef NON_SAVING_SETJMP
5175 /* Don't put any variables in registers if we call setjmp
5176 on a machine that fails to restore the registers. */
5177 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
5179 if (DECL_INITIAL (current_function_decl) != error_mark_node)
5180 setjmp_protect (DECL_INITIAL (current_function_decl));
5182 setjmp_protect_args ();
5186 /* Save the argument pointer if a save area was made for it. */
5187 if (arg_pointer_save_area)
5189 rtx x = gen_move_insn (arg_pointer_save_area, virtual_incoming_args_rtx);
5190 emit_insn_before (x, tail_recursion_reentry);
5193 /* Initialize any trampolines required by this function. */
5194 for (link = trampoline_list; link; link = TREE_CHAIN (link))
5196 tree function = TREE_PURPOSE (link);
5197 rtx context = lookup_static_chain (function);
5198 rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
5201 /* First make sure this compilation has a template for
5202 initializing trampolines. */
5203 if (initial_trampoline == 0)
5205 end_temporary_allocation ();
5207 = gen_rtx (MEM, BLKmode, assemble_trampoline_template ());
5208 resume_temporary_allocation ();
5211 /* Generate insns to initialize the trampoline. */
5213 tramp = change_address (initial_trampoline, BLKmode,
5214 round_trampoline_addr (XEXP (tramp, 0)));
5215 emit_block_move (tramp, initial_trampoline, GEN_INT (TRAMPOLINE_SIZE),
5216 FUNCTION_BOUNDARY / BITS_PER_UNIT);
5217 INITIALIZE_TRAMPOLINE (XEXP (tramp, 0),
5218 XEXP (DECL_RTL (function), 0), context);
5222 /* Put those insns at entry to the containing function (this one). */
5223 emit_insns_before (seq, tail_recursion_reentry);
5226 #if 0 /* I think unused parms are legitimate enough. */
5227 /* Warn about unused parms. */
5232 for (decl = DECL_ARGUMENTS (current_function_decl);
5233 decl; decl = TREE_CHAIN (decl))
5234 if (! TREE_USED (decl) && TREE_CODE (decl) == VAR_DECL)
5235 warning_with_decl (decl, "unused parameter `%s'");
5239 /* Delete handlers for nonlocal gotos if nothing uses them. */
5240 if (nonlocal_goto_handler_slot != 0 && !current_function_has_nonlocal_label)
5243 /* End any sequences that failed to be closed due to syntax errors. */
5244 while (in_sequence_p ())
5247 /* Outside function body, can't compute type's actual size
5248 until next function's body starts. */
5249 immediate_size_expand--;
5251 /* If doing stupid register allocation,
5252 mark register parms as dying here. */
5257 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
5258 use_variable (regno_reg_rtx[i]);
5260 /* Likewise for the regs of all the SAVE_EXPRs in the function. */
5262 for (tem = save_expr_regs; tem; tem = XEXP (tem, 1))
5264 use_variable (XEXP (tem, 0));
5265 use_variable_after (XEXP (tem, 0), parm_birth_insn);
5268 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
5269 use_variable (current_function_internal_arg_pointer);
5272 clear_pending_stack_adjust ();
5273 do_pending_stack_adjust ();
5275 /* Mark the end of the function body.
5276 If control reaches this insn, the function can drop through
5277 without returning a value. */
5278 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_END);
5280 /* Output a linenumber for the end of the function.
5281 SDB depends on this. */
5282 emit_line_note_force (filename, line);
5284 /* Output the label for the actual return from the function,
5285 if one is expected. This happens either because a function epilogue
5286 is used instead of a return instruction, or because a return was done
5287 with a goto in order to run local cleanups, or because of pcc-style
5288 structure returning. */
5291 emit_label (return_label);
5293 /* C++ uses this. */
5295 expand_end_bindings (0, 0, 0);
5297 /* If we had calls to alloca, and this machine needs
5298 an accurate stack pointer to exit the function,
5299 insert some code to save and restore the stack pointer. */
5300 #ifdef EXIT_IGNORE_STACK
5301 if (! EXIT_IGNORE_STACK)
5303 if (current_function_calls_alloca)
5307 emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
5308 emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
5311 /* If scalar return value was computed in a pseudo-reg,
5312 copy that to the hard return register. */
5313 if (DECL_RTL (DECL_RESULT (current_function_decl)) != 0
5314 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG
5315 && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl)))
5316 >= FIRST_PSEUDO_REGISTER))
5318 rtx real_decl_result;
5320 #ifdef FUNCTION_OUTGOING_VALUE
5322 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
5323 current_function_decl);
5326 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
5327 current_function_decl);
5329 REG_FUNCTION_VALUE_P (real_decl_result) = 1;
5330 emit_move_insn (real_decl_result,
5331 DECL_RTL (DECL_RESULT (current_function_decl)));
5332 emit_insn (gen_rtx (USE, VOIDmode, real_decl_result));
5335 /* If returning a structure, arrange to return the address of the value
5336 in a place where debuggers expect to find it.
5338 If returning a structure PCC style,
5339 the caller also depends on this value.
5340 And current_function_returns_pcc_struct is not necessarily set. */
5341 if (current_function_returns_struct
5342 || current_function_returns_pcc_struct)
5344 rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
5345 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
5346 #ifdef FUNCTION_OUTGOING_VALUE
5348 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
5349 current_function_decl);
5352 = FUNCTION_VALUE (build_pointer_type (type),
5353 current_function_decl);
5356 /* Mark this as a function return value so integrate will delete the
5357 assignment and USE below when inlining this function. */
5358 REG_FUNCTION_VALUE_P (outgoing) = 1;
5360 emit_move_insn (outgoing, value_address);
5361 use_variable (outgoing);
5364 /* Output a return insn if we are using one.
5365 Otherwise, let the rtl chain end here, to drop through
5366 into the epilogue. */
5371 emit_jump_insn (gen_return ());
5376 /* Fix up any gotos that jumped out to the outermost
5377 binding level of the function.
5378 Must follow emitting RETURN_LABEL. */
5380 /* If you have any cleanups to do at this point,
5381 and they need to create temporary variables,
5382 then you will lose. */
5383 expand_fixups (get_insns ());
5386 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
5388 static int *prologue;
5389 static int *epilogue;
5391 /* Create an array that records the INSN_UIDs of INSNS (either a sequence
5392 or a single insn). */
5395 record_insns (insns)
5400 if (GET_CODE (insns) == SEQUENCE)
5402 int len = XVECLEN (insns, 0);
5403 vec = (int *) oballoc ((len + 1) * sizeof (int));
5406 vec[len] = INSN_UID (XVECEXP (insns, 0, len));
5410 vec = (int *) oballoc (2 * sizeof (int));
5411 vec[0] = INSN_UID (insns);
5417 /* Determine how many INSN_UIDs in VEC are part of INSN. */
5420 contains (insn, vec)
5426 if (GET_CODE (insn) == INSN
5427 && GET_CODE (PATTERN (insn)) == SEQUENCE)
5430 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
5431 for (j = 0; vec[j]; j++)
5432 if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == vec[j])
5438 for (j = 0; vec[j]; j++)
5439 if (INSN_UID (insn) == vec[j])
5445 /* Generate the prologe and epilogue RTL if the machine supports it. Thread
5446 this into place with notes indicating where the prologue ends and where
5447 the epilogue begins. Update the basic block information when possible. */
5450 thread_prologue_and_epilogue_insns (f)
5453 #ifdef HAVE_prologue
5456 rtx head, seq, insn;
5458 /* The first insn (a NOTE_INSN_DELETED) is followed by zero or more
5459 prologue insns and a NOTE_INSN_PROLOGUE_END. */
5460 emit_note_after (NOTE_INSN_PROLOGUE_END, f);
5461 seq = gen_prologue ();
5462 head = emit_insn_after (seq, f);
5464 /* Include the new prologue insns in the first block. Ignore them
5465 if they form a basic block unto themselves. */
5466 if (basic_block_head && n_basic_blocks
5467 && GET_CODE (basic_block_head[0]) != CODE_LABEL)
5468 basic_block_head[0] = NEXT_INSN (f);
5470 /* Retain a map of the prologue insns. */
5471 prologue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : head);
5477 #ifdef HAVE_epilogue
5480 rtx insn = get_last_insn ();
5481 rtx prev = prev_nonnote_insn (insn);
5483 /* If we end with a BARRIER, we don't need an epilogue. */
5484 if (! (prev && GET_CODE (prev) == BARRIER))
5490 /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, the
5491 epilogue insns, the USE insns at the end of a function,
5492 the jump insn that returns, and then a BARRIER. */
5494 /* Move the USE insns at the end of a function onto a list. */
5496 && GET_CODE (prev) == INSN
5497 && GET_CODE (PATTERN (prev)) == USE)
5500 prev = prev_nonnote_insn (prev);
5502 NEXT_INSN (PREV_INSN (tem)) = NEXT_INSN (tem);
5503 PREV_INSN (NEXT_INSN (tem)) = PREV_INSN (tem);
5506 NEXT_INSN (tem) = first_use;
5507 PREV_INSN (first_use) = tem;
5514 emit_barrier_after (insn);
5516 seq = gen_epilogue ();
5517 tail = emit_jump_insn_after (seq, insn);
5519 /* Insert the USE insns immediately before the return insn, which
5520 must be the first instruction before the final barrier. */
5523 tem = prev_nonnote_insn (get_last_insn ());
5524 NEXT_INSN (PREV_INSN (tem)) = first_use;
5525 PREV_INSN (first_use) = PREV_INSN (tem);
5526 PREV_INSN (tem) = last_use;
5527 NEXT_INSN (last_use) = tem;
5530 emit_note_after (NOTE_INSN_EPILOGUE_BEG, insn);
5532 /* Include the new epilogue insns in the last block. Ignore
5533 them if they form a basic block unto themselves. */
5534 if (basic_block_end && n_basic_blocks
5535 && GET_CODE (basic_block_end[n_basic_blocks - 1]) != JUMP_INSN)
5536 basic_block_end[n_basic_blocks - 1] = tail;
5538 /* Retain a map of the epilogue insns. */
5539 epilogue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : tail);
5547 /* Reposition the prologue-end and epilogue-begin notes after instruction
5548 scheduling and delayed branch scheduling. */
5551 reposition_prologue_and_epilogue_notes (f)
5554 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
5555 /* Reposition the prologue and epilogue notes. */
5563 register rtx insn, note = 0;
5565 /* Scan from the beginning until we reach the last prologue insn.
5566 We apparently can't depend on basic_block_{head,end} after
5568 for (len = 0; prologue[len]; len++)
5570 for (insn = f; len && insn; insn = NEXT_INSN (insn))
5572 if (GET_CODE (insn) == NOTE)
5574 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
5577 else if ((len -= contains (insn, prologue)) == 0)
5579 /* Find the prologue-end note if we haven't already, and
5580 move it to just after the last prologue insn. */
5583 for (note = insn; note = NEXT_INSN (note);)
5584 if (GET_CODE (note) == NOTE
5585 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
5588 next = NEXT_INSN (note);
5589 prev = PREV_INSN (note);
5591 NEXT_INSN (prev) = next;
5593 PREV_INSN (next) = prev;
5594 add_insn_after (note, insn);
5601 register rtx insn, note = 0;
5603 /* Scan from the end until we reach the first epilogue insn.
5604 We apparently can't depend on basic_block_{head,end} after
5606 for (len = 0; epilogue[len]; len++)
5608 for (insn = get_last_insn (); len && insn; insn = PREV_INSN (insn))
5610 if (GET_CODE (insn) == NOTE)
5612 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
5615 else if ((len -= contains (insn, epilogue)) == 0)
5617 /* Find the epilogue-begin note if we haven't already, and
5618 move it to just before the first epilogue insn. */
5621 for (note = insn; note = PREV_INSN (note);)
5622 if (GET_CODE (note) == NOTE
5623 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
5626 next = NEXT_INSN (note);
5627 prev = PREV_INSN (note);
5629 NEXT_INSN (prev) = next;
5631 PREV_INSN (next) = prev;
5632 add_insn_after (note, PREV_INSN (insn));
5637 #endif /* HAVE_prologue or HAVE_epilogue */