1 /* Expands front end tree to back end RTL for GNU C-Compiler
2 Copyright (C) 1987, 88, 89, 91-95, 1996 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.
926 DONT_PROMOTE is 1 if we should not promote values in register
930 assign_temp (type, keep, memory_required, dont_promote)
936 enum machine_mode mode = TYPE_MODE (type);
937 int unsignedp = TREE_UNSIGNED (type);
939 if (mode == BLKmode || memory_required)
941 int size = int_size_in_bytes (type);
944 /* Unfortunately, we don't yet know how to allocate variable-sized
945 temporaries. However, sometimes we have a fixed upper limit on
946 the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that
947 instead. This is the case for Chill variable-sized strings. */
948 if (size == -1 && TREE_CODE (type) == ARRAY_TYPE
949 && TYPE_ARRAY_MAX_SIZE (type) != NULL_TREE
950 && TREE_CODE (TYPE_ARRAY_MAX_SIZE (type)) == INTEGER_CST)
951 size = TREE_INT_CST_LOW (TYPE_ARRAY_MAX_SIZE (type));
953 tmp = assign_stack_temp (mode, size, keep);
954 MEM_IN_STRUCT_P (tmp) = AGGREGATE_TYPE_P (type);
958 #ifndef PROMOTE_FOR_CALL_ONLY
960 mode = promote_mode (type, mode, &unsignedp, 0);
963 return gen_reg_rtx (mode);
966 /* Combine temporary stack slots which are adjacent on the stack.
968 This allows for better use of already allocated stack space. This is only
969 done for BLKmode slots because we can be sure that we won't have alignment
970 problems in this case. */
973 combine_temp_slots ()
975 struct temp_slot *p, *q;
976 struct temp_slot *prev_p, *prev_q;
977 /* Determine where to free back to after this function. */
978 rtx free_pointer = rtx_alloc (CONST_INT);
980 for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots)
983 if (! p->in_use && GET_MODE (p->slot) == BLKmode)
984 for (q = p->next, prev_q = p; q; q = prev_q->next)
987 if (! q->in_use && GET_MODE (q->slot) == BLKmode)
989 if (p->base_offset + p->full_size == q->base_offset)
991 /* Q comes after P; combine Q into P. */
993 p->full_size += q->full_size;
996 else if (q->base_offset + q->full_size == p->base_offset)
998 /* P comes after Q; combine P into Q. */
1000 q->full_size += p->full_size;
1005 /* Either delete Q or advance past it. */
1007 prev_q->next = q->next;
1011 /* Either delete P or advance past it. */
1015 prev_p->next = p->next;
1017 temp_slots = p->next;
1023 /* Free all the RTL made by plus_constant. */
1024 rtx_free (free_pointer);
1027 /* Find the temp slot corresponding to the object at address X. */
1029 static struct temp_slot *
1030 find_temp_slot_from_address (x)
1033 struct temp_slot *p;
1036 for (p = temp_slots; p; p = p->next)
1040 else if (XEXP (p->slot, 0) == x
1044 else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST)
1045 for (next = p->address; next; next = XEXP (next, 1))
1046 if (XEXP (next, 0) == x)
1053 /* Indicate that NEW is an alternate way of referring to the temp slot
1054 that previous was known by OLD. */
1057 update_temp_slot_address (old, new)
1060 struct temp_slot *p = find_temp_slot_from_address (old);
1062 /* If none, return. Else add NEW as an alias. */
1065 else if (p->address == 0)
1069 if (GET_CODE (p->address) != EXPR_LIST)
1070 p->address = gen_rtx (EXPR_LIST, VOIDmode, p->address, NULL_RTX);
1072 p->address = gen_rtx (EXPR_LIST, VOIDmode, new, p->address);
1076 /* If X could be a reference to a temporary slot, mark the fact that its
1077 address was taken. */
1080 mark_temp_addr_taken (x)
1083 struct temp_slot *p;
1088 /* If X is not in memory or is at a constant address, it cannot be in
1089 a temporary slot. */
1090 if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1093 p = find_temp_slot_from_address (XEXP (x, 0));
1098 /* If X could be a reference to a temporary slot, mark that slot as
1099 belonging to the to one level higher than the current level. If X
1100 matched one of our slots, just mark that one. Otherwise, we can't
1101 easily predict which it is, so upgrade all of them. Kept slots
1102 need not be touched.
1104 This is called when an ({...}) construct occurs and a statement
1105 returns a value in memory. */
1108 preserve_temp_slots (x)
1111 struct temp_slot *p = 0;
1113 /* If there is no result, we still might have some objects whose address
1114 were taken, so we need to make sure they stay around. */
1117 for (p = temp_slots; p; p = p->next)
1118 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1124 /* If X is a register that is being used as a pointer, see if we have
1125 a temporary slot we know it points to. To be consistent with
1126 the code below, we really should preserve all non-kept slots
1127 if we can't find a match, but that seems to be much too costly. */
1128 if (GET_CODE (x) == REG && REGNO_POINTER_FLAG (REGNO (x)))
1129 p = find_temp_slot_from_address (x);
1131 /* If X is not in memory or is at a constant address, it cannot be in
1132 a temporary slot, but it can contain something whose address was
1134 if (p == 0 && (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))))
1136 for (p = temp_slots; p; p = p->next)
1137 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1143 /* First see if we can find a match. */
1145 p = find_temp_slot_from_address (XEXP (x, 0));
1149 /* Move everything at our level whose address was taken to our new
1150 level in case we used its address. */
1151 struct temp_slot *q;
1153 if (p->level == temp_slot_level)
1155 for (q = temp_slots; q; q = q->next)
1156 if (q != p && q->addr_taken && q->level == p->level)
1165 /* Otherwise, preserve all non-kept slots at this level. */
1166 for (p = temp_slots; p; p = p->next)
1167 if (p->in_use && p->level == temp_slot_level && ! p->keep)
1171 /* X is the result of an RTL_EXPR. If it is a temporary slot associated
1172 with that RTL_EXPR, promote it into a temporary slot at the present
1173 level so it will not be freed when we free slots made in the
1177 preserve_rtl_expr_result (x)
1180 struct temp_slot *p;
1182 /* If X is not in memory or is at a constant address, it cannot be in
1183 a temporary slot. */
1184 if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1187 /* If we can find a match, move it to our level unless it is already at
1189 p = find_temp_slot_from_address (XEXP (x, 0));
1192 p->level = MIN (p->level, temp_slot_level);
1199 /* Free all temporaries used so far. This is normally called at the end
1200 of generating code for a statement. Don't free any temporaries
1201 currently in use for an RTL_EXPR that hasn't yet been emitted.
1202 We could eventually do better than this since it can be reused while
1203 generating the same RTL_EXPR, but this is complex and probably not
1209 struct temp_slot *p;
1211 for (p = temp_slots; p; p = p->next)
1212 if (p->in_use && p->level == temp_slot_level && ! p->keep
1213 && p->rtl_expr == 0)
1216 combine_temp_slots ();
1219 /* Free all temporary slots used in T, an RTL_EXPR node. */
1222 free_temps_for_rtl_expr (t)
1225 struct temp_slot *p;
1227 for (p = temp_slots; p; p = p->next)
1228 if (p->rtl_expr == t)
1231 combine_temp_slots ();
1234 /* Push deeper into the nesting level for stack temporaries. */
1242 /* Pop a temporary nesting level. All slots in use in the current level
1248 struct temp_slot *p;
1250 for (p = temp_slots; p; p = p->next)
1251 if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0)
1254 combine_temp_slots ();
1259 /* Initialize temporary slots. */
1264 /* We have not allocated any temporaries yet. */
1266 temp_slot_level = 0;
1267 target_temp_slot_level = 0;
1270 /* Retroactively move an auto variable from a register to a stack slot.
1271 This is done when an address-reference to the variable is seen. */
1274 put_var_into_stack (decl)
1278 enum machine_mode promoted_mode, decl_mode;
1279 struct function *function = 0;
1282 if (output_bytecode)
1285 context = decl_function_context (decl);
1287 /* Get the current rtl used for this object and it's original mode. */
1288 reg = TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl) : DECL_RTL (decl);
1290 /* No need to do anything if decl has no rtx yet
1291 since in that case caller is setting TREE_ADDRESSABLE
1292 and a stack slot will be assigned when the rtl is made. */
1296 /* Get the declared mode for this object. */
1297 decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl))
1298 : DECL_MODE (decl));
1299 /* Get the mode it's actually stored in. */
1300 promoted_mode = GET_MODE (reg);
1302 /* If this variable comes from an outer function,
1303 find that function's saved context. */
1304 if (context != current_function_decl)
1305 for (function = outer_function_chain; function; function = function->next)
1306 if (function->decl == context)
1309 /* If this is a variable-size object with a pseudo to address it,
1310 put that pseudo into the stack, if the var is nonlocal. */
1311 if (DECL_NONLOCAL (decl)
1312 && GET_CODE (reg) == MEM
1313 && GET_CODE (XEXP (reg, 0)) == REG
1314 && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
1316 reg = XEXP (reg, 0);
1317 decl_mode = promoted_mode = GET_MODE (reg);
1320 /* Now we should have a value that resides in one or more pseudo regs. */
1322 if (GET_CODE (reg) == REG)
1323 put_reg_into_stack (function, reg, TREE_TYPE (decl),
1324 promoted_mode, decl_mode, TREE_SIDE_EFFECTS (decl));
1325 else if (GET_CODE (reg) == CONCAT)
1327 /* A CONCAT contains two pseudos; put them both in the stack.
1328 We do it so they end up consecutive. */
1329 enum machine_mode part_mode = GET_MODE (XEXP (reg, 0));
1330 tree part_type = TREE_TYPE (TREE_TYPE (decl));
1331 #ifdef FRAME_GROWS_DOWNWARD
1332 /* Since part 0 should have a lower address, do it second. */
1333 put_reg_into_stack (function, XEXP (reg, 1), part_type, part_mode,
1334 part_mode, TREE_SIDE_EFFECTS (decl));
1335 put_reg_into_stack (function, XEXP (reg, 0), part_type, part_mode,
1336 part_mode, TREE_SIDE_EFFECTS (decl));
1338 put_reg_into_stack (function, XEXP (reg, 0), part_type, part_mode,
1339 part_mode, TREE_SIDE_EFFECTS (decl));
1340 put_reg_into_stack (function, XEXP (reg, 1), part_type, part_mode,
1341 part_mode, TREE_SIDE_EFFECTS (decl));
1344 /* Change the CONCAT into a combined MEM for both parts. */
1345 PUT_CODE (reg, MEM);
1346 MEM_VOLATILE_P (reg) = MEM_VOLATILE_P (XEXP (reg, 0));
1348 /* The two parts are in memory order already.
1349 Use the lower parts address as ours. */
1350 XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0);
1351 /* Prevent sharing of rtl that might lose. */
1352 if (GET_CODE (XEXP (reg, 0)) == PLUS)
1353 XEXP (reg, 0) = copy_rtx (XEXP (reg, 0));
1357 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1358 into the stack frame of FUNCTION (0 means the current function).
1359 DECL_MODE is the machine mode of the user-level data type.
1360 PROMOTED_MODE is the machine mode of the register.
1361 VOLATILE_P is nonzero if this is for a "volatile" decl. */
1364 put_reg_into_stack (function, reg, type, promoted_mode, decl_mode, volatile_p)
1365 struct function *function;
1368 enum machine_mode promoted_mode, decl_mode;
1375 if (REGNO (reg) < function->max_parm_reg)
1376 new = function->parm_reg_stack_loc[REGNO (reg)];
1378 new = assign_outer_stack_local (decl_mode, GET_MODE_SIZE (decl_mode),
1383 if (REGNO (reg) < max_parm_reg)
1384 new = parm_reg_stack_loc[REGNO (reg)];
1386 new = assign_stack_local (decl_mode, GET_MODE_SIZE (decl_mode), 0);
1389 PUT_MODE (reg, decl_mode);
1390 XEXP (reg, 0) = XEXP (new, 0);
1391 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1392 MEM_VOLATILE_P (reg) = volatile_p;
1393 PUT_CODE (reg, MEM);
1395 /* If this is a memory ref that contains aggregate components,
1396 mark it as such for cse and loop optimize. */
1397 MEM_IN_STRUCT_P (reg) = AGGREGATE_TYPE_P (type);
1399 /* Now make sure that all refs to the variable, previously made
1400 when it was a register, are fixed up to be valid again. */
1403 struct var_refs_queue *temp;
1405 /* Variable is inherited; fix it up when we get back to its function. */
1406 push_obstacks (function->function_obstack,
1407 function->function_maybepermanent_obstack);
1409 /* See comment in restore_tree_status in tree.c for why this needs to be
1410 on saveable obstack. */
1412 = (struct var_refs_queue *) savealloc (sizeof (struct var_refs_queue));
1413 temp->modified = reg;
1414 temp->promoted_mode = promoted_mode;
1415 temp->unsignedp = TREE_UNSIGNED (type);
1416 temp->next = function->fixup_var_refs_queue;
1417 function->fixup_var_refs_queue = temp;
1421 /* Variable is local; fix it up now. */
1422 fixup_var_refs (reg, promoted_mode, TREE_UNSIGNED (type));
1426 fixup_var_refs (var, promoted_mode, unsignedp)
1428 enum machine_mode promoted_mode;
1432 rtx first_insn = get_insns ();
1433 struct sequence_stack *stack = sequence_stack;
1434 tree rtl_exps = rtl_expr_chain;
1436 /* Must scan all insns for stack-refs that exceed the limit. */
1437 fixup_var_refs_insns (var, promoted_mode, unsignedp, first_insn, stack == 0);
1439 /* Scan all pending sequences too. */
1440 for (; stack; stack = stack->next)
1442 push_to_sequence (stack->first);
1443 fixup_var_refs_insns (var, promoted_mode, unsignedp,
1444 stack->first, stack->next != 0);
1445 /* Update remembered end of sequence
1446 in case we added an insn at the end. */
1447 stack->last = get_last_insn ();
1451 /* Scan all waiting RTL_EXPRs too. */
1452 for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
1454 rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
1455 if (seq != const0_rtx && seq != 0)
1457 push_to_sequence (seq);
1458 fixup_var_refs_insns (var, promoted_mode, unsignedp, seq, 0);
1464 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1465 some part of an insn. Return a struct fixup_replacement whose OLD
1466 value is equal to X. Allocate a new structure if no such entry exists. */
1468 static struct fixup_replacement *
1469 find_fixup_replacement (replacements, x)
1470 struct fixup_replacement **replacements;
1473 struct fixup_replacement *p;
1475 /* See if we have already replaced this. */
1476 for (p = *replacements; p && p->old != x; p = p->next)
1481 p = (struct fixup_replacement *) oballoc (sizeof (struct fixup_replacement));
1484 p->next = *replacements;
1491 /* Scan the insn-chain starting with INSN for refs to VAR
1492 and fix them up. TOPLEVEL is nonzero if this chain is the
1493 main chain of insns for the current function. */
1496 fixup_var_refs_insns (var, promoted_mode, unsignedp, insn, toplevel)
1498 enum machine_mode promoted_mode;
1507 rtx next = NEXT_INSN (insn);
1509 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1511 /* If this is a CLOBBER of VAR, delete it.
1513 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1514 and REG_RETVAL notes too. */
1515 if (GET_CODE (PATTERN (insn)) == CLOBBER
1516 && XEXP (PATTERN (insn), 0) == var)
1518 if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0)
1519 /* The REG_LIBCALL note will go away since we are going to
1520 turn INSN into a NOTE, so just delete the
1521 corresponding REG_RETVAL note. */
1522 remove_note (XEXP (note, 0),
1523 find_reg_note (XEXP (note, 0), REG_RETVAL,
1526 /* In unoptimized compilation, we shouldn't call delete_insn
1527 except in jump.c doing warnings. */
1528 PUT_CODE (insn, NOTE);
1529 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1530 NOTE_SOURCE_FILE (insn) = 0;
1533 /* The insn to load VAR from a home in the arglist
1534 is now a no-op. When we see it, just delete it. */
1536 && GET_CODE (PATTERN (insn)) == SET
1537 && SET_DEST (PATTERN (insn)) == var
1538 /* If this represents the result of an insn group,
1539 don't delete the insn. */
1540 && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0
1541 && rtx_equal_p (SET_SRC (PATTERN (insn)), var))
1543 /* In unoptimized compilation, we shouldn't call delete_insn
1544 except in jump.c doing warnings. */
1545 PUT_CODE (insn, NOTE);
1546 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1547 NOTE_SOURCE_FILE (insn) = 0;
1548 if (insn == last_parm_insn)
1549 last_parm_insn = PREV_INSN (next);
1553 struct fixup_replacement *replacements = 0;
1554 rtx next_insn = NEXT_INSN (insn);
1556 #ifdef SMALL_REGISTER_CLASSES
1557 /* If the insn that copies the results of a CALL_INSN
1558 into a pseudo now references VAR, we have to use an
1559 intermediate pseudo since we want the life of the
1560 return value register to be only a single insn.
1562 If we don't use an intermediate pseudo, such things as
1563 address computations to make the address of VAR valid
1564 if it is not can be placed between the CALL_INSN and INSN.
1566 To make sure this doesn't happen, we record the destination
1567 of the CALL_INSN and see if the next insn uses both that
1570 if (call_dest != 0 && GET_CODE (insn) == INSN
1571 && reg_mentioned_p (var, PATTERN (insn))
1572 && reg_mentioned_p (call_dest, PATTERN (insn)))
1574 rtx temp = gen_reg_rtx (GET_MODE (call_dest));
1576 emit_insn_before (gen_move_insn (temp, call_dest), insn);
1578 PATTERN (insn) = replace_rtx (PATTERN (insn),
1582 if (GET_CODE (insn) == CALL_INSN
1583 && GET_CODE (PATTERN (insn)) == SET)
1584 call_dest = SET_DEST (PATTERN (insn));
1585 else if (GET_CODE (insn) == CALL_INSN
1586 && GET_CODE (PATTERN (insn)) == PARALLEL
1587 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
1588 call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
1593 /* See if we have to do anything to INSN now that VAR is in
1594 memory. If it needs to be loaded into a pseudo, use a single
1595 pseudo for the entire insn in case there is a MATCH_DUP
1596 between two operands. We pass a pointer to the head of
1597 a list of struct fixup_replacements. If fixup_var_refs_1
1598 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1599 it will record them in this list.
1601 If it allocated a pseudo for any replacement, we copy into
1604 fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn,
1607 /* If this is last_parm_insn, and any instructions were output
1608 after it to fix it up, then we must set last_parm_insn to
1609 the last such instruction emitted. */
1610 if (insn == last_parm_insn)
1611 last_parm_insn = PREV_INSN (next_insn);
1613 while (replacements)
1615 if (GET_CODE (replacements->new) == REG)
1620 /* OLD might be a (subreg (mem)). */
1621 if (GET_CODE (replacements->old) == SUBREG)
1623 = fixup_memory_subreg (replacements->old, insn, 0);
1626 = fixup_stack_1 (replacements->old, insn);
1628 insert_before = insn;
1630 /* If we are changing the mode, do a conversion.
1631 This might be wasteful, but combine.c will
1632 eliminate much of the waste. */
1634 if (GET_MODE (replacements->new)
1635 != GET_MODE (replacements->old))
1638 convert_move (replacements->new,
1639 replacements->old, unsignedp);
1640 seq = gen_sequence ();
1644 seq = gen_move_insn (replacements->new,
1647 emit_insn_before (seq, insert_before);
1650 replacements = replacements->next;
1654 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1655 But don't touch other insns referred to by reg-notes;
1656 we will get them elsewhere. */
1657 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
1658 if (GET_CODE (note) != INSN_LIST)
1660 = walk_fixup_memory_subreg (XEXP (note, 0), insn, 1);
1666 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1667 See if the rtx expression at *LOC in INSN needs to be changed.
1669 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1670 contain a list of original rtx's and replacements. If we find that we need
1671 to modify this insn by replacing a memory reference with a pseudo or by
1672 making a new MEM to implement a SUBREG, we consult that list to see if
1673 we have already chosen a replacement. If none has already been allocated,
1674 we allocate it and update the list. fixup_var_refs_insns will copy VAR
1675 or the SUBREG, as appropriate, to the pseudo. */
1678 fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements)
1680 enum machine_mode promoted_mode;
1683 struct fixup_replacement **replacements;
1686 register rtx x = *loc;
1687 RTX_CODE code = GET_CODE (x);
1689 register rtx tem, tem1;
1690 struct fixup_replacement *replacement;
1697 /* If we already have a replacement, use it. Otherwise,
1698 try to fix up this address in case it is invalid. */
1700 replacement = find_fixup_replacement (replacements, var);
1701 if (replacement->new)
1703 *loc = replacement->new;
1707 *loc = replacement->new = x = fixup_stack_1 (x, insn);
1709 /* Unless we are forcing memory to register or we changed the mode,
1710 we can leave things the way they are if the insn is valid. */
1712 INSN_CODE (insn) = -1;
1713 if (! flag_force_mem && GET_MODE (x) == promoted_mode
1714 && recog_memoized (insn) >= 0)
1717 *loc = replacement->new = gen_reg_rtx (promoted_mode);
1721 /* If X contains VAR, we need to unshare it here so that we update
1722 each occurrence separately. But all identical MEMs in one insn
1723 must be replaced with the same rtx because of the possibility of
1726 if (reg_mentioned_p (var, x))
1728 replacement = find_fixup_replacement (replacements, x);
1729 if (replacement->new == 0)
1730 replacement->new = copy_most_rtx (x, var);
1732 *loc = x = replacement->new;
1748 /* Note that in some cases those types of expressions are altered
1749 by optimize_bit_field, and do not survive to get here. */
1750 if (XEXP (x, 0) == var
1751 || (GET_CODE (XEXP (x, 0)) == SUBREG
1752 && SUBREG_REG (XEXP (x, 0)) == var))
1754 /* Get TEM as a valid MEM in the mode presently in the insn.
1756 We don't worry about the possibility of MATCH_DUP here; it
1757 is highly unlikely and would be tricky to handle. */
1760 if (GET_CODE (tem) == SUBREG)
1761 tem = fixup_memory_subreg (tem, insn, 1);
1762 tem = fixup_stack_1 (tem, insn);
1764 /* Unless we want to load from memory, get TEM into the proper mode
1765 for an extract from memory. This can only be done if the
1766 extract is at a constant position and length. */
1768 if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
1769 && GET_CODE (XEXP (x, 2)) == CONST_INT
1770 && ! mode_dependent_address_p (XEXP (tem, 0))
1771 && ! MEM_VOLATILE_P (tem))
1773 enum machine_mode wanted_mode = VOIDmode;
1774 enum machine_mode is_mode = GET_MODE (tem);
1775 int width = INTVAL (XEXP (x, 1));
1776 int pos = INTVAL (XEXP (x, 2));
1779 if (GET_CODE (x) == ZERO_EXTRACT)
1780 wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
1783 if (GET_CODE (x) == SIGN_EXTRACT)
1784 wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
1786 /* If we have a narrower mode, we can do something. */
1787 if (wanted_mode != VOIDmode
1788 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
1790 int offset = pos / BITS_PER_UNIT;
1791 rtx old_pos = XEXP (x, 2);
1794 /* If the bytes and bits are counted differently, we
1795 must adjust the offset. */
1796 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
1797 offset = (GET_MODE_SIZE (is_mode)
1798 - GET_MODE_SIZE (wanted_mode) - offset);
1800 pos %= GET_MODE_BITSIZE (wanted_mode);
1802 newmem = gen_rtx (MEM, wanted_mode,
1803 plus_constant (XEXP (tem, 0), offset));
1804 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
1805 MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
1806 MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
1808 /* Make the change and see if the insn remains valid. */
1809 INSN_CODE (insn) = -1;
1810 XEXP (x, 0) = newmem;
1811 XEXP (x, 2) = GEN_INT (pos);
1813 if (recog_memoized (insn) >= 0)
1816 /* Otherwise, restore old position. XEXP (x, 0) will be
1818 XEXP (x, 2) = old_pos;
1822 /* If we get here, the bitfield extract insn can't accept a memory
1823 reference. Copy the input into a register. */
1825 tem1 = gen_reg_rtx (GET_MODE (tem));
1826 emit_insn_before (gen_move_insn (tem1, tem), insn);
1833 if (SUBREG_REG (x) == var)
1835 /* If this is a special SUBREG made because VAR was promoted
1836 from a wider mode, replace it with VAR and call ourself
1837 recursively, this time saying that the object previously
1838 had its current mode (by virtue of the SUBREG). */
1840 if (SUBREG_PROMOTED_VAR_P (x))
1843 fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements);
1847 /* If this SUBREG makes VAR wider, it has become a paradoxical
1848 SUBREG with VAR in memory, but these aren't allowed at this
1849 stage of the compilation. So load VAR into a pseudo and take
1850 a SUBREG of that pseudo. */
1851 if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
1853 replacement = find_fixup_replacement (replacements, var);
1854 if (replacement->new == 0)
1855 replacement->new = gen_reg_rtx (GET_MODE (var));
1856 SUBREG_REG (x) = replacement->new;
1860 /* See if we have already found a replacement for this SUBREG.
1861 If so, use it. Otherwise, make a MEM and see if the insn
1862 is recognized. If not, or if we should force MEM into a register,
1863 make a pseudo for this SUBREG. */
1864 replacement = find_fixup_replacement (replacements, x);
1865 if (replacement->new)
1867 *loc = replacement->new;
1871 replacement->new = *loc = fixup_memory_subreg (x, insn, 0);
1873 INSN_CODE (insn) = -1;
1874 if (! flag_force_mem && recog_memoized (insn) >= 0)
1877 *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
1883 /* First do special simplification of bit-field references. */
1884 if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
1885 || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
1886 optimize_bit_field (x, insn, 0);
1887 if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
1888 || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
1889 optimize_bit_field (x, insn, NULL_PTR);
1891 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
1892 insn into a pseudo and store the low part of the pseudo into VAR. */
1893 if (GET_CODE (SET_DEST (x)) == SUBREG
1894 && SUBREG_REG (SET_DEST (x)) == var
1895 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
1896 > GET_MODE_SIZE (GET_MODE (var))))
1898 SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
1899 emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
1906 rtx dest = SET_DEST (x);
1907 rtx src = SET_SRC (x);
1908 rtx outerdest = dest;
1910 while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
1911 || GET_CODE (dest) == SIGN_EXTRACT
1912 || GET_CODE (dest) == ZERO_EXTRACT)
1913 dest = XEXP (dest, 0);
1915 if (GET_CODE (src) == SUBREG)
1916 src = XEXP (src, 0);
1918 /* If VAR does not appear at the top level of the SET
1919 just scan the lower levels of the tree. */
1921 if (src != var && dest != var)
1924 /* We will need to rerecognize this insn. */
1925 INSN_CODE (insn) = -1;
1928 if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var)
1930 /* Since this case will return, ensure we fixup all the
1932 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1),
1933 insn, replacements);
1934 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2),
1935 insn, replacements);
1936 fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x),
1937 insn, replacements);
1939 tem = XEXP (outerdest, 0);
1941 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
1942 that may appear inside a ZERO_EXTRACT.
1943 This was legitimate when the MEM was a REG. */
1944 if (GET_CODE (tem) == SUBREG
1945 && SUBREG_REG (tem) == var)
1946 tem = fixup_memory_subreg (tem, insn, 1);
1948 tem = fixup_stack_1 (tem, insn);
1950 if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
1951 && GET_CODE (XEXP (outerdest, 2)) == CONST_INT
1952 && ! mode_dependent_address_p (XEXP (tem, 0))
1953 && ! MEM_VOLATILE_P (tem))
1955 enum machine_mode wanted_mode
1956 = insn_operand_mode[(int) CODE_FOR_insv][0];
1957 enum machine_mode is_mode = GET_MODE (tem);
1958 int width = INTVAL (XEXP (outerdest, 1));
1959 int pos = INTVAL (XEXP (outerdest, 2));
1961 /* If we have a narrower mode, we can do something. */
1962 if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
1964 int offset = pos / BITS_PER_UNIT;
1965 rtx old_pos = XEXP (outerdest, 2);
1968 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
1969 offset = (GET_MODE_SIZE (is_mode)
1970 - GET_MODE_SIZE (wanted_mode) - offset);
1972 pos %= GET_MODE_BITSIZE (wanted_mode);
1974 newmem = gen_rtx (MEM, wanted_mode,
1975 plus_constant (XEXP (tem, 0), offset));
1976 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
1977 MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
1978 MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
1980 /* Make the change and see if the insn remains valid. */
1981 INSN_CODE (insn) = -1;
1982 XEXP (outerdest, 0) = newmem;
1983 XEXP (outerdest, 2) = GEN_INT (pos);
1985 if (recog_memoized (insn) >= 0)
1988 /* Otherwise, restore old position. XEXP (x, 0) will be
1990 XEXP (outerdest, 2) = old_pos;
1994 /* If we get here, the bit-field store doesn't allow memory
1995 or isn't located at a constant position. Load the value into
1996 a register, do the store, and put it back into memory. */
1998 tem1 = gen_reg_rtx (GET_MODE (tem));
1999 emit_insn_before (gen_move_insn (tem1, tem), insn);
2000 emit_insn_after (gen_move_insn (tem, tem1), insn);
2001 XEXP (outerdest, 0) = tem1;
2006 /* STRICT_LOW_PART is a no-op on memory references
2007 and it can cause combinations to be unrecognizable,
2010 if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
2011 SET_DEST (x) = XEXP (SET_DEST (x), 0);
2013 /* A valid insn to copy VAR into or out of a register
2014 must be left alone, to avoid an infinite loop here.
2015 If the reference to VAR is by a subreg, fix that up,
2016 since SUBREG is not valid for a memref.
2017 Also fix up the address of the stack slot.
2019 Note that we must not try to recognize the insn until
2020 after we know that we have valid addresses and no
2021 (subreg (mem ...) ...) constructs, since these interfere
2022 with determining the validity of the insn. */
2024 if ((SET_SRC (x) == var
2025 || (GET_CODE (SET_SRC (x)) == SUBREG
2026 && SUBREG_REG (SET_SRC (x)) == var))
2027 && (GET_CODE (SET_DEST (x)) == REG
2028 || (GET_CODE (SET_DEST (x)) == SUBREG
2029 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
2030 && GET_MODE (var) == promoted_mode
2031 && x == single_set (insn))
2035 replacement = find_fixup_replacement (replacements, SET_SRC (x));
2036 if (replacement->new)
2037 SET_SRC (x) = replacement->new;
2038 else if (GET_CODE (SET_SRC (x)) == SUBREG)
2039 SET_SRC (x) = replacement->new
2040 = fixup_memory_subreg (SET_SRC (x), insn, 0);
2042 SET_SRC (x) = replacement->new
2043 = fixup_stack_1 (SET_SRC (x), insn);
2045 if (recog_memoized (insn) >= 0)
2048 /* INSN is not valid, but we know that we want to
2049 copy SET_SRC (x) to SET_DEST (x) in some way. So
2050 we generate the move and see whether it requires more
2051 than one insn. If it does, we emit those insns and
2052 delete INSN. Otherwise, we an just replace the pattern
2053 of INSN; we have already verified above that INSN has
2054 no other function that to do X. */
2056 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2057 if (GET_CODE (pat) == SEQUENCE)
2059 emit_insn_after (pat, insn);
2060 PUT_CODE (insn, NOTE);
2061 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2062 NOTE_SOURCE_FILE (insn) = 0;
2065 PATTERN (insn) = pat;
2070 if ((SET_DEST (x) == var
2071 || (GET_CODE (SET_DEST (x)) == SUBREG
2072 && SUBREG_REG (SET_DEST (x)) == var))
2073 && (GET_CODE (SET_SRC (x)) == REG
2074 || (GET_CODE (SET_SRC (x)) == SUBREG
2075 && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
2076 && GET_MODE (var) == promoted_mode
2077 && x == single_set (insn))
2081 if (GET_CODE (SET_DEST (x)) == SUBREG)
2082 SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn, 0);
2084 SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
2086 if (recog_memoized (insn) >= 0)
2089 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2090 if (GET_CODE (pat) == SEQUENCE)
2092 emit_insn_after (pat, insn);
2093 PUT_CODE (insn, NOTE);
2094 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2095 NOTE_SOURCE_FILE (insn) = 0;
2098 PATTERN (insn) = pat;
2103 /* Otherwise, storing into VAR must be handled specially
2104 by storing into a temporary and copying that into VAR
2105 with a new insn after this one. Note that this case
2106 will be used when storing into a promoted scalar since
2107 the insn will now have different modes on the input
2108 and output and hence will be invalid (except for the case
2109 of setting it to a constant, which does not need any
2110 change if it is valid). We generate extra code in that case,
2111 but combine.c will eliminate it. */
2116 rtx fixeddest = SET_DEST (x);
2118 /* STRICT_LOW_PART can be discarded, around a MEM. */
2119 if (GET_CODE (fixeddest) == STRICT_LOW_PART)
2120 fixeddest = XEXP (fixeddest, 0);
2121 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
2122 if (GET_CODE (fixeddest) == SUBREG)
2124 fixeddest = fixup_memory_subreg (fixeddest, insn, 0);
2125 promoted_mode = GET_MODE (fixeddest);
2128 fixeddest = fixup_stack_1 (fixeddest, insn);
2130 temp = gen_reg_rtx (promoted_mode);
2132 emit_insn_after (gen_move_insn (fixeddest,
2133 gen_lowpart (GET_MODE (fixeddest),
2137 SET_DEST (x) = temp;
2142 /* Nothing special about this RTX; fix its operands. */
2144 fmt = GET_RTX_FORMAT (code);
2145 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2148 fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements);
2152 for (j = 0; j < XVECLEN (x, i); j++)
2153 fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j),
2154 insn, replacements);
2159 /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
2160 return an rtx (MEM:m1 newaddr) which is equivalent.
2161 If any insns must be emitted to compute NEWADDR, put them before INSN.
2163 UNCRITICAL nonzero means accept paradoxical subregs.
2164 This is used for subregs found inside of ZERO_EXTRACTs and in REG_NOTES. */
2167 fixup_memory_subreg (x, insn, uncritical)
2172 int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
2173 rtx addr = XEXP (SUBREG_REG (x), 0);
2174 enum machine_mode mode = GET_MODE (x);
2177 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2178 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
2182 if (BYTES_BIG_ENDIAN)
2183 offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
2184 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
2185 addr = plus_constant (addr, offset);
2186 if (!flag_force_addr && memory_address_p (mode, addr))
2187 /* Shortcut if no insns need be emitted. */
2188 return change_address (SUBREG_REG (x), mode, addr);
2190 result = change_address (SUBREG_REG (x), mode, addr);
2191 emit_insn_before (gen_sequence (), insn);
2196 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2197 Replace subexpressions of X in place.
2198 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2199 Otherwise return X, with its contents possibly altered.
2201 If any insns must be emitted to compute NEWADDR, put them before INSN.
2203 UNCRITICAL is as in fixup_memory_subreg. */
2206 walk_fixup_memory_subreg (x, insn, uncritical)
2211 register enum rtx_code code;
2218 code = GET_CODE (x);
2220 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
2221 return fixup_memory_subreg (x, insn, uncritical);
2223 /* Nothing special about this RTX; fix its operands. */
2225 fmt = GET_RTX_FORMAT (code);
2226 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2229 XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn, uncritical);
2233 for (j = 0; j < XVECLEN (x, i); j++)
2235 = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn, uncritical);
2241 /* For each memory ref within X, if it refers to a stack slot
2242 with an out of range displacement, put the address in a temp register
2243 (emitting new insns before INSN to load these registers)
2244 and alter the memory ref to use that register.
2245 Replace each such MEM rtx with a copy, to avoid clobberage. */
2248 fixup_stack_1 (x, insn)
2253 register RTX_CODE code = GET_CODE (x);
2258 register rtx ad = XEXP (x, 0);
2259 /* If we have address of a stack slot but it's not valid
2260 (displacement is too large), compute the sum in a register. */
2261 if (GET_CODE (ad) == PLUS
2262 && GET_CODE (XEXP (ad, 0)) == REG
2263 && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
2264 && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER)
2265 || XEXP (ad, 0) == current_function_internal_arg_pointer)
2266 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
2269 if (memory_address_p (GET_MODE (x), ad))
2273 temp = copy_to_reg (ad);
2274 seq = gen_sequence ();
2276 emit_insn_before (seq, insn);
2277 return change_address (x, VOIDmode, temp);
2282 fmt = GET_RTX_FORMAT (code);
2283 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2286 XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
2290 for (j = 0; j < XVECLEN (x, i); j++)
2291 XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
2297 /* Optimization: a bit-field instruction whose field
2298 happens to be a byte or halfword in memory
2299 can be changed to a move instruction.
2301 We call here when INSN is an insn to examine or store into a bit-field.
2302 BODY is the SET-rtx to be altered.
2304 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2305 (Currently this is called only from function.c, and EQUIV_MEM
2309 optimize_bit_field (body, insn, equiv_mem)
2314 register rtx bitfield;
2317 enum machine_mode mode;
2319 if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
2320 || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
2321 bitfield = SET_DEST (body), destflag = 1;
2323 bitfield = SET_SRC (body), destflag = 0;
2325 /* First check that the field being stored has constant size and position
2326 and is in fact a byte or halfword suitably aligned. */
2328 if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
2329 && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
2330 && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
2332 && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
2334 register rtx memref = 0;
2336 /* Now check that the containing word is memory, not a register,
2337 and that it is safe to change the machine mode. */
2339 if (GET_CODE (XEXP (bitfield, 0)) == MEM)
2340 memref = XEXP (bitfield, 0);
2341 else if (GET_CODE (XEXP (bitfield, 0)) == REG
2343 memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
2344 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2345 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
2346 memref = SUBREG_REG (XEXP (bitfield, 0));
2347 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2349 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
2350 memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
2353 && ! mode_dependent_address_p (XEXP (memref, 0))
2354 && ! MEM_VOLATILE_P (memref))
2356 /* Now adjust the address, first for any subreg'ing
2357 that we are now getting rid of,
2358 and then for which byte of the word is wanted. */
2360 register int offset = INTVAL (XEXP (bitfield, 2));
2363 /* Adjust OFFSET to count bits from low-address byte. */
2364 if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN)
2365 offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
2366 - offset - INTVAL (XEXP (bitfield, 1)));
2368 /* Adjust OFFSET to count bytes from low-address byte. */
2369 offset /= BITS_PER_UNIT;
2370 if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
2372 offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD;
2373 if (BYTES_BIG_ENDIAN)
2374 offset -= (MIN (UNITS_PER_WORD,
2375 GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
2376 - MIN (UNITS_PER_WORD,
2377 GET_MODE_SIZE (GET_MODE (memref))));
2381 memref = change_address (memref, mode,
2382 plus_constant (XEXP (memref, 0), offset));
2383 insns = get_insns ();
2385 emit_insns_before (insns, insn);
2387 /* Store this memory reference where
2388 we found the bit field reference. */
2392 validate_change (insn, &SET_DEST (body), memref, 1);
2393 if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
2395 rtx src = SET_SRC (body);
2396 while (GET_CODE (src) == SUBREG
2397 && SUBREG_WORD (src) == 0)
2398 src = SUBREG_REG (src);
2399 if (GET_MODE (src) != GET_MODE (memref))
2400 src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
2401 validate_change (insn, &SET_SRC (body), src, 1);
2403 else if (GET_MODE (SET_SRC (body)) != VOIDmode
2404 && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
2405 /* This shouldn't happen because anything that didn't have
2406 one of these modes should have got converted explicitly
2407 and then referenced through a subreg.
2408 This is so because the original bit-field was
2409 handled by agg_mode and so its tree structure had
2410 the same mode that memref now has. */
2415 rtx dest = SET_DEST (body);
2417 while (GET_CODE (dest) == SUBREG
2418 && SUBREG_WORD (dest) == 0
2419 && (GET_MODE_CLASS (GET_MODE (dest))
2420 == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest)))))
2421 dest = SUBREG_REG (dest);
2423 validate_change (insn, &SET_DEST (body), dest, 1);
2425 if (GET_MODE (dest) == GET_MODE (memref))
2426 validate_change (insn, &SET_SRC (body), memref, 1);
2429 /* Convert the mem ref to the destination mode. */
2430 rtx newreg = gen_reg_rtx (GET_MODE (dest));
2433 convert_move (newreg, memref,
2434 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
2438 validate_change (insn, &SET_SRC (body), newreg, 1);
2442 /* See if we can convert this extraction or insertion into
2443 a simple move insn. We might not be able to do so if this
2444 was, for example, part of a PARALLEL.
2446 If we succeed, write out any needed conversions. If we fail,
2447 it is hard to guess why we failed, so don't do anything
2448 special; just let the optimization be suppressed. */
2450 if (apply_change_group () && seq)
2451 emit_insns_before (seq, insn);
2456 /* These routines are responsible for converting virtual register references
2457 to the actual hard register references once RTL generation is complete.
2459 The following four variables are used for communication between the
2460 routines. They contain the offsets of the virtual registers from their
2461 respective hard registers. */
2463 static int in_arg_offset;
2464 static int var_offset;
2465 static int dynamic_offset;
2466 static int out_arg_offset;
2468 /* In most machines, the stack pointer register is equivalent to the bottom
2471 #ifndef STACK_POINTER_OFFSET
2472 #define STACK_POINTER_OFFSET 0
2475 /* If not defined, pick an appropriate default for the offset of dynamically
2476 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2477 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2479 #ifndef STACK_DYNAMIC_OFFSET
2481 #ifdef ACCUMULATE_OUTGOING_ARGS
2482 /* The bottom of the stack points to the actual arguments. If
2483 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2484 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2485 stack space for register parameters is not pushed by the caller, but
2486 rather part of the fixed stack areas and hence not included in
2487 `current_function_outgoing_args_size'. Nevertheless, we must allow
2488 for it when allocating stack dynamic objects. */
2490 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2491 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2492 (current_function_outgoing_args_size \
2493 + REG_PARM_STACK_SPACE (FNDECL) + (STACK_POINTER_OFFSET))
2496 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2497 (current_function_outgoing_args_size + (STACK_POINTER_OFFSET))
2501 #define STACK_DYNAMIC_OFFSET(FNDECL) STACK_POINTER_OFFSET
2505 /* Pass through the INSNS of function FNDECL and convert virtual register
2506 references to hard register references. */
2509 instantiate_virtual_regs (fndecl, insns)
2515 /* Compute the offsets to use for this function. */
2516 in_arg_offset = FIRST_PARM_OFFSET (fndecl);
2517 var_offset = STARTING_FRAME_OFFSET;
2518 dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
2519 out_arg_offset = STACK_POINTER_OFFSET;
2521 /* Scan all variables and parameters of this function. For each that is
2522 in memory, instantiate all virtual registers if the result is a valid
2523 address. If not, we do it later. That will handle most uses of virtual
2524 regs on many machines. */
2525 instantiate_decls (fndecl, 1);
2527 /* Initialize recognition, indicating that volatile is OK. */
2530 /* Scan through all the insns, instantiating every virtual register still
2532 for (insn = insns; insn; insn = NEXT_INSN (insn))
2533 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
2534 || GET_CODE (insn) == CALL_INSN)
2536 instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1);
2537 instantiate_virtual_regs_1 (®_NOTES (insn), NULL_RTX, 0);
2540 /* Now instantiate the remaining register equivalences for debugging info.
2541 These will not be valid addresses. */
2542 instantiate_decls (fndecl, 0);
2544 /* Indicate that, from now on, assign_stack_local should use
2545 frame_pointer_rtx. */
2546 virtuals_instantiated = 1;
2549 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
2550 all virtual registers in their DECL_RTL's.
2552 If VALID_ONLY, do this only if the resulting address is still valid.
2553 Otherwise, always do it. */
2556 instantiate_decls (fndecl, valid_only)
2562 if (DECL_SAVED_INSNS (fndecl))
2563 /* When compiling an inline function, the obstack used for
2564 rtl allocation is the maybepermanent_obstack. Calling
2565 `resume_temporary_allocation' switches us back to that
2566 obstack while we process this function's parameters. */
2567 resume_temporary_allocation ();
2569 /* Process all parameters of the function. */
2570 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
2572 instantiate_decl (DECL_RTL (decl), int_size_in_bytes (TREE_TYPE (decl)),
2574 instantiate_decl (DECL_INCOMING_RTL (decl),
2575 int_size_in_bytes (TREE_TYPE (decl)), valid_only);
2578 /* Now process all variables defined in the function or its subblocks. */
2579 instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
2581 if (DECL_INLINE (fndecl) || DECL_DEFER_OUTPUT (fndecl))
2583 /* Save all rtl allocated for this function by raising the
2584 high-water mark on the maybepermanent_obstack. */
2586 /* All further rtl allocation is now done in the current_obstack. */
2587 rtl_in_current_obstack ();
2591 /* Subroutine of instantiate_decls: Process all decls in the given
2592 BLOCK node and all its subblocks. */
2595 instantiate_decls_1 (let, valid_only)
2601 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
2602 instantiate_decl (DECL_RTL (t), int_size_in_bytes (TREE_TYPE (t)),
2605 /* Process all subblocks. */
2606 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
2607 instantiate_decls_1 (t, valid_only);
2610 /* Subroutine of the preceding procedures: Given RTL representing a
2611 decl and the size of the object, do any instantiation required.
2613 If VALID_ONLY is non-zero, it means that the RTL should only be
2614 changed if the new address is valid. */
2617 instantiate_decl (x, size, valid_only)
2622 enum machine_mode mode;
2625 /* If this is not a MEM, no need to do anything. Similarly if the
2626 address is a constant or a register that is not a virtual register. */
2628 if (x == 0 || GET_CODE (x) != MEM)
2632 if (CONSTANT_P (addr)
2633 || (GET_CODE (addr) == REG
2634 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
2635 || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
2638 /* If we should only do this if the address is valid, copy the address.
2639 We need to do this so we can undo any changes that might make the
2640 address invalid. This copy is unfortunate, but probably can't be
2644 addr = copy_rtx (addr);
2646 instantiate_virtual_regs_1 (&addr, NULL_RTX, 0);
2651 /* Now verify that the resulting address is valid for every integer or
2652 floating-point mode up to and including SIZE bytes long. We do this
2653 since the object might be accessed in any mode and frame addresses
2656 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2657 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
2658 mode = GET_MODE_WIDER_MODE (mode))
2659 if (! memory_address_p (mode, addr))
2662 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
2663 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
2664 mode = GET_MODE_WIDER_MODE (mode))
2665 if (! memory_address_p (mode, addr))
2668 /* Otherwise, put back the address, now that we have updated it and we
2669 know it is valid. */
2674 /* Given a pointer to a piece of rtx and an optional pointer to the
2675 containing object, instantiate any virtual registers present in it.
2677 If EXTRA_INSNS, we always do the replacement and generate
2678 any extra insns before OBJECT. If it zero, we do nothing if replacement
2681 Return 1 if we either had nothing to do or if we were able to do the
2682 needed replacement. Return 0 otherwise; we only return zero if
2683 EXTRA_INSNS is zero.
2685 We first try some simple transformations to avoid the creation of extra
2689 instantiate_virtual_regs_1 (loc, object, extra_insns)
2703 /* Re-start here to avoid recursion in common cases. */
2710 code = GET_CODE (x);
2712 /* Check for some special cases. */
2729 /* We are allowed to set the virtual registers. This means that
2730 that the actual register should receive the source minus the
2731 appropriate offset. This is used, for example, in the handling
2732 of non-local gotos. */
2733 if (SET_DEST (x) == virtual_incoming_args_rtx)
2734 new = arg_pointer_rtx, offset = - in_arg_offset;
2735 else if (SET_DEST (x) == virtual_stack_vars_rtx)
2736 new = frame_pointer_rtx, offset = - var_offset;
2737 else if (SET_DEST (x) == virtual_stack_dynamic_rtx)
2738 new = stack_pointer_rtx, offset = - dynamic_offset;
2739 else if (SET_DEST (x) == virtual_outgoing_args_rtx)
2740 new = stack_pointer_rtx, offset = - out_arg_offset;
2744 /* The only valid sources here are PLUS or REG. Just do
2745 the simplest possible thing to handle them. */
2746 if (GET_CODE (SET_SRC (x)) != REG
2747 && GET_CODE (SET_SRC (x)) != PLUS)
2751 if (GET_CODE (SET_SRC (x)) != REG)
2752 temp = force_operand (SET_SRC (x), NULL_RTX);
2755 temp = force_operand (plus_constant (temp, offset), NULL_RTX);
2759 emit_insns_before (seq, object);
2762 if (!validate_change (object, &SET_SRC (x), temp, 0)
2769 instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns);
2774 /* Handle special case of virtual register plus constant. */
2775 if (CONSTANT_P (XEXP (x, 1)))
2777 rtx old, new_offset;
2779 /* Check for (plus (plus VIRT foo) (const_int)) first. */
2780 if (GET_CODE (XEXP (x, 0)) == PLUS)
2782 rtx inner = XEXP (XEXP (x, 0), 0);
2784 if (inner == virtual_incoming_args_rtx)
2785 new = arg_pointer_rtx, offset = in_arg_offset;
2786 else if (inner == virtual_stack_vars_rtx)
2787 new = frame_pointer_rtx, offset = var_offset;
2788 else if (inner == virtual_stack_dynamic_rtx)
2789 new = stack_pointer_rtx, offset = dynamic_offset;
2790 else if (inner == virtual_outgoing_args_rtx)
2791 new = stack_pointer_rtx, offset = out_arg_offset;
2798 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object,
2800 new = gen_rtx (PLUS, Pmode, new, XEXP (XEXP (x, 0), 1));
2803 else if (XEXP (x, 0) == virtual_incoming_args_rtx)
2804 new = arg_pointer_rtx, offset = in_arg_offset;
2805 else if (XEXP (x, 0) == virtual_stack_vars_rtx)
2806 new = frame_pointer_rtx, offset = var_offset;
2807 else if (XEXP (x, 0) == virtual_stack_dynamic_rtx)
2808 new = stack_pointer_rtx, offset = dynamic_offset;
2809 else if (XEXP (x, 0) == virtual_outgoing_args_rtx)
2810 new = stack_pointer_rtx, offset = out_arg_offset;
2813 /* We know the second operand is a constant. Unless the
2814 first operand is a REG (which has been already checked),
2815 it needs to be checked. */
2816 if (GET_CODE (XEXP (x, 0)) != REG)
2824 new_offset = plus_constant (XEXP (x, 1), offset);
2826 /* If the new constant is zero, try to replace the sum with just
2828 if (new_offset == const0_rtx
2829 && validate_change (object, loc, new, 0))
2832 /* Next try to replace the register and new offset.
2833 There are two changes to validate here and we can't assume that
2834 in the case of old offset equals new just changing the register
2835 will yield a valid insn. In the interests of a little efficiency,
2836 however, we only call validate change once (we don't queue up the
2837 changes and then call apply_change_group). */
2841 ? ! validate_change (object, &XEXP (x, 0), new, 0)
2842 : (XEXP (x, 0) = new,
2843 ! validate_change (object, &XEXP (x, 1), new_offset, 0)))
2851 /* Otherwise copy the new constant into a register and replace
2852 constant with that register. */
2853 temp = gen_reg_rtx (Pmode);
2855 if (validate_change (object, &XEXP (x, 1), temp, 0))
2856 emit_insn_before (gen_move_insn (temp, new_offset), object);
2859 /* If that didn't work, replace this expression with a
2860 register containing the sum. */
2863 new = gen_rtx (PLUS, Pmode, new, new_offset);
2866 temp = force_operand (new, NULL_RTX);
2870 emit_insns_before (seq, object);
2871 if (! validate_change (object, loc, temp, 0)
2872 && ! validate_replace_rtx (x, temp, object))
2880 /* Fall through to generic two-operand expression case. */
2886 case DIV: case UDIV:
2887 case MOD: case UMOD:
2888 case AND: case IOR: case XOR:
2889 case ROTATERT: case ROTATE:
2890 case ASHIFTRT: case LSHIFTRT: case ASHIFT:
2892 case GE: case GT: case GEU: case GTU:
2893 case LE: case LT: case LEU: case LTU:
2894 if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
2895 instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns);
2900 /* Most cases of MEM that convert to valid addresses have already been
2901 handled by our scan of regno_reg_rtx. The only special handling we
2902 need here is to make a copy of the rtx to ensure it isn't being
2903 shared if we have to change it to a pseudo.
2905 If the rtx is a simple reference to an address via a virtual register,
2906 it can potentially be shared. In such cases, first try to make it
2907 a valid address, which can also be shared. Otherwise, copy it and
2910 First check for common cases that need no processing. These are
2911 usually due to instantiation already being done on a previous instance
2915 if (CONSTANT_ADDRESS_P (temp)
2916 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2917 || temp == arg_pointer_rtx
2919 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2920 || temp == hard_frame_pointer_rtx
2922 || temp == frame_pointer_rtx)
2925 if (GET_CODE (temp) == PLUS
2926 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
2927 && (XEXP (temp, 0) == frame_pointer_rtx
2928 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2929 || XEXP (temp, 0) == hard_frame_pointer_rtx
2931 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2932 || XEXP (temp, 0) == arg_pointer_rtx
2937 if (temp == virtual_stack_vars_rtx
2938 || temp == virtual_incoming_args_rtx
2939 || (GET_CODE (temp) == PLUS
2940 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
2941 && (XEXP (temp, 0) == virtual_stack_vars_rtx
2942 || XEXP (temp, 0) == virtual_incoming_args_rtx)))
2944 /* This MEM may be shared. If the substitution can be done without
2945 the need to generate new pseudos, we want to do it in place
2946 so all copies of the shared rtx benefit. The call below will
2947 only make substitutions if the resulting address is still
2950 Note that we cannot pass X as the object in the recursive call
2951 since the insn being processed may not allow all valid
2952 addresses. However, if we were not passed on object, we can
2953 only modify X without copying it if X will have a valid
2956 ??? Also note that this can still lose if OBJECT is an insn that
2957 has less restrictions on an address that some other insn.
2958 In that case, we will modify the shared address. This case
2959 doesn't seem very likely, though. */
2961 if (instantiate_virtual_regs_1 (&XEXP (x, 0),
2962 object ? object : x, 0))
2965 /* Otherwise make a copy and process that copy. We copy the entire
2966 RTL expression since it might be a PLUS which could also be
2968 *loc = x = copy_rtx (x);
2971 /* Fall through to generic unary operation case. */
2975 case STRICT_LOW_PART:
2977 case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC:
2978 case SIGN_EXTEND: case ZERO_EXTEND:
2979 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE:
2980 case FLOAT: case FIX:
2981 case UNSIGNED_FIX: case UNSIGNED_FLOAT:
2985 /* These case either have just one operand or we know that we need not
2986 check the rest of the operands. */
2991 /* Try to replace with a PLUS. If that doesn't work, compute the sum
2992 in front of this insn and substitute the temporary. */
2993 if (x == virtual_incoming_args_rtx)
2994 new = arg_pointer_rtx, offset = in_arg_offset;
2995 else if (x == virtual_stack_vars_rtx)
2996 new = frame_pointer_rtx, offset = var_offset;
2997 else if (x == virtual_stack_dynamic_rtx)
2998 new = stack_pointer_rtx, offset = dynamic_offset;
2999 else if (x == virtual_outgoing_args_rtx)
3000 new = stack_pointer_rtx, offset = out_arg_offset;
3004 temp = plus_constant (new, offset);
3005 if (!validate_change (object, loc, temp, 0))
3011 temp = force_operand (temp, NULL_RTX);
3015 emit_insns_before (seq, object);
3016 if (! validate_change (object, loc, temp, 0)
3017 && ! validate_replace_rtx (x, temp, object))
3025 /* Scan all subexpressions. */
3026 fmt = GET_RTX_FORMAT (code);
3027 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
3030 if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns))
3033 else if (*fmt == 'E')
3034 for (j = 0; j < XVECLEN (x, i); j++)
3035 if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object,
3042 /* Optimization: assuming this function does not receive nonlocal gotos,
3043 delete the handlers for such, as well as the insns to establish
3044 and disestablish them. */
3050 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3052 /* Delete the handler by turning off the flag that would
3053 prevent jump_optimize from deleting it.
3054 Also permit deletion of the nonlocal labels themselves
3055 if nothing local refers to them. */
3056 if (GET_CODE (insn) == CODE_LABEL)
3060 LABEL_PRESERVE_P (insn) = 0;
3062 /* Remove it from the nonlocal_label list, to avoid confusing
3064 for (t = nonlocal_labels, last_t = 0; t;
3065 last_t = t, t = TREE_CHAIN (t))
3066 if (DECL_RTL (TREE_VALUE (t)) == insn)
3071 nonlocal_labels = TREE_CHAIN (nonlocal_labels);
3073 TREE_CHAIN (last_t) = TREE_CHAIN (t);
3076 if (GET_CODE (insn) == INSN
3077 && ((nonlocal_goto_handler_slot != 0
3078 && reg_mentioned_p (nonlocal_goto_handler_slot, PATTERN (insn)))
3079 || (nonlocal_goto_stack_level != 0
3080 && reg_mentioned_p (nonlocal_goto_stack_level,
3086 /* Return a list (chain of EXPR_LIST nodes) for the nonlocal labels
3087 of the current function. */
3090 nonlocal_label_rtx_list ()
3095 for (t = nonlocal_labels; t; t = TREE_CHAIN (t))
3096 x = gen_rtx (EXPR_LIST, VOIDmode, label_rtx (TREE_VALUE (t)), x);
3101 /* Output a USE for any register use in RTL.
3102 This is used with -noreg to mark the extent of lifespan
3103 of any registers used in a user-visible variable's DECL_RTL. */
3109 if (GET_CODE (rtl) == REG)
3110 /* This is a register variable. */
3111 emit_insn (gen_rtx (USE, VOIDmode, rtl));
3112 else if (GET_CODE (rtl) == MEM
3113 && GET_CODE (XEXP (rtl, 0)) == REG
3114 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
3115 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
3116 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
3117 /* This is a variable-sized structure. */
3118 emit_insn (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)));
3121 /* Like use_variable except that it outputs the USEs after INSN
3122 instead of at the end of the insn-chain. */
3125 use_variable_after (rtl, insn)
3128 if (GET_CODE (rtl) == REG)
3129 /* This is a register variable. */
3130 emit_insn_after (gen_rtx (USE, VOIDmode, rtl), insn);
3131 else if (GET_CODE (rtl) == MEM
3132 && GET_CODE (XEXP (rtl, 0)) == REG
3133 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
3134 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
3135 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
3136 /* This is a variable-sized structure. */
3137 emit_insn_after (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)), insn);
3143 return max_parm_reg;
3146 /* Return the first insn following those generated by `assign_parms'. */
3149 get_first_nonparm_insn ()
3152 return NEXT_INSN (last_parm_insn);
3153 return get_insns ();
3156 /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
3157 Crash if there is none. */
3160 get_first_block_beg ()
3162 register rtx searcher;
3163 register rtx insn = get_first_nonparm_insn ();
3165 for (searcher = insn; searcher; searcher = NEXT_INSN (searcher))
3166 if (GET_CODE (searcher) == NOTE
3167 && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG)
3170 abort (); /* Invalid call to this function. (See comments above.) */
3174 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
3175 This means a type for which function calls must pass an address to the
3176 function or get an address back from the function.
3177 EXP may be a type node or an expression (whose type is tested). */
3180 aggregate_value_p (exp)
3183 int i, regno, nregs;
3186 if (TREE_CODE_CLASS (TREE_CODE (exp)) == 't')
3189 type = TREE_TYPE (exp);
3191 if (RETURN_IN_MEMORY (type))
3193 if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
3195 /* Make sure we have suitable call-clobbered regs to return
3196 the value in; if not, we must return it in memory. */
3197 reg = hard_function_value (type, 0);
3198 regno = REGNO (reg);
3199 nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type));
3200 for (i = 0; i < nregs; i++)
3201 if (! call_used_regs[regno + i])
3206 /* Assign RTL expressions to the function's parameters.
3207 This may involve copying them into registers and using
3208 those registers as the RTL for them.
3210 If SECOND_TIME is non-zero it means that this function is being
3211 called a second time. This is done by integrate.c when a function's
3212 compilation is deferred. We need to come back here in case the
3213 FUNCTION_ARG macro computes items needed for the rest of the compilation
3214 (such as changing which registers are fixed or caller-saved). But suppress
3215 writing any insns or setting DECL_RTL of anything in this case. */
3218 assign_parms (fndecl, second_time)
3223 register rtx entry_parm = 0;
3224 register rtx stack_parm = 0;
3225 CUMULATIVE_ARGS args_so_far;
3226 enum machine_mode promoted_mode, passed_mode;
3227 enum machine_mode nominal_mode, promoted_nominal_mode;
3229 /* Total space needed so far for args on the stack,
3230 given as a constant and a tree-expression. */
3231 struct args_size stack_args_size;
3232 tree fntype = TREE_TYPE (fndecl);
3233 tree fnargs = DECL_ARGUMENTS (fndecl);
3234 /* This is used for the arg pointer when referring to stack args. */
3235 rtx internal_arg_pointer;
3236 /* This is a dummy PARM_DECL that we used for the function result if
3237 the function returns a structure. */
3238 tree function_result_decl = 0;
3239 int nparmregs = list_length (fnargs) + LAST_VIRTUAL_REGISTER + 1;
3240 int varargs_setup = 0;
3241 rtx conversion_insns = 0;
3243 /* Nonzero if the last arg is named `__builtin_va_alist',
3244 which is used on some machines for old-fashioned non-ANSI varargs.h;
3245 this should be stuck onto the stack as if it had arrived there. */
3247 = (current_function_varargs
3249 && (parm = tree_last (fnargs)) != 0
3251 && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
3252 "__builtin_va_alist")));
3254 /* Nonzero if function takes extra anonymous args.
3255 This means the last named arg must be on the stack
3256 right before the anonymous ones. */
3258 = (TYPE_ARG_TYPES (fntype) != 0
3259 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3260 != void_type_node));
3262 current_function_stdarg = stdarg;
3264 /* If the reg that the virtual arg pointer will be translated into is
3265 not a fixed reg or is the stack pointer, make a copy of the virtual
3266 arg pointer, and address parms via the copy. The frame pointer is
3267 considered fixed even though it is not marked as such.
3269 The second time through, simply use ap to avoid generating rtx. */
3271 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
3272 || ! (fixed_regs[ARG_POINTER_REGNUM]
3273 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM))
3275 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
3277 internal_arg_pointer = virtual_incoming_args_rtx;
3278 current_function_internal_arg_pointer = internal_arg_pointer;
3280 stack_args_size.constant = 0;
3281 stack_args_size.var = 0;
3283 /* If struct value address is treated as the first argument, make it so. */
3284 if (aggregate_value_p (DECL_RESULT (fndecl))
3285 && ! current_function_returns_pcc_struct
3286 && struct_value_incoming_rtx == 0)
3288 tree type = build_pointer_type (TREE_TYPE (fntype));
3290 function_result_decl = build_decl (PARM_DECL, NULL_TREE, type);
3292 DECL_ARG_TYPE (function_result_decl) = type;
3293 TREE_CHAIN (function_result_decl) = fnargs;
3294 fnargs = function_result_decl;
3297 parm_reg_stack_loc = (rtx *) oballoc (nparmregs * sizeof (rtx));
3298 bzero ((char *) parm_reg_stack_loc, nparmregs * sizeof (rtx));
3300 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
3301 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX);
3303 INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX, 0);
3306 /* We haven't yet found an argument that we must push and pretend the
3308 current_function_pretend_args_size = 0;
3310 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
3312 int aggregate = AGGREGATE_TYPE_P (TREE_TYPE (parm));
3313 struct args_size stack_offset;
3314 struct args_size arg_size;
3315 int passed_pointer = 0;
3316 int did_conversion = 0;
3317 tree passed_type = DECL_ARG_TYPE (parm);
3318 tree nominal_type = TREE_TYPE (parm);
3320 /* Set LAST_NAMED if this is last named arg before some
3321 anonymous args. We treat it as if it were anonymous too. */
3322 int last_named = ((TREE_CHAIN (parm) == 0
3323 || DECL_NAME (TREE_CHAIN (parm)) == 0)
3324 && (stdarg || current_function_varargs));
3326 if (TREE_TYPE (parm) == error_mark_node
3327 /* This can happen after weird syntax errors
3328 or if an enum type is defined among the parms. */
3329 || TREE_CODE (parm) != PARM_DECL
3330 || passed_type == NULL)
3332 DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = gen_rtx (MEM, BLKmode,
3334 TREE_USED (parm) = 1;
3338 /* For varargs.h function, save info about regs and stack space
3339 used by the individual args, not including the va_alist arg. */
3340 if (hide_last_arg && last_named)
3341 current_function_args_info = args_so_far;
3343 /* Find mode of arg as it is passed, and mode of arg
3344 as it should be during execution of this function. */
3345 passed_mode = TYPE_MODE (passed_type);
3346 nominal_mode = TYPE_MODE (nominal_type);
3348 /* If the parm's mode is VOID, its value doesn't matter,
3349 and avoid the usual things like emit_move_insn that could crash. */
3350 if (nominal_mode == VOIDmode)
3352 DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = const0_rtx;
3356 /* If the parm is to be passed as a transparent union, use the
3357 type of the first field for the tests below. We have already
3358 verified that the modes are the same. */
3359 if (DECL_TRANSPARENT_UNION (parm)
3360 || TYPE_TRANSPARENT_UNION (passed_type))
3361 passed_type = TREE_TYPE (TYPE_FIELDS (passed_type));
3363 /* See if this arg was passed by invisible reference. It is if
3364 it is an object whose size depends on the contents of the
3365 object itself or if the machine requires these objects be passed
3368 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
3369 && contains_placeholder_p (TYPE_SIZE (passed_type)))
3370 || TREE_ADDRESSABLE (passed_type)
3371 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
3372 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
3373 passed_type, ! last_named)
3377 passed_type = nominal_type = build_pointer_type (passed_type);
3379 passed_mode = nominal_mode = Pmode;
3382 promoted_mode = passed_mode;
3384 #ifdef PROMOTE_FUNCTION_ARGS
3385 /* Compute the mode in which the arg is actually extended to. */
3386 promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1);
3389 /* Let machine desc say which reg (if any) the parm arrives in.
3390 0 means it arrives on the stack. */
3391 #ifdef FUNCTION_INCOMING_ARG
3392 entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
3393 passed_type, ! last_named);
3395 entry_parm = FUNCTION_ARG (args_so_far, promoted_mode,
3396 passed_type, ! last_named);
3399 if (entry_parm == 0)
3400 promoted_mode = passed_mode;
3402 #ifdef SETUP_INCOMING_VARARGS
3403 /* If this is the last named parameter, do any required setup for
3404 varargs or stdargs. We need to know about the case of this being an
3405 addressable type, in which case we skip the registers it
3406 would have arrived in.
3408 For stdargs, LAST_NAMED will be set for two parameters, the one that
3409 is actually the last named, and the dummy parameter. We only
3410 want to do this action once.
3412 Also, indicate when RTL generation is to be suppressed. */
3413 if (last_named && !varargs_setup)
3415 SETUP_INCOMING_VARARGS (args_so_far, promoted_mode, passed_type,
3416 current_function_pretend_args_size,
3422 /* Determine parm's home in the stack,
3423 in case it arrives in the stack or we should pretend it did.
3425 Compute the stack position and rtx where the argument arrives
3428 There is one complexity here: If this was a parameter that would
3429 have been passed in registers, but wasn't only because it is
3430 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
3431 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
3432 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
3433 0 as it was the previous time. */
3435 locate_and_pad_parm (promoted_mode, passed_type,
3436 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3439 #ifdef FUNCTION_INCOMING_ARG
3440 FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
3443 || varargs_setup)) != 0,
3445 FUNCTION_ARG (args_so_far, promoted_mode,
3447 ! last_named || varargs_setup) != 0,
3450 fndecl, &stack_args_size, &stack_offset, &arg_size);
3454 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
3456 if (offset_rtx == const0_rtx)
3457 stack_parm = gen_rtx (MEM, promoted_mode, internal_arg_pointer);
3459 stack_parm = gen_rtx (MEM, promoted_mode,
3460 gen_rtx (PLUS, Pmode,
3461 internal_arg_pointer, offset_rtx));
3463 /* If this is a memory ref that contains aggregate components,
3464 mark it as such for cse and loop optimize. */
3465 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3468 /* If this parameter was passed both in registers and in the stack,
3469 use the copy on the stack. */
3470 if (MUST_PASS_IN_STACK (promoted_mode, passed_type))
3473 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3474 /* If this parm was passed part in regs and part in memory,
3475 pretend it arrived entirely in memory
3476 by pushing the register-part onto the stack.
3478 In the special case of a DImode or DFmode that is split,
3479 we could put it together in a pseudoreg directly,
3480 but for now that's not worth bothering with. */
3484 int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, promoted_mode,
3485 passed_type, ! last_named);
3489 current_function_pretend_args_size
3490 = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
3491 / (PARM_BOUNDARY / BITS_PER_UNIT)
3492 * (PARM_BOUNDARY / BITS_PER_UNIT));
3495 move_block_from_reg (REGNO (entry_parm),
3496 validize_mem (stack_parm), nregs,
3497 int_size_in_bytes (TREE_TYPE (parm)));
3498 entry_parm = stack_parm;
3503 /* If we didn't decide this parm came in a register,
3504 by default it came on the stack. */
3505 if (entry_parm == 0)
3506 entry_parm = stack_parm;
3508 /* Record permanently how this parm was passed. */
3510 DECL_INCOMING_RTL (parm) = entry_parm;
3512 /* If there is actually space on the stack for this parm,
3513 count it in stack_args_size; otherwise set stack_parm to 0
3514 to indicate there is no preallocated stack slot for the parm. */
3516 if (entry_parm == stack_parm
3517 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
3518 /* On some machines, even if a parm value arrives in a register
3519 there is still an (uninitialized) stack slot allocated for it.
3521 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
3522 whether this parameter already has a stack slot allocated,
3523 because an arg block exists only if current_function_args_size
3524 is larger than some threshold, and we haven't calculated that
3525 yet. So, for now, we just assume that stack slots never exist
3527 || REG_PARM_STACK_SPACE (fndecl) > 0
3531 stack_args_size.constant += arg_size.constant;
3533 ADD_PARM_SIZE (stack_args_size, arg_size.var);
3536 /* No stack slot was pushed for this parm. */
3539 /* Update info on where next arg arrives in registers. */
3541 FUNCTION_ARG_ADVANCE (args_so_far, promoted_mode,
3542 passed_type, ! last_named);
3544 /* If this is our second time through, we are done with this parm. */
3548 /* If we can't trust the parm stack slot to be aligned enough
3549 for its ultimate type, don't use that slot after entry.
3550 We'll make another stack slot, if we need one. */
3552 int thisparm_boundary
3553 = FUNCTION_ARG_BOUNDARY (promoted_mode, passed_type);
3555 if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary)
3559 /* If parm was passed in memory, and we need to convert it on entry,
3560 don't store it back in that same slot. */
3562 && nominal_mode != BLKmode && nominal_mode != passed_mode)
3566 /* Now adjust STACK_PARM to the mode and precise location
3567 where this parameter should live during execution,
3568 if we discover that it must live in the stack during execution.
3569 To make debuggers happier on big-endian machines, we store
3570 the value in the last bytes of the space available. */
3572 if (nominal_mode != BLKmode && nominal_mode != passed_mode
3577 if (BYTES_BIG_ENDIAN
3578 && GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD)
3579 stack_offset.constant += (GET_MODE_SIZE (passed_mode)
3580 - GET_MODE_SIZE (nominal_mode));
3582 offset_rtx = ARGS_SIZE_RTX (stack_offset);
3583 if (offset_rtx == const0_rtx)
3584 stack_parm = gen_rtx (MEM, nominal_mode, internal_arg_pointer);
3586 stack_parm = gen_rtx (MEM, nominal_mode,
3587 gen_rtx (PLUS, Pmode,
3588 internal_arg_pointer, offset_rtx));
3590 /* If this is a memory ref that contains aggregate components,
3591 mark it as such for cse and loop optimize. */
3592 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3597 /* We need this "use" info, because the gcc-register->stack-register
3598 converter in reg-stack.c needs to know which registers are active
3599 at the start of the function call. The actual parameter loading
3600 instructions are not always available then anymore, since they might
3601 have been optimised away. */
3603 if (GET_CODE (entry_parm) == REG && !(hide_last_arg && last_named))
3604 emit_insn (gen_rtx (USE, GET_MODE (entry_parm), entry_parm));
3607 /* ENTRY_PARM is an RTX for the parameter as it arrives,
3608 in the mode in which it arrives.
3609 STACK_PARM is an RTX for a stack slot where the parameter can live
3610 during the function (in case we want to put it there).
3611 STACK_PARM is 0 if no stack slot was pushed for it.
3613 Now output code if necessary to convert ENTRY_PARM to
3614 the type in which this function declares it,
3615 and store that result in an appropriate place,
3616 which may be a pseudo reg, may be STACK_PARM,
3617 or may be a local stack slot if STACK_PARM is 0.
3619 Set DECL_RTL to that place. */
3621 if (nominal_mode == BLKmode)
3623 /* If a BLKmode arrives in registers, copy it to a stack slot. */
3624 if (GET_CODE (entry_parm) == REG)
3627 = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
3630 /* Note that we will be storing an integral number of words.
3631 So we have to be careful to ensure that we allocate an
3632 integral number of words. We do this below in the
3633 assign_stack_local if space was not allocated in the argument
3634 list. If it was, this will not work if PARM_BOUNDARY is not
3635 a multiple of BITS_PER_WORD. It isn't clear how to fix this
3636 if it becomes a problem. */
3638 if (stack_parm == 0)
3641 = assign_stack_local (GET_MODE (entry_parm),
3644 /* If this is a memory ref that contains aggregate
3645 components, mark it as such for cse and loop optimize. */
3646 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3649 else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
3652 if (TREE_READONLY (parm))
3653 RTX_UNCHANGING_P (stack_parm) = 1;
3655 move_block_from_reg (REGNO (entry_parm),
3656 validize_mem (stack_parm),
3657 size_stored / UNITS_PER_WORD,
3658 int_size_in_bytes (TREE_TYPE (parm)));
3660 DECL_RTL (parm) = stack_parm;
3662 else if (! ((obey_regdecls && ! DECL_REGISTER (parm)
3663 && ! DECL_INLINE (fndecl))
3664 /* layout_decl may set this. */
3665 || TREE_ADDRESSABLE (parm)
3666 || TREE_SIDE_EFFECTS (parm)
3667 /* If -ffloat-store specified, don't put explicit
3668 float variables into registers. */
3669 || (flag_float_store
3670 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
3671 /* Always assign pseudo to structure return or item passed
3672 by invisible reference. */
3673 || passed_pointer || parm == function_result_decl)
3675 /* Store the parm in a pseudoregister during the function, but we
3676 may need to do it in a wider mode. */
3678 register rtx parmreg;
3679 int regno, regnoi, regnor;
3681 unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
3683 promoted_nominal_mode
3684 = promote_mode (TREE_TYPE (parm), nominal_mode, &unsignedp, 0);
3686 parmreg = gen_reg_rtx (promoted_nominal_mode);
3687 REG_USERVAR_P (parmreg) = 1;
3689 /* If this was an item that we received a pointer to, set DECL_RTL
3694 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (passed_type)), parmreg);
3695 MEM_IN_STRUCT_P (DECL_RTL (parm)) = aggregate;
3698 DECL_RTL (parm) = parmreg;
3700 /* Copy the value into the register. */
3701 if (nominal_mode != passed_mode
3702 || promoted_nominal_mode != promoted_mode)
3704 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
3705 mode, by the caller. We now have to convert it to
3706 NOMINAL_MODE, if different. However, PARMREG may be in
3707 a diffent mode than NOMINAL_MODE if it is being stored
3710 If ENTRY_PARM is a hard register, it might be in a register
3711 not valid for operating in its mode (e.g., an odd-numbered
3712 register for a DFmode). In that case, moves are the only
3713 thing valid, so we can't do a convert from there. This
3714 occurs when the calling sequence allow such misaligned
3717 In addition, the conversion may involve a call, which could
3718 clobber parameters which haven't been copied to pseudo
3719 registers yet. Therefore, we must first copy the parm to
3720 a pseudo reg here, and save the conversion until after all
3721 parameters have been moved. */
3723 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
3725 emit_move_insn (tempreg, validize_mem (entry_parm));
3727 push_to_sequence (conversion_insns);
3728 tempreg = convert_to_mode (nominal_mode, tempreg, unsignedp);
3730 expand_assignment (parm,
3731 make_tree (nominal_type, tempreg), 0, 0);
3732 conversion_insns = get_insns ();
3737 emit_move_insn (parmreg, validize_mem (entry_parm));
3739 /* If we were passed a pointer but the actual value
3740 can safely live in a register, put it in one. */
3741 if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
3742 && ! ((obey_regdecls && ! DECL_REGISTER (parm)
3743 && ! DECL_INLINE (fndecl))
3744 /* layout_decl may set this. */
3745 || TREE_ADDRESSABLE (parm)
3746 || TREE_SIDE_EFFECTS (parm)
3747 /* If -ffloat-store specified, don't put explicit
3748 float variables into registers. */
3749 || (flag_float_store
3750 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))
3752 /* We can't use nominal_mode, because it will have been set to
3753 Pmode above. We must use the actual mode of the parm. */
3754 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
3755 REG_USERVAR_P (parmreg) = 1;
3756 emit_move_insn (parmreg, DECL_RTL (parm));
3757 DECL_RTL (parm) = parmreg;
3758 /* STACK_PARM is the pointer, not the parm, and PARMREG is
3762 #ifdef FUNCTION_ARG_CALLEE_COPIES
3763 /* If we are passed an arg by reference and it is our responsibility
3764 to make a copy, do it now.
3765 PASSED_TYPE and PASSED mode now refer to the pointer, not the
3766 original argument, so we must recreate them in the call to
3767 FUNCTION_ARG_CALLEE_COPIES. */
3768 /* ??? Later add code to handle the case that if the argument isn't
3769 modified, don't do the copy. */
3771 else if (passed_pointer
3772 && FUNCTION_ARG_CALLEE_COPIES (args_so_far,
3773 TYPE_MODE (DECL_ARG_TYPE (parm)),
3774 DECL_ARG_TYPE (parm),
3776 && ! TREE_ADDRESSABLE (DECL_ARG_TYPE (parm)))
3779 tree type = DECL_ARG_TYPE (parm);
3781 /* This sequence may involve a library call perhaps clobbering
3782 registers that haven't been copied to pseudos yet. */
3784 push_to_sequence (conversion_insns);
3786 if (TYPE_SIZE (type) == 0
3787 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
3788 /* This is a variable sized object. */
3789 copy = gen_rtx (MEM, BLKmode,
3790 allocate_dynamic_stack_space
3791 (expr_size (parm), NULL_RTX,
3792 TYPE_ALIGN (type)));
3794 copy = assign_stack_temp (TYPE_MODE (type),
3795 int_size_in_bytes (type), 1);
3796 MEM_IN_STRUCT_P (copy) = AGGREGATE_TYPE_P (type);
3798 store_expr (parm, copy, 0);
3799 emit_move_insn (parmreg, XEXP (copy, 0));
3800 conversion_insns = get_insns ();
3804 #endif /* FUNCTION_ARG_CALLEE_COPIES */
3806 /* In any case, record the parm's desired stack location
3807 in case we later discover it must live in the stack.
3809 If it is a COMPLEX value, store the stack location for both
3812 if (GET_CODE (parmreg) == CONCAT)
3813 regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1)));
3815 regno = REGNO (parmreg);
3817 if (regno >= nparmregs)
3820 int old_nparmregs = nparmregs;
3822 nparmregs = regno + 5;
3823 new = (rtx *) oballoc (nparmregs * sizeof (rtx));
3824 bcopy ((char *) parm_reg_stack_loc, (char *) new,
3825 old_nparmregs * sizeof (rtx));
3826 bzero ((char *) (new + old_nparmregs),
3827 (nparmregs - old_nparmregs) * sizeof (rtx));
3828 parm_reg_stack_loc = new;
3831 if (GET_CODE (parmreg) == CONCAT)
3833 enum machine_mode submode = GET_MODE (XEXP (parmreg, 0));
3835 regnor = REGNO (gen_realpart (submode, parmreg));
3836 regnoi = REGNO (gen_imagpart (submode, parmreg));
3838 if (stack_parm != 0)
3840 parm_reg_stack_loc[regnor]
3841 = gen_realpart (submode, stack_parm);
3842 parm_reg_stack_loc[regnoi]
3843 = gen_imagpart (submode, stack_parm);
3847 parm_reg_stack_loc[regnor] = 0;
3848 parm_reg_stack_loc[regnoi] = 0;
3852 parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
3854 /* Mark the register as eliminable if we did no conversion
3855 and it was copied from memory at a fixed offset,
3856 and the arg pointer was not copied to a pseudo-reg.
3857 If the arg pointer is a pseudo reg or the offset formed
3858 an invalid address, such memory-equivalences
3859 as we make here would screw up life analysis for it. */
3860 if (nominal_mode == passed_mode
3862 && GET_CODE (entry_parm) == MEM
3863 && entry_parm == stack_parm
3864 && stack_offset.var == 0
3865 && reg_mentioned_p (virtual_incoming_args_rtx,
3866 XEXP (entry_parm, 0)))
3868 rtx linsn = get_last_insn ();
3870 /* Mark complex types separately. */
3871 if (GET_CODE (parmreg) == CONCAT)
3874 = gen_rtx (EXPR_LIST, REG_EQUIV,
3875 parm_reg_stack_loc[regnoi], REG_NOTES (linsn));
3877 /* Now search backward for where we set the real part. */
3879 && ! reg_referenced_p (parm_reg_stack_loc[regnor],
3881 linsn = prev_nonnote_insn (linsn))
3885 = gen_rtx (EXPR_LIST, REG_EQUIV,
3886 parm_reg_stack_loc[regnor], REG_NOTES (linsn));
3890 = gen_rtx (EXPR_LIST, REG_EQUIV,
3891 entry_parm, REG_NOTES (linsn));
3894 /* For pointer data type, suggest pointer register. */
3895 if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE)
3896 mark_reg_pointer (parmreg,
3897 (TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm)))
3902 /* Value must be stored in the stack slot STACK_PARM
3903 during function execution. */
3905 if (promoted_mode != nominal_mode)
3907 /* Conversion is required. */
3908 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
3910 emit_move_insn (tempreg, validize_mem (entry_parm));
3912 push_to_sequence (conversion_insns);
3913 entry_parm = convert_to_mode (nominal_mode, tempreg,
3914 TREE_UNSIGNED (TREE_TYPE (parm)));
3915 conversion_insns = get_insns ();
3920 if (entry_parm != stack_parm)
3922 if (stack_parm == 0)
3925 = assign_stack_local (GET_MODE (entry_parm),
3926 GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
3927 /* If this is a memory ref that contains aggregate components,
3928 mark it as such for cse and loop optimize. */
3929 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3932 if (promoted_mode != nominal_mode)
3934 push_to_sequence (conversion_insns);
3935 emit_move_insn (validize_mem (stack_parm),
3936 validize_mem (entry_parm));
3937 conversion_insns = get_insns ();
3941 emit_move_insn (validize_mem (stack_parm),
3942 validize_mem (entry_parm));
3945 DECL_RTL (parm) = stack_parm;
3948 /* If this "parameter" was the place where we are receiving the
3949 function's incoming structure pointer, set up the result. */
3950 if (parm == function_result_decl)
3952 tree result = DECL_RESULT (fndecl);
3953 tree restype = TREE_TYPE (result);
3956 = gen_rtx (MEM, DECL_MODE (result), DECL_RTL (parm));
3958 MEM_IN_STRUCT_P (DECL_RTL (result)) = AGGREGATE_TYPE_P (restype);
3961 if (TREE_THIS_VOLATILE (parm))
3962 MEM_VOLATILE_P (DECL_RTL (parm)) = 1;
3963 if (TREE_READONLY (parm))
3964 RTX_UNCHANGING_P (DECL_RTL (parm)) = 1;
3967 /* Output all parameter conversion instructions (possibly including calls)
3968 now that all parameters have been copied out of hard registers. */
3969 emit_insns (conversion_insns);
3971 max_parm_reg = max_reg_num ();
3972 last_parm_insn = get_last_insn ();
3974 current_function_args_size = stack_args_size.constant;
3976 /* Adjust function incoming argument size for alignment and
3979 #ifdef REG_PARM_STACK_SPACE
3980 #ifndef MAYBE_REG_PARM_STACK_SPACE
3981 current_function_args_size = MAX (current_function_args_size,
3982 REG_PARM_STACK_SPACE (fndecl));
3986 #ifdef STACK_BOUNDARY
3987 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
3989 current_function_args_size
3990 = ((current_function_args_size + STACK_BYTES - 1)
3991 / STACK_BYTES) * STACK_BYTES;
3994 #ifdef ARGS_GROW_DOWNWARD
3995 current_function_arg_offset_rtx
3996 = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
3997 : expand_expr (size_binop (MINUS_EXPR, stack_args_size.var,
3998 size_int (-stack_args_size.constant)),
3999 NULL_RTX, VOIDmode, 0));
4001 current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
4004 /* See how many bytes, if any, of its args a function should try to pop
4007 current_function_pops_args = RETURN_POPS_ARGS (fndecl, TREE_TYPE (fndecl),
4008 current_function_args_size);
4010 /* For stdarg.h function, save info about
4011 regs and stack space used by the named args. */
4014 current_function_args_info = args_so_far;
4016 /* Set the rtx used for the function return value. Put this in its
4017 own variable so any optimizers that need this information don't have
4018 to include tree.h. Do this here so it gets done when an inlined
4019 function gets output. */
4021 current_function_return_rtx = DECL_RTL (DECL_RESULT (fndecl));
4024 /* Indicate whether REGNO is an incoming argument to the current function
4025 that was promoted to a wider mode. If so, return the RTX for the
4026 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
4027 that REGNO is promoted from and whether the promotion was signed or
4030 #ifdef PROMOTE_FUNCTION_ARGS
4033 promoted_input_arg (regno, pmode, punsignedp)
4035 enum machine_mode *pmode;
4040 for (arg = DECL_ARGUMENTS (current_function_decl); arg;
4041 arg = TREE_CHAIN (arg))
4042 if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
4043 && REGNO (DECL_INCOMING_RTL (arg)) == regno
4044 && TYPE_MODE (DECL_ARG_TYPE (arg)) == TYPE_MODE (TREE_TYPE (arg)))
4046 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
4047 int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
4049 mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1);
4050 if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
4051 && mode != DECL_MODE (arg))
4053 *pmode = DECL_MODE (arg);
4054 *punsignedp = unsignedp;
4055 return DECL_INCOMING_RTL (arg);
4064 /* Compute the size and offset from the start of the stacked arguments for a
4065 parm passed in mode PASSED_MODE and with type TYPE.
4067 INITIAL_OFFSET_PTR points to the current offset into the stacked
4070 The starting offset and size for this parm are returned in *OFFSET_PTR
4071 and *ARG_SIZE_PTR, respectively.
4073 IN_REGS is non-zero if the argument will be passed in registers. It will
4074 never be set if REG_PARM_STACK_SPACE is not defined.
4076 FNDECL is the function in which the argument was defined.
4078 There are two types of rounding that are done. The first, controlled by
4079 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
4080 list to be aligned to the specific boundary (in bits). This rounding
4081 affects the initial and starting offsets, but not the argument size.
4083 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
4084 optionally rounds the size of the parm to PARM_BOUNDARY. The
4085 initial offset is not affected by this rounding, while the size always
4086 is and the starting offset may be. */
4088 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
4089 initial_offset_ptr is positive because locate_and_pad_parm's
4090 callers pass in the total size of args so far as
4091 initial_offset_ptr. arg_size_ptr is always positive.*/
4094 locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
4095 initial_offset_ptr, offset_ptr, arg_size_ptr)
4096 enum machine_mode passed_mode;
4100 struct args_size *initial_offset_ptr;
4101 struct args_size *offset_ptr;
4102 struct args_size *arg_size_ptr;
4105 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
4106 enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
4107 int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
4108 int boundary_in_bytes = boundary / BITS_PER_UNIT;
4109 int reg_parm_stack_space = 0;
4111 #ifdef REG_PARM_STACK_SPACE
4112 /* If we have found a stack parm before we reach the end of the
4113 area reserved for registers, skip that area. */
4116 #ifdef MAYBE_REG_PARM_STACK_SPACE
4117 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
4119 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
4121 if (reg_parm_stack_space > 0)
4123 if (initial_offset_ptr->var)
4125 initial_offset_ptr->var
4126 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
4127 size_int (reg_parm_stack_space));
4128 initial_offset_ptr->constant = 0;
4130 else if (initial_offset_ptr->constant < reg_parm_stack_space)
4131 initial_offset_ptr->constant = reg_parm_stack_space;
4134 #endif /* REG_PARM_STACK_SPACE */
4136 arg_size_ptr->var = 0;
4137 arg_size_ptr->constant = 0;
4139 #ifdef ARGS_GROW_DOWNWARD
4140 if (initial_offset_ptr->var)
4142 offset_ptr->constant = 0;
4143 offset_ptr->var = size_binop (MINUS_EXPR, integer_zero_node,
4144 initial_offset_ptr->var);
4148 offset_ptr->constant = - initial_offset_ptr->constant;
4149 offset_ptr->var = 0;
4151 if (where_pad != none
4152 && (TREE_CODE (sizetree) != INTEGER_CST
4153 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
4154 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4155 SUB_PARM_SIZE (*offset_ptr, sizetree);
4156 if (where_pad != downward)
4157 pad_to_arg_alignment (offset_ptr, boundary);
4158 if (initial_offset_ptr->var)
4160 arg_size_ptr->var = size_binop (MINUS_EXPR,
4161 size_binop (MINUS_EXPR,
4163 initial_offset_ptr->var),
4168 arg_size_ptr->constant = (- initial_offset_ptr->constant -
4169 offset_ptr->constant);
4171 #else /* !ARGS_GROW_DOWNWARD */
4172 pad_to_arg_alignment (initial_offset_ptr, boundary);
4173 *offset_ptr = *initial_offset_ptr;
4175 #ifdef PUSH_ROUNDING
4176 if (passed_mode != BLKmode)
4177 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
4180 /* Pad_below needs the pre-rounded size to know how much to pad below
4181 so this must be done before rounding up. */
4182 if (where_pad == downward
4183 /* However, BLKmode args passed in regs have their padding done elsewhere.
4184 The stack slot must be able to hold the entire register. */
4185 && !(in_regs && passed_mode == BLKmode))
4186 pad_below (offset_ptr, passed_mode, sizetree);
4188 if (where_pad != none
4189 && (TREE_CODE (sizetree) != INTEGER_CST
4190 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
4191 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4193 ADD_PARM_SIZE (*arg_size_ptr, sizetree);
4194 #endif /* ARGS_GROW_DOWNWARD */
4197 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
4198 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
4201 pad_to_arg_alignment (offset_ptr, boundary)
4202 struct args_size *offset_ptr;
4205 int boundary_in_bytes = boundary / BITS_PER_UNIT;
4207 if (boundary > BITS_PER_UNIT)
4209 if (offset_ptr->var)
4212 #ifdef ARGS_GROW_DOWNWARD
4217 (ARGS_SIZE_TREE (*offset_ptr),
4218 boundary / BITS_PER_UNIT);
4219 offset_ptr->constant = 0; /*?*/
4222 offset_ptr->constant =
4223 #ifdef ARGS_GROW_DOWNWARD
4224 FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes);
4226 CEIL_ROUND (offset_ptr->constant, boundary_in_bytes);
4232 pad_below (offset_ptr, passed_mode, sizetree)
4233 struct args_size *offset_ptr;
4234 enum machine_mode passed_mode;
4237 if (passed_mode != BLKmode)
4239 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
4240 offset_ptr->constant
4241 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
4242 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
4243 - GET_MODE_SIZE (passed_mode));
4247 if (TREE_CODE (sizetree) != INTEGER_CST
4248 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
4250 /* Round the size up to multiple of PARM_BOUNDARY bits. */
4251 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4253 ADD_PARM_SIZE (*offset_ptr, s2);
4254 SUB_PARM_SIZE (*offset_ptr, sizetree);
4260 round_down (value, divisor)
4264 return size_binop (MULT_EXPR,
4265 size_binop (FLOOR_DIV_EXPR, value, size_int (divisor)),
4266 size_int (divisor));
4269 /* Walk the tree of blocks describing the binding levels within a function
4270 and warn about uninitialized variables.
4271 This is done after calling flow_analysis and before global_alloc
4272 clobbers the pseudo-regs to hard regs. */
4275 uninitialized_vars_warning (block)
4278 register tree decl, sub;
4279 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
4281 if (TREE_CODE (decl) == VAR_DECL
4282 /* These warnings are unreliable for and aggregates
4283 because assigning the fields one by one can fail to convince
4284 flow.c that the entire aggregate was initialized.
4285 Unions are troublesome because members may be shorter. */
4286 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl))
4287 && DECL_RTL (decl) != 0
4288 && GET_CODE (DECL_RTL (decl)) == REG
4289 && regno_uninitialized (REGNO (DECL_RTL (decl))))
4290 warning_with_decl (decl,
4291 "`%s' might be used uninitialized in this function");
4292 if (TREE_CODE (decl) == VAR_DECL
4293 && DECL_RTL (decl) != 0
4294 && GET_CODE (DECL_RTL (decl)) == REG
4295 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
4296 warning_with_decl (decl,
4297 "variable `%s' might be clobbered by `longjmp' or `vfork'");
4299 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
4300 uninitialized_vars_warning (sub);
4303 /* Do the appropriate part of uninitialized_vars_warning
4304 but for arguments instead of local variables. */
4307 setjmp_args_warning ()
4310 for (decl = DECL_ARGUMENTS (current_function_decl);
4311 decl; decl = TREE_CHAIN (decl))
4312 if (DECL_RTL (decl) != 0
4313 && GET_CODE (DECL_RTL (decl)) == REG
4314 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
4315 warning_with_decl (decl, "argument `%s' might be clobbered by `longjmp' or `vfork'");
4318 /* If this function call setjmp, put all vars into the stack
4319 unless they were declared `register'. */
4322 setjmp_protect (block)
4325 register tree decl, sub;
4326 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
4327 if ((TREE_CODE (decl) == VAR_DECL
4328 || TREE_CODE (decl) == PARM_DECL)
4329 && DECL_RTL (decl) != 0
4330 && GET_CODE (DECL_RTL (decl)) == REG
4331 /* If this variable came from an inline function, it must be
4332 that it's life doesn't overlap the setjmp. If there was a
4333 setjmp in the function, it would already be in memory. We
4334 must exclude such variable because their DECL_RTL might be
4335 set to strange things such as virtual_stack_vars_rtx. */
4336 && ! DECL_FROM_INLINE (decl)
4338 #ifdef NON_SAVING_SETJMP
4339 /* If longjmp doesn't restore the registers,
4340 don't put anything in them. */
4344 ! DECL_REGISTER (decl)))
4345 put_var_into_stack (decl);
4346 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
4347 setjmp_protect (sub);
4350 /* Like the previous function, but for args instead of local variables. */
4353 setjmp_protect_args ()
4355 register tree decl, sub;
4356 for (decl = DECL_ARGUMENTS (current_function_decl);
4357 decl; decl = TREE_CHAIN (decl))
4358 if ((TREE_CODE (decl) == VAR_DECL
4359 || TREE_CODE (decl) == PARM_DECL)
4360 && DECL_RTL (decl) != 0
4361 && GET_CODE (DECL_RTL (decl)) == REG
4363 /* If longjmp doesn't restore the registers,
4364 don't put anything in them. */
4365 #ifdef NON_SAVING_SETJMP
4369 ! DECL_REGISTER (decl)))
4370 put_var_into_stack (decl);
4373 /* Return the context-pointer register corresponding to DECL,
4374 or 0 if it does not need one. */
4377 lookup_static_chain (decl)
4380 tree context = decl_function_context (decl);
4384 || (TREE_CODE (decl) == FUNCTION_DECL && DECL_NO_STATIC_CHAIN (decl)))
4387 /* We treat inline_function_decl as an alias for the current function
4388 because that is the inline function whose vars, types, etc.
4389 are being merged into the current function.
4390 See expand_inline_function. */
4391 if (context == current_function_decl || context == inline_function_decl)
4392 return virtual_stack_vars_rtx;
4394 for (link = context_display; link; link = TREE_CHAIN (link))
4395 if (TREE_PURPOSE (link) == context)
4396 return RTL_EXPR_RTL (TREE_VALUE (link));
4401 /* Convert a stack slot address ADDR for variable VAR
4402 (from a containing function)
4403 into an address valid in this function (using a static chain). */
4406 fix_lexical_addr (addr, var)
4412 tree context = decl_function_context (var);
4413 struct function *fp;
4416 /* If this is the present function, we need not do anything. */
4417 if (context == current_function_decl || context == inline_function_decl)
4420 for (fp = outer_function_chain; fp; fp = fp->next)
4421 if (fp->decl == context)
4427 /* Decode given address as base reg plus displacement. */
4428 if (GET_CODE (addr) == REG)
4429 basereg = addr, displacement = 0;
4430 else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
4431 basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
4435 /* We accept vars reached via the containing function's
4436 incoming arg pointer and via its stack variables pointer. */
4437 if (basereg == fp->internal_arg_pointer)
4439 /* If reached via arg pointer, get the arg pointer value
4440 out of that function's stack frame.
4442 There are two cases: If a separate ap is needed, allocate a
4443 slot in the outer function for it and dereference it that way.
4444 This is correct even if the real ap is actually a pseudo.
4445 Otherwise, just adjust the offset from the frame pointer to
4448 #ifdef NEED_SEPARATE_AP
4451 if (fp->arg_pointer_save_area == 0)
4452 fp->arg_pointer_save_area
4453 = assign_outer_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0, fp);
4455 addr = fix_lexical_addr (XEXP (fp->arg_pointer_save_area, 0), var);
4456 addr = memory_address (Pmode, addr);
4458 base = copy_to_reg (gen_rtx (MEM, Pmode, addr));
4460 displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
4461 base = lookup_static_chain (var);
4465 else if (basereg == virtual_stack_vars_rtx)
4467 /* This is the same code as lookup_static_chain, duplicated here to
4468 avoid an extra call to decl_function_context. */
4471 for (link = context_display; link; link = TREE_CHAIN (link))
4472 if (TREE_PURPOSE (link) == context)
4474 base = RTL_EXPR_RTL (TREE_VALUE (link));
4482 /* Use same offset, relative to appropriate static chain or argument
4484 return plus_constant (base, displacement);
4487 /* Return the address of the trampoline for entering nested fn FUNCTION.
4488 If necessary, allocate a trampoline (in the stack frame)
4489 and emit rtl to initialize its contents (at entry to this function). */
4492 trampoline_address (function)
4498 struct function *fp;
4501 /* Find an existing trampoline and return it. */
4502 for (link = trampoline_list; link; link = TREE_CHAIN (link))
4503 if (TREE_PURPOSE (link) == function)
4505 round_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0));
4507 for (fp = outer_function_chain; fp; fp = fp->next)
4508 for (link = fp->trampoline_list; link; link = TREE_CHAIN (link))
4509 if (TREE_PURPOSE (link) == function)
4511 tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
4513 return round_trampoline_addr (tramp);
4516 /* None exists; we must make one. */
4518 /* Find the `struct function' for the function containing FUNCTION. */
4520 fn_context = decl_function_context (function);
4521 if (fn_context != current_function_decl)
4522 for (fp = outer_function_chain; fp; fp = fp->next)
4523 if (fp->decl == fn_context)
4526 /* Allocate run-time space for this trampoline
4527 (usually in the defining function's stack frame). */
4528 #ifdef ALLOCATE_TRAMPOLINE
4529 tramp = ALLOCATE_TRAMPOLINE (fp);
4531 /* If rounding needed, allocate extra space
4532 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
4533 #ifdef TRAMPOLINE_ALIGNMENT
4534 #define TRAMPOLINE_REAL_SIZE \
4535 (TRAMPOLINE_SIZE + (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT) - 1)
4537 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
4540 tramp = assign_outer_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0, fp);
4542 tramp = assign_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0);
4545 /* Record the trampoline for reuse and note it for later initialization
4546 by expand_function_end. */
4549 push_obstacks (fp->function_maybepermanent_obstack,
4550 fp->function_maybepermanent_obstack);
4551 rtlexp = make_node (RTL_EXPR);
4552 RTL_EXPR_RTL (rtlexp) = tramp;
4553 fp->trampoline_list = tree_cons (function, rtlexp, fp->trampoline_list);
4558 /* Make the RTL_EXPR node temporary, not momentary, so that the
4559 trampoline_list doesn't become garbage. */
4560 int momentary = suspend_momentary ();
4561 rtlexp = make_node (RTL_EXPR);
4562 resume_momentary (momentary);
4564 RTL_EXPR_RTL (rtlexp) = tramp;
4565 trampoline_list = tree_cons (function, rtlexp, trampoline_list);
4568 tramp = fix_lexical_addr (XEXP (tramp, 0), function);
4569 return round_trampoline_addr (tramp);
4572 /* Given a trampoline address,
4573 round it to multiple of TRAMPOLINE_ALIGNMENT. */
4576 round_trampoline_addr (tramp)
4579 #ifdef TRAMPOLINE_ALIGNMENT
4580 /* Round address up to desired boundary. */
4581 rtx temp = gen_reg_rtx (Pmode);
4582 temp = expand_binop (Pmode, add_optab, tramp,
4583 GEN_INT (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT - 1),
4584 temp, 0, OPTAB_LIB_WIDEN);
4585 tramp = expand_binop (Pmode, and_optab, temp,
4586 GEN_INT (- TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT),
4587 temp, 0, OPTAB_LIB_WIDEN);
4592 /* The functions identify_blocks and reorder_blocks provide a way to
4593 reorder the tree of BLOCK nodes, for optimizers that reshuffle or
4594 duplicate portions of the RTL code. Call identify_blocks before
4595 changing the RTL, and call reorder_blocks after. */
4597 /* Put all this function's BLOCK nodes including those that are chained
4598 onto the first block into a vector, and return it.
4599 Also store in each NOTE for the beginning or end of a block
4600 the index of that block in the vector.
4601 The arguments are BLOCK, the chain of top-level blocks of the function,
4602 and INSNS, the insn chain of the function. */
4605 identify_blocks (block, insns)
4613 int next_block_number = 1;
4614 int current_block_number = 1;
4620 n_blocks = all_blocks (block, 0);
4621 block_vector = (tree *) xmalloc (n_blocks * sizeof (tree));
4622 block_stack = (int *) alloca (n_blocks * sizeof (int));
4624 all_blocks (block, block_vector);
4626 for (insn = insns; insn; insn = NEXT_INSN (insn))
4627 if (GET_CODE (insn) == NOTE)
4629 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
4631 block_stack[depth++] = current_block_number;
4632 current_block_number = next_block_number;
4633 NOTE_BLOCK_NUMBER (insn) = next_block_number++;
4635 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
4637 current_block_number = block_stack[--depth];
4638 NOTE_BLOCK_NUMBER (insn) = current_block_number;
4642 if (n_blocks != next_block_number)
4645 return block_vector;
4648 /* Given BLOCK_VECTOR which was returned by identify_blocks,
4649 and a revised instruction chain, rebuild the tree structure
4650 of BLOCK nodes to correspond to the new order of RTL.
4651 The new block tree is inserted below TOP_BLOCK.
4652 Returns the current top-level block. */
4655 reorder_blocks (block_vector, block, insns)
4660 tree current_block = block;
4663 if (block_vector == 0)
4666 /* Prune the old trees away, so that it doesn't get in the way. */
4667 BLOCK_SUBBLOCKS (current_block) = 0;
4668 BLOCK_CHAIN (current_block) = 0;
4670 for (insn = insns; insn; insn = NEXT_INSN (insn))
4671 if (GET_CODE (insn) == NOTE)
4673 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
4675 tree block = block_vector[NOTE_BLOCK_NUMBER (insn)];
4676 /* If we have seen this block before, copy it. */
4677 if (TREE_ASM_WRITTEN (block))
4678 block = copy_node (block);
4679 BLOCK_SUBBLOCKS (block) = 0;
4680 TREE_ASM_WRITTEN (block) = 1;
4681 BLOCK_SUPERCONTEXT (block) = current_block;
4682 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
4683 BLOCK_SUBBLOCKS (current_block) = block;
4684 current_block = block;
4685 NOTE_SOURCE_FILE (insn) = 0;
4687 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
4689 BLOCK_SUBBLOCKS (current_block)
4690 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
4691 current_block = BLOCK_SUPERCONTEXT (current_block);
4692 NOTE_SOURCE_FILE (insn) = 0;
4696 BLOCK_SUBBLOCKS (current_block)
4697 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
4698 return current_block;
4701 /* Reverse the order of elements in the chain T of blocks,
4702 and return the new head of the chain (old last element). */
4708 register tree prev = 0, decl, next;
4709 for (decl = t; decl; decl = next)
4711 next = BLOCK_CHAIN (decl);
4712 BLOCK_CHAIN (decl) = prev;
4718 /* Count the subblocks of the list starting with BLOCK, and list them
4719 all into the vector VECTOR. Also clear TREE_ASM_WRITTEN in all
4723 all_blocks (block, vector)
4731 TREE_ASM_WRITTEN (block) = 0;
4733 /* Record this block. */
4735 vector[n_blocks] = block;
4739 /* Record the subblocks, and their subblocks... */
4740 n_blocks += all_blocks (BLOCK_SUBBLOCKS (block),
4741 vector ? vector + n_blocks : 0);
4742 block = BLOCK_CHAIN (block);
4748 /* Build bytecode call descriptor for function SUBR. */
4751 bc_build_calldesc (subr)
4754 tree calldesc = 0, arg;
4757 /* Build the argument description vector in reverse order. */
4758 DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
4761 for (arg = DECL_ARGUMENTS (subr); arg; arg = TREE_CHAIN (arg))
4765 calldesc = tree_cons ((tree) 0, size_in_bytes (TREE_TYPE (arg)), calldesc);
4766 calldesc = tree_cons ((tree) 0, bc_runtime_type_code (TREE_TYPE (arg)), calldesc);
4769 DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
4771 /* Prepend the function's return type. */
4772 calldesc = tree_cons ((tree) 0,
4773 size_in_bytes (TREE_TYPE (TREE_TYPE (subr))),
4776 calldesc = tree_cons ((tree) 0,
4777 bc_runtime_type_code (TREE_TYPE (TREE_TYPE (subr))),
4780 /* Prepend the arg count. */
4781 calldesc = tree_cons ((tree) 0, build_int_2 (nargs, 0), calldesc);
4783 /* Output the call description vector and get its address. */
4784 calldesc = build_nt (CONSTRUCTOR, (tree) 0, calldesc);
4785 TREE_TYPE (calldesc) = build_array_type (integer_type_node,
4786 build_index_type (build_int_2 (nargs * 2, 0)));
4788 return output_constant_def (calldesc);
4792 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
4793 and initialize static variables for generating RTL for the statements
4797 init_function_start (subr, filename, line)
4804 if (output_bytecode)
4806 this_function_decl = subr;
4807 this_function_calldesc = bc_build_calldesc (subr);
4808 local_vars_size = 0;
4810 max_stack_depth = 0;
4811 stmt_expr_depth = 0;
4815 init_stmt_for_function ();
4817 cse_not_expected = ! optimize;
4819 /* Caller save not needed yet. */
4820 caller_save_needed = 0;
4822 /* No stack slots have been made yet. */
4823 stack_slot_list = 0;
4825 /* There is no stack slot for handling nonlocal gotos. */
4826 nonlocal_goto_handler_slot = 0;
4827 nonlocal_goto_stack_level = 0;
4829 /* No labels have been declared for nonlocal use. */
4830 nonlocal_labels = 0;
4832 /* No function calls so far in this function. */
4833 function_call_count = 0;
4835 /* No parm regs have been allocated.
4836 (This is important for output_inline_function.) */
4837 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
4839 /* Initialize the RTL mechanism. */
4842 /* Initialize the queue of pending postincrement and postdecrements,
4843 and some other info in expr.c. */
4846 /* We haven't done register allocation yet. */
4849 init_const_rtx_hash_table ();
4851 current_function_name = (*decl_printable_name) (subr, &junk);
4853 /* Nonzero if this is a nested function that uses a static chain. */
4855 current_function_needs_context
4856 = (decl_function_context (current_function_decl) != 0
4857 && ! DECL_NO_STATIC_CHAIN (current_function_decl));
4859 /* Set if a call to setjmp is seen. */
4860 current_function_calls_setjmp = 0;
4862 /* Set if a call to longjmp is seen. */
4863 current_function_calls_longjmp = 0;
4865 current_function_calls_alloca = 0;
4866 current_function_has_nonlocal_label = 0;
4867 current_function_has_nonlocal_goto = 0;
4868 current_function_contains_functions = 0;
4870 current_function_returns_pcc_struct = 0;
4871 current_function_returns_struct = 0;
4872 current_function_epilogue_delay_list = 0;
4873 current_function_uses_const_pool = 0;
4874 current_function_uses_pic_offset_table = 0;
4876 /* We have not yet needed to make a label to jump to for tail-recursion. */
4877 tail_recursion_label = 0;
4879 /* We haven't had a need to make a save area for ap yet. */
4881 arg_pointer_save_area = 0;
4883 /* No stack slots allocated yet. */
4886 /* No SAVE_EXPRs in this function yet. */
4889 /* No RTL_EXPRs in this function yet. */
4892 /* Set up to allocate temporaries. */
4895 /* Within function body, compute a type's size as soon it is laid out. */
4896 immediate_size_expand++;
4898 /* We haven't made any trampolines for this function yet. */
4899 trampoline_list = 0;
4901 init_pending_stack_adjust ();
4902 inhibit_defer_pop = 0;
4904 current_function_outgoing_args_size = 0;
4906 /* Prevent ever trying to delete the first instruction of a function.
4907 Also tell final how to output a linenum before the function prologue. */
4908 emit_line_note (filename, line);
4910 /* Make sure first insn is a note even if we don't want linenums.
4911 This makes sure the first insn will never be deleted.
4912 Also, final expects a note to appear there. */
4913 emit_note (NULL_PTR, NOTE_INSN_DELETED);
4915 /* Set flags used by final.c. */
4916 if (aggregate_value_p (DECL_RESULT (subr)))
4918 #ifdef PCC_STATIC_STRUCT_RETURN
4919 current_function_returns_pcc_struct = 1;
4921 current_function_returns_struct = 1;
4924 /* Warn if this value is an aggregate type,
4925 regardless of which calling convention we are using for it. */
4926 if (warn_aggregate_return
4927 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
4928 warning ("function returns an aggregate");
4930 current_function_returns_pointer
4931 = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
4933 /* Indicate that we need to distinguish between the return value of the
4934 present function and the return value of a function being called. */
4935 rtx_equal_function_value_matters = 1;
4937 /* Indicate that we have not instantiated virtual registers yet. */
4938 virtuals_instantiated = 0;
4940 /* Indicate we have no need of a frame pointer yet. */
4941 frame_pointer_needed = 0;
4943 /* By default assume not varargs or stdarg. */
4944 current_function_varargs = 0;
4945 current_function_stdarg = 0;
4948 /* Indicate that the current function uses extra args
4949 not explicitly mentioned in the argument list in any fashion. */
4954 current_function_varargs = 1;
4957 /* Expand a call to __main at the beginning of a possible main function. */
4959 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
4960 #undef HAS_INIT_SECTION
4961 #define HAS_INIT_SECTION
4965 expand_main_function ()
4967 if (!output_bytecode)
4969 /* The zero below avoids a possible parse error */
4971 #if !defined (HAS_INIT_SECTION)
4972 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, NAME__MAIN), 0,
4974 #endif /* not HAS_INIT_SECTION */
4978 extern struct obstack permanent_obstack;
4980 /* Expand start of bytecode function. See comment at
4981 expand_function_start below for details. */
4984 bc_expand_function_start (subr, parms_have_cleanups)
4986 int parms_have_cleanups;
4988 char label[20], *name;
4993 if (TREE_PUBLIC (subr))
4994 bc_globalize_label (IDENTIFIER_POINTER (DECL_NAME (subr)));
4996 #ifdef DEBUG_PRINT_CODE
4997 fprintf (stderr, "\n<func %s>\n", IDENTIFIER_POINTER (DECL_NAME (subr)));
5000 for (argsz = 0, thisarg = DECL_ARGUMENTS (subr); thisarg; thisarg = TREE_CHAIN (thisarg))
5002 if (DECL_RTL (thisarg))
5003 abort (); /* Should be NULL here I think. */
5004 else if (TREE_CONSTANT (DECL_SIZE (thisarg)))
5006 DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
5007 argsz += TREE_INT_CST_LOW (DECL_SIZE (thisarg));
5011 /* Variable-sized objects are pointers to their storage. */
5012 DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
5013 argsz += POINTER_SIZE;
5017 bc_begin_function (xstrdup (IDENTIFIER_POINTER (DECL_NAME (subr))));
5019 ASM_GENERATE_INTERNAL_LABEL (label, "LX", nlab);
5022 name = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
5023 this_function_callinfo = bc_gen_rtx (name, 0, (struct bc_label *) 0);
5024 this_function_bytecode =
5025 bc_emit_trampoline (BYTECODE_LABEL (this_function_callinfo));
5029 /* Expand end of bytecode function. See details the comment of
5030 expand_function_end(), below. */
5033 bc_expand_function_end ()
5037 expand_null_return ();
5039 /* Emit any fixup code. This must be done before the call to
5040 to BC_END_FUNCTION (), since that will cause the bytecode
5041 segment to be finished off and closed. */
5043 expand_fixups (NULL_RTX);
5045 ptrconsts = bc_end_function ();
5047 bc_align_const (2 /* INT_ALIGN */);
5049 /* If this changes also make sure to change bc-interp.h! */
5051 bc_emit_const_labeldef (BYTECODE_LABEL (this_function_callinfo));
5052 bc_emit_const ((char *) &max_stack_depth, sizeof max_stack_depth);
5053 bc_emit_const ((char *) &local_vars_size, sizeof local_vars_size);
5054 bc_emit_const_labelref (this_function_bytecode, 0);
5055 bc_emit_const_labelref (ptrconsts, 0);
5056 bc_emit_const_labelref (BYTECODE_LABEL (this_function_calldesc), 0);
5060 /* Start the RTL for a new function, and set variables used for
5062 SUBR is the FUNCTION_DECL node.
5063 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
5064 the function's parameters, which must be run at any return statement. */
5067 expand_function_start (subr, parms_have_cleanups)
5069 int parms_have_cleanups;
5075 if (output_bytecode)
5077 bc_expand_function_start (subr, parms_have_cleanups);
5081 /* Make sure volatile mem refs aren't considered
5082 valid operands of arithmetic insns. */
5083 init_recog_no_volatile ();
5085 /* If function gets a static chain arg, store it in the stack frame.
5086 Do this first, so it gets the first stack slot offset. */
5087 if (current_function_needs_context)
5089 last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
5091 #ifdef SMALL_REGISTER_CLASSES
5092 /* Delay copying static chain if it is not a register to avoid
5093 conflicts with regs used for parameters. */
5094 if (GET_CODE (static_chain_incoming_rtx) == REG)
5096 emit_move_insn (last_ptr, static_chain_incoming_rtx);
5099 /* If the parameters of this function need cleaning up, get a label
5100 for the beginning of the code which executes those cleanups. This must
5101 be done before doing anything with return_label. */
5102 if (parms_have_cleanups)
5103 cleanup_label = gen_label_rtx ();
5107 /* Make the label for return statements to jump to, if this machine
5108 does not have a one-instruction return and uses an epilogue,
5109 or if it returns a structure, or if it has parm cleanups. */
5111 if (cleanup_label == 0 && HAVE_return
5112 && ! current_function_returns_pcc_struct
5113 && ! (current_function_returns_struct && ! optimize))
5116 return_label = gen_label_rtx ();
5118 return_label = gen_label_rtx ();
5121 /* Initialize rtx used to return the value. */
5122 /* Do this before assign_parms so that we copy the struct value address
5123 before any library calls that assign parms might generate. */
5125 /* Decide whether to return the value in memory or in a register. */
5126 if (aggregate_value_p (DECL_RESULT (subr)))
5128 /* Returning something that won't go in a register. */
5129 register rtx value_address = 0;
5131 #ifdef PCC_STATIC_STRUCT_RETURN
5132 if (current_function_returns_pcc_struct)
5134 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
5135 value_address = assemble_static_space (size);
5140 /* Expect to be passed the address of a place to store the value.
5141 If it is passed as an argument, assign_parms will take care of
5143 if (struct_value_incoming_rtx)
5145 value_address = gen_reg_rtx (Pmode);
5146 emit_move_insn (value_address, struct_value_incoming_rtx);
5151 DECL_RTL (DECL_RESULT (subr))
5152 = gen_rtx (MEM, DECL_MODE (DECL_RESULT (subr)), value_address);
5153 MEM_IN_STRUCT_P (DECL_RTL (DECL_RESULT (subr)))
5154 = AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
5157 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
5158 /* If return mode is void, this decl rtl should not be used. */
5159 DECL_RTL (DECL_RESULT (subr)) = 0;
5160 else if (parms_have_cleanups)
5162 /* If function will end with cleanup code for parms,
5163 compute the return values into a pseudo reg,
5164 which we will copy into the true return register
5165 after the cleanups are done. */
5167 enum machine_mode mode = DECL_MODE (DECL_RESULT (subr));
5169 #ifdef PROMOTE_FUNCTION_RETURN
5170 tree type = TREE_TYPE (DECL_RESULT (subr));
5171 int unsignedp = TREE_UNSIGNED (type);
5173 mode = promote_mode (type, mode, &unsignedp, 1);
5176 DECL_RTL (DECL_RESULT (subr)) = gen_reg_rtx (mode);
5179 /* Scalar, returned in a register. */
5181 #ifdef FUNCTION_OUTGOING_VALUE
5182 DECL_RTL (DECL_RESULT (subr))
5183 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
5185 DECL_RTL (DECL_RESULT (subr))
5186 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
5189 /* Mark this reg as the function's return value. */
5190 if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG)
5192 REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1;
5193 /* Needed because we may need to move this to memory
5194 in case it's a named return value whose address is taken. */
5195 DECL_REGISTER (DECL_RESULT (subr)) = 1;
5199 /* Initialize rtx for parameters and local variables.
5200 In some cases this requires emitting insns. */
5202 assign_parms (subr, 0);
5204 #ifdef SMALL_REGISTER_CLASSES
5205 /* Copy the static chain now if it wasn't a register. The delay is to
5206 avoid conflicts with the parameter passing registers. */
5208 if (current_function_needs_context)
5209 if (GET_CODE (static_chain_incoming_rtx) != REG)
5210 emit_move_insn (last_ptr, static_chain_incoming_rtx);
5213 /* The following was moved from init_function_start.
5214 The move is supposed to make sdb output more accurate. */
5215 /* Indicate the beginning of the function body,
5216 as opposed to parm setup. */
5217 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_BEG);
5219 /* If doing stupid allocation, mark parms as born here. */
5221 if (GET_CODE (get_last_insn ()) != NOTE)
5222 emit_note (NULL_PTR, NOTE_INSN_DELETED);
5223 parm_birth_insn = get_last_insn ();
5227 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
5228 use_variable (regno_reg_rtx[i]);
5230 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
5231 use_variable (current_function_internal_arg_pointer);
5234 context_display = 0;
5235 if (current_function_needs_context)
5237 /* Fetch static chain values for containing functions. */
5238 tem = decl_function_context (current_function_decl);
5239 /* If not doing stupid register allocation copy the static chain
5240 pointer into a pseudo. If we have small register classes, copy
5241 the value from memory if static_chain_incoming_rtx is a REG. If
5242 we do stupid register allocation, we use the stack address
5244 if (tem && ! obey_regdecls)
5246 #ifdef SMALL_REGISTER_CLASSES
5247 /* If the static chain originally came in a register, put it back
5248 there, then move it out in the next insn. The reason for
5249 this peculiar code is to satisfy function integration. */
5250 if (GET_CODE (static_chain_incoming_rtx) == REG)
5251 emit_move_insn (static_chain_incoming_rtx, last_ptr);
5254 last_ptr = copy_to_reg (static_chain_incoming_rtx);
5259 tree rtlexp = make_node (RTL_EXPR);
5261 RTL_EXPR_RTL (rtlexp) = last_ptr;
5262 context_display = tree_cons (tem, rtlexp, context_display);
5263 tem = decl_function_context (tem);
5266 /* Chain thru stack frames, assuming pointer to next lexical frame
5267 is found at the place we always store it. */
5268 #ifdef FRAME_GROWS_DOWNWARD
5269 last_ptr = plus_constant (last_ptr, - GET_MODE_SIZE (Pmode));
5271 last_ptr = copy_to_reg (gen_rtx (MEM, Pmode,
5272 memory_address (Pmode, last_ptr)));
5274 /* If we are not optimizing, ensure that we know that this
5275 piece of context is live over the entire function. */
5277 save_expr_regs = gen_rtx (EXPR_LIST, VOIDmode, last_ptr,
5282 /* After the display initializations is where the tail-recursion label
5283 should go, if we end up needing one. Ensure we have a NOTE here
5284 since some things (like trampolines) get placed before this. */
5285 tail_recursion_reentry = emit_note (NULL_PTR, NOTE_INSN_DELETED);
5287 /* Evaluate now the sizes of any types declared among the arguments. */
5288 for (tem = nreverse (get_pending_sizes ()); tem; tem = TREE_CHAIN (tem))
5289 expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode, 0);
5291 /* Make sure there is a line number after the function entry setup code. */
5292 force_next_line_note ();
5295 /* Generate RTL for the end of the current function.
5296 FILENAME and LINE are the current position in the source file.
5298 It is up to language-specific callers to do cleanups for parameters--
5299 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */
5302 expand_function_end (filename, line, end_bindings)
5310 static rtx initial_trampoline;
5312 if (output_bytecode)
5314 bc_expand_function_end ();
5318 #ifdef NON_SAVING_SETJMP
5319 /* Don't put any variables in registers if we call setjmp
5320 on a machine that fails to restore the registers. */
5321 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
5323 if (DECL_INITIAL (current_function_decl) != error_mark_node)
5324 setjmp_protect (DECL_INITIAL (current_function_decl));
5326 setjmp_protect_args ();
5330 /* Save the argument pointer if a save area was made for it. */
5331 if (arg_pointer_save_area)
5333 rtx x = gen_move_insn (arg_pointer_save_area, virtual_incoming_args_rtx);
5334 emit_insn_before (x, tail_recursion_reentry);
5337 /* Initialize any trampolines required by this function. */
5338 for (link = trampoline_list; link; link = TREE_CHAIN (link))
5340 tree function = TREE_PURPOSE (link);
5341 rtx context = lookup_static_chain (function);
5342 rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
5345 /* First make sure this compilation has a template for
5346 initializing trampolines. */
5347 if (initial_trampoline == 0)
5349 end_temporary_allocation ();
5351 = gen_rtx (MEM, BLKmode, assemble_trampoline_template ());
5352 resume_temporary_allocation ();
5355 /* Generate insns to initialize the trampoline. */
5357 tramp = change_address (initial_trampoline, BLKmode,
5358 round_trampoline_addr (XEXP (tramp, 0)));
5359 emit_block_move (tramp, initial_trampoline, GEN_INT (TRAMPOLINE_SIZE),
5360 FUNCTION_BOUNDARY / BITS_PER_UNIT);
5361 INITIALIZE_TRAMPOLINE (XEXP (tramp, 0),
5362 XEXP (DECL_RTL (function), 0), context);
5366 /* Put those insns at entry to the containing function (this one). */
5367 emit_insns_before (seq, tail_recursion_reentry);
5370 /* Warn about unused parms if extra warnings were specified. */
5371 if (warn_unused && extra_warnings)
5375 for (decl = DECL_ARGUMENTS (current_function_decl);
5376 decl; decl = TREE_CHAIN (decl))
5377 if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
5378 && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
5379 warning_with_decl (decl, "unused parameter `%s'");
5382 /* Delete handlers for nonlocal gotos if nothing uses them. */
5383 if (nonlocal_goto_handler_slot != 0 && !current_function_has_nonlocal_label)
5386 /* End any sequences that failed to be closed due to syntax errors. */
5387 while (in_sequence_p ())
5390 /* Outside function body, can't compute type's actual size
5391 until next function's body starts. */
5392 immediate_size_expand--;
5394 /* If doing stupid register allocation,
5395 mark register parms as dying here. */
5400 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
5401 use_variable (regno_reg_rtx[i]);
5403 /* Likewise for the regs of all the SAVE_EXPRs in the function. */
5405 for (tem = save_expr_regs; tem; tem = XEXP (tem, 1))
5407 use_variable (XEXP (tem, 0));
5408 use_variable_after (XEXP (tem, 0), parm_birth_insn);
5411 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
5412 use_variable (current_function_internal_arg_pointer);
5415 clear_pending_stack_adjust ();
5416 do_pending_stack_adjust ();
5418 /* Mark the end of the function body.
5419 If control reaches this insn, the function can drop through
5420 without returning a value. */
5421 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_END);
5423 /* Output a linenumber for the end of the function.
5424 SDB depends on this. */
5425 emit_line_note_force (filename, line);
5427 /* Output the label for the actual return from the function,
5428 if one is expected. This happens either because a function epilogue
5429 is used instead of a return instruction, or because a return was done
5430 with a goto in order to run local cleanups, or because of pcc-style
5431 structure returning. */
5434 emit_label (return_label);
5436 /* C++ uses this. */
5438 expand_end_bindings (0, 0, 0);
5440 /* If we had calls to alloca, and this machine needs
5441 an accurate stack pointer to exit the function,
5442 insert some code to save and restore the stack pointer. */
5443 #ifdef EXIT_IGNORE_STACK
5444 if (! EXIT_IGNORE_STACK)
5446 if (current_function_calls_alloca)
5450 emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
5451 emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
5454 /* If scalar return value was computed in a pseudo-reg,
5455 copy that to the hard return register. */
5456 if (DECL_RTL (DECL_RESULT (current_function_decl)) != 0
5457 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG
5458 && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl)))
5459 >= FIRST_PSEUDO_REGISTER))
5461 rtx real_decl_result;
5463 #ifdef FUNCTION_OUTGOING_VALUE
5465 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
5466 current_function_decl);
5469 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
5470 current_function_decl);
5472 REG_FUNCTION_VALUE_P (real_decl_result) = 1;
5473 emit_move_insn (real_decl_result,
5474 DECL_RTL (DECL_RESULT (current_function_decl)));
5475 emit_insn (gen_rtx (USE, VOIDmode, real_decl_result));
5478 /* If returning a structure, arrange to return the address of the value
5479 in a place where debuggers expect to find it.
5481 If returning a structure PCC style,
5482 the caller also depends on this value.
5483 And current_function_returns_pcc_struct is not necessarily set. */
5484 if (current_function_returns_struct
5485 || current_function_returns_pcc_struct)
5487 rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
5488 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
5489 #ifdef FUNCTION_OUTGOING_VALUE
5491 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
5492 current_function_decl);
5495 = FUNCTION_VALUE (build_pointer_type (type),
5496 current_function_decl);
5499 /* Mark this as a function return value so integrate will delete the
5500 assignment and USE below when inlining this function. */
5501 REG_FUNCTION_VALUE_P (outgoing) = 1;
5503 emit_move_insn (outgoing, value_address);
5504 use_variable (outgoing);
5507 /* Output a return insn if we are using one.
5508 Otherwise, let the rtl chain end here, to drop through
5509 into the epilogue. */
5514 emit_jump_insn (gen_return ());
5519 /* Fix up any gotos that jumped out to the outermost
5520 binding level of the function.
5521 Must follow emitting RETURN_LABEL. */
5523 /* If you have any cleanups to do at this point,
5524 and they need to create temporary variables,
5525 then you will lose. */
5526 expand_fixups (get_insns ());
5529 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
5531 static int *prologue;
5532 static int *epilogue;
5534 /* Create an array that records the INSN_UIDs of INSNS (either a sequence
5535 or a single insn). */
5538 record_insns (insns)
5543 if (GET_CODE (insns) == SEQUENCE)
5545 int len = XVECLEN (insns, 0);
5546 vec = (int *) oballoc ((len + 1) * sizeof (int));
5549 vec[len] = INSN_UID (XVECEXP (insns, 0, len));
5553 vec = (int *) oballoc (2 * sizeof (int));
5554 vec[0] = INSN_UID (insns);
5560 /* Determine how many INSN_UIDs in VEC are part of INSN. */
5563 contains (insn, vec)
5569 if (GET_CODE (insn) == INSN
5570 && GET_CODE (PATTERN (insn)) == SEQUENCE)
5573 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
5574 for (j = 0; vec[j]; j++)
5575 if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == vec[j])
5581 for (j = 0; vec[j]; j++)
5582 if (INSN_UID (insn) == vec[j])
5588 /* Generate the prologue and epilogue RTL if the machine supports it. Thread
5589 this into place with notes indicating where the prologue ends and where
5590 the epilogue begins. Update the basic block information when possible. */
5593 thread_prologue_and_epilogue_insns (f)
5596 #ifdef HAVE_prologue
5599 rtx head, seq, insn;
5601 /* The first insn (a NOTE_INSN_DELETED) is followed by zero or more
5602 prologue insns and a NOTE_INSN_PROLOGUE_END. */
5603 emit_note_after (NOTE_INSN_PROLOGUE_END, f);
5604 seq = gen_prologue ();
5605 head = emit_insn_after (seq, f);
5607 /* Include the new prologue insns in the first block. Ignore them
5608 if they form a basic block unto themselves. */
5609 if (basic_block_head && n_basic_blocks
5610 && GET_CODE (basic_block_head[0]) != CODE_LABEL)
5611 basic_block_head[0] = NEXT_INSN (f);
5613 /* Retain a map of the prologue insns. */
5614 prologue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : head);
5620 #ifdef HAVE_epilogue
5623 rtx insn = get_last_insn ();
5624 rtx prev = prev_nonnote_insn (insn);
5626 /* If we end with a BARRIER, we don't need an epilogue. */
5627 if (! (prev && GET_CODE (prev) == BARRIER))
5633 /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, the
5634 epilogue insns, the USE insns at the end of a function,
5635 the jump insn that returns, and then a BARRIER. */
5637 /* Move the USE insns at the end of a function onto a list. */
5639 && GET_CODE (prev) == INSN
5640 && GET_CODE (PATTERN (prev)) == USE)
5643 prev = prev_nonnote_insn (prev);
5645 NEXT_INSN (PREV_INSN (tem)) = NEXT_INSN (tem);
5646 PREV_INSN (NEXT_INSN (tem)) = PREV_INSN (tem);
5649 NEXT_INSN (tem) = first_use;
5650 PREV_INSN (first_use) = tem;
5657 emit_barrier_after (insn);
5659 seq = gen_epilogue ();
5660 tail = emit_jump_insn_after (seq, insn);
5662 /* Insert the USE insns immediately before the return insn, which
5663 must be the first instruction before the final barrier. */
5666 tem = prev_nonnote_insn (get_last_insn ());
5667 NEXT_INSN (PREV_INSN (tem)) = first_use;
5668 PREV_INSN (first_use) = PREV_INSN (tem);
5669 PREV_INSN (tem) = last_use;
5670 NEXT_INSN (last_use) = tem;
5673 emit_note_after (NOTE_INSN_EPILOGUE_BEG, insn);
5675 /* Include the new epilogue insns in the last block. Ignore
5676 them if they form a basic block unto themselves. */
5677 if (basic_block_end && n_basic_blocks
5678 && GET_CODE (basic_block_end[n_basic_blocks - 1]) != JUMP_INSN)
5679 basic_block_end[n_basic_blocks - 1] = tail;
5681 /* Retain a map of the epilogue insns. */
5682 epilogue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : tail);
5690 /* Reposition the prologue-end and epilogue-begin notes after instruction
5691 scheduling and delayed branch scheduling. */
5694 reposition_prologue_and_epilogue_notes (f)
5697 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
5698 /* Reposition the prologue and epilogue notes. */
5706 register rtx insn, note = 0;
5708 /* Scan from the beginning until we reach the last prologue insn.
5709 We apparently can't depend on basic_block_{head,end} after
5711 for (len = 0; prologue[len]; len++)
5713 for (insn = f; len && insn; insn = NEXT_INSN (insn))
5715 if (GET_CODE (insn) == NOTE)
5717 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
5720 else if ((len -= contains (insn, prologue)) == 0)
5722 /* Find the prologue-end note if we haven't already, and
5723 move it to just after the last prologue insn. */
5726 for (note = insn; note = NEXT_INSN (note);)
5727 if (GET_CODE (note) == NOTE
5728 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
5731 next = NEXT_INSN (note);
5732 prev = PREV_INSN (note);
5734 NEXT_INSN (prev) = next;
5736 PREV_INSN (next) = prev;
5737 add_insn_after (note, insn);
5744 register rtx insn, note = 0;
5746 /* Scan from the end until we reach the first epilogue insn.
5747 We apparently can't depend on basic_block_{head,end} after
5749 for (len = 0; epilogue[len]; len++)
5751 for (insn = get_last_insn (); len && insn; insn = PREV_INSN (insn))
5753 if (GET_CODE (insn) == NOTE)
5755 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
5758 else if ((len -= contains (insn, epilogue)) == 0)
5760 /* Find the epilogue-begin note if we haven't already, and
5761 move it to just before the first epilogue insn. */
5764 for (note = insn; note = PREV_INSN (note);)
5765 if (GET_CODE (note) == NOTE
5766 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
5769 next = NEXT_INSN (note);
5770 prev = PREV_INSN (note);
5772 NEXT_INSN (prev) = next;
5774 PREV_INSN (next) = prev;
5775 add_insn_after (note, PREV_INSN (insn));
5780 #endif /* HAVE_prologue or HAVE_epilogue */