* i386.c (notice_update_cc): Remove bogus pentium GCC code.
[official-gcc.git] / gcc / function.c
blob057da555c71ab4211e211150df151e4a2d5cfc62
1 /* Expands front end tree to back end RTL for GNU C-Compiler
2 Copyright (C) 1987, 88, 89, 91-96, 1997 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)
9 any later version.
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. */
41 #include "config.h"
42 #include <stdio.h>
43 #include "rtl.h"
44 #include "tree.h"
45 #include "flags.h"
46 #include "except.h"
47 #include "function.h"
48 #include "insn-flags.h"
49 #include "expr.h"
50 #include "insn-codes.h"
51 #include "regs.h"
52 #include "hard-reg-set.h"
53 #include "insn-config.h"
54 #include "recog.h"
55 #include "output.h"
56 #include "basic-block.h"
57 #include "obstack.h"
58 #include "bytecode.h"
59 #include "bc-emit.h"
61 #ifndef TRAMPOLINE_ALIGNMENT
62 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
63 #endif
65 /* Some systems use __main in a way incompatible with its use in gcc, in these
66 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
67 give the same symbol without quotes for an alternative entry point. You
68 must define both, or neither. */
69 #ifndef NAME__MAIN
70 #define NAME__MAIN "__main"
71 #define SYMBOL__MAIN __main
72 #endif
74 /* Round a value to the lowest integer less than it that is a multiple of
75 the required alignment. Avoid using division in case the value is
76 negative. Assume the alignment is a power of two. */
77 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
79 /* Similar, but round to the next highest integer that meets the
80 alignment. */
81 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
83 /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp
84 during rtl generation. If they are different register numbers, this is
85 always true. It may also be true if
86 FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl
87 generation. See fix_lexical_addr for details. */
89 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
90 #define NEED_SEPARATE_AP
91 #endif
93 /* Number of bytes of args popped by function being compiled on its return.
94 Zero if no bytes are to be popped.
95 May affect compilation of return insn or of function epilogue. */
97 int current_function_pops_args;
99 /* Nonzero if function being compiled needs to be given an address
100 where the value should be stored. */
102 int current_function_returns_struct;
104 /* Nonzero if function being compiled needs to
105 return the address of where it has put a structure value. */
107 int current_function_returns_pcc_struct;
109 /* Nonzero if function being compiled needs to be passed a static chain. */
111 int current_function_needs_context;
113 /* Nonzero if function being compiled can call setjmp. */
115 int current_function_calls_setjmp;
117 /* Nonzero if function being compiled can call longjmp. */
119 int current_function_calls_longjmp;
121 /* Nonzero if function being compiled receives nonlocal gotos
122 from nested functions. */
124 int current_function_has_nonlocal_label;
126 /* Nonzero if function being compiled has nonlocal gotos to parent
127 function. */
129 int current_function_has_nonlocal_goto;
131 /* Nonzero if function being compiled contains nested functions. */
133 int current_function_contains_functions;
135 /* Nonzero if the current function is a thunk (a lightweight function that
136 just adjusts one of its arguments and forwards to another function), so
137 we should try to cut corners where we can. */
138 int current_function_is_thunk;
140 /* Nonzero if function being compiled can call alloca,
141 either as a subroutine or builtin. */
143 int current_function_calls_alloca;
145 /* Nonzero if the current function returns a pointer type */
147 int current_function_returns_pointer;
149 /* If some insns can be deferred to the delay slots of the epilogue, the
150 delay list for them is recorded here. */
152 rtx current_function_epilogue_delay_list;
154 /* If function's args have a fixed size, this is that size, in bytes.
155 Otherwise, it is -1.
156 May affect compilation of return insn or of function epilogue. */
158 int current_function_args_size;
160 /* # bytes the prologue should push and pretend that the caller pushed them.
161 The prologue must do this, but only if parms can be passed in registers. */
163 int current_function_pretend_args_size;
165 /* # of bytes of outgoing arguments. If ACCUMULATE_OUTGOING_ARGS is
166 defined, the needed space is pushed by the prologue. */
168 int current_function_outgoing_args_size;
170 /* This is the offset from the arg pointer to the place where the first
171 anonymous arg can be found, if there is one. */
173 rtx current_function_arg_offset_rtx;
175 /* Nonzero if current function uses varargs.h or equivalent.
176 Zero for functions that use stdarg.h. */
178 int current_function_varargs;
180 /* Nonzero if current function uses stdarg.h or equivalent.
181 Zero for functions that use varargs.h. */
183 int current_function_stdarg;
185 /* Quantities of various kinds of registers
186 used for the current function's args. */
188 CUMULATIVE_ARGS current_function_args_info;
190 /* Name of function now being compiled. */
192 char *current_function_name;
194 /* If non-zero, an RTL expression for the location at which the current
195 function returns its result. If the current function returns its
196 result in a register, current_function_return_rtx will always be
197 the hard register containing the result. */
199 rtx current_function_return_rtx;
201 /* Nonzero if the current function uses the constant pool. */
203 int current_function_uses_const_pool;
205 /* Nonzero if the current function uses pic_offset_table_rtx. */
206 int current_function_uses_pic_offset_table;
208 /* The arg pointer hard register, or the pseudo into which it was copied. */
209 rtx current_function_internal_arg_pointer;
211 /* The FUNCTION_DECL for an inline function currently being expanded. */
212 tree inline_function_decl;
214 /* Number of function calls seen so far in current function. */
216 int function_call_count;
218 /* List (chain of TREE_LIST) of LABEL_DECLs for all nonlocal labels
219 (labels to which there can be nonlocal gotos from nested functions)
220 in this function. */
222 tree nonlocal_labels;
224 /* RTX for stack slot that holds the current handler for nonlocal gotos.
225 Zero when function does not have nonlocal labels. */
227 rtx nonlocal_goto_handler_slot;
229 /* RTX for stack slot that holds the stack pointer value to restore
230 for a nonlocal goto.
231 Zero when function does not have nonlocal labels. */
233 rtx nonlocal_goto_stack_level;
235 /* Label that will go on parm cleanup code, if any.
236 Jumping to this label runs cleanup code for parameters, if
237 such code must be run. Following this code is the logical return label. */
239 rtx cleanup_label;
241 /* Label that will go on function epilogue.
242 Jumping to this label serves as a "return" instruction
243 on machines which require execution of the epilogue on all returns. */
245 rtx return_label;
247 /* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs.
248 So we can mark them all live at the end of the function, if nonopt. */
249 rtx save_expr_regs;
251 /* List (chain of EXPR_LISTs) of all stack slots in this function.
252 Made for the sake of unshare_all_rtl. */
253 rtx stack_slot_list;
255 /* Chain of all RTL_EXPRs that have insns in them. */
256 tree rtl_expr_chain;
258 /* Label to jump back to for tail recursion, or 0 if we have
259 not yet needed one for this function. */
260 rtx tail_recursion_label;
262 /* Place after which to insert the tail_recursion_label if we need one. */
263 rtx tail_recursion_reentry;
265 /* Location at which to save the argument pointer if it will need to be
266 referenced. There are two cases where this is done: if nonlocal gotos
267 exist, or if vars stored at an offset from the argument pointer will be
268 needed by inner routines. */
270 rtx arg_pointer_save_area;
272 /* Offset to end of allocated area of stack frame.
273 If stack grows down, this is the address of the last stack slot allocated.
274 If stack grows up, this is the address for the next slot. */
275 HOST_WIDE_INT frame_offset;
277 /* List (chain of TREE_LISTs) of static chains for containing functions.
278 Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
279 in an RTL_EXPR in the TREE_VALUE. */
280 static tree context_display;
282 /* List (chain of TREE_LISTs) of trampolines for nested functions.
283 The trampoline sets up the static chain and jumps to the function.
284 We supply the trampoline's address when the function's address is requested.
286 Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
287 in an RTL_EXPR in the TREE_VALUE. */
288 static tree trampoline_list;
290 /* Insn after which register parms and SAVE_EXPRs are born, if nonopt. */
291 static rtx parm_birth_insn;
293 #if 0
294 /* Nonzero if a stack slot has been generated whose address is not
295 actually valid. It means that the generated rtl must all be scanned
296 to detect and correct the invalid addresses where they occur. */
297 static int invalid_stack_slot;
298 #endif
300 /* Last insn of those whose job was to put parms into their nominal homes. */
301 static rtx last_parm_insn;
303 /* 1 + last pseudo register number used for loading a copy
304 of a parameter of this function. */
305 static int max_parm_reg;
307 /* Vector indexed by REGNO, containing location on stack in which
308 to put the parm which is nominally in pseudo register REGNO,
309 if we discover that that parm must go in the stack. */
310 static rtx *parm_reg_stack_loc;
312 /* Nonzero once virtual register instantiation has been done.
313 assign_stack_local uses frame_pointer_rtx when this is nonzero. */
314 static int virtuals_instantiated;
316 /* These variables hold pointers to functions to
317 save and restore machine-specific data,
318 in push_function_context and pop_function_context. */
319 void (*save_machine_status) PROTO((struct function *));
320 void (*restore_machine_status) PROTO((struct function *));
322 /* Nonzero if we need to distinguish between the return value of this function
323 and the return value of a function called by this function. This helps
324 integrate.c */
326 extern int rtx_equal_function_value_matters;
327 extern tree sequence_rtl_expr;
329 /* In order to evaluate some expressions, such as function calls returning
330 structures in memory, we need to temporarily allocate stack locations.
331 We record each allocated temporary in the following structure.
333 Associated with each temporary slot is a nesting level. When we pop up
334 one level, all temporaries associated with the previous level are freed.
335 Normally, all temporaries are freed after the execution of the statement
336 in which they were created. However, if we are inside a ({...}) grouping,
337 the result may be in a temporary and hence must be preserved. If the
338 result could be in a temporary, we preserve it if we can determine which
339 one it is in. If we cannot determine which temporary may contain the
340 result, all temporaries are preserved. A temporary is preserved by
341 pretending it was allocated at the previous nesting level.
343 Automatic variables are also assigned temporary slots, at the nesting
344 level where they are defined. They are marked a "kept" so that
345 free_temp_slots will not free them. */
347 struct temp_slot
349 /* Points to next temporary slot. */
350 struct temp_slot *next;
351 /* The rtx to used to reference the slot. */
352 rtx slot;
353 /* The rtx used to represent the address if not the address of the
354 slot above. May be an EXPR_LIST if multiple addresses exist. */
355 rtx address;
356 /* The size, in units, of the slot. */
357 int size;
358 /* The value of `sequence_rtl_expr' when this temporary is allocated. */
359 tree rtl_expr;
360 /* Non-zero if this temporary is currently in use. */
361 char in_use;
362 /* Non-zero if this temporary has its address taken. */
363 char addr_taken;
364 /* Nesting level at which this slot is being used. */
365 int level;
366 /* Non-zero if this should survive a call to free_temp_slots. */
367 int keep;
368 /* The offset of the slot from the frame_pointer, including extra space
369 for alignment. This info is for combine_temp_slots. */
370 int base_offset;
371 /* The size of the slot, including extra space for alignment. This
372 info is for combine_temp_slots. */
373 int full_size;
376 /* List of all temporaries allocated, both available and in use. */
378 struct temp_slot *temp_slots;
380 /* Current nesting level for temporaries. */
382 int temp_slot_level;
384 /* The FUNCTION_DECL node for the current function. */
385 static tree this_function_decl;
387 /* Callinfo pointer for the current function. */
388 static rtx this_function_callinfo;
390 /* The label in the bytecode file of this function's actual bytecode.
391 Not an rtx. */
392 static char *this_function_bytecode;
394 /* The call description vector for the current function. */
395 static rtx this_function_calldesc;
397 /* Size of the local variables allocated for the current function. */
398 int local_vars_size;
400 /* Current depth of the bytecode evaluation stack. */
401 int stack_depth;
403 /* Maximum depth of the evaluation stack in this function. */
404 int max_stack_depth;
406 /* Current depth in statement expressions. */
407 static int stmt_expr_depth;
409 /* This structure is used to record MEMs or pseudos used to replace VAR, any
410 SUBREGs of VAR, and any MEMs containing VAR as an address. We need to
411 maintain this list in case two operands of an insn were required to match;
412 in that case we must ensure we use the same replacement. */
414 struct fixup_replacement
416 rtx old;
417 rtx new;
418 struct fixup_replacement *next;
421 /* Forward declarations. */
423 static struct temp_slot *find_temp_slot_from_address PROTO((rtx));
424 static void put_reg_into_stack PROTO((struct function *, rtx, tree,
425 enum machine_mode, enum machine_mode,
426 int));
427 static void fixup_var_refs PROTO((rtx, enum machine_mode, int));
428 static struct fixup_replacement
429 *find_fixup_replacement PROTO((struct fixup_replacement **, rtx));
430 static void fixup_var_refs_insns PROTO((rtx, enum machine_mode, int,
431 rtx, int));
432 static void fixup_var_refs_1 PROTO((rtx, enum machine_mode, rtx *, rtx,
433 struct fixup_replacement **));
434 static rtx fixup_memory_subreg PROTO((rtx, rtx, int));
435 static rtx walk_fixup_memory_subreg PROTO((rtx, rtx, int));
436 static rtx fixup_stack_1 PROTO((rtx, rtx));
437 static void optimize_bit_field PROTO((rtx, rtx, rtx *));
438 static void instantiate_decls PROTO((tree, int));
439 static void instantiate_decls_1 PROTO((tree, int));
440 static void instantiate_decl PROTO((rtx, int, int));
441 static int instantiate_virtual_regs_1 PROTO((rtx *, rtx, int));
442 static void delete_handlers PROTO((void));
443 static void pad_to_arg_alignment PROTO((struct args_size *, int));
444 static void pad_below PROTO((struct args_size *, enum machine_mode,
445 tree));
446 static tree round_down PROTO((tree, int));
447 static rtx round_trampoline_addr PROTO((rtx));
448 static tree blocks_nreverse PROTO((tree));
449 static int all_blocks PROTO((tree, tree *));
450 static int *record_insns PROTO((rtx));
451 static int contains PROTO((rtx, int *));
453 /* Pointer to chain of `struct function' for containing functions. */
454 struct function *outer_function_chain;
456 /* Given a function decl for a containing function,
457 return the `struct function' for it. */
459 struct function *
460 find_function_data (decl)
461 tree decl;
463 struct function *p;
464 for (p = outer_function_chain; p; p = p->next)
465 if (p->decl == decl)
466 return p;
467 abort ();
470 /* Save the current context for compilation of a nested function.
471 This is called from language-specific code.
472 The caller is responsible for saving any language-specific status,
473 since this function knows only about language-independent variables. */
475 void
476 push_function_context_to (context)
477 tree context;
479 struct function *p = (struct function *) xmalloc (sizeof (struct function));
481 p->next = outer_function_chain;
482 outer_function_chain = p;
484 p->name = current_function_name;
485 p->decl = current_function_decl;
486 p->pops_args = current_function_pops_args;
487 p->returns_struct = current_function_returns_struct;
488 p->returns_pcc_struct = current_function_returns_pcc_struct;
489 p->returns_pointer = current_function_returns_pointer;
490 p->needs_context = current_function_needs_context;
491 p->calls_setjmp = current_function_calls_setjmp;
492 p->calls_longjmp = current_function_calls_longjmp;
493 p->calls_alloca = current_function_calls_alloca;
494 p->has_nonlocal_label = current_function_has_nonlocal_label;
495 p->has_nonlocal_goto = current_function_has_nonlocal_goto;
496 p->contains_functions = current_function_contains_functions;
497 p->is_thunk = current_function_is_thunk;
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;
531 p->args_info = current_function_args_info;
533 save_tree_status (p, context);
534 save_storage_status (p);
535 save_emit_status (p);
536 init_emit ();
537 save_expr_status (p);
538 save_stmt_status (p);
539 save_varasm_status (p);
541 if (save_machine_status)
542 (*save_machine_status) (p);
545 void
546 push_function_context ()
548 push_function_context_to (current_function_decl);
551 /* Restore the last saved context, at the end of a nested function.
552 This function is called from language-specific code. */
554 void
555 pop_function_context_from (context)
556 tree context;
558 struct function *p = outer_function_chain;
560 outer_function_chain = p->next;
562 current_function_contains_functions
563 = p->contains_functions || p->inline_obstacks
564 || context == current_function_decl;
565 current_function_name = p->name;
566 current_function_decl = p->decl;
567 current_function_pops_args = p->pops_args;
568 current_function_returns_struct = p->returns_struct;
569 current_function_returns_pcc_struct = p->returns_pcc_struct;
570 current_function_returns_pointer = p->returns_pointer;
571 current_function_needs_context = p->needs_context;
572 current_function_calls_setjmp = p->calls_setjmp;
573 current_function_calls_longjmp = p->calls_longjmp;
574 current_function_calls_alloca = p->calls_alloca;
575 current_function_has_nonlocal_label = p->has_nonlocal_label;
576 current_function_has_nonlocal_goto = p->has_nonlocal_goto;
577 current_function_is_thunk = p->is_thunk;
578 current_function_args_size = p->args_size;
579 current_function_pretend_args_size = p->pretend_args_size;
580 current_function_arg_offset_rtx = p->arg_offset_rtx;
581 current_function_varargs = p->varargs;
582 current_function_stdarg = p->stdarg;
583 current_function_uses_const_pool = p->uses_const_pool;
584 current_function_uses_pic_offset_table = p->uses_pic_offset_table;
585 current_function_internal_arg_pointer = p->internal_arg_pointer;
586 max_parm_reg = p->max_parm_reg;
587 parm_reg_stack_loc = p->parm_reg_stack_loc;
588 current_function_outgoing_args_size = p->outgoing_args_size;
589 current_function_return_rtx = p->return_rtx;
590 nonlocal_goto_handler_slot = p->nonlocal_goto_handler_slot;
591 nonlocal_goto_stack_level = p->nonlocal_goto_stack_level;
592 nonlocal_labels = p->nonlocal_labels;
593 cleanup_label = p->cleanup_label;
594 return_label = p->return_label;
595 save_expr_regs = p->save_expr_regs;
596 stack_slot_list = p->stack_slot_list;
597 parm_birth_insn = p->parm_birth_insn;
598 frame_offset = p->frame_offset;
599 tail_recursion_label = p->tail_recursion_label;
600 tail_recursion_reentry = p->tail_recursion_reentry;
601 arg_pointer_save_area = p->arg_pointer_save_area;
602 rtl_expr_chain = p->rtl_expr_chain;
603 last_parm_insn = p->last_parm_insn;
604 context_display = p->context_display;
605 trampoline_list = p->trampoline_list;
606 function_call_count = p->function_call_count;
607 temp_slots = p->temp_slots;
608 temp_slot_level = p->temp_slot_level;
609 current_function_epilogue_delay_list = p->epilogue_delay_list;
610 reg_renumber = 0;
611 current_function_args_info = p->args_info;
613 restore_tree_status (p, context);
614 restore_storage_status (p);
615 restore_expr_status (p);
616 restore_emit_status (p);
617 restore_stmt_status (p);
618 restore_varasm_status (p);
620 if (restore_machine_status)
621 (*restore_machine_status) (p);
623 /* Finish doing put_var_into_stack for any of our variables
624 which became addressable during the nested function. */
626 struct var_refs_queue *queue = p->fixup_var_refs_queue;
627 for (; queue; queue = queue->next)
628 fixup_var_refs (queue->modified, queue->promoted_mode, queue->unsignedp);
631 free (p);
633 /* Reset variables that have known state during rtx generation. */
634 rtx_equal_function_value_matters = 1;
635 virtuals_instantiated = 0;
638 void pop_function_context ()
640 pop_function_context_from (current_function_decl);
643 /* Allocate fixed slots in the stack frame of the current function. */
645 /* Return size needed for stack frame based on slots so far allocated.
646 This size counts from zero. It is not rounded to STACK_BOUNDARY;
647 the caller may have to do that. */
649 HOST_WIDE_INT
650 get_frame_size ()
652 #ifdef FRAME_GROWS_DOWNWARD
653 return -frame_offset;
654 #else
655 return frame_offset;
656 #endif
659 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
660 with machine mode MODE.
662 ALIGN controls the amount of alignment for the address of the slot:
663 0 means according to MODE,
664 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
665 positive specifies alignment boundary in bits.
667 We do not round to stack_boundary here. */
670 assign_stack_local (mode, size, align)
671 enum machine_mode mode;
672 int size;
673 int align;
675 register rtx x, addr;
676 int bigend_correction = 0;
677 int alignment;
679 if (align == 0)
681 alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
682 if (mode == BLKmode)
683 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
685 else if (align == -1)
687 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
688 size = CEIL_ROUND (size, alignment);
690 else
691 alignment = align / BITS_PER_UNIT;
693 /* Round frame offset to that alignment.
694 We must be careful here, since FRAME_OFFSET might be negative and
695 division with a negative dividend isn't as well defined as we might
696 like. So we instead assume that ALIGNMENT is a power of two and
697 use logical operations which are unambiguous. */
698 #ifdef FRAME_GROWS_DOWNWARD
699 frame_offset = FLOOR_ROUND (frame_offset, alignment);
700 #else
701 frame_offset = CEIL_ROUND (frame_offset, alignment);
702 #endif
704 /* On a big-endian machine, if we are allocating more space than we will use,
705 use the least significant bytes of those that are allocated. */
706 if (BYTES_BIG_ENDIAN && mode != BLKmode)
707 bigend_correction = size - GET_MODE_SIZE (mode);
709 #ifdef FRAME_GROWS_DOWNWARD
710 frame_offset -= size;
711 #endif
713 /* If we have already instantiated virtual registers, return the actual
714 address relative to the frame pointer. */
715 if (virtuals_instantiated)
716 addr = plus_constant (frame_pointer_rtx,
717 (frame_offset + bigend_correction
718 + STARTING_FRAME_OFFSET));
719 else
720 addr = plus_constant (virtual_stack_vars_rtx,
721 frame_offset + bigend_correction);
723 #ifndef FRAME_GROWS_DOWNWARD
724 frame_offset += size;
725 #endif
727 x = gen_rtx (MEM, mode, addr);
729 stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, x, stack_slot_list);
731 return x;
734 /* Assign a stack slot in a containing function.
735 First three arguments are same as in preceding function.
736 The last argument specifies the function to allocate in. */
739 assign_outer_stack_local (mode, size, align, function)
740 enum machine_mode mode;
741 int size;
742 int align;
743 struct function *function;
745 register rtx x, addr;
746 int bigend_correction = 0;
747 int alignment;
749 /* Allocate in the memory associated with the function in whose frame
750 we are assigning. */
751 push_obstacks (function->function_obstack,
752 function->function_maybepermanent_obstack);
754 if (align == 0)
756 alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
757 if (mode == BLKmode)
758 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
760 else if (align == -1)
762 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
763 size = CEIL_ROUND (size, alignment);
765 else
766 alignment = align / BITS_PER_UNIT;
768 /* Round frame offset to that alignment. */
769 #ifdef FRAME_GROWS_DOWNWARD
770 function->frame_offset = FLOOR_ROUND (function->frame_offset, alignment);
771 #else
772 function->frame_offset = CEIL_ROUND (function->frame_offset, alignment);
773 #endif
775 /* On a big-endian machine, if we are allocating more space than we will use,
776 use the least significant bytes of those that are allocated. */
777 if (BYTES_BIG_ENDIAN && mode != BLKmode)
778 bigend_correction = size - GET_MODE_SIZE (mode);
780 #ifdef FRAME_GROWS_DOWNWARD
781 function->frame_offset -= size;
782 #endif
783 addr = plus_constant (virtual_stack_vars_rtx,
784 function->frame_offset + bigend_correction);
785 #ifndef FRAME_GROWS_DOWNWARD
786 function->frame_offset += size;
787 #endif
789 x = gen_rtx (MEM, mode, addr);
791 function->stack_slot_list
792 = gen_rtx (EXPR_LIST, VOIDmode, x, function->stack_slot_list);
794 pop_obstacks ();
796 return x;
799 /* Allocate a temporary stack slot and record it for possible later
800 reuse.
802 MODE is the machine mode to be given to the returned rtx.
804 SIZE is the size in units of the space required. We do no rounding here
805 since assign_stack_local will do any required rounding.
807 KEEP is 1 if this slot is to be retained after a call to
808 free_temp_slots. Automatic variables for a block are allocated
809 with this flag. KEEP is 2, if we allocate a longer term temporary,
810 whose lifetime is controlled by CLEANUP_POINT_EXPRs. */
813 assign_stack_temp (mode, size, keep)
814 enum machine_mode mode;
815 int size;
816 int keep;
818 struct temp_slot *p, *best_p = 0;
820 /* If SIZE is -1 it means that somebody tried to allocate a temporary
821 of a variable size. */
822 if (size == -1)
823 abort ();
825 /* First try to find an available, already-allocated temporary that is the
826 exact size we require. */
827 for (p = temp_slots; p; p = p->next)
828 if (p->size == size && GET_MODE (p->slot) == mode && ! p->in_use)
829 break;
831 /* If we didn't find, one, try one that is larger than what we want. We
832 find the smallest such. */
833 if (p == 0)
834 for (p = temp_slots; p; p = p->next)
835 if (p->size > size && GET_MODE (p->slot) == mode && ! p->in_use
836 && (best_p == 0 || best_p->size > p->size))
837 best_p = p;
839 /* Make our best, if any, the one to use. */
840 if (best_p)
842 /* If there are enough aligned bytes left over, make them into a new
843 temp_slot so that the extra bytes don't get wasted. Do this only
844 for BLKmode slots, so that we can be sure of the alignment. */
845 if (GET_MODE (best_p->slot) == BLKmode)
847 int alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
848 int rounded_size = CEIL_ROUND (size, alignment);
850 if (best_p->size - rounded_size >= alignment)
852 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
853 p->in_use = p->addr_taken = 0;
854 p->size = best_p->size - rounded_size;
855 p->base_offset = best_p->base_offset + rounded_size;
856 p->full_size = best_p->full_size - rounded_size;
857 p->slot = gen_rtx (MEM, BLKmode,
858 plus_constant (XEXP (best_p->slot, 0),
859 rounded_size));
860 p->address = 0;
861 p->rtl_expr = 0;
862 p->next = temp_slots;
863 temp_slots = p;
865 stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, p->slot,
866 stack_slot_list);
868 best_p->size = rounded_size;
869 best_p->full_size = rounded_size;
873 p = best_p;
876 /* If we still didn't find one, make a new temporary. */
877 if (p == 0)
879 int frame_offset_old = frame_offset;
880 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
881 /* If the temp slot mode doesn't indicate the alignment,
882 use the largest possible, so no one will be disappointed. */
883 p->slot = assign_stack_local (mode, size, mode == BLKmode ? -1 : 0);
884 /* The following slot size computation is necessary because we don't
885 know the actual size of the temporary slot until assign_stack_local
886 has performed all the frame alignment and size rounding for the
887 requested temporary. Note that extra space added for alignment
888 can be either above or below this stack slot depending on which
889 way the frame grows. We include the extra space if and only if it
890 is above this slot. */
891 #ifdef FRAME_GROWS_DOWNWARD
892 p->size = frame_offset_old - frame_offset;
893 #else
894 p->size = size;
895 #endif
896 /* Now define the fields used by combine_temp_slots. */
897 #ifdef FRAME_GROWS_DOWNWARD
898 p->base_offset = frame_offset;
899 p->full_size = frame_offset_old - frame_offset;
900 #else
901 p->base_offset = frame_offset_old;
902 p->full_size = frame_offset - frame_offset_old;
903 #endif
904 p->address = 0;
905 p->next = temp_slots;
906 temp_slots = p;
909 p->in_use = 1;
910 p->addr_taken = 0;
911 p->rtl_expr = sequence_rtl_expr;
913 if (keep == 2)
915 p->level = target_temp_slot_level;
916 p->keep = 0;
918 else
920 p->level = temp_slot_level;
921 p->keep = keep;
924 /* We may be reusing an old slot, so clear any MEM flags that may have been
925 set from before. */
926 RTX_UNCHANGING_P (p->slot) = 0;
927 MEM_IN_STRUCT_P (p->slot) = 0;
928 return p->slot;
931 /* Assign a temporary of given TYPE.
932 KEEP is as for assign_stack_temp.
933 MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
934 it is 0 if a register is OK.
935 DONT_PROMOTE is 1 if we should not promote values in register
936 to wider modes. */
939 assign_temp (type, keep, memory_required, dont_promote)
940 tree type;
941 int keep;
942 int memory_required;
943 int dont_promote;
945 enum machine_mode mode = TYPE_MODE (type);
946 int unsignedp = TREE_UNSIGNED (type);
948 if (mode == BLKmode || memory_required)
950 int size = int_size_in_bytes (type);
951 rtx tmp;
953 /* Unfortunately, we don't yet know how to allocate variable-sized
954 temporaries. However, sometimes we have a fixed upper limit on
955 the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that
956 instead. This is the case for Chill variable-sized strings. */
957 if (size == -1 && TREE_CODE (type) == ARRAY_TYPE
958 && TYPE_ARRAY_MAX_SIZE (type) != NULL_TREE
959 && TREE_CODE (TYPE_ARRAY_MAX_SIZE (type)) == INTEGER_CST)
960 size = TREE_INT_CST_LOW (TYPE_ARRAY_MAX_SIZE (type));
962 tmp = assign_stack_temp (mode, size, keep);
963 MEM_IN_STRUCT_P (tmp) = AGGREGATE_TYPE_P (type);
964 return tmp;
967 #ifndef PROMOTE_FOR_CALL_ONLY
968 if (! dont_promote)
969 mode = promote_mode (type, mode, &unsignedp, 0);
970 #endif
972 return gen_reg_rtx (mode);
975 /* Combine temporary stack slots which are adjacent on the stack.
977 This allows for better use of already allocated stack space. This is only
978 done for BLKmode slots because we can be sure that we won't have alignment
979 problems in this case. */
981 void
982 combine_temp_slots ()
984 struct temp_slot *p, *q;
985 struct temp_slot *prev_p, *prev_q;
986 /* Determine where to free back to after this function. */
987 rtx free_pointer = rtx_alloc (CONST_INT);
989 for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots)
991 int delete_p = 0;
992 if (! p->in_use && GET_MODE (p->slot) == BLKmode)
993 for (q = p->next, prev_q = p; q; q = prev_q->next)
995 int delete_q = 0;
996 if (! q->in_use && GET_MODE (q->slot) == BLKmode)
998 if (p->base_offset + p->full_size == q->base_offset)
1000 /* Q comes after P; combine Q into P. */
1001 p->size += q->size;
1002 p->full_size += q->full_size;
1003 delete_q = 1;
1005 else if (q->base_offset + q->full_size == p->base_offset)
1007 /* P comes after Q; combine P into Q. */
1008 q->size += p->size;
1009 q->full_size += p->full_size;
1010 delete_p = 1;
1011 break;
1014 /* Either delete Q or advance past it. */
1015 if (delete_q)
1016 prev_q->next = q->next;
1017 else
1018 prev_q = q;
1020 /* Either delete P or advance past it. */
1021 if (delete_p)
1023 if (prev_p)
1024 prev_p->next = p->next;
1025 else
1026 temp_slots = p->next;
1028 else
1029 prev_p = p;
1032 /* Free all the RTL made by plus_constant. */
1033 rtx_free (free_pointer);
1036 /* Find the temp slot corresponding to the object at address X. */
1038 static struct temp_slot *
1039 find_temp_slot_from_address (x)
1040 rtx x;
1042 struct temp_slot *p;
1043 rtx next;
1045 for (p = temp_slots; p; p = p->next)
1047 if (! p->in_use)
1048 continue;
1049 else if (XEXP (p->slot, 0) == x
1050 || p->address == x
1051 || (GET_CODE (x) == PLUS
1052 && XEXP (x, 0) == virtual_stack_vars_rtx
1053 && GET_CODE (XEXP (x, 1)) == CONST_INT
1054 && INTVAL (XEXP (x, 1)) >= p->base_offset
1055 && INTVAL (XEXP (x, 1)) < p->base_offset + p->full_size))
1056 return p;
1058 else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST)
1059 for (next = p->address; next; next = XEXP (next, 1))
1060 if (XEXP (next, 0) == x)
1061 return p;
1064 return 0;
1067 /* Indicate that NEW is an alternate way of referring to the temp slot
1068 that previous was known by OLD. */
1070 void
1071 update_temp_slot_address (old, new)
1072 rtx old, new;
1074 struct temp_slot *p = find_temp_slot_from_address (old);
1076 /* If none, return. Else add NEW as an alias. */
1077 if (p == 0)
1078 return;
1079 else if (p->address == 0)
1080 p->address = new;
1081 else
1083 if (GET_CODE (p->address) != EXPR_LIST)
1084 p->address = gen_rtx (EXPR_LIST, VOIDmode, p->address, NULL_RTX);
1086 p->address = gen_rtx (EXPR_LIST, VOIDmode, new, p->address);
1090 /* If X could be a reference to a temporary slot, mark the fact that its
1091 address was taken. */
1093 void
1094 mark_temp_addr_taken (x)
1095 rtx x;
1097 struct temp_slot *p;
1099 if (x == 0)
1100 return;
1102 /* If X is not in memory or is at a constant address, it cannot be in
1103 a temporary slot. */
1104 if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1105 return;
1107 p = find_temp_slot_from_address (XEXP (x, 0));
1108 if (p != 0)
1109 p->addr_taken = 1;
1112 /* If X could be a reference to a temporary slot, mark that slot as
1113 belonging to the to one level higher than the current level. If X
1114 matched one of our slots, just mark that one. Otherwise, we can't
1115 easily predict which it is, so upgrade all of them. Kept slots
1116 need not be touched.
1118 This is called when an ({...}) construct occurs and a statement
1119 returns a value in memory. */
1121 void
1122 preserve_temp_slots (x)
1123 rtx x;
1125 struct temp_slot *p = 0;
1127 /* If there is no result, we still might have some objects whose address
1128 were taken, so we need to make sure they stay around. */
1129 if (x == 0)
1131 for (p = temp_slots; p; p = p->next)
1132 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1133 p->level--;
1135 return;
1138 /* If X is a register that is being used as a pointer, see if we have
1139 a temporary slot we know it points to. To be consistent with
1140 the code below, we really should preserve all non-kept slots
1141 if we can't find a match, but that seems to be much too costly. */
1142 if (GET_CODE (x) == REG && REGNO_POINTER_FLAG (REGNO (x)))
1143 p = find_temp_slot_from_address (x);
1145 /* If X is not in memory or is at a constant address, it cannot be in
1146 a temporary slot, but it can contain something whose address was
1147 taken. */
1148 if (p == 0 && (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))))
1150 for (p = temp_slots; p; p = p->next)
1151 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1152 p->level--;
1154 return;
1157 /* First see if we can find a match. */
1158 if (p == 0)
1159 p = find_temp_slot_from_address (XEXP (x, 0));
1161 if (p != 0)
1163 /* Move everything at our level whose address was taken to our new
1164 level in case we used its address. */
1165 struct temp_slot *q;
1167 if (p->level == temp_slot_level)
1169 for (q = temp_slots; q; q = q->next)
1170 if (q != p && q->addr_taken && q->level == p->level)
1171 q->level--;
1173 p->level--;
1174 p->addr_taken = 0;
1176 return;
1179 /* Otherwise, preserve all non-kept slots at this level. */
1180 for (p = temp_slots; p; p = p->next)
1181 if (p->in_use && p->level == temp_slot_level && ! p->keep)
1182 p->level--;
1185 /* X is the result of an RTL_EXPR. If it is a temporary slot associated
1186 with that RTL_EXPR, promote it into a temporary slot at the present
1187 level so it will not be freed when we free slots made in the
1188 RTL_EXPR. */
1190 void
1191 preserve_rtl_expr_result (x)
1192 rtx x;
1194 struct temp_slot *p;
1196 /* If X is not in memory or is at a constant address, it cannot be in
1197 a temporary slot. */
1198 if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1199 return;
1201 /* If we can find a match, move it to our level unless it is already at
1202 an upper level. */
1203 p = find_temp_slot_from_address (XEXP (x, 0));
1204 if (p != 0)
1206 p->level = MIN (p->level, temp_slot_level);
1207 p->rtl_expr = 0;
1210 return;
1213 /* Free all temporaries used so far. This is normally called at the end
1214 of generating code for a statement. Don't free any temporaries
1215 currently in use for an RTL_EXPR that hasn't yet been emitted.
1216 We could eventually do better than this since it can be reused while
1217 generating the same RTL_EXPR, but this is complex and probably not
1218 worthwhile. */
1220 void
1221 free_temp_slots ()
1223 struct temp_slot *p;
1225 for (p = temp_slots; p; p = p->next)
1226 if (p->in_use && p->level == temp_slot_level && ! p->keep
1227 && p->rtl_expr == 0)
1228 p->in_use = 0;
1230 combine_temp_slots ();
1233 /* Free all temporary slots used in T, an RTL_EXPR node. */
1235 void
1236 free_temps_for_rtl_expr (t)
1237 tree t;
1239 struct temp_slot *p;
1241 for (p = temp_slots; p; p = p->next)
1242 if (p->rtl_expr == t)
1243 p->in_use = 0;
1245 combine_temp_slots ();
1248 /* Mark all temporaries ever allocated in this functon as not suitable
1249 for reuse until the current level is exited. */
1251 void
1252 mark_all_temps_used ()
1254 struct temp_slot *p;
1256 for (p = temp_slots; p; p = p->next)
1258 p->in_use = p->keep = 1;
1259 p->level = MIN (p->level, temp_slot_level);
1263 /* Push deeper into the nesting level for stack temporaries. */
1265 void
1266 push_temp_slots ()
1268 temp_slot_level++;
1271 /* Pop a temporary nesting level. All slots in use in the current level
1272 are freed. */
1274 void
1275 pop_temp_slots ()
1277 struct temp_slot *p;
1279 for (p = temp_slots; p; p = p->next)
1280 if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0)
1281 p->in_use = 0;
1283 combine_temp_slots ();
1285 temp_slot_level--;
1288 /* Initialize temporary slots. */
1290 void
1291 init_temp_slots ()
1293 /* We have not allocated any temporaries yet. */
1294 temp_slots = 0;
1295 temp_slot_level = 0;
1296 target_temp_slot_level = 0;
1299 /* Retroactively move an auto variable from a register to a stack slot.
1300 This is done when an address-reference to the variable is seen. */
1302 void
1303 put_var_into_stack (decl)
1304 tree decl;
1306 register rtx reg;
1307 enum machine_mode promoted_mode, decl_mode;
1308 struct function *function = 0;
1309 tree context;
1311 if (output_bytecode)
1312 return;
1314 context = decl_function_context (decl);
1316 /* Get the current rtl used for this object and it's original mode. */
1317 reg = TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl) : DECL_RTL (decl);
1319 /* No need to do anything if decl has no rtx yet
1320 since in that case caller is setting TREE_ADDRESSABLE
1321 and a stack slot will be assigned when the rtl is made. */
1322 if (reg == 0)
1323 return;
1325 /* Get the declared mode for this object. */
1326 decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl))
1327 : DECL_MODE (decl));
1328 /* Get the mode it's actually stored in. */
1329 promoted_mode = GET_MODE (reg);
1331 /* If this variable comes from an outer function,
1332 find that function's saved context. */
1333 if (context != current_function_decl && context != inline_function_decl)
1334 for (function = outer_function_chain; function; function = function->next)
1335 if (function->decl == context)
1336 break;
1338 /* If this is a variable-size object with a pseudo to address it,
1339 put that pseudo into the stack, if the var is nonlocal. */
1340 if (DECL_NONLOCAL (decl)
1341 && GET_CODE (reg) == MEM
1342 && GET_CODE (XEXP (reg, 0)) == REG
1343 && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
1345 reg = XEXP (reg, 0);
1346 decl_mode = promoted_mode = GET_MODE (reg);
1349 /* Now we should have a value that resides in one or more pseudo regs. */
1351 if (GET_CODE (reg) == REG)
1352 put_reg_into_stack (function, reg, TREE_TYPE (decl),
1353 promoted_mode, decl_mode, TREE_SIDE_EFFECTS (decl));
1354 else if (GET_CODE (reg) == CONCAT)
1356 /* A CONCAT contains two pseudos; put them both in the stack.
1357 We do it so they end up consecutive. */
1358 enum machine_mode part_mode = GET_MODE (XEXP (reg, 0));
1359 tree part_type = TREE_TYPE (TREE_TYPE (decl));
1360 #ifdef FRAME_GROWS_DOWNWARD
1361 /* Since part 0 should have a lower address, do it second. */
1362 put_reg_into_stack (function, XEXP (reg, 1), part_type, part_mode,
1363 part_mode, TREE_SIDE_EFFECTS (decl));
1364 put_reg_into_stack (function, XEXP (reg, 0), part_type, part_mode,
1365 part_mode, TREE_SIDE_EFFECTS (decl));
1366 #else
1367 put_reg_into_stack (function, XEXP (reg, 0), part_type, part_mode,
1368 part_mode, TREE_SIDE_EFFECTS (decl));
1369 put_reg_into_stack (function, XEXP (reg, 1), part_type, part_mode,
1370 part_mode, TREE_SIDE_EFFECTS (decl));
1371 #endif
1373 /* Change the CONCAT into a combined MEM for both parts. */
1374 PUT_CODE (reg, MEM);
1375 MEM_VOLATILE_P (reg) = MEM_VOLATILE_P (XEXP (reg, 0));
1377 /* The two parts are in memory order already.
1378 Use the lower parts address as ours. */
1379 XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0);
1380 /* Prevent sharing of rtl that might lose. */
1381 if (GET_CODE (XEXP (reg, 0)) == PLUS)
1382 XEXP (reg, 0) = copy_rtx (XEXP (reg, 0));
1384 else
1385 return;
1387 if (flag_check_memory_usage)
1388 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
1389 XEXP (reg, 0), ptr_mode,
1390 GEN_INT (GET_MODE_SIZE (GET_MODE (reg))),
1391 TYPE_MODE (sizetype),
1392 GEN_INT (MEMORY_USE_RW), QImode);
1395 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1396 into the stack frame of FUNCTION (0 means the current function).
1397 DECL_MODE is the machine mode of the user-level data type.
1398 PROMOTED_MODE is the machine mode of the register.
1399 VOLATILE_P is nonzero if this is for a "volatile" decl. */
1401 static void
1402 put_reg_into_stack (function, reg, type, promoted_mode, decl_mode, volatile_p)
1403 struct function *function;
1404 rtx reg;
1405 tree type;
1406 enum machine_mode promoted_mode, decl_mode;
1407 int volatile_p;
1409 rtx new = 0;
1411 if (function)
1413 if (REGNO (reg) < function->max_parm_reg)
1414 new = function->parm_reg_stack_loc[REGNO (reg)];
1415 if (new == 0)
1416 new = assign_outer_stack_local (decl_mode, GET_MODE_SIZE (decl_mode),
1417 0, function);
1419 else
1421 if (REGNO (reg) < max_parm_reg)
1422 new = parm_reg_stack_loc[REGNO (reg)];
1423 if (new == 0)
1424 new = assign_stack_local (decl_mode, GET_MODE_SIZE (decl_mode), 0);
1427 PUT_MODE (reg, decl_mode);
1428 XEXP (reg, 0) = XEXP (new, 0);
1429 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1430 MEM_VOLATILE_P (reg) = volatile_p;
1431 PUT_CODE (reg, MEM);
1433 /* If this is a memory ref that contains aggregate components,
1434 mark it as such for cse and loop optimize. */
1435 MEM_IN_STRUCT_P (reg) = AGGREGATE_TYPE_P (type);
1437 /* Now make sure that all refs to the variable, previously made
1438 when it was a register, are fixed up to be valid again. */
1439 if (function)
1441 struct var_refs_queue *temp;
1443 /* Variable is inherited; fix it up when we get back to its function. */
1444 push_obstacks (function->function_obstack,
1445 function->function_maybepermanent_obstack);
1447 /* See comment in restore_tree_status in tree.c for why this needs to be
1448 on saveable obstack. */
1449 temp
1450 = (struct var_refs_queue *) savealloc (sizeof (struct var_refs_queue));
1451 temp->modified = reg;
1452 temp->promoted_mode = promoted_mode;
1453 temp->unsignedp = TREE_UNSIGNED (type);
1454 temp->next = function->fixup_var_refs_queue;
1455 function->fixup_var_refs_queue = temp;
1456 pop_obstacks ();
1458 else
1459 /* Variable is local; fix it up now. */
1460 fixup_var_refs (reg, promoted_mode, TREE_UNSIGNED (type));
1463 static void
1464 fixup_var_refs (var, promoted_mode, unsignedp)
1465 rtx var;
1466 enum machine_mode promoted_mode;
1467 int unsignedp;
1469 tree pending;
1470 rtx first_insn = get_insns ();
1471 struct sequence_stack *stack = sequence_stack;
1472 tree rtl_exps = rtl_expr_chain;
1474 /* Must scan all insns for stack-refs that exceed the limit. */
1475 fixup_var_refs_insns (var, promoted_mode, unsignedp, first_insn, stack == 0);
1477 /* Scan all pending sequences too. */
1478 for (; stack; stack = stack->next)
1480 push_to_sequence (stack->first);
1481 fixup_var_refs_insns (var, promoted_mode, unsignedp,
1482 stack->first, stack->next != 0);
1483 /* Update remembered end of sequence
1484 in case we added an insn at the end. */
1485 stack->last = get_last_insn ();
1486 end_sequence ();
1489 /* Scan all waiting RTL_EXPRs too. */
1490 for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
1492 rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
1493 if (seq != const0_rtx && seq != 0)
1495 push_to_sequence (seq);
1496 fixup_var_refs_insns (var, promoted_mode, unsignedp, seq, 0);
1497 end_sequence ();
1502 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1503 some part of an insn. Return a struct fixup_replacement whose OLD
1504 value is equal to X. Allocate a new structure if no such entry exists. */
1506 static struct fixup_replacement *
1507 find_fixup_replacement (replacements, x)
1508 struct fixup_replacement **replacements;
1509 rtx x;
1511 struct fixup_replacement *p;
1513 /* See if we have already replaced this. */
1514 for (p = *replacements; p && p->old != x; p = p->next)
1517 if (p == 0)
1519 p = (struct fixup_replacement *) oballoc (sizeof (struct fixup_replacement));
1520 p->old = x;
1521 p->new = 0;
1522 p->next = *replacements;
1523 *replacements = p;
1526 return p;
1529 /* Scan the insn-chain starting with INSN for refs to VAR
1530 and fix them up. TOPLEVEL is nonzero if this chain is the
1531 main chain of insns for the current function. */
1533 static void
1534 fixup_var_refs_insns (var, promoted_mode, unsignedp, insn, toplevel)
1535 rtx var;
1536 enum machine_mode promoted_mode;
1537 int unsignedp;
1538 rtx insn;
1539 int toplevel;
1541 rtx call_dest = 0;
1543 while (insn)
1545 rtx next = NEXT_INSN (insn);
1546 rtx note;
1547 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1549 /* If this is a CLOBBER of VAR, delete it.
1551 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1552 and REG_RETVAL notes too. */
1553 if (GET_CODE (PATTERN (insn)) == CLOBBER
1554 && XEXP (PATTERN (insn), 0) == var)
1556 if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0)
1557 /* The REG_LIBCALL note will go away since we are going to
1558 turn INSN into a NOTE, so just delete the
1559 corresponding REG_RETVAL note. */
1560 remove_note (XEXP (note, 0),
1561 find_reg_note (XEXP (note, 0), REG_RETVAL,
1562 NULL_RTX));
1564 /* In unoptimized compilation, we shouldn't call delete_insn
1565 except in jump.c doing warnings. */
1566 PUT_CODE (insn, NOTE);
1567 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1568 NOTE_SOURCE_FILE (insn) = 0;
1571 /* The insn to load VAR from a home in the arglist
1572 is now a no-op. When we see it, just delete it. */
1573 else if (toplevel
1574 && GET_CODE (PATTERN (insn)) == SET
1575 && SET_DEST (PATTERN (insn)) == var
1576 /* If this represents the result of an insn group,
1577 don't delete the insn. */
1578 && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0
1579 && rtx_equal_p (SET_SRC (PATTERN (insn)), var))
1581 /* In unoptimized compilation, we shouldn't call delete_insn
1582 except in jump.c doing warnings. */
1583 PUT_CODE (insn, NOTE);
1584 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1585 NOTE_SOURCE_FILE (insn) = 0;
1586 if (insn == last_parm_insn)
1587 last_parm_insn = PREV_INSN (next);
1589 else
1591 struct fixup_replacement *replacements = 0;
1592 rtx next_insn = NEXT_INSN (insn);
1594 #ifdef SMALL_REGISTER_CLASSES
1595 /* If the insn that copies the results of a CALL_INSN
1596 into a pseudo now references VAR, we have to use an
1597 intermediate pseudo since we want the life of the
1598 return value register to be only a single insn.
1600 If we don't use an intermediate pseudo, such things as
1601 address computations to make the address of VAR valid
1602 if it is not can be placed between the CALL_INSN and INSN.
1604 To make sure this doesn't happen, we record the destination
1605 of the CALL_INSN and see if the next insn uses both that
1606 and VAR. */
1608 if (SMALL_REGISTER_CLASSES)
1610 if (call_dest != 0 && GET_CODE (insn) == INSN
1611 && reg_mentioned_p (var, PATTERN (insn))
1612 && reg_mentioned_p (call_dest, PATTERN (insn)))
1614 rtx temp = gen_reg_rtx (GET_MODE (call_dest));
1616 emit_insn_before (gen_move_insn (temp, call_dest), insn);
1618 PATTERN (insn) = replace_rtx (PATTERN (insn),
1619 call_dest, temp);
1622 if (GET_CODE (insn) == CALL_INSN
1623 && GET_CODE (PATTERN (insn)) == SET)
1624 call_dest = SET_DEST (PATTERN (insn));
1625 else if (GET_CODE (insn) == CALL_INSN
1626 && GET_CODE (PATTERN (insn)) == PARALLEL
1627 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
1628 call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
1629 else
1630 call_dest = 0;
1632 #endif
1634 /* See if we have to do anything to INSN now that VAR is in
1635 memory. If it needs to be loaded into a pseudo, use a single
1636 pseudo for the entire insn in case there is a MATCH_DUP
1637 between two operands. We pass a pointer to the head of
1638 a list of struct fixup_replacements. If fixup_var_refs_1
1639 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1640 it will record them in this list.
1642 If it allocated a pseudo for any replacement, we copy into
1643 it here. */
1645 fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn,
1646 &replacements);
1648 /* If this is last_parm_insn, and any instructions were output
1649 after it to fix it up, then we must set last_parm_insn to
1650 the last such instruction emitted. */
1651 if (insn == last_parm_insn)
1652 last_parm_insn = PREV_INSN (next_insn);
1654 while (replacements)
1656 if (GET_CODE (replacements->new) == REG)
1658 rtx insert_before;
1659 rtx seq;
1661 /* OLD might be a (subreg (mem)). */
1662 if (GET_CODE (replacements->old) == SUBREG)
1663 replacements->old
1664 = fixup_memory_subreg (replacements->old, insn, 0);
1665 else
1666 replacements->old
1667 = fixup_stack_1 (replacements->old, insn);
1669 insert_before = insn;
1671 /* If we are changing the mode, do a conversion.
1672 This might be wasteful, but combine.c will
1673 eliminate much of the waste. */
1675 if (GET_MODE (replacements->new)
1676 != GET_MODE (replacements->old))
1678 start_sequence ();
1679 convert_move (replacements->new,
1680 replacements->old, unsignedp);
1681 seq = gen_sequence ();
1682 end_sequence ();
1684 else
1685 seq = gen_move_insn (replacements->new,
1686 replacements->old);
1688 emit_insn_before (seq, insert_before);
1691 replacements = replacements->next;
1695 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1696 But don't touch other insns referred to by reg-notes;
1697 we will get them elsewhere. */
1698 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
1699 if (GET_CODE (note) != INSN_LIST)
1700 XEXP (note, 0)
1701 = walk_fixup_memory_subreg (XEXP (note, 0), insn, 1);
1703 insn = next;
1707 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1708 See if the rtx expression at *LOC in INSN needs to be changed.
1710 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1711 contain a list of original rtx's and replacements. If we find that we need
1712 to modify this insn by replacing a memory reference with a pseudo or by
1713 making a new MEM to implement a SUBREG, we consult that list to see if
1714 we have already chosen a replacement. If none has already been allocated,
1715 we allocate it and update the list. fixup_var_refs_insns will copy VAR
1716 or the SUBREG, as appropriate, to the pseudo. */
1718 static void
1719 fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements)
1720 register rtx var;
1721 enum machine_mode promoted_mode;
1722 register rtx *loc;
1723 rtx insn;
1724 struct fixup_replacement **replacements;
1726 register int i;
1727 register rtx x = *loc;
1728 RTX_CODE code = GET_CODE (x);
1729 register char *fmt;
1730 register rtx tem, tem1;
1731 struct fixup_replacement *replacement;
1733 switch (code)
1735 case MEM:
1736 if (var == x)
1738 /* If we already have a replacement, use it. Otherwise,
1739 try to fix up this address in case it is invalid. */
1741 replacement = find_fixup_replacement (replacements, var);
1742 if (replacement->new)
1744 *loc = replacement->new;
1745 return;
1748 *loc = replacement->new = x = fixup_stack_1 (x, insn);
1750 /* Unless we are forcing memory to register or we changed the mode,
1751 we can leave things the way they are if the insn is valid. */
1753 INSN_CODE (insn) = -1;
1754 if (! flag_force_mem && GET_MODE (x) == promoted_mode
1755 && recog_memoized (insn) >= 0)
1756 return;
1758 *loc = replacement->new = gen_reg_rtx (promoted_mode);
1759 return;
1762 /* If X contains VAR, we need to unshare it here so that we update
1763 each occurrence separately. But all identical MEMs in one insn
1764 must be replaced with the same rtx because of the possibility of
1765 MATCH_DUPs. */
1767 if (reg_mentioned_p (var, x))
1769 replacement = find_fixup_replacement (replacements, x);
1770 if (replacement->new == 0)
1771 replacement->new = copy_most_rtx (x, var);
1773 *loc = x = replacement->new;
1775 break;
1777 case REG:
1778 case CC0:
1779 case PC:
1780 case CONST_INT:
1781 case CONST:
1782 case SYMBOL_REF:
1783 case LABEL_REF:
1784 case CONST_DOUBLE:
1785 return;
1787 case SIGN_EXTRACT:
1788 case ZERO_EXTRACT:
1789 /* Note that in some cases those types of expressions are altered
1790 by optimize_bit_field, and do not survive to get here. */
1791 if (XEXP (x, 0) == var
1792 || (GET_CODE (XEXP (x, 0)) == SUBREG
1793 && SUBREG_REG (XEXP (x, 0)) == var))
1795 /* Get TEM as a valid MEM in the mode presently in the insn.
1797 We don't worry about the possibility of MATCH_DUP here; it
1798 is highly unlikely and would be tricky to handle. */
1800 tem = XEXP (x, 0);
1801 if (GET_CODE (tem) == SUBREG)
1803 if (GET_MODE_BITSIZE (GET_MODE (tem))
1804 > GET_MODE_BITSIZE (GET_MODE (var)))
1806 replacement = find_fixup_replacement (replacements, var);
1807 if (replacement->new == 0)
1808 replacement->new = gen_reg_rtx (GET_MODE (var));
1809 SUBREG_REG (tem) = replacement->new;
1811 else
1812 tem = fixup_memory_subreg (tem, insn, 0);
1814 else
1815 tem = fixup_stack_1 (tem, insn);
1817 /* Unless we want to load from memory, get TEM into the proper mode
1818 for an extract from memory. This can only be done if the
1819 extract is at a constant position and length. */
1821 if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
1822 && GET_CODE (XEXP (x, 2)) == CONST_INT
1823 && ! mode_dependent_address_p (XEXP (tem, 0))
1824 && ! MEM_VOLATILE_P (tem))
1826 enum machine_mode wanted_mode = VOIDmode;
1827 enum machine_mode is_mode = GET_MODE (tem);
1828 int width = INTVAL (XEXP (x, 1));
1829 int pos = INTVAL (XEXP (x, 2));
1831 #ifdef HAVE_extzv
1832 if (GET_CODE (x) == ZERO_EXTRACT)
1833 wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
1834 #endif
1835 #ifdef HAVE_extv
1836 if (GET_CODE (x) == SIGN_EXTRACT)
1837 wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
1838 #endif
1839 /* If we have a narrower mode, we can do something. */
1840 if (wanted_mode != VOIDmode
1841 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
1843 int offset = pos / BITS_PER_UNIT;
1844 rtx old_pos = XEXP (x, 2);
1845 rtx newmem;
1847 /* If the bytes and bits are counted differently, we
1848 must adjust the offset. */
1849 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
1850 offset = (GET_MODE_SIZE (is_mode)
1851 - GET_MODE_SIZE (wanted_mode) - offset);
1853 pos %= GET_MODE_BITSIZE (wanted_mode);
1855 newmem = gen_rtx (MEM, wanted_mode,
1856 plus_constant (XEXP (tem, 0), offset));
1857 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
1858 MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
1859 MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
1861 /* Make the change and see if the insn remains valid. */
1862 INSN_CODE (insn) = -1;
1863 XEXP (x, 0) = newmem;
1864 XEXP (x, 2) = GEN_INT (pos);
1866 if (recog_memoized (insn) >= 0)
1867 return;
1869 /* Otherwise, restore old position. XEXP (x, 0) will be
1870 restored later. */
1871 XEXP (x, 2) = old_pos;
1875 /* If we get here, the bitfield extract insn can't accept a memory
1876 reference. Copy the input into a register. */
1878 tem1 = gen_reg_rtx (GET_MODE (tem));
1879 emit_insn_before (gen_move_insn (tem1, tem), insn);
1880 XEXP (x, 0) = tem1;
1881 return;
1883 break;
1885 case SUBREG:
1886 if (SUBREG_REG (x) == var)
1888 /* If this is a special SUBREG made because VAR was promoted
1889 from a wider mode, replace it with VAR and call ourself
1890 recursively, this time saying that the object previously
1891 had its current mode (by virtue of the SUBREG). */
1893 if (SUBREG_PROMOTED_VAR_P (x))
1895 *loc = var;
1896 fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements);
1897 return;
1900 /* If this SUBREG makes VAR wider, it has become a paradoxical
1901 SUBREG with VAR in memory, but these aren't allowed at this
1902 stage of the compilation. So load VAR into a pseudo and take
1903 a SUBREG of that pseudo. */
1904 if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
1906 replacement = find_fixup_replacement (replacements, var);
1907 if (replacement->new == 0)
1908 replacement->new = gen_reg_rtx (GET_MODE (var));
1909 SUBREG_REG (x) = replacement->new;
1910 return;
1913 /* See if we have already found a replacement for this SUBREG.
1914 If so, use it. Otherwise, make a MEM and see if the insn
1915 is recognized. If not, or if we should force MEM into a register,
1916 make a pseudo for this SUBREG. */
1917 replacement = find_fixup_replacement (replacements, x);
1918 if (replacement->new)
1920 *loc = replacement->new;
1921 return;
1924 replacement->new = *loc = fixup_memory_subreg (x, insn, 0);
1926 INSN_CODE (insn) = -1;
1927 if (! flag_force_mem && recog_memoized (insn) >= 0)
1928 return;
1930 *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
1931 return;
1933 break;
1935 case SET:
1936 /* First do special simplification of bit-field references. */
1937 if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
1938 || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
1939 optimize_bit_field (x, insn, 0);
1940 if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
1941 || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
1942 optimize_bit_field (x, insn, NULL_PTR);
1944 /* For a paradoxical SUBREG inside a ZERO_EXTRACT, load the object
1945 into a register and then store it back out. */
1946 if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT
1947 && GET_CODE (XEXP (SET_DEST (x), 0)) == SUBREG
1948 && SUBREG_REG (XEXP (SET_DEST (x), 0)) == var
1949 && (GET_MODE_SIZE (GET_MODE (XEXP (SET_DEST (x), 0)))
1950 > GET_MODE_SIZE (GET_MODE (var))))
1952 replacement = find_fixup_replacement (replacements, var);
1953 if (replacement->new == 0)
1954 replacement->new = gen_reg_rtx (GET_MODE (var));
1956 SUBREG_REG (XEXP (SET_DEST (x), 0)) = replacement->new;
1957 emit_insn_after (gen_move_insn (var, replacement->new), insn);
1960 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
1961 insn into a pseudo and store the low part of the pseudo into VAR. */
1962 if (GET_CODE (SET_DEST (x)) == SUBREG
1963 && SUBREG_REG (SET_DEST (x)) == var
1964 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
1965 > GET_MODE_SIZE (GET_MODE (var))))
1967 SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
1968 emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
1969 tem)),
1970 insn);
1971 break;
1975 rtx dest = SET_DEST (x);
1976 rtx src = SET_SRC (x);
1977 rtx outerdest = dest;
1979 while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
1980 || GET_CODE (dest) == SIGN_EXTRACT
1981 || GET_CODE (dest) == ZERO_EXTRACT)
1982 dest = XEXP (dest, 0);
1984 if (GET_CODE (src) == SUBREG)
1985 src = XEXP (src, 0);
1987 /* If VAR does not appear at the top level of the SET
1988 just scan the lower levels of the tree. */
1990 if (src != var && dest != var)
1991 break;
1993 /* We will need to rerecognize this insn. */
1994 INSN_CODE (insn) = -1;
1996 #ifdef HAVE_insv
1997 if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var)
1999 /* Since this case will return, ensure we fixup all the
2000 operands here. */
2001 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1),
2002 insn, replacements);
2003 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2),
2004 insn, replacements);
2005 fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x),
2006 insn, replacements);
2008 tem = XEXP (outerdest, 0);
2010 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
2011 that may appear inside a ZERO_EXTRACT.
2012 This was legitimate when the MEM was a REG. */
2013 if (GET_CODE (tem) == SUBREG
2014 && SUBREG_REG (tem) == var)
2015 tem = fixup_memory_subreg (tem, insn, 0);
2016 else
2017 tem = fixup_stack_1 (tem, insn);
2019 if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
2020 && GET_CODE (XEXP (outerdest, 2)) == CONST_INT
2021 && ! mode_dependent_address_p (XEXP (tem, 0))
2022 && ! MEM_VOLATILE_P (tem))
2024 enum machine_mode wanted_mode
2025 = insn_operand_mode[(int) CODE_FOR_insv][0];
2026 enum machine_mode is_mode = GET_MODE (tem);
2027 int width = INTVAL (XEXP (outerdest, 1));
2028 int pos = INTVAL (XEXP (outerdest, 2));
2030 /* If we have a narrower mode, we can do something. */
2031 if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
2033 int offset = pos / BITS_PER_UNIT;
2034 rtx old_pos = XEXP (outerdest, 2);
2035 rtx newmem;
2037 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
2038 offset = (GET_MODE_SIZE (is_mode)
2039 - GET_MODE_SIZE (wanted_mode) - offset);
2041 pos %= GET_MODE_BITSIZE (wanted_mode);
2043 newmem = gen_rtx (MEM, wanted_mode,
2044 plus_constant (XEXP (tem, 0), offset));
2045 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
2046 MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
2047 MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
2049 /* Make the change and see if the insn remains valid. */
2050 INSN_CODE (insn) = -1;
2051 XEXP (outerdest, 0) = newmem;
2052 XEXP (outerdest, 2) = GEN_INT (pos);
2054 if (recog_memoized (insn) >= 0)
2055 return;
2057 /* Otherwise, restore old position. XEXP (x, 0) will be
2058 restored later. */
2059 XEXP (outerdest, 2) = old_pos;
2063 /* If we get here, the bit-field store doesn't allow memory
2064 or isn't located at a constant position. Load the value into
2065 a register, do the store, and put it back into memory. */
2067 tem1 = gen_reg_rtx (GET_MODE (tem));
2068 emit_insn_before (gen_move_insn (tem1, tem), insn);
2069 emit_insn_after (gen_move_insn (tem, tem1), insn);
2070 XEXP (outerdest, 0) = tem1;
2071 return;
2073 #endif
2075 /* STRICT_LOW_PART is a no-op on memory references
2076 and it can cause combinations to be unrecognizable,
2077 so eliminate it. */
2079 if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
2080 SET_DEST (x) = XEXP (SET_DEST (x), 0);
2082 /* A valid insn to copy VAR into or out of a register
2083 must be left alone, to avoid an infinite loop here.
2084 If the reference to VAR is by a subreg, fix that up,
2085 since SUBREG is not valid for a memref.
2086 Also fix up the address of the stack slot.
2088 Note that we must not try to recognize the insn until
2089 after we know that we have valid addresses and no
2090 (subreg (mem ...) ...) constructs, since these interfere
2091 with determining the validity of the insn. */
2093 if ((SET_SRC (x) == var
2094 || (GET_CODE (SET_SRC (x)) == SUBREG
2095 && SUBREG_REG (SET_SRC (x)) == var))
2096 && (GET_CODE (SET_DEST (x)) == REG
2097 || (GET_CODE (SET_DEST (x)) == SUBREG
2098 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
2099 && GET_MODE (var) == promoted_mode
2100 && x == single_set (insn))
2102 rtx pat;
2104 replacement = find_fixup_replacement (replacements, SET_SRC (x));
2105 if (replacement->new)
2106 SET_SRC (x) = replacement->new;
2107 else if (GET_CODE (SET_SRC (x)) == SUBREG)
2108 SET_SRC (x) = replacement->new
2109 = fixup_memory_subreg (SET_SRC (x), insn, 0);
2110 else
2111 SET_SRC (x) = replacement->new
2112 = fixup_stack_1 (SET_SRC (x), insn);
2114 if (recog_memoized (insn) >= 0)
2115 return;
2117 /* INSN is not valid, but we know that we want to
2118 copy SET_SRC (x) to SET_DEST (x) in some way. So
2119 we generate the move and see whether it requires more
2120 than one insn. If it does, we emit those insns and
2121 delete INSN. Otherwise, we an just replace the pattern
2122 of INSN; we have already verified above that INSN has
2123 no other function that to do X. */
2125 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2126 if (GET_CODE (pat) == SEQUENCE)
2128 emit_insn_after (pat, insn);
2129 PUT_CODE (insn, NOTE);
2130 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2131 NOTE_SOURCE_FILE (insn) = 0;
2133 else
2134 PATTERN (insn) = pat;
2136 return;
2139 if ((SET_DEST (x) == var
2140 || (GET_CODE (SET_DEST (x)) == SUBREG
2141 && SUBREG_REG (SET_DEST (x)) == var))
2142 && (GET_CODE (SET_SRC (x)) == REG
2143 || (GET_CODE (SET_SRC (x)) == SUBREG
2144 && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
2145 && GET_MODE (var) == promoted_mode
2146 && x == single_set (insn))
2148 rtx pat;
2150 if (GET_CODE (SET_DEST (x)) == SUBREG)
2151 SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn, 0);
2152 else
2153 SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
2155 if (recog_memoized (insn) >= 0)
2156 return;
2158 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2159 if (GET_CODE (pat) == SEQUENCE)
2161 emit_insn_after (pat, insn);
2162 PUT_CODE (insn, NOTE);
2163 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2164 NOTE_SOURCE_FILE (insn) = 0;
2166 else
2167 PATTERN (insn) = pat;
2169 return;
2172 /* Otherwise, storing into VAR must be handled specially
2173 by storing into a temporary and copying that into VAR
2174 with a new insn after this one. Note that this case
2175 will be used when storing into a promoted scalar since
2176 the insn will now have different modes on the input
2177 and output and hence will be invalid (except for the case
2178 of setting it to a constant, which does not need any
2179 change if it is valid). We generate extra code in that case,
2180 but combine.c will eliminate it. */
2182 if (dest == var)
2184 rtx temp;
2185 rtx fixeddest = SET_DEST (x);
2187 /* STRICT_LOW_PART can be discarded, around a MEM. */
2188 if (GET_CODE (fixeddest) == STRICT_LOW_PART)
2189 fixeddest = XEXP (fixeddest, 0);
2190 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
2191 if (GET_CODE (fixeddest) == SUBREG)
2193 fixeddest = fixup_memory_subreg (fixeddest, insn, 0);
2194 promoted_mode = GET_MODE (fixeddest);
2196 else
2197 fixeddest = fixup_stack_1 (fixeddest, insn);
2199 temp = gen_reg_rtx (promoted_mode);
2201 emit_insn_after (gen_move_insn (fixeddest,
2202 gen_lowpart (GET_MODE (fixeddest),
2203 temp)),
2204 insn);
2206 SET_DEST (x) = temp;
2211 /* Nothing special about this RTX; fix its operands. */
2213 fmt = GET_RTX_FORMAT (code);
2214 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2216 if (fmt[i] == 'e')
2217 fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements);
2218 if (fmt[i] == 'E')
2220 register int j;
2221 for (j = 0; j < XVECLEN (x, i); j++)
2222 fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j),
2223 insn, replacements);
2228 /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
2229 return an rtx (MEM:m1 newaddr) which is equivalent.
2230 If any insns must be emitted to compute NEWADDR, put them before INSN.
2232 UNCRITICAL nonzero means accept paradoxical subregs.
2233 This is used for subregs found inside REG_NOTES. */
2235 static rtx
2236 fixup_memory_subreg (x, insn, uncritical)
2237 rtx x;
2238 rtx insn;
2239 int uncritical;
2241 int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
2242 rtx addr = XEXP (SUBREG_REG (x), 0);
2243 enum machine_mode mode = GET_MODE (x);
2244 rtx saved, result;
2246 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2247 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
2248 && ! uncritical)
2249 abort ();
2251 if (BYTES_BIG_ENDIAN)
2252 offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
2253 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
2254 addr = plus_constant (addr, offset);
2255 if (!flag_force_addr && memory_address_p (mode, addr))
2256 /* Shortcut if no insns need be emitted. */
2257 return change_address (SUBREG_REG (x), mode, addr);
2258 start_sequence ();
2259 result = change_address (SUBREG_REG (x), mode, addr);
2260 emit_insn_before (gen_sequence (), insn);
2261 end_sequence ();
2262 return result;
2265 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2266 Replace subexpressions of X in place.
2267 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2268 Otherwise return X, with its contents possibly altered.
2270 If any insns must be emitted to compute NEWADDR, put them before INSN.
2272 UNCRITICAL is as in fixup_memory_subreg. */
2274 static rtx
2275 walk_fixup_memory_subreg (x, insn, uncritical)
2276 register rtx x;
2277 rtx insn;
2278 int uncritical;
2280 register enum rtx_code code;
2281 register char *fmt;
2282 register int i;
2284 if (x == 0)
2285 return 0;
2287 code = GET_CODE (x);
2289 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
2290 return fixup_memory_subreg (x, insn, uncritical);
2292 /* Nothing special about this RTX; fix its operands. */
2294 fmt = GET_RTX_FORMAT (code);
2295 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2297 if (fmt[i] == 'e')
2298 XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn, uncritical);
2299 if (fmt[i] == 'E')
2301 register int j;
2302 for (j = 0; j < XVECLEN (x, i); j++)
2303 XVECEXP (x, i, j)
2304 = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn, uncritical);
2307 return x;
2310 /* For each memory ref within X, if it refers to a stack slot
2311 with an out of range displacement, put the address in a temp register
2312 (emitting new insns before INSN to load these registers)
2313 and alter the memory ref to use that register.
2314 Replace each such MEM rtx with a copy, to avoid clobberage. */
2316 static rtx
2317 fixup_stack_1 (x, insn)
2318 rtx x;
2319 rtx insn;
2321 register int i;
2322 register RTX_CODE code = GET_CODE (x);
2323 register char *fmt;
2325 if (code == MEM)
2327 register rtx ad = XEXP (x, 0);
2328 /* If we have address of a stack slot but it's not valid
2329 (displacement is too large), compute the sum in a register. */
2330 if (GET_CODE (ad) == PLUS
2331 && GET_CODE (XEXP (ad, 0)) == REG
2332 && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
2333 && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER)
2334 || XEXP (ad, 0) == current_function_internal_arg_pointer)
2335 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
2337 rtx temp, seq;
2338 if (memory_address_p (GET_MODE (x), ad))
2339 return x;
2341 start_sequence ();
2342 temp = copy_to_reg (ad);
2343 seq = gen_sequence ();
2344 end_sequence ();
2345 emit_insn_before (seq, insn);
2346 return change_address (x, VOIDmode, temp);
2348 return x;
2351 fmt = GET_RTX_FORMAT (code);
2352 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2354 if (fmt[i] == 'e')
2355 XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
2356 if (fmt[i] == 'E')
2358 register int j;
2359 for (j = 0; j < XVECLEN (x, i); j++)
2360 XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
2363 return x;
2366 /* Optimization: a bit-field instruction whose field
2367 happens to be a byte or halfword in memory
2368 can be changed to a move instruction.
2370 We call here when INSN is an insn to examine or store into a bit-field.
2371 BODY is the SET-rtx to be altered.
2373 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2374 (Currently this is called only from function.c, and EQUIV_MEM
2375 is always 0.) */
2377 static void
2378 optimize_bit_field (body, insn, equiv_mem)
2379 rtx body;
2380 rtx insn;
2381 rtx *equiv_mem;
2383 register rtx bitfield;
2384 int destflag;
2385 rtx seq = 0;
2386 enum machine_mode mode;
2388 if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
2389 || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
2390 bitfield = SET_DEST (body), destflag = 1;
2391 else
2392 bitfield = SET_SRC (body), destflag = 0;
2394 /* First check that the field being stored has constant size and position
2395 and is in fact a byte or halfword suitably aligned. */
2397 if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
2398 && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
2399 && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
2400 != BLKmode)
2401 && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
2403 register rtx memref = 0;
2405 /* Now check that the containing word is memory, not a register,
2406 and that it is safe to change the machine mode. */
2408 if (GET_CODE (XEXP (bitfield, 0)) == MEM)
2409 memref = XEXP (bitfield, 0);
2410 else if (GET_CODE (XEXP (bitfield, 0)) == REG
2411 && equiv_mem != 0)
2412 memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
2413 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2414 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
2415 memref = SUBREG_REG (XEXP (bitfield, 0));
2416 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2417 && equiv_mem != 0
2418 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
2419 memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
2421 if (memref
2422 && ! mode_dependent_address_p (XEXP (memref, 0))
2423 && ! MEM_VOLATILE_P (memref))
2425 /* Now adjust the address, first for any subreg'ing
2426 that we are now getting rid of,
2427 and then for which byte of the word is wanted. */
2429 register int offset = INTVAL (XEXP (bitfield, 2));
2430 rtx insns;
2432 /* Adjust OFFSET to count bits from low-address byte. */
2433 if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN)
2434 offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
2435 - offset - INTVAL (XEXP (bitfield, 1)));
2437 /* Adjust OFFSET to count bytes from low-address byte. */
2438 offset /= BITS_PER_UNIT;
2439 if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
2441 offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD;
2442 if (BYTES_BIG_ENDIAN)
2443 offset -= (MIN (UNITS_PER_WORD,
2444 GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
2445 - MIN (UNITS_PER_WORD,
2446 GET_MODE_SIZE (GET_MODE (memref))));
2449 start_sequence ();
2450 memref = change_address (memref, mode,
2451 plus_constant (XEXP (memref, 0), offset));
2452 insns = get_insns ();
2453 end_sequence ();
2454 emit_insns_before (insns, insn);
2456 /* Store this memory reference where
2457 we found the bit field reference. */
2459 if (destflag)
2461 validate_change (insn, &SET_DEST (body), memref, 1);
2462 if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
2464 rtx src = SET_SRC (body);
2465 while (GET_CODE (src) == SUBREG
2466 && SUBREG_WORD (src) == 0)
2467 src = SUBREG_REG (src);
2468 if (GET_MODE (src) != GET_MODE (memref))
2469 src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
2470 validate_change (insn, &SET_SRC (body), src, 1);
2472 else if (GET_MODE (SET_SRC (body)) != VOIDmode
2473 && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
2474 /* This shouldn't happen because anything that didn't have
2475 one of these modes should have got converted explicitly
2476 and then referenced through a subreg.
2477 This is so because the original bit-field was
2478 handled by agg_mode and so its tree structure had
2479 the same mode that memref now has. */
2480 abort ();
2482 else
2484 rtx dest = SET_DEST (body);
2486 while (GET_CODE (dest) == SUBREG
2487 && SUBREG_WORD (dest) == 0
2488 && (GET_MODE_CLASS (GET_MODE (dest))
2489 == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest)))))
2490 dest = SUBREG_REG (dest);
2492 validate_change (insn, &SET_DEST (body), dest, 1);
2494 if (GET_MODE (dest) == GET_MODE (memref))
2495 validate_change (insn, &SET_SRC (body), memref, 1);
2496 else
2498 /* Convert the mem ref to the destination mode. */
2499 rtx newreg = gen_reg_rtx (GET_MODE (dest));
2501 start_sequence ();
2502 convert_move (newreg, memref,
2503 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
2504 seq = get_insns ();
2505 end_sequence ();
2507 validate_change (insn, &SET_SRC (body), newreg, 1);
2511 /* See if we can convert this extraction or insertion into
2512 a simple move insn. We might not be able to do so if this
2513 was, for example, part of a PARALLEL.
2515 If we succeed, write out any needed conversions. If we fail,
2516 it is hard to guess why we failed, so don't do anything
2517 special; just let the optimization be suppressed. */
2519 if (apply_change_group () && seq)
2520 emit_insns_before (seq, insn);
2525 /* These routines are responsible for converting virtual register references
2526 to the actual hard register references once RTL generation is complete.
2528 The following four variables are used for communication between the
2529 routines. They contain the offsets of the virtual registers from their
2530 respective hard registers. */
2532 static int in_arg_offset;
2533 static int var_offset;
2534 static int dynamic_offset;
2535 static int out_arg_offset;
2537 /* In most machines, the stack pointer register is equivalent to the bottom
2538 of the stack. */
2540 #ifndef STACK_POINTER_OFFSET
2541 #define STACK_POINTER_OFFSET 0
2542 #endif
2544 /* If not defined, pick an appropriate default for the offset of dynamically
2545 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2546 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2548 #ifndef STACK_DYNAMIC_OFFSET
2550 #ifdef ACCUMULATE_OUTGOING_ARGS
2551 /* The bottom of the stack points to the actual arguments. If
2552 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2553 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2554 stack space for register parameters is not pushed by the caller, but
2555 rather part of the fixed stack areas and hence not included in
2556 `current_function_outgoing_args_size'. Nevertheless, we must allow
2557 for it when allocating stack dynamic objects. */
2559 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2560 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2561 (current_function_outgoing_args_size \
2562 + REG_PARM_STACK_SPACE (FNDECL) + (STACK_POINTER_OFFSET))
2564 #else
2565 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2566 (current_function_outgoing_args_size + (STACK_POINTER_OFFSET))
2567 #endif
2569 #else
2570 #define STACK_DYNAMIC_OFFSET(FNDECL) STACK_POINTER_OFFSET
2571 #endif
2572 #endif
2574 /* Pass through the INSNS of function FNDECL and convert virtual register
2575 references to hard register references. */
2577 void
2578 instantiate_virtual_regs (fndecl, insns)
2579 tree fndecl;
2580 rtx insns;
2582 rtx insn;
2584 /* Compute the offsets to use for this function. */
2585 in_arg_offset = FIRST_PARM_OFFSET (fndecl);
2586 var_offset = STARTING_FRAME_OFFSET;
2587 dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
2588 out_arg_offset = STACK_POINTER_OFFSET;
2590 /* Scan all variables and parameters of this function. For each that is
2591 in memory, instantiate all virtual registers if the result is a valid
2592 address. If not, we do it later. That will handle most uses of virtual
2593 regs on many machines. */
2594 instantiate_decls (fndecl, 1);
2596 /* Initialize recognition, indicating that volatile is OK. */
2597 init_recog ();
2599 /* Scan through all the insns, instantiating every virtual register still
2600 present. */
2601 for (insn = insns; insn; insn = NEXT_INSN (insn))
2602 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
2603 || GET_CODE (insn) == CALL_INSN)
2605 instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1);
2606 instantiate_virtual_regs_1 (&REG_NOTES (insn), NULL_RTX, 0);
2609 /* Now instantiate the remaining register equivalences for debugging info.
2610 These will not be valid addresses. */
2611 instantiate_decls (fndecl, 0);
2613 /* Indicate that, from now on, assign_stack_local should use
2614 frame_pointer_rtx. */
2615 virtuals_instantiated = 1;
2618 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
2619 all virtual registers in their DECL_RTL's.
2621 If VALID_ONLY, do this only if the resulting address is still valid.
2622 Otherwise, always do it. */
2624 static void
2625 instantiate_decls (fndecl, valid_only)
2626 tree fndecl;
2627 int valid_only;
2629 tree decl;
2631 if (DECL_SAVED_INSNS (fndecl))
2632 /* When compiling an inline function, the obstack used for
2633 rtl allocation is the maybepermanent_obstack. Calling
2634 `resume_temporary_allocation' switches us back to that
2635 obstack while we process this function's parameters. */
2636 resume_temporary_allocation ();
2638 /* Process all parameters of the function. */
2639 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
2641 int size = int_size_in_bytes (TREE_TYPE (decl));
2642 instantiate_decl (DECL_RTL (decl), size, valid_only);
2644 /* If the parameter was promoted, then the incoming RTL mode may be
2645 larger than the declared type size. We must use the larger of
2646 the two sizes. */
2647 size = MAX (GET_MODE_SIZE (GET_MODE (DECL_INCOMING_RTL (decl))), size);
2648 instantiate_decl (DECL_INCOMING_RTL (decl), size, valid_only);
2651 /* Now process all variables defined in the function or its subblocks. */
2652 instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
2654 if (DECL_INLINE (fndecl) || DECL_DEFER_OUTPUT (fndecl))
2656 /* Save all rtl allocated for this function by raising the
2657 high-water mark on the maybepermanent_obstack. */
2658 preserve_data ();
2659 /* All further rtl allocation is now done in the current_obstack. */
2660 rtl_in_current_obstack ();
2664 /* Subroutine of instantiate_decls: Process all decls in the given
2665 BLOCK node and all its subblocks. */
2667 static void
2668 instantiate_decls_1 (let, valid_only)
2669 tree let;
2670 int valid_only;
2672 tree t;
2674 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
2675 instantiate_decl (DECL_RTL (t), int_size_in_bytes (TREE_TYPE (t)),
2676 valid_only);
2678 /* Process all subblocks. */
2679 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
2680 instantiate_decls_1 (t, valid_only);
2683 /* Subroutine of the preceding procedures: Given RTL representing a
2684 decl and the size of the object, do any instantiation required.
2686 If VALID_ONLY is non-zero, it means that the RTL should only be
2687 changed if the new address is valid. */
2689 static void
2690 instantiate_decl (x, size, valid_only)
2691 rtx x;
2692 int size;
2693 int valid_only;
2695 enum machine_mode mode;
2696 rtx addr;
2698 /* If this is not a MEM, no need to do anything. Similarly if the
2699 address is a constant or a register that is not a virtual register. */
2701 if (x == 0 || GET_CODE (x) != MEM)
2702 return;
2704 addr = XEXP (x, 0);
2705 if (CONSTANT_P (addr)
2706 || (GET_CODE (addr) == REG
2707 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
2708 || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
2709 return;
2711 /* If we should only do this if the address is valid, copy the address.
2712 We need to do this so we can undo any changes that might make the
2713 address invalid. This copy is unfortunate, but probably can't be
2714 avoided. */
2716 if (valid_only)
2717 addr = copy_rtx (addr);
2719 instantiate_virtual_regs_1 (&addr, NULL_RTX, 0);
2721 if (valid_only)
2723 /* Now verify that the resulting address is valid for every integer or
2724 floating-point mode up to and including SIZE bytes long. We do this
2725 since the object might be accessed in any mode and frame addresses
2726 are shared. */
2728 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2729 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
2730 mode = GET_MODE_WIDER_MODE (mode))
2731 if (! memory_address_p (mode, addr))
2732 return;
2734 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
2735 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
2736 mode = GET_MODE_WIDER_MODE (mode))
2737 if (! memory_address_p (mode, addr))
2738 return;
2741 /* Put back the address now that we have updated it and we either know
2742 it is valid or we don't care whether it is valid. */
2744 XEXP (x, 0) = addr;
2747 /* Given a pointer to a piece of rtx and an optional pointer to the
2748 containing object, instantiate any virtual registers present in it.
2750 If EXTRA_INSNS, we always do the replacement and generate
2751 any extra insns before OBJECT. If it zero, we do nothing if replacement
2752 is not valid.
2754 Return 1 if we either had nothing to do or if we were able to do the
2755 needed replacement. Return 0 otherwise; we only return zero if
2756 EXTRA_INSNS is zero.
2758 We first try some simple transformations to avoid the creation of extra
2759 pseudos. */
2761 static int
2762 instantiate_virtual_regs_1 (loc, object, extra_insns)
2763 rtx *loc;
2764 rtx object;
2765 int extra_insns;
2767 rtx x;
2768 RTX_CODE code;
2769 rtx new = 0;
2770 int offset;
2771 rtx temp;
2772 rtx seq;
2773 int i, j;
2774 char *fmt;
2776 /* Re-start here to avoid recursion in common cases. */
2777 restart:
2779 x = *loc;
2780 if (x == 0)
2781 return 1;
2783 code = GET_CODE (x);
2785 /* Check for some special cases. */
2786 switch (code)
2788 case CONST_INT:
2789 case CONST_DOUBLE:
2790 case CONST:
2791 case SYMBOL_REF:
2792 case CODE_LABEL:
2793 case PC:
2794 case CC0:
2795 case ASM_INPUT:
2796 case ADDR_VEC:
2797 case ADDR_DIFF_VEC:
2798 case RETURN:
2799 return 1;
2801 case SET:
2802 /* We are allowed to set the virtual registers. This means that
2803 that the actual register should receive the source minus the
2804 appropriate offset. This is used, for example, in the handling
2805 of non-local gotos. */
2806 if (SET_DEST (x) == virtual_incoming_args_rtx)
2807 new = arg_pointer_rtx, offset = - in_arg_offset;
2808 else if (SET_DEST (x) == virtual_stack_vars_rtx)
2809 new = frame_pointer_rtx, offset = - var_offset;
2810 else if (SET_DEST (x) == virtual_stack_dynamic_rtx)
2811 new = stack_pointer_rtx, offset = - dynamic_offset;
2812 else if (SET_DEST (x) == virtual_outgoing_args_rtx)
2813 new = stack_pointer_rtx, offset = - out_arg_offset;
2815 if (new)
2817 /* The only valid sources here are PLUS or REG. Just do
2818 the simplest possible thing to handle them. */
2819 if (GET_CODE (SET_SRC (x)) != REG
2820 && GET_CODE (SET_SRC (x)) != PLUS)
2821 abort ();
2823 start_sequence ();
2824 if (GET_CODE (SET_SRC (x)) != REG)
2825 temp = force_operand (SET_SRC (x), NULL_RTX);
2826 else
2827 temp = SET_SRC (x);
2828 temp = force_operand (plus_constant (temp, offset), NULL_RTX);
2829 seq = get_insns ();
2830 end_sequence ();
2832 emit_insns_before (seq, object);
2833 SET_DEST (x) = new;
2835 if (!validate_change (object, &SET_SRC (x), temp, 0)
2836 || ! extra_insns)
2837 abort ();
2839 return 1;
2842 instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns);
2843 loc = &SET_SRC (x);
2844 goto restart;
2846 case PLUS:
2847 /* Handle special case of virtual register plus constant. */
2848 if (CONSTANT_P (XEXP (x, 1)))
2850 rtx old, new_offset;
2852 /* Check for (plus (plus VIRT foo) (const_int)) first. */
2853 if (GET_CODE (XEXP (x, 0)) == PLUS)
2855 rtx inner = XEXP (XEXP (x, 0), 0);
2857 if (inner == virtual_incoming_args_rtx)
2858 new = arg_pointer_rtx, offset = in_arg_offset;
2859 else if (inner == virtual_stack_vars_rtx)
2860 new = frame_pointer_rtx, offset = var_offset;
2861 else if (inner == virtual_stack_dynamic_rtx)
2862 new = stack_pointer_rtx, offset = dynamic_offset;
2863 else if (inner == virtual_outgoing_args_rtx)
2864 new = stack_pointer_rtx, offset = out_arg_offset;
2865 else
2867 loc = &XEXP (x, 0);
2868 goto restart;
2871 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object,
2872 extra_insns);
2873 new = gen_rtx (PLUS, Pmode, new, XEXP (XEXP (x, 0), 1));
2876 else if (XEXP (x, 0) == virtual_incoming_args_rtx)
2877 new = arg_pointer_rtx, offset = in_arg_offset;
2878 else if (XEXP (x, 0) == virtual_stack_vars_rtx)
2879 new = frame_pointer_rtx, offset = var_offset;
2880 else if (XEXP (x, 0) == virtual_stack_dynamic_rtx)
2881 new = stack_pointer_rtx, offset = dynamic_offset;
2882 else if (XEXP (x, 0) == virtual_outgoing_args_rtx)
2883 new = stack_pointer_rtx, offset = out_arg_offset;
2884 else
2886 /* We know the second operand is a constant. Unless the
2887 first operand is a REG (which has been already checked),
2888 it needs to be checked. */
2889 if (GET_CODE (XEXP (x, 0)) != REG)
2891 loc = &XEXP (x, 0);
2892 goto restart;
2894 return 1;
2897 new_offset = plus_constant (XEXP (x, 1), offset);
2899 /* If the new constant is zero, try to replace the sum with just
2900 the register. */
2901 if (new_offset == const0_rtx
2902 && validate_change (object, loc, new, 0))
2903 return 1;
2905 /* Next try to replace the register and new offset.
2906 There are two changes to validate here and we can't assume that
2907 in the case of old offset equals new just changing the register
2908 will yield a valid insn. In the interests of a little efficiency,
2909 however, we only call validate change once (we don't queue up the
2910 changes and then call apply_change_group). */
2912 old = XEXP (x, 0);
2913 if (offset == 0
2914 ? ! validate_change (object, &XEXP (x, 0), new, 0)
2915 : (XEXP (x, 0) = new,
2916 ! validate_change (object, &XEXP (x, 1), new_offset, 0)))
2918 if (! extra_insns)
2920 XEXP (x, 0) = old;
2921 return 0;
2924 /* Otherwise copy the new constant into a register and replace
2925 constant with that register. */
2926 temp = gen_reg_rtx (Pmode);
2927 XEXP (x, 0) = new;
2928 if (validate_change (object, &XEXP (x, 1), temp, 0))
2929 emit_insn_before (gen_move_insn (temp, new_offset), object);
2930 else
2932 /* If that didn't work, replace this expression with a
2933 register containing the sum. */
2935 XEXP (x, 0) = old;
2936 new = gen_rtx (PLUS, Pmode, new, new_offset);
2938 start_sequence ();
2939 temp = force_operand (new, NULL_RTX);
2940 seq = get_insns ();
2941 end_sequence ();
2943 emit_insns_before (seq, object);
2944 if (! validate_change (object, loc, temp, 0)
2945 && ! validate_replace_rtx (x, temp, object))
2946 abort ();
2950 return 1;
2953 /* Fall through to generic two-operand expression case. */
2954 case EXPR_LIST:
2955 case CALL:
2956 case COMPARE:
2957 case MINUS:
2958 case MULT:
2959 case DIV: case UDIV:
2960 case MOD: case UMOD:
2961 case AND: case IOR: case XOR:
2962 case ROTATERT: case ROTATE:
2963 case ASHIFTRT: case LSHIFTRT: case ASHIFT:
2964 case NE: case EQ:
2965 case GE: case GT: case GEU: case GTU:
2966 case LE: case LT: case LEU: case LTU:
2967 if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
2968 instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns);
2969 loc = &XEXP (x, 0);
2970 goto restart;
2972 case MEM:
2973 /* Most cases of MEM that convert to valid addresses have already been
2974 handled by our scan of decls. The only special handling we
2975 need here is to make a copy of the rtx to ensure it isn't being
2976 shared if we have to change it to a pseudo.
2978 If the rtx is a simple reference to an address via a virtual register,
2979 it can potentially be shared. In such cases, first try to make it
2980 a valid address, which can also be shared. Otherwise, copy it and
2981 proceed normally.
2983 First check for common cases that need no processing. These are
2984 usually due to instantiation already being done on a previous instance
2985 of a shared rtx. */
2987 temp = XEXP (x, 0);
2988 if (CONSTANT_ADDRESS_P (temp)
2989 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2990 || temp == arg_pointer_rtx
2991 #endif
2992 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2993 || temp == hard_frame_pointer_rtx
2994 #endif
2995 || temp == frame_pointer_rtx)
2996 return 1;
2998 if (GET_CODE (temp) == PLUS
2999 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
3000 && (XEXP (temp, 0) == frame_pointer_rtx
3001 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3002 || XEXP (temp, 0) == hard_frame_pointer_rtx
3003 #endif
3004 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3005 || XEXP (temp, 0) == arg_pointer_rtx
3006 #endif
3008 return 1;
3010 if (temp == virtual_stack_vars_rtx
3011 || temp == virtual_incoming_args_rtx
3012 || (GET_CODE (temp) == PLUS
3013 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
3014 && (XEXP (temp, 0) == virtual_stack_vars_rtx
3015 || XEXP (temp, 0) == virtual_incoming_args_rtx)))
3017 /* This MEM may be shared. If the substitution can be done without
3018 the need to generate new pseudos, we want to do it in place
3019 so all copies of the shared rtx benefit. The call below will
3020 only make substitutions if the resulting address is still
3021 valid.
3023 Note that we cannot pass X as the object in the recursive call
3024 since the insn being processed may not allow all valid
3025 addresses. However, if we were not passed on object, we can
3026 only modify X without copying it if X will have a valid
3027 address.
3029 ??? Also note that this can still lose if OBJECT is an insn that
3030 has less restrictions on an address that some other insn.
3031 In that case, we will modify the shared address. This case
3032 doesn't seem very likely, though. One case where this could
3033 happen is in the case of a USE or CLOBBER reference, but we
3034 take care of that below. */
3036 if (instantiate_virtual_regs_1 (&XEXP (x, 0),
3037 object ? object : x, 0))
3038 return 1;
3040 /* Otherwise make a copy and process that copy. We copy the entire
3041 RTL expression since it might be a PLUS which could also be
3042 shared. */
3043 *loc = x = copy_rtx (x);
3046 /* Fall through to generic unary operation case. */
3047 case SUBREG:
3048 case STRICT_LOW_PART:
3049 case NEG: case NOT:
3050 case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC:
3051 case SIGN_EXTEND: case ZERO_EXTEND:
3052 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE:
3053 case FLOAT: case FIX:
3054 case UNSIGNED_FIX: case UNSIGNED_FLOAT:
3055 case ABS:
3056 case SQRT:
3057 case FFS:
3058 /* These case either have just one operand or we know that we need not
3059 check the rest of the operands. */
3060 loc = &XEXP (x, 0);
3061 goto restart;
3063 case USE:
3064 case CLOBBER:
3065 /* If the operand is a MEM, see if the change is a valid MEM. If not,
3066 go ahead and make the invalid one, but do it to a copy. For a REG,
3067 just make the recursive call, since there's no chance of a problem. */
3069 if ((GET_CODE (XEXP (x, 0)) == MEM
3070 && instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), XEXP (x, 0),
3072 || (GET_CODE (XEXP (x, 0)) == REG
3073 && instantiate_virtual_regs_1 (&XEXP (x, 0), object, 0)))
3074 return 1;
3076 XEXP (x, 0) = copy_rtx (XEXP (x, 0));
3077 loc = &XEXP (x, 0);
3078 goto restart;
3080 case REG:
3081 /* Try to replace with a PLUS. If that doesn't work, compute the sum
3082 in front of this insn and substitute the temporary. */
3083 if (x == virtual_incoming_args_rtx)
3084 new = arg_pointer_rtx, offset = in_arg_offset;
3085 else if (x == virtual_stack_vars_rtx)
3086 new = frame_pointer_rtx, offset = var_offset;
3087 else if (x == virtual_stack_dynamic_rtx)
3088 new = stack_pointer_rtx, offset = dynamic_offset;
3089 else if (x == virtual_outgoing_args_rtx)
3090 new = stack_pointer_rtx, offset = out_arg_offset;
3092 if (new)
3094 temp = plus_constant (new, offset);
3095 if (!validate_change (object, loc, temp, 0))
3097 if (! extra_insns)
3098 return 0;
3100 start_sequence ();
3101 temp = force_operand (temp, NULL_RTX);
3102 seq = get_insns ();
3103 end_sequence ();
3105 emit_insns_before (seq, object);
3106 if (! validate_change (object, loc, temp, 0)
3107 && ! validate_replace_rtx (x, temp, object))
3108 abort ();
3112 return 1;
3115 /* Scan all subexpressions. */
3116 fmt = GET_RTX_FORMAT (code);
3117 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
3118 if (*fmt == 'e')
3120 if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns))
3121 return 0;
3123 else if (*fmt == 'E')
3124 for (j = 0; j < XVECLEN (x, i); j++)
3125 if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object,
3126 extra_insns))
3127 return 0;
3129 return 1;
3132 /* Optimization: assuming this function does not receive nonlocal gotos,
3133 delete the handlers for such, as well as the insns to establish
3134 and disestablish them. */
3136 static void
3137 delete_handlers ()
3139 rtx insn;
3140 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3142 /* Delete the handler by turning off the flag that would
3143 prevent jump_optimize from deleting it.
3144 Also permit deletion of the nonlocal labels themselves
3145 if nothing local refers to them. */
3146 if (GET_CODE (insn) == CODE_LABEL)
3148 tree t, last_t;
3150 LABEL_PRESERVE_P (insn) = 0;
3152 /* Remove it from the nonlocal_label list, to avoid confusing
3153 flow. */
3154 for (t = nonlocal_labels, last_t = 0; t;
3155 last_t = t, t = TREE_CHAIN (t))
3156 if (DECL_RTL (TREE_VALUE (t)) == insn)
3157 break;
3158 if (t)
3160 if (! last_t)
3161 nonlocal_labels = TREE_CHAIN (nonlocal_labels);
3162 else
3163 TREE_CHAIN (last_t) = TREE_CHAIN (t);
3166 if (GET_CODE (insn) == INSN
3167 && ((nonlocal_goto_handler_slot != 0
3168 && reg_mentioned_p (nonlocal_goto_handler_slot, PATTERN (insn)))
3169 || (nonlocal_goto_stack_level != 0
3170 && reg_mentioned_p (nonlocal_goto_stack_level,
3171 PATTERN (insn)))))
3172 delete_insn (insn);
3176 /* Return a list (chain of EXPR_LIST nodes) for the nonlocal labels
3177 of the current function. */
3180 nonlocal_label_rtx_list ()
3182 tree t;
3183 rtx x = 0;
3185 for (t = nonlocal_labels; t; t = TREE_CHAIN (t))
3186 x = gen_rtx (EXPR_LIST, VOIDmode, label_rtx (TREE_VALUE (t)), x);
3188 return x;
3191 /* Output a USE for any register use in RTL.
3192 This is used with -noreg to mark the extent of lifespan
3193 of any registers used in a user-visible variable's DECL_RTL. */
3195 void
3196 use_variable (rtl)
3197 rtx rtl;
3199 if (GET_CODE (rtl) == REG)
3200 /* This is a register variable. */
3201 emit_insn (gen_rtx (USE, VOIDmode, rtl));
3202 else if (GET_CODE (rtl) == MEM
3203 && GET_CODE (XEXP (rtl, 0)) == REG
3204 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
3205 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
3206 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
3207 /* This is a variable-sized structure. */
3208 emit_insn (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)));
3211 /* Like use_variable except that it outputs the USEs after INSN
3212 instead of at the end of the insn-chain. */
3214 void
3215 use_variable_after (rtl, insn)
3216 rtx rtl, insn;
3218 if (GET_CODE (rtl) == REG)
3219 /* This is a register variable. */
3220 emit_insn_after (gen_rtx (USE, VOIDmode, rtl), insn);
3221 else if (GET_CODE (rtl) == MEM
3222 && GET_CODE (XEXP (rtl, 0)) == REG
3223 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
3224 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
3225 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
3226 /* This is a variable-sized structure. */
3227 emit_insn_after (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)), insn);
3231 max_parm_reg_num ()
3233 return max_parm_reg;
3236 /* Return the first insn following those generated by `assign_parms'. */
3239 get_first_nonparm_insn ()
3241 if (last_parm_insn)
3242 return NEXT_INSN (last_parm_insn);
3243 return get_insns ();
3246 /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
3247 Crash if there is none. */
3250 get_first_block_beg ()
3252 register rtx searcher;
3253 register rtx insn = get_first_nonparm_insn ();
3255 for (searcher = insn; searcher; searcher = NEXT_INSN (searcher))
3256 if (GET_CODE (searcher) == NOTE
3257 && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG)
3258 return searcher;
3260 abort (); /* Invalid call to this function. (See comments above.) */
3261 return NULL_RTX;
3264 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
3265 This means a type for which function calls must pass an address to the
3266 function or get an address back from the function.
3267 EXP may be a type node or an expression (whose type is tested). */
3270 aggregate_value_p (exp)
3271 tree exp;
3273 int i, regno, nregs;
3274 rtx reg;
3275 tree type;
3276 if (TREE_CODE_CLASS (TREE_CODE (exp)) == 't')
3277 type = exp;
3278 else
3279 type = TREE_TYPE (exp);
3281 if (RETURN_IN_MEMORY (type))
3282 return 1;
3283 /* Types that are TREE_ADDRESSABLE must be contructed in memory,
3284 and thus can't be returned in registers. */
3285 if (TREE_ADDRESSABLE (type))
3286 return 1;
3287 if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
3288 return 1;
3289 /* Make sure we have suitable call-clobbered regs to return
3290 the value in; if not, we must return it in memory. */
3291 reg = hard_function_value (type, 0);
3293 /* If we have something other than a REG (e.g. a PARALLEL), then assume
3294 it is OK. */
3295 if (GET_CODE (reg) != REG)
3296 return 0;
3298 regno = REGNO (reg);
3299 nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type));
3300 for (i = 0; i < nregs; i++)
3301 if (! call_used_regs[regno + i])
3302 return 1;
3303 return 0;
3306 /* Assign RTL expressions to the function's parameters.
3307 This may involve copying them into registers and using
3308 those registers as the RTL for them.
3310 If SECOND_TIME is non-zero it means that this function is being
3311 called a second time. This is done by integrate.c when a function's
3312 compilation is deferred. We need to come back here in case the
3313 FUNCTION_ARG macro computes items needed for the rest of the compilation
3314 (such as changing which registers are fixed or caller-saved). But suppress
3315 writing any insns or setting DECL_RTL of anything in this case. */
3317 void
3318 assign_parms (fndecl, second_time)
3319 tree fndecl;
3320 int second_time;
3322 register tree parm;
3323 register rtx entry_parm = 0;
3324 register rtx stack_parm = 0;
3325 CUMULATIVE_ARGS args_so_far;
3326 enum machine_mode promoted_mode, passed_mode;
3327 enum machine_mode nominal_mode, promoted_nominal_mode;
3328 int unsignedp;
3329 /* Total space needed so far for args on the stack,
3330 given as a constant and a tree-expression. */
3331 struct args_size stack_args_size;
3332 tree fntype = TREE_TYPE (fndecl);
3333 tree fnargs = DECL_ARGUMENTS (fndecl);
3334 /* This is used for the arg pointer when referring to stack args. */
3335 rtx internal_arg_pointer;
3336 /* This is a dummy PARM_DECL that we used for the function result if
3337 the function returns a structure. */
3338 tree function_result_decl = 0;
3339 int nparmregs = list_length (fnargs) + LAST_VIRTUAL_REGISTER + 1;
3340 int varargs_setup = 0;
3341 rtx conversion_insns = 0;
3343 /* Nonzero if the last arg is named `__builtin_va_alist',
3344 which is used on some machines for old-fashioned non-ANSI varargs.h;
3345 this should be stuck onto the stack as if it had arrived there. */
3346 int hide_last_arg
3347 = (current_function_varargs
3348 && fnargs
3349 && (parm = tree_last (fnargs)) != 0
3350 && DECL_NAME (parm)
3351 && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
3352 "__builtin_va_alist")));
3354 /* Nonzero if function takes extra anonymous args.
3355 This means the last named arg must be on the stack
3356 right before the anonymous ones. */
3357 int stdarg
3358 = (TYPE_ARG_TYPES (fntype) != 0
3359 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3360 != void_type_node));
3362 current_function_stdarg = stdarg;
3364 /* If the reg that the virtual arg pointer will be translated into is
3365 not a fixed reg or is the stack pointer, make a copy of the virtual
3366 arg pointer, and address parms via the copy. The frame pointer is
3367 considered fixed even though it is not marked as such.
3369 The second time through, simply use ap to avoid generating rtx. */
3371 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
3372 || ! (fixed_regs[ARG_POINTER_REGNUM]
3373 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM))
3374 && ! second_time)
3375 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
3376 else
3377 internal_arg_pointer = virtual_incoming_args_rtx;
3378 current_function_internal_arg_pointer = internal_arg_pointer;
3380 stack_args_size.constant = 0;
3381 stack_args_size.var = 0;
3383 /* If struct value address is treated as the first argument, make it so. */
3384 if (aggregate_value_p (DECL_RESULT (fndecl))
3385 && ! current_function_returns_pcc_struct
3386 && struct_value_incoming_rtx == 0)
3388 tree type = build_pointer_type (TREE_TYPE (fntype));
3390 function_result_decl = build_decl (PARM_DECL, NULL_TREE, type);
3392 DECL_ARG_TYPE (function_result_decl) = type;
3393 TREE_CHAIN (function_result_decl) = fnargs;
3394 fnargs = function_result_decl;
3397 parm_reg_stack_loc = (rtx *) oballoc (nparmregs * sizeof (rtx));
3398 bzero ((char *) parm_reg_stack_loc, nparmregs * sizeof (rtx));
3400 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
3401 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX);
3402 #else
3403 INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX, 0);
3404 #endif
3406 /* We haven't yet found an argument that we must push and pretend the
3407 caller did. */
3408 current_function_pretend_args_size = 0;
3410 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
3412 int aggregate = AGGREGATE_TYPE_P (TREE_TYPE (parm));
3413 struct args_size stack_offset;
3414 struct args_size arg_size;
3415 int passed_pointer = 0;
3416 int did_conversion = 0;
3417 tree passed_type = DECL_ARG_TYPE (parm);
3418 tree nominal_type = TREE_TYPE (parm);
3420 /* Set LAST_NAMED if this is last named arg before some
3421 anonymous args. We treat it as if it were anonymous too. */
3422 int last_named = ((TREE_CHAIN (parm) == 0
3423 || DECL_NAME (TREE_CHAIN (parm)) == 0)
3424 && (stdarg || current_function_varargs));
3426 if (TREE_TYPE (parm) == error_mark_node
3427 /* This can happen after weird syntax errors
3428 or if an enum type is defined among the parms. */
3429 || TREE_CODE (parm) != PARM_DECL
3430 || passed_type == NULL)
3432 DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = gen_rtx (MEM, BLKmode,
3433 const0_rtx);
3434 TREE_USED (parm) = 1;
3435 continue;
3438 /* For varargs.h function, save info about regs and stack space
3439 used by the individual args, not including the va_alist arg. */
3440 if (hide_last_arg && last_named)
3441 current_function_args_info = args_so_far;
3443 /* Find mode of arg as it is passed, and mode of arg
3444 as it should be during execution of this function. */
3445 passed_mode = TYPE_MODE (passed_type);
3446 nominal_mode = TYPE_MODE (nominal_type);
3448 /* If the parm's mode is VOID, its value doesn't matter,
3449 and avoid the usual things like emit_move_insn that could crash. */
3450 if (nominal_mode == VOIDmode)
3452 DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = const0_rtx;
3453 continue;
3456 /* If the parm is to be passed as a transparent union, use the
3457 type of the first field for the tests below. We have already
3458 verified that the modes are the same. */
3459 if (DECL_TRANSPARENT_UNION (parm)
3460 || TYPE_TRANSPARENT_UNION (passed_type))
3461 passed_type = TREE_TYPE (TYPE_FIELDS (passed_type));
3463 /* See if this arg was passed by invisible reference. It is if
3464 it is an object whose size depends on the contents of the
3465 object itself or if the machine requires these objects be passed
3466 that way. */
3468 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
3469 && contains_placeholder_p (TYPE_SIZE (passed_type)))
3470 || TREE_ADDRESSABLE (passed_type)
3471 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
3472 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
3473 passed_type, ! last_named)
3474 #endif
3477 passed_type = nominal_type = build_pointer_type (passed_type);
3478 passed_pointer = 1;
3479 passed_mode = nominal_mode = Pmode;
3482 promoted_mode = passed_mode;
3484 #ifdef PROMOTE_FUNCTION_ARGS
3485 /* Compute the mode in which the arg is actually extended to. */
3486 promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1);
3487 #endif
3489 /* Let machine desc say which reg (if any) the parm arrives in.
3490 0 means it arrives on the stack. */
3491 #ifdef FUNCTION_INCOMING_ARG
3492 entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
3493 passed_type, ! last_named);
3494 #else
3495 entry_parm = FUNCTION_ARG (args_so_far, promoted_mode,
3496 passed_type, ! last_named);
3497 #endif
3499 if (entry_parm == 0)
3500 promoted_mode = passed_mode;
3502 #ifdef SETUP_INCOMING_VARARGS
3503 /* If this is the last named parameter, do any required setup for
3504 varargs or stdargs. We need to know about the case of this being an
3505 addressable type, in which case we skip the registers it
3506 would have arrived in.
3508 For stdargs, LAST_NAMED will be set for two parameters, the one that
3509 is actually the last named, and the dummy parameter. We only
3510 want to do this action once.
3512 Also, indicate when RTL generation is to be suppressed. */
3513 if (last_named && !varargs_setup)
3515 SETUP_INCOMING_VARARGS (args_so_far, promoted_mode, passed_type,
3516 current_function_pretend_args_size,
3517 second_time);
3518 varargs_setup = 1;
3520 #endif
3522 /* Determine parm's home in the stack,
3523 in case it arrives in the stack or we should pretend it did.
3525 Compute the stack position and rtx where the argument arrives
3526 and its size.
3528 There is one complexity here: If this was a parameter that would
3529 have been passed in registers, but wasn't only because it is
3530 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
3531 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
3532 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
3533 0 as it was the previous time. */
3535 locate_and_pad_parm (promoted_mode, passed_type,
3536 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3538 #else
3539 #ifdef FUNCTION_INCOMING_ARG
3540 FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
3541 passed_type,
3542 (! last_named
3543 || varargs_setup)) != 0,
3544 #else
3545 FUNCTION_ARG (args_so_far, promoted_mode,
3546 passed_type,
3547 ! last_named || varargs_setup) != 0,
3548 #endif
3549 #endif
3550 fndecl, &stack_args_size, &stack_offset, &arg_size);
3552 if (! second_time)
3554 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
3556 if (offset_rtx == const0_rtx)
3557 stack_parm = gen_rtx (MEM, promoted_mode, internal_arg_pointer);
3558 else
3559 stack_parm = gen_rtx (MEM, promoted_mode,
3560 gen_rtx (PLUS, Pmode,
3561 internal_arg_pointer, offset_rtx));
3563 /* If this is a memory ref that contains aggregate components,
3564 mark it as such for cse and loop optimize. Likewise if it
3565 is readonly. */
3566 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3567 RTX_UNCHANGING_P (stack_parm) = TREE_READONLY (parm);
3570 /* If this parameter was passed both in registers and in the stack,
3571 use the copy on the stack. */
3572 if (MUST_PASS_IN_STACK (promoted_mode, passed_type))
3573 entry_parm = 0;
3575 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3576 /* If this parm was passed part in regs and part in memory,
3577 pretend it arrived entirely in memory
3578 by pushing the register-part onto the stack.
3580 In the special case of a DImode or DFmode that is split,
3581 we could put it together in a pseudoreg directly,
3582 but for now that's not worth bothering with. */
3584 if (entry_parm)
3586 int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, promoted_mode,
3587 passed_type, ! last_named);
3589 if (nregs > 0)
3591 current_function_pretend_args_size
3592 = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
3593 / (PARM_BOUNDARY / BITS_PER_UNIT)
3594 * (PARM_BOUNDARY / BITS_PER_UNIT));
3596 if (! second_time)
3598 /* Handle calls that pass values in multiple non-contiguous
3599 locations. The Irix 6 ABI has examples of this. */
3600 if (GET_CODE (entry_parm) == PARALLEL)
3601 emit_group_store (validize_mem (stack_parm),
3602 entry_parm);
3603 else
3604 move_block_from_reg (REGNO (entry_parm),
3605 validize_mem (stack_parm), nregs,
3606 int_size_in_bytes (TREE_TYPE (parm)));
3608 entry_parm = stack_parm;
3611 #endif
3613 /* If we didn't decide this parm came in a register,
3614 by default it came on the stack. */
3615 if (entry_parm == 0)
3616 entry_parm = stack_parm;
3618 /* Record permanently how this parm was passed. */
3619 if (! second_time)
3620 DECL_INCOMING_RTL (parm) = entry_parm;
3622 /* If there is actually space on the stack for this parm,
3623 count it in stack_args_size; otherwise set stack_parm to 0
3624 to indicate there is no preallocated stack slot for the parm. */
3626 if (entry_parm == stack_parm
3627 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
3628 /* On some machines, even if a parm value arrives in a register
3629 there is still an (uninitialized) stack slot allocated for it.
3631 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
3632 whether this parameter already has a stack slot allocated,
3633 because an arg block exists only if current_function_args_size
3634 is larger than some threshold, and we haven't calculated that
3635 yet. So, for now, we just assume that stack slots never exist
3636 in this case. */
3637 || REG_PARM_STACK_SPACE (fndecl) > 0
3638 #endif
3641 stack_args_size.constant += arg_size.constant;
3642 if (arg_size.var)
3643 ADD_PARM_SIZE (stack_args_size, arg_size.var);
3645 else
3646 /* No stack slot was pushed for this parm. */
3647 stack_parm = 0;
3649 /* Update info on where next arg arrives in registers. */
3651 FUNCTION_ARG_ADVANCE (args_so_far, promoted_mode,
3652 passed_type, ! last_named);
3654 /* If this is our second time through, we are done with this parm. */
3655 if (second_time)
3656 continue;
3658 /* If we can't trust the parm stack slot to be aligned enough
3659 for its ultimate type, don't use that slot after entry.
3660 We'll make another stack slot, if we need one. */
3662 int thisparm_boundary
3663 = FUNCTION_ARG_BOUNDARY (promoted_mode, passed_type);
3665 if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary)
3666 stack_parm = 0;
3669 /* If parm was passed in memory, and we need to convert it on entry,
3670 don't store it back in that same slot. */
3671 if (entry_parm != 0
3672 && nominal_mode != BLKmode && nominal_mode != passed_mode)
3673 stack_parm = 0;
3675 #if 0
3676 /* Now adjust STACK_PARM to the mode and precise location
3677 where this parameter should live during execution,
3678 if we discover that it must live in the stack during execution.
3679 To make debuggers happier on big-endian machines, we store
3680 the value in the last bytes of the space available. */
3682 if (nominal_mode != BLKmode && nominal_mode != passed_mode
3683 && stack_parm != 0)
3685 rtx offset_rtx;
3687 if (BYTES_BIG_ENDIAN
3688 && GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD)
3689 stack_offset.constant += (GET_MODE_SIZE (passed_mode)
3690 - GET_MODE_SIZE (nominal_mode));
3692 offset_rtx = ARGS_SIZE_RTX (stack_offset);
3693 if (offset_rtx == const0_rtx)
3694 stack_parm = gen_rtx (MEM, nominal_mode, internal_arg_pointer);
3695 else
3696 stack_parm = gen_rtx (MEM, nominal_mode,
3697 gen_rtx (PLUS, Pmode,
3698 if (flag_check_memory_usage)
3700 push_to_sequence (conversion_insns);
3701 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
3702 XEXP (stack_parm, 0), ptr_mode,
3703 GEN_INT (int_size_in_bytes
3704 (TREE_TYPE (parm))),
3705 TYPE_MODE (sizetype),
3706 GEN_INT (MEMORY_USE_RW), QImode);
3707 conversion_insns = get_insns ();
3708 end_sequence ();
3710 internal_arg_pointer, offset_rtx));
3712 /* If this is a memory ref that contains aggregate components,
3713 mark it as such for cse and loop optimize. */
3714 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3716 #endif /* 0 */
3718 #ifdef STACK_REGS
3719 /* We need this "use" info, because the gcc-register->stack-register
3720 converter in reg-stack.c needs to know which registers are active
3721 at the start of the function call. The actual parameter loading
3722 instructions are not always available then anymore, since they might
3723 have been optimised away. */
3725 if (GET_CODE (entry_parm) == REG && !(hide_last_arg && last_named))
3726 emit_insn (gen_rtx (USE, GET_MODE (entry_parm), entry_parm));
3727 #endif
3729 /* ENTRY_PARM is an RTX for the parameter as it arrives,
3730 in the mode in which it arrives.
3731 STACK_PARM is an RTX for a stack slot where the parameter can live
3732 during the function (in case we want to put it there).
3733 STACK_PARM is 0 if no stack slot was pushed for it.
3735 Now output code if necessary to convert ENTRY_PARM to
3736 the type in which this function declares it,
3737 and store that result in an appropriate place,
3738 which may be a pseudo reg, may be STACK_PARM,
3739 or may be a local stack slot if STACK_PARM is 0.
3741 Set DECL_RTL to that place. */
3743 if (nominal_mode == BLKmode || GET_CODE (entry_parm) == PARALLEL)
3745 /* If a BLKmode arrives in registers, copy it to a stack slot.
3746 Handle calls that pass values in multiple non-contiguous
3747 locations. The Irix 6 ABI has examples of this. */
3748 if (GET_CODE (entry_parm) == REG
3749 || GET_CODE (entry_parm) == PARALLEL)
3751 int size_stored
3752 = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
3753 UNITS_PER_WORD);
3755 /* Note that we will be storing an integral number of words.
3756 So we have to be careful to ensure that we allocate an
3757 integral number of words. We do this below in the
3758 assign_stack_local if space was not allocated in the argument
3759 list. If it was, this will not work if PARM_BOUNDARY is not
3760 a multiple of BITS_PER_WORD. It isn't clear how to fix this
3761 if it becomes a problem. */
3763 if (stack_parm == 0)
3765 stack_parm
3766 = assign_stack_local (GET_MODE (entry_parm),
3767 size_stored, 0);
3769 /* If this is a memory ref that contains aggregate
3770 components, mark it as such for cse and loop optimize. */
3771 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3774 else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
3775 abort ();
3777 if (TREE_READONLY (parm))
3778 RTX_UNCHANGING_P (stack_parm) = 1;
3780 /* Handle calls that pass values in multiple non-contiguous
3781 locations. The Irix 6 ABI has examples of this. */
3782 if (GET_CODE (entry_parm) == PARALLEL)
3783 emit_group_store (validize_mem (stack_parm), entry_parm);
3784 else
3785 move_block_from_reg (REGNO (entry_parm),
3786 validize_mem (stack_parm),
3787 size_stored / UNITS_PER_WORD,
3788 int_size_in_bytes (TREE_TYPE (parm)));
3790 DECL_RTL (parm) = stack_parm;
3792 else if (! ((obey_regdecls && ! DECL_REGISTER (parm)
3793 && ! DECL_INLINE (fndecl))
3794 /* layout_decl may set this. */
3795 || TREE_ADDRESSABLE (parm)
3796 || TREE_SIDE_EFFECTS (parm)
3797 /* If -ffloat-store specified, don't put explicit
3798 float variables into registers. */
3799 || (flag_float_store
3800 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
3801 /* Always assign pseudo to structure return or item passed
3802 by invisible reference. */
3803 || passed_pointer || parm == function_result_decl)
3805 /* Store the parm in a pseudoregister during the function, but we
3806 may need to do it in a wider mode. */
3808 register rtx parmreg;
3809 int regno, regnoi, regnor;
3811 unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
3813 promoted_nominal_mode
3814 = promote_mode (TREE_TYPE (parm), nominal_mode, &unsignedp, 0);
3816 parmreg = gen_reg_rtx (promoted_nominal_mode);
3817 mark_user_reg (parmreg);
3819 /* If this was an item that we received a pointer to, set DECL_RTL
3820 appropriately. */
3821 if (passed_pointer)
3823 DECL_RTL (parm)
3824 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (passed_type)), parmreg);
3825 MEM_IN_STRUCT_P (DECL_RTL (parm)) = aggregate;
3827 else
3828 DECL_RTL (parm) = parmreg;
3830 /* Copy the value into the register. */
3831 if (nominal_mode != passed_mode
3832 || promoted_nominal_mode != promoted_mode)
3834 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
3835 mode, by the caller. We now have to convert it to
3836 NOMINAL_MODE, if different. However, PARMREG may be in
3837 a diffent mode than NOMINAL_MODE if it is being stored
3838 promoted.
3840 If ENTRY_PARM is a hard register, it might be in a register
3841 not valid for operating in its mode (e.g., an odd-numbered
3842 register for a DFmode). In that case, moves are the only
3843 thing valid, so we can't do a convert from there. This
3844 occurs when the calling sequence allow such misaligned
3845 usages.
3847 In addition, the conversion may involve a call, which could
3848 clobber parameters which haven't been copied to pseudo
3849 registers yet. Therefore, we must first copy the parm to
3850 a pseudo reg here, and save the conversion until after all
3851 parameters have been moved. */
3853 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
3855 emit_move_insn (tempreg, validize_mem (entry_parm));
3857 push_to_sequence (conversion_insns);
3858 tempreg = convert_to_mode (nominal_mode, tempreg, unsignedp);
3860 expand_assignment (parm,
3861 make_tree (nominal_type, tempreg), 0, 0);
3862 conversion_insns = get_insns ();
3863 did_conversion = 1;
3864 end_sequence ();
3866 else
3867 emit_move_insn (parmreg, validize_mem (entry_parm));
3869 /* If we were passed a pointer but the actual value
3870 can safely live in a register, put it in one. */
3871 if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
3872 && ! ((obey_regdecls && ! DECL_REGISTER (parm)
3873 && ! DECL_INLINE (fndecl))
3874 /* layout_decl may set this. */
3875 || TREE_ADDRESSABLE (parm)
3876 || TREE_SIDE_EFFECTS (parm)
3877 /* If -ffloat-store specified, don't put explicit
3878 float variables into registers. */
3879 || (flag_float_store
3880 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))
3882 /* We can't use nominal_mode, because it will have been set to
3883 Pmode above. We must use the actual mode of the parm. */
3884 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
3885 mark_user_reg (parmreg);
3886 emit_move_insn (parmreg, DECL_RTL (parm));
3887 DECL_RTL (parm) = parmreg;
3888 /* STACK_PARM is the pointer, not the parm, and PARMREG is
3889 now the parm. */
3890 stack_parm = 0;
3892 #ifdef FUNCTION_ARG_CALLEE_COPIES
3893 /* If we are passed an arg by reference and it is our responsibility
3894 to make a copy, do it now.
3895 PASSED_TYPE and PASSED mode now refer to the pointer, not the
3896 original argument, so we must recreate them in the call to
3897 FUNCTION_ARG_CALLEE_COPIES. */
3898 /* ??? Later add code to handle the case that if the argument isn't
3899 modified, don't do the copy. */
3901 else if (passed_pointer
3902 && FUNCTION_ARG_CALLEE_COPIES (args_so_far,
3903 TYPE_MODE (DECL_ARG_TYPE (parm)),
3904 DECL_ARG_TYPE (parm),
3905 ! last_named)
3906 && ! TREE_ADDRESSABLE (DECL_ARG_TYPE (parm)))
3908 rtx copy;
3909 tree type = DECL_ARG_TYPE (parm);
3911 /* This sequence may involve a library call perhaps clobbering
3912 registers that haven't been copied to pseudos yet. */
3914 push_to_sequence (conversion_insns);
3916 if (TYPE_SIZE (type) == 0
3917 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
3918 /* This is a variable sized object. */
3919 copy = gen_rtx (MEM, BLKmode,
3920 allocate_dynamic_stack_space
3921 (expr_size (parm), NULL_RTX,
3922 TYPE_ALIGN (type)));
3923 else
3924 copy = assign_stack_temp (TYPE_MODE (type),
3925 int_size_in_bytes (type), 1);
3926 MEM_IN_STRUCT_P (copy) = AGGREGATE_TYPE_P (type);
3928 store_expr (parm, copy, 0);
3929 emit_move_insn (parmreg, XEXP (copy, 0));
3930 if (flag_check_memory_usage)
3931 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
3932 XEXP (copy, 0), ptr_mode,
3933 GEN_INT (int_size_in_bytes (type)),
3934 TYPE_MODE (sizetype),
3935 GEN_INT (MEMORY_USE_RW), QImode);
3936 conversion_insns = get_insns ();
3937 did_conversion = 1;
3938 end_sequence ();
3940 #endif /* FUNCTION_ARG_CALLEE_COPIES */
3942 /* In any case, record the parm's desired stack location
3943 in case we later discover it must live in the stack.
3945 If it is a COMPLEX value, store the stack location for both
3946 halves. */
3948 if (GET_CODE (parmreg) == CONCAT)
3949 regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1)));
3950 else
3951 regno = REGNO (parmreg);
3953 if (regno >= nparmregs)
3955 rtx *new;
3956 int old_nparmregs = nparmregs;
3958 nparmregs = regno + 5;
3959 new = (rtx *) oballoc (nparmregs * sizeof (rtx));
3960 bcopy ((char *) parm_reg_stack_loc, (char *) new,
3961 old_nparmregs * sizeof (rtx));
3962 bzero ((char *) (new + old_nparmregs),
3963 (nparmregs - old_nparmregs) * sizeof (rtx));
3964 parm_reg_stack_loc = new;
3967 if (GET_CODE (parmreg) == CONCAT)
3969 enum machine_mode submode = GET_MODE (XEXP (parmreg, 0));
3971 regnor = REGNO (gen_realpart (submode, parmreg));
3972 regnoi = REGNO (gen_imagpart (submode, parmreg));
3974 if (stack_parm != 0)
3976 parm_reg_stack_loc[regnor]
3977 = gen_realpart (submode, stack_parm);
3978 parm_reg_stack_loc[regnoi]
3979 = gen_imagpart (submode, stack_parm);
3981 else
3983 parm_reg_stack_loc[regnor] = 0;
3984 parm_reg_stack_loc[regnoi] = 0;
3987 else
3988 parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
3990 /* Mark the register as eliminable if we did no conversion
3991 and it was copied from memory at a fixed offset,
3992 and the arg pointer was not copied to a pseudo-reg.
3993 If the arg pointer is a pseudo reg or the offset formed
3994 an invalid address, such memory-equivalences
3995 as we make here would screw up life analysis for it. */
3996 if (nominal_mode == passed_mode
3997 && ! did_conversion
3998 && stack_parm != 0
3999 && GET_CODE (stack_parm) == MEM
4000 && stack_offset.var == 0
4001 && reg_mentioned_p (virtual_incoming_args_rtx,
4002 XEXP (stack_parm, 0)))
4004 rtx linsn = get_last_insn ();
4005 rtx sinsn, set;
4007 /* Mark complex types separately. */
4008 if (GET_CODE (parmreg) == CONCAT)
4009 /* Scan backwards for the set of the real and
4010 imaginary parts. */
4011 for (sinsn = linsn; sinsn != 0;
4012 sinsn = prev_nonnote_insn (sinsn))
4014 set = single_set (sinsn);
4015 if (set != 0
4016 && SET_DEST (set) == regno_reg_rtx [regnoi])
4017 REG_NOTES (sinsn)
4018 = gen_rtx (EXPR_LIST, REG_EQUIV,
4019 parm_reg_stack_loc[regnoi],
4020 REG_NOTES (sinsn));
4021 else if (set != 0
4022 && SET_DEST (set) == regno_reg_rtx [regnor])
4023 REG_NOTES (sinsn)
4024 = gen_rtx (EXPR_LIST, REG_EQUIV,
4025 parm_reg_stack_loc[regnor],
4026 REG_NOTES (sinsn));
4028 else if ((set = single_set (linsn)) != 0
4029 && SET_DEST (set) == parmreg)
4030 REG_NOTES (linsn)
4031 = gen_rtx (EXPR_LIST, REG_EQUIV,
4032 stack_parm, REG_NOTES (linsn));
4035 /* For pointer data type, suggest pointer register. */
4036 if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE)
4037 mark_reg_pointer (parmreg,
4038 (TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm)))
4039 / BITS_PER_UNIT));
4041 else
4043 /* Value must be stored in the stack slot STACK_PARM
4044 during function execution. */
4046 if (promoted_mode != nominal_mode)
4048 /* Conversion is required. */
4049 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
4051 emit_move_insn (tempreg, validize_mem (entry_parm));
4053 push_to_sequence (conversion_insns);
4054 entry_parm = convert_to_mode (nominal_mode, tempreg,
4055 TREE_UNSIGNED (TREE_TYPE (parm)));
4056 if (stack_parm)
4058 /* ??? This may need a big-endian conversion on sparc64. */
4059 stack_parm = change_address (stack_parm, nominal_mode,
4060 NULL_RTX);
4062 conversion_insns = get_insns ();
4063 did_conversion = 1;
4064 end_sequence ();
4067 if (entry_parm != stack_parm)
4069 if (stack_parm == 0)
4071 stack_parm
4072 = assign_stack_local (GET_MODE (entry_parm),
4073 GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
4074 /* If this is a memory ref that contains aggregate components,
4075 mark it as such for cse and loop optimize. */
4076 MEM_IN_STRUCT_P (stack_parm) = aggregate;
4079 if (promoted_mode != nominal_mode)
4081 push_to_sequence (conversion_insns);
4082 emit_move_insn (validize_mem (stack_parm),
4083 validize_mem (entry_parm));
4084 conversion_insns = get_insns ();
4085 end_sequence ();
4087 else
4088 emit_move_insn (validize_mem (stack_parm),
4089 validize_mem (entry_parm));
4091 if (flag_check_memory_usage)
4093 push_to_sequence (conversion_insns);
4094 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
4095 XEXP (stack_parm, 0), ptr_mode,
4096 GEN_INT (GET_MODE_SIZE (GET_MODE
4097 (entry_parm))),
4098 TYPE_MODE (sizetype),
4099 GEN_INT (MEMORY_USE_RW), QImode);
4101 conversion_insns = get_insns ();
4102 end_sequence ();
4104 DECL_RTL (parm) = stack_parm;
4107 /* If this "parameter" was the place where we are receiving the
4108 function's incoming structure pointer, set up the result. */
4109 if (parm == function_result_decl)
4111 tree result = DECL_RESULT (fndecl);
4112 tree restype = TREE_TYPE (result);
4114 DECL_RTL (result)
4115 = gen_rtx (MEM, DECL_MODE (result), DECL_RTL (parm));
4117 MEM_IN_STRUCT_P (DECL_RTL (result)) = AGGREGATE_TYPE_P (restype);
4120 if (TREE_THIS_VOLATILE (parm))
4121 MEM_VOLATILE_P (DECL_RTL (parm)) = 1;
4122 if (TREE_READONLY (parm))
4123 RTX_UNCHANGING_P (DECL_RTL (parm)) = 1;
4126 /* Output all parameter conversion instructions (possibly including calls)
4127 now that all parameters have been copied out of hard registers. */
4128 emit_insns (conversion_insns);
4130 max_parm_reg = max_reg_num ();
4131 last_parm_insn = get_last_insn ();
4133 current_function_args_size = stack_args_size.constant;
4135 /* Adjust function incoming argument size for alignment and
4136 minimum length. */
4138 #ifdef REG_PARM_STACK_SPACE
4139 #ifndef MAYBE_REG_PARM_STACK_SPACE
4140 current_function_args_size = MAX (current_function_args_size,
4141 REG_PARM_STACK_SPACE (fndecl));
4142 #endif
4143 #endif
4145 #ifdef STACK_BOUNDARY
4146 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
4148 current_function_args_size
4149 = ((current_function_args_size + STACK_BYTES - 1)
4150 / STACK_BYTES) * STACK_BYTES;
4151 #endif
4153 #ifdef ARGS_GROW_DOWNWARD
4154 current_function_arg_offset_rtx
4155 = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
4156 : expand_expr (size_binop (MINUS_EXPR, stack_args_size.var,
4157 size_int (-stack_args_size.constant)),
4158 NULL_RTX, VOIDmode, EXPAND_MEMORY_USE_BAD));
4159 #else
4160 current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
4161 #endif
4163 /* See how many bytes, if any, of its args a function should try to pop
4164 on return. */
4166 current_function_pops_args = RETURN_POPS_ARGS (fndecl, TREE_TYPE (fndecl),
4167 current_function_args_size);
4169 /* For stdarg.h function, save info about
4170 regs and stack space used by the named args. */
4172 if (!hide_last_arg)
4173 current_function_args_info = args_so_far;
4175 /* Set the rtx used for the function return value. Put this in its
4176 own variable so any optimizers that need this information don't have
4177 to include tree.h. Do this here so it gets done when an inlined
4178 function gets output. */
4180 current_function_return_rtx = DECL_RTL (DECL_RESULT (fndecl));
4183 /* Indicate whether REGNO is an incoming argument to the current function
4184 that was promoted to a wider mode. If so, return the RTX for the
4185 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
4186 that REGNO is promoted from and whether the promotion was signed or
4187 unsigned. */
4189 #ifdef PROMOTE_FUNCTION_ARGS
4192 promoted_input_arg (regno, pmode, punsignedp)
4193 int regno;
4194 enum machine_mode *pmode;
4195 int *punsignedp;
4197 tree arg;
4199 for (arg = DECL_ARGUMENTS (current_function_decl); arg;
4200 arg = TREE_CHAIN (arg))
4201 if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
4202 && REGNO (DECL_INCOMING_RTL (arg)) == regno
4203 && TYPE_MODE (DECL_ARG_TYPE (arg)) == TYPE_MODE (TREE_TYPE (arg)))
4205 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
4206 int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
4208 mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1);
4209 if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
4210 && mode != DECL_MODE (arg))
4212 *pmode = DECL_MODE (arg);
4213 *punsignedp = unsignedp;
4214 return DECL_INCOMING_RTL (arg);
4218 return 0;
4221 #endif
4223 /* Compute the size and offset from the start of the stacked arguments for a
4224 parm passed in mode PASSED_MODE and with type TYPE.
4226 INITIAL_OFFSET_PTR points to the current offset into the stacked
4227 arguments.
4229 The starting offset and size for this parm are returned in *OFFSET_PTR
4230 and *ARG_SIZE_PTR, respectively.
4232 IN_REGS is non-zero if the argument will be passed in registers. It will
4233 never be set if REG_PARM_STACK_SPACE is not defined.
4235 FNDECL is the function in which the argument was defined.
4237 There are two types of rounding that are done. The first, controlled by
4238 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
4239 list to be aligned to the specific boundary (in bits). This rounding
4240 affects the initial and starting offsets, but not the argument size.
4242 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
4243 optionally rounds the size of the parm to PARM_BOUNDARY. The
4244 initial offset is not affected by this rounding, while the size always
4245 is and the starting offset may be. */
4247 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
4248 initial_offset_ptr is positive because locate_and_pad_parm's
4249 callers pass in the total size of args so far as
4250 initial_offset_ptr. arg_size_ptr is always positive.*/
4252 void
4253 locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
4254 initial_offset_ptr, offset_ptr, arg_size_ptr)
4255 enum machine_mode passed_mode;
4256 tree type;
4257 int in_regs;
4258 tree fndecl;
4259 struct args_size *initial_offset_ptr;
4260 struct args_size *offset_ptr;
4261 struct args_size *arg_size_ptr;
4263 tree sizetree
4264 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
4265 enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
4266 int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
4267 int boundary_in_bytes = boundary / BITS_PER_UNIT;
4268 int reg_parm_stack_space = 0;
4270 #ifdef REG_PARM_STACK_SPACE
4271 /* If we have found a stack parm before we reach the end of the
4272 area reserved for registers, skip that area. */
4273 if (! in_regs)
4275 #ifdef MAYBE_REG_PARM_STACK_SPACE
4276 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
4277 #else
4278 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
4279 #endif
4280 if (reg_parm_stack_space > 0)
4282 if (initial_offset_ptr->var)
4284 initial_offset_ptr->var
4285 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
4286 size_int (reg_parm_stack_space));
4287 initial_offset_ptr->constant = 0;
4289 else if (initial_offset_ptr->constant < reg_parm_stack_space)
4290 initial_offset_ptr->constant = reg_parm_stack_space;
4293 #endif /* REG_PARM_STACK_SPACE */
4295 arg_size_ptr->var = 0;
4296 arg_size_ptr->constant = 0;
4298 #ifdef ARGS_GROW_DOWNWARD
4299 if (initial_offset_ptr->var)
4301 offset_ptr->constant = 0;
4302 offset_ptr->var = size_binop (MINUS_EXPR, integer_zero_node,
4303 initial_offset_ptr->var);
4305 else
4307 offset_ptr->constant = - initial_offset_ptr->constant;
4308 offset_ptr->var = 0;
4310 if (where_pad != none
4311 && (TREE_CODE (sizetree) != INTEGER_CST
4312 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
4313 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4314 SUB_PARM_SIZE (*offset_ptr, sizetree);
4315 if (where_pad != downward)
4316 pad_to_arg_alignment (offset_ptr, boundary);
4317 if (initial_offset_ptr->var)
4319 arg_size_ptr->var = size_binop (MINUS_EXPR,
4320 size_binop (MINUS_EXPR,
4321 integer_zero_node,
4322 initial_offset_ptr->var),
4323 offset_ptr->var);
4325 else
4327 arg_size_ptr->constant = (- initial_offset_ptr->constant
4328 - offset_ptr->constant);
4330 #else /* !ARGS_GROW_DOWNWARD */
4331 pad_to_arg_alignment (initial_offset_ptr, boundary);
4332 *offset_ptr = *initial_offset_ptr;
4334 #ifdef PUSH_ROUNDING
4335 if (passed_mode != BLKmode)
4336 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
4337 #endif
4339 /* Pad_below needs the pre-rounded size to know how much to pad below
4340 so this must be done before rounding up. */
4341 if (where_pad == downward
4342 /* However, BLKmode args passed in regs have their padding done elsewhere.
4343 The stack slot must be able to hold the entire register. */
4344 && !(in_regs && passed_mode == BLKmode))
4345 pad_below (offset_ptr, passed_mode, sizetree);
4347 if (where_pad != none
4348 && (TREE_CODE (sizetree) != INTEGER_CST
4349 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
4350 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4352 ADD_PARM_SIZE (*arg_size_ptr, sizetree);
4353 #endif /* ARGS_GROW_DOWNWARD */
4356 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
4357 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
4359 static void
4360 pad_to_arg_alignment (offset_ptr, boundary)
4361 struct args_size *offset_ptr;
4362 int boundary;
4364 int boundary_in_bytes = boundary / BITS_PER_UNIT;
4366 if (boundary > BITS_PER_UNIT)
4368 if (offset_ptr->var)
4370 offset_ptr->var =
4371 #ifdef ARGS_GROW_DOWNWARD
4372 round_down
4373 #else
4374 round_up
4375 #endif
4376 (ARGS_SIZE_TREE (*offset_ptr),
4377 boundary / BITS_PER_UNIT);
4378 offset_ptr->constant = 0; /*?*/
4380 else
4381 offset_ptr->constant =
4382 #ifdef ARGS_GROW_DOWNWARD
4383 FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes);
4384 #else
4385 CEIL_ROUND (offset_ptr->constant, boundary_in_bytes);
4386 #endif
4390 static void
4391 pad_below (offset_ptr, passed_mode, sizetree)
4392 struct args_size *offset_ptr;
4393 enum machine_mode passed_mode;
4394 tree sizetree;
4396 if (passed_mode != BLKmode)
4398 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
4399 offset_ptr->constant
4400 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
4401 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
4402 - GET_MODE_SIZE (passed_mode));
4404 else
4406 if (TREE_CODE (sizetree) != INTEGER_CST
4407 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
4409 /* Round the size up to multiple of PARM_BOUNDARY bits. */
4410 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4411 /* Add it in. */
4412 ADD_PARM_SIZE (*offset_ptr, s2);
4413 SUB_PARM_SIZE (*offset_ptr, sizetree);
4418 static tree
4419 round_down (value, divisor)
4420 tree value;
4421 int divisor;
4423 return size_binop (MULT_EXPR,
4424 size_binop (FLOOR_DIV_EXPR, value, size_int (divisor)),
4425 size_int (divisor));
4428 /* Walk the tree of blocks describing the binding levels within a function
4429 and warn about uninitialized variables.
4430 This is done after calling flow_analysis and before global_alloc
4431 clobbers the pseudo-regs to hard regs. */
4433 void
4434 uninitialized_vars_warning (block)
4435 tree block;
4437 register tree decl, sub;
4438 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
4440 if (TREE_CODE (decl) == VAR_DECL
4441 /* These warnings are unreliable for and aggregates
4442 because assigning the fields one by one can fail to convince
4443 flow.c that the entire aggregate was initialized.
4444 Unions are troublesome because members may be shorter. */
4445 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl))
4446 && DECL_RTL (decl) != 0
4447 && GET_CODE (DECL_RTL (decl)) == REG
4448 && regno_uninitialized (REGNO (DECL_RTL (decl))))
4449 warning_with_decl (decl,
4450 "`%s' might be used uninitialized in this function");
4451 if (TREE_CODE (decl) == VAR_DECL
4452 && DECL_RTL (decl) != 0
4453 && GET_CODE (DECL_RTL (decl)) == REG
4454 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
4455 warning_with_decl (decl,
4456 "variable `%s' might be clobbered by `longjmp' or `vfork'");
4458 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
4459 uninitialized_vars_warning (sub);
4462 /* Do the appropriate part of uninitialized_vars_warning
4463 but for arguments instead of local variables. */
4465 void
4466 setjmp_args_warning ()
4468 register tree decl;
4469 for (decl = DECL_ARGUMENTS (current_function_decl);
4470 decl; decl = TREE_CHAIN (decl))
4471 if (DECL_RTL (decl) != 0
4472 && GET_CODE (DECL_RTL (decl)) == REG
4473 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
4474 warning_with_decl (decl, "argument `%s' might be clobbered by `longjmp' or `vfork'");
4477 /* If this function call setjmp, put all vars into the stack
4478 unless they were declared `register'. */
4480 void
4481 setjmp_protect (block)
4482 tree block;
4484 register tree decl, sub;
4485 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
4486 if ((TREE_CODE (decl) == VAR_DECL
4487 || TREE_CODE (decl) == PARM_DECL)
4488 && DECL_RTL (decl) != 0
4489 && GET_CODE (DECL_RTL (decl)) == REG
4490 /* If this variable came from an inline function, it must be
4491 that it's life doesn't overlap the setjmp. If there was a
4492 setjmp in the function, it would already be in memory. We
4493 must exclude such variable because their DECL_RTL might be
4494 set to strange things such as virtual_stack_vars_rtx. */
4495 && ! DECL_FROM_INLINE (decl)
4496 && (
4497 #ifdef NON_SAVING_SETJMP
4498 /* If longjmp doesn't restore the registers,
4499 don't put anything in them. */
4500 NON_SAVING_SETJMP
4502 #endif
4503 ! DECL_REGISTER (decl)))
4504 put_var_into_stack (decl);
4505 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
4506 setjmp_protect (sub);
4509 /* Like the previous function, but for args instead of local variables. */
4511 void
4512 setjmp_protect_args ()
4514 register tree decl, sub;
4515 for (decl = DECL_ARGUMENTS (current_function_decl);
4516 decl; decl = TREE_CHAIN (decl))
4517 if ((TREE_CODE (decl) == VAR_DECL
4518 || TREE_CODE (decl) == PARM_DECL)
4519 && DECL_RTL (decl) != 0
4520 && GET_CODE (DECL_RTL (decl)) == REG
4521 && (
4522 /* If longjmp doesn't restore the registers,
4523 don't put anything in them. */
4524 #ifdef NON_SAVING_SETJMP
4525 NON_SAVING_SETJMP
4527 #endif
4528 ! DECL_REGISTER (decl)))
4529 put_var_into_stack (decl);
4532 /* Return the context-pointer register corresponding to DECL,
4533 or 0 if it does not need one. */
4536 lookup_static_chain (decl)
4537 tree decl;
4539 tree context = decl_function_context (decl);
4540 tree link;
4542 if (context == 0
4543 || (TREE_CODE (decl) == FUNCTION_DECL && DECL_NO_STATIC_CHAIN (decl)))
4544 return 0;
4546 /* We treat inline_function_decl as an alias for the current function
4547 because that is the inline function whose vars, types, etc.
4548 are being merged into the current function.
4549 See expand_inline_function. */
4550 if (context == current_function_decl || context == inline_function_decl)
4551 return virtual_stack_vars_rtx;
4553 for (link = context_display; link; link = TREE_CHAIN (link))
4554 if (TREE_PURPOSE (link) == context)
4555 return RTL_EXPR_RTL (TREE_VALUE (link));
4557 abort ();
4560 /* Convert a stack slot address ADDR for variable VAR
4561 (from a containing function)
4562 into an address valid in this function (using a static chain). */
4565 fix_lexical_addr (addr, var)
4566 rtx addr;
4567 tree var;
4569 rtx basereg;
4570 int displacement;
4571 tree context = decl_function_context (var);
4572 struct function *fp;
4573 rtx base = 0;
4575 /* If this is the present function, we need not do anything. */
4576 if (context == current_function_decl || context == inline_function_decl)
4577 return addr;
4579 for (fp = outer_function_chain; fp; fp = fp->next)
4580 if (fp->decl == context)
4581 break;
4583 if (fp == 0)
4584 abort ();
4586 /* Decode given address as base reg plus displacement. */
4587 if (GET_CODE (addr) == REG)
4588 basereg = addr, displacement = 0;
4589 else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
4590 basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
4591 else
4592 abort ();
4594 /* We accept vars reached via the containing function's
4595 incoming arg pointer and via its stack variables pointer. */
4596 if (basereg == fp->internal_arg_pointer)
4598 /* If reached via arg pointer, get the arg pointer value
4599 out of that function's stack frame.
4601 There are two cases: If a separate ap is needed, allocate a
4602 slot in the outer function for it and dereference it that way.
4603 This is correct even if the real ap is actually a pseudo.
4604 Otherwise, just adjust the offset from the frame pointer to
4605 compensate. */
4607 #ifdef NEED_SEPARATE_AP
4608 rtx addr;
4610 if (fp->arg_pointer_save_area == 0)
4611 fp->arg_pointer_save_area
4612 = assign_outer_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0, fp);
4614 addr = fix_lexical_addr (XEXP (fp->arg_pointer_save_area, 0), var);
4615 addr = memory_address (Pmode, addr);
4617 base = copy_to_reg (gen_rtx (MEM, Pmode, addr));
4618 #else
4619 displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
4620 base = lookup_static_chain (var);
4621 #endif
4624 else if (basereg == virtual_stack_vars_rtx)
4626 /* This is the same code as lookup_static_chain, duplicated here to
4627 avoid an extra call to decl_function_context. */
4628 tree link;
4630 for (link = context_display; link; link = TREE_CHAIN (link))
4631 if (TREE_PURPOSE (link) == context)
4633 base = RTL_EXPR_RTL (TREE_VALUE (link));
4634 break;
4638 if (base == 0)
4639 abort ();
4641 /* Use same offset, relative to appropriate static chain or argument
4642 pointer. */
4643 return plus_constant (base, displacement);
4646 /* Return the address of the trampoline for entering nested fn FUNCTION.
4647 If necessary, allocate a trampoline (in the stack frame)
4648 and emit rtl to initialize its contents (at entry to this function). */
4651 trampoline_address (function)
4652 tree function;
4654 tree link;
4655 tree rtlexp;
4656 rtx tramp;
4657 struct function *fp;
4658 tree fn_context;
4660 /* Find an existing trampoline and return it. */
4661 for (link = trampoline_list; link; link = TREE_CHAIN (link))
4662 if (TREE_PURPOSE (link) == function)
4663 return
4664 round_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0));
4666 for (fp = outer_function_chain; fp; fp = fp->next)
4667 for (link = fp->trampoline_list; link; link = TREE_CHAIN (link))
4668 if (TREE_PURPOSE (link) == function)
4670 tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
4671 function);
4672 return round_trampoline_addr (tramp);
4675 /* None exists; we must make one. */
4677 /* Find the `struct function' for the function containing FUNCTION. */
4678 fp = 0;
4679 fn_context = decl_function_context (function);
4680 if (fn_context != current_function_decl
4681 && fn_context != inline_function_decl)
4682 for (fp = outer_function_chain; fp; fp = fp->next)
4683 if (fp->decl == fn_context)
4684 break;
4686 /* Allocate run-time space for this trampoline
4687 (usually in the defining function's stack frame). */
4688 #ifdef ALLOCATE_TRAMPOLINE
4689 tramp = ALLOCATE_TRAMPOLINE (fp);
4690 #else
4691 /* If rounding needed, allocate extra space
4692 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
4693 #ifdef TRAMPOLINE_ALIGNMENT
4694 #define TRAMPOLINE_REAL_SIZE \
4695 (TRAMPOLINE_SIZE + (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT) - 1)
4696 #else
4697 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
4698 #endif
4699 if (fp != 0)
4700 tramp = assign_outer_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0, fp);
4701 else
4702 tramp = assign_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0);
4703 #endif
4705 /* Record the trampoline for reuse and note it for later initialization
4706 by expand_function_end. */
4707 if (fp != 0)
4709 push_obstacks (fp->function_maybepermanent_obstack,
4710 fp->function_maybepermanent_obstack);
4711 rtlexp = make_node (RTL_EXPR);
4712 RTL_EXPR_RTL (rtlexp) = tramp;
4713 fp->trampoline_list = tree_cons (function, rtlexp, fp->trampoline_list);
4714 pop_obstacks ();
4716 else
4718 /* Make the RTL_EXPR node temporary, not momentary, so that the
4719 trampoline_list doesn't become garbage. */
4720 int momentary = suspend_momentary ();
4721 rtlexp = make_node (RTL_EXPR);
4722 resume_momentary (momentary);
4724 RTL_EXPR_RTL (rtlexp) = tramp;
4725 trampoline_list = tree_cons (function, rtlexp, trampoline_list);
4728 tramp = fix_lexical_addr (XEXP (tramp, 0), function);
4729 return round_trampoline_addr (tramp);
4732 /* Given a trampoline address,
4733 round it to multiple of TRAMPOLINE_ALIGNMENT. */
4735 static rtx
4736 round_trampoline_addr (tramp)
4737 rtx tramp;
4739 #ifdef TRAMPOLINE_ALIGNMENT
4740 /* Round address up to desired boundary. */
4741 rtx temp = gen_reg_rtx (Pmode);
4742 temp = expand_binop (Pmode, add_optab, tramp,
4743 GEN_INT (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT - 1),
4744 temp, 0, OPTAB_LIB_WIDEN);
4745 tramp = expand_binop (Pmode, and_optab, temp,
4746 GEN_INT (- TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT),
4747 temp, 0, OPTAB_LIB_WIDEN);
4748 #endif
4749 return tramp;
4752 /* The functions identify_blocks and reorder_blocks provide a way to
4753 reorder the tree of BLOCK nodes, for optimizers that reshuffle or
4754 duplicate portions of the RTL code. Call identify_blocks before
4755 changing the RTL, and call reorder_blocks after. */
4757 /* Put all this function's BLOCK nodes including those that are chained
4758 onto the first block into a vector, and return it.
4759 Also store in each NOTE for the beginning or end of a block
4760 the index of that block in the vector.
4761 The arguments are BLOCK, the chain of top-level blocks of the function,
4762 and INSNS, the insn chain of the function. */
4764 tree *
4765 identify_blocks (block, insns)
4766 tree block;
4767 rtx insns;
4769 int n_blocks;
4770 tree *block_vector;
4771 int *block_stack;
4772 int depth = 0;
4773 int next_block_number = 1;
4774 int current_block_number = 1;
4775 rtx insn;
4777 if (block == 0)
4778 return 0;
4780 n_blocks = all_blocks (block, 0);
4781 block_vector = (tree *) xmalloc (n_blocks * sizeof (tree));
4782 block_stack = (int *) alloca (n_blocks * sizeof (int));
4784 all_blocks (block, block_vector);
4786 for (insn = insns; insn; insn = NEXT_INSN (insn))
4787 if (GET_CODE (insn) == NOTE)
4789 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
4791 block_stack[depth++] = current_block_number;
4792 current_block_number = next_block_number;
4793 NOTE_BLOCK_NUMBER (insn) = next_block_number++;
4795 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
4797 current_block_number = block_stack[--depth];
4798 NOTE_BLOCK_NUMBER (insn) = current_block_number;
4802 if (n_blocks != next_block_number)
4803 abort ();
4805 return block_vector;
4808 /* Given BLOCK_VECTOR which was returned by identify_blocks,
4809 and a revised instruction chain, rebuild the tree structure
4810 of BLOCK nodes to correspond to the new order of RTL.
4811 The new block tree is inserted below TOP_BLOCK.
4812 Returns the current top-level block. */
4814 tree
4815 reorder_blocks (block_vector, block, insns)
4816 tree *block_vector;
4817 tree block;
4818 rtx insns;
4820 tree current_block = block;
4821 rtx insn;
4823 if (block_vector == 0)
4824 return block;
4826 /* Prune the old trees away, so that it doesn't get in the way. */
4827 BLOCK_SUBBLOCKS (current_block) = 0;
4828 BLOCK_CHAIN (current_block) = 0;
4830 for (insn = insns; insn; insn = NEXT_INSN (insn))
4831 if (GET_CODE (insn) == NOTE)
4833 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
4835 tree block = block_vector[NOTE_BLOCK_NUMBER (insn)];
4836 /* If we have seen this block before, copy it. */
4837 if (TREE_ASM_WRITTEN (block))
4838 block = copy_node (block);
4839 BLOCK_SUBBLOCKS (block) = 0;
4840 TREE_ASM_WRITTEN (block) = 1;
4841 BLOCK_SUPERCONTEXT (block) = current_block;
4842 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
4843 BLOCK_SUBBLOCKS (current_block) = block;
4844 current_block = block;
4845 NOTE_SOURCE_FILE (insn) = 0;
4847 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
4849 BLOCK_SUBBLOCKS (current_block)
4850 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
4851 current_block = BLOCK_SUPERCONTEXT (current_block);
4852 NOTE_SOURCE_FILE (insn) = 0;
4856 BLOCK_SUBBLOCKS (current_block)
4857 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
4858 return current_block;
4861 /* Reverse the order of elements in the chain T of blocks,
4862 and return the new head of the chain (old last element). */
4864 static tree
4865 blocks_nreverse (t)
4866 tree t;
4868 register tree prev = 0, decl, next;
4869 for (decl = t; decl; decl = next)
4871 next = BLOCK_CHAIN (decl);
4872 BLOCK_CHAIN (decl) = prev;
4873 prev = decl;
4875 return prev;
4878 /* Count the subblocks of the list starting with BLOCK, and list them
4879 all into the vector VECTOR. Also clear TREE_ASM_WRITTEN in all
4880 blocks. */
4882 static int
4883 all_blocks (block, vector)
4884 tree block;
4885 tree *vector;
4887 int n_blocks = 0;
4889 while (block)
4891 TREE_ASM_WRITTEN (block) = 0;
4893 /* Record this block. */
4894 if (vector)
4895 vector[n_blocks] = block;
4897 ++n_blocks;
4899 /* Record the subblocks, and their subblocks... */
4900 n_blocks += all_blocks (BLOCK_SUBBLOCKS (block),
4901 vector ? vector + n_blocks : 0);
4902 block = BLOCK_CHAIN (block);
4905 return n_blocks;
4908 /* Build bytecode call descriptor for function SUBR. */
4911 bc_build_calldesc (subr)
4912 tree subr;
4914 tree calldesc = 0, arg;
4915 int nargs = 0;
4917 /* Build the argument description vector in reverse order. */
4918 DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
4919 nargs = 0;
4921 for (arg = DECL_ARGUMENTS (subr); arg; arg = TREE_CHAIN (arg))
4923 ++nargs;
4925 calldesc = tree_cons ((tree) 0, size_in_bytes (TREE_TYPE (arg)), calldesc);
4926 calldesc = tree_cons ((tree) 0, bc_runtime_type_code (TREE_TYPE (arg)), calldesc);
4929 DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
4931 /* Prepend the function's return type. */
4932 calldesc = tree_cons ((tree) 0,
4933 size_in_bytes (TREE_TYPE (TREE_TYPE (subr))),
4934 calldesc);
4936 calldesc = tree_cons ((tree) 0,
4937 bc_runtime_type_code (TREE_TYPE (TREE_TYPE (subr))),
4938 calldesc);
4940 /* Prepend the arg count. */
4941 calldesc = tree_cons ((tree) 0, build_int_2 (nargs, 0), calldesc);
4943 /* Output the call description vector and get its address. */
4944 calldesc = build_nt (CONSTRUCTOR, (tree) 0, calldesc);
4945 TREE_TYPE (calldesc) = build_array_type (integer_type_node,
4946 build_index_type (build_int_2 (nargs * 2, 0)));
4948 return output_constant_def (calldesc);
4952 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
4953 and initialize static variables for generating RTL for the statements
4954 of the function. */
4956 void
4957 init_function_start (subr, filename, line)
4958 tree subr;
4959 char *filename;
4960 int line;
4962 if (output_bytecode)
4964 this_function_decl = subr;
4965 this_function_calldesc = bc_build_calldesc (subr);
4966 local_vars_size = 0;
4967 stack_depth = 0;
4968 max_stack_depth = 0;
4969 stmt_expr_depth = 0;
4970 return;
4973 init_stmt_for_function ();
4975 cse_not_expected = ! optimize;
4977 /* Caller save not needed yet. */
4978 caller_save_needed = 0;
4980 /* No stack slots have been made yet. */
4981 stack_slot_list = 0;
4983 /* There is no stack slot for handling nonlocal gotos. */
4984 nonlocal_goto_handler_slot = 0;
4985 nonlocal_goto_stack_level = 0;
4987 /* No labels have been declared for nonlocal use. */
4988 nonlocal_labels = 0;
4990 /* No function calls so far in this function. */
4991 function_call_count = 0;
4993 /* No parm regs have been allocated.
4994 (This is important for output_inline_function.) */
4995 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
4997 /* Initialize the RTL mechanism. */
4998 init_emit ();
5000 /* Initialize the queue of pending postincrement and postdecrements,
5001 and some other info in expr.c. */
5002 init_expr ();
5004 /* We haven't done register allocation yet. */
5005 reg_renumber = 0;
5007 init_const_rtx_hash_table ();
5009 current_function_name = (*decl_printable_name) (subr, 2);
5011 /* Nonzero if this is a nested function that uses a static chain. */
5013 current_function_needs_context
5014 = (decl_function_context (current_function_decl) != 0
5015 && ! DECL_NO_STATIC_CHAIN (current_function_decl));
5017 /* Set if a call to setjmp is seen. */
5018 current_function_calls_setjmp = 0;
5020 /* Set if a call to longjmp is seen. */
5021 current_function_calls_longjmp = 0;
5023 current_function_calls_alloca = 0;
5024 current_function_has_nonlocal_label = 0;
5025 current_function_has_nonlocal_goto = 0;
5026 current_function_contains_functions = 0;
5027 current_function_is_thunk = 0;
5029 current_function_returns_pcc_struct = 0;
5030 current_function_returns_struct = 0;
5031 current_function_epilogue_delay_list = 0;
5032 current_function_uses_const_pool = 0;
5033 current_function_uses_pic_offset_table = 0;
5035 /* We have not yet needed to make a label to jump to for tail-recursion. */
5036 tail_recursion_label = 0;
5038 /* We haven't had a need to make a save area for ap yet. */
5040 arg_pointer_save_area = 0;
5042 /* No stack slots allocated yet. */
5043 frame_offset = 0;
5045 /* No SAVE_EXPRs in this function yet. */
5046 save_expr_regs = 0;
5048 /* No RTL_EXPRs in this function yet. */
5049 rtl_expr_chain = 0;
5051 /* Set up to allocate temporaries. */
5052 init_temp_slots ();
5054 /* Within function body, compute a type's size as soon it is laid out. */
5055 immediate_size_expand++;
5057 /* We haven't made any trampolines for this function yet. */
5058 trampoline_list = 0;
5060 init_pending_stack_adjust ();
5061 inhibit_defer_pop = 0;
5063 current_function_outgoing_args_size = 0;
5065 /* Prevent ever trying to delete the first instruction of a function.
5066 Also tell final how to output a linenum before the function prologue. */
5067 emit_line_note (filename, line);
5069 /* Make sure first insn is a note even if we don't want linenums.
5070 This makes sure the first insn will never be deleted.
5071 Also, final expects a note to appear there. */
5072 emit_note (NULL_PTR, NOTE_INSN_DELETED);
5074 /* Set flags used by final.c. */
5075 if (aggregate_value_p (DECL_RESULT (subr)))
5077 #ifdef PCC_STATIC_STRUCT_RETURN
5078 current_function_returns_pcc_struct = 1;
5079 #endif
5080 current_function_returns_struct = 1;
5083 /* Warn if this value is an aggregate type,
5084 regardless of which calling convention we are using for it. */
5085 if (warn_aggregate_return
5086 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
5087 warning ("function returns an aggregate");
5089 current_function_returns_pointer
5090 = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
5092 /* Indicate that we need to distinguish between the return value of the
5093 present function and the return value of a function being called. */
5094 rtx_equal_function_value_matters = 1;
5096 /* Indicate that we have not instantiated virtual registers yet. */
5097 virtuals_instantiated = 0;
5099 /* Indicate we have no need of a frame pointer yet. */
5100 frame_pointer_needed = 0;
5102 /* By default assume not varargs or stdarg. */
5103 current_function_varargs = 0;
5104 current_function_stdarg = 0;
5107 /* Indicate that the current function uses extra args
5108 not explicitly mentioned in the argument list in any fashion. */
5110 void
5111 mark_varargs ()
5113 current_function_varargs = 1;
5116 /* Expand a call to __main at the beginning of a possible main function. */
5118 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
5119 #undef HAS_INIT_SECTION
5120 #define HAS_INIT_SECTION
5121 #endif
5123 void
5124 expand_main_function ()
5126 if (!output_bytecode)
5128 /* The zero below avoids a possible parse error */
5130 #if !defined (HAS_INIT_SECTION)
5131 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, NAME__MAIN), 0,
5132 VOIDmode, 0);
5133 #endif /* not HAS_INIT_SECTION */
5137 extern struct obstack permanent_obstack;
5139 /* Expand start of bytecode function. See comment at
5140 expand_function_start below for details. */
5142 void
5143 bc_expand_function_start (subr, parms_have_cleanups)
5144 tree subr;
5145 int parms_have_cleanups;
5147 char label[20], *name;
5148 static int nlab;
5149 tree thisarg;
5150 int argsz;
5152 if (TREE_PUBLIC (subr))
5153 bc_globalize_label (IDENTIFIER_POINTER (DECL_NAME (subr)));
5155 #ifdef DEBUG_PRINT_CODE
5156 fprintf (stderr, "\n<func %s>\n", IDENTIFIER_POINTER (DECL_NAME (subr)));
5157 #endif
5159 for (argsz = 0, thisarg = DECL_ARGUMENTS (subr); thisarg; thisarg = TREE_CHAIN (thisarg))
5161 if (DECL_RTL (thisarg))
5162 abort (); /* Should be NULL here I think. */
5163 else if (TREE_CONSTANT (DECL_SIZE (thisarg)))
5165 DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
5166 argsz += TREE_INT_CST_LOW (DECL_SIZE (thisarg));
5168 else
5170 /* Variable-sized objects are pointers to their storage. */
5171 DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
5172 argsz += POINTER_SIZE;
5176 bc_begin_function (xstrdup (IDENTIFIER_POINTER (DECL_NAME (subr))));
5178 ASM_GENERATE_INTERNAL_LABEL (label, "LX", nlab);
5180 ++nlab;
5181 name = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
5182 this_function_callinfo = bc_gen_rtx (name, 0, (struct bc_label *) 0);
5183 this_function_bytecode
5184 = bc_emit_trampoline (BYTECODE_LABEL (this_function_callinfo));
5188 /* Expand end of bytecode function. See details the comment of
5189 expand_function_end(), below. */
5191 void
5192 bc_expand_function_end ()
5194 char *ptrconsts;
5196 expand_null_return ();
5198 /* Emit any fixup code. This must be done before the call to
5199 to BC_END_FUNCTION (), since that will cause the bytecode
5200 segment to be finished off and closed. */
5202 expand_fixups (NULL_RTX);
5204 ptrconsts = bc_end_function ();
5206 bc_align_const (2 /* INT_ALIGN */);
5208 /* If this changes also make sure to change bc-interp.h! */
5210 bc_emit_const_labeldef (BYTECODE_LABEL (this_function_callinfo));
5211 bc_emit_const ((char *) &max_stack_depth, sizeof max_stack_depth);
5212 bc_emit_const ((char *) &local_vars_size, sizeof local_vars_size);
5213 bc_emit_const_labelref (this_function_bytecode, 0);
5214 bc_emit_const_labelref (ptrconsts, 0);
5215 bc_emit_const_labelref (BYTECODE_LABEL (this_function_calldesc), 0);
5219 /* Start the RTL for a new function, and set variables used for
5220 emitting RTL.
5221 SUBR is the FUNCTION_DECL node.
5222 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
5223 the function's parameters, which must be run at any return statement. */
5225 void
5226 expand_function_start (subr, parms_have_cleanups)
5227 tree subr;
5228 int parms_have_cleanups;
5230 register int i;
5231 tree tem;
5232 rtx last_ptr;
5234 if (output_bytecode)
5236 bc_expand_function_start (subr, parms_have_cleanups);
5237 return;
5240 /* Make sure volatile mem refs aren't considered
5241 valid operands of arithmetic insns. */
5242 init_recog_no_volatile ();
5244 /* If function gets a static chain arg, store it in the stack frame.
5245 Do this first, so it gets the first stack slot offset. */
5246 if (current_function_needs_context)
5248 last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
5250 #ifdef SMALL_REGISTER_CLASSES
5251 /* Delay copying static chain if it is not a register to avoid
5252 conflicts with regs used for parameters. */
5253 if (! SMALL_REGISTER_CLASSES
5254 || GET_CODE (static_chain_incoming_rtx) == REG)
5255 #endif
5256 emit_move_insn (last_ptr, static_chain_incoming_rtx);
5259 /* If the parameters of this function need cleaning up, get a label
5260 for the beginning of the code which executes those cleanups. This must
5261 be done before doing anything with return_label. */
5262 if (parms_have_cleanups)
5263 cleanup_label = gen_label_rtx ();
5264 else
5265 cleanup_label = 0;
5267 /* Make the label for return statements to jump to, if this machine
5268 does not have a one-instruction return and uses an epilogue,
5269 or if it returns a structure, or if it has parm cleanups. */
5270 #ifdef HAVE_return
5271 if (cleanup_label == 0 && HAVE_return
5272 && ! current_function_returns_pcc_struct
5273 && ! (current_function_returns_struct && ! optimize))
5274 return_label = 0;
5275 else
5276 return_label = gen_label_rtx ();
5277 #else
5278 return_label = gen_label_rtx ();
5279 #endif
5281 /* Initialize rtx used to return the value. */
5282 /* Do this before assign_parms so that we copy the struct value address
5283 before any library calls that assign parms might generate. */
5285 /* Decide whether to return the value in memory or in a register. */
5286 if (aggregate_value_p (DECL_RESULT (subr)))
5288 /* Returning something that won't go in a register. */
5289 register rtx value_address = 0;
5291 #ifdef PCC_STATIC_STRUCT_RETURN
5292 if (current_function_returns_pcc_struct)
5294 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
5295 value_address = assemble_static_space (size);
5297 else
5298 #endif
5300 /* Expect to be passed the address of a place to store the value.
5301 If it is passed as an argument, assign_parms will take care of
5302 it. */
5303 if (struct_value_incoming_rtx)
5305 value_address = gen_reg_rtx (Pmode);
5306 emit_move_insn (value_address, struct_value_incoming_rtx);
5309 if (value_address)
5311 DECL_RTL (DECL_RESULT (subr))
5312 = gen_rtx (MEM, DECL_MODE (DECL_RESULT (subr)), value_address);
5313 MEM_IN_STRUCT_P (DECL_RTL (DECL_RESULT (subr)))
5314 = AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
5317 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
5318 /* If return mode is void, this decl rtl should not be used. */
5319 DECL_RTL (DECL_RESULT (subr)) = 0;
5320 else if (parms_have_cleanups)
5322 /* If function will end with cleanup code for parms,
5323 compute the return values into a pseudo reg,
5324 which we will copy into the true return register
5325 after the cleanups are done. */
5327 enum machine_mode mode = DECL_MODE (DECL_RESULT (subr));
5329 #ifdef PROMOTE_FUNCTION_RETURN
5330 tree type = TREE_TYPE (DECL_RESULT (subr));
5331 int unsignedp = TREE_UNSIGNED (type);
5333 mode = promote_mode (type, mode, &unsignedp, 1);
5334 #endif
5336 DECL_RTL (DECL_RESULT (subr)) = gen_reg_rtx (mode);
5338 else
5339 /* Scalar, returned in a register. */
5341 #ifdef FUNCTION_OUTGOING_VALUE
5342 DECL_RTL (DECL_RESULT (subr))
5343 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
5344 #else
5345 DECL_RTL (DECL_RESULT (subr))
5346 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
5347 #endif
5349 /* Mark this reg as the function's return value. */
5350 if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG)
5352 REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1;
5353 /* Needed because we may need to move this to memory
5354 in case it's a named return value whose address is taken. */
5355 DECL_REGISTER (DECL_RESULT (subr)) = 1;
5359 /* Initialize rtx for parameters and local variables.
5360 In some cases this requires emitting insns. */
5362 assign_parms (subr, 0);
5364 #ifdef SMALL_REGISTER_CLASSES
5365 /* Copy the static chain now if it wasn't a register. The delay is to
5366 avoid conflicts with the parameter passing registers. */
5368 if (SMALL_REGISTER_CLASSES && current_function_needs_context)
5369 if (GET_CODE (static_chain_incoming_rtx) != REG)
5370 emit_move_insn (last_ptr, static_chain_incoming_rtx);
5371 #endif
5373 /* The following was moved from init_function_start.
5374 The move is supposed to make sdb output more accurate. */
5375 /* Indicate the beginning of the function body,
5376 as opposed to parm setup. */
5377 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_BEG);
5379 /* If doing stupid allocation, mark parms as born here. */
5381 if (GET_CODE (get_last_insn ()) != NOTE)
5382 emit_note (NULL_PTR, NOTE_INSN_DELETED);
5383 parm_birth_insn = get_last_insn ();
5385 if (obey_regdecls)
5387 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
5388 use_variable (regno_reg_rtx[i]);
5390 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
5391 use_variable (current_function_internal_arg_pointer);
5394 context_display = 0;
5395 if (current_function_needs_context)
5397 /* Fetch static chain values for containing functions. */
5398 tem = decl_function_context (current_function_decl);
5399 /* If not doing stupid register allocation copy the static chain
5400 pointer into a pseudo. If we have small register classes, copy
5401 the value from memory if static_chain_incoming_rtx is a REG. If
5402 we do stupid register allocation, we use the stack address
5403 generated above. */
5404 if (tem && ! obey_regdecls)
5406 #ifdef SMALL_REGISTER_CLASSES
5407 /* If the static chain originally came in a register, put it back
5408 there, then move it out in the next insn. The reason for
5409 this peculiar code is to satisfy function integration. */
5410 if (SMALL_REGISTER_CLASSES
5411 && GET_CODE (static_chain_incoming_rtx) == REG)
5412 emit_move_insn (static_chain_incoming_rtx, last_ptr);
5413 #endif
5415 last_ptr = copy_to_reg (static_chain_incoming_rtx);
5418 while (tem)
5420 tree rtlexp = make_node (RTL_EXPR);
5422 RTL_EXPR_RTL (rtlexp) = last_ptr;
5423 context_display = tree_cons (tem, rtlexp, context_display);
5424 tem = decl_function_context (tem);
5425 if (tem == 0)
5426 break;
5427 /* Chain thru stack frames, assuming pointer to next lexical frame
5428 is found at the place we always store it. */
5429 #ifdef FRAME_GROWS_DOWNWARD
5430 last_ptr = plus_constant (last_ptr, - GET_MODE_SIZE (Pmode));
5431 #endif
5432 last_ptr = copy_to_reg (gen_rtx (MEM, Pmode,
5433 memory_address (Pmode, last_ptr)));
5435 /* If we are not optimizing, ensure that we know that this
5436 piece of context is live over the entire function. */
5437 if (! optimize)
5438 save_expr_regs = gen_rtx (EXPR_LIST, VOIDmode, last_ptr,
5439 save_expr_regs);
5443 /* After the display initializations is where the tail-recursion label
5444 should go, if we end up needing one. Ensure we have a NOTE here
5445 since some things (like trampolines) get placed before this. */
5446 tail_recursion_reentry = emit_note (NULL_PTR, NOTE_INSN_DELETED);
5448 /* Evaluate now the sizes of any types declared among the arguments. */
5449 for (tem = nreverse (get_pending_sizes ()); tem; tem = TREE_CHAIN (tem))
5451 expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode,
5452 EXPAND_MEMORY_USE_BAD);
5453 /* Flush the queue in case this parameter declaration has
5454 side-effects. */
5455 emit_queue ();
5458 /* Make sure there is a line number after the function entry setup code. */
5459 force_next_line_note ();
5462 /* Generate RTL for the end of the current function.
5463 FILENAME and LINE are the current position in the source file.
5465 It is up to language-specific callers to do cleanups for parameters--
5466 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */
5468 void
5469 expand_function_end (filename, line, end_bindings)
5470 char *filename;
5471 int line;
5472 int end_bindings;
5474 register int i;
5475 tree link;
5477 #ifdef TRAMPOLINE_TEMPLATE
5478 static rtx initial_trampoline;
5479 #endif
5481 if (output_bytecode)
5483 bc_expand_function_end ();
5484 return;
5487 #ifdef NON_SAVING_SETJMP
5488 /* Don't put any variables in registers if we call setjmp
5489 on a machine that fails to restore the registers. */
5490 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
5492 if (DECL_INITIAL (current_function_decl) != error_mark_node)
5493 setjmp_protect (DECL_INITIAL (current_function_decl));
5495 setjmp_protect_args ();
5497 #endif
5499 /* Save the argument pointer if a save area was made for it. */
5500 if (arg_pointer_save_area)
5502 rtx x = gen_move_insn (arg_pointer_save_area, virtual_incoming_args_rtx);
5503 emit_insn_before (x, tail_recursion_reentry);
5506 /* Initialize any trampolines required by this function. */
5507 for (link = trampoline_list; link; link = TREE_CHAIN (link))
5509 tree function = TREE_PURPOSE (link);
5510 rtx context = lookup_static_chain (function);
5511 rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
5512 rtx blktramp;
5513 rtx seq;
5515 #ifdef TRAMPOLINE_TEMPLATE
5516 /* First make sure this compilation has a template for
5517 initializing trampolines. */
5518 if (initial_trampoline == 0)
5520 end_temporary_allocation ();
5521 initial_trampoline
5522 = gen_rtx (MEM, BLKmode, assemble_trampoline_template ());
5523 resume_temporary_allocation ();
5525 #endif
5527 /* Generate insns to initialize the trampoline. */
5528 start_sequence ();
5529 tramp = round_trampoline_addr (XEXP (tramp, 0));
5530 #ifdef TRAMPOLINE_TEMPLATE
5531 blktramp = change_address (initial_trampoline, BLKmode, tramp);
5532 emit_block_move (blktramp, initial_trampoline,
5533 GEN_INT (TRAMPOLINE_SIZE),
5534 TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
5535 #endif
5536 INITIALIZE_TRAMPOLINE (tramp, XEXP (DECL_RTL (function), 0), context);
5537 seq = get_insns ();
5538 end_sequence ();
5540 /* Put those insns at entry to the containing function (this one). */
5541 emit_insns_before (seq, tail_recursion_reentry);
5544 /* If we are doing stack checking and this function makes calls,
5545 do a stack probe at the start of the function to ensure we have enough
5546 space for another stack frame. */
5547 if (flag_stack_check && ! STACK_CHECK_BUILTIN)
5549 rtx insn, seq;
5551 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
5552 if (GET_CODE (insn) == CALL_INSN)
5554 start_sequence ();
5555 probe_stack_range (STACK_CHECK_PROTECT,
5556 GEN_INT (STACK_CHECK_MAX_FRAME_SIZE));
5557 seq = get_insns ();
5558 end_sequence ();
5559 emit_insns_before (seq, tail_recursion_reentry);
5560 break;
5564 /* Warn about unused parms if extra warnings were specified. */
5565 if (warn_unused && extra_warnings)
5567 tree decl;
5569 for (decl = DECL_ARGUMENTS (current_function_decl);
5570 decl; decl = TREE_CHAIN (decl))
5571 if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
5572 && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
5573 warning_with_decl (decl, "unused parameter `%s'");
5576 /* Delete handlers for nonlocal gotos if nothing uses them. */
5577 if (nonlocal_goto_handler_slot != 0 && !current_function_has_nonlocal_label)
5578 delete_handlers ();
5580 /* End any sequences that failed to be closed due to syntax errors. */
5581 while (in_sequence_p ())
5582 end_sequence ();
5584 /* Outside function body, can't compute type's actual size
5585 until next function's body starts. */
5586 immediate_size_expand--;
5588 /* If doing stupid register allocation,
5589 mark register parms as dying here. */
5591 if (obey_regdecls)
5593 rtx tem;
5594 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
5595 use_variable (regno_reg_rtx[i]);
5597 /* Likewise for the regs of all the SAVE_EXPRs in the function. */
5599 for (tem = save_expr_regs; tem; tem = XEXP (tem, 1))
5601 use_variable (XEXP (tem, 0));
5602 use_variable_after (XEXP (tem, 0), parm_birth_insn);
5605 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
5606 use_variable (current_function_internal_arg_pointer);
5609 clear_pending_stack_adjust ();
5610 do_pending_stack_adjust ();
5612 /* Mark the end of the function body.
5613 If control reaches this insn, the function can drop through
5614 without returning a value. */
5615 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_END);
5617 /* Must mark the last line number note in the function, so that the test
5618 coverage code can avoid counting the last line twice. This just tells
5619 the code to ignore the immediately following line note, since there
5620 already exists a copy of this note somewhere above. This line number
5621 note is still needed for debugging though, so we can't delete it. */
5622 if (flag_test_coverage)
5623 emit_note (NULL_PTR, NOTE_REPEATED_LINE_NUMBER);
5625 /* Output a linenumber for the end of the function.
5626 SDB depends on this. */
5627 emit_line_note_force (filename, line);
5629 /* Output the label for the actual return from the function,
5630 if one is expected. This happens either because a function epilogue
5631 is used instead of a return instruction, or because a return was done
5632 with a goto in order to run local cleanups, or because of pcc-style
5633 structure returning. */
5635 if (return_label)
5636 emit_label (return_label);
5638 /* C++ uses this. */
5639 if (end_bindings)
5640 expand_end_bindings (0, 0, 0);
5642 /* Now handle any leftover exception regions that may have been
5643 created for the parameters. */
5645 rtx last = get_last_insn ();
5646 rtx label;
5648 expand_leftover_cleanups ();
5650 /* If the above emitted any code, may sure we jump around it. */
5651 if (last != get_last_insn ())
5653 label = gen_label_rtx ();
5654 last = emit_jump_insn_after (gen_jump (label), last);
5655 last = emit_barrier_after (last);
5656 emit_label (label);
5660 /* If we had calls to alloca, and this machine needs
5661 an accurate stack pointer to exit the function,
5662 insert some code to save and restore the stack pointer. */
5663 #ifdef EXIT_IGNORE_STACK
5664 if (! EXIT_IGNORE_STACK)
5665 #endif
5666 if (current_function_calls_alloca)
5668 rtx tem = 0;
5670 emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
5671 emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
5674 /* If scalar return value was computed in a pseudo-reg,
5675 copy that to the hard return register. */
5676 if (DECL_RTL (DECL_RESULT (current_function_decl)) != 0
5677 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG
5678 && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl)))
5679 >= FIRST_PSEUDO_REGISTER))
5681 rtx real_decl_result;
5683 #ifdef FUNCTION_OUTGOING_VALUE
5684 real_decl_result
5685 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
5686 current_function_decl);
5687 #else
5688 real_decl_result
5689 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
5690 current_function_decl);
5691 #endif
5692 REG_FUNCTION_VALUE_P (real_decl_result) = 1;
5693 /* If this is a BLKmode structure being returned in registers, then use
5694 the mode computed in expand_return. */
5695 if (GET_MODE (real_decl_result) == BLKmode)
5696 PUT_MODE (real_decl_result,
5697 GET_MODE (DECL_RTL (DECL_RESULT (current_function_decl))));
5698 emit_move_insn (real_decl_result,
5699 DECL_RTL (DECL_RESULT (current_function_decl)));
5700 emit_insn (gen_rtx (USE, VOIDmode, real_decl_result));
5702 /* The delay slot scheduler assumes that current_function_return_rtx
5703 holds the hard register containing the return value, not a temporary
5704 pseudo. */
5705 current_function_return_rtx = real_decl_result;
5708 /* If returning a structure, arrange to return the address of the value
5709 in a place where debuggers expect to find it.
5711 If returning a structure PCC style,
5712 the caller also depends on this value.
5713 And current_function_returns_pcc_struct is not necessarily set. */
5714 if (current_function_returns_struct
5715 || current_function_returns_pcc_struct)
5717 rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
5718 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
5719 #ifdef FUNCTION_OUTGOING_VALUE
5720 rtx outgoing
5721 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
5722 current_function_decl);
5723 #else
5724 rtx outgoing
5725 = FUNCTION_VALUE (build_pointer_type (type),
5726 current_function_decl);
5727 #endif
5729 /* Mark this as a function return value so integrate will delete the
5730 assignment and USE below when inlining this function. */
5731 REG_FUNCTION_VALUE_P (outgoing) = 1;
5733 emit_move_insn (outgoing, value_address);
5734 use_variable (outgoing);
5737 /* Output a return insn if we are using one.
5738 Otherwise, let the rtl chain end here, to drop through
5739 into the epilogue. */
5741 #ifdef HAVE_return
5742 if (HAVE_return)
5744 emit_jump_insn (gen_return ());
5745 emit_barrier ();
5747 #endif
5749 /* Fix up any gotos that jumped out to the outermost
5750 binding level of the function.
5751 Must follow emitting RETURN_LABEL. */
5753 /* If you have any cleanups to do at this point,
5754 and they need to create temporary variables,
5755 then you will lose. */
5756 expand_fixups (get_insns ());
5759 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
5761 static int *prologue;
5762 static int *epilogue;
5764 /* Create an array that records the INSN_UIDs of INSNS (either a sequence
5765 or a single insn). */
5767 static int *
5768 record_insns (insns)
5769 rtx insns;
5771 int *vec;
5773 if (GET_CODE (insns) == SEQUENCE)
5775 int len = XVECLEN (insns, 0);
5776 vec = (int *) oballoc ((len + 1) * sizeof (int));
5777 vec[len] = 0;
5778 while (--len >= 0)
5779 vec[len] = INSN_UID (XVECEXP (insns, 0, len));
5781 else
5783 vec = (int *) oballoc (2 * sizeof (int));
5784 vec[0] = INSN_UID (insns);
5785 vec[1] = 0;
5787 return vec;
5790 /* Determine how many INSN_UIDs in VEC are part of INSN. */
5792 static int
5793 contains (insn, vec)
5794 rtx insn;
5795 int *vec;
5797 register int i, j;
5799 if (GET_CODE (insn) == INSN
5800 && GET_CODE (PATTERN (insn)) == SEQUENCE)
5802 int count = 0;
5803 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
5804 for (j = 0; vec[j]; j++)
5805 if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == vec[j])
5806 count++;
5807 return count;
5809 else
5811 for (j = 0; vec[j]; j++)
5812 if (INSN_UID (insn) == vec[j])
5813 return 1;
5815 return 0;
5818 /* Generate the prologue and epilogue RTL if the machine supports it. Thread
5819 this into place with notes indicating where the prologue ends and where
5820 the epilogue begins. Update the basic block information when possible. */
5822 void
5823 thread_prologue_and_epilogue_insns (f)
5824 rtx f;
5826 #ifdef HAVE_prologue
5827 if (HAVE_prologue)
5829 rtx head, seq, insn;
5831 /* The first insn (a NOTE_INSN_DELETED) is followed by zero or more
5832 prologue insns and a NOTE_INSN_PROLOGUE_END. */
5833 emit_note_after (NOTE_INSN_PROLOGUE_END, f);
5834 seq = gen_prologue ();
5835 head = emit_insn_after (seq, f);
5837 /* Include the new prologue insns in the first block. Ignore them
5838 if they form a basic block unto themselves. */
5839 if (basic_block_head && n_basic_blocks
5840 && GET_CODE (basic_block_head[0]) != CODE_LABEL)
5841 basic_block_head[0] = NEXT_INSN (f);
5843 /* Retain a map of the prologue insns. */
5844 prologue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : head);
5846 else
5847 #endif
5848 prologue = 0;
5850 #ifdef HAVE_epilogue
5851 if (HAVE_epilogue)
5853 rtx insn = get_last_insn ();
5854 rtx prev = prev_nonnote_insn (insn);
5856 /* If we end with a BARRIER, we don't need an epilogue. */
5857 if (! (prev && GET_CODE (prev) == BARRIER))
5859 rtx tail, seq, tem;
5860 rtx first_use = 0;
5861 rtx last_use = 0;
5863 /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, the
5864 epilogue insns, the USE insns at the end of a function,
5865 the jump insn that returns, and then a BARRIER. */
5867 /* Move the USE insns at the end of a function onto a list. */
5868 while (prev
5869 && GET_CODE (prev) == INSN
5870 && GET_CODE (PATTERN (prev)) == USE)
5872 tem = prev;
5873 prev = prev_nonnote_insn (prev);
5875 NEXT_INSN (PREV_INSN (tem)) = NEXT_INSN (tem);
5876 PREV_INSN (NEXT_INSN (tem)) = PREV_INSN (tem);
5877 if (first_use)
5879 NEXT_INSN (tem) = first_use;
5880 PREV_INSN (first_use) = tem;
5882 first_use = tem;
5883 if (!last_use)
5884 last_use = tem;
5887 emit_barrier_after (insn);
5889 seq = gen_epilogue ();
5890 tail = emit_jump_insn_after (seq, insn);
5892 /* Insert the USE insns immediately before the return insn, which
5893 must be the first instruction before the final barrier. */
5894 if (first_use)
5896 tem = prev_nonnote_insn (get_last_insn ());
5897 NEXT_INSN (PREV_INSN (tem)) = first_use;
5898 PREV_INSN (first_use) = PREV_INSN (tem);
5899 PREV_INSN (tem) = last_use;
5900 NEXT_INSN (last_use) = tem;
5903 emit_note_after (NOTE_INSN_EPILOGUE_BEG, insn);
5905 /* Include the new epilogue insns in the last block. Ignore
5906 them if they form a basic block unto themselves. */
5907 if (basic_block_end && n_basic_blocks
5908 && GET_CODE (basic_block_end[n_basic_blocks - 1]) != JUMP_INSN)
5909 basic_block_end[n_basic_blocks - 1] = tail;
5911 /* Retain a map of the epilogue insns. */
5912 epilogue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : tail);
5913 return;
5916 #endif
5917 epilogue = 0;
5920 /* Reposition the prologue-end and epilogue-begin notes after instruction
5921 scheduling and delayed branch scheduling. */
5923 void
5924 reposition_prologue_and_epilogue_notes (f)
5925 rtx f;
5927 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
5928 /* Reposition the prologue and epilogue notes. */
5929 if (n_basic_blocks)
5931 rtx next, prev;
5932 int len;
5934 if (prologue)
5936 register rtx insn, note = 0;
5938 /* Scan from the beginning until we reach the last prologue insn.
5939 We apparently can't depend on basic_block_{head,end} after
5940 reorg has run. */
5941 for (len = 0; prologue[len]; len++)
5943 for (insn = f; len && insn; insn = NEXT_INSN (insn))
5945 if (GET_CODE (insn) == NOTE)
5947 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
5948 note = insn;
5950 else if ((len -= contains (insn, prologue)) == 0)
5952 /* Find the prologue-end note if we haven't already, and
5953 move it to just after the last prologue insn. */
5954 if (note == 0)
5956 for (note = insn; note = NEXT_INSN (note);)
5957 if (GET_CODE (note) == NOTE
5958 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
5959 break;
5961 next = NEXT_INSN (note);
5962 prev = PREV_INSN (note);
5963 if (prev)
5964 NEXT_INSN (prev) = next;
5965 if (next)
5966 PREV_INSN (next) = prev;
5967 add_insn_after (note, insn);
5972 if (epilogue)
5974 register rtx insn, note = 0;
5976 /* Scan from the end until we reach the first epilogue insn.
5977 We apparently can't depend on basic_block_{head,end} after
5978 reorg has run. */
5979 for (len = 0; epilogue[len]; len++)
5981 for (insn = get_last_insn (); len && insn; insn = PREV_INSN (insn))
5983 if (GET_CODE (insn) == NOTE)
5985 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
5986 note = insn;
5988 else if ((len -= contains (insn, epilogue)) == 0)
5990 /* Find the epilogue-begin note if we haven't already, and
5991 move it to just before the first epilogue insn. */
5992 if (note == 0)
5994 for (note = insn; note = PREV_INSN (note);)
5995 if (GET_CODE (note) == NOTE
5996 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
5997 break;
5999 next = NEXT_INSN (note);
6000 prev = PREV_INSN (note);
6001 if (prev)
6002 NEXT_INSN (prev) = next;
6003 if (next)
6004 PREV_INSN (next) = prev;
6005 add_insn_after (note, PREV_INSN (insn));
6010 #endif /* HAVE_prologue or HAVE_epilogue */