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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* This file handles the generation of rtl code from tree structure
23 at the level of the function as a whole.
24 It creates the rtl expressions for parameters and auto variables
25 and has full responsibility for allocating stack slots.
27 `expand_function_start' is called at the beginning of a function,
28 before the function body is parsed, and `expand_function_end' is
29 called after parsing the body.
31 Call `assign_stack_local' to allocate a stack slot for a local variable.
32 This is usually done during the RTL generation for the function body,
33 but it can also be done in the reload pass when a pseudo-register does
34 not get a hard register.
36 Call `put_var_into_stack' when you learn, belatedly, that a variable
37 previously given a pseudo-register must in fact go in the stack.
38 This function changes the DECL_RTL to be a stack slot instead of a reg
39 then scans all the RTL instructions so far generated to correct them. */
49 #include "insn-flags.h"
51 #include "insn-codes.h"
53 #include "hard-reg-set.h"
54 #include "insn-config.h"
57 #include "basic-block.h"
61 /* Some systems use __main in a way incompatible with its use in gcc, in these
62 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
63 give the same symbol without quotes for an alternative entry point. You
64 must define both, or neither. */
66 #define NAME__MAIN "__main"
67 #define SYMBOL__MAIN __main
70 /* Round a value to the lowest integer less than it that is a multiple of
71 the required alignment. Avoid using division in case the value is
72 negative. Assume the alignment is a power of two. */
73 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
75 /* Similar, but round to the next highest integer that meets the
77 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
79 /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp
80 during rtl generation. If they are different register numbers, this is
81 always true. It may also be true if
82 FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl
83 generation. See fix_lexical_addr for details. */
85 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
86 #define NEED_SEPARATE_AP
89 /* Number of bytes of args popped by function being compiled on its return.
90 Zero if no bytes are to be popped.
91 May affect compilation of return insn or of function epilogue. */
93 int current_function_pops_args;
95 /* Nonzero if function being compiled needs to be given an address
96 where the value should be stored. */
98 int current_function_returns_struct;
100 /* Nonzero if function being compiled needs to
101 return the address of where it has put a structure value. */
103 int current_function_returns_pcc_struct;
105 /* Nonzero if function being compiled needs to be passed a static chain. */
107 int current_function_needs_context;
109 /* Nonzero if function being compiled can call setjmp. */
111 int current_function_calls_setjmp;
113 /* Nonzero if function being compiled can call longjmp. */
115 int current_function_calls_longjmp;
117 /* Nonzero if function being compiled receives nonlocal gotos
118 from nested functions. */
120 int current_function_has_nonlocal_label;
122 /* Nonzero if function being compiled has nonlocal gotos to parent
125 int current_function_has_nonlocal_goto;
127 /* Nonzero if function being compiled contains nested functions. */
129 int current_function_contains_functions;
131 /* Nonzero if function being compiled can call alloca,
132 either as a subroutine or builtin. */
134 int current_function_calls_alloca;
136 /* Nonzero if the current function returns a pointer type */
138 int current_function_returns_pointer;
140 /* If some insns can be deferred to the delay slots of the epilogue, the
141 delay list for them is recorded here. */
143 rtx current_function_epilogue_delay_list;
145 /* If function's args have a fixed size, this is that size, in bytes.
147 May affect compilation of return insn or of function epilogue. */
149 int current_function_args_size;
151 /* # bytes the prologue should push and pretend that the caller pushed them.
152 The prologue must do this, but only if parms can be passed in registers. */
154 int current_function_pretend_args_size;
156 /* # of bytes of outgoing arguments. If ACCUMULATE_OUTGOING_ARGS is
157 defined, the needed space is pushed by the prologue. */
159 int current_function_outgoing_args_size;
161 /* This is the offset from the arg pointer to the place where the first
162 anonymous arg can be found, if there is one. */
164 rtx current_function_arg_offset_rtx;
166 /* Nonzero if current function uses varargs.h or equivalent.
167 Zero for functions that use stdarg.h. */
169 int current_function_varargs;
171 /* Nonzero if current function uses stdarg.h or equivalent.
172 Zero for functions that use varargs.h. */
174 int current_function_stdarg;
176 /* Quantities of various kinds of registers
177 used for the current function's args. */
179 CUMULATIVE_ARGS current_function_args_info;
181 /* Name of function now being compiled. */
183 char *current_function_name;
185 /* If non-zero, an RTL expression for that location at which the current
186 function returns its result. Always equal to
187 DECL_RTL (DECL_RESULT (current_function_decl)), but provided
188 independently of the tree structures. */
190 rtx current_function_return_rtx;
192 /* Nonzero if the current function uses the constant pool. */
194 int current_function_uses_const_pool;
196 /* Nonzero if the current function uses pic_offset_table_rtx. */
197 int current_function_uses_pic_offset_table;
199 /* The arg pointer hard register, or the pseudo into which it was copied. */
200 rtx current_function_internal_arg_pointer;
202 /* The FUNCTION_DECL for an inline function currently being expanded. */
203 tree inline_function_decl;
205 /* Number of function calls seen so far in current function. */
207 int function_call_count;
209 /* List (chain of TREE_LIST) of LABEL_DECLs for all nonlocal labels
210 (labels to which there can be nonlocal gotos from nested functions)
213 tree nonlocal_labels;
215 /* RTX for stack slot that holds the current handler for nonlocal gotos.
216 Zero when function does not have nonlocal labels. */
218 rtx nonlocal_goto_handler_slot;
220 /* RTX for stack slot that holds the stack pointer value to restore
222 Zero when function does not have nonlocal labels. */
224 rtx nonlocal_goto_stack_level;
226 /* Label that will go on parm cleanup code, if any.
227 Jumping to this label runs cleanup code for parameters, if
228 such code must be run. Following this code is the logical return label. */
232 /* Label that will go on function epilogue.
233 Jumping to this label serves as a "return" instruction
234 on machines which require execution of the epilogue on all returns. */
238 /* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs.
239 So we can mark them all live at the end of the function, if nonopt. */
242 /* List (chain of EXPR_LISTs) of all stack slots in this function.
243 Made for the sake of unshare_all_rtl. */
246 /* Chain of all RTL_EXPRs that have insns in them. */
249 /* Label to jump back to for tail recursion, or 0 if we have
250 not yet needed one for this function. */
251 rtx tail_recursion_label;
253 /* Place after which to insert the tail_recursion_label if we need one. */
254 rtx tail_recursion_reentry;
256 /* Location at which to save the argument pointer if it will need to be
257 referenced. There are two cases where this is done: if nonlocal gotos
258 exist, or if vars stored at an offset from the argument pointer will be
259 needed by inner routines. */
261 rtx arg_pointer_save_area;
263 /* Offset to end of allocated area of stack frame.
264 If stack grows down, this is the address of the last stack slot allocated.
265 If stack grows up, this is the address for the next slot. */
268 /* List (chain of TREE_LISTs) of static chains for containing functions.
269 Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
270 in an RTL_EXPR in the TREE_VALUE. */
271 static tree context_display;
273 /* List (chain of TREE_LISTs) of trampolines for nested functions.
274 The trampoline sets up the static chain and jumps to the function.
275 We supply the trampoline's address when the function's address is requested.
277 Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
278 in an RTL_EXPR in the TREE_VALUE. */
279 static tree trampoline_list;
281 /* Insn after which register parms and SAVE_EXPRs are born, if nonopt. */
282 static rtx parm_birth_insn;
285 /* Nonzero if a stack slot has been generated whose address is not
286 actually valid. It means that the generated rtl must all be scanned
287 to detect and correct the invalid addresses where they occur. */
288 static int invalid_stack_slot;
291 /* Last insn of those whose job was to put parms into their nominal homes. */
292 static rtx last_parm_insn;
294 /* 1 + last pseudo register number used for loading a copy
295 of a parameter of this function. */
296 static int max_parm_reg;
298 /* Vector indexed by REGNO, containing location on stack in which
299 to put the parm which is nominally in pseudo register REGNO,
300 if we discover that that parm must go in the stack. */
301 static rtx *parm_reg_stack_loc;
303 #if 0 /* Turned off because 0 seems to work just as well. */
304 /* Cleanup lists are required for binding levels regardless of whether
305 that binding level has cleanups or not. This node serves as the
306 cleanup list whenever an empty list is required. */
307 static tree empty_cleanup_list;
310 /* Nonzero once virtual register instantiation has been done.
311 assign_stack_local uses frame_pointer_rtx when this is nonzero. */
312 static int virtuals_instantiated;
314 /* These variables hold pointers to functions to
315 save and restore machine-specific data,
316 in push_function_context and pop_function_context. */
317 void (*save_machine_status) ();
318 void (*restore_machine_status) ();
320 /* Nonzero if we need to distinguish between the return value of this function
321 and the return value of a function called by this function. This helps
324 extern int rtx_equal_function_value_matters;
325 extern tree sequence_rtl_expr;
326 extern tree bc_runtime_type_code ();
327 extern rtx bc_build_calldesc ();
328 extern char *bc_emit_trampoline ();
329 extern char *bc_end_function ();
331 /* In order to evaluate some expressions, such as function calls returning
332 structures in memory, we need to temporarily allocate stack locations.
333 We record each allocated temporary in the following structure.
335 Associated with each temporary slot is a nesting level. When we pop up
336 one level, all temporaries associated with the previous level are freed.
337 Normally, all temporaries are freed after the execution of the statement
338 in which they were created. However, if we are inside a ({...}) grouping,
339 the result may be in a temporary and hence must be preserved. If the
340 result could be in a temporary, we preserve it if we can determine which
341 one it is in. If we cannot determine which temporary may contain the
342 result, all temporaries are preserved. A temporary is preserved by
343 pretending it was allocated at the previous nesting level.
345 Automatic variables are also assigned temporary slots, at the nesting
346 level where they are defined. They are marked a "kept" so that
347 free_temp_slots will not free them. */
351 /* Points to next temporary slot. */
352 struct temp_slot *next;
353 /* The rtx to used to reference the slot. */
355 /* The rtx used to represent the address if not the address of the
356 slot above. May be an EXPR_LIST if multiple addresses exist. */
358 /* The size, in units, of the slot. */
360 /* The value of `sequence_rtl_expr' when this temporary is allocated. */
362 /* Non-zero if this temporary is currently in use. */
364 /* Non-zero if this temporary has its address taken. */
366 /* Nesting level at which this slot is being used. */
368 /* Non-zero if this should survive a call to free_temp_slots. */
370 /* The offset of the slot from the frame_pointer, including extra space
371 for alignment. This info is for combine_temp_slots. */
373 /* The size of the slot, including extra space for alignment. This
374 info is for combine_temp_slots. */
378 /* List of all temporaries allocated, both available and in use. */
380 struct temp_slot *temp_slots;
382 /* Current nesting level for temporaries. */
386 /* The FUNCTION_DECL node for the current function. */
387 static tree this_function_decl;
389 /* Callinfo pointer for the current function. */
390 static rtx this_function_callinfo;
392 /* The label in the bytecode file of this function's actual bytecode.
394 static char *this_function_bytecode;
396 /* The call description vector for the current function. */
397 static rtx this_function_calldesc;
399 /* Size of the local variables allocated for the current function. */
402 /* Current depth of the bytecode evaluation stack. */
405 /* Maximum depth of the evaluation stack in this function. */
408 /* Current depth in statement expressions. */
409 static int stmt_expr_depth;
411 /* This structure is used to record MEMs or pseudos used to replace VAR, any
412 SUBREGs of VAR, and any MEMs containing VAR as an address. We need to
413 maintain this list in case two operands of an insn were required to match;
414 in that case we must ensure we use the same replacement. */
416 struct fixup_replacement
420 struct fixup_replacement *next;
423 /* Forward declarations. */
425 static struct temp_slot *find_temp_slot_from_address PROTO((rtx));
426 static void put_reg_into_stack PROTO((struct function *, rtx, tree,
427 enum machine_mode, enum machine_mode,
429 static void fixup_var_refs PROTO((rtx, enum machine_mode, int));
430 static struct fixup_replacement
431 *find_fixup_replacement PROTO((struct fixup_replacement **, rtx));
432 static void fixup_var_refs_insns PROTO((rtx, enum machine_mode, int,
434 static void fixup_var_refs_1 PROTO((rtx, enum machine_mode, rtx *, rtx,
435 struct fixup_replacement **));
436 static rtx fixup_memory_subreg PROTO((rtx, rtx, int));
437 static rtx walk_fixup_memory_subreg PROTO((rtx, rtx, int));
438 static rtx fixup_stack_1 PROTO((rtx, rtx));
439 static void optimize_bit_field PROTO((rtx, rtx, rtx *));
440 static void instantiate_decls PROTO((tree, int));
441 static void instantiate_decls_1 PROTO((tree, int));
442 static void instantiate_decl PROTO((rtx, int, int));
443 static int instantiate_virtual_regs_1 PROTO((rtx *, rtx, int));
444 static void delete_handlers PROTO((void));
445 static void pad_to_arg_alignment PROTO((struct args_size *, int));
446 static void pad_below PROTO((struct args_size *, enum machine_mode,
448 static tree round_down PROTO((tree, int));
449 static rtx round_trampoline_addr PROTO((rtx));
450 static tree blocks_nreverse PROTO((tree));
451 static int all_blocks PROTO((tree, tree *));
452 static int *record_insns PROTO((rtx));
453 static int contains PROTO((rtx, int *));
455 /* Pointer to chain of `struct function' for containing functions. */
456 struct function *outer_function_chain;
458 /* Given a function decl for a containing function,
459 return the `struct function' for it. */
462 find_function_data (decl)
466 for (p = outer_function_chain; p; p = p->next)
472 /* Save the current context for compilation of a nested function.
473 This is called from language-specific code.
474 The caller is responsible for saving any language-specific status,
475 since this function knows only about language-independent variables. */
478 push_function_context_to (context)
481 struct function *p = (struct function *) xmalloc (sizeof (struct function));
483 p->next = outer_function_chain;
484 outer_function_chain = p;
486 p->name = current_function_name;
487 p->decl = current_function_decl;
488 p->pops_args = current_function_pops_args;
489 p->returns_struct = current_function_returns_struct;
490 p->returns_pcc_struct = current_function_returns_pcc_struct;
491 p->needs_context = current_function_needs_context;
492 p->calls_setjmp = current_function_calls_setjmp;
493 p->calls_longjmp = current_function_calls_longjmp;
494 p->calls_alloca = current_function_calls_alloca;
495 p->has_nonlocal_label = current_function_has_nonlocal_label;
496 p->has_nonlocal_goto = current_function_has_nonlocal_goto;
497 p->contains_functions = current_function_contains_functions;
498 p->args_size = current_function_args_size;
499 p->pretend_args_size = current_function_pretend_args_size;
500 p->arg_offset_rtx = current_function_arg_offset_rtx;
501 p->varargs = current_function_varargs;
502 p->stdarg = current_function_stdarg;
503 p->uses_const_pool = current_function_uses_const_pool;
504 p->uses_pic_offset_table = current_function_uses_pic_offset_table;
505 p->internal_arg_pointer = current_function_internal_arg_pointer;
506 p->max_parm_reg = max_parm_reg;
507 p->parm_reg_stack_loc = parm_reg_stack_loc;
508 p->outgoing_args_size = current_function_outgoing_args_size;
509 p->return_rtx = current_function_return_rtx;
510 p->nonlocal_goto_handler_slot = nonlocal_goto_handler_slot;
511 p->nonlocal_goto_stack_level = nonlocal_goto_stack_level;
512 p->nonlocal_labels = nonlocal_labels;
513 p->cleanup_label = cleanup_label;
514 p->return_label = return_label;
515 p->save_expr_regs = save_expr_regs;
516 p->stack_slot_list = stack_slot_list;
517 p->parm_birth_insn = parm_birth_insn;
518 p->frame_offset = frame_offset;
519 p->tail_recursion_label = tail_recursion_label;
520 p->tail_recursion_reentry = tail_recursion_reentry;
521 p->arg_pointer_save_area = arg_pointer_save_area;
522 p->rtl_expr_chain = rtl_expr_chain;
523 p->last_parm_insn = last_parm_insn;
524 p->context_display = context_display;
525 p->trampoline_list = trampoline_list;
526 p->function_call_count = function_call_count;
527 p->temp_slots = temp_slots;
528 p->temp_slot_level = temp_slot_level;
529 p->fixup_var_refs_queue = 0;
530 p->epilogue_delay_list = current_function_epilogue_delay_list;
532 save_tree_status (p, context);
533 save_storage_status (p);
534 save_emit_status (p);
536 save_expr_status (p);
537 save_stmt_status (p);
538 save_varasm_status (p);
540 if (save_machine_status)
541 (*save_machine_status) (p);
545 push_function_context ()
547 push_function_context_to (current_function_decl);
550 /* Restore the last saved context, at the end of a nested function.
551 This function is called from language-specific code. */
554 pop_function_context_from (context)
557 struct function *p = outer_function_chain;
559 outer_function_chain = p->next;
561 current_function_contains_functions
562 = p->contains_functions || p->inline_obstacks
563 || context == current_function_decl;
564 current_function_name = p->name;
565 current_function_decl = p->decl;
566 current_function_pops_args = p->pops_args;
567 current_function_returns_struct = p->returns_struct;
568 current_function_returns_pcc_struct = p->returns_pcc_struct;
569 current_function_needs_context = p->needs_context;
570 current_function_calls_setjmp = p->calls_setjmp;
571 current_function_calls_longjmp = p->calls_longjmp;
572 current_function_calls_alloca = p->calls_alloca;
573 current_function_has_nonlocal_label = p->has_nonlocal_label;
574 current_function_has_nonlocal_goto = p->has_nonlocal_goto;
575 current_function_args_size = p->args_size;
576 current_function_pretend_args_size = p->pretend_args_size;
577 current_function_arg_offset_rtx = p->arg_offset_rtx;
578 current_function_varargs = p->varargs;
579 current_function_stdarg = p->stdarg;
580 current_function_uses_const_pool = p->uses_const_pool;
581 current_function_uses_pic_offset_table = p->uses_pic_offset_table;
582 current_function_internal_arg_pointer = p->internal_arg_pointer;
583 max_parm_reg = p->max_parm_reg;
584 parm_reg_stack_loc = p->parm_reg_stack_loc;
585 current_function_outgoing_args_size = p->outgoing_args_size;
586 current_function_return_rtx = p->return_rtx;
587 nonlocal_goto_handler_slot = p->nonlocal_goto_handler_slot;
588 nonlocal_goto_stack_level = p->nonlocal_goto_stack_level;
589 nonlocal_labels = p->nonlocal_labels;
590 cleanup_label = p->cleanup_label;
591 return_label = p->return_label;
592 save_expr_regs = p->save_expr_regs;
593 stack_slot_list = p->stack_slot_list;
594 parm_birth_insn = p->parm_birth_insn;
595 frame_offset = p->frame_offset;
596 tail_recursion_label = p->tail_recursion_label;
597 tail_recursion_reentry = p->tail_recursion_reentry;
598 arg_pointer_save_area = p->arg_pointer_save_area;
599 rtl_expr_chain = p->rtl_expr_chain;
600 last_parm_insn = p->last_parm_insn;
601 context_display = p->context_display;
602 trampoline_list = p->trampoline_list;
603 function_call_count = p->function_call_count;
604 temp_slots = p->temp_slots;
605 temp_slot_level = p->temp_slot_level;
606 current_function_epilogue_delay_list = p->epilogue_delay_list;
609 restore_tree_status (p);
610 restore_storage_status (p);
611 restore_expr_status (p);
612 restore_emit_status (p);
613 restore_stmt_status (p);
614 restore_varasm_status (p);
616 if (restore_machine_status)
617 (*restore_machine_status) (p);
619 /* Finish doing put_var_into_stack for any of our variables
620 which became addressable during the nested function. */
622 struct var_refs_queue *queue = p->fixup_var_refs_queue;
623 for (; queue; queue = queue->next)
624 fixup_var_refs (queue->modified, queue->promoted_mode, queue->unsignedp);
629 /* Reset variables that have known state during rtx generation. */
630 rtx_equal_function_value_matters = 1;
631 virtuals_instantiated = 0;
634 void pop_function_context ()
636 pop_function_context_from (current_function_decl);
639 /* Allocate fixed slots in the stack frame of the current function. */
641 /* Return size needed for stack frame based on slots so far allocated.
642 This size counts from zero. It is not rounded to STACK_BOUNDARY;
643 the caller may have to do that. */
648 #ifdef FRAME_GROWS_DOWNWARD
649 return -frame_offset;
655 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
656 with machine mode MODE.
658 ALIGN controls the amount of alignment for the address of the slot:
659 0 means according to MODE,
660 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
661 positive specifies alignment boundary in bits.
663 We do not round to stack_boundary here. */
666 assign_stack_local (mode, size, align)
667 enum machine_mode mode;
671 register rtx x, addr;
672 int bigend_correction = 0;
677 alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
679 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
681 else if (align == -1)
683 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
684 size = CEIL_ROUND (size, alignment);
687 alignment = align / BITS_PER_UNIT;
689 /* Round frame offset to that alignment.
690 We must be careful here, since FRAME_OFFSET might be negative and
691 division with a negative dividend isn't as well defined as we might
692 like. So we instead assume that ALIGNMENT is a power of two and
693 use logical operations which are unambiguous. */
694 #ifdef FRAME_GROWS_DOWNWARD
695 frame_offset = FLOOR_ROUND (frame_offset, alignment);
697 frame_offset = CEIL_ROUND (frame_offset, alignment);
700 /* On a big-endian machine, if we are allocating more space than we will use,
701 use the least significant bytes of those that are allocated. */
702 if (BYTES_BIG_ENDIAN && mode != BLKmode)
703 bigend_correction = size - GET_MODE_SIZE (mode);
705 #ifdef FRAME_GROWS_DOWNWARD
706 frame_offset -= size;
709 /* If we have already instantiated virtual registers, return the actual
710 address relative to the frame pointer. */
711 if (virtuals_instantiated)
712 addr = plus_constant (frame_pointer_rtx,
713 (frame_offset + bigend_correction
714 + STARTING_FRAME_OFFSET));
716 addr = plus_constant (virtual_stack_vars_rtx,
717 frame_offset + bigend_correction);
719 #ifndef FRAME_GROWS_DOWNWARD
720 frame_offset += size;
723 x = gen_rtx (MEM, mode, addr);
725 stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, x, stack_slot_list);
730 /* Assign a stack slot in a containing function.
731 First three arguments are same as in preceding function.
732 The last argument specifies the function to allocate in. */
735 assign_outer_stack_local (mode, size, align, function)
736 enum machine_mode mode;
739 struct function *function;
741 register rtx x, addr;
742 int bigend_correction = 0;
745 /* Allocate in the memory associated with the function in whose frame
747 push_obstacks (function->function_obstack,
748 function->function_maybepermanent_obstack);
752 alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
754 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
756 else if (align == -1)
758 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
759 size = CEIL_ROUND (size, alignment);
762 alignment = align / BITS_PER_UNIT;
764 /* Round frame offset to that alignment. */
765 #ifdef FRAME_GROWS_DOWNWARD
766 function->frame_offset = FLOOR_ROUND (function->frame_offset, alignment);
768 function->frame_offset = CEIL_ROUND (function->frame_offset, alignment);
771 /* On a big-endian machine, if we are allocating more space than we will use,
772 use the least significant bytes of those that are allocated. */
773 if (BYTES_BIG_ENDIAN && mode != BLKmode)
774 bigend_correction = size - GET_MODE_SIZE (mode);
776 #ifdef FRAME_GROWS_DOWNWARD
777 function->frame_offset -= size;
779 addr = plus_constant (virtual_stack_vars_rtx,
780 function->frame_offset + bigend_correction);
781 #ifndef FRAME_GROWS_DOWNWARD
782 function->frame_offset += size;
785 x = gen_rtx (MEM, mode, addr);
787 function->stack_slot_list
788 = gen_rtx (EXPR_LIST, VOIDmode, x, function->stack_slot_list);
795 /* Allocate a temporary stack slot and record it for possible later
798 MODE is the machine mode to be given to the returned rtx.
800 SIZE is the size in units of the space required. We do no rounding here
801 since assign_stack_local will do any required rounding.
803 KEEP is 1 if this slot is to be retained after a call to
804 free_temp_slots. Automatic variables for a block are allocated
805 with this flag. KEEP is 2, if we allocate a longer term temporary,
806 whose lifetime is controlled by CLEANUP_POINT_EXPRs. */
809 assign_stack_temp (mode, size, keep)
810 enum machine_mode mode;
814 struct temp_slot *p, *best_p = 0;
816 /* If SIZE is -1 it means that somebody tried to allocate a temporary
817 of a variable size. */
821 /* First try to find an available, already-allocated temporary that is the
822 exact size we require. */
823 for (p = temp_slots; p; p = p->next)
824 if (p->size == size && GET_MODE (p->slot) == mode && ! p->in_use)
827 /* If we didn't find, one, try one that is larger than what we want. We
828 find the smallest such. */
830 for (p = temp_slots; p; p = p->next)
831 if (p->size > size && GET_MODE (p->slot) == mode && ! p->in_use
832 && (best_p == 0 || best_p->size > p->size))
835 /* Make our best, if any, the one to use. */
838 /* If there are enough aligned bytes left over, make them into a new
839 temp_slot so that the extra bytes don't get wasted. Do this only
840 for BLKmode slots, so that we can be sure of the alignment. */
841 if (GET_MODE (best_p->slot) == BLKmode)
843 int alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
844 int rounded_size = CEIL_ROUND (size, alignment);
846 if (best_p->size - rounded_size >= alignment)
848 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
849 p->in_use = p->addr_taken = 0;
850 p->size = best_p->size - rounded_size;
851 p->base_offset = best_p->base_offset + rounded_size;
852 p->full_size = best_p->full_size - rounded_size;
853 p->slot = gen_rtx (MEM, BLKmode,
854 plus_constant (XEXP (best_p->slot, 0),
858 p->next = temp_slots;
861 stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, p->slot,
864 best_p->size = rounded_size;
865 best_p->full_size = rounded_size;
872 /* If we still didn't find one, make a new temporary. */
875 int frame_offset_old = frame_offset;
876 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
877 /* If the temp slot mode doesn't indicate the alignment,
878 use the largest possible, so no one will be disappointed. */
879 p->slot = assign_stack_local (mode, size, mode == BLKmode ? -1 : 0);
880 /* The following slot size computation is necessary because we don't
881 know the actual size of the temporary slot until assign_stack_local
882 has performed all the frame alignment and size rounding for the
883 requested temporary. Note that extra space added for alignment
884 can be either above or below this stack slot depending on which
885 way the frame grows. We include the extra space if and only if it
886 is above this slot. */
887 #ifdef FRAME_GROWS_DOWNWARD
888 p->size = frame_offset_old - frame_offset;
892 /* Now define the fields used by combine_temp_slots. */
893 #ifdef FRAME_GROWS_DOWNWARD
894 p->base_offset = frame_offset;
895 p->full_size = frame_offset_old - frame_offset;
897 p->base_offset = frame_offset_old;
898 p->full_size = frame_offset - frame_offset_old;
901 p->next = temp_slots;
907 p->rtl_expr = sequence_rtl_expr;
911 p->level = target_temp_slot_level;
916 p->level = temp_slot_level;
922 /* Assign a temporary of given TYPE.
923 KEEP is as for assign_stack_temp.
924 MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
925 it is 0 if a register is OK. */
928 assign_temp (type, keep, memory_required)
933 enum machine_mode mode = TYPE_MODE (type);
934 int unsignedp = TREE_UNSIGNED (type);
936 if (mode == BLKmode || memory_required)
938 int size = int_size_in_bytes (type);
941 /* Unfortunately, we don't yet know how to allocate variable-sized
942 temporaries. However, sometimes we have a fixed upper limit on
943 the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that
944 instead. This is the case for Chill variable-sized strings. */
945 if (size == -1 && TREE_CODE (type) == ARRAY_TYPE
946 && TYPE_ARRAY_MAX_SIZE (type) != NULL_TREE
947 && TREE_CODE (TYPE_ARRAY_MAX_SIZE (type)) == INTEGER_CST)
948 size = TREE_INT_CST_LOW (TYPE_ARRAY_MAX_SIZE (type));
950 tmp = assign_stack_temp (mode, size, keep);
951 MEM_IN_STRUCT_P (tmp) = AGGREGATE_TYPE_P (type);
955 if (mode == VOIDmode)
958 #ifndef PROMOTE_FOR_CALL_ONLY
959 mode = promote_mode (type, mode, &unsignedp, 0);
962 return gen_reg_rtx (mode);
965 /* Combine temporary stack slots which are adjacent on the stack.
967 This allows for better use of already allocated stack space. This is only
968 done for BLKmode slots because we can be sure that we won't have alignment
969 problems in this case. */
972 combine_temp_slots ()
974 struct temp_slot *p, *q;
975 struct temp_slot *prev_p, *prev_q;
976 /* Determine where to free back to after this function. */
977 rtx free_pointer = rtx_alloc (CONST_INT);
979 for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots)
982 if (! p->in_use && GET_MODE (p->slot) == BLKmode)
983 for (q = p->next, prev_q = p; q; q = prev_q->next)
986 if (! q->in_use && GET_MODE (q->slot) == BLKmode)
988 if (p->base_offset + p->full_size == q->base_offset)
990 /* Q comes after P; combine Q into P. */
992 p->full_size += q->full_size;
995 else if (q->base_offset + q->full_size == p->base_offset)
997 /* P comes after Q; combine P into Q. */
999 q->full_size += p->full_size;
1004 /* Either delete Q or advance past it. */
1006 prev_q->next = q->next;
1010 /* Either delete P or advance past it. */
1014 prev_p->next = p->next;
1016 temp_slots = p->next;
1022 /* Free all the RTL made by plus_constant. */
1023 rtx_free (free_pointer);
1026 /* Find the temp slot corresponding to the object at address X. */
1028 static struct temp_slot *
1029 find_temp_slot_from_address (x)
1032 struct temp_slot *p;
1035 for (p = temp_slots; p; p = p->next)
1039 else if (XEXP (p->slot, 0) == x
1043 else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST)
1044 for (next = p->address; next; next = XEXP (next, 1))
1045 if (XEXP (next, 0) == x)
1052 /* Indicate that NEW is an alternate way of referring to the temp slot
1053 that previous was known by OLD. */
1056 update_temp_slot_address (old, new)
1059 struct temp_slot *p = find_temp_slot_from_address (old);
1061 /* If none, return. Else add NEW as an alias. */
1064 else if (p->address == 0)
1068 if (GET_CODE (p->address) != EXPR_LIST)
1069 p->address = gen_rtx (EXPR_LIST, VOIDmode, p->address, NULL_RTX);
1071 p->address = gen_rtx (EXPR_LIST, VOIDmode, new, p->address);
1075 /* If X could be a reference to a temporary slot, mark the fact that its
1076 address was taken. */
1079 mark_temp_addr_taken (x)
1082 struct temp_slot *p;
1087 /* If X is not in memory or is at a constant address, it cannot be in
1088 a temporary slot. */
1089 if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1092 p = find_temp_slot_from_address (XEXP (x, 0));
1097 /* If X could be a reference to a temporary slot, mark that slot as belonging
1098 to the to one level higher. If X matched one of our slots, just mark that
1099 one. Otherwise, we can't easily predict which it is, so upgrade all of
1100 them. Kept slots need not be touched.
1102 This is called when an ({...}) construct occurs and a statement
1103 returns a value in memory. */
1106 preserve_temp_slots (x)
1109 struct temp_slot *p = 0;
1111 /* If there is no result, we still might have some objects whose address
1112 were taken, so we need to make sure they stay around. */
1115 for (p = temp_slots; p; p = p->next)
1116 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1122 /* If X is a register that is being used as a pointer, see if we have
1123 a temporary slot we know it points to. To be consistent with
1124 the code below, we really should preserve all non-kept slots
1125 if we can't find a match, but that seems to be much too costly. */
1126 if (GET_CODE (x) == REG && REGNO_POINTER_FLAG (REGNO (x)))
1127 p = find_temp_slot_from_address (x);
1129 /* If X is not in memory or is at a constant address, it cannot be in
1130 a temporary slot, but it can contain something whose address was
1132 if (p == 0 && (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))))
1134 for (p = temp_slots; p; p = p->next)
1135 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1141 /* First see if we can find a match. */
1143 p = find_temp_slot_from_address (XEXP (x, 0));
1147 /* Move everything at our level whose address was taken to our new
1148 level in case we used its address. */
1149 struct temp_slot *q;
1151 for (q = temp_slots; q; q = q->next)
1152 if (q != p && q->addr_taken && q->level == p->level)
1160 /* Otherwise, preserve all non-kept slots at this level. */
1161 for (p = temp_slots; p; p = p->next)
1162 if (p->in_use && p->level == temp_slot_level && ! p->keep)
1166 /* X is the result of an RTL_EXPR. If it is a temporary slot associated
1167 with that RTL_EXPR, promote it into a temporary slot at the present
1168 level so it will not be freed when we free slots made in the
1172 preserve_rtl_expr_result (x)
1175 struct temp_slot *p;
1177 /* If X is not in memory or is at a constant address, it cannot be in
1178 a temporary slot. */
1179 if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1182 /* If we can find a match, move it to our level unless it is already at
1184 p = find_temp_slot_from_address (XEXP (x, 0));
1187 p->level = MIN (p->level, temp_slot_level);
1194 /* Free all temporaries used so far. This is normally called at the end
1195 of generating code for a statement. Don't free any temporaries
1196 currently in use for an RTL_EXPR that hasn't yet been emitted.
1197 We could eventually do better than this since it can be reused while
1198 generating the same RTL_EXPR, but this is complex and probably not
1204 struct temp_slot *p;
1206 for (p = temp_slots; p; p = p->next)
1207 if (p->in_use && p->level == temp_slot_level && ! p->keep
1208 && p->rtl_expr == 0)
1211 combine_temp_slots ();
1214 /* Free all temporary slots used in T, an RTL_EXPR node. */
1217 free_temps_for_rtl_expr (t)
1220 struct temp_slot *p;
1222 for (p = temp_slots; p; p = p->next)
1223 if (p->rtl_expr == t)
1226 combine_temp_slots ();
1229 /* Push deeper into the nesting level for stack temporaries. */
1237 /* Pop a temporary nesting level. All slots in use in the current level
1243 struct temp_slot *p;
1245 for (p = temp_slots; p; p = p->next)
1246 if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0)
1249 combine_temp_slots ();
1254 /* Initialize temporary slots. */
1259 /* We have not allocated any temporaries yet. */
1261 temp_slot_level = 0;
1262 target_temp_slot_level = 0;
1265 /* Retroactively move an auto variable from a register to a stack slot.
1266 This is done when an address-reference to the variable is seen. */
1269 put_var_into_stack (decl)
1273 enum machine_mode promoted_mode, decl_mode;
1274 struct function *function = 0;
1277 if (output_bytecode)
1280 context = decl_function_context (decl);
1282 /* Get the current rtl used for this object and it's original mode. */
1283 reg = TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl) : DECL_RTL (decl);
1285 /* No need to do anything if decl has no rtx yet
1286 since in that case caller is setting TREE_ADDRESSABLE
1287 and a stack slot will be assigned when the rtl is made. */
1291 /* Get the declared mode for this object. */
1292 decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl))
1293 : DECL_MODE (decl));
1294 /* Get the mode it's actually stored in. */
1295 promoted_mode = GET_MODE (reg);
1297 /* If this variable comes from an outer function,
1298 find that function's saved context. */
1299 if (context != current_function_decl)
1300 for (function = outer_function_chain; function; function = function->next)
1301 if (function->decl == context)
1304 /* If this is a variable-size object with a pseudo to address it,
1305 put that pseudo into the stack, if the var is nonlocal. */
1306 if (DECL_NONLOCAL (decl)
1307 && GET_CODE (reg) == MEM
1308 && GET_CODE (XEXP (reg, 0)) == REG
1309 && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
1311 reg = XEXP (reg, 0);
1312 decl_mode = promoted_mode = GET_MODE (reg);
1315 /* Now we should have a value that resides in one or more pseudo regs. */
1317 if (GET_CODE (reg) == REG)
1318 put_reg_into_stack (function, reg, TREE_TYPE (decl),
1319 promoted_mode, decl_mode, TREE_SIDE_EFFECTS (decl));
1320 else if (GET_CODE (reg) == CONCAT)
1322 /* A CONCAT contains two pseudos; put them both in the stack.
1323 We do it so they end up consecutive. */
1324 enum machine_mode part_mode = GET_MODE (XEXP (reg, 0));
1325 tree part_type = TREE_TYPE (TREE_TYPE (decl));
1326 #ifdef FRAME_GROWS_DOWNWARD
1327 /* Since part 0 should have a lower address, do it second. */
1328 put_reg_into_stack (function, XEXP (reg, 1), part_type, part_mode,
1329 part_mode, TREE_SIDE_EFFECTS (decl));
1330 put_reg_into_stack (function, XEXP (reg, 0), part_type, part_mode,
1331 part_mode, TREE_SIDE_EFFECTS (decl));
1333 put_reg_into_stack (function, XEXP (reg, 0), part_type, part_mode,
1334 part_mode, TREE_SIDE_EFFECTS (decl));
1335 put_reg_into_stack (function, XEXP (reg, 1), part_type, part_mode,
1336 part_mode, TREE_SIDE_EFFECTS (decl));
1339 /* Change the CONCAT into a combined MEM for both parts. */
1340 PUT_CODE (reg, MEM);
1341 MEM_VOLATILE_P (reg) = MEM_VOLATILE_P (XEXP (reg, 0));
1343 /* The two parts are in memory order already.
1344 Use the lower parts address as ours. */
1345 XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0);
1346 /* Prevent sharing of rtl that might lose. */
1347 if (GET_CODE (XEXP (reg, 0)) == PLUS)
1348 XEXP (reg, 0) = copy_rtx (XEXP (reg, 0));
1352 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1353 into the stack frame of FUNCTION (0 means the current function).
1354 DECL_MODE is the machine mode of the user-level data type.
1355 PROMOTED_MODE is the machine mode of the register.
1356 VOLATILE_P is nonzero if this is for a "volatile" decl. */
1359 put_reg_into_stack (function, reg, type, promoted_mode, decl_mode, volatile_p)
1360 struct function *function;
1363 enum machine_mode promoted_mode, decl_mode;
1370 if (REGNO (reg) < function->max_parm_reg)
1371 new = function->parm_reg_stack_loc[REGNO (reg)];
1373 new = assign_outer_stack_local (decl_mode, GET_MODE_SIZE (decl_mode),
1378 if (REGNO (reg) < max_parm_reg)
1379 new = parm_reg_stack_loc[REGNO (reg)];
1381 new = assign_stack_local (decl_mode, GET_MODE_SIZE (decl_mode), 0);
1384 PUT_MODE (reg, decl_mode);
1385 XEXP (reg, 0) = XEXP (new, 0);
1386 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1387 MEM_VOLATILE_P (reg) = volatile_p;
1388 PUT_CODE (reg, MEM);
1390 /* If this is a memory ref that contains aggregate components,
1391 mark it as such for cse and loop optimize. */
1392 MEM_IN_STRUCT_P (reg) = AGGREGATE_TYPE_P (type);
1394 /* Now make sure that all refs to the variable, previously made
1395 when it was a register, are fixed up to be valid again. */
1398 struct var_refs_queue *temp;
1400 /* Variable is inherited; fix it up when we get back to its function. */
1401 push_obstacks (function->function_obstack,
1402 function->function_maybepermanent_obstack);
1404 /* See comment in restore_tree_status in tree.c for why this needs to be
1405 on saveable obstack. */
1407 = (struct var_refs_queue *) savealloc (sizeof (struct var_refs_queue));
1408 temp->modified = reg;
1409 temp->promoted_mode = promoted_mode;
1410 temp->unsignedp = TREE_UNSIGNED (type);
1411 temp->next = function->fixup_var_refs_queue;
1412 function->fixup_var_refs_queue = temp;
1416 /* Variable is local; fix it up now. */
1417 fixup_var_refs (reg, promoted_mode, TREE_UNSIGNED (type));
1421 fixup_var_refs (var, promoted_mode, unsignedp)
1423 enum machine_mode promoted_mode;
1427 rtx first_insn = get_insns ();
1428 struct sequence_stack *stack = sequence_stack;
1429 tree rtl_exps = rtl_expr_chain;
1431 /* Must scan all insns for stack-refs that exceed the limit. */
1432 fixup_var_refs_insns (var, promoted_mode, unsignedp, first_insn, stack == 0);
1434 /* Scan all pending sequences too. */
1435 for (; stack; stack = stack->next)
1437 push_to_sequence (stack->first);
1438 fixup_var_refs_insns (var, promoted_mode, unsignedp,
1439 stack->first, stack->next != 0);
1440 /* Update remembered end of sequence
1441 in case we added an insn at the end. */
1442 stack->last = get_last_insn ();
1446 /* Scan all waiting RTL_EXPRs too. */
1447 for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
1449 rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
1450 if (seq != const0_rtx && seq != 0)
1452 push_to_sequence (seq);
1453 fixup_var_refs_insns (var, promoted_mode, unsignedp, seq, 0);
1459 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1460 some part of an insn. Return a struct fixup_replacement whose OLD
1461 value is equal to X. Allocate a new structure if no such entry exists. */
1463 static struct fixup_replacement *
1464 find_fixup_replacement (replacements, x)
1465 struct fixup_replacement **replacements;
1468 struct fixup_replacement *p;
1470 /* See if we have already replaced this. */
1471 for (p = *replacements; p && p->old != x; p = p->next)
1476 p = (struct fixup_replacement *) oballoc (sizeof (struct fixup_replacement));
1479 p->next = *replacements;
1486 /* Scan the insn-chain starting with INSN for refs to VAR
1487 and fix them up. TOPLEVEL is nonzero if this chain is the
1488 main chain of insns for the current function. */
1491 fixup_var_refs_insns (var, promoted_mode, unsignedp, insn, toplevel)
1493 enum machine_mode promoted_mode;
1502 rtx next = NEXT_INSN (insn);
1504 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1506 /* If this is a CLOBBER of VAR, delete it.
1508 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1509 and REG_RETVAL notes too. */
1510 if (GET_CODE (PATTERN (insn)) == CLOBBER
1511 && XEXP (PATTERN (insn), 0) == var)
1513 if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0)
1514 /* The REG_LIBCALL note will go away since we are going to
1515 turn INSN into a NOTE, so just delete the
1516 corresponding REG_RETVAL note. */
1517 remove_note (XEXP (note, 0),
1518 find_reg_note (XEXP (note, 0), REG_RETVAL,
1521 /* In unoptimized compilation, we shouldn't call delete_insn
1522 except in jump.c doing warnings. */
1523 PUT_CODE (insn, NOTE);
1524 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1525 NOTE_SOURCE_FILE (insn) = 0;
1528 /* The insn to load VAR from a home in the arglist
1529 is now a no-op. When we see it, just delete it. */
1531 && GET_CODE (PATTERN (insn)) == SET
1532 && SET_DEST (PATTERN (insn)) == var
1533 /* If this represents the result of an insn group,
1534 don't delete the insn. */
1535 && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0
1536 && rtx_equal_p (SET_SRC (PATTERN (insn)), var))
1538 /* In unoptimized compilation, we shouldn't call delete_insn
1539 except in jump.c doing warnings. */
1540 PUT_CODE (insn, NOTE);
1541 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1542 NOTE_SOURCE_FILE (insn) = 0;
1543 if (insn == last_parm_insn)
1544 last_parm_insn = PREV_INSN (next);
1548 struct fixup_replacement *replacements = 0;
1549 rtx next_insn = NEXT_INSN (insn);
1551 #ifdef SMALL_REGISTER_CLASSES
1552 /* If the insn that copies the results of a CALL_INSN
1553 into a pseudo now references VAR, we have to use an
1554 intermediate pseudo since we want the life of the
1555 return value register to be only a single insn.
1557 If we don't use an intermediate pseudo, such things as
1558 address computations to make the address of VAR valid
1559 if it is not can be placed between the CALL_INSN and INSN.
1561 To make sure this doesn't happen, we record the destination
1562 of the CALL_INSN and see if the next insn uses both that
1565 if (call_dest != 0 && GET_CODE (insn) == INSN
1566 && reg_mentioned_p (var, PATTERN (insn))
1567 && reg_mentioned_p (call_dest, PATTERN (insn)))
1569 rtx temp = gen_reg_rtx (GET_MODE (call_dest));
1571 emit_insn_before (gen_move_insn (temp, call_dest), insn);
1573 PATTERN (insn) = replace_rtx (PATTERN (insn),
1577 if (GET_CODE (insn) == CALL_INSN
1578 && GET_CODE (PATTERN (insn)) == SET)
1579 call_dest = SET_DEST (PATTERN (insn));
1580 else if (GET_CODE (insn) == CALL_INSN
1581 && GET_CODE (PATTERN (insn)) == PARALLEL
1582 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
1583 call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
1588 /* See if we have to do anything to INSN now that VAR is in
1589 memory. If it needs to be loaded into a pseudo, use a single
1590 pseudo for the entire insn in case there is a MATCH_DUP
1591 between two operands. We pass a pointer to the head of
1592 a list of struct fixup_replacements. If fixup_var_refs_1
1593 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1594 it will record them in this list.
1596 If it allocated a pseudo for any replacement, we copy into
1599 fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn,
1602 /* If this is last_parm_insn, and any instructions were output
1603 after it to fix it up, then we must set last_parm_insn to
1604 the last such instruction emitted. */
1605 if (insn == last_parm_insn)
1606 last_parm_insn = PREV_INSN (next_insn);
1608 while (replacements)
1610 if (GET_CODE (replacements->new) == REG)
1615 /* OLD might be a (subreg (mem)). */
1616 if (GET_CODE (replacements->old) == SUBREG)
1618 = fixup_memory_subreg (replacements->old, insn, 0);
1621 = fixup_stack_1 (replacements->old, insn);
1623 insert_before = insn;
1625 /* If we are changing the mode, do a conversion.
1626 This might be wasteful, but combine.c will
1627 eliminate much of the waste. */
1629 if (GET_MODE (replacements->new)
1630 != GET_MODE (replacements->old))
1633 convert_move (replacements->new,
1634 replacements->old, unsignedp);
1635 seq = gen_sequence ();
1639 seq = gen_move_insn (replacements->new,
1642 emit_insn_before (seq, insert_before);
1645 replacements = replacements->next;
1649 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1650 But don't touch other insns referred to by reg-notes;
1651 we will get them elsewhere. */
1652 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
1653 if (GET_CODE (note) != INSN_LIST)
1655 = walk_fixup_memory_subreg (XEXP (note, 0), insn, 1);
1661 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1662 See if the rtx expression at *LOC in INSN needs to be changed.
1664 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1665 contain a list of original rtx's and replacements. If we find that we need
1666 to modify this insn by replacing a memory reference with a pseudo or by
1667 making a new MEM to implement a SUBREG, we consult that list to see if
1668 we have already chosen a replacement. If none has already been allocated,
1669 we allocate it and update the list. fixup_var_refs_insns will copy VAR
1670 or the SUBREG, as appropriate, to the pseudo. */
1673 fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements)
1675 enum machine_mode promoted_mode;
1678 struct fixup_replacement **replacements;
1681 register rtx x = *loc;
1682 RTX_CODE code = GET_CODE (x);
1684 register rtx tem, tem1;
1685 struct fixup_replacement *replacement;
1692 /* If we already have a replacement, use it. Otherwise,
1693 try to fix up this address in case it is invalid. */
1695 replacement = find_fixup_replacement (replacements, var);
1696 if (replacement->new)
1698 *loc = replacement->new;
1702 *loc = replacement->new = x = fixup_stack_1 (x, insn);
1704 /* Unless we are forcing memory to register or we changed the mode,
1705 we can leave things the way they are if the insn is valid. */
1707 INSN_CODE (insn) = -1;
1708 if (! flag_force_mem && GET_MODE (x) == promoted_mode
1709 && recog_memoized (insn) >= 0)
1712 *loc = replacement->new = gen_reg_rtx (promoted_mode);
1716 /* If X contains VAR, we need to unshare it here so that we update
1717 each occurrence separately. But all identical MEMs in one insn
1718 must be replaced with the same rtx because of the possibility of
1721 if (reg_mentioned_p (var, x))
1723 replacement = find_fixup_replacement (replacements, x);
1724 if (replacement->new == 0)
1725 replacement->new = copy_most_rtx (x, var);
1727 *loc = x = replacement->new;
1743 /* Note that in some cases those types of expressions are altered
1744 by optimize_bit_field, and do not survive to get here. */
1745 if (XEXP (x, 0) == var
1746 || (GET_CODE (XEXP (x, 0)) == SUBREG
1747 && SUBREG_REG (XEXP (x, 0)) == var))
1749 /* Get TEM as a valid MEM in the mode presently in the insn.
1751 We don't worry about the possibility of MATCH_DUP here; it
1752 is highly unlikely and would be tricky to handle. */
1755 if (GET_CODE (tem) == SUBREG)
1756 tem = fixup_memory_subreg (tem, insn, 1);
1757 tem = fixup_stack_1 (tem, insn);
1759 /* Unless we want to load from memory, get TEM into the proper mode
1760 for an extract from memory. This can only be done if the
1761 extract is at a constant position and length. */
1763 if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
1764 && GET_CODE (XEXP (x, 2)) == CONST_INT
1765 && ! mode_dependent_address_p (XEXP (tem, 0))
1766 && ! MEM_VOLATILE_P (tem))
1768 enum machine_mode wanted_mode = VOIDmode;
1769 enum machine_mode is_mode = GET_MODE (tem);
1770 int width = INTVAL (XEXP (x, 1));
1771 int pos = INTVAL (XEXP (x, 2));
1774 if (GET_CODE (x) == ZERO_EXTRACT)
1775 wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
1778 if (GET_CODE (x) == SIGN_EXTRACT)
1779 wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
1781 /* If we have a narrower mode, we can do something. */
1782 if (wanted_mode != VOIDmode
1783 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
1785 int offset = pos / BITS_PER_UNIT;
1786 rtx old_pos = XEXP (x, 2);
1789 /* If the bytes and bits are counted differently, we
1790 must adjust the offset. */
1791 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
1792 offset = (GET_MODE_SIZE (is_mode)
1793 - GET_MODE_SIZE (wanted_mode) - offset);
1795 pos %= GET_MODE_BITSIZE (wanted_mode);
1797 newmem = gen_rtx (MEM, wanted_mode,
1798 plus_constant (XEXP (tem, 0), offset));
1799 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
1800 MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
1801 MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
1803 /* Make the change and see if the insn remains valid. */
1804 INSN_CODE (insn) = -1;
1805 XEXP (x, 0) = newmem;
1806 XEXP (x, 2) = GEN_INT (pos);
1808 if (recog_memoized (insn) >= 0)
1811 /* Otherwise, restore old position. XEXP (x, 0) will be
1813 XEXP (x, 2) = old_pos;
1817 /* If we get here, the bitfield extract insn can't accept a memory
1818 reference. Copy the input into a register. */
1820 tem1 = gen_reg_rtx (GET_MODE (tem));
1821 emit_insn_before (gen_move_insn (tem1, tem), insn);
1828 if (SUBREG_REG (x) == var)
1830 /* If this is a special SUBREG made because VAR was promoted
1831 from a wider mode, replace it with VAR and call ourself
1832 recursively, this time saying that the object previously
1833 had its current mode (by virtue of the SUBREG). */
1835 if (SUBREG_PROMOTED_VAR_P (x))
1838 fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements);
1842 /* If this SUBREG makes VAR wider, it has become a paradoxical
1843 SUBREG with VAR in memory, but these aren't allowed at this
1844 stage of the compilation. So load VAR into a pseudo and take
1845 a SUBREG of that pseudo. */
1846 if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
1848 replacement = find_fixup_replacement (replacements, var);
1849 if (replacement->new == 0)
1850 replacement->new = gen_reg_rtx (GET_MODE (var));
1851 SUBREG_REG (x) = replacement->new;
1855 /* See if we have already found a replacement for this SUBREG.
1856 If so, use it. Otherwise, make a MEM and see if the insn
1857 is recognized. If not, or if we should force MEM into a register,
1858 make a pseudo for this SUBREG. */
1859 replacement = find_fixup_replacement (replacements, x);
1860 if (replacement->new)
1862 *loc = replacement->new;
1866 replacement->new = *loc = fixup_memory_subreg (x, insn, 0);
1868 INSN_CODE (insn) = -1;
1869 if (! flag_force_mem && recog_memoized (insn) >= 0)
1872 *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
1878 /* First do special simplification of bit-field references. */
1879 if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
1880 || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
1881 optimize_bit_field (x, insn, 0);
1882 if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
1883 || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
1884 optimize_bit_field (x, insn, NULL_PTR);
1886 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
1887 insn into a pseudo and store the low part of the pseudo into VAR. */
1888 if (GET_CODE (SET_DEST (x)) == SUBREG
1889 && SUBREG_REG (SET_DEST (x)) == var
1890 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
1891 > GET_MODE_SIZE (GET_MODE (var))))
1893 SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
1894 emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
1901 rtx dest = SET_DEST (x);
1902 rtx src = SET_SRC (x);
1903 rtx outerdest = dest;
1905 while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
1906 || GET_CODE (dest) == SIGN_EXTRACT
1907 || GET_CODE (dest) == ZERO_EXTRACT)
1908 dest = XEXP (dest, 0);
1910 if (GET_CODE (src) == SUBREG)
1911 src = XEXP (src, 0);
1913 /* If VAR does not appear at the top level of the SET
1914 just scan the lower levels of the tree. */
1916 if (src != var && dest != var)
1919 /* We will need to rerecognize this insn. */
1920 INSN_CODE (insn) = -1;
1923 if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var)
1925 /* Since this case will return, ensure we fixup all the
1927 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1),
1928 insn, replacements);
1929 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2),
1930 insn, replacements);
1931 fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x),
1932 insn, replacements);
1934 tem = XEXP (outerdest, 0);
1936 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
1937 that may appear inside a ZERO_EXTRACT.
1938 This was legitimate when the MEM was a REG. */
1939 if (GET_CODE (tem) == SUBREG
1940 && SUBREG_REG (tem) == var)
1941 tem = fixup_memory_subreg (tem, insn, 1);
1943 tem = fixup_stack_1 (tem, insn);
1945 if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
1946 && GET_CODE (XEXP (outerdest, 2)) == CONST_INT
1947 && ! mode_dependent_address_p (XEXP (tem, 0))
1948 && ! MEM_VOLATILE_P (tem))
1950 enum machine_mode wanted_mode
1951 = insn_operand_mode[(int) CODE_FOR_insv][0];
1952 enum machine_mode is_mode = GET_MODE (tem);
1953 int width = INTVAL (XEXP (outerdest, 1));
1954 int pos = INTVAL (XEXP (outerdest, 2));
1956 /* If we have a narrower mode, we can do something. */
1957 if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
1959 int offset = pos / BITS_PER_UNIT;
1960 rtx old_pos = XEXP (outerdest, 2);
1963 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
1964 offset = (GET_MODE_SIZE (is_mode)
1965 - GET_MODE_SIZE (wanted_mode) - offset);
1967 pos %= GET_MODE_BITSIZE (wanted_mode);
1969 newmem = gen_rtx (MEM, wanted_mode,
1970 plus_constant (XEXP (tem, 0), offset));
1971 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
1972 MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
1973 MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
1975 /* Make the change and see if the insn remains valid. */
1976 INSN_CODE (insn) = -1;
1977 XEXP (outerdest, 0) = newmem;
1978 XEXP (outerdest, 2) = GEN_INT (pos);
1980 if (recog_memoized (insn) >= 0)
1983 /* Otherwise, restore old position. XEXP (x, 0) will be
1985 XEXP (outerdest, 2) = old_pos;
1989 /* If we get here, the bit-field store doesn't allow memory
1990 or isn't located at a constant position. Load the value into
1991 a register, do the store, and put it back into memory. */
1993 tem1 = gen_reg_rtx (GET_MODE (tem));
1994 emit_insn_before (gen_move_insn (tem1, tem), insn);
1995 emit_insn_after (gen_move_insn (tem, tem1), insn);
1996 XEXP (outerdest, 0) = tem1;
2001 /* STRICT_LOW_PART is a no-op on memory references
2002 and it can cause combinations to be unrecognizable,
2005 if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
2006 SET_DEST (x) = XEXP (SET_DEST (x), 0);
2008 /* A valid insn to copy VAR into or out of a register
2009 must be left alone, to avoid an infinite loop here.
2010 If the reference to VAR is by a subreg, fix that up,
2011 since SUBREG is not valid for a memref.
2012 Also fix up the address of the stack slot.
2014 Note that we must not try to recognize the insn until
2015 after we know that we have valid addresses and no
2016 (subreg (mem ...) ...) constructs, since these interfere
2017 with determining the validity of the insn. */
2019 if ((SET_SRC (x) == var
2020 || (GET_CODE (SET_SRC (x)) == SUBREG
2021 && SUBREG_REG (SET_SRC (x)) == var))
2022 && (GET_CODE (SET_DEST (x)) == REG
2023 || (GET_CODE (SET_DEST (x)) == SUBREG
2024 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
2025 && GET_MODE (var) == promoted_mode
2026 && x == single_set (insn))
2030 replacement = find_fixup_replacement (replacements, SET_SRC (x));
2031 if (replacement->new)
2032 SET_SRC (x) = replacement->new;
2033 else if (GET_CODE (SET_SRC (x)) == SUBREG)
2034 SET_SRC (x) = replacement->new
2035 = fixup_memory_subreg (SET_SRC (x), insn, 0);
2037 SET_SRC (x) = replacement->new
2038 = fixup_stack_1 (SET_SRC (x), insn);
2040 if (recog_memoized (insn) >= 0)
2043 /* INSN is not valid, but we know that we want to
2044 copy SET_SRC (x) to SET_DEST (x) in some way. So
2045 we generate the move and see whether it requires more
2046 than one insn. If it does, we emit those insns and
2047 delete INSN. Otherwise, we an just replace the pattern
2048 of INSN; we have already verified above that INSN has
2049 no other function that to do X. */
2051 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2052 if (GET_CODE (pat) == SEQUENCE)
2054 emit_insn_after (pat, insn);
2055 PUT_CODE (insn, NOTE);
2056 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2057 NOTE_SOURCE_FILE (insn) = 0;
2060 PATTERN (insn) = pat;
2065 if ((SET_DEST (x) == var
2066 || (GET_CODE (SET_DEST (x)) == SUBREG
2067 && SUBREG_REG (SET_DEST (x)) == var))
2068 && (GET_CODE (SET_SRC (x)) == REG
2069 || (GET_CODE (SET_SRC (x)) == SUBREG
2070 && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
2071 && GET_MODE (var) == promoted_mode
2072 && x == single_set (insn))
2076 if (GET_CODE (SET_DEST (x)) == SUBREG)
2077 SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn, 0);
2079 SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
2081 if (recog_memoized (insn) >= 0)
2084 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2085 if (GET_CODE (pat) == SEQUENCE)
2087 emit_insn_after (pat, insn);
2088 PUT_CODE (insn, NOTE);
2089 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2090 NOTE_SOURCE_FILE (insn) = 0;
2093 PATTERN (insn) = pat;
2098 /* Otherwise, storing into VAR must be handled specially
2099 by storing into a temporary and copying that into VAR
2100 with a new insn after this one. Note that this case
2101 will be used when storing into a promoted scalar since
2102 the insn will now have different modes on the input
2103 and output and hence will be invalid (except for the case
2104 of setting it to a constant, which does not need any
2105 change if it is valid). We generate extra code in that case,
2106 but combine.c will eliminate it. */
2111 rtx fixeddest = SET_DEST (x);
2113 /* STRICT_LOW_PART can be discarded, around a MEM. */
2114 if (GET_CODE (fixeddest) == STRICT_LOW_PART)
2115 fixeddest = XEXP (fixeddest, 0);
2116 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
2117 if (GET_CODE (fixeddest) == SUBREG)
2119 fixeddest = fixup_memory_subreg (fixeddest, insn, 0);
2120 promoted_mode = GET_MODE (fixeddest);
2123 fixeddest = fixup_stack_1 (fixeddest, insn);
2125 temp = gen_reg_rtx (promoted_mode);
2127 emit_insn_after (gen_move_insn (fixeddest,
2128 gen_lowpart (GET_MODE (fixeddest),
2132 SET_DEST (x) = temp;
2137 /* Nothing special about this RTX; fix its operands. */
2139 fmt = GET_RTX_FORMAT (code);
2140 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2143 fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements);
2147 for (j = 0; j < XVECLEN (x, i); j++)
2148 fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j),
2149 insn, replacements);
2154 /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
2155 return an rtx (MEM:m1 newaddr) which is equivalent.
2156 If any insns must be emitted to compute NEWADDR, put them before INSN.
2158 UNCRITICAL nonzero means accept paradoxical subregs.
2159 This is used for subregs found inside of ZERO_EXTRACTs and in REG_NOTES. */
2162 fixup_memory_subreg (x, insn, uncritical)
2167 int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
2168 rtx addr = XEXP (SUBREG_REG (x), 0);
2169 enum machine_mode mode = GET_MODE (x);
2172 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2173 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
2177 if (BYTES_BIG_ENDIAN)
2178 offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
2179 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
2180 addr = plus_constant (addr, offset);
2181 if (!flag_force_addr && memory_address_p (mode, addr))
2182 /* Shortcut if no insns need be emitted. */
2183 return change_address (SUBREG_REG (x), mode, addr);
2185 result = change_address (SUBREG_REG (x), mode, addr);
2186 emit_insn_before (gen_sequence (), insn);
2191 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2192 Replace subexpressions of X in place.
2193 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2194 Otherwise return X, with its contents possibly altered.
2196 If any insns must be emitted to compute NEWADDR, put them before INSN.
2198 UNCRITICAL is as in fixup_memory_subreg. */
2201 walk_fixup_memory_subreg (x, insn, uncritical)
2206 register enum rtx_code code;
2213 code = GET_CODE (x);
2215 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
2216 return fixup_memory_subreg (x, insn, uncritical);
2218 /* Nothing special about this RTX; fix its operands. */
2220 fmt = GET_RTX_FORMAT (code);
2221 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2224 XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn, uncritical);
2228 for (j = 0; j < XVECLEN (x, i); j++)
2230 = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn, uncritical);
2236 /* For each memory ref within X, if it refers to a stack slot
2237 with an out of range displacement, put the address in a temp register
2238 (emitting new insns before INSN to load these registers)
2239 and alter the memory ref to use that register.
2240 Replace each such MEM rtx with a copy, to avoid clobberage. */
2243 fixup_stack_1 (x, insn)
2248 register RTX_CODE code = GET_CODE (x);
2253 register rtx ad = XEXP (x, 0);
2254 /* If we have address of a stack slot but it's not valid
2255 (displacement is too large), compute the sum in a register. */
2256 if (GET_CODE (ad) == PLUS
2257 && GET_CODE (XEXP (ad, 0)) == REG
2258 && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
2259 && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER)
2260 || XEXP (ad, 0) == current_function_internal_arg_pointer)
2261 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
2264 if (memory_address_p (GET_MODE (x), ad))
2268 temp = copy_to_reg (ad);
2269 seq = gen_sequence ();
2271 emit_insn_before (seq, insn);
2272 return change_address (x, VOIDmode, temp);
2277 fmt = GET_RTX_FORMAT (code);
2278 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2281 XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
2285 for (j = 0; j < XVECLEN (x, i); j++)
2286 XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
2292 /* Optimization: a bit-field instruction whose field
2293 happens to be a byte or halfword in memory
2294 can be changed to a move instruction.
2296 We call here when INSN is an insn to examine or store into a bit-field.
2297 BODY is the SET-rtx to be altered.
2299 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2300 (Currently this is called only from function.c, and EQUIV_MEM
2304 optimize_bit_field (body, insn, equiv_mem)
2309 register rtx bitfield;
2312 enum machine_mode mode;
2314 if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
2315 || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
2316 bitfield = SET_DEST (body), destflag = 1;
2318 bitfield = SET_SRC (body), destflag = 0;
2320 /* First check that the field being stored has constant size and position
2321 and is in fact a byte or halfword suitably aligned. */
2323 if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
2324 && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
2325 && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
2327 && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
2329 register rtx memref = 0;
2331 /* Now check that the containing word is memory, not a register,
2332 and that it is safe to change the machine mode. */
2334 if (GET_CODE (XEXP (bitfield, 0)) == MEM)
2335 memref = XEXP (bitfield, 0);
2336 else if (GET_CODE (XEXP (bitfield, 0)) == REG
2338 memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
2339 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2340 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
2341 memref = SUBREG_REG (XEXP (bitfield, 0));
2342 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2344 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
2345 memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
2348 && ! mode_dependent_address_p (XEXP (memref, 0))
2349 && ! MEM_VOLATILE_P (memref))
2351 /* Now adjust the address, first for any subreg'ing
2352 that we are now getting rid of,
2353 and then for which byte of the word is wanted. */
2355 register int offset = INTVAL (XEXP (bitfield, 2));
2358 /* Adjust OFFSET to count bits from low-address byte. */
2359 if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN)
2360 offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
2361 - offset - INTVAL (XEXP (bitfield, 1)));
2363 /* Adjust OFFSET to count bytes from low-address byte. */
2364 offset /= BITS_PER_UNIT;
2365 if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
2367 offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD;
2368 if (BYTES_BIG_ENDIAN)
2369 offset -= (MIN (UNITS_PER_WORD,
2370 GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
2371 - MIN (UNITS_PER_WORD,
2372 GET_MODE_SIZE (GET_MODE (memref))));
2376 memref = change_address (memref, mode,
2377 plus_constant (XEXP (memref, 0), offset));
2378 insns = get_insns ();
2380 emit_insns_before (insns, insn);
2382 /* Store this memory reference where
2383 we found the bit field reference. */
2387 validate_change (insn, &SET_DEST (body), memref, 1);
2388 if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
2390 rtx src = SET_SRC (body);
2391 while (GET_CODE (src) == SUBREG
2392 && SUBREG_WORD (src) == 0)
2393 src = SUBREG_REG (src);
2394 if (GET_MODE (src) != GET_MODE (memref))
2395 src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
2396 validate_change (insn, &SET_SRC (body), src, 1);
2398 else if (GET_MODE (SET_SRC (body)) != VOIDmode
2399 && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
2400 /* This shouldn't happen because anything that didn't have
2401 one of these modes should have got converted explicitly
2402 and then referenced through a subreg.
2403 This is so because the original bit-field was
2404 handled by agg_mode and so its tree structure had
2405 the same mode that memref now has. */
2410 rtx dest = SET_DEST (body);
2412 while (GET_CODE (dest) == SUBREG
2413 && SUBREG_WORD (dest) == 0
2414 && (GET_MODE_CLASS (GET_MODE (dest))
2415 == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest)))))
2416 dest = SUBREG_REG (dest);
2418 validate_change (insn, &SET_DEST (body), dest, 1);
2420 if (GET_MODE (dest) == GET_MODE (memref))
2421 validate_change (insn, &SET_SRC (body), memref, 1);
2424 /* Convert the mem ref to the destination mode. */
2425 rtx newreg = gen_reg_rtx (GET_MODE (dest));
2428 convert_move (newreg, memref,
2429 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
2433 validate_change (insn, &SET_SRC (body), newreg, 1);
2437 /* See if we can convert this extraction or insertion into
2438 a simple move insn. We might not be able to do so if this
2439 was, for example, part of a PARALLEL.
2441 If we succeed, write out any needed conversions. If we fail,
2442 it is hard to guess why we failed, so don't do anything
2443 special; just let the optimization be suppressed. */
2445 if (apply_change_group () && seq)
2446 emit_insns_before (seq, insn);
2451 /* These routines are responsible for converting virtual register references
2452 to the actual hard register references once RTL generation is complete.
2454 The following four variables are used for communication between the
2455 routines. They contain the offsets of the virtual registers from their
2456 respective hard registers. */
2458 static int in_arg_offset;
2459 static int var_offset;
2460 static int dynamic_offset;
2461 static int out_arg_offset;
2463 /* In most machines, the stack pointer register is equivalent to the bottom
2466 #ifndef STACK_POINTER_OFFSET
2467 #define STACK_POINTER_OFFSET 0
2470 /* If not defined, pick an appropriate default for the offset of dynamically
2471 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2472 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2474 #ifndef STACK_DYNAMIC_OFFSET
2476 #ifdef ACCUMULATE_OUTGOING_ARGS
2477 /* The bottom of the stack points to the actual arguments. If
2478 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2479 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2480 stack space for register parameters is not pushed by the caller, but
2481 rather part of the fixed stack areas and hence not included in
2482 `current_function_outgoing_args_size'. Nevertheless, we must allow
2483 for it when allocating stack dynamic objects. */
2485 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2486 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2487 (current_function_outgoing_args_size \
2488 + REG_PARM_STACK_SPACE (FNDECL) + (STACK_POINTER_OFFSET))
2491 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2492 (current_function_outgoing_args_size + (STACK_POINTER_OFFSET))
2496 #define STACK_DYNAMIC_OFFSET(FNDECL) STACK_POINTER_OFFSET
2500 /* Pass through the INSNS of function FNDECL and convert virtual register
2501 references to hard register references. */
2504 instantiate_virtual_regs (fndecl, insns)
2510 /* Compute the offsets to use for this function. */
2511 in_arg_offset = FIRST_PARM_OFFSET (fndecl);
2512 var_offset = STARTING_FRAME_OFFSET;
2513 dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
2514 out_arg_offset = STACK_POINTER_OFFSET;
2516 /* Scan all variables and parameters of this function. For each that is
2517 in memory, instantiate all virtual registers if the result is a valid
2518 address. If not, we do it later. That will handle most uses of virtual
2519 regs on many machines. */
2520 instantiate_decls (fndecl, 1);
2522 /* Initialize recognition, indicating that volatile is OK. */
2525 /* Scan through all the insns, instantiating every virtual register still
2527 for (insn = insns; insn; insn = NEXT_INSN (insn))
2528 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
2529 || GET_CODE (insn) == CALL_INSN)
2531 instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1);
2532 instantiate_virtual_regs_1 (®_NOTES (insn), NULL_RTX, 0);
2535 /* Now instantiate the remaining register equivalences for debugging info.
2536 These will not be valid addresses. */
2537 instantiate_decls (fndecl, 0);
2539 /* Indicate that, from now on, assign_stack_local should use
2540 frame_pointer_rtx. */
2541 virtuals_instantiated = 1;
2544 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
2545 all virtual registers in their DECL_RTL's.
2547 If VALID_ONLY, do this only if the resulting address is still valid.
2548 Otherwise, always do it. */
2551 instantiate_decls (fndecl, valid_only)
2557 if (DECL_SAVED_INSNS (fndecl))
2558 /* When compiling an inline function, the obstack used for
2559 rtl allocation is the maybepermanent_obstack. Calling
2560 `resume_temporary_allocation' switches us back to that
2561 obstack while we process this function's parameters. */
2562 resume_temporary_allocation ();
2564 /* Process all parameters of the function. */
2565 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
2567 instantiate_decl (DECL_RTL (decl), int_size_in_bytes (TREE_TYPE (decl)),
2569 instantiate_decl (DECL_INCOMING_RTL (decl),
2570 int_size_in_bytes (TREE_TYPE (decl)), valid_only);
2573 /* Now process all variables defined in the function or its subblocks. */
2574 instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
2576 if (DECL_INLINE (fndecl) || DECL_DEFER_OUTPUT (fndecl))
2578 /* Save all rtl allocated for this function by raising the
2579 high-water mark on the maybepermanent_obstack. */
2581 /* All further rtl allocation is now done in the current_obstack. */
2582 rtl_in_current_obstack ();
2586 /* Subroutine of instantiate_decls: Process all decls in the given
2587 BLOCK node and all its subblocks. */
2590 instantiate_decls_1 (let, valid_only)
2596 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
2597 instantiate_decl (DECL_RTL (t), int_size_in_bytes (TREE_TYPE (t)),
2600 /* Process all subblocks. */
2601 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
2602 instantiate_decls_1 (t, valid_only);
2605 /* Subroutine of the preceding procedures: Given RTL representing a
2606 decl and the size of the object, do any instantiation required.
2608 If VALID_ONLY is non-zero, it means that the RTL should only be
2609 changed if the new address is valid. */
2612 instantiate_decl (x, size, valid_only)
2617 enum machine_mode mode;
2620 /* If this is not a MEM, no need to do anything. Similarly if the
2621 address is a constant or a register that is not a virtual register. */
2623 if (x == 0 || GET_CODE (x) != MEM)
2627 if (CONSTANT_P (addr)
2628 || (GET_CODE (addr) == REG
2629 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
2630 || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
2633 /* If we should only do this if the address is valid, copy the address.
2634 We need to do this so we can undo any changes that might make the
2635 address invalid. This copy is unfortunate, but probably can't be
2639 addr = copy_rtx (addr);
2641 instantiate_virtual_regs_1 (&addr, NULL_RTX, 0);
2646 /* Now verify that the resulting address is valid for every integer or
2647 floating-point mode up to and including SIZE bytes long. We do this
2648 since the object might be accessed in any mode and frame addresses
2651 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2652 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
2653 mode = GET_MODE_WIDER_MODE (mode))
2654 if (! memory_address_p (mode, addr))
2657 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
2658 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
2659 mode = GET_MODE_WIDER_MODE (mode))
2660 if (! memory_address_p (mode, addr))
2663 /* Otherwise, put back the address, now that we have updated it and we
2664 know it is valid. */
2669 /* Given a pointer to a piece of rtx and an optional pointer to the
2670 containing object, instantiate any virtual registers present in it.
2672 If EXTRA_INSNS, we always do the replacement and generate
2673 any extra insns before OBJECT. If it zero, we do nothing if replacement
2676 Return 1 if we either had nothing to do or if we were able to do the
2677 needed replacement. Return 0 otherwise; we only return zero if
2678 EXTRA_INSNS is zero.
2680 We first try some simple transformations to avoid the creation of extra
2684 instantiate_virtual_regs_1 (loc, object, extra_insns)
2698 /* Re-start here to avoid recursion in common cases. */
2705 code = GET_CODE (x);
2707 /* Check for some special cases. */
2724 /* We are allowed to set the virtual registers. This means that
2725 that the actual register should receive the source minus the
2726 appropriate offset. This is used, for example, in the handling
2727 of non-local gotos. */
2728 if (SET_DEST (x) == virtual_incoming_args_rtx)
2729 new = arg_pointer_rtx, offset = - in_arg_offset;
2730 else if (SET_DEST (x) == virtual_stack_vars_rtx)
2731 new = frame_pointer_rtx, offset = - var_offset;
2732 else if (SET_DEST (x) == virtual_stack_dynamic_rtx)
2733 new = stack_pointer_rtx, offset = - dynamic_offset;
2734 else if (SET_DEST (x) == virtual_outgoing_args_rtx)
2735 new = stack_pointer_rtx, offset = - out_arg_offset;
2739 /* The only valid sources here are PLUS or REG. Just do
2740 the simplest possible thing to handle them. */
2741 if (GET_CODE (SET_SRC (x)) != REG
2742 && GET_CODE (SET_SRC (x)) != PLUS)
2746 if (GET_CODE (SET_SRC (x)) != REG)
2747 temp = force_operand (SET_SRC (x), NULL_RTX);
2750 temp = force_operand (plus_constant (temp, offset), NULL_RTX);
2754 emit_insns_before (seq, object);
2757 if (!validate_change (object, &SET_SRC (x), temp, 0)
2764 instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns);
2769 /* Handle special case of virtual register plus constant. */
2770 if (CONSTANT_P (XEXP (x, 1)))
2772 rtx old, new_offset;
2774 /* Check for (plus (plus VIRT foo) (const_int)) first. */
2775 if (GET_CODE (XEXP (x, 0)) == PLUS)
2777 rtx inner = XEXP (XEXP (x, 0), 0);
2779 if (inner == virtual_incoming_args_rtx)
2780 new = arg_pointer_rtx, offset = in_arg_offset;
2781 else if (inner == virtual_stack_vars_rtx)
2782 new = frame_pointer_rtx, offset = var_offset;
2783 else if (inner == virtual_stack_dynamic_rtx)
2784 new = stack_pointer_rtx, offset = dynamic_offset;
2785 else if (inner == virtual_outgoing_args_rtx)
2786 new = stack_pointer_rtx, offset = out_arg_offset;
2793 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object,
2795 new = gen_rtx (PLUS, Pmode, new, XEXP (XEXP (x, 0), 1));
2798 else if (XEXP (x, 0) == virtual_incoming_args_rtx)
2799 new = arg_pointer_rtx, offset = in_arg_offset;
2800 else if (XEXP (x, 0) == virtual_stack_vars_rtx)
2801 new = frame_pointer_rtx, offset = var_offset;
2802 else if (XEXP (x, 0) == virtual_stack_dynamic_rtx)
2803 new = stack_pointer_rtx, offset = dynamic_offset;
2804 else if (XEXP (x, 0) == virtual_outgoing_args_rtx)
2805 new = stack_pointer_rtx, offset = out_arg_offset;
2808 /* We know the second operand is a constant. Unless the
2809 first operand is a REG (which has been already checked),
2810 it needs to be checked. */
2811 if (GET_CODE (XEXP (x, 0)) != REG)
2819 new_offset = plus_constant (XEXP (x, 1), offset);
2821 /* If the new constant is zero, try to replace the sum with just
2823 if (new_offset == const0_rtx
2824 && validate_change (object, loc, new, 0))
2827 /* Next try to replace the register and new offset.
2828 There are two changes to validate here and we can't assume that
2829 in the case of old offset equals new just changing the register
2830 will yield a valid insn. In the interests of a little efficiency,
2831 however, we only call validate change once (we don't queue up the
2832 changes and then call apply_change_group). */
2836 ? ! validate_change (object, &XEXP (x, 0), new, 0)
2837 : (XEXP (x, 0) = new,
2838 ! validate_change (object, &XEXP (x, 1), new_offset, 0)))
2846 /* Otherwise copy the new constant into a register and replace
2847 constant with that register. */
2848 temp = gen_reg_rtx (Pmode);
2850 if (validate_change (object, &XEXP (x, 1), temp, 0))
2851 emit_insn_before (gen_move_insn (temp, new_offset), object);
2854 /* If that didn't work, replace this expression with a
2855 register containing the sum. */
2858 new = gen_rtx (PLUS, Pmode, new, new_offset);
2861 temp = force_operand (new, NULL_RTX);
2865 emit_insns_before (seq, object);
2866 if (! validate_change (object, loc, temp, 0)
2867 && ! validate_replace_rtx (x, temp, object))
2875 /* Fall through to generic two-operand expression case. */
2881 case DIV: case UDIV:
2882 case MOD: case UMOD:
2883 case AND: case IOR: case XOR:
2884 case ROTATERT: case ROTATE:
2885 case ASHIFTRT: case LSHIFTRT: case ASHIFT:
2887 case GE: case GT: case GEU: case GTU:
2888 case LE: case LT: case LEU: case LTU:
2889 if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
2890 instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns);
2895 /* Most cases of MEM that convert to valid addresses have already been
2896 handled by our scan of regno_reg_rtx. The only special handling we
2897 need here is to make a copy of the rtx to ensure it isn't being
2898 shared if we have to change it to a pseudo.
2900 If the rtx is a simple reference to an address via a virtual register,
2901 it can potentially be shared. In such cases, first try to make it
2902 a valid address, which can also be shared. Otherwise, copy it and
2905 First check for common cases that need no processing. These are
2906 usually due to instantiation already being done on a previous instance
2910 if (CONSTANT_ADDRESS_P (temp)
2911 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2912 || temp == arg_pointer_rtx
2914 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2915 || temp == hard_frame_pointer_rtx
2917 || temp == frame_pointer_rtx)
2920 if (GET_CODE (temp) == PLUS
2921 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
2922 && (XEXP (temp, 0) == frame_pointer_rtx
2923 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2924 || XEXP (temp, 0) == hard_frame_pointer_rtx
2926 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2927 || XEXP (temp, 0) == arg_pointer_rtx
2932 if (temp == virtual_stack_vars_rtx
2933 || temp == virtual_incoming_args_rtx
2934 || (GET_CODE (temp) == PLUS
2935 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
2936 && (XEXP (temp, 0) == virtual_stack_vars_rtx
2937 || XEXP (temp, 0) == virtual_incoming_args_rtx)))
2939 /* This MEM may be shared. If the substitution can be done without
2940 the need to generate new pseudos, we want to do it in place
2941 so all copies of the shared rtx benefit. The call below will
2942 only make substitutions if the resulting address is still
2945 Note that we cannot pass X as the object in the recursive call
2946 since the insn being processed may not allow all valid
2947 addresses. However, if we were not passed on object, we can
2948 only modify X without copying it if X will have a valid
2951 ??? Also note that this can still lose if OBJECT is an insn that
2952 has less restrictions on an address that some other insn.
2953 In that case, we will modify the shared address. This case
2954 doesn't seem very likely, though. */
2956 if (instantiate_virtual_regs_1 (&XEXP (x, 0),
2957 object ? object : x, 0))
2960 /* Otherwise make a copy and process that copy. We copy the entire
2961 RTL expression since it might be a PLUS which could also be
2963 *loc = x = copy_rtx (x);
2966 /* Fall through to generic unary operation case. */
2970 case STRICT_LOW_PART:
2972 case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC:
2973 case SIGN_EXTEND: case ZERO_EXTEND:
2974 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE:
2975 case FLOAT: case FIX:
2976 case UNSIGNED_FIX: case UNSIGNED_FLOAT:
2980 /* These case either have just one operand or we know that we need not
2981 check the rest of the operands. */
2986 /* Try to replace with a PLUS. If that doesn't work, compute the sum
2987 in front of this insn and substitute the temporary. */
2988 if (x == virtual_incoming_args_rtx)
2989 new = arg_pointer_rtx, offset = in_arg_offset;
2990 else if (x == virtual_stack_vars_rtx)
2991 new = frame_pointer_rtx, offset = var_offset;
2992 else if (x == virtual_stack_dynamic_rtx)
2993 new = stack_pointer_rtx, offset = dynamic_offset;
2994 else if (x == virtual_outgoing_args_rtx)
2995 new = stack_pointer_rtx, offset = out_arg_offset;
2999 temp = plus_constant (new, offset);
3000 if (!validate_change (object, loc, temp, 0))
3006 temp = force_operand (temp, NULL_RTX);
3010 emit_insns_before (seq, object);
3011 if (! validate_change (object, loc, temp, 0)
3012 && ! validate_replace_rtx (x, temp, object))
3020 /* Scan all subexpressions. */
3021 fmt = GET_RTX_FORMAT (code);
3022 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
3025 if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns))
3028 else if (*fmt == 'E')
3029 for (j = 0; j < XVECLEN (x, i); j++)
3030 if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object,
3037 /* Optimization: assuming this function does not receive nonlocal gotos,
3038 delete the handlers for such, as well as the insns to establish
3039 and disestablish them. */
3045 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3047 /* Delete the handler by turning off the flag that would
3048 prevent jump_optimize from deleting it.
3049 Also permit deletion of the nonlocal labels themselves
3050 if nothing local refers to them. */
3051 if (GET_CODE (insn) == CODE_LABEL)
3055 LABEL_PRESERVE_P (insn) = 0;
3057 /* Remove it from the nonlocal_label list, to avoid confusing
3059 for (t = nonlocal_labels, last_t = 0; t;
3060 last_t = t, t = TREE_CHAIN (t))
3061 if (DECL_RTL (TREE_VALUE (t)) == insn)
3066 nonlocal_labels = TREE_CHAIN (nonlocal_labels);
3068 TREE_CHAIN (last_t) = TREE_CHAIN (t);
3071 if (GET_CODE (insn) == INSN
3072 && ((nonlocal_goto_handler_slot != 0
3073 && reg_mentioned_p (nonlocal_goto_handler_slot, PATTERN (insn)))
3074 || (nonlocal_goto_stack_level != 0
3075 && reg_mentioned_p (nonlocal_goto_stack_level,
3081 /* Return a list (chain of EXPR_LIST nodes) for the nonlocal labels
3082 of the current function. */
3085 nonlocal_label_rtx_list ()
3090 for (t = nonlocal_labels; t; t = TREE_CHAIN (t))
3091 x = gen_rtx (EXPR_LIST, VOIDmode, label_rtx (TREE_VALUE (t)), x);
3096 /* Output a USE for any register use in RTL.
3097 This is used with -noreg to mark the extent of lifespan
3098 of any registers used in a user-visible variable's DECL_RTL. */
3104 if (GET_CODE (rtl) == REG)
3105 /* This is a register variable. */
3106 emit_insn (gen_rtx (USE, VOIDmode, rtl));
3107 else if (GET_CODE (rtl) == MEM
3108 && GET_CODE (XEXP (rtl, 0)) == REG
3109 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
3110 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
3111 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
3112 /* This is a variable-sized structure. */
3113 emit_insn (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)));
3116 /* Like use_variable except that it outputs the USEs after INSN
3117 instead of at the end of the insn-chain. */
3120 use_variable_after (rtl, insn)
3123 if (GET_CODE (rtl) == REG)
3124 /* This is a register variable. */
3125 emit_insn_after (gen_rtx (USE, VOIDmode, rtl), insn);
3126 else if (GET_CODE (rtl) == MEM
3127 && GET_CODE (XEXP (rtl, 0)) == REG
3128 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
3129 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
3130 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
3131 /* This is a variable-sized structure. */
3132 emit_insn_after (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)), insn);
3138 return max_parm_reg;
3141 /* Return the first insn following those generated by `assign_parms'. */
3144 get_first_nonparm_insn ()
3147 return NEXT_INSN (last_parm_insn);
3148 return get_insns ();
3151 /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
3152 Crash if there is none. */
3155 get_first_block_beg ()
3157 register rtx searcher;
3158 register rtx insn = get_first_nonparm_insn ();
3160 for (searcher = insn; searcher; searcher = NEXT_INSN (searcher))
3161 if (GET_CODE (searcher) == NOTE
3162 && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG)
3165 abort (); /* Invalid call to this function. (See comments above.) */
3169 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
3170 This means a type for which function calls must pass an address to the
3171 function or get an address back from the function.
3172 EXP may be a type node or an expression (whose type is tested). */
3175 aggregate_value_p (exp)
3178 int i, regno, nregs;
3181 if (TREE_CODE_CLASS (TREE_CODE (exp)) == 't')
3184 type = TREE_TYPE (exp);
3186 if (RETURN_IN_MEMORY (type))
3188 if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
3190 /* Make sure we have suitable call-clobbered regs to return
3191 the value in; if not, we must return it in memory. */
3192 reg = hard_function_value (type, 0);
3193 regno = REGNO (reg);
3194 nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type));
3195 for (i = 0; i < nregs; i++)
3196 if (! call_used_regs[regno + i])
3201 /* Assign RTL expressions to the function's parameters.
3202 This may involve copying them into registers and using
3203 those registers as the RTL for them.
3205 If SECOND_TIME is non-zero it means that this function is being
3206 called a second time. This is done by integrate.c when a function's
3207 compilation is deferred. We need to come back here in case the
3208 FUNCTION_ARG macro computes items needed for the rest of the compilation
3209 (such as changing which registers are fixed or caller-saved). But suppress
3210 writing any insns or setting DECL_RTL of anything in this case. */
3213 assign_parms (fndecl, second_time)
3218 register rtx entry_parm = 0;
3219 register rtx stack_parm = 0;
3220 CUMULATIVE_ARGS args_so_far;
3221 enum machine_mode promoted_mode, passed_mode;
3222 enum machine_mode nominal_mode, promoted_nominal_mode;
3224 /* Total space needed so far for args on the stack,
3225 given as a constant and a tree-expression. */
3226 struct args_size stack_args_size;
3227 tree fntype = TREE_TYPE (fndecl);
3228 tree fnargs = DECL_ARGUMENTS (fndecl);
3229 /* This is used for the arg pointer when referring to stack args. */
3230 rtx internal_arg_pointer;
3231 /* This is a dummy PARM_DECL that we used for the function result if
3232 the function returns a structure. */
3233 tree function_result_decl = 0;
3234 int nparmregs = list_length (fnargs) + LAST_VIRTUAL_REGISTER + 1;
3235 int varargs_setup = 0;
3236 rtx conversion_insns = 0;
3237 /* FUNCTION_ARG may look at this variable. Since this is not
3238 expanding a call it will always be zero in this function. */
3239 int current_call_is_indirect = 0;
3241 /* Nonzero if the last arg is named `__builtin_va_alist',
3242 which is used on some machines for old-fashioned non-ANSI varargs.h;
3243 this should be stuck onto the stack as if it had arrived there. */
3245 = (current_function_varargs
3247 && (parm = tree_last (fnargs)) != 0
3249 && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
3250 "__builtin_va_alist")));
3252 /* Nonzero if function takes extra anonymous args.
3253 This means the last named arg must be on the stack
3254 right before the anonymous ones. */
3256 = (TYPE_ARG_TYPES (fntype) != 0
3257 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3258 != void_type_node));
3260 current_function_stdarg = stdarg;
3262 /* If the reg that the virtual arg pointer will be translated into is
3263 not a fixed reg or is the stack pointer, make a copy of the virtual
3264 arg pointer, and address parms via the copy. The frame pointer is
3265 considered fixed even though it is not marked as such.
3267 The second time through, simply use ap to avoid generating rtx. */
3269 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
3270 || ! (fixed_regs[ARG_POINTER_REGNUM]
3271 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM))
3273 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
3275 internal_arg_pointer = virtual_incoming_args_rtx;
3276 current_function_internal_arg_pointer = internal_arg_pointer;
3278 stack_args_size.constant = 0;
3279 stack_args_size.var = 0;
3281 /* If struct value address is treated as the first argument, make it so. */
3282 if (aggregate_value_p (DECL_RESULT (fndecl))
3283 && ! current_function_returns_pcc_struct
3284 && struct_value_incoming_rtx == 0)
3286 tree type = build_pointer_type (TREE_TYPE (fntype));
3288 function_result_decl = build_decl (PARM_DECL, NULL_TREE, type);
3290 DECL_ARG_TYPE (function_result_decl) = type;
3291 TREE_CHAIN (function_result_decl) = fnargs;
3292 fnargs = function_result_decl;
3295 parm_reg_stack_loc = (rtx *) oballoc (nparmregs * sizeof (rtx));
3296 bzero ((char *) parm_reg_stack_loc, nparmregs * sizeof (rtx));
3298 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
3299 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX);
3301 INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX);
3304 /* We haven't yet found an argument that we must push and pretend the
3306 current_function_pretend_args_size = 0;
3308 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
3310 int aggregate = AGGREGATE_TYPE_P (TREE_TYPE (parm));
3311 struct args_size stack_offset;
3312 struct args_size arg_size;
3313 int passed_pointer = 0;
3314 int did_conversion = 0;
3315 tree passed_type = DECL_ARG_TYPE (parm);
3316 tree nominal_type = TREE_TYPE (parm);
3318 /* Set LAST_NAMED if this is last named arg before some
3319 anonymous args. We treat it as if it were anonymous too. */
3320 int last_named = ((TREE_CHAIN (parm) == 0
3321 || DECL_NAME (TREE_CHAIN (parm)) == 0)
3322 && (stdarg || current_function_varargs));
3324 if (TREE_TYPE (parm) == error_mark_node
3325 /* This can happen after weird syntax errors
3326 or if an enum type is defined among the parms. */
3327 || TREE_CODE (parm) != PARM_DECL
3328 || passed_type == NULL)
3330 DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = gen_rtx (MEM, BLKmode,
3332 TREE_USED (parm) = 1;
3336 /* For varargs.h function, save info about regs and stack space
3337 used by the individual args, not including the va_alist arg. */
3338 if (hide_last_arg && last_named)
3339 current_function_args_info = args_so_far;
3341 /* Find mode of arg as it is passed, and mode of arg
3342 as it should be during execution of this function. */
3343 passed_mode = TYPE_MODE (passed_type);
3344 nominal_mode = TYPE_MODE (nominal_type);
3346 /* If the parm's mode is VOID, its value doesn't matter,
3347 and avoid the usual things like emit_move_insn that could crash. */
3348 if (nominal_mode == VOIDmode)
3350 DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = const0_rtx;
3354 /* If the parm is to be passed as a transparent union, use the
3355 type of the first field for the tests below. We have already
3356 verified that the modes are the same. */
3357 if (DECL_TRANSPARENT_UNION (parm)
3358 || TYPE_TRANSPARENT_UNION (passed_type))
3359 passed_type = TREE_TYPE (TYPE_FIELDS (passed_type));
3361 /* See if this arg was passed by invisible reference. It is if
3362 it is an object whose size depends on the contents of the
3363 object itself or if the machine requires these objects be passed
3366 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
3367 && contains_placeholder_p (TYPE_SIZE (passed_type)))
3368 || TREE_ADDRESSABLE (passed_type)
3369 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
3370 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
3371 passed_type, ! last_named)
3375 passed_type = nominal_type = build_pointer_type (passed_type);
3377 passed_mode = nominal_mode = Pmode;
3380 promoted_mode = passed_mode;
3382 #ifdef PROMOTE_FUNCTION_ARGS
3383 /* Compute the mode in which the arg is actually extended to. */
3384 promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1);
3387 /* Let machine desc say which reg (if any) the parm arrives in.
3388 0 means it arrives on the stack. */
3389 #ifdef FUNCTION_INCOMING_ARG
3390 entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
3391 passed_type, ! last_named);
3393 entry_parm = FUNCTION_ARG (args_so_far, promoted_mode,
3394 passed_type, ! last_named);
3397 if (entry_parm == 0)
3398 promoted_mode = passed_mode;
3400 #ifdef SETUP_INCOMING_VARARGS
3401 /* If this is the last named parameter, do any required setup for
3402 varargs or stdargs. We need to know about the case of this being an
3403 addressable type, in which case we skip the registers it
3404 would have arrived in.
3406 For stdargs, LAST_NAMED will be set for two parameters, the one that
3407 is actually the last named, and the dummy parameter. We only
3408 want to do this action once.
3410 Also, indicate when RTL generation is to be suppressed. */
3411 if (last_named && !varargs_setup)
3413 SETUP_INCOMING_VARARGS (args_so_far, promoted_mode, passed_type,
3414 current_function_pretend_args_size,
3420 /* Determine parm's home in the stack,
3421 in case it arrives in the stack or we should pretend it did.
3423 Compute the stack position and rtx where the argument arrives
3426 There is one complexity here: If this was a parameter that would
3427 have been passed in registers, but wasn't only because it is
3428 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
3429 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
3430 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
3431 0 as it was the previous time. */
3433 locate_and_pad_parm (promoted_mode, passed_type,
3434 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3437 #ifdef FUNCTION_INCOMING_ARG
3438 FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
3441 || varargs_setup)) != 0,
3443 FUNCTION_ARG (args_so_far, promoted_mode,
3445 ! last_named || varargs_setup) != 0,
3448 fndecl, &stack_args_size, &stack_offset, &arg_size);
3452 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
3454 if (offset_rtx == const0_rtx)
3455 stack_parm = gen_rtx (MEM, promoted_mode, internal_arg_pointer);
3457 stack_parm = gen_rtx (MEM, promoted_mode,
3458 gen_rtx (PLUS, Pmode,
3459 internal_arg_pointer, offset_rtx));
3461 /* If this is a memory ref that contains aggregate components,
3462 mark it as such for cse and loop optimize. */
3463 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3466 /* If this parameter was passed both in registers and in the stack,
3467 use the copy on the stack. */
3468 if (MUST_PASS_IN_STACK (promoted_mode, passed_type))
3471 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3472 /* If this parm was passed part in regs and part in memory,
3473 pretend it arrived entirely in memory
3474 by pushing the register-part onto the stack.
3476 In the special case of a DImode or DFmode that is split,
3477 we could put it together in a pseudoreg directly,
3478 but for now that's not worth bothering with. */
3482 int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, promoted_mode,
3483 passed_type, ! last_named);
3487 current_function_pretend_args_size
3488 = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
3489 / (PARM_BOUNDARY / BITS_PER_UNIT)
3490 * (PARM_BOUNDARY / BITS_PER_UNIT));
3493 move_block_from_reg (REGNO (entry_parm),
3494 validize_mem (stack_parm), nregs,
3495 int_size_in_bytes (TREE_TYPE (parm)));
3496 entry_parm = stack_parm;
3501 /* If we didn't decide this parm came in a register,
3502 by default it came on the stack. */
3503 if (entry_parm == 0)
3504 entry_parm = stack_parm;
3506 /* Record permanently how this parm was passed. */
3508 DECL_INCOMING_RTL (parm) = entry_parm;
3510 /* If there is actually space on the stack for this parm,
3511 count it in stack_args_size; otherwise set stack_parm to 0
3512 to indicate there is no preallocated stack slot for the parm. */
3514 if (entry_parm == stack_parm
3515 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
3516 /* On some machines, even if a parm value arrives in a register
3517 there is still an (uninitialized) stack slot allocated for it.
3519 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
3520 whether this parameter already has a stack slot allocated,
3521 because an arg block exists only if current_function_args_size
3522 is larger than some threshold, and we haven't calculated that
3523 yet. So, for now, we just assume that stack slots never exist
3525 || REG_PARM_STACK_SPACE (fndecl) > 0
3529 stack_args_size.constant += arg_size.constant;
3531 ADD_PARM_SIZE (stack_args_size, arg_size.var);
3534 /* No stack slot was pushed for this parm. */
3537 /* Update info on where next arg arrives in registers. */
3539 FUNCTION_ARG_ADVANCE (args_so_far, promoted_mode,
3540 passed_type, ! last_named);
3542 /* If this is our second time through, we are done with this parm. */
3546 /* If we can't trust the parm stack slot to be aligned enough
3547 for its ultimate type, don't use that slot after entry.
3548 We'll make another stack slot, if we need one. */
3550 int thisparm_boundary
3551 = FUNCTION_ARG_BOUNDARY (promoted_mode, passed_type);
3553 if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary)
3557 /* If parm was passed in memory, and we need to convert it on entry,
3558 don't store it back in that same slot. */
3560 && nominal_mode != BLKmode && nominal_mode != passed_mode)
3564 /* Now adjust STACK_PARM to the mode and precise location
3565 where this parameter should live during execution,
3566 if we discover that it must live in the stack during execution.
3567 To make debuggers happier on big-endian machines, we store
3568 the value in the last bytes of the space available. */
3570 if (nominal_mode != BLKmode && nominal_mode != passed_mode
3575 if (BYTES_BIG_ENDIAN
3576 && GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD)
3577 stack_offset.constant += (GET_MODE_SIZE (passed_mode)
3578 - GET_MODE_SIZE (nominal_mode));
3580 offset_rtx = ARGS_SIZE_RTX (stack_offset);
3581 if (offset_rtx == const0_rtx)
3582 stack_parm = gen_rtx (MEM, nominal_mode, internal_arg_pointer);
3584 stack_parm = gen_rtx (MEM, nominal_mode,
3585 gen_rtx (PLUS, Pmode,
3586 internal_arg_pointer, offset_rtx));
3588 /* If this is a memory ref that contains aggregate components,
3589 mark it as such for cse and loop optimize. */
3590 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3595 /* We need this "use" info, because the gcc-register->stack-register
3596 converter in reg-stack.c needs to know which registers are active
3597 at the start of the function call. The actual parameter loading
3598 instructions are not always available then anymore, since they might
3599 have been optimised away. */
3601 if (GET_CODE (entry_parm) == REG && !(hide_last_arg && last_named))
3602 emit_insn (gen_rtx (USE, GET_MODE (entry_parm), entry_parm));
3605 /* ENTRY_PARM is an RTX for the parameter as it arrives,
3606 in the mode in which it arrives.
3607 STACK_PARM is an RTX for a stack slot where the parameter can live
3608 during the function (in case we want to put it there).
3609 STACK_PARM is 0 if no stack slot was pushed for it.
3611 Now output code if necessary to convert ENTRY_PARM to
3612 the type in which this function declares it,
3613 and store that result in an appropriate place,
3614 which may be a pseudo reg, may be STACK_PARM,
3615 or may be a local stack slot if STACK_PARM is 0.
3617 Set DECL_RTL to that place. */
3619 if (nominal_mode == BLKmode)
3621 /* If a BLKmode arrives in registers, copy it to a stack slot. */
3622 if (GET_CODE (entry_parm) == REG)
3625 = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
3628 /* Note that we will be storing an integral number of words.
3629 So we have to be careful to ensure that we allocate an
3630 integral number of words. We do this below in the
3631 assign_stack_local if space was not allocated in the argument
3632 list. If it was, this will not work if PARM_BOUNDARY is not
3633 a multiple of BITS_PER_WORD. It isn't clear how to fix this
3634 if it becomes a problem. */
3636 if (stack_parm == 0)
3639 = assign_stack_local (GET_MODE (entry_parm),
3642 /* If this is a memory ref that contains aggregate
3643 components, mark it as such for cse and loop optimize. */
3644 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3647 else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
3650 if (TREE_READONLY (parm))
3651 RTX_UNCHANGING_P (stack_parm) = 1;
3653 move_block_from_reg (REGNO (entry_parm),
3654 validize_mem (stack_parm),
3655 size_stored / UNITS_PER_WORD,
3656 int_size_in_bytes (TREE_TYPE (parm)));
3658 DECL_RTL (parm) = stack_parm;
3660 else if (! ((obey_regdecls && ! DECL_REGISTER (parm)
3661 && ! DECL_INLINE (fndecl))
3662 /* layout_decl may set this. */
3663 || TREE_ADDRESSABLE (parm)
3664 || TREE_SIDE_EFFECTS (parm)
3665 /* If -ffloat-store specified, don't put explicit
3666 float variables into registers. */
3667 || (flag_float_store
3668 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
3669 /* Always assign pseudo to structure return or item passed
3670 by invisible reference. */
3671 || passed_pointer || parm == function_result_decl)
3673 /* Store the parm in a pseudoregister during the function, but we
3674 may need to do it in a wider mode. */
3676 register rtx parmreg;
3677 int regno, regnoi, regnor;
3679 unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
3681 promoted_nominal_mode
3682 = promote_mode (TREE_TYPE (parm), nominal_mode, &unsignedp, 0);
3684 parmreg = gen_reg_rtx (promoted_nominal_mode);
3685 REG_USERVAR_P (parmreg) = 1;
3687 /* If this was an item that we received a pointer to, set DECL_RTL
3692 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (passed_type)), parmreg);
3693 MEM_IN_STRUCT_P (DECL_RTL (parm)) = aggregate;
3696 DECL_RTL (parm) = parmreg;
3698 /* Copy the value into the register. */
3699 if (nominal_mode != passed_mode
3700 || promoted_nominal_mode != promoted_mode)
3702 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
3703 mode, by the caller. We now have to convert it to
3704 NOMINAL_MODE, if different. However, PARMREG may be in
3705 a diffent mode than NOMINAL_MODE if it is being stored
3708 If ENTRY_PARM is a hard register, it might be in a register
3709 not valid for operating in its mode (e.g., an odd-numbered
3710 register for a DFmode). In that case, moves are the only
3711 thing valid, so we can't do a convert from there. This
3712 occurs when the calling sequence allow such misaligned
3715 In addition, the conversion may involve a call, which could
3716 clobber parameters which haven't been copied to pseudo
3717 registers yet. Therefore, we must first copy the parm to
3718 a pseudo reg here, and save the conversion until after all
3719 parameters have been moved. */
3721 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
3723 emit_move_insn (tempreg, validize_mem (entry_parm));
3725 push_to_sequence (conversion_insns);
3726 tempreg = convert_to_mode (nominal_mode, tempreg, unsignedp);
3728 expand_assignment (parm,
3729 make_tree (nominal_type, tempreg), 0, 0);
3730 conversion_insns = get_insns ();
3735 emit_move_insn (parmreg, validize_mem (entry_parm));
3737 /* If we were passed a pointer but the actual value
3738 can safely live in a register, put it in one. */
3739 if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
3740 && ! ((obey_regdecls && ! DECL_REGISTER (parm)
3741 && ! DECL_INLINE (fndecl))
3742 /* layout_decl may set this. */
3743 || TREE_ADDRESSABLE (parm)
3744 || TREE_SIDE_EFFECTS (parm)
3745 /* If -ffloat-store specified, don't put explicit
3746 float variables into registers. */
3747 || (flag_float_store
3748 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))
3750 /* We can't use nominal_mode, because it will have been set to
3751 Pmode above. We must use the actual mode of the parm. */
3752 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
3753 REG_USERVAR_P (parmreg) = 1;
3754 emit_move_insn (parmreg, DECL_RTL (parm));
3755 DECL_RTL (parm) = parmreg;
3756 /* STACK_PARM is the pointer, not the parm, and PARMREG is
3760 #ifdef FUNCTION_ARG_CALLEE_COPIES
3761 /* If we are passed an arg by reference and it is our responsibility
3762 to make a copy, do it now.
3763 PASSED_TYPE and PASSED mode now refer to the pointer, not the
3764 original argument, so we must recreate them in the call to
3765 FUNCTION_ARG_CALLEE_COPIES. */
3766 /* ??? Later add code to handle the case that if the argument isn't
3767 modified, don't do the copy. */
3769 else if (passed_pointer
3770 && FUNCTION_ARG_CALLEE_COPIES (args_so_far,
3771 TYPE_MODE (DECL_ARG_TYPE (parm)),
3772 DECL_ARG_TYPE (parm),
3774 && ! TREE_ADDRESSABLE (DECL_ARG_TYPE (parm)))
3777 tree type = DECL_ARG_TYPE (parm);
3779 /* This sequence may involve a library call perhaps clobbering
3780 registers that haven't been copied to pseudos yet. */
3782 push_to_sequence (conversion_insns);
3784 if (TYPE_SIZE (type) == 0
3785 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
3786 /* This is a variable sized object. */
3787 copy = gen_rtx (MEM, BLKmode,
3788 allocate_dynamic_stack_space
3789 (expr_size (parm), NULL_RTX,
3790 TYPE_ALIGN (type)));
3792 copy = assign_stack_temp (TYPE_MODE (type),
3793 int_size_in_bytes (type), 1);
3794 MEM_IN_STRUCT_P (copy) = AGGREGATE_TYPE_P (type);
3796 store_expr (parm, copy, 0);
3797 emit_move_insn (parmreg, XEXP (copy, 0));
3798 conversion_insns = get_insns ();
3802 #endif /* FUNCTION_ARG_CALLEE_COPIES */
3804 /* In any case, record the parm's desired stack location
3805 in case we later discover it must live in the stack.
3807 If it is a COMPLEX value, store the stack location for both
3810 if (GET_CODE (parmreg) == CONCAT)
3811 regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1)));
3813 regno = REGNO (parmreg);
3815 if (regno >= nparmregs)
3818 int old_nparmregs = nparmregs;
3820 nparmregs = regno + 5;
3821 new = (rtx *) oballoc (nparmregs * sizeof (rtx));
3822 bcopy ((char *) parm_reg_stack_loc, (char *) new,
3823 old_nparmregs * sizeof (rtx));
3824 bzero ((char *) (new + old_nparmregs),
3825 (nparmregs - old_nparmregs) * sizeof (rtx));
3826 parm_reg_stack_loc = new;
3829 if (GET_CODE (parmreg) == CONCAT)
3831 enum machine_mode submode = GET_MODE (XEXP (parmreg, 0));
3833 regnor = REGNO (gen_realpart (submode, parmreg));
3834 regnoi = REGNO (gen_imagpart (submode, parmreg));
3836 if (stack_parm != 0)
3838 parm_reg_stack_loc[regnor]
3839 = gen_realpart (submode, stack_parm);
3840 parm_reg_stack_loc[regnoi]
3841 = gen_imagpart (submode, stack_parm);
3845 parm_reg_stack_loc[regnor] = 0;
3846 parm_reg_stack_loc[regnoi] = 0;
3850 parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
3852 /* Mark the register as eliminable if we did no conversion
3853 and it was copied from memory at a fixed offset,
3854 and the arg pointer was not copied to a pseudo-reg.
3855 If the arg pointer is a pseudo reg or the offset formed
3856 an invalid address, such memory-equivalences
3857 as we make here would screw up life analysis for it. */
3858 if (nominal_mode == passed_mode
3860 && GET_CODE (entry_parm) == MEM
3861 && entry_parm == stack_parm
3862 && stack_offset.var == 0
3863 && reg_mentioned_p (virtual_incoming_args_rtx,
3864 XEXP (entry_parm, 0)))
3866 rtx linsn = get_last_insn ();
3868 /* Mark complex types separately. */
3869 if (GET_CODE (parmreg) == CONCAT)
3872 = gen_rtx (EXPR_LIST, REG_EQUIV,
3873 parm_reg_stack_loc[regnoi], REG_NOTES (linsn));
3875 /* Now search backward for where we set the real part. */
3877 && ! reg_referenced_p (parm_reg_stack_loc[regnor],
3879 linsn = prev_nonnote_insn (linsn))
3883 = gen_rtx (EXPR_LIST, REG_EQUIV,
3884 parm_reg_stack_loc[regnor], REG_NOTES (linsn));
3888 = gen_rtx (EXPR_LIST, REG_EQUIV,
3889 entry_parm, REG_NOTES (linsn));
3892 /* For pointer data type, suggest pointer register. */
3893 if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE)
3894 mark_reg_pointer (parmreg,
3895 (TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm)))
3900 /* Value must be stored in the stack slot STACK_PARM
3901 during function execution. */
3903 if (promoted_mode != nominal_mode)
3905 /* Conversion is required. */
3906 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
3908 emit_move_insn (tempreg, validize_mem (entry_parm));
3910 push_to_sequence (conversion_insns);
3911 entry_parm = convert_to_mode (nominal_mode, tempreg,
3912 TREE_UNSIGNED (TREE_TYPE (parm)));
3913 conversion_insns = get_insns ();
3918 if (entry_parm != stack_parm)
3920 if (stack_parm == 0)
3923 = assign_stack_local (GET_MODE (entry_parm),
3924 GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
3925 /* If this is a memory ref that contains aggregate components,
3926 mark it as such for cse and loop optimize. */
3927 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3930 if (promoted_mode != nominal_mode)
3932 push_to_sequence (conversion_insns);
3933 emit_move_insn (validize_mem (stack_parm),
3934 validize_mem (entry_parm));
3935 conversion_insns = get_insns ();
3939 emit_move_insn (validize_mem (stack_parm),
3940 validize_mem (entry_parm));
3943 DECL_RTL (parm) = stack_parm;
3946 /* If this "parameter" was the place where we are receiving the
3947 function's incoming structure pointer, set up the result. */
3948 if (parm == function_result_decl)
3950 tree result = DECL_RESULT (fndecl);
3951 tree restype = TREE_TYPE (result);
3954 = gen_rtx (MEM, DECL_MODE (result), DECL_RTL (parm));
3956 MEM_IN_STRUCT_P (DECL_RTL (result)) = AGGREGATE_TYPE_P (restype);
3959 if (TREE_THIS_VOLATILE (parm))
3960 MEM_VOLATILE_P (DECL_RTL (parm)) = 1;
3961 if (TREE_READONLY (parm))
3962 RTX_UNCHANGING_P (DECL_RTL (parm)) = 1;
3965 /* Output all parameter conversion instructions (possibly including calls)
3966 now that all parameters have been copied out of hard registers. */
3967 emit_insns (conversion_insns);
3969 max_parm_reg = max_reg_num ();
3970 last_parm_insn = get_last_insn ();
3972 current_function_args_size = stack_args_size.constant;
3974 /* Adjust function incoming argument size for alignment and
3977 #ifdef REG_PARM_STACK_SPACE
3978 #ifndef MAYBE_REG_PARM_STACK_SPACE
3979 current_function_args_size = MAX (current_function_args_size,
3980 REG_PARM_STACK_SPACE (fndecl));
3984 #ifdef STACK_BOUNDARY
3985 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
3987 current_function_args_size
3988 = ((current_function_args_size + STACK_BYTES - 1)
3989 / STACK_BYTES) * STACK_BYTES;
3992 #ifdef ARGS_GROW_DOWNWARD
3993 current_function_arg_offset_rtx
3994 = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
3995 : expand_expr (size_binop (MINUS_EXPR, stack_args_size.var,
3996 size_int (-stack_args_size.constant)),
3997 NULL_RTX, VOIDmode, 0));
3999 current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
4002 /* See how many bytes, if any, of its args a function should try to pop
4005 current_function_pops_args = RETURN_POPS_ARGS (fndecl, TREE_TYPE (fndecl),
4006 current_function_args_size);
4008 /* For stdarg.h function, save info about
4009 regs and stack space used by the named args. */
4012 current_function_args_info = args_so_far;
4014 /* Set the rtx used for the function return value. Put this in its
4015 own variable so any optimizers that need this information don't have
4016 to include tree.h. Do this here so it gets done when an inlined
4017 function gets output. */
4019 current_function_return_rtx = DECL_RTL (DECL_RESULT (fndecl));
4022 /* Indicate whether REGNO is an incoming argument to the current function
4023 that was promoted to a wider mode. If so, return the RTX for the
4024 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
4025 that REGNO is promoted from and whether the promotion was signed or
4028 #ifdef PROMOTE_FUNCTION_ARGS
4031 promoted_input_arg (regno, pmode, punsignedp)
4033 enum machine_mode *pmode;
4038 for (arg = DECL_ARGUMENTS (current_function_decl); arg;
4039 arg = TREE_CHAIN (arg))
4040 if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
4041 && REGNO (DECL_INCOMING_RTL (arg)) == regno
4042 && TYPE_MODE (DECL_ARG_TYPE (arg)) == TYPE_MODE (TREE_TYPE (arg)))
4044 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
4045 int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
4047 mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1);
4048 if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
4049 && mode != DECL_MODE (arg))
4051 *pmode = DECL_MODE (arg);
4052 *punsignedp = unsignedp;
4053 return DECL_INCOMING_RTL (arg);
4062 /* Compute the size and offset from the start of the stacked arguments for a
4063 parm passed in mode PASSED_MODE and with type TYPE.
4065 INITIAL_OFFSET_PTR points to the current offset into the stacked
4068 The starting offset and size for this parm are returned in *OFFSET_PTR
4069 and *ARG_SIZE_PTR, respectively.
4071 IN_REGS is non-zero if the argument will be passed in registers. It will
4072 never be set if REG_PARM_STACK_SPACE is not defined.
4074 FNDECL is the function in which the argument was defined.
4076 There are two types of rounding that are done. The first, controlled by
4077 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
4078 list to be aligned to the specific boundary (in bits). This rounding
4079 affects the initial and starting offsets, but not the argument size.
4081 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
4082 optionally rounds the size of the parm to PARM_BOUNDARY. The
4083 initial offset is not affected by this rounding, while the size always
4084 is and the starting offset may be. */
4086 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
4087 initial_offset_ptr is positive because locate_and_pad_parm's
4088 callers pass in the total size of args so far as
4089 initial_offset_ptr. arg_size_ptr is always positive.*/
4092 locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
4093 initial_offset_ptr, offset_ptr, arg_size_ptr)
4094 enum machine_mode passed_mode;
4098 struct args_size *initial_offset_ptr;
4099 struct args_size *offset_ptr;
4100 struct args_size *arg_size_ptr;
4103 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
4104 enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
4105 int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
4106 int boundary_in_bytes = boundary / BITS_PER_UNIT;
4107 int reg_parm_stack_space = 0;
4109 #ifdef REG_PARM_STACK_SPACE
4110 /* If we have found a stack parm before we reach the end of the
4111 area reserved for registers, skip that area. */
4114 #ifdef MAYBE_REG_PARM_STACK_SPACE
4115 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
4117 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
4119 if (reg_parm_stack_space > 0)
4121 if (initial_offset_ptr->var)
4123 initial_offset_ptr->var
4124 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
4125 size_int (reg_parm_stack_space));
4126 initial_offset_ptr->constant = 0;
4128 else if (initial_offset_ptr->constant < reg_parm_stack_space)
4129 initial_offset_ptr->constant = reg_parm_stack_space;
4132 #endif /* REG_PARM_STACK_SPACE */
4134 arg_size_ptr->var = 0;
4135 arg_size_ptr->constant = 0;
4137 #ifdef ARGS_GROW_DOWNWARD
4138 if (initial_offset_ptr->var)
4140 offset_ptr->constant = 0;
4141 offset_ptr->var = size_binop (MINUS_EXPR, integer_zero_node,
4142 initial_offset_ptr->var);
4146 offset_ptr->constant = - initial_offset_ptr->constant;
4147 offset_ptr->var = 0;
4149 if (where_pad != none
4150 && (TREE_CODE (sizetree) != INTEGER_CST
4151 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
4152 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4153 SUB_PARM_SIZE (*offset_ptr, sizetree);
4154 if (where_pad != downward)
4155 pad_to_arg_alignment (offset_ptr, boundary);
4156 if (initial_offset_ptr->var)
4158 arg_size_ptr->var = size_binop (MINUS_EXPR,
4159 size_binop (MINUS_EXPR,
4161 initial_offset_ptr->var),
4166 arg_size_ptr->constant = (- initial_offset_ptr->constant -
4167 offset_ptr->constant);
4169 #else /* !ARGS_GROW_DOWNWARD */
4170 pad_to_arg_alignment (initial_offset_ptr, boundary);
4171 *offset_ptr = *initial_offset_ptr;
4173 #ifdef PUSH_ROUNDING
4174 if (passed_mode != BLKmode)
4175 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
4178 /* Pad_below needs the pre-rounded size to know how much to pad below
4179 so this must be done before rounding up. */
4180 if (where_pad == downward
4181 /* However, BLKmode args passed in regs have their padding done elsewhere.
4182 The stack slot must be able to hold the entire register. */
4183 && !(in_regs && passed_mode == BLKmode))
4184 pad_below (offset_ptr, passed_mode, sizetree);
4186 if (where_pad != none
4187 && (TREE_CODE (sizetree) != INTEGER_CST
4188 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
4189 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4191 ADD_PARM_SIZE (*arg_size_ptr, sizetree);
4192 #endif /* ARGS_GROW_DOWNWARD */
4195 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
4196 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
4199 pad_to_arg_alignment (offset_ptr, boundary)
4200 struct args_size *offset_ptr;
4203 int boundary_in_bytes = boundary / BITS_PER_UNIT;
4205 if (boundary > BITS_PER_UNIT)
4207 if (offset_ptr->var)
4210 #ifdef ARGS_GROW_DOWNWARD
4215 (ARGS_SIZE_TREE (*offset_ptr),
4216 boundary / BITS_PER_UNIT);
4217 offset_ptr->constant = 0; /*?*/
4220 offset_ptr->constant =
4221 #ifdef ARGS_GROW_DOWNWARD
4222 FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes);
4224 CEIL_ROUND (offset_ptr->constant, boundary_in_bytes);
4230 pad_below (offset_ptr, passed_mode, sizetree)
4231 struct args_size *offset_ptr;
4232 enum machine_mode passed_mode;
4235 if (passed_mode != BLKmode)
4237 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
4238 offset_ptr->constant
4239 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
4240 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
4241 - GET_MODE_SIZE (passed_mode));
4245 if (TREE_CODE (sizetree) != INTEGER_CST
4246 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
4248 /* Round the size up to multiple of PARM_BOUNDARY bits. */
4249 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4251 ADD_PARM_SIZE (*offset_ptr, s2);
4252 SUB_PARM_SIZE (*offset_ptr, sizetree);
4258 round_down (value, divisor)
4262 return size_binop (MULT_EXPR,
4263 size_binop (FLOOR_DIV_EXPR, value, size_int (divisor)),
4264 size_int (divisor));
4267 /* Walk the tree of blocks describing the binding levels within a function
4268 and warn about uninitialized variables.
4269 This is done after calling flow_analysis and before global_alloc
4270 clobbers the pseudo-regs to hard regs. */
4273 uninitialized_vars_warning (block)
4276 register tree decl, sub;
4277 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
4279 if (TREE_CODE (decl) == VAR_DECL
4280 /* These warnings are unreliable for and aggregates
4281 because assigning the fields one by one can fail to convince
4282 flow.c that the entire aggregate was initialized.
4283 Unions are troublesome because members may be shorter. */
4284 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl))
4285 && DECL_RTL (decl) != 0
4286 && GET_CODE (DECL_RTL (decl)) == REG
4287 && regno_uninitialized (REGNO (DECL_RTL (decl))))
4288 warning_with_decl (decl,
4289 "`%s' might be used uninitialized in this function");
4290 if (TREE_CODE (decl) == VAR_DECL
4291 && DECL_RTL (decl) != 0
4292 && GET_CODE (DECL_RTL (decl)) == REG
4293 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
4294 warning_with_decl (decl,
4295 "variable `%s' might be clobbered by `longjmp' or `vfork'");
4297 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
4298 uninitialized_vars_warning (sub);
4301 /* Do the appropriate part of uninitialized_vars_warning
4302 but for arguments instead of local variables. */
4305 setjmp_args_warning ()
4308 for (decl = DECL_ARGUMENTS (current_function_decl);
4309 decl; decl = TREE_CHAIN (decl))
4310 if (DECL_RTL (decl) != 0
4311 && GET_CODE (DECL_RTL (decl)) == REG
4312 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
4313 warning_with_decl (decl, "argument `%s' might be clobbered by `longjmp' or `vfork'");
4316 /* If this function call setjmp, put all vars into the stack
4317 unless they were declared `register'. */
4320 setjmp_protect (block)
4323 register tree decl, sub;
4324 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
4325 if ((TREE_CODE (decl) == VAR_DECL
4326 || TREE_CODE (decl) == PARM_DECL)
4327 && DECL_RTL (decl) != 0
4328 && GET_CODE (DECL_RTL (decl)) == REG
4329 /* If this variable came from an inline function, it must be
4330 that it's life doesn't overlap the setjmp. If there was a
4331 setjmp in the function, it would already be in memory. We
4332 must exclude such variable because their DECL_RTL might be
4333 set to strange things such as virtual_stack_vars_rtx. */
4334 && ! DECL_FROM_INLINE (decl)
4336 #ifdef NON_SAVING_SETJMP
4337 /* If longjmp doesn't restore the registers,
4338 don't put anything in them. */
4342 ! DECL_REGISTER (decl)))
4343 put_var_into_stack (decl);
4344 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
4345 setjmp_protect (sub);
4348 /* Like the previous function, but for args instead of local variables. */
4351 setjmp_protect_args ()
4353 register tree decl, sub;
4354 for (decl = DECL_ARGUMENTS (current_function_decl);
4355 decl; decl = TREE_CHAIN (decl))
4356 if ((TREE_CODE (decl) == VAR_DECL
4357 || TREE_CODE (decl) == PARM_DECL)
4358 && DECL_RTL (decl) != 0
4359 && GET_CODE (DECL_RTL (decl)) == REG
4361 /* If longjmp doesn't restore the registers,
4362 don't put anything in them. */
4363 #ifdef NON_SAVING_SETJMP
4367 ! DECL_REGISTER (decl)))
4368 put_var_into_stack (decl);
4371 /* Return the context-pointer register corresponding to DECL,
4372 or 0 if it does not need one. */
4375 lookup_static_chain (decl)
4378 tree context = decl_function_context (decl);
4384 /* We treat inline_function_decl as an alias for the current function
4385 because that is the inline function whose vars, types, etc.
4386 are being merged into the current function.
4387 See expand_inline_function. */
4388 if (context == current_function_decl || context == inline_function_decl)
4389 return virtual_stack_vars_rtx;
4391 for (link = context_display; link; link = TREE_CHAIN (link))
4392 if (TREE_PURPOSE (link) == context)
4393 return RTL_EXPR_RTL (TREE_VALUE (link));
4398 /* Convert a stack slot address ADDR for variable VAR
4399 (from a containing function)
4400 into an address valid in this function (using a static chain). */
4403 fix_lexical_addr (addr, var)
4409 tree context = decl_function_context (var);
4410 struct function *fp;
4413 /* If this is the present function, we need not do anything. */
4414 if (context == current_function_decl || context == inline_function_decl)
4417 for (fp = outer_function_chain; fp; fp = fp->next)
4418 if (fp->decl == context)
4424 /* Decode given address as base reg plus displacement. */
4425 if (GET_CODE (addr) == REG)
4426 basereg = addr, displacement = 0;
4427 else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
4428 basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
4432 /* We accept vars reached via the containing function's
4433 incoming arg pointer and via its stack variables pointer. */
4434 if (basereg == fp->internal_arg_pointer)
4436 /* If reached via arg pointer, get the arg pointer value
4437 out of that function's stack frame.
4439 There are two cases: If a separate ap is needed, allocate a
4440 slot in the outer function for it and dereference it that way.
4441 This is correct even if the real ap is actually a pseudo.
4442 Otherwise, just adjust the offset from the frame pointer to
4445 #ifdef NEED_SEPARATE_AP
4448 if (fp->arg_pointer_save_area == 0)
4449 fp->arg_pointer_save_area
4450 = assign_outer_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0, fp);
4452 addr = fix_lexical_addr (XEXP (fp->arg_pointer_save_area, 0), var);
4453 addr = memory_address (Pmode, addr);
4455 base = copy_to_reg (gen_rtx (MEM, Pmode, addr));
4457 displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
4458 base = lookup_static_chain (var);
4462 else if (basereg == virtual_stack_vars_rtx)
4464 /* This is the same code as lookup_static_chain, duplicated here to
4465 avoid an extra call to decl_function_context. */
4468 for (link = context_display; link; link = TREE_CHAIN (link))
4469 if (TREE_PURPOSE (link) == context)
4471 base = RTL_EXPR_RTL (TREE_VALUE (link));
4479 /* Use same offset, relative to appropriate static chain or argument
4481 return plus_constant (base, displacement);
4484 /* Return the address of the trampoline for entering nested fn FUNCTION.
4485 If necessary, allocate a trampoline (in the stack frame)
4486 and emit rtl to initialize its contents (at entry to this function). */
4489 trampoline_address (function)
4495 struct function *fp;
4498 /* Find an existing trampoline and return it. */
4499 for (link = trampoline_list; link; link = TREE_CHAIN (link))
4500 if (TREE_PURPOSE (link) == function)
4502 round_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0));
4504 for (fp = outer_function_chain; fp; fp = fp->next)
4505 for (link = fp->trampoline_list; link; link = TREE_CHAIN (link))
4506 if (TREE_PURPOSE (link) == function)
4508 tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
4510 return round_trampoline_addr (tramp);
4513 /* None exists; we must make one. */
4515 /* Find the `struct function' for the function containing FUNCTION. */
4517 fn_context = decl_function_context (function);
4518 if (fn_context != current_function_decl)
4519 for (fp = outer_function_chain; fp; fp = fp->next)
4520 if (fp->decl == fn_context)
4523 /* Allocate run-time space for this trampoline
4524 (usually in the defining function's stack frame). */
4525 #ifdef ALLOCATE_TRAMPOLINE
4526 tramp = ALLOCATE_TRAMPOLINE (fp);
4528 /* If rounding needed, allocate extra space
4529 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
4530 #ifdef TRAMPOLINE_ALIGNMENT
4531 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE + TRAMPOLINE_ALIGNMENT - 1)
4533 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
4536 tramp = assign_outer_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0, fp);
4538 tramp = assign_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0);
4541 /* Record the trampoline for reuse and note it for later initialization
4542 by expand_function_end. */
4545 push_obstacks (fp->function_maybepermanent_obstack,
4546 fp->function_maybepermanent_obstack);
4547 rtlexp = make_node (RTL_EXPR);
4548 RTL_EXPR_RTL (rtlexp) = tramp;
4549 fp->trampoline_list = tree_cons (function, rtlexp, fp->trampoline_list);
4554 /* Make the RTL_EXPR node temporary, not momentary, so that the
4555 trampoline_list doesn't become garbage. */
4556 int momentary = suspend_momentary ();
4557 rtlexp = make_node (RTL_EXPR);
4558 resume_momentary (momentary);
4560 RTL_EXPR_RTL (rtlexp) = tramp;
4561 trampoline_list = tree_cons (function, rtlexp, trampoline_list);
4564 tramp = fix_lexical_addr (XEXP (tramp, 0), function);
4565 return round_trampoline_addr (tramp);
4568 /* Given a trampoline address,
4569 round it to multiple of TRAMPOLINE_ALIGNMENT. */
4572 round_trampoline_addr (tramp)
4575 #ifdef TRAMPOLINE_ALIGNMENT
4576 /* Round address up to desired boundary. */
4577 rtx temp = gen_reg_rtx (Pmode);
4578 temp = expand_binop (Pmode, add_optab, tramp,
4579 GEN_INT (TRAMPOLINE_ALIGNMENT - 1),
4580 temp, 0, OPTAB_LIB_WIDEN);
4581 tramp = expand_binop (Pmode, and_optab, temp,
4582 GEN_INT (- TRAMPOLINE_ALIGNMENT),
4583 temp, 0, OPTAB_LIB_WIDEN);
4588 /* The functions identify_blocks and reorder_blocks provide a way to
4589 reorder the tree of BLOCK nodes, for optimizers that reshuffle or
4590 duplicate portions of the RTL code. Call identify_blocks before
4591 changing the RTL, and call reorder_blocks after. */
4593 /* Put all this function's BLOCK nodes including those that are chained
4594 onto the first block into a vector, and return it.
4595 Also store in each NOTE for the beginning or end of a block
4596 the index of that block in the vector.
4597 The arguments are BLOCK, the chain of top-level blocks of the function,
4598 and INSNS, the insn chain of the function. */
4601 identify_blocks (block, insns)
4609 int next_block_number = 1;
4610 int current_block_number = 1;
4616 n_blocks = all_blocks (block, 0);
4617 block_vector = (tree *) xmalloc (n_blocks * sizeof (tree));
4618 block_stack = (int *) alloca (n_blocks * sizeof (int));
4620 all_blocks (block, block_vector);
4622 for (insn = insns; insn; insn = NEXT_INSN (insn))
4623 if (GET_CODE (insn) == NOTE)
4625 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
4627 block_stack[depth++] = current_block_number;
4628 current_block_number = next_block_number;
4629 NOTE_BLOCK_NUMBER (insn) = next_block_number++;
4631 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
4633 current_block_number = block_stack[--depth];
4634 NOTE_BLOCK_NUMBER (insn) = current_block_number;
4638 if (n_blocks != next_block_number)
4641 return block_vector;
4644 /* Given BLOCK_VECTOR which was returned by identify_blocks,
4645 and a revised instruction chain, rebuild the tree structure
4646 of BLOCK nodes to correspond to the new order of RTL.
4647 The new block tree is inserted below TOP_BLOCK.
4648 Returns the current top-level block. */
4651 reorder_blocks (block_vector, block, insns)
4656 tree current_block = block;
4659 if (block_vector == 0)
4662 /* Prune the old trees away, so that it doesn't get in the way. */
4663 BLOCK_SUBBLOCKS (current_block) = 0;
4664 BLOCK_CHAIN (current_block) = 0;
4666 for (insn = insns; insn; insn = NEXT_INSN (insn))
4667 if (GET_CODE (insn) == NOTE)
4669 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
4671 tree block = block_vector[NOTE_BLOCK_NUMBER (insn)];
4672 /* If we have seen this block before, copy it. */
4673 if (TREE_ASM_WRITTEN (block))
4674 block = copy_node (block);
4675 BLOCK_SUBBLOCKS (block) = 0;
4676 TREE_ASM_WRITTEN (block) = 1;
4677 BLOCK_SUPERCONTEXT (block) = current_block;
4678 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
4679 BLOCK_SUBBLOCKS (current_block) = block;
4680 current_block = block;
4681 NOTE_SOURCE_FILE (insn) = 0;
4683 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
4685 BLOCK_SUBBLOCKS (current_block)
4686 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
4687 current_block = BLOCK_SUPERCONTEXT (current_block);
4688 NOTE_SOURCE_FILE (insn) = 0;
4692 BLOCK_SUBBLOCKS (current_block)
4693 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
4694 return current_block;
4697 /* Reverse the order of elements in the chain T of blocks,
4698 and return the new head of the chain (old last element). */
4704 register tree prev = 0, decl, next;
4705 for (decl = t; decl; decl = next)
4707 next = BLOCK_CHAIN (decl);
4708 BLOCK_CHAIN (decl) = prev;
4714 /* Count the subblocks of the list starting with BLOCK, and list them
4715 all into the vector VECTOR. Also clear TREE_ASM_WRITTEN in all
4719 all_blocks (block, vector)
4727 TREE_ASM_WRITTEN (block) = 0;
4729 /* Record this block. */
4731 vector[n_blocks] = block;
4735 /* Record the subblocks, and their subblocks... */
4736 n_blocks += all_blocks (BLOCK_SUBBLOCKS (block),
4737 vector ? vector + n_blocks : 0);
4738 block = BLOCK_CHAIN (block);
4744 /* Build bytecode call descriptor for function SUBR. */
4747 bc_build_calldesc (subr)
4750 tree calldesc = 0, arg;
4753 /* Build the argument description vector in reverse order. */
4754 DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
4757 for (arg = DECL_ARGUMENTS (subr); arg; arg = TREE_CHAIN (arg))
4761 calldesc = tree_cons ((tree) 0, size_in_bytes (TREE_TYPE (arg)), calldesc);
4762 calldesc = tree_cons ((tree) 0, bc_runtime_type_code (TREE_TYPE (arg)), calldesc);
4765 DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
4767 /* Prepend the function's return type. */
4768 calldesc = tree_cons ((tree) 0,
4769 size_in_bytes (TREE_TYPE (TREE_TYPE (subr))),
4772 calldesc = tree_cons ((tree) 0,
4773 bc_runtime_type_code (TREE_TYPE (TREE_TYPE (subr))),
4776 /* Prepend the arg count. */
4777 calldesc = tree_cons ((tree) 0, build_int_2 (nargs, 0), calldesc);
4779 /* Output the call description vector and get its address. */
4780 calldesc = build_nt (CONSTRUCTOR, (tree) 0, calldesc);
4781 TREE_TYPE (calldesc) = build_array_type (integer_type_node,
4782 build_index_type (build_int_2 (nargs * 2, 0)));
4784 return output_constant_def (calldesc);
4788 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
4789 and initialize static variables for generating RTL for the statements
4793 init_function_start (subr, filename, line)
4800 if (output_bytecode)
4802 this_function_decl = subr;
4803 this_function_calldesc = bc_build_calldesc (subr);
4804 local_vars_size = 0;
4806 max_stack_depth = 0;
4807 stmt_expr_depth = 0;
4811 init_stmt_for_function ();
4813 cse_not_expected = ! optimize;
4815 /* Caller save not needed yet. */
4816 caller_save_needed = 0;
4818 /* No stack slots have been made yet. */
4819 stack_slot_list = 0;
4821 /* There is no stack slot for handling nonlocal gotos. */
4822 nonlocal_goto_handler_slot = 0;
4823 nonlocal_goto_stack_level = 0;
4825 /* No labels have been declared for nonlocal use. */
4826 nonlocal_labels = 0;
4828 /* No function calls so far in this function. */
4829 function_call_count = 0;
4831 /* No parm regs have been allocated.
4832 (This is important for output_inline_function.) */
4833 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
4835 /* Initialize the RTL mechanism. */
4838 /* Initialize the queue of pending postincrement and postdecrements,
4839 and some other info in expr.c. */
4842 /* We haven't done register allocation yet. */
4845 init_const_rtx_hash_table ();
4847 current_function_name = (*decl_printable_name) (subr, &junk);
4849 /* Nonzero if this is a nested function that uses a static chain. */
4851 current_function_needs_context
4852 = (decl_function_context (current_function_decl) != 0);
4854 /* Set if a call to setjmp is seen. */
4855 current_function_calls_setjmp = 0;
4857 /* Set if a call to longjmp is seen. */
4858 current_function_calls_longjmp = 0;
4860 current_function_calls_alloca = 0;
4861 current_function_has_nonlocal_label = 0;
4862 current_function_has_nonlocal_goto = 0;
4863 current_function_contains_functions = 0;
4865 current_function_returns_pcc_struct = 0;
4866 current_function_returns_struct = 0;
4867 current_function_epilogue_delay_list = 0;
4868 current_function_uses_const_pool = 0;
4869 current_function_uses_pic_offset_table = 0;
4871 /* We have not yet needed to make a label to jump to for tail-recursion. */
4872 tail_recursion_label = 0;
4874 /* We haven't had a need to make a save area for ap yet. */
4876 arg_pointer_save_area = 0;
4878 /* No stack slots allocated yet. */
4881 /* No SAVE_EXPRs in this function yet. */
4884 /* No RTL_EXPRs in this function yet. */
4887 /* Set up to allocate temporaries. */
4890 /* Within function body, compute a type's size as soon it is laid out. */
4891 immediate_size_expand++;
4893 /* We haven't made any trampolines for this function yet. */
4894 trampoline_list = 0;
4896 init_pending_stack_adjust ();
4897 inhibit_defer_pop = 0;
4899 current_function_outgoing_args_size = 0;
4901 /* Prevent ever trying to delete the first instruction of a function.
4902 Also tell final how to output a linenum before the function prologue. */
4903 emit_line_note (filename, line);
4905 /* Make sure first insn is a note even if we don't want linenums.
4906 This makes sure the first insn will never be deleted.
4907 Also, final expects a note to appear there. */
4908 emit_note (NULL_PTR, NOTE_INSN_DELETED);
4910 /* Set flags used by final.c. */
4911 if (aggregate_value_p (DECL_RESULT (subr)))
4913 #ifdef PCC_STATIC_STRUCT_RETURN
4914 current_function_returns_pcc_struct = 1;
4916 current_function_returns_struct = 1;
4919 /* Warn if this value is an aggregate type,
4920 regardless of which calling convention we are using for it. */
4921 if (warn_aggregate_return
4922 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
4923 warning ("function returns an aggregate");
4925 current_function_returns_pointer
4926 = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
4928 /* Indicate that we need to distinguish between the return value of the
4929 present function and the return value of a function being called. */
4930 rtx_equal_function_value_matters = 1;
4932 /* Indicate that we have not instantiated virtual registers yet. */
4933 virtuals_instantiated = 0;
4935 /* Indicate we have no need of a frame pointer yet. */
4936 frame_pointer_needed = 0;
4938 /* By default assume not varargs or stdarg. */
4939 current_function_varargs = 0;
4940 current_function_stdarg = 0;
4943 /* Indicate that the current function uses extra args
4944 not explicitly mentioned in the argument list in any fashion. */
4949 current_function_varargs = 1;
4952 /* Expand a call to __main at the beginning of a possible main function. */
4954 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
4955 #undef HAS_INIT_SECTION
4956 #define HAS_INIT_SECTION
4960 expand_main_function ()
4962 if (!output_bytecode)
4964 /* The zero below avoids a possible parse error */
4966 #if !defined (HAS_INIT_SECTION)
4967 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, NAME__MAIN), 0,
4969 #endif /* not HAS_INIT_SECTION */
4973 extern struct obstack permanent_obstack;
4975 /* Expand start of bytecode function. See comment at
4976 expand_function_start below for details. */
4979 bc_expand_function_start (subr, parms_have_cleanups)
4981 int parms_have_cleanups;
4983 char label[20], *name;
4988 if (TREE_PUBLIC (subr))
4989 bc_globalize_label (IDENTIFIER_POINTER (DECL_NAME (subr)));
4991 #ifdef DEBUG_PRINT_CODE
4992 fprintf (stderr, "\n<func %s>\n", IDENTIFIER_POINTER (DECL_NAME (subr)));
4995 for (argsz = 0, thisarg = DECL_ARGUMENTS (subr); thisarg; thisarg = TREE_CHAIN (thisarg))
4997 if (DECL_RTL (thisarg))
4998 abort (); /* Should be NULL here I think. */
4999 else if (TREE_CONSTANT (DECL_SIZE (thisarg)))
5001 DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
5002 argsz += TREE_INT_CST_LOW (DECL_SIZE (thisarg));
5006 /* Variable-sized objects are pointers to their storage. */
5007 DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
5008 argsz += POINTER_SIZE;
5012 bc_begin_function (bc_xstrdup (IDENTIFIER_POINTER (DECL_NAME (subr))));
5014 ASM_GENERATE_INTERNAL_LABEL (label, "LX", nlab);
5017 name = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
5018 this_function_callinfo = bc_gen_rtx (name, 0, (struct bc_label *) 0);
5019 this_function_bytecode =
5020 bc_emit_trampoline (BYTECODE_LABEL (this_function_callinfo));
5024 /* Expand end of bytecode function. See details the comment of
5025 expand_function_end(), below. */
5028 bc_expand_function_end ()
5032 expand_null_return ();
5034 /* Emit any fixup code. This must be done before the call to
5035 to BC_END_FUNCTION (), since that will cause the bytecode
5036 segment to be finished off and closed. */
5038 expand_fixups (NULL_RTX);
5040 ptrconsts = bc_end_function ();
5042 bc_align_const (2 /* INT_ALIGN */);
5044 /* If this changes also make sure to change bc-interp.h! */
5046 bc_emit_const_labeldef (BYTECODE_LABEL (this_function_callinfo));
5047 bc_emit_const ((char *) &max_stack_depth, sizeof max_stack_depth);
5048 bc_emit_const ((char *) &local_vars_size, sizeof local_vars_size);
5049 bc_emit_const_labelref (this_function_bytecode, 0);
5050 bc_emit_const_labelref (ptrconsts, 0);
5051 bc_emit_const_labelref (BYTECODE_LABEL (this_function_calldesc), 0);
5055 /* Start the RTL for a new function, and set variables used for
5057 SUBR is the FUNCTION_DECL node.
5058 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
5059 the function's parameters, which must be run at any return statement. */
5062 expand_function_start (subr, parms_have_cleanups)
5064 int parms_have_cleanups;
5070 if (output_bytecode)
5072 bc_expand_function_start (subr, parms_have_cleanups);
5076 /* Make sure volatile mem refs aren't considered
5077 valid operands of arithmetic insns. */
5078 init_recog_no_volatile ();
5080 /* If function gets a static chain arg, store it in the stack frame.
5081 Do this first, so it gets the first stack slot offset. */
5082 if (current_function_needs_context)
5084 last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
5086 #ifdef SMALL_REGISTER_CLASSES
5087 /* Delay copying static chain if it is not a register to avoid
5088 conflicts with regs used for parameters. */
5089 if (GET_CODE (static_chain_incoming_rtx) == REG)
5091 emit_move_insn (last_ptr, static_chain_incoming_rtx);
5094 /* If the parameters of this function need cleaning up, get a label
5095 for the beginning of the code which executes those cleanups. This must
5096 be done before doing anything with return_label. */
5097 if (parms_have_cleanups)
5098 cleanup_label = gen_label_rtx ();
5102 /* Make the label for return statements to jump to, if this machine
5103 does not have a one-instruction return and uses an epilogue,
5104 or if it returns a structure, or if it has parm cleanups. */
5106 if (cleanup_label == 0 && HAVE_return
5107 && ! current_function_returns_pcc_struct
5108 && ! (current_function_returns_struct && ! optimize))
5111 return_label = gen_label_rtx ();
5113 return_label = gen_label_rtx ();
5116 /* Initialize rtx used to return the value. */
5117 /* Do this before assign_parms so that we copy the struct value address
5118 before any library calls that assign parms might generate. */
5120 /* Decide whether to return the value in memory or in a register. */
5121 if (aggregate_value_p (DECL_RESULT (subr)))
5123 /* Returning something that won't go in a register. */
5124 register rtx value_address = 0;
5126 #ifdef PCC_STATIC_STRUCT_RETURN
5127 if (current_function_returns_pcc_struct)
5129 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
5130 value_address = assemble_static_space (size);
5135 /* Expect to be passed the address of a place to store the value.
5136 If it is passed as an argument, assign_parms will take care of
5138 if (struct_value_incoming_rtx)
5140 value_address = gen_reg_rtx (Pmode);
5141 emit_move_insn (value_address, struct_value_incoming_rtx);
5146 DECL_RTL (DECL_RESULT (subr))
5147 = gen_rtx (MEM, DECL_MODE (DECL_RESULT (subr)), value_address);
5148 MEM_IN_STRUCT_P (DECL_RTL (DECL_RESULT (subr)))
5149 = AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
5152 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
5153 /* If return mode is void, this decl rtl should not be used. */
5154 DECL_RTL (DECL_RESULT (subr)) = 0;
5155 else if (parms_have_cleanups)
5157 /* If function will end with cleanup code for parms,
5158 compute the return values into a pseudo reg,
5159 which we will copy into the true return register
5160 after the cleanups are done. */
5162 enum machine_mode mode = DECL_MODE (DECL_RESULT (subr));
5164 #ifdef PROMOTE_FUNCTION_RETURN
5165 tree type = TREE_TYPE (DECL_RESULT (subr));
5166 int unsignedp = TREE_UNSIGNED (type);
5168 mode = promote_mode (type, mode, &unsignedp, 1);
5171 DECL_RTL (DECL_RESULT (subr)) = gen_reg_rtx (mode);
5174 /* Scalar, returned in a register. */
5176 #ifdef FUNCTION_OUTGOING_VALUE
5177 DECL_RTL (DECL_RESULT (subr))
5178 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
5180 DECL_RTL (DECL_RESULT (subr))
5181 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
5184 /* Mark this reg as the function's return value. */
5185 if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG)
5187 REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1;
5188 /* Needed because we may need to move this to memory
5189 in case it's a named return value whose address is taken. */
5190 DECL_REGISTER (DECL_RESULT (subr)) = 1;
5194 /* Initialize rtx for parameters and local variables.
5195 In some cases this requires emitting insns. */
5197 assign_parms (subr, 0);
5199 #ifdef SMALL_REGISTER_CLASSES
5200 /* Copy the static chain now if it wasn't a register. The delay is to
5201 avoid conflicts with the parameter passing registers. */
5203 if (current_function_needs_context)
5204 if (GET_CODE (static_chain_incoming_rtx) != REG)
5205 emit_move_insn (last_ptr, static_chain_incoming_rtx);
5208 /* The following was moved from init_function_start.
5209 The move is supposed to make sdb output more accurate. */
5210 /* Indicate the beginning of the function body,
5211 as opposed to parm setup. */
5212 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_BEG);
5214 /* If doing stupid allocation, mark parms as born here. */
5216 if (GET_CODE (get_last_insn ()) != NOTE)
5217 emit_note (NULL_PTR, NOTE_INSN_DELETED);
5218 parm_birth_insn = get_last_insn ();
5222 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
5223 use_variable (regno_reg_rtx[i]);
5225 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
5226 use_variable (current_function_internal_arg_pointer);
5229 /* Fetch static chain values for containing functions. */
5230 tem = decl_function_context (current_function_decl);
5231 /* If not doing stupid register allocation copy the static chain
5232 pointer into a pseudo. If we have small register classes, copy the
5233 value from memory if static_chain_incoming_rtx is a REG. If we do
5234 stupid register allocation, we use the stack address generated above. */
5235 if (tem && ! obey_regdecls)
5237 #ifdef SMALL_REGISTER_CLASSES
5238 /* If the static chain originally came in a register, put it back
5239 there, then move it out in the next insn. The reason for
5240 this peculiar code is to satisfy function integration. */
5241 if (GET_CODE (static_chain_incoming_rtx) == REG)
5242 emit_move_insn (static_chain_incoming_rtx, last_ptr);
5245 last_ptr = copy_to_reg (static_chain_incoming_rtx);
5248 context_display = 0;
5251 tree rtlexp = make_node (RTL_EXPR);
5253 RTL_EXPR_RTL (rtlexp) = last_ptr;
5254 context_display = tree_cons (tem, rtlexp, context_display);
5255 tem = decl_function_context (tem);
5258 /* Chain thru stack frames, assuming pointer to next lexical frame
5259 is found at the place we always store it. */
5260 #ifdef FRAME_GROWS_DOWNWARD
5261 last_ptr = plus_constant (last_ptr, - GET_MODE_SIZE (Pmode));
5263 last_ptr = copy_to_reg (gen_rtx (MEM, Pmode,
5264 memory_address (Pmode, last_ptr)));
5266 /* If we are not optimizing, ensure that we know that this
5267 piece of context is live over the entire function. */
5269 save_expr_regs = gen_rtx (EXPR_LIST, VOIDmode, last_ptr,
5273 /* After the display initializations is where the tail-recursion label
5274 should go, if we end up needing one. Ensure we have a NOTE here
5275 since some things (like trampolines) get placed before this. */
5276 tail_recursion_reentry = emit_note (NULL_PTR, NOTE_INSN_DELETED);
5278 /* Evaluate now the sizes of any types declared among the arguments. */
5279 for (tem = nreverse (get_pending_sizes ()); tem; tem = TREE_CHAIN (tem))
5280 expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode, 0);
5282 /* Make sure there is a line number after the function entry setup code. */
5283 force_next_line_note ();
5286 /* Generate RTL for the end of the current function.
5287 FILENAME and LINE are the current position in the source file.
5289 It is up to language-specific callers to do cleanups for parameters--
5290 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */
5293 expand_function_end (filename, line, end_bindings)
5301 static rtx initial_trampoline;
5303 if (output_bytecode)
5305 bc_expand_function_end ();
5309 #ifdef NON_SAVING_SETJMP
5310 /* Don't put any variables in registers if we call setjmp
5311 on a machine that fails to restore the registers. */
5312 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
5314 if (DECL_INITIAL (current_function_decl) != error_mark_node)
5315 setjmp_protect (DECL_INITIAL (current_function_decl));
5317 setjmp_protect_args ();
5321 /* Save the argument pointer if a save area was made for it. */
5322 if (arg_pointer_save_area)
5324 rtx x = gen_move_insn (arg_pointer_save_area, virtual_incoming_args_rtx);
5325 emit_insn_before (x, tail_recursion_reentry);
5328 /* Initialize any trampolines required by this function. */
5329 for (link = trampoline_list; link; link = TREE_CHAIN (link))
5331 tree function = TREE_PURPOSE (link);
5332 rtx context = lookup_static_chain (function);
5333 rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
5336 /* First make sure this compilation has a template for
5337 initializing trampolines. */
5338 if (initial_trampoline == 0)
5340 end_temporary_allocation ();
5342 = gen_rtx (MEM, BLKmode, assemble_trampoline_template ());
5343 resume_temporary_allocation ();
5346 /* Generate insns to initialize the trampoline. */
5348 tramp = change_address (initial_trampoline, BLKmode,
5349 round_trampoline_addr (XEXP (tramp, 0)));
5350 emit_block_move (tramp, initial_trampoline, GEN_INT (TRAMPOLINE_SIZE),
5351 FUNCTION_BOUNDARY / BITS_PER_UNIT);
5352 INITIALIZE_TRAMPOLINE (XEXP (tramp, 0),
5353 XEXP (DECL_RTL (function), 0), context);
5357 /* Put those insns at entry to the containing function (this one). */
5358 emit_insns_before (seq, tail_recursion_reentry);
5361 /* Warn about unused parms if extra warnings were specified. */
5362 if (warn_unused && extra_warnings)
5366 for (decl = DECL_ARGUMENTS (current_function_decl);
5367 decl; decl = TREE_CHAIN (decl))
5368 if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
5369 && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
5370 warning_with_decl (decl, "unused parameter `%s'");
5373 /* Delete handlers for nonlocal gotos if nothing uses them. */
5374 if (nonlocal_goto_handler_slot != 0 && !current_function_has_nonlocal_label)
5377 /* End any sequences that failed to be closed due to syntax errors. */
5378 while (in_sequence_p ())
5381 /* Outside function body, can't compute type's actual size
5382 until next function's body starts. */
5383 immediate_size_expand--;
5385 /* If doing stupid register allocation,
5386 mark register parms as dying here. */
5391 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
5392 use_variable (regno_reg_rtx[i]);
5394 /* Likewise for the regs of all the SAVE_EXPRs in the function. */
5396 for (tem = save_expr_regs; tem; tem = XEXP (tem, 1))
5398 use_variable (XEXP (tem, 0));
5399 use_variable_after (XEXP (tem, 0), parm_birth_insn);
5402 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
5403 use_variable (current_function_internal_arg_pointer);
5406 clear_pending_stack_adjust ();
5407 do_pending_stack_adjust ();
5409 /* Mark the end of the function body.
5410 If control reaches this insn, the function can drop through
5411 without returning a value. */
5412 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_END);
5414 /* Output a linenumber for the end of the function.
5415 SDB depends on this. */
5416 emit_line_note_force (filename, line);
5418 /* Output the label for the actual return from the function,
5419 if one is expected. This happens either because a function epilogue
5420 is used instead of a return instruction, or because a return was done
5421 with a goto in order to run local cleanups, or because of pcc-style
5422 structure returning. */
5425 emit_label (return_label);
5427 /* C++ uses this. */
5429 expand_end_bindings (0, 0, 0);
5431 /* If we had calls to alloca, and this machine needs
5432 an accurate stack pointer to exit the function,
5433 insert some code to save and restore the stack pointer. */
5434 #ifdef EXIT_IGNORE_STACK
5435 if (! EXIT_IGNORE_STACK)
5437 if (current_function_calls_alloca)
5441 emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
5442 emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
5445 /* If scalar return value was computed in a pseudo-reg,
5446 copy that to the hard return register. */
5447 if (DECL_RTL (DECL_RESULT (current_function_decl)) != 0
5448 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG
5449 && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl)))
5450 >= FIRST_PSEUDO_REGISTER))
5452 rtx real_decl_result;
5454 #ifdef FUNCTION_OUTGOING_VALUE
5456 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
5457 current_function_decl);
5460 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
5461 current_function_decl);
5463 REG_FUNCTION_VALUE_P (real_decl_result) = 1;
5464 emit_move_insn (real_decl_result,
5465 DECL_RTL (DECL_RESULT (current_function_decl)));
5466 emit_insn (gen_rtx (USE, VOIDmode, real_decl_result));
5469 /* If returning a structure, arrange to return the address of the value
5470 in a place where debuggers expect to find it.
5472 If returning a structure PCC style,
5473 the caller also depends on this value.
5474 And current_function_returns_pcc_struct is not necessarily set. */
5475 if (current_function_returns_struct
5476 || current_function_returns_pcc_struct)
5478 rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
5479 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
5480 #ifdef FUNCTION_OUTGOING_VALUE
5482 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
5483 current_function_decl);
5486 = FUNCTION_VALUE (build_pointer_type (type),
5487 current_function_decl);
5490 /* Mark this as a function return value so integrate will delete the
5491 assignment and USE below when inlining this function. */
5492 REG_FUNCTION_VALUE_P (outgoing) = 1;
5494 emit_move_insn (outgoing, value_address);
5495 use_variable (outgoing);
5498 /* Output a return insn if we are using one.
5499 Otherwise, let the rtl chain end here, to drop through
5500 into the epilogue. */
5505 emit_jump_insn (gen_return ());
5510 /* Fix up any gotos that jumped out to the outermost
5511 binding level of the function.
5512 Must follow emitting RETURN_LABEL. */
5514 /* If you have any cleanups to do at this point,
5515 and they need to create temporary variables,
5516 then you will lose. */
5517 expand_fixups (get_insns ());
5520 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
5522 static int *prologue;
5523 static int *epilogue;
5525 /* Create an array that records the INSN_UIDs of INSNS (either a sequence
5526 or a single insn). */
5529 record_insns (insns)
5534 if (GET_CODE (insns) == SEQUENCE)
5536 int len = XVECLEN (insns, 0);
5537 vec = (int *) oballoc ((len + 1) * sizeof (int));
5540 vec[len] = INSN_UID (XVECEXP (insns, 0, len));
5544 vec = (int *) oballoc (2 * sizeof (int));
5545 vec[0] = INSN_UID (insns);
5551 /* Determine how many INSN_UIDs in VEC are part of INSN. */
5554 contains (insn, vec)
5560 if (GET_CODE (insn) == INSN
5561 && GET_CODE (PATTERN (insn)) == SEQUENCE)
5564 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
5565 for (j = 0; vec[j]; j++)
5566 if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == vec[j])
5572 for (j = 0; vec[j]; j++)
5573 if (INSN_UID (insn) == vec[j])
5579 /* Generate the prologue and epilogue RTL if the machine supports it. Thread
5580 this into place with notes indicating where the prologue ends and where
5581 the epilogue begins. Update the basic block information when possible. */
5584 thread_prologue_and_epilogue_insns (f)
5587 #ifdef HAVE_prologue
5590 rtx head, seq, insn;
5592 /* The first insn (a NOTE_INSN_DELETED) is followed by zero or more
5593 prologue insns and a NOTE_INSN_PROLOGUE_END. */
5594 emit_note_after (NOTE_INSN_PROLOGUE_END, f);
5595 seq = gen_prologue ();
5596 head = emit_insn_after (seq, f);
5598 /* Include the new prologue insns in the first block. Ignore them
5599 if they form a basic block unto themselves. */
5600 if (basic_block_head && n_basic_blocks
5601 && GET_CODE (basic_block_head[0]) != CODE_LABEL)
5602 basic_block_head[0] = NEXT_INSN (f);
5604 /* Retain a map of the prologue insns. */
5605 prologue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : head);
5611 #ifdef HAVE_epilogue
5614 rtx insn = get_last_insn ();
5615 rtx prev = prev_nonnote_insn (insn);
5617 /* If we end with a BARRIER, we don't need an epilogue. */
5618 if (! (prev && GET_CODE (prev) == BARRIER))
5624 /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, the
5625 epilogue insns, the USE insns at the end of a function,
5626 the jump insn that returns, and then a BARRIER. */
5628 /* Move the USE insns at the end of a function onto a list. */
5630 && GET_CODE (prev) == INSN
5631 && GET_CODE (PATTERN (prev)) == USE)
5634 prev = prev_nonnote_insn (prev);
5636 NEXT_INSN (PREV_INSN (tem)) = NEXT_INSN (tem);
5637 PREV_INSN (NEXT_INSN (tem)) = PREV_INSN (tem);
5640 NEXT_INSN (tem) = first_use;
5641 PREV_INSN (first_use) = tem;
5648 emit_barrier_after (insn);
5650 seq = gen_epilogue ();
5651 tail = emit_jump_insn_after (seq, insn);
5653 /* Insert the USE insns immediately before the return insn, which
5654 must be the first instruction before the final barrier. */
5657 tem = prev_nonnote_insn (get_last_insn ());
5658 NEXT_INSN (PREV_INSN (tem)) = first_use;
5659 PREV_INSN (first_use) = PREV_INSN (tem);
5660 PREV_INSN (tem) = last_use;
5661 NEXT_INSN (last_use) = tem;
5664 emit_note_after (NOTE_INSN_EPILOGUE_BEG, insn);
5666 /* Include the new epilogue insns in the last block. Ignore
5667 them if they form a basic block unto themselves. */
5668 if (basic_block_end && n_basic_blocks
5669 && GET_CODE (basic_block_end[n_basic_blocks - 1]) != JUMP_INSN)
5670 basic_block_end[n_basic_blocks - 1] = tail;
5672 /* Retain a map of the epilogue insns. */
5673 epilogue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : tail);
5681 /* Reposition the prologue-end and epilogue-begin notes after instruction
5682 scheduling and delayed branch scheduling. */
5685 reposition_prologue_and_epilogue_notes (f)
5688 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
5689 /* Reposition the prologue and epilogue notes. */
5697 register rtx insn, note = 0;
5699 /* Scan from the beginning until we reach the last prologue insn.
5700 We apparently can't depend on basic_block_{head,end} after
5702 for (len = 0; prologue[len]; len++)
5704 for (insn = f; len && insn; insn = NEXT_INSN (insn))
5706 if (GET_CODE (insn) == NOTE)
5708 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
5711 else if ((len -= contains (insn, prologue)) == 0)
5713 /* Find the prologue-end note if we haven't already, and
5714 move it to just after the last prologue insn. */
5717 for (note = insn; note = NEXT_INSN (note);)
5718 if (GET_CODE (note) == NOTE
5719 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
5722 next = NEXT_INSN (note);
5723 prev = PREV_INSN (note);
5725 NEXT_INSN (prev) = next;
5727 PREV_INSN (next) = prev;
5728 add_insn_after (note, insn);
5735 register rtx insn, note = 0;
5737 /* Scan from the end until we reach the first epilogue insn.
5738 We apparently can't depend on basic_block_{head,end} after
5740 for (len = 0; epilogue[len]; len++)
5742 for (insn = get_last_insn (); len && insn; insn = PREV_INSN (insn))
5744 if (GET_CODE (insn) == NOTE)
5746 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
5749 else if ((len -= contains (insn, epilogue)) == 0)
5751 /* Find the epilogue-begin note if we haven't already, and
5752 move it to just before the first epilogue insn. */
5755 for (note = insn; note = PREV_INSN (note);)
5756 if (GET_CODE (note) == NOTE
5757 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
5760 next = NEXT_INSN (note);
5761 prev = PREV_INSN (note);
5763 NEXT_INSN (prev) = next;
5765 PREV_INSN (next) = prev;
5766 add_insn_after (note, PREV_INSN (insn));
5771 #endif /* HAVE_prologue or HAVE_epilogue */