Initial revision
[official-gcc.git] / gcc / function.c
blob88b346cb6241df0cdd3ff0d621b2f16b0de5d399
1 /* Expands front end tree to back end RTL for GNU C-Compiler
2 Copyright (C) 1987, 88, 89, 91-94, 1995 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
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, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This file handles the generation of rtl code from tree structure
22 at the level of the function as a whole.
23 It creates the rtl expressions for parameters and auto variables
24 and has full responsibility for allocating stack slots.
26 `expand_function_start' is called at the beginning of a function,
27 before the function body is parsed, and `expand_function_end' is
28 called after parsing the body.
30 Call `assign_stack_local' to allocate a stack slot for a local variable.
31 This is usually done during the RTL generation for the function body,
32 but it can also be done in the reload pass when a pseudo-register does
33 not get a hard register.
35 Call `put_var_into_stack' when you learn, belatedly, that a variable
36 previously given a pseudo-register must in fact go in the stack.
37 This function changes the DECL_RTL to be a stack slot instead of a reg
38 then scans all the RTL instructions so far generated to correct them. */
40 #include "config.h"
42 #include <stdio.h>
44 #include "rtl.h"
45 #include "tree.h"
46 #include "flags.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"
60 /* Some systems use __main in a way incompatible with its use in gcc, in these
61 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
62 give the same symbol without quotes for an alternative entry point. You
63 must define both, or niether. */
64 #ifndef NAME__MAIN
65 #define NAME__MAIN "__main"
66 #define SYMBOL__MAIN __main
67 #endif
69 /* Round a value to the lowest integer less than it that is a multiple of
70 the required alignment. Avoid using division in case the value is
71 negative. Assume the alignment is a power of two. */
72 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
74 /* Similar, but round to the next highest integer that meets the
75 alignment. */
76 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
78 /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp
79 during rtl generation. If they are different register numbers, this is
80 always true. It may also be true if
81 FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl
82 generation. See fix_lexical_addr for details. */
84 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
85 #define NEED_SEPARATE_AP
86 #endif
88 /* Number of bytes of args popped by function being compiled on its return.
89 Zero if no bytes are to be popped.
90 May affect compilation of return insn or of function epilogue. */
92 int current_function_pops_args;
94 /* Nonzero if function being compiled needs to be given an address
95 where the value should be stored. */
97 int current_function_returns_struct;
99 /* Nonzero if function being compiled needs to
100 return the address of where it has put a structure value. */
102 int current_function_returns_pcc_struct;
104 /* Nonzero if function being compiled needs to be passed a static chain. */
106 int current_function_needs_context;
108 /* Nonzero if function being compiled can call setjmp. */
110 int current_function_calls_setjmp;
112 /* Nonzero if function being compiled can call longjmp. */
114 int current_function_calls_longjmp;
116 /* Nonzero if function being compiled receives nonlocal gotos
117 from nested functions. */
119 int current_function_has_nonlocal_label;
121 /* Nonzero if function being compiled has nonlocal gotos to parent
122 function. */
124 int current_function_has_nonlocal_goto;
126 /* Nonzero if function being compiled contains nested functions. */
128 int current_function_contains_functions;
130 /* Nonzero if function being compiled can call alloca,
131 either as a subroutine or builtin. */
133 int current_function_calls_alloca;
135 /* Nonzero if the current function returns a pointer type */
137 int current_function_returns_pointer;
139 /* If some insns can be deferred to the delay slots of the epilogue, the
140 delay list for them is recorded here. */
142 rtx current_function_epilogue_delay_list;
144 /* If function's args have a fixed size, this is that size, in bytes.
145 Otherwise, it is -1.
146 May affect compilation of return insn or of function epilogue. */
148 int current_function_args_size;
150 /* # bytes the prologue should push and pretend that the caller pushed them.
151 The prologue must do this, but only if parms can be passed in registers. */
153 int current_function_pretend_args_size;
155 /* # of bytes of outgoing arguments. If ACCUMULATE_OUTGOING_ARGS is
156 defined, the needed space is pushed by the prologue. */
158 int current_function_outgoing_args_size;
160 /* This is the offset from the arg pointer to the place where the first
161 anonymous arg can be found, if there is one. */
163 rtx current_function_arg_offset_rtx;
165 /* Nonzero if current function uses varargs.h or equivalent.
166 Zero for functions that use stdarg.h. */
168 int current_function_varargs;
170 /* Quantities of various kinds of registers
171 used for the current function's args. */
173 CUMULATIVE_ARGS current_function_args_info;
175 /* Name of function now being compiled. */
177 char *current_function_name;
179 /* If non-zero, an RTL expression for that location at which the current
180 function returns its result. Always equal to
181 DECL_RTL (DECL_RESULT (current_function_decl)), but provided
182 independently of the tree structures. */
184 rtx current_function_return_rtx;
186 /* Nonzero if the current function uses the constant pool. */
188 int current_function_uses_const_pool;
190 /* Nonzero if the current function uses pic_offset_table_rtx. */
191 int current_function_uses_pic_offset_table;
193 /* The arg pointer hard register, or the pseudo into which it was copied. */
194 rtx current_function_internal_arg_pointer;
196 /* The FUNCTION_DECL for an inline function currently being expanded. */
197 tree inline_function_decl;
199 /* Number of function calls seen so far in current function. */
201 int function_call_count;
203 /* List (chain of TREE_LIST) of LABEL_DECLs for all nonlocal labels
204 (labels to which there can be nonlocal gotos from nested functions)
205 in this function. */
207 tree nonlocal_labels;
209 /* RTX for stack slot that holds the current handler for nonlocal gotos.
210 Zero when function does not have nonlocal labels. */
212 rtx nonlocal_goto_handler_slot;
214 /* RTX for stack slot that holds the stack pointer value to restore
215 for a nonlocal goto.
216 Zero when function does not have nonlocal labels. */
218 rtx nonlocal_goto_stack_level;
220 /* Label that will go on parm cleanup code, if any.
221 Jumping to this label runs cleanup code for parameters, if
222 such code must be run. Following this code is the logical return label. */
224 rtx cleanup_label;
226 /* Label that will go on function epilogue.
227 Jumping to this label serves as a "return" instruction
228 on machines which require execution of the epilogue on all returns. */
230 rtx return_label;
232 /* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs.
233 So we can mark them all live at the end of the function, if nonopt. */
234 rtx save_expr_regs;
236 /* List (chain of EXPR_LISTs) of all stack slots in this function.
237 Made for the sake of unshare_all_rtl. */
238 rtx stack_slot_list;
240 /* Chain of all RTL_EXPRs that have insns in them. */
241 tree rtl_expr_chain;
243 /* Label to jump back to for tail recursion, or 0 if we have
244 not yet needed one for this function. */
245 rtx tail_recursion_label;
247 /* Place after which to insert the tail_recursion_label if we need one. */
248 rtx tail_recursion_reentry;
250 /* Location at which to save the argument pointer if it will need to be
251 referenced. There are two cases where this is done: if nonlocal gotos
252 exist, or if vars stored at an offset from the argument pointer will be
253 needed by inner routines. */
255 rtx arg_pointer_save_area;
257 /* Offset to end of allocated area of stack frame.
258 If stack grows down, this is the address of the last stack slot allocated.
259 If stack grows up, this is the address for the next slot. */
260 int frame_offset;
262 /* List (chain of TREE_LISTs) of static chains for containing functions.
263 Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
264 in an RTL_EXPR in the TREE_VALUE. */
265 static tree context_display;
267 /* List (chain of TREE_LISTs) of trampolines for nested functions.
268 The trampoline sets up the static chain and jumps to the function.
269 We supply the trampoline's address when the function's address is requested.
271 Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
272 in an RTL_EXPR in the TREE_VALUE. */
273 static tree trampoline_list;
275 /* Insn after which register parms and SAVE_EXPRs are born, if nonopt. */
276 static rtx parm_birth_insn;
278 #if 0
279 /* Nonzero if a stack slot has been generated whose address is not
280 actually valid. It means that the generated rtl must all be scanned
281 to detect and correct the invalid addresses where they occur. */
282 static int invalid_stack_slot;
283 #endif
285 /* Last insn of those whose job was to put parms into their nominal homes. */
286 static rtx last_parm_insn;
288 /* 1 + last pseudo register number used for loading a copy
289 of a parameter of this function. */
290 static int max_parm_reg;
292 /* Vector indexed by REGNO, containing location on stack in which
293 to put the parm which is nominally in pseudo register REGNO,
294 if we discover that that parm must go in the stack. */
295 static rtx *parm_reg_stack_loc;
297 #if 0 /* Turned off because 0 seems to work just as well. */
298 /* Cleanup lists are required for binding levels regardless of whether
299 that binding level has cleanups or not. This node serves as the
300 cleanup list whenever an empty list is required. */
301 static tree empty_cleanup_list;
302 #endif
304 /* Nonzero once virtual register instantiation has been done.
305 assign_stack_local uses frame_pointer_rtx when this is nonzero. */
306 static int virtuals_instantiated;
308 /* These variables hold pointers to functions to
309 save and restore machine-specific data,
310 in push_function_context and pop_function_context. */
311 void (*save_machine_status) ();
312 void (*restore_machine_status) ();
314 /* Nonzero if we need to distinguish between the return value of this function
315 and the return value of a function called by this function. This helps
316 integrate.c */
318 extern int rtx_equal_function_value_matters;
319 extern tree sequence_rtl_expr;
320 extern tree bc_runtime_type_code ();
321 extern rtx bc_build_calldesc ();
322 extern char *bc_emit_trampoline ();
323 extern char *bc_end_function ();
325 /* In order to evaluate some expressions, such as function calls returning
326 structures in memory, we need to temporarily allocate stack locations.
327 We record each allocated temporary in the following structure.
329 Associated with each temporary slot is a nesting level. When we pop up
330 one level, all temporaries associated with the previous level are freed.
331 Normally, all temporaries are freed after the execution of the statement
332 in which they were created. However, if we are inside a ({...}) grouping,
333 the result may be in a temporary and hence must be preserved. If the
334 result could be in a temporary, we preserve it if we can determine which
335 one it is in. If we cannot determine which temporary may contain the
336 result, all temporaries are preserved. A temporary is preserved by
337 pretending it was allocated at the previous nesting level.
339 Automatic variables are also assigned temporary slots, at the nesting
340 level where they are defined. They are marked a "kept" so that
341 free_temp_slots will not free them. */
343 struct temp_slot
345 /* Points to next temporary slot. */
346 struct temp_slot *next;
347 /* The rtx to used to reference the slot. */
348 rtx slot;
349 /* The rtx used to represent the address if not the address of the
350 slot above. May be an EXPR_LIST if multiple addresses exist. */
351 rtx address;
352 /* The size, in units, of the slot. */
353 int size;
354 /* The value of `sequence_rtl_expr' when this temporary is allocated. */
355 tree rtl_expr;
356 /* Non-zero if this temporary is currently in use. */
357 char in_use;
358 /* Non-zero if this temporary has its address taken. */
359 char addr_taken;
360 /* Nesting level at which this slot is being used. */
361 int level;
362 /* Non-zero if this should survive a call to free_temp_slots. */
363 int keep;
366 /* List of all temporaries allocated, both available and in use. */
368 struct temp_slot *temp_slots;
370 /* Current nesting level for temporaries. */
372 int temp_slot_level;
374 /* The FUNCTION_DECL node for the current function. */
375 static tree this_function_decl;
377 /* Callinfo pointer for the current function. */
378 static rtx this_function_callinfo;
380 /* The label in the bytecode file of this function's actual bytecode.
381 Not an rtx. */
382 static char *this_function_bytecode;
384 /* The call description vector for the current function. */
385 static rtx this_function_calldesc;
387 /* Size of the local variables allocated for the current function. */
388 int local_vars_size;
390 /* Current depth of the bytecode evaluation stack. */
391 int stack_depth;
393 /* Maximum depth of the evaluation stack in this function. */
394 int max_stack_depth;
396 /* Current depth in statement expressions. */
397 static int stmt_expr_depth;
399 /* This structure is used to record MEMs or pseudos used to replace VAR, any
400 SUBREGs of VAR, and any MEMs containing VAR as an address. We need to
401 maintain this list in case two operands of an insn were required to match;
402 in that case we must ensure we use the same replacement. */
404 struct fixup_replacement
406 rtx old;
407 rtx new;
408 struct fixup_replacement *next;
411 /* Forward declarations. */
413 static struct temp_slot *find_temp_slot_from_address PROTO((rtx));
414 static void put_reg_into_stack PROTO((struct function *, rtx, tree,
415 enum machine_mode, enum machine_mode));
416 static void fixup_var_refs PROTO((rtx, enum machine_mode, int));
417 static struct fixup_replacement
418 *find_fixup_replacement PROTO((struct fixup_replacement **, rtx));
419 static void fixup_var_refs_insns PROTO((rtx, enum machine_mode, int,
420 rtx, int));
421 static void fixup_var_refs_1 PROTO((rtx, enum machine_mode, rtx *, rtx,
422 struct fixup_replacement **));
423 static rtx fixup_memory_subreg PROTO((rtx, rtx, int));
424 static rtx walk_fixup_memory_subreg PROTO((rtx, rtx, int));
425 static rtx fixup_stack_1 PROTO((rtx, rtx));
426 static void optimize_bit_field PROTO((rtx, rtx, rtx *));
427 static void instantiate_decls PROTO((tree, int));
428 static void instantiate_decls_1 PROTO((tree, int));
429 static void instantiate_decl PROTO((rtx, int, int));
430 static int instantiate_virtual_regs_1 PROTO((rtx *, rtx, int));
431 static void delete_handlers PROTO((void));
432 static void pad_to_arg_alignment PROTO((struct args_size *, int));
433 static void pad_below PROTO((struct args_size *, enum machine_mode,
434 tree));
435 static tree round_down PROTO((tree, int));
436 static rtx round_trampoline_addr PROTO((rtx));
437 static tree blocks_nreverse PROTO((tree));
438 static int all_blocks PROTO((tree, tree *));
439 static int *record_insns PROTO((rtx));
440 static int contains PROTO((rtx, int *));
442 /* Pointer to chain of `struct function' for containing functions. */
443 struct function *outer_function_chain;
445 /* Given a function decl for a containing function,
446 return the `struct function' for it. */
448 struct function *
449 find_function_data (decl)
450 tree decl;
452 struct function *p;
453 for (p = outer_function_chain; p; p = p->next)
454 if (p->decl == decl)
455 return p;
456 abort ();
459 /* Save the current context for compilation of a nested function.
460 This is called from language-specific code.
461 The caller is responsible for saving any language-specific status,
462 since this function knows only about language-independent variables. */
464 void
465 push_function_context_to (toplevel)
466 int toplevel;
468 struct function *p = (struct function *) xmalloc (sizeof (struct function));
470 p->next = outer_function_chain;
471 outer_function_chain = p;
473 p->name = current_function_name;
474 p->decl = current_function_decl;
475 p->pops_args = current_function_pops_args;
476 p->returns_struct = current_function_returns_struct;
477 p->returns_pcc_struct = current_function_returns_pcc_struct;
478 p->needs_context = current_function_needs_context;
479 p->calls_setjmp = current_function_calls_setjmp;
480 p->calls_longjmp = current_function_calls_longjmp;
481 p->calls_alloca = current_function_calls_alloca;
482 p->has_nonlocal_label = current_function_has_nonlocal_label;
483 p->has_nonlocal_goto = current_function_has_nonlocal_goto;
484 p->args_size = current_function_args_size;
485 p->pretend_args_size = current_function_pretend_args_size;
486 p->arg_offset_rtx = current_function_arg_offset_rtx;
487 p->varargs = current_function_varargs;
488 p->uses_const_pool = current_function_uses_const_pool;
489 p->uses_pic_offset_table = current_function_uses_pic_offset_table;
490 p->internal_arg_pointer = current_function_internal_arg_pointer;
491 p->max_parm_reg = max_parm_reg;
492 p->parm_reg_stack_loc = parm_reg_stack_loc;
493 p->outgoing_args_size = current_function_outgoing_args_size;
494 p->return_rtx = current_function_return_rtx;
495 p->nonlocal_goto_handler_slot = nonlocal_goto_handler_slot;
496 p->nonlocal_goto_stack_level = nonlocal_goto_stack_level;
497 p->nonlocal_labels = nonlocal_labels;
498 p->cleanup_label = cleanup_label;
499 p->return_label = return_label;
500 p->save_expr_regs = save_expr_regs;
501 p->stack_slot_list = stack_slot_list;
502 p->parm_birth_insn = parm_birth_insn;
503 p->frame_offset = frame_offset;
504 p->tail_recursion_label = tail_recursion_label;
505 p->tail_recursion_reentry = tail_recursion_reentry;
506 p->arg_pointer_save_area = arg_pointer_save_area;
507 p->rtl_expr_chain = rtl_expr_chain;
508 p->last_parm_insn = last_parm_insn;
509 p->context_display = context_display;
510 p->trampoline_list = trampoline_list;
511 p->function_call_count = function_call_count;
512 p->temp_slots = temp_slots;
513 p->temp_slot_level = temp_slot_level;
514 p->fixup_var_refs_queue = 0;
515 p->epilogue_delay_list = current_function_epilogue_delay_list;
517 save_tree_status (p, toplevel);
518 save_storage_status (p);
519 save_emit_status (p);
520 init_emit ();
521 save_expr_status (p);
522 save_stmt_status (p);
523 save_varasm_status (p);
525 if (save_machine_status)
526 (*save_machine_status) (p);
529 void
530 push_function_context ()
532 push_function_context_to (0);
535 /* Restore the last saved context, at the end of a nested function.
536 This function is called from language-specific code. */
538 void
539 pop_function_context_from (toplevel)
540 int toplevel;
542 struct function *p = outer_function_chain;
544 outer_function_chain = p->next;
546 current_function_name = p->name;
547 current_function_decl = p->decl;
548 current_function_pops_args = p->pops_args;
549 current_function_returns_struct = p->returns_struct;
550 current_function_returns_pcc_struct = p->returns_pcc_struct;
551 current_function_needs_context = p->needs_context;
552 current_function_calls_setjmp = p->calls_setjmp;
553 current_function_calls_longjmp = p->calls_longjmp;
554 current_function_calls_alloca = p->calls_alloca;
555 current_function_has_nonlocal_label = p->has_nonlocal_label;
556 current_function_has_nonlocal_goto = p->has_nonlocal_goto;
557 if (! toplevel)
558 current_function_contains_functions = 1;
559 current_function_args_size = p->args_size;
560 current_function_pretend_args_size = p->pretend_args_size;
561 current_function_arg_offset_rtx = p->arg_offset_rtx;
562 current_function_varargs = p->varargs;
563 current_function_uses_const_pool = p->uses_const_pool;
564 current_function_uses_pic_offset_table = p->uses_pic_offset_table;
565 current_function_internal_arg_pointer = p->internal_arg_pointer;
566 max_parm_reg = p->max_parm_reg;
567 parm_reg_stack_loc = p->parm_reg_stack_loc;
568 current_function_outgoing_args_size = p->outgoing_args_size;
569 current_function_return_rtx = p->return_rtx;
570 nonlocal_goto_handler_slot = p->nonlocal_goto_handler_slot;
571 nonlocal_goto_stack_level = p->nonlocal_goto_stack_level;
572 nonlocal_labels = p->nonlocal_labels;
573 cleanup_label = p->cleanup_label;
574 return_label = p->return_label;
575 save_expr_regs = p->save_expr_regs;
576 stack_slot_list = p->stack_slot_list;
577 parm_birth_insn = p->parm_birth_insn;
578 frame_offset = p->frame_offset;
579 tail_recursion_label = p->tail_recursion_label;
580 tail_recursion_reentry = p->tail_recursion_reentry;
581 arg_pointer_save_area = p->arg_pointer_save_area;
582 rtl_expr_chain = p->rtl_expr_chain;
583 last_parm_insn = p->last_parm_insn;
584 context_display = p->context_display;
585 trampoline_list = p->trampoline_list;
586 function_call_count = p->function_call_count;
587 temp_slots = p->temp_slots;
588 temp_slot_level = p->temp_slot_level;
589 current_function_epilogue_delay_list = p->epilogue_delay_list;
590 reg_renumber = 0;
592 restore_tree_status (p, toplevel);
593 restore_storage_status (p);
594 restore_expr_status (p);
595 restore_emit_status (p);
596 restore_stmt_status (p);
597 restore_varasm_status (p);
599 if (restore_machine_status)
600 (*restore_machine_status) (p);
602 /* Finish doing put_var_into_stack for any of our variables
603 which became addressable during the nested function. */
605 struct var_refs_queue *queue = p->fixup_var_refs_queue;
606 for (; queue; queue = queue->next)
607 fixup_var_refs (queue->modified, queue->promoted_mode, queue->unsignedp);
610 free (p);
612 /* Reset variables that have known state during rtx generation. */
613 rtx_equal_function_value_matters = 1;
614 virtuals_instantiated = 0;
617 void pop_function_context ()
619 pop_function_context_from (0);
622 /* Allocate fixed slots in the stack frame of the current function. */
624 /* Return size needed for stack frame based on slots so far allocated.
625 This size counts from zero. It is not rounded to STACK_BOUNDARY;
626 the caller may have to do that. */
629 get_frame_size ()
631 #ifdef FRAME_GROWS_DOWNWARD
632 return -frame_offset;
633 #else
634 return frame_offset;
635 #endif
638 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
639 with machine mode MODE.
641 ALIGN controls the amount of alignment for the address of the slot:
642 0 means according to MODE,
643 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
644 positive specifies alignment boundary in bits.
646 We do not round to stack_boundary here. */
649 assign_stack_local (mode, size, align)
650 enum machine_mode mode;
651 int size;
652 int align;
654 register rtx x, addr;
655 int bigend_correction = 0;
656 int alignment;
658 if (align == 0)
660 alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
661 if (mode == BLKmode)
662 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
664 else if (align == -1)
666 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
667 size = CEIL_ROUND (size, alignment);
669 else
670 alignment = align / BITS_PER_UNIT;
672 /* Round frame offset to that alignment.
673 We must be careful here, since FRAME_OFFSET might be negative and
674 division with a negative dividend isn't as well defined as we might
675 like. So we instead assume that ALIGNMENT is a power of two and
676 use logical operations which are unambiguous. */
677 #ifdef FRAME_GROWS_DOWNWARD
678 frame_offset = FLOOR_ROUND (frame_offset, alignment);
679 #else
680 frame_offset = CEIL_ROUND (frame_offset, alignment);
681 #endif
683 /* On a big-endian machine, if we are allocating more space than we will use,
684 use the least significant bytes of those that are allocated. */
685 if (BYTES_BIG_ENDIAN && mode != BLKmode)
686 bigend_correction = size - GET_MODE_SIZE (mode);
688 #ifdef FRAME_GROWS_DOWNWARD
689 frame_offset -= size;
690 #endif
692 /* If we have already instantiated virtual registers, return the actual
693 address relative to the frame pointer. */
694 if (virtuals_instantiated)
695 addr = plus_constant (frame_pointer_rtx,
696 (frame_offset + bigend_correction
697 + STARTING_FRAME_OFFSET));
698 else
699 addr = plus_constant (virtual_stack_vars_rtx,
700 frame_offset + bigend_correction);
702 #ifndef FRAME_GROWS_DOWNWARD
703 frame_offset += size;
704 #endif
706 x = gen_rtx (MEM, mode, addr);
708 stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, x, stack_slot_list);
710 return x;
713 /* Assign a stack slot in a containing function.
714 First three arguments are same as in preceding function.
715 The last argument specifies the function to allocate in. */
718 assign_outer_stack_local (mode, size, align, function)
719 enum machine_mode mode;
720 int size;
721 int align;
722 struct function *function;
724 register rtx x, addr;
725 int bigend_correction = 0;
726 int alignment;
728 /* Allocate in the memory associated with the function in whose frame
729 we are assigning. */
730 push_obstacks (function->function_obstack,
731 function->function_maybepermanent_obstack);
733 if (align == 0)
735 alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
736 if (mode == BLKmode)
737 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
739 else if (align == -1)
741 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
742 size = CEIL_ROUND (size, alignment);
744 else
745 alignment = align / BITS_PER_UNIT;
747 /* Round frame offset to that alignment. */
748 #ifdef FRAME_GROWS_DOWNWARD
749 function->frame_offset = FLOOR_ROUND (function->frame_offset, alignment);
750 #else
751 function->frame_offset = CEIL_ROUND (function->frame_offset, alignment);
752 #endif
754 /* On a big-endian machine, if we are allocating more space than we will use,
755 use the least significant bytes of those that are allocated. */
756 if (BYTES_BIG_ENDIAN && mode != BLKmode)
757 bigend_correction = size - GET_MODE_SIZE (mode);
759 #ifdef FRAME_GROWS_DOWNWARD
760 function->frame_offset -= size;
761 #endif
762 addr = plus_constant (virtual_stack_vars_rtx,
763 function->frame_offset + bigend_correction);
764 #ifndef FRAME_GROWS_DOWNWARD
765 function->frame_offset += size;
766 #endif
768 x = gen_rtx (MEM, mode, addr);
770 function->stack_slot_list
771 = gen_rtx (EXPR_LIST, VOIDmode, x, function->stack_slot_list);
773 pop_obstacks ();
775 return x;
778 /* Allocate a temporary stack slot and record it for possible later
779 reuse.
781 MODE is the machine mode to be given to the returned rtx.
783 SIZE is the size in units of the space required. We do no rounding here
784 since assign_stack_local will do any required rounding.
786 KEEP is 1 if this slot is to be retained after a call to
787 free_temp_slots. Automatic variables for a block are allocated
788 with this flag. KEEP is 2, if we allocate a longer term temporary,
789 whose lifetime is controlled by CLEANUP_POINT_EXPRs. */
792 assign_stack_temp (mode, size, keep)
793 enum machine_mode mode;
794 int size;
795 int keep;
797 struct temp_slot *p, *best_p = 0;
799 /* If SIZE is -1 it means that somebody tried to allocate a temporary
800 of a variable size. */
801 if (size == -1)
802 abort ();
804 /* First try to find an available, already-allocated temporary that is the
805 exact size we require. */
806 for (p = temp_slots; p; p = p->next)
807 if (p->size == size && GET_MODE (p->slot) == mode && ! p->in_use)
808 break;
810 /* If we didn't find, one, try one that is larger than what we want. We
811 find the smallest such. */
812 if (p == 0)
813 for (p = temp_slots; p; p = p->next)
814 if (p->size > size && GET_MODE (p->slot) == mode && ! p->in_use
815 && (best_p == 0 || best_p->size > p->size))
816 best_p = p;
818 /* Make our best, if any, the one to use. */
819 if (best_p)
821 /* If there are enough aligned bytes left over, make them into a new
822 temp_slot so that the extra bytes don't get wasted. Do this only
823 for BLKmode slots, so that we can be sure of the alignment. */
824 if (GET_MODE (best_p->slot) == BLKmode)
826 int alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
827 int rounded_size = CEIL_ROUND (size, alignment);
829 if (best_p->size - rounded_size >= alignment)
831 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
832 p->in_use = p->addr_taken = 0;
833 p->size = best_p->size - rounded_size;
834 p->slot = gen_rtx (MEM, BLKmode,
835 plus_constant (XEXP (best_p->slot, 0),
836 rounded_size));
837 p->address = 0;
838 p->rtl_expr = 0;
839 p->next = temp_slots;
840 temp_slots = p;
842 stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, p->slot,
843 stack_slot_list);
845 best_p->size = rounded_size;
849 p = best_p;
852 /* If we still didn't find one, make a new temporary. */
853 if (p == 0)
855 int frame_offset_old = frame_offset;
856 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
857 /* If the temp slot mode doesn't indicate the alignment,
858 use the largest possible, so no one will be disappointed. */
859 p->slot = assign_stack_local (mode, size, mode == BLKmode ? -1 : 0);
860 /* The following slot size computation is necessary because we don't
861 know the actual size of the temporary slot until assign_stack_local
862 has performed all the frame alignment and size rounding for the
863 requested temporary. Otherwise combine_temp_slots won't think that
864 adjacent slots really are adjacent. */
865 #ifdef FRAME_GROWS_DOWNWARD
866 p->size = frame_offset_old - frame_offset;
867 #else
868 p->size = frame_offset - frame_offset_old;
869 #endif
870 p->address = 0;
871 p->next = temp_slots;
872 temp_slots = p;
875 p->in_use = 1;
876 p->addr_taken = 0;
877 p->rtl_expr = sequence_rtl_expr;
879 if (keep == 2)
881 p->level = target_temp_slot_level;
882 p->keep = 0;
884 else
886 p->level = temp_slot_level;
887 p->keep = keep;
889 return p->slot;
892 /* Combine temporary stack slots which are adjacent on the stack.
894 This allows for better use of already allocated stack space. This is only
895 done for BLKmode slots because we can be sure that we won't have alignment
896 problems in this case. */
898 void
899 combine_temp_slots ()
901 struct temp_slot *p, *q;
902 struct temp_slot *prev_p, *prev_q;
903 /* Determine where to free back to after this function. */
904 rtx free_pointer = rtx_alloc (CONST_INT);
906 for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots)
908 int delete_p = 0;
909 if (! p->in_use && GET_MODE (p->slot) == BLKmode)
910 for (q = p->next, prev_q = p; q; q = prev_q->next)
912 int delete_q = 0;
913 if (! q->in_use && GET_MODE (q->slot) == BLKmode)
915 if (rtx_equal_p (plus_constant (XEXP (p->slot, 0), p->size),
916 XEXP (q->slot, 0)))
918 /* Q comes after P; combine Q into P. */
919 p->size += q->size;
920 delete_q = 1;
922 else if (rtx_equal_p (plus_constant (XEXP (q->slot, 0), q->size),
923 XEXP (p->slot, 0)))
925 /* P comes after Q; combine P into Q. */
926 q->size += p->size;
927 delete_p = 1;
928 break;
931 /* Either delete Q or advance past it. */
932 if (delete_q)
933 prev_q->next = q->next;
934 else
935 prev_q = q;
937 /* Either delete P or advance past it. */
938 if (delete_p)
940 if (prev_p)
941 prev_p->next = p->next;
942 else
943 temp_slots = p->next;
945 else
946 prev_p = p;
949 /* Free all the RTL made by plus_constant. */
950 rtx_free (free_pointer);
953 /* Find the temp slot corresponding to the object at address X. */
955 static struct temp_slot *
956 find_temp_slot_from_address (x)
957 rtx x;
959 struct temp_slot *p;
960 rtx next;
962 for (p = temp_slots; p; p = p->next)
964 if (! p->in_use)
965 continue;
966 else if (XEXP (p->slot, 0) == x
967 || p->address == x)
968 return p;
970 else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST)
971 for (next = p->address; next; next = XEXP (next, 1))
972 if (XEXP (next, 0) == x)
973 return p;
976 return 0;
979 /* Indicate that NEW is an alternate way of refering to the temp slot
980 that previous was known by OLD. */
982 void
983 update_temp_slot_address (old, new)
984 rtx old, new;
986 struct temp_slot *p = find_temp_slot_from_address (old);
988 /* If none, return. Else add NEW as an alias. */
989 if (p == 0)
990 return;
991 else if (p->address == 0)
992 p->address = new;
993 else
995 if (GET_CODE (p->address) != EXPR_LIST)
996 p->address = gen_rtx (EXPR_LIST, VOIDmode, p->address, NULL_RTX);
998 p->address = gen_rtx (EXPR_LIST, VOIDmode, new, p->address);
1002 /* If X could be a reference to a temporary slot, mark the fact that its
1003 adddress was taken. */
1005 void
1006 mark_temp_addr_taken (x)
1007 rtx x;
1009 struct temp_slot *p;
1011 if (x == 0)
1012 return;
1014 /* If X is not in memory or is at a constant address, it cannot be in
1015 a temporary slot. */
1016 if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1017 return;
1019 p = find_temp_slot_from_address (XEXP (x, 0));
1020 if (p != 0)
1021 p->addr_taken = 1;
1024 /* If X could be a reference to a temporary slot, mark that slot as belonging
1025 to the to one level higher. If X matched one of our slots, just mark that
1026 one. Otherwise, we can't easily predict which it is, so upgrade all of
1027 them. Kept slots need not be touched.
1029 This is called when an ({...}) construct occurs and a statement
1030 returns a value in memory. */
1032 void
1033 preserve_temp_slots (x)
1034 rtx x;
1036 struct temp_slot *p = 0;
1038 /* If there is no result, we still might have some objects whose address
1039 were taken, so we need to make sure they stay around. */
1040 if (x == 0)
1042 for (p = temp_slots; p; p = p->next)
1043 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1044 p->level--;
1046 return;
1049 /* If X is a register that is being used as a pointer, see if we have
1050 a temporary slot we know it points to. To be consistent with
1051 the code below, we really should preserve all non-kept slots
1052 if we can't find a match, but that seems to be much too costly. */
1053 if (GET_CODE (x) == REG && REGNO_POINTER_FLAG (REGNO (x)))
1054 p = find_temp_slot_from_address (x);
1056 /* If X is not in memory or is at a constant address, it cannot be in
1057 a temporary slot, but it can contain something whose address was
1058 taken. */
1059 if (p == 0 && (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))))
1061 for (p = temp_slots; p; p = p->next)
1062 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1063 p->level--;
1065 return;
1068 /* First see if we can find a match. */
1069 if (p == 0)
1070 p = find_temp_slot_from_address (XEXP (x, 0));
1072 if (p != 0)
1074 /* Move everything at our level whose address was taken to our new
1075 level in case we used its address. */
1076 struct temp_slot *q;
1078 for (q = temp_slots; q; q = q->next)
1079 if (q != p && q->addr_taken && q->level == p->level)
1080 q->level--;
1082 p->level--;
1083 return;
1086 /* Otherwise, preserve all non-kept slots at this level. */
1087 for (p = temp_slots; p; p = p->next)
1088 if (p->in_use && p->level == temp_slot_level && ! p->keep)
1089 p->level--;
1092 /* X is the result of an RTL_EXPR. If it is a temporary slot associated
1093 with that RTL_EXPR, promote it into a temporary slot at the present
1094 level so it will not be freed when we free slots made in the
1095 RTL_EXPR. */
1097 void
1098 preserve_rtl_expr_result (x)
1099 rtx x;
1101 struct temp_slot *p;
1103 /* If X is not in memory or is at a constant address, it cannot be in
1104 a temporary slot. */
1105 if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1106 return;
1108 /* If we can find a match, move it to our level unless it is already at
1109 an upper level. */
1110 p = find_temp_slot_from_address (XEXP (x, 0));
1111 if (p != 0)
1113 p->level = MIN (p->level, temp_slot_level);
1114 p->rtl_expr = 0;
1117 return;
1120 /* Free all temporaries used so far. This is normally called at the end
1121 of generating code for a statement. Don't free any temporaries
1122 currently in use for an RTL_EXPR that hasn't yet been emitted.
1123 We could eventually do better than this since it can be reused while
1124 generating the same RTL_EXPR, but this is complex and probably not
1125 worthwhile. */
1127 void
1128 free_temp_slots ()
1130 struct temp_slot *p;
1132 for (p = temp_slots; p; p = p->next)
1133 if (p->in_use && p->level == temp_slot_level && ! p->keep
1134 && p->rtl_expr == 0)
1135 p->in_use = 0;
1137 combine_temp_slots ();
1140 /* Free all temporary slots used in T, an RTL_EXPR node. */
1142 void
1143 free_temps_for_rtl_expr (t)
1144 tree t;
1146 struct temp_slot *p;
1148 for (p = temp_slots; p; p = p->next)
1149 if (p->rtl_expr == t)
1150 p->in_use = 0;
1152 combine_temp_slots ();
1155 /* Push deeper into the nesting level for stack temporaries. */
1157 void
1158 push_temp_slots ()
1160 temp_slot_level++;
1163 /* Pop a temporary nesting level. All slots in use in the current level
1164 are freed. */
1166 void
1167 pop_temp_slots ()
1169 struct temp_slot *p;
1171 for (p = temp_slots; p; p = p->next)
1172 if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0)
1173 p->in_use = 0;
1175 combine_temp_slots ();
1177 temp_slot_level--;
1180 /* Retroactively move an auto variable from a register to a stack slot.
1181 This is done when an address-reference to the variable is seen. */
1183 void
1184 put_var_into_stack (decl)
1185 tree decl;
1187 register rtx reg;
1188 enum machine_mode promoted_mode, decl_mode;
1189 struct function *function = 0;
1190 tree context;
1192 if (output_bytecode)
1193 return;
1195 context = decl_function_context (decl);
1197 /* Get the current rtl used for this object and it's original mode. */
1198 reg = TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl) : DECL_RTL (decl);
1200 /* No need to do anything if decl has no rtx yet
1201 since in that case caller is setting TREE_ADDRESSABLE
1202 and a stack slot will be assigned when the rtl is made. */
1203 if (reg == 0)
1204 return;
1206 /* Get the declared mode for this object. */
1207 decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl))
1208 : DECL_MODE (decl));
1209 /* Get the mode it's actually stored in. */
1210 promoted_mode = GET_MODE (reg);
1212 /* If this variable comes from an outer function,
1213 find that function's saved context. */
1214 if (context != current_function_decl)
1215 for (function = outer_function_chain; function; function = function->next)
1216 if (function->decl == context)
1217 break;
1219 /* If this is a variable-size object with a pseudo to address it,
1220 put that pseudo into the stack, if the var is nonlocal. */
1221 if (DECL_NONLOCAL (decl)
1222 && GET_CODE (reg) == MEM
1223 && GET_CODE (XEXP (reg, 0)) == REG
1224 && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
1226 reg = XEXP (reg, 0);
1227 decl_mode = promoted_mode = GET_MODE (reg);
1230 /* Now we should have a value that resides in one or more pseudo regs. */
1232 if (GET_CODE (reg) == REG)
1233 put_reg_into_stack (function, reg, TREE_TYPE (decl),
1234 promoted_mode, decl_mode);
1235 else if (GET_CODE (reg) == CONCAT)
1237 /* A CONCAT contains two pseudos; put them both in the stack.
1238 We do it so they end up consecutive. */
1239 enum machine_mode part_mode = GET_MODE (XEXP (reg, 0));
1240 tree part_type = TREE_TYPE (TREE_TYPE (decl));
1241 #ifdef STACK_GROWS_DOWNWARD
1242 /* Since part 0 should have a lower address, do it second. */
1243 put_reg_into_stack (function, XEXP (reg, 1),
1244 part_type, part_mode, part_mode);
1245 put_reg_into_stack (function, XEXP (reg, 0),
1246 part_type, part_mode, part_mode);
1247 #else
1248 put_reg_into_stack (function, XEXP (reg, 0),
1249 part_type, part_mode, part_mode);
1250 put_reg_into_stack (function, XEXP (reg, 1),
1251 part_type, part_mode, part_mode);
1252 #endif
1254 /* Change the CONCAT into a combined MEM for both parts. */
1255 PUT_CODE (reg, MEM);
1256 /* The two parts are in memory order already.
1257 Use the lower parts address as ours. */
1258 XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0);
1259 /* Prevent sharing of rtl that might lose. */
1260 if (GET_CODE (XEXP (reg, 0)) == PLUS)
1261 XEXP (reg, 0) = copy_rtx (XEXP (reg, 0));
1265 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1266 into the stack frame of FUNCTION (0 means the current function).
1267 DECL_MODE is the machine mode of the user-level data type.
1268 PROMOTED_MODE is the machine mode of the register. */
1270 static void
1271 put_reg_into_stack (function, reg, type, promoted_mode, decl_mode)
1272 struct function *function;
1273 rtx reg;
1274 tree type;
1275 enum machine_mode promoted_mode, decl_mode;
1277 rtx new = 0;
1279 if (function)
1281 if (REGNO (reg) < function->max_parm_reg)
1282 new = function->parm_reg_stack_loc[REGNO (reg)];
1283 if (new == 0)
1284 new = assign_outer_stack_local (decl_mode, GET_MODE_SIZE (decl_mode),
1285 0, function);
1287 else
1289 if (REGNO (reg) < max_parm_reg)
1290 new = parm_reg_stack_loc[REGNO (reg)];
1291 if (new == 0)
1292 new = assign_stack_local (decl_mode, GET_MODE_SIZE (decl_mode), 0);
1295 XEXP (reg, 0) = XEXP (new, 0);
1296 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1297 REG_USERVAR_P (reg) = 0;
1298 PUT_CODE (reg, MEM);
1299 PUT_MODE (reg, decl_mode);
1301 /* If this is a memory ref that contains aggregate components,
1302 mark it as such for cse and loop optimize. */
1303 MEM_IN_STRUCT_P (reg) = AGGREGATE_TYPE_P (type);
1305 /* Now make sure that all refs to the variable, previously made
1306 when it was a register, are fixed up to be valid again. */
1307 if (function)
1309 struct var_refs_queue *temp;
1311 /* Variable is inherited; fix it up when we get back to its function. */
1312 push_obstacks (function->function_obstack,
1313 function->function_maybepermanent_obstack);
1315 /* See comment in restore_tree_status in tree.c for why this needs to be
1316 on saveable obstack. */
1317 temp
1318 = (struct var_refs_queue *) savealloc (sizeof (struct var_refs_queue));
1319 temp->modified = reg;
1320 temp->promoted_mode = promoted_mode;
1321 temp->unsignedp = TREE_UNSIGNED (type);
1322 temp->next = function->fixup_var_refs_queue;
1323 function->fixup_var_refs_queue = temp;
1324 pop_obstacks ();
1326 else
1327 /* Variable is local; fix it up now. */
1328 fixup_var_refs (reg, promoted_mode, TREE_UNSIGNED (type));
1331 static void
1332 fixup_var_refs (var, promoted_mode, unsignedp)
1333 rtx var;
1334 enum machine_mode promoted_mode;
1335 int unsignedp;
1337 tree pending;
1338 rtx first_insn = get_insns ();
1339 struct sequence_stack *stack = sequence_stack;
1340 tree rtl_exps = rtl_expr_chain;
1342 /* Must scan all insns for stack-refs that exceed the limit. */
1343 fixup_var_refs_insns (var, promoted_mode, unsignedp, first_insn, stack == 0);
1345 /* Scan all pending sequences too. */
1346 for (; stack; stack = stack->next)
1348 push_to_sequence (stack->first);
1349 fixup_var_refs_insns (var, promoted_mode, unsignedp,
1350 stack->first, stack->next != 0);
1351 /* Update remembered end of sequence
1352 in case we added an insn at the end. */
1353 stack->last = get_last_insn ();
1354 end_sequence ();
1357 /* Scan all waiting RTL_EXPRs too. */
1358 for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
1360 rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
1361 if (seq != const0_rtx && seq != 0)
1363 push_to_sequence (seq);
1364 fixup_var_refs_insns (var, promoted_mode, unsignedp, seq, 0);
1365 end_sequence ();
1370 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1371 some part of an insn. Return a struct fixup_replacement whose OLD
1372 value is equal to X. Allocate a new structure if no such entry exists. */
1374 static struct fixup_replacement *
1375 find_fixup_replacement (replacements, x)
1376 struct fixup_replacement **replacements;
1377 rtx x;
1379 struct fixup_replacement *p;
1381 /* See if we have already replaced this. */
1382 for (p = *replacements; p && p->old != x; p = p->next)
1385 if (p == 0)
1387 p = (struct fixup_replacement *) oballoc (sizeof (struct fixup_replacement));
1388 p->old = x;
1389 p->new = 0;
1390 p->next = *replacements;
1391 *replacements = p;
1394 return p;
1397 /* Scan the insn-chain starting with INSN for refs to VAR
1398 and fix them up. TOPLEVEL is nonzero if this chain is the
1399 main chain of insns for the current function. */
1401 static void
1402 fixup_var_refs_insns (var, promoted_mode, unsignedp, insn, toplevel)
1403 rtx var;
1404 enum machine_mode promoted_mode;
1405 int unsignedp;
1406 rtx insn;
1407 int toplevel;
1409 rtx call_dest = 0;
1411 while (insn)
1413 rtx next = NEXT_INSN (insn);
1414 rtx note;
1415 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1417 /* If this is a CLOBBER of VAR, delete it.
1419 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1420 and REG_RETVAL notes too. */
1421 if (GET_CODE (PATTERN (insn)) == CLOBBER
1422 && XEXP (PATTERN (insn), 0) == var)
1424 if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0)
1425 /* The REG_LIBCALL note will go away since we are going to
1426 turn INSN into a NOTE, so just delete the
1427 corresponding REG_RETVAL note. */
1428 remove_note (XEXP (note, 0),
1429 find_reg_note (XEXP (note, 0), REG_RETVAL,
1430 NULL_RTX));
1432 /* In unoptimized compilation, we shouldn't call delete_insn
1433 except in jump.c doing warnings. */
1434 PUT_CODE (insn, NOTE);
1435 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1436 NOTE_SOURCE_FILE (insn) = 0;
1439 /* The insn to load VAR from a home in the arglist
1440 is now a no-op. When we see it, just delete it. */
1441 else if (toplevel
1442 && GET_CODE (PATTERN (insn)) == SET
1443 && SET_DEST (PATTERN (insn)) == var
1444 /* If this represents the result of an insn group,
1445 don't delete the insn. */
1446 && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0
1447 && rtx_equal_p (SET_SRC (PATTERN (insn)), var))
1449 /* In unoptimized compilation, we shouldn't call delete_insn
1450 except in jump.c doing warnings. */
1451 PUT_CODE (insn, NOTE);
1452 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1453 NOTE_SOURCE_FILE (insn) = 0;
1454 if (insn == last_parm_insn)
1455 last_parm_insn = PREV_INSN (next);
1457 else
1459 struct fixup_replacement *replacements = 0;
1460 rtx next_insn = NEXT_INSN (insn);
1462 #ifdef SMALL_REGISTER_CLASSES
1463 /* If the insn that copies the results of a CALL_INSN
1464 into a pseudo now references VAR, we have to use an
1465 intermediate pseudo since we want the life of the
1466 return value register to be only a single insn.
1468 If we don't use an intermediate pseudo, such things as
1469 address computations to make the address of VAR valid
1470 if it is not can be placed beween the CALL_INSN and INSN.
1472 To make sure this doesn't happen, we record the destination
1473 of the CALL_INSN and see if the next insn uses both that
1474 and VAR. */
1476 if (call_dest != 0 && GET_CODE (insn) == INSN
1477 && reg_mentioned_p (var, PATTERN (insn))
1478 && reg_mentioned_p (call_dest, PATTERN (insn)))
1480 rtx temp = gen_reg_rtx (GET_MODE (call_dest));
1482 emit_insn_before (gen_move_insn (temp, call_dest), insn);
1484 PATTERN (insn) = replace_rtx (PATTERN (insn),
1485 call_dest, temp);
1488 if (GET_CODE (insn) == CALL_INSN
1489 && GET_CODE (PATTERN (insn)) == SET)
1490 call_dest = SET_DEST (PATTERN (insn));
1491 else if (GET_CODE (insn) == CALL_INSN
1492 && GET_CODE (PATTERN (insn)) == PARALLEL
1493 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
1494 call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
1495 else
1496 call_dest = 0;
1497 #endif
1499 /* See if we have to do anything to INSN now that VAR is in
1500 memory. If it needs to be loaded into a pseudo, use a single
1501 pseudo for the entire insn in case there is a MATCH_DUP
1502 between two operands. We pass a pointer to the head of
1503 a list of struct fixup_replacements. If fixup_var_refs_1
1504 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1505 it will record them in this list.
1507 If it allocated a pseudo for any replacement, we copy into
1508 it here. */
1510 fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn,
1511 &replacements);
1513 /* If this is last_parm_insn, and any instructions were output
1514 after it to fix it up, then we must set last_parm_insn to
1515 the last such instruction emitted. */
1516 if (insn == last_parm_insn)
1517 last_parm_insn = PREV_INSN (next_insn);
1519 while (replacements)
1521 if (GET_CODE (replacements->new) == REG)
1523 rtx insert_before;
1524 rtx seq;
1526 /* OLD might be a (subreg (mem)). */
1527 if (GET_CODE (replacements->old) == SUBREG)
1528 replacements->old
1529 = fixup_memory_subreg (replacements->old, insn, 0);
1530 else
1531 replacements->old
1532 = fixup_stack_1 (replacements->old, insn);
1534 insert_before = insn;
1536 /* If we are changing the mode, do a conversion.
1537 This might be wasteful, but combine.c will
1538 eliminate much of the waste. */
1540 if (GET_MODE (replacements->new)
1541 != GET_MODE (replacements->old))
1543 start_sequence ();
1544 convert_move (replacements->new,
1545 replacements->old, unsignedp);
1546 seq = gen_sequence ();
1547 end_sequence ();
1549 else
1550 seq = gen_move_insn (replacements->new,
1551 replacements->old);
1553 emit_insn_before (seq, insert_before);
1556 replacements = replacements->next;
1560 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1561 But don't touch other insns referred to by reg-notes;
1562 we will get them elsewhere. */
1563 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
1564 if (GET_CODE (note) != INSN_LIST)
1565 XEXP (note, 0)
1566 = walk_fixup_memory_subreg (XEXP (note, 0), insn, 1);
1568 insn = next;
1572 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1573 See if the rtx expression at *LOC in INSN needs to be changed.
1575 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1576 contain a list of original rtx's and replacements. If we find that we need
1577 to modify this insn by replacing a memory reference with a pseudo or by
1578 making a new MEM to implement a SUBREG, we consult that list to see if
1579 we have already chosen a replacement. If none has already been allocated,
1580 we allocate it and update the list. fixup_var_refs_insns will copy VAR
1581 or the SUBREG, as appropriate, to the pseudo. */
1583 static void
1584 fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements)
1585 register rtx var;
1586 enum machine_mode promoted_mode;
1587 register rtx *loc;
1588 rtx insn;
1589 struct fixup_replacement **replacements;
1591 register int i;
1592 register rtx x = *loc;
1593 RTX_CODE code = GET_CODE (x);
1594 register char *fmt;
1595 register rtx tem, tem1;
1596 struct fixup_replacement *replacement;
1598 switch (code)
1600 case MEM:
1601 if (var == x)
1603 /* If we already have a replacement, use it. Otherwise,
1604 try to fix up this address in case it is invalid. */
1606 replacement = find_fixup_replacement (replacements, var);
1607 if (replacement->new)
1609 *loc = replacement->new;
1610 return;
1613 *loc = replacement->new = x = fixup_stack_1 (x, insn);
1615 /* Unless we are forcing memory to register or we changed the mode,
1616 we can leave things the way they are if the insn is valid. */
1618 INSN_CODE (insn) = -1;
1619 if (! flag_force_mem && GET_MODE (x) == promoted_mode
1620 && recog_memoized (insn) >= 0)
1621 return;
1623 *loc = replacement->new = gen_reg_rtx (promoted_mode);
1624 return;
1627 /* If X contains VAR, we need to unshare it here so that we update
1628 each occurrence separately. But all identical MEMs in one insn
1629 must be replaced with the same rtx because of the possibility of
1630 MATCH_DUPs. */
1632 if (reg_mentioned_p (var, x))
1634 replacement = find_fixup_replacement (replacements, x);
1635 if (replacement->new == 0)
1636 replacement->new = copy_most_rtx (x, var);
1638 *loc = x = replacement->new;
1640 break;
1642 case REG:
1643 case CC0:
1644 case PC:
1645 case CONST_INT:
1646 case CONST:
1647 case SYMBOL_REF:
1648 case LABEL_REF:
1649 case CONST_DOUBLE:
1650 return;
1652 case SIGN_EXTRACT:
1653 case ZERO_EXTRACT:
1654 /* Note that in some cases those types of expressions are altered
1655 by optimize_bit_field, and do not survive to get here. */
1656 if (XEXP (x, 0) == var
1657 || (GET_CODE (XEXP (x, 0)) == SUBREG
1658 && SUBREG_REG (XEXP (x, 0)) == var))
1660 /* Get TEM as a valid MEM in the mode presently in the insn.
1662 We don't worry about the possibility of MATCH_DUP here; it
1663 is highly unlikely and would be tricky to handle. */
1665 tem = XEXP (x, 0);
1666 if (GET_CODE (tem) == SUBREG)
1667 tem = fixup_memory_subreg (tem, insn, 1);
1668 tem = fixup_stack_1 (tem, insn);
1670 /* Unless we want to load from memory, get TEM into the proper mode
1671 for an extract from memory. This can only be done if the
1672 extract is at a constant position and length. */
1674 if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
1675 && GET_CODE (XEXP (x, 2)) == CONST_INT
1676 && ! mode_dependent_address_p (XEXP (tem, 0))
1677 && ! MEM_VOLATILE_P (tem))
1679 enum machine_mode wanted_mode = VOIDmode;
1680 enum machine_mode is_mode = GET_MODE (tem);
1681 int width = INTVAL (XEXP (x, 1));
1682 int pos = INTVAL (XEXP (x, 2));
1684 #ifdef HAVE_extzv
1685 if (GET_CODE (x) == ZERO_EXTRACT)
1686 wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
1687 #endif
1688 #ifdef HAVE_extv
1689 if (GET_CODE (x) == SIGN_EXTRACT)
1690 wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
1691 #endif
1692 /* If we have a narrower mode, we can do something. */
1693 if (wanted_mode != VOIDmode
1694 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
1696 int offset = pos / BITS_PER_UNIT;
1697 rtx old_pos = XEXP (x, 2);
1698 rtx newmem;
1700 /* If the bytes and bits are counted differently, we
1701 must adjust the offset. */
1702 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
1703 offset = (GET_MODE_SIZE (is_mode)
1704 - GET_MODE_SIZE (wanted_mode) - offset);
1706 pos %= GET_MODE_BITSIZE (wanted_mode);
1708 newmem = gen_rtx (MEM, wanted_mode,
1709 plus_constant (XEXP (tem, 0), offset));
1710 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
1711 MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
1712 MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
1714 /* Make the change and see if the insn remains valid. */
1715 INSN_CODE (insn) = -1;
1716 XEXP (x, 0) = newmem;
1717 XEXP (x, 2) = GEN_INT (pos);
1719 if (recog_memoized (insn) >= 0)
1720 return;
1722 /* Otherwise, restore old position. XEXP (x, 0) will be
1723 restored later. */
1724 XEXP (x, 2) = old_pos;
1728 /* If we get here, the bitfield extract insn can't accept a memory
1729 reference. Copy the input into a register. */
1731 tem1 = gen_reg_rtx (GET_MODE (tem));
1732 emit_insn_before (gen_move_insn (tem1, tem), insn);
1733 XEXP (x, 0) = tem1;
1734 return;
1736 break;
1738 case SUBREG:
1739 if (SUBREG_REG (x) == var)
1741 /* If this is a special SUBREG made because VAR was promoted
1742 from a wider mode, replace it with VAR and call ourself
1743 recursively, this time saying that the object previously
1744 had its current mode (by virtue of the SUBREG). */
1746 if (SUBREG_PROMOTED_VAR_P (x))
1748 *loc = var;
1749 fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements);
1750 return;
1753 /* If this SUBREG makes VAR wider, it has become a paradoxical
1754 SUBREG with VAR in memory, but these aren't allowed at this
1755 stage of the compilation. So load VAR into a pseudo and take
1756 a SUBREG of that pseudo. */
1757 if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
1759 replacement = find_fixup_replacement (replacements, var);
1760 if (replacement->new == 0)
1761 replacement->new = gen_reg_rtx (GET_MODE (var));
1762 SUBREG_REG (x) = replacement->new;
1763 return;
1766 /* See if we have already found a replacement for this SUBREG.
1767 If so, use it. Otherwise, make a MEM and see if the insn
1768 is recognized. If not, or if we should force MEM into a register,
1769 make a pseudo for this SUBREG. */
1770 replacement = find_fixup_replacement (replacements, x);
1771 if (replacement->new)
1773 *loc = replacement->new;
1774 return;
1777 replacement->new = *loc = fixup_memory_subreg (x, insn, 0);
1779 INSN_CODE (insn) = -1;
1780 if (! flag_force_mem && recog_memoized (insn) >= 0)
1781 return;
1783 *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
1784 return;
1786 break;
1788 case SET:
1789 /* First do special simplification of bit-field references. */
1790 if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
1791 || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
1792 optimize_bit_field (x, insn, 0);
1793 if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
1794 || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
1795 optimize_bit_field (x, insn, NULL_PTR);
1797 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
1798 insn into a pseudo and store the low part of the pseudo into VAR. */
1799 if (GET_CODE (SET_DEST (x)) == SUBREG
1800 && SUBREG_REG (SET_DEST (x)) == var
1801 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
1802 > GET_MODE_SIZE (GET_MODE (var))))
1804 SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
1805 emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
1806 tem)),
1807 insn);
1808 break;
1812 rtx dest = SET_DEST (x);
1813 rtx src = SET_SRC (x);
1814 rtx outerdest = dest;
1816 while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
1817 || GET_CODE (dest) == SIGN_EXTRACT
1818 || GET_CODE (dest) == ZERO_EXTRACT)
1819 dest = XEXP (dest, 0);
1821 if (GET_CODE (src) == SUBREG)
1822 src = XEXP (src, 0);
1824 /* If VAR does not appear at the top level of the SET
1825 just scan the lower levels of the tree. */
1827 if (src != var && dest != var)
1828 break;
1830 /* We will need to rerecognize this insn. */
1831 INSN_CODE (insn) = -1;
1833 #ifdef HAVE_insv
1834 if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var)
1836 /* Since this case will return, ensure we fixup all the
1837 operands here. */
1838 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1),
1839 insn, replacements);
1840 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2),
1841 insn, replacements);
1842 fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x),
1843 insn, replacements);
1845 tem = XEXP (outerdest, 0);
1847 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
1848 that may appear inside a ZERO_EXTRACT.
1849 This was legitimate when the MEM was a REG. */
1850 if (GET_CODE (tem) == SUBREG
1851 && SUBREG_REG (tem) == var)
1852 tem = fixup_memory_subreg (tem, insn, 1);
1853 else
1854 tem = fixup_stack_1 (tem, insn);
1856 if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
1857 && GET_CODE (XEXP (outerdest, 2)) == CONST_INT
1858 && ! mode_dependent_address_p (XEXP (tem, 0))
1859 && ! MEM_VOLATILE_P (tem))
1861 enum machine_mode wanted_mode
1862 = insn_operand_mode[(int) CODE_FOR_insv][0];
1863 enum machine_mode is_mode = GET_MODE (tem);
1864 int width = INTVAL (XEXP (outerdest, 1));
1865 int pos = INTVAL (XEXP (outerdest, 2));
1867 /* If we have a narrower mode, we can do something. */
1868 if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
1870 int offset = pos / BITS_PER_UNIT;
1871 rtx old_pos = XEXP (outerdest, 2);
1872 rtx newmem;
1874 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
1875 offset = (GET_MODE_SIZE (is_mode)
1876 - GET_MODE_SIZE (wanted_mode) - offset);
1878 pos %= GET_MODE_BITSIZE (wanted_mode);
1880 newmem = gen_rtx (MEM, wanted_mode,
1881 plus_constant (XEXP (tem, 0), offset));
1882 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
1883 MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
1884 MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
1886 /* Make the change and see if the insn remains valid. */
1887 INSN_CODE (insn) = -1;
1888 XEXP (outerdest, 0) = newmem;
1889 XEXP (outerdest, 2) = GEN_INT (pos);
1891 if (recog_memoized (insn) >= 0)
1892 return;
1894 /* Otherwise, restore old position. XEXP (x, 0) will be
1895 restored later. */
1896 XEXP (outerdest, 2) = old_pos;
1900 /* If we get here, the bit-field store doesn't allow memory
1901 or isn't located at a constant position. Load the value into
1902 a register, do the store, and put it back into memory. */
1904 tem1 = gen_reg_rtx (GET_MODE (tem));
1905 emit_insn_before (gen_move_insn (tem1, tem), insn);
1906 emit_insn_after (gen_move_insn (tem, tem1), insn);
1907 XEXP (outerdest, 0) = tem1;
1908 return;
1910 #endif
1912 /* STRICT_LOW_PART is a no-op on memory references
1913 and it can cause combinations to be unrecognizable,
1914 so eliminate it. */
1916 if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
1917 SET_DEST (x) = XEXP (SET_DEST (x), 0);
1919 /* A valid insn to copy VAR into or out of a register
1920 must be left alone, to avoid an infinite loop here.
1921 If the reference to VAR is by a subreg, fix that up,
1922 since SUBREG is not valid for a memref.
1923 Also fix up the address of the stack slot.
1925 Note that we must not try to recognize the insn until
1926 after we know that we have valid addresses and no
1927 (subreg (mem ...) ...) constructs, since these interfere
1928 with determining the validity of the insn. */
1930 if ((SET_SRC (x) == var
1931 || (GET_CODE (SET_SRC (x)) == SUBREG
1932 && SUBREG_REG (SET_SRC (x)) == var))
1933 && (GET_CODE (SET_DEST (x)) == REG
1934 || (GET_CODE (SET_DEST (x)) == SUBREG
1935 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
1936 && x == single_set (PATTERN (insn)))
1938 rtx pat;
1940 replacement = find_fixup_replacement (replacements, SET_SRC (x));
1941 if (replacement->new)
1942 SET_SRC (x) = replacement->new;
1943 else if (GET_CODE (SET_SRC (x)) == SUBREG)
1944 SET_SRC (x) = replacement->new
1945 = fixup_memory_subreg (SET_SRC (x), insn, 0);
1946 else
1947 SET_SRC (x) = replacement->new
1948 = fixup_stack_1 (SET_SRC (x), insn);
1950 if (recog_memoized (insn) >= 0)
1951 return;
1953 /* INSN is not valid, but we know that we want to
1954 copy SET_SRC (x) to SET_DEST (x) in some way. So
1955 we generate the move and see whether it requires more
1956 than one insn. If it does, we emit those insns and
1957 delete INSN. Otherwise, we an just replace the pattern
1958 of INSN; we have already verified above that INSN has
1959 no other function that to do X. */
1961 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
1962 if (GET_CODE (pat) == SEQUENCE)
1964 emit_insn_after (pat, insn);
1965 PUT_CODE (insn, NOTE);
1966 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1967 NOTE_SOURCE_FILE (insn) = 0;
1969 else
1970 PATTERN (insn) = pat;
1972 return;
1975 if ((SET_DEST (x) == var
1976 || (GET_CODE (SET_DEST (x)) == SUBREG
1977 && SUBREG_REG (SET_DEST (x)) == var))
1978 && (GET_CODE (SET_SRC (x)) == REG
1979 || (GET_CODE (SET_SRC (x)) == SUBREG
1980 && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
1981 && x == single_set (PATTERN (insn)))
1983 rtx pat;
1985 if (GET_CODE (SET_DEST (x)) == SUBREG)
1986 SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn, 0);
1987 else
1988 SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
1990 if (recog_memoized (insn) >= 0)
1991 return;
1993 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
1994 if (GET_CODE (pat) == SEQUENCE)
1996 emit_insn_after (pat, insn);
1997 PUT_CODE (insn, NOTE);
1998 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1999 NOTE_SOURCE_FILE (insn) = 0;
2001 else
2002 PATTERN (insn) = pat;
2004 return;
2007 /* Otherwise, storing into VAR must be handled specially
2008 by storing into a temporary and copying that into VAR
2009 with a new insn after this one. Note that this case
2010 will be used when storing into a promoted scalar since
2011 the insn will now have different modes on the input
2012 and output and hence will be invalid (except for the case
2013 of setting it to a constant, which does not need any
2014 change if it is valid). We generate extra code in that case,
2015 but combine.c will eliminate it. */
2017 if (dest == var)
2019 rtx temp;
2020 rtx fixeddest = SET_DEST (x);
2022 /* STRICT_LOW_PART can be discarded, around a MEM. */
2023 if (GET_CODE (fixeddest) == STRICT_LOW_PART)
2024 fixeddest = XEXP (fixeddest, 0);
2025 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
2026 if (GET_CODE (fixeddest) == SUBREG)
2027 fixeddest = fixup_memory_subreg (fixeddest, insn, 0);
2028 else
2029 fixeddest = fixup_stack_1 (fixeddest, insn);
2031 temp = gen_reg_rtx (GET_MODE (SET_SRC (x)) == VOIDmode
2032 ? GET_MODE (fixeddest)
2033 : GET_MODE (SET_SRC (x)));
2035 emit_insn_after (gen_move_insn (fixeddest,
2036 gen_lowpart (GET_MODE (fixeddest),
2037 temp)),
2038 insn);
2040 SET_DEST (x) = temp;
2045 /* Nothing special about this RTX; fix its operands. */
2047 fmt = GET_RTX_FORMAT (code);
2048 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2050 if (fmt[i] == 'e')
2051 fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements);
2052 if (fmt[i] == 'E')
2054 register int j;
2055 for (j = 0; j < XVECLEN (x, i); j++)
2056 fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j),
2057 insn, replacements);
2062 /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
2063 return an rtx (MEM:m1 newaddr) which is equivalent.
2064 If any insns must be emitted to compute NEWADDR, put them before INSN.
2066 UNCRITICAL nonzero means accept paradoxical subregs.
2067 This is used for subregs found inside of ZERO_EXTRACTs and in REG_NOTES. */
2069 static rtx
2070 fixup_memory_subreg (x, insn, uncritical)
2071 rtx x;
2072 rtx insn;
2073 int uncritical;
2075 int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
2076 rtx addr = XEXP (SUBREG_REG (x), 0);
2077 enum machine_mode mode = GET_MODE (x);
2078 rtx saved, result;
2080 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2081 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
2082 && ! uncritical)
2083 abort ();
2085 if (BYTES_BIG_ENDIAN)
2086 offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
2087 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
2088 addr = plus_constant (addr, offset);
2089 if (!flag_force_addr && memory_address_p (mode, addr))
2090 /* Shortcut if no insns need be emitted. */
2091 return change_address (SUBREG_REG (x), mode, addr);
2092 start_sequence ();
2093 result = change_address (SUBREG_REG (x), mode, addr);
2094 emit_insn_before (gen_sequence (), insn);
2095 end_sequence ();
2096 return result;
2099 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2100 Replace subexpressions of X in place.
2101 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2102 Otherwise return X, with its contents possibly altered.
2104 If any insns must be emitted to compute NEWADDR, put them before INSN.
2106 UNCRITICAL is as in fixup_memory_subreg. */
2108 static rtx
2109 walk_fixup_memory_subreg (x, insn, uncritical)
2110 register rtx x;
2111 rtx insn;
2112 int uncritical;
2114 register enum rtx_code code;
2115 register char *fmt;
2116 register int i;
2118 if (x == 0)
2119 return 0;
2121 code = GET_CODE (x);
2123 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
2124 return fixup_memory_subreg (x, insn, uncritical);
2126 /* Nothing special about this RTX; fix its operands. */
2128 fmt = GET_RTX_FORMAT (code);
2129 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2131 if (fmt[i] == 'e')
2132 XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn, uncritical);
2133 if (fmt[i] == 'E')
2135 register int j;
2136 for (j = 0; j < XVECLEN (x, i); j++)
2137 XVECEXP (x, i, j)
2138 = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn, uncritical);
2141 return x;
2144 /* For each memory ref within X, if it refers to a stack slot
2145 with an out of range displacement, put the address in a temp register
2146 (emitting new insns before INSN to load these registers)
2147 and alter the memory ref to use that register.
2148 Replace each such MEM rtx with a copy, to avoid clobberage. */
2150 static rtx
2151 fixup_stack_1 (x, insn)
2152 rtx x;
2153 rtx insn;
2155 register int i;
2156 register RTX_CODE code = GET_CODE (x);
2157 register char *fmt;
2159 if (code == MEM)
2161 register rtx ad = XEXP (x, 0);
2162 /* If we have address of a stack slot but it's not valid
2163 (displacement is too large), compute the sum in a register. */
2164 if (GET_CODE (ad) == PLUS
2165 && GET_CODE (XEXP (ad, 0)) == REG
2166 && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
2167 && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER)
2168 || XEXP (ad, 0) == current_function_internal_arg_pointer)
2169 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
2171 rtx temp, seq;
2172 if (memory_address_p (GET_MODE (x), ad))
2173 return x;
2175 start_sequence ();
2176 temp = copy_to_reg (ad);
2177 seq = gen_sequence ();
2178 end_sequence ();
2179 emit_insn_before (seq, insn);
2180 return change_address (x, VOIDmode, temp);
2182 return x;
2185 fmt = GET_RTX_FORMAT (code);
2186 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2188 if (fmt[i] == 'e')
2189 XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
2190 if (fmt[i] == 'E')
2192 register int j;
2193 for (j = 0; j < XVECLEN (x, i); j++)
2194 XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
2197 return x;
2200 /* Optimization: a bit-field instruction whose field
2201 happens to be a byte or halfword in memory
2202 can be changed to a move instruction.
2204 We call here when INSN is an insn to examine or store into a bit-field.
2205 BODY is the SET-rtx to be altered.
2207 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2208 (Currently this is called only from function.c, and EQUIV_MEM
2209 is always 0.) */
2211 static void
2212 optimize_bit_field (body, insn, equiv_mem)
2213 rtx body;
2214 rtx insn;
2215 rtx *equiv_mem;
2217 register rtx bitfield;
2218 int destflag;
2219 rtx seq = 0;
2220 enum machine_mode mode;
2222 if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
2223 || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
2224 bitfield = SET_DEST (body), destflag = 1;
2225 else
2226 bitfield = SET_SRC (body), destflag = 0;
2228 /* First check that the field being stored has constant size and position
2229 and is in fact a byte or halfword suitably aligned. */
2231 if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
2232 && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
2233 && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
2234 != BLKmode)
2235 && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
2237 register rtx memref = 0;
2239 /* Now check that the containing word is memory, not a register,
2240 and that it is safe to change the machine mode. */
2242 if (GET_CODE (XEXP (bitfield, 0)) == MEM)
2243 memref = XEXP (bitfield, 0);
2244 else if (GET_CODE (XEXP (bitfield, 0)) == REG
2245 && equiv_mem != 0)
2246 memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
2247 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2248 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
2249 memref = SUBREG_REG (XEXP (bitfield, 0));
2250 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2251 && equiv_mem != 0
2252 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
2253 memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
2255 if (memref
2256 && ! mode_dependent_address_p (XEXP (memref, 0))
2257 && ! MEM_VOLATILE_P (memref))
2259 /* Now adjust the address, first for any subreg'ing
2260 that we are now getting rid of,
2261 and then for which byte of the word is wanted. */
2263 register int offset = INTVAL (XEXP (bitfield, 2));
2264 rtx insns;
2266 /* Adjust OFFSET to count bits from low-address byte. */
2267 if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN)
2268 offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
2269 - offset - INTVAL (XEXP (bitfield, 1)));
2271 /* Adjust OFFSET to count bytes from low-address byte. */
2272 offset /= BITS_PER_UNIT;
2273 if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
2275 offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD;
2276 if (BYTES_BIG_ENDIAN)
2277 offset -= (MIN (UNITS_PER_WORD,
2278 GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
2279 - MIN (UNITS_PER_WORD,
2280 GET_MODE_SIZE (GET_MODE (memref))));
2283 start_sequence ();
2284 memref = change_address (memref, mode,
2285 plus_constant (XEXP (memref, 0), offset));
2286 insns = get_insns ();
2287 end_sequence ();
2288 emit_insns_before (insns, insn);
2290 /* Store this memory reference where
2291 we found the bit field reference. */
2293 if (destflag)
2295 validate_change (insn, &SET_DEST (body), memref, 1);
2296 if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
2298 rtx src = SET_SRC (body);
2299 while (GET_CODE (src) == SUBREG
2300 && SUBREG_WORD (src) == 0)
2301 src = SUBREG_REG (src);
2302 if (GET_MODE (src) != GET_MODE (memref))
2303 src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
2304 validate_change (insn, &SET_SRC (body), src, 1);
2306 else if (GET_MODE (SET_SRC (body)) != VOIDmode
2307 && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
2308 /* This shouldn't happen because anything that didn't have
2309 one of these modes should have got converted explicitly
2310 and then referenced through a subreg.
2311 This is so because the original bit-field was
2312 handled by agg_mode and so its tree structure had
2313 the same mode that memref now has. */
2314 abort ();
2316 else
2318 rtx dest = SET_DEST (body);
2320 while (GET_CODE (dest) == SUBREG
2321 && SUBREG_WORD (dest) == 0
2322 && (GET_MODE_CLASS (GET_MODE (dest))
2323 == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest)))))
2324 dest = SUBREG_REG (dest);
2326 validate_change (insn, &SET_DEST (body), dest, 1);
2328 if (GET_MODE (dest) == GET_MODE (memref))
2329 validate_change (insn, &SET_SRC (body), memref, 1);
2330 else
2332 /* Convert the mem ref to the destination mode. */
2333 rtx newreg = gen_reg_rtx (GET_MODE (dest));
2335 start_sequence ();
2336 convert_move (newreg, memref,
2337 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
2338 seq = get_insns ();
2339 end_sequence ();
2341 validate_change (insn, &SET_SRC (body), newreg, 1);
2345 /* See if we can convert this extraction or insertion into
2346 a simple move insn. We might not be able to do so if this
2347 was, for example, part of a PARALLEL.
2349 If we succeed, write out any needed conversions. If we fail,
2350 it is hard to guess why we failed, so don't do anything
2351 special; just let the optimization be suppressed. */
2353 if (apply_change_group () && seq)
2354 emit_insns_before (seq, insn);
2359 /* These routines are responsible for converting virtual register references
2360 to the actual hard register references once RTL generation is complete.
2362 The following four variables are used for communication between the
2363 routines. They contain the offsets of the virtual registers from their
2364 respective hard registers. */
2366 static int in_arg_offset;
2367 static int var_offset;
2368 static int dynamic_offset;
2369 static int out_arg_offset;
2371 /* In most machines, the stack pointer register is equivalent to the bottom
2372 of the stack. */
2374 #ifndef STACK_POINTER_OFFSET
2375 #define STACK_POINTER_OFFSET 0
2376 #endif
2378 /* If not defined, pick an appropriate default for the offset of dynamically
2379 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2380 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2382 #ifndef STACK_DYNAMIC_OFFSET
2384 #ifdef ACCUMULATE_OUTGOING_ARGS
2385 /* The bottom of the stack points to the actual arguments. If
2386 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2387 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2388 stack space for register parameters is not pushed by the caller, but
2389 rather part of the fixed stack areas and hence not included in
2390 `current_function_outgoing_args_size'. Nevertheless, we must allow
2391 for it when allocating stack dynamic objects. */
2393 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2394 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2395 (current_function_outgoing_args_size \
2396 + REG_PARM_STACK_SPACE (FNDECL) + (STACK_POINTER_OFFSET))
2398 #else
2399 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2400 (current_function_outgoing_args_size + (STACK_POINTER_OFFSET))
2401 #endif
2403 #else
2404 #define STACK_DYNAMIC_OFFSET(FNDECL) STACK_POINTER_OFFSET
2405 #endif
2406 #endif
2408 /* Pass through the INSNS of function FNDECL and convert virtual register
2409 references to hard register references. */
2411 void
2412 instantiate_virtual_regs (fndecl, insns)
2413 tree fndecl;
2414 rtx insns;
2416 rtx insn;
2418 /* Compute the offsets to use for this function. */
2419 in_arg_offset = FIRST_PARM_OFFSET (fndecl);
2420 var_offset = STARTING_FRAME_OFFSET;
2421 dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
2422 out_arg_offset = STACK_POINTER_OFFSET;
2424 /* Scan all variables and parameters of this function. For each that is
2425 in memory, instantiate all virtual registers if the result is a valid
2426 address. If not, we do it later. That will handle most uses of virtual
2427 regs on many machines. */
2428 instantiate_decls (fndecl, 1);
2430 /* Initialize recognition, indicating that volatile is OK. */
2431 init_recog ();
2433 /* Scan through all the insns, instantiating every virtual register still
2434 present. */
2435 for (insn = insns; insn; insn = NEXT_INSN (insn))
2436 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
2437 || GET_CODE (insn) == CALL_INSN)
2439 instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1);
2440 instantiate_virtual_regs_1 (&REG_NOTES (insn), NULL_RTX, 0);
2443 /* Now instantiate the remaining register equivalences for debugging info.
2444 These will not be valid addresses. */
2445 instantiate_decls (fndecl, 0);
2447 /* Indicate that, from now on, assign_stack_local should use
2448 frame_pointer_rtx. */
2449 virtuals_instantiated = 1;
2452 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
2453 all virtual registers in their DECL_RTL's.
2455 If VALID_ONLY, do this only if the resulting address is still valid.
2456 Otherwise, always do it. */
2458 static void
2459 instantiate_decls (fndecl, valid_only)
2460 tree fndecl;
2461 int valid_only;
2463 tree decl;
2465 if (DECL_INLINE (fndecl))
2466 /* When compiling an inline function, the obstack used for
2467 rtl allocation is the maybepermanent_obstack. Calling
2468 `resume_temporary_allocation' switches us back to that
2469 obstack while we process this function's parameters. */
2470 resume_temporary_allocation ();
2472 /* Process all parameters of the function. */
2473 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
2475 instantiate_decl (DECL_RTL (decl), int_size_in_bytes (TREE_TYPE (decl)),
2476 valid_only);
2477 instantiate_decl (DECL_INCOMING_RTL (decl),
2478 int_size_in_bytes (TREE_TYPE (decl)), valid_only);
2481 /* Now process all variables defined in the function or its subblocks. */
2482 instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
2484 if (DECL_INLINE (fndecl))
2486 /* Save all rtl allocated for this function by raising the
2487 high-water mark on the maybepermanent_obstack. */
2488 preserve_data ();
2489 /* All further rtl allocation is now done in the current_obstack. */
2490 rtl_in_current_obstack ();
2494 /* Subroutine of instantiate_decls: Process all decls in the given
2495 BLOCK node and all its subblocks. */
2497 static void
2498 instantiate_decls_1 (let, valid_only)
2499 tree let;
2500 int valid_only;
2502 tree t;
2504 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
2505 instantiate_decl (DECL_RTL (t), int_size_in_bytes (TREE_TYPE (t)),
2506 valid_only);
2508 /* Process all subblocks. */
2509 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
2510 instantiate_decls_1 (t, valid_only);
2513 /* Subroutine of the preceding procedures: Given RTL representing a
2514 decl and the size of the object, do any instantiation required.
2516 If VALID_ONLY is non-zero, it means that the RTL should only be
2517 changed if the new address is valid. */
2519 static void
2520 instantiate_decl (x, size, valid_only)
2521 rtx x;
2522 int size;
2523 int valid_only;
2525 enum machine_mode mode;
2526 rtx addr;
2528 /* If this is not a MEM, no need to do anything. Similarly if the
2529 address is a constant or a register that is not a virtual register. */
2531 if (x == 0 || GET_CODE (x) != MEM)
2532 return;
2534 addr = XEXP (x, 0);
2535 if (CONSTANT_P (addr)
2536 || (GET_CODE (addr) == REG
2537 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
2538 || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
2539 return;
2541 /* If we should only do this if the address is valid, copy the address.
2542 We need to do this so we can undo any changes that might make the
2543 address invalid. This copy is unfortunate, but probably can't be
2544 avoided. */
2546 if (valid_only)
2547 addr = copy_rtx (addr);
2549 instantiate_virtual_regs_1 (&addr, NULL_RTX, 0);
2551 if (! valid_only)
2552 return;
2554 /* Now verify that the resulting address is valid for every integer or
2555 floating-point mode up to and including SIZE bytes long. We do this
2556 since the object might be accessed in any mode and frame addresses
2557 are shared. */
2559 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2560 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
2561 mode = GET_MODE_WIDER_MODE (mode))
2562 if (! memory_address_p (mode, addr))
2563 return;
2565 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
2566 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
2567 mode = GET_MODE_WIDER_MODE (mode))
2568 if (! memory_address_p (mode, addr))
2569 return;
2571 /* Otherwise, put back the address, now that we have updated it and we
2572 know it is valid. */
2574 XEXP (x, 0) = addr;
2577 /* Given a pointer to a piece of rtx and an optional pointer to the
2578 containing object, instantiate any virtual registers present in it.
2580 If EXTRA_INSNS, we always do the replacement and generate
2581 any extra insns before OBJECT. If it zero, we do nothing if replacement
2582 is not valid.
2584 Return 1 if we either had nothing to do or if we were able to do the
2585 needed replacement. Return 0 otherwise; we only return zero if
2586 EXTRA_INSNS is zero.
2588 We first try some simple transformations to avoid the creation of extra
2589 pseudos. */
2591 static int
2592 instantiate_virtual_regs_1 (loc, object, extra_insns)
2593 rtx *loc;
2594 rtx object;
2595 int extra_insns;
2597 rtx x;
2598 RTX_CODE code;
2599 rtx new = 0;
2600 int offset;
2601 rtx temp;
2602 rtx seq;
2603 int i, j;
2604 char *fmt;
2606 /* Re-start here to avoid recursion in common cases. */
2607 restart:
2609 x = *loc;
2610 if (x == 0)
2611 return 1;
2613 code = GET_CODE (x);
2615 /* Check for some special cases. */
2616 switch (code)
2618 case CONST_INT:
2619 case CONST_DOUBLE:
2620 case CONST:
2621 case SYMBOL_REF:
2622 case CODE_LABEL:
2623 case PC:
2624 case CC0:
2625 case ASM_INPUT:
2626 case ADDR_VEC:
2627 case ADDR_DIFF_VEC:
2628 case RETURN:
2629 return 1;
2631 case SET:
2632 /* We are allowed to set the virtual registers. This means that
2633 that the actual register should receive the source minus the
2634 appropriate offset. This is used, for example, in the handling
2635 of non-local gotos. */
2636 if (SET_DEST (x) == virtual_incoming_args_rtx)
2637 new = arg_pointer_rtx, offset = - in_arg_offset;
2638 else if (SET_DEST (x) == virtual_stack_vars_rtx)
2639 new = frame_pointer_rtx, offset = - var_offset;
2640 else if (SET_DEST (x) == virtual_stack_dynamic_rtx)
2641 new = stack_pointer_rtx, offset = - dynamic_offset;
2642 else if (SET_DEST (x) == virtual_outgoing_args_rtx)
2643 new = stack_pointer_rtx, offset = - out_arg_offset;
2645 if (new)
2647 /* The only valid sources here are PLUS or REG. Just do
2648 the simplest possible thing to handle them. */
2649 if (GET_CODE (SET_SRC (x)) != REG
2650 && GET_CODE (SET_SRC (x)) != PLUS)
2651 abort ();
2653 start_sequence ();
2654 if (GET_CODE (SET_SRC (x)) != REG)
2655 temp = force_operand (SET_SRC (x), NULL_RTX);
2656 else
2657 temp = SET_SRC (x);
2658 temp = force_operand (plus_constant (temp, offset), NULL_RTX);
2659 seq = get_insns ();
2660 end_sequence ();
2662 emit_insns_before (seq, object);
2663 SET_DEST (x) = new;
2665 if (!validate_change (object, &SET_SRC (x), temp, 0)
2666 || ! extra_insns)
2667 abort ();
2669 return 1;
2672 instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns);
2673 loc = &SET_SRC (x);
2674 goto restart;
2676 case PLUS:
2677 /* Handle special case of virtual register plus constant. */
2678 if (CONSTANT_P (XEXP (x, 1)))
2680 rtx old, new_offset;
2682 /* Check for (plus (plus VIRT foo) (const_int)) first. */
2683 if (GET_CODE (XEXP (x, 0)) == PLUS)
2685 rtx inner = XEXP (XEXP (x, 0), 0);
2687 if (inner == virtual_incoming_args_rtx)
2688 new = arg_pointer_rtx, offset = in_arg_offset;
2689 else if (inner == virtual_stack_vars_rtx)
2690 new = frame_pointer_rtx, offset = var_offset;
2691 else if (inner == virtual_stack_dynamic_rtx)
2692 new = stack_pointer_rtx, offset = dynamic_offset;
2693 else if (inner == virtual_outgoing_args_rtx)
2694 new = stack_pointer_rtx, offset = out_arg_offset;
2695 else
2697 loc = &XEXP (x, 0);
2698 goto restart;
2701 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object,
2702 extra_insns);
2703 new = gen_rtx (PLUS, Pmode, new, XEXP (XEXP (x, 0), 1));
2706 else if (XEXP (x, 0) == virtual_incoming_args_rtx)
2707 new = arg_pointer_rtx, offset = in_arg_offset;
2708 else if (XEXP (x, 0) == virtual_stack_vars_rtx)
2709 new = frame_pointer_rtx, offset = var_offset;
2710 else if (XEXP (x, 0) == virtual_stack_dynamic_rtx)
2711 new = stack_pointer_rtx, offset = dynamic_offset;
2712 else if (XEXP (x, 0) == virtual_outgoing_args_rtx)
2713 new = stack_pointer_rtx, offset = out_arg_offset;
2714 else
2716 /* We know the second operand is a constant. Unless the
2717 first operand is a REG (which has been already checked),
2718 it needs to be checked. */
2719 if (GET_CODE (XEXP (x, 0)) != REG)
2721 loc = &XEXP (x, 0);
2722 goto restart;
2724 return 1;
2727 new_offset = plus_constant (XEXP (x, 1), offset);
2729 /* If the new constant is zero, try to replace the sum with just
2730 the register. */
2731 if (new_offset == const0_rtx
2732 && validate_change (object, loc, new, 0))
2733 return 1;
2735 /* Next try to replace the register and new offset.
2736 There are two changes to validate here and we can't assume that
2737 in the case of old offset equals new just changing the register
2738 will yield a valid insn. In the interests of a little efficiency,
2739 however, we only call validate change once (we don't queue up the
2740 changes and then call apply_change_group). */
2742 old = XEXP (x, 0);
2743 if (offset == 0
2744 ? ! validate_change (object, &XEXP (x, 0), new, 0)
2745 : (XEXP (x, 0) = new,
2746 ! validate_change (object, &XEXP (x, 1), new_offset, 0)))
2748 if (! extra_insns)
2750 XEXP (x, 0) = old;
2751 return 0;
2754 /* Otherwise copy the new constant into a register and replace
2755 constant with that register. */
2756 temp = gen_reg_rtx (Pmode);
2757 XEXP (x, 0) = new;
2758 if (validate_change (object, &XEXP (x, 1), temp, 0))
2759 emit_insn_before (gen_move_insn (temp, new_offset), object);
2760 else
2762 /* If that didn't work, replace this expression with a
2763 register containing the sum. */
2765 XEXP (x, 0) = old;
2766 new = gen_rtx (PLUS, Pmode, new, new_offset);
2768 start_sequence ();
2769 temp = force_operand (new, NULL_RTX);
2770 seq = get_insns ();
2771 end_sequence ();
2773 emit_insns_before (seq, object);
2774 if (! validate_change (object, loc, temp, 0)
2775 && ! validate_replace_rtx (x, temp, object))
2776 abort ();
2780 return 1;
2783 /* Fall through to generic two-operand expression case. */
2784 case EXPR_LIST:
2785 case CALL:
2786 case COMPARE:
2787 case MINUS:
2788 case MULT:
2789 case DIV: case UDIV:
2790 case MOD: case UMOD:
2791 case AND: case IOR: case XOR:
2792 case ROTATERT: case ROTATE:
2793 case ASHIFTRT: case LSHIFTRT: case ASHIFT:
2794 case NE: case EQ:
2795 case GE: case GT: case GEU: case GTU:
2796 case LE: case LT: case LEU: case LTU:
2797 if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
2798 instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns);
2799 loc = &XEXP (x, 0);
2800 goto restart;
2802 case MEM:
2803 /* Most cases of MEM that convert to valid addresses have already been
2804 handled by our scan of regno_reg_rtx. The only special handling we
2805 need here is to make a copy of the rtx to ensure it isn't being
2806 shared if we have to change it to a pseudo.
2808 If the rtx is a simple reference to an address via a virtual register,
2809 it can potentially be shared. In such cases, first try to make it
2810 a valid address, which can also be shared. Otherwise, copy it and
2811 proceed normally.
2813 First check for common cases that need no processing. These are
2814 usually due to instantiation already being done on a previous instance
2815 of a shared rtx. */
2817 temp = XEXP (x, 0);
2818 if (CONSTANT_ADDRESS_P (temp)
2819 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2820 || temp == arg_pointer_rtx
2821 #endif
2822 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2823 || temp == hard_frame_pointer_rtx
2824 #endif
2825 || temp == frame_pointer_rtx)
2826 return 1;
2828 if (GET_CODE (temp) == PLUS
2829 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
2830 && (XEXP (temp, 0) == frame_pointer_rtx
2831 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2832 || XEXP (temp, 0) == hard_frame_pointer_rtx
2833 #endif
2834 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
2835 || XEXP (temp, 0) == arg_pointer_rtx
2836 #endif
2838 return 1;
2840 if (temp == virtual_stack_vars_rtx
2841 || temp == virtual_incoming_args_rtx
2842 || (GET_CODE (temp) == PLUS
2843 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
2844 && (XEXP (temp, 0) == virtual_stack_vars_rtx
2845 || XEXP (temp, 0) == virtual_incoming_args_rtx)))
2847 /* This MEM may be shared. If the substitution can be done without
2848 the need to generate new pseudos, we want to do it in place
2849 so all copies of the shared rtx benefit. The call below will
2850 only make substitutions if the resulting address is still
2851 valid.
2853 Note that we cannot pass X as the object in the recursive call
2854 since the insn being processed may not allow all valid
2855 addresses. However, if we were not passed on object, we can
2856 only modify X without copying it if X will have a valid
2857 address.
2859 ??? Also note that this can still lose if OBJECT is an insn that
2860 has less restrictions on an address that some other insn.
2861 In that case, we will modify the shared address. This case
2862 doesn't seem very likely, though. */
2864 if (instantiate_virtual_regs_1 (&XEXP (x, 0),
2865 object ? object : x, 0))
2866 return 1;
2868 /* Otherwise make a copy and process that copy. We copy the entire
2869 RTL expression since it might be a PLUS which could also be
2870 shared. */
2871 *loc = x = copy_rtx (x);
2874 /* Fall through to generic unary operation case. */
2875 case USE:
2876 case CLOBBER:
2877 case SUBREG:
2878 case STRICT_LOW_PART:
2879 case NEG: case NOT:
2880 case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC:
2881 case SIGN_EXTEND: case ZERO_EXTEND:
2882 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE:
2883 case FLOAT: case FIX:
2884 case UNSIGNED_FIX: case UNSIGNED_FLOAT:
2885 case ABS:
2886 case SQRT:
2887 case FFS:
2888 /* These case either have just one operand or we know that we need not
2889 check the rest of the operands. */
2890 loc = &XEXP (x, 0);
2891 goto restart;
2893 case REG:
2894 /* Try to replace with a PLUS. If that doesn't work, compute the sum
2895 in front of this insn and substitute the temporary. */
2896 if (x == virtual_incoming_args_rtx)
2897 new = arg_pointer_rtx, offset = in_arg_offset;
2898 else if (x == virtual_stack_vars_rtx)
2899 new = frame_pointer_rtx, offset = var_offset;
2900 else if (x == virtual_stack_dynamic_rtx)
2901 new = stack_pointer_rtx, offset = dynamic_offset;
2902 else if (x == virtual_outgoing_args_rtx)
2903 new = stack_pointer_rtx, offset = out_arg_offset;
2905 if (new)
2907 temp = plus_constant (new, offset);
2908 if (!validate_change (object, loc, temp, 0))
2910 if (! extra_insns)
2911 return 0;
2913 start_sequence ();
2914 temp = force_operand (temp, NULL_RTX);
2915 seq = get_insns ();
2916 end_sequence ();
2918 emit_insns_before (seq, object);
2919 if (! validate_change (object, loc, temp, 0)
2920 && ! validate_replace_rtx (x, temp, object))
2921 abort ();
2925 return 1;
2928 /* Scan all subexpressions. */
2929 fmt = GET_RTX_FORMAT (code);
2930 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
2931 if (*fmt == 'e')
2933 if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns))
2934 return 0;
2936 else if (*fmt == 'E')
2937 for (j = 0; j < XVECLEN (x, i); j++)
2938 if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object,
2939 extra_insns))
2940 return 0;
2942 return 1;
2945 /* Optimization: assuming this function does not receive nonlocal gotos,
2946 delete the handlers for such, as well as the insns to establish
2947 and disestablish them. */
2949 static void
2950 delete_handlers ()
2952 rtx insn;
2953 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2955 /* Delete the handler by turning off the flag that would
2956 prevent jump_optimize from deleting it.
2957 Also permit deletion of the nonlocal labels themselves
2958 if nothing local refers to them. */
2959 if (GET_CODE (insn) == CODE_LABEL)
2961 tree t, last_t;
2963 LABEL_PRESERVE_P (insn) = 0;
2965 /* Remove it from the nonlocal_label list, to avoid confusing
2966 flow. */
2967 for (t = nonlocal_labels, last_t = 0; t;
2968 last_t = t, t = TREE_CHAIN (t))
2969 if (DECL_RTL (TREE_VALUE (t)) == insn)
2970 break;
2971 if (t)
2973 if (! last_t)
2974 nonlocal_labels = TREE_CHAIN (nonlocal_labels);
2975 else
2976 TREE_CHAIN (last_t) = TREE_CHAIN (t);
2979 if (GET_CODE (insn) == INSN
2980 && ((nonlocal_goto_handler_slot != 0
2981 && reg_mentioned_p (nonlocal_goto_handler_slot, PATTERN (insn)))
2982 || (nonlocal_goto_stack_level != 0
2983 && reg_mentioned_p (nonlocal_goto_stack_level,
2984 PATTERN (insn)))))
2985 delete_insn (insn);
2989 /* Return a list (chain of EXPR_LIST nodes) for the nonlocal labels
2990 of the current function. */
2993 nonlocal_label_rtx_list ()
2995 tree t;
2996 rtx x = 0;
2998 for (t = nonlocal_labels; t; t = TREE_CHAIN (t))
2999 x = gen_rtx (EXPR_LIST, VOIDmode, label_rtx (TREE_VALUE (t)), x);
3001 return x;
3004 /* Output a USE for any register use in RTL.
3005 This is used with -noreg to mark the extent of lifespan
3006 of any registers used in a user-visible variable's DECL_RTL. */
3008 void
3009 use_variable (rtl)
3010 rtx rtl;
3012 if (GET_CODE (rtl) == REG)
3013 /* This is a register variable. */
3014 emit_insn (gen_rtx (USE, VOIDmode, rtl));
3015 else if (GET_CODE (rtl) == MEM
3016 && GET_CODE (XEXP (rtl, 0)) == REG
3017 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
3018 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
3019 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
3020 /* This is a variable-sized structure. */
3021 emit_insn (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)));
3024 /* Like use_variable except that it outputs the USEs after INSN
3025 instead of at the end of the insn-chain. */
3027 void
3028 use_variable_after (rtl, insn)
3029 rtx rtl, insn;
3031 if (GET_CODE (rtl) == REG)
3032 /* This is a register variable. */
3033 emit_insn_after (gen_rtx (USE, VOIDmode, rtl), insn);
3034 else if (GET_CODE (rtl) == MEM
3035 && GET_CODE (XEXP (rtl, 0)) == REG
3036 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
3037 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
3038 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
3039 /* This is a variable-sized structure. */
3040 emit_insn_after (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)), insn);
3044 max_parm_reg_num ()
3046 return max_parm_reg;
3049 /* Return the first insn following those generated by `assign_parms'. */
3052 get_first_nonparm_insn ()
3054 if (last_parm_insn)
3055 return NEXT_INSN (last_parm_insn);
3056 return get_insns ();
3059 /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
3060 Crash if there is none. */
3063 get_first_block_beg ()
3065 register rtx searcher;
3066 register rtx insn = get_first_nonparm_insn ();
3068 for (searcher = insn; searcher; searcher = NEXT_INSN (searcher))
3069 if (GET_CODE (searcher) == NOTE
3070 && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG)
3071 return searcher;
3073 abort (); /* Invalid call to this function. (See comments above.) */
3074 return NULL_RTX;
3077 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
3078 This means a type for which function calls must pass an address to the
3079 function or get an address back from the function.
3080 EXP may be a type node or an expression (whose type is tested). */
3083 aggregate_value_p (exp)
3084 tree exp;
3086 int i, regno, nregs;
3087 rtx reg;
3088 tree type;
3089 if (TREE_CODE_CLASS (TREE_CODE (exp)) == 't')
3090 type = exp;
3091 else
3092 type = TREE_TYPE (exp);
3094 if (RETURN_IN_MEMORY (type))
3095 return 1;
3096 if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
3097 return 1;
3098 /* Make sure we have suitable call-clobbered regs to return
3099 the value in; if not, we must return it in memory. */
3100 reg = hard_function_value (type, 0);
3101 regno = REGNO (reg);
3102 nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type));
3103 for (i = 0; i < nregs; i++)
3104 if (! call_used_regs[regno + i])
3105 return 1;
3106 return 0;
3109 /* Assign RTL expressions to the function's parameters.
3110 This may involve copying them into registers and using
3111 those registers as the RTL for them.
3113 If SECOND_TIME is non-zero it means that this function is being
3114 called a second time. This is done by integrate.c when a function's
3115 compilation is deferred. We need to come back here in case the
3116 FUNCTION_ARG macro computes items needed for the rest of the compilation
3117 (such as changing which registers are fixed or caller-saved). But suppress
3118 writing any insns or setting DECL_RTL of anything in this case. */
3120 void
3121 assign_parms (fndecl, second_time)
3122 tree fndecl;
3123 int second_time;
3125 register tree parm;
3126 register rtx entry_parm = 0;
3127 register rtx stack_parm = 0;
3128 CUMULATIVE_ARGS args_so_far;
3129 enum machine_mode promoted_mode, passed_mode, nominal_mode;
3130 int unsignedp;
3131 /* Total space needed so far for args on the stack,
3132 given as a constant and a tree-expression. */
3133 struct args_size stack_args_size;
3134 tree fntype = TREE_TYPE (fndecl);
3135 tree fnargs = DECL_ARGUMENTS (fndecl);
3136 /* This is used for the arg pointer when referring to stack args. */
3137 rtx internal_arg_pointer;
3138 /* This is a dummy PARM_DECL that we used for the function result if
3139 the function returns a structure. */
3140 tree function_result_decl = 0;
3141 int nparmregs = list_length (fnargs) + LAST_VIRTUAL_REGISTER + 1;
3142 int varargs_setup = 0;
3143 rtx conversion_insns = 0;
3144 /* FUNCTION_ARG may look at this variable. Since this is not
3145 expanding a call it will always be zero in this function. */
3146 int current_call_is_indirect = 0;
3148 /* Nonzero if the last arg is named `__builtin_va_alist',
3149 which is used on some machines for old-fashioned non-ANSI varargs.h;
3150 this should be stuck onto the stack as if it had arrived there. */
3151 int hide_last_arg
3152 = (current_function_varargs
3153 && fnargs
3154 && (parm = tree_last (fnargs)) != 0
3155 && DECL_NAME (parm)
3156 && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
3157 "__builtin_va_alist")));
3159 /* Nonzero if function takes extra anonymous args.
3160 This means the last named arg must be on the stack
3161 right before the anonymous ones. */
3162 int stdarg
3163 = (TYPE_ARG_TYPES (fntype) != 0
3164 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3165 != void_type_node));
3167 /* If the reg that the virtual arg pointer will be translated into is
3168 not a fixed reg or is the stack pointer, make a copy of the virtual
3169 arg pointer, and address parms via the copy. The frame pointer is
3170 considered fixed even though it is not marked as such.
3172 The second time through, simply use ap to avoid generating rtx. */
3174 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
3175 || ! (fixed_regs[ARG_POINTER_REGNUM]
3176 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM))
3177 && ! second_time)
3178 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
3179 else
3180 internal_arg_pointer = virtual_incoming_args_rtx;
3181 current_function_internal_arg_pointer = internal_arg_pointer;
3183 stack_args_size.constant = 0;
3184 stack_args_size.var = 0;
3186 /* If struct value address is treated as the first argument, make it so. */
3187 if (aggregate_value_p (DECL_RESULT (fndecl))
3188 && ! current_function_returns_pcc_struct
3189 && struct_value_incoming_rtx == 0)
3191 tree type = build_pointer_type (fntype);
3193 function_result_decl = build_decl (PARM_DECL, NULL_TREE, type);
3195 DECL_ARG_TYPE (function_result_decl) = type;
3196 TREE_CHAIN (function_result_decl) = fnargs;
3197 fnargs = function_result_decl;
3200 parm_reg_stack_loc = (rtx *) oballoc (nparmregs * sizeof (rtx));
3201 bzero ((char *) parm_reg_stack_loc, nparmregs * sizeof (rtx));
3203 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
3204 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX);
3205 #else
3206 INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX);
3207 #endif
3209 /* We haven't yet found an argument that we must push and pretend the
3210 caller did. */
3211 current_function_pretend_args_size = 0;
3213 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
3215 int aggregate = AGGREGATE_TYPE_P (TREE_TYPE (parm));
3216 struct args_size stack_offset;
3217 struct args_size arg_size;
3218 int passed_pointer = 0;
3219 tree passed_type = DECL_ARG_TYPE (parm);
3221 /* Set LAST_NAMED if this is last named arg before some
3222 anonymous args. We treat it as if it were anonymous too. */
3223 int last_named = ((TREE_CHAIN (parm) == 0
3224 || DECL_NAME (TREE_CHAIN (parm)) == 0)
3225 && (stdarg || current_function_varargs));
3227 if (TREE_TYPE (parm) == error_mark_node
3228 /* This can happen after weird syntax errors
3229 or if an enum type is defined among the parms. */
3230 || TREE_CODE (parm) != PARM_DECL
3231 || passed_type == NULL)
3233 DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = gen_rtx (MEM, BLKmode,
3234 const0_rtx);
3235 TREE_USED (parm) = 1;
3236 continue;
3239 /* For varargs.h function, save info about regs and stack space
3240 used by the individual args, not including the va_alist arg. */
3241 if (hide_last_arg && last_named)
3242 current_function_args_info = args_so_far;
3244 /* Find mode of arg as it is passed, and mode of arg
3245 as it should be during execution of this function. */
3246 passed_mode = TYPE_MODE (passed_type);
3247 nominal_mode = TYPE_MODE (TREE_TYPE (parm));
3249 /* If the parm's mode is VOID, its value doesn't matter,
3250 and avoid the usual things like emit_move_insn that could crash. */
3251 if (nominal_mode == VOIDmode)
3253 DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = const0_rtx;
3254 continue;
3257 /* If the parm is to be passed as a transparent union, use the
3258 type of the first field for the tests below. We have already
3259 verified that the modes are the same. */
3260 if (DECL_TRANSPARENT_UNION (parm)
3261 || TYPE_TRANSPARENT_UNION (passed_type))
3262 passed_type = TREE_TYPE (TYPE_FIELDS (passed_type));
3264 /* See if this arg was passed by invisible reference. It is if
3265 it is an object whose size depends on the contents of the
3266 object itself or if the machine requires these objects be passed
3267 that way. */
3269 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
3270 && contains_placeholder_p (TYPE_SIZE (passed_type)))
3271 || TYPE_NEEDS_CONSTRUCTING (passed_type)
3272 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
3273 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
3274 passed_type, ! last_named)
3275 #endif
3278 passed_type = build_pointer_type (passed_type);
3279 passed_pointer = 1;
3280 passed_mode = nominal_mode = Pmode;
3283 promoted_mode = passed_mode;
3285 #ifdef PROMOTE_FUNCTION_ARGS
3286 /* Compute the mode in which the arg is actually extended to. */
3287 promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1);
3288 #endif
3290 /* Let machine desc say which reg (if any) the parm arrives in.
3291 0 means it arrives on the stack. */
3292 #ifdef FUNCTION_INCOMING_ARG
3293 entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
3294 passed_type, ! last_named);
3295 #else
3296 entry_parm = FUNCTION_ARG (args_so_far, promoted_mode,
3297 passed_type, ! last_named);
3298 #endif
3300 if (entry_parm)
3301 passed_mode = promoted_mode;
3303 #ifdef SETUP_INCOMING_VARARGS
3304 /* If this is the last named parameter, do any required setup for
3305 varargs or stdargs. We need to know about the case of this being an
3306 addressable type, in which case we skip the registers it
3307 would have arrived in.
3309 For stdargs, LAST_NAMED will be set for two parameters, the one that
3310 is actually the last named, and the dummy parameter. We only
3311 want to do this action once.
3313 Also, indicate when RTL generation is to be suppressed. */
3314 if (last_named && !varargs_setup)
3316 SETUP_INCOMING_VARARGS (args_so_far, passed_mode, passed_type,
3317 current_function_pretend_args_size,
3318 second_time);
3319 varargs_setup = 1;
3321 #endif
3323 /* Determine parm's home in the stack,
3324 in case it arrives in the stack or we should pretend it did.
3326 Compute the stack position and rtx where the argument arrives
3327 and its size.
3329 There is one complexity here: If this was a parameter that would
3330 have been passed in registers, but wasn't only because it is
3331 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
3332 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
3333 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
3334 0 as it was the previous time. */
3336 locate_and_pad_parm (passed_mode, passed_type,
3337 #ifdef STACK_PARMS_IN_REG_PARM_AREA
3339 #else
3340 #ifdef FUNCTION_INCOMING_ARG
3341 FUNCTION_INCOMING_ARG (args_so_far, passed_mode,
3342 passed_type,
3343 (! last_named
3344 || varargs_setup)) != 0,
3345 #else
3346 FUNCTION_ARG (args_so_far, passed_mode,
3347 passed_type,
3348 ! last_named || varargs_setup) != 0,
3349 #endif
3350 #endif
3351 fndecl, &stack_args_size, &stack_offset, &arg_size);
3353 if (! second_time)
3355 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
3357 if (offset_rtx == const0_rtx)
3358 stack_parm = gen_rtx (MEM, passed_mode, internal_arg_pointer);
3359 else
3360 stack_parm = gen_rtx (MEM, passed_mode,
3361 gen_rtx (PLUS, Pmode,
3362 internal_arg_pointer, offset_rtx));
3364 /* If this is a memory ref that contains aggregate components,
3365 mark it as such for cse and loop optimize. */
3366 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3369 /* If this parameter was passed both in registers and in the stack,
3370 use the copy on the stack. */
3371 if (MUST_PASS_IN_STACK (passed_mode, passed_type))
3372 entry_parm = 0;
3374 #ifdef FUNCTION_ARG_PARTIAL_NREGS
3375 /* If this parm was passed part in regs and part in memory,
3376 pretend it arrived entirely in memory
3377 by pushing the register-part onto the stack.
3379 In the special case of a DImode or DFmode that is split,
3380 we could put it together in a pseudoreg directly,
3381 but for now that's not worth bothering with. */
3383 if (entry_parm)
3385 int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, passed_mode,
3386 passed_type, ! last_named);
3388 if (nregs > 0)
3390 current_function_pretend_args_size
3391 = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
3392 / (PARM_BOUNDARY / BITS_PER_UNIT)
3393 * (PARM_BOUNDARY / BITS_PER_UNIT));
3395 if (! second_time)
3396 move_block_from_reg (REGNO (entry_parm),
3397 validize_mem (stack_parm), nregs,
3398 int_size_in_bytes (TREE_TYPE (parm)));
3399 entry_parm = stack_parm;
3402 #endif
3404 /* If we didn't decide this parm came in a register,
3405 by default it came on the stack. */
3406 if (entry_parm == 0)
3407 entry_parm = stack_parm;
3409 /* Record permanently how this parm was passed. */
3410 if (! second_time)
3411 DECL_INCOMING_RTL (parm) = entry_parm;
3413 /* If there is actually space on the stack for this parm,
3414 count it in stack_args_size; otherwise set stack_parm to 0
3415 to indicate there is no preallocated stack slot for the parm. */
3417 if (entry_parm == stack_parm
3418 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
3419 /* On some machines, even if a parm value arrives in a register
3420 there is still an (uninitialized) stack slot allocated for it.
3422 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
3423 whether this parameter already has a stack slot allocated,
3424 because an arg block exists only if current_function_args_size
3425 is larger than some threshhold, and we haven't calculated that
3426 yet. So, for now, we just assume that stack slots never exist
3427 in this case. */
3428 || REG_PARM_STACK_SPACE (fndecl) > 0
3429 #endif
3432 stack_args_size.constant += arg_size.constant;
3433 if (arg_size.var)
3434 ADD_PARM_SIZE (stack_args_size, arg_size.var);
3436 else
3437 /* No stack slot was pushed for this parm. */
3438 stack_parm = 0;
3440 /* Update info on where next arg arrives in registers. */
3442 FUNCTION_ARG_ADVANCE (args_so_far, passed_mode,
3443 passed_type, ! last_named);
3445 /* If this is our second time through, we are done with this parm. */
3446 if (second_time)
3447 continue;
3449 /* If we can't trust the parm stack slot to be aligned enough
3450 for its ultimate type, don't use that slot after entry.
3451 We'll make another stack slot, if we need one. */
3453 int thisparm_boundary
3454 = FUNCTION_ARG_BOUNDARY (passed_mode, passed_type);
3456 if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary)
3457 stack_parm = 0;
3460 /* If parm was passed in memory, and we need to convert it on entry,
3461 don't store it back in that same slot. */
3462 if (entry_parm != 0
3463 && nominal_mode != BLKmode && nominal_mode != passed_mode)
3464 stack_parm = 0;
3466 #if 0
3467 /* Now adjust STACK_PARM to the mode and precise location
3468 where this parameter should live during execution,
3469 if we discover that it must live in the stack during execution.
3470 To make debuggers happier on big-endian machines, we store
3471 the value in the last bytes of the space available. */
3473 if (nominal_mode != BLKmode && nominal_mode != passed_mode
3474 && stack_parm != 0)
3476 rtx offset_rtx;
3478 if (BYTES_BIG_ENDIAN
3479 && GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD)
3480 stack_offset.constant += (GET_MODE_SIZE (passed_mode)
3481 - GET_MODE_SIZE (nominal_mode));
3483 offset_rtx = ARGS_SIZE_RTX (stack_offset);
3484 if (offset_rtx == const0_rtx)
3485 stack_parm = gen_rtx (MEM, nominal_mode, internal_arg_pointer);
3486 else
3487 stack_parm = gen_rtx (MEM, nominal_mode,
3488 gen_rtx (PLUS, Pmode,
3489 internal_arg_pointer, offset_rtx));
3491 /* If this is a memory ref that contains aggregate components,
3492 mark it as such for cse and loop optimize. */
3493 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3495 #endif /* 0 */
3497 /* ENTRY_PARM is an RTX for the parameter as it arrives,
3498 in the mode in which it arrives.
3499 STACK_PARM is an RTX for a stack slot where the parameter can live
3500 during the function (in case we want to put it there).
3501 STACK_PARM is 0 if no stack slot was pushed for it.
3503 Now output code if necessary to convert ENTRY_PARM to
3504 the type in which this function declares it,
3505 and store that result in an appropriate place,
3506 which may be a pseudo reg, may be STACK_PARM,
3507 or may be a local stack slot if STACK_PARM is 0.
3509 Set DECL_RTL to that place. */
3511 if (nominal_mode == BLKmode)
3513 /* If a BLKmode arrives in registers, copy it to a stack slot. */
3514 if (GET_CODE (entry_parm) == REG)
3516 int size_stored = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
3517 UNITS_PER_WORD);
3519 /* Note that we will be storing an integral number of words.
3520 So we have to be careful to ensure that we allocate an
3521 integral number of words. We do this below in the
3522 assign_stack_local if space was not allocated in the argument
3523 list. If it was, this will not work if PARM_BOUNDARY is not
3524 a multiple of BITS_PER_WORD. It isn't clear how to fix this
3525 if it becomes a problem. */
3527 if (stack_parm == 0)
3529 stack_parm
3530 = assign_stack_local (GET_MODE (entry_parm), size_stored, 0);
3531 /* If this is a memory ref that contains aggregate components,
3532 mark it as such for cse and loop optimize. */
3533 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3536 else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
3537 abort ();
3539 if (TREE_READONLY (parm))
3540 RTX_UNCHANGING_P (stack_parm) = 1;
3542 move_block_from_reg (REGNO (entry_parm),
3543 validize_mem (stack_parm),
3544 size_stored / UNITS_PER_WORD,
3545 int_size_in_bytes (TREE_TYPE (parm)));
3547 DECL_RTL (parm) = stack_parm;
3549 else if (! ((obey_regdecls && ! DECL_REGISTER (parm)
3550 && ! DECL_INLINE (fndecl))
3551 /* layout_decl may set this. */
3552 || TREE_ADDRESSABLE (parm)
3553 || TREE_SIDE_EFFECTS (parm)
3554 /* If -ffloat-store specified, don't put explicit
3555 float variables into registers. */
3556 || (flag_float_store
3557 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
3558 /* Always assign pseudo to structure return or item passed
3559 by invisible reference. */
3560 || passed_pointer || parm == function_result_decl)
3562 /* Store the parm in a pseudoregister during the function, but we
3563 may need to do it in a wider mode. */
3565 register rtx parmreg;
3566 int regno, regnoi, regnor;
3568 unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
3569 nominal_mode = promote_mode (TREE_TYPE (parm), nominal_mode,
3570 &unsignedp, 1);
3572 parmreg = gen_reg_rtx (nominal_mode);
3573 REG_USERVAR_P (parmreg) = 1;
3575 /* If this was an item that we received a pointer to, set DECL_RTL
3576 appropriately. */
3577 if (passed_pointer)
3579 DECL_RTL (parm) = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (passed_type)), parmreg);
3580 MEM_IN_STRUCT_P (DECL_RTL (parm)) = aggregate;
3582 else
3583 DECL_RTL (parm) = parmreg;
3585 /* Copy the value into the register. */
3586 if (GET_MODE (parmreg) != GET_MODE (entry_parm))
3588 /* If ENTRY_PARM is a hard register, it might be in a register
3589 not valid for operating in its mode (e.g., an odd-numbered
3590 register for a DFmode). In that case, moves are the only
3591 thing valid, so we can't do a convert from there. This
3592 occurs when the calling sequence allow such misaligned
3593 usages.
3595 In addition, the conversion may involve a call, which could
3596 clobber parameters which haven't been copied to pseudo
3597 registers yet. Therefore, we must first copy the parm to
3598 a pseudo reg here, and save the conversion until after all
3599 parameters have been moved. */
3601 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
3603 emit_move_insn (tempreg, validize_mem (entry_parm));
3605 push_to_sequence (conversion_insns);
3606 convert_move (parmreg, tempreg, unsignedp);
3607 conversion_insns = get_insns ();
3608 end_sequence ();
3610 else
3611 emit_move_insn (parmreg, validize_mem (entry_parm));
3613 /* If we were passed a pointer but the actual value
3614 can safely live in a register, put it in one. */
3615 if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
3616 && ! ((obey_regdecls && ! DECL_REGISTER (parm)
3617 && ! DECL_INLINE (fndecl))
3618 /* layout_decl may set this. */
3619 || TREE_ADDRESSABLE (parm)
3620 || TREE_SIDE_EFFECTS (parm)
3621 /* If -ffloat-store specified, don't put explicit
3622 float variables into registers. */
3623 || (flag_float_store
3624 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))
3626 /* We can't use nominal_mode, because it will have been set to
3627 Pmode above. We must use the actual mode of the parm. */
3628 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
3629 REG_USERVAR_P (parmreg) = 1;
3630 emit_move_insn (parmreg, DECL_RTL (parm));
3631 DECL_RTL (parm) = parmreg;
3632 /* STACK_PARM is the pointer, not the parm, and PARMREG is
3633 now the parm. */
3634 stack_parm = 0;
3636 #ifdef FUNCTION_ARG_CALLEE_COPIES
3637 /* If we are passed an arg by reference and it is our responsibility
3638 to make a copy, do it now.
3639 PASSED_TYPE and PASSED mode now refer to the pointer, not the
3640 original argument, so we must recreate them in the call to
3641 FUNCTION_ARG_CALLEE_COPIES. */
3642 /* ??? Later add code to handle the case that if the argument isn't
3643 modified, don't do the copy. */
3645 else if (passed_pointer
3646 && FUNCTION_ARG_CALLEE_COPIES (args_so_far,
3647 TYPE_MODE (DECL_ARG_TYPE (parm)),
3648 DECL_ARG_TYPE (parm),
3649 ! last_named))
3651 rtx copy;
3652 tree type = DECL_ARG_TYPE (parm);
3654 /* This sequence may involve a library call perhaps clobbering
3655 registers that haven't been copied to pseudos yet. */
3657 push_to_sequence (conversion_insns);
3659 if (TYPE_SIZE (type) == 0
3660 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
3661 /* This is a variable sized object. */
3662 copy = gen_rtx (MEM, BLKmode,
3663 allocate_dynamic_stack_space
3664 (expr_size (parm), NULL_RTX,
3665 TYPE_ALIGN (type)));
3666 else
3667 copy = assign_stack_temp (TYPE_MODE (type),
3668 int_size_in_bytes (type), 1);
3669 MEM_IN_STRUCT_P (copy) = AGGREGATE_TYPE_P (type);
3671 store_expr (parm, copy, 0);
3672 emit_move_insn (parmreg, XEXP (copy, 0));
3673 conversion_insns = get_insns ();
3674 end_sequence ();
3676 #endif /* FUNCTION_ARG_CALLEE_COPIES */
3678 /* In any case, record the parm's desired stack location
3679 in case we later discover it must live in the stack.
3681 If it is a COMPLEX value, store the stack location for both
3682 halves. */
3684 if (GET_CODE (parmreg) == CONCAT)
3685 regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1)));
3686 else
3687 regno = REGNO (parmreg);
3689 if (regno >= nparmregs)
3691 rtx *new;
3692 int old_nparmregs = nparmregs;
3694 nparmregs = regno + 5;
3695 new = (rtx *) oballoc (nparmregs * sizeof (rtx));
3696 bcopy ((char *) parm_reg_stack_loc, (char *) new,
3697 old_nparmregs * sizeof (rtx));
3698 bzero ((char *) (new + old_nparmregs),
3699 (nparmregs - old_nparmregs) * sizeof (rtx));
3700 parm_reg_stack_loc = new;
3703 if (GET_CODE (parmreg) == CONCAT)
3705 enum machine_mode submode = GET_MODE (XEXP (parmreg, 0));
3707 regnor = REGNO (gen_realpart (submode, parmreg));
3708 regnoi = REGNO (gen_imagpart (submode, parmreg));
3710 if (stack_parm != 0)
3712 parm_reg_stack_loc[regnor]
3713 = gen_realpart (submode, stack_parm);
3714 parm_reg_stack_loc[regnoi]
3715 = gen_imagpart (submode, stack_parm);
3717 else
3719 parm_reg_stack_loc[regnor] = 0;
3720 parm_reg_stack_loc[regnoi] = 0;
3723 else
3724 parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
3726 /* Mark the register as eliminable if we did no conversion
3727 and it was copied from memory at a fixed offset,
3728 and the arg pointer was not copied to a pseudo-reg.
3729 If the arg pointer is a pseudo reg or the offset formed
3730 an invalid address, such memory-equivalences
3731 as we make here would screw up life analysis for it. */
3732 if (nominal_mode == passed_mode
3733 && ! conversion_insns
3734 && GET_CODE (entry_parm) == MEM
3735 && entry_parm == stack_parm
3736 && stack_offset.var == 0
3737 && reg_mentioned_p (virtual_incoming_args_rtx,
3738 XEXP (entry_parm, 0)))
3740 rtx linsn = get_last_insn ();
3742 /* Mark complex types separately. */
3743 if (GET_CODE (parmreg) == CONCAT)
3745 REG_NOTES (linsn)
3746 = gen_rtx (EXPR_LIST, REG_EQUIV,
3747 parm_reg_stack_loc[regnoi], REG_NOTES (linsn));
3749 /* Now search backward for where we set the real part. */
3750 for (; linsn != 0
3751 && ! reg_referenced_p (parm_reg_stack_loc[regnor],
3752 PATTERN (linsn));
3753 linsn = prev_nonnote_insn (linsn))
3756 REG_NOTES (linsn)
3757 = gen_rtx (EXPR_LIST, REG_EQUIV,
3758 parm_reg_stack_loc[regnor], REG_NOTES (linsn));
3760 else
3761 REG_NOTES (linsn)
3762 = gen_rtx (EXPR_LIST, REG_EQUIV,
3763 entry_parm, REG_NOTES (linsn));
3766 /* For pointer data type, suggest pointer register. */
3767 if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE)
3768 mark_reg_pointer (parmreg);
3770 else
3772 /* Value must be stored in the stack slot STACK_PARM
3773 during function execution. */
3775 if (passed_mode != nominal_mode)
3777 /* Conversion is required. */
3778 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
3780 emit_move_insn (tempreg, validize_mem (entry_parm));
3782 push_to_sequence (conversion_insns);
3783 entry_parm = convert_to_mode (nominal_mode, tempreg,
3784 TREE_UNSIGNED (TREE_TYPE (parm)));
3785 conversion_insns = get_insns ();
3786 end_sequence ();
3789 if (entry_parm != stack_parm)
3791 if (stack_parm == 0)
3793 stack_parm
3794 = assign_stack_local (GET_MODE (entry_parm),
3795 GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
3796 /* If this is a memory ref that contains aggregate components,
3797 mark it as such for cse and loop optimize. */
3798 MEM_IN_STRUCT_P (stack_parm) = aggregate;
3801 if (passed_mode != nominal_mode)
3803 push_to_sequence (conversion_insns);
3804 emit_move_insn (validize_mem (stack_parm),
3805 validize_mem (entry_parm));
3806 conversion_insns = get_insns ();
3807 end_sequence ();
3809 else
3810 emit_move_insn (validize_mem (stack_parm),
3811 validize_mem (entry_parm));
3814 DECL_RTL (parm) = stack_parm;
3817 /* If this "parameter" was the place where we are receiving the
3818 function's incoming structure pointer, set up the result. */
3819 if (parm == function_result_decl)
3821 tree result = DECL_RESULT (fndecl);
3822 tree restype = TREE_TYPE (result);
3824 DECL_RTL (result)
3825 = gen_rtx (MEM, DECL_MODE (result), DECL_RTL (parm));
3827 MEM_IN_STRUCT_P (DECL_RTL (result)) = AGGREGATE_TYPE_P (restype);
3830 if (TREE_THIS_VOLATILE (parm))
3831 MEM_VOLATILE_P (DECL_RTL (parm)) = 1;
3832 if (TREE_READONLY (parm))
3833 RTX_UNCHANGING_P (DECL_RTL (parm)) = 1;
3836 /* Output all parameter conversion instructions (possibly including calls)
3837 now that all parameters have been copied out of hard registers. */
3838 emit_insns (conversion_insns);
3840 max_parm_reg = max_reg_num ();
3841 last_parm_insn = get_last_insn ();
3843 current_function_args_size = stack_args_size.constant;
3845 /* Adjust function incoming argument size for alignment and
3846 minimum length. */
3848 #ifdef REG_PARM_STACK_SPACE
3849 #ifndef MAYBE_REG_PARM_STACK_SPACE
3850 current_function_args_size = MAX (current_function_args_size,
3851 REG_PARM_STACK_SPACE (fndecl));
3852 #endif
3853 #endif
3855 #ifdef STACK_BOUNDARY
3856 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
3858 current_function_args_size
3859 = ((current_function_args_size + STACK_BYTES - 1)
3860 / STACK_BYTES) * STACK_BYTES;
3861 #endif
3863 #ifdef ARGS_GROW_DOWNWARD
3864 current_function_arg_offset_rtx
3865 = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
3866 : expand_expr (size_binop (MINUS_EXPR, stack_args_size.var,
3867 size_int (-stack_args_size.constant)),
3868 NULL_RTX, VOIDmode, 0));
3869 #else
3870 current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
3871 #endif
3873 /* See how many bytes, if any, of its args a function should try to pop
3874 on return. */
3876 current_function_pops_args = RETURN_POPS_ARGS (TREE_TYPE (fndecl),
3877 current_function_args_size);
3879 /* For stdarg.h function, save info about
3880 regs and stack space used by the named args. */
3882 if (!hide_last_arg)
3883 current_function_args_info = args_so_far;
3885 /* Set the rtx used for the function return value. Put this in its
3886 own variable so any optimizers that need this information don't have
3887 to include tree.h. Do this here so it gets done when an inlined
3888 function gets output. */
3890 current_function_return_rtx = DECL_RTL (DECL_RESULT (fndecl));
3893 /* Indicate whether REGNO is an incoming argument to the current function
3894 that was promoted to a wider mode. If so, return the RTX for the
3895 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
3896 that REGNO is promoted from and whether the promotion was signed or
3897 unsigned. */
3899 #ifdef PROMOTE_FUNCTION_ARGS
3902 promoted_input_arg (regno, pmode, punsignedp)
3903 int regno;
3904 enum machine_mode *pmode;
3905 int *punsignedp;
3907 tree arg;
3909 for (arg = DECL_ARGUMENTS (current_function_decl); arg;
3910 arg = TREE_CHAIN (arg))
3911 if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
3912 && REGNO (DECL_INCOMING_RTL (arg)) == regno)
3914 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
3915 int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
3917 mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1);
3918 if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
3919 && mode != DECL_MODE (arg))
3921 *pmode = DECL_MODE (arg);
3922 *punsignedp = unsignedp;
3923 return DECL_INCOMING_RTL (arg);
3927 return 0;
3930 #endif
3932 /* Compute the size and offset from the start of the stacked arguments for a
3933 parm passed in mode PASSED_MODE and with type TYPE.
3935 INITIAL_OFFSET_PTR points to the current offset into the stacked
3936 arguments.
3938 The starting offset and size for this parm are returned in *OFFSET_PTR
3939 and *ARG_SIZE_PTR, respectively.
3941 IN_REGS is non-zero if the argument will be passed in registers. It will
3942 never be set if REG_PARM_STACK_SPACE is not defined.
3944 FNDECL is the function in which the argument was defined.
3946 There are two types of rounding that are done. The first, controlled by
3947 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
3948 list to be aligned to the specific boundary (in bits). This rounding
3949 affects the initial and starting offsets, but not the argument size.
3951 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
3952 optionally rounds the size of the parm to PARM_BOUNDARY. The
3953 initial offset is not affected by this rounding, while the size always
3954 is and the starting offset may be. */
3956 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
3957 initial_offset_ptr is positive because locate_and_pad_parm's
3958 callers pass in the total size of args so far as
3959 initial_offset_ptr. arg_size_ptr is always positive.*/
3961 void
3962 locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
3963 initial_offset_ptr, offset_ptr, arg_size_ptr)
3964 enum machine_mode passed_mode;
3965 tree type;
3966 int in_regs;
3967 tree fndecl;
3968 struct args_size *initial_offset_ptr;
3969 struct args_size *offset_ptr;
3970 struct args_size *arg_size_ptr;
3972 tree sizetree
3973 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
3974 enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
3975 int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
3976 int boundary_in_bytes = boundary / BITS_PER_UNIT;
3977 int reg_parm_stack_space = 0;
3979 #ifdef REG_PARM_STACK_SPACE
3980 /* If we have found a stack parm before we reach the end of the
3981 area reserved for registers, skip that area. */
3982 if (! in_regs)
3984 #ifdef MAYBE_REG_PARM_STACK_SPACE
3985 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
3986 #else
3987 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
3988 #endif
3989 if (reg_parm_stack_space > 0)
3991 if (initial_offset_ptr->var)
3993 initial_offset_ptr->var
3994 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
3995 size_int (reg_parm_stack_space));
3996 initial_offset_ptr->constant = 0;
3998 else if (initial_offset_ptr->constant < reg_parm_stack_space)
3999 initial_offset_ptr->constant = reg_parm_stack_space;
4002 #endif /* REG_PARM_STACK_SPACE */
4004 arg_size_ptr->var = 0;
4005 arg_size_ptr->constant = 0;
4007 #ifdef ARGS_GROW_DOWNWARD
4008 if (initial_offset_ptr->var)
4010 offset_ptr->constant = 0;
4011 offset_ptr->var = size_binop (MINUS_EXPR, integer_zero_node,
4012 initial_offset_ptr->var);
4014 else
4016 offset_ptr->constant = - initial_offset_ptr->constant;
4017 offset_ptr->var = 0;
4019 if (where_pad != none
4020 && (TREE_CODE (sizetree) != INTEGER_CST
4021 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
4022 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4023 SUB_PARM_SIZE (*offset_ptr, sizetree);
4024 if (where_pad != downward)
4025 pad_to_arg_alignment (offset_ptr, boundary);
4026 if (initial_offset_ptr->var)
4028 arg_size_ptr->var = size_binop (MINUS_EXPR,
4029 size_binop (MINUS_EXPR,
4030 integer_zero_node,
4031 initial_offset_ptr->var),
4032 offset_ptr->var);
4034 else
4036 arg_size_ptr->constant = (- initial_offset_ptr->constant -
4037 offset_ptr->constant);
4039 #else /* !ARGS_GROW_DOWNWARD */
4040 pad_to_arg_alignment (initial_offset_ptr, boundary);
4041 *offset_ptr = *initial_offset_ptr;
4043 #ifdef PUSH_ROUNDING
4044 if (passed_mode != BLKmode)
4045 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
4046 #endif
4048 /* Pad_below needs the pre-rounded size to know how much to pad below
4049 so this must be done before rounding up. */
4050 if (where_pad == downward
4051 /* However, BLKmode args passed in regs have their padding done elsewhere.
4052 The stack slot must be able to hold the entire register. */
4053 && !(in_regs && passed_mode == BLKmode))
4054 pad_below (offset_ptr, passed_mode, sizetree);
4056 if (where_pad != none
4057 && (TREE_CODE (sizetree) != INTEGER_CST
4058 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
4059 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4061 ADD_PARM_SIZE (*arg_size_ptr, sizetree);
4062 #endif /* ARGS_GROW_DOWNWARD */
4065 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
4066 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
4068 static void
4069 pad_to_arg_alignment (offset_ptr, boundary)
4070 struct args_size *offset_ptr;
4071 int boundary;
4073 int boundary_in_bytes = boundary / BITS_PER_UNIT;
4075 if (boundary > BITS_PER_UNIT)
4077 if (offset_ptr->var)
4079 offset_ptr->var =
4080 #ifdef ARGS_GROW_DOWNWARD
4081 round_down
4082 #else
4083 round_up
4084 #endif
4085 (ARGS_SIZE_TREE (*offset_ptr),
4086 boundary / BITS_PER_UNIT);
4087 offset_ptr->constant = 0; /*?*/
4089 else
4090 offset_ptr->constant =
4091 #ifdef ARGS_GROW_DOWNWARD
4092 FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes);
4093 #else
4094 CEIL_ROUND (offset_ptr->constant, boundary_in_bytes);
4095 #endif
4099 static void
4100 pad_below (offset_ptr, passed_mode, sizetree)
4101 struct args_size *offset_ptr;
4102 enum machine_mode passed_mode;
4103 tree sizetree;
4105 if (passed_mode != BLKmode)
4107 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
4108 offset_ptr->constant
4109 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
4110 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
4111 - GET_MODE_SIZE (passed_mode));
4113 else
4115 if (TREE_CODE (sizetree) != INTEGER_CST
4116 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
4118 /* Round the size up to multiple of PARM_BOUNDARY bits. */
4119 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
4120 /* Add it in. */
4121 ADD_PARM_SIZE (*offset_ptr, s2);
4122 SUB_PARM_SIZE (*offset_ptr, sizetree);
4127 static tree
4128 round_down (value, divisor)
4129 tree value;
4130 int divisor;
4132 return size_binop (MULT_EXPR,
4133 size_binop (FLOOR_DIV_EXPR, value, size_int (divisor)),
4134 size_int (divisor));
4137 /* Walk the tree of blocks describing the binding levels within a function
4138 and warn about uninitialized variables.
4139 This is done after calling flow_analysis and before global_alloc
4140 clobbers the pseudo-regs to hard regs. */
4142 void
4143 uninitialized_vars_warning (block)
4144 tree block;
4146 register tree decl, sub;
4147 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
4149 if (TREE_CODE (decl) == VAR_DECL
4150 /* These warnings are unreliable for and aggregates
4151 because assigning the fields one by one can fail to convince
4152 flow.c that the entire aggregate was initialized.
4153 Unions are troublesome because members may be shorter. */
4154 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl))
4155 && DECL_RTL (decl) != 0
4156 && GET_CODE (DECL_RTL (decl)) == REG
4157 && regno_uninitialized (REGNO (DECL_RTL (decl))))
4158 warning_with_decl (decl,
4159 "`%s' might be used uninitialized in this function");
4160 if (TREE_CODE (decl) == VAR_DECL
4161 && DECL_RTL (decl) != 0
4162 && GET_CODE (DECL_RTL (decl)) == REG
4163 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
4164 warning_with_decl (decl,
4165 "variable `%s' might be clobbered by `longjmp' or `vfork'");
4167 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
4168 uninitialized_vars_warning (sub);
4171 /* Do the appropriate part of uninitialized_vars_warning
4172 but for arguments instead of local variables. */
4174 void
4175 setjmp_args_warning (block)
4176 tree block;
4178 register tree decl;
4179 for (decl = DECL_ARGUMENTS (current_function_decl);
4180 decl; decl = TREE_CHAIN (decl))
4181 if (DECL_RTL (decl) != 0
4182 && GET_CODE (DECL_RTL (decl)) == REG
4183 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
4184 warning_with_decl (decl, "argument `%s' might be clobbered by `longjmp' or `vfork'");
4187 /* If this function call setjmp, put all vars into the stack
4188 unless they were declared `register'. */
4190 void
4191 setjmp_protect (block)
4192 tree block;
4194 register tree decl, sub;
4195 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
4196 if ((TREE_CODE (decl) == VAR_DECL
4197 || TREE_CODE (decl) == PARM_DECL)
4198 && DECL_RTL (decl) != 0
4199 && GET_CODE (DECL_RTL (decl)) == REG
4200 /* If this variable came from an inline function, it must be
4201 that it's life doesn't overlap the setjmp. If there was a
4202 setjmp in the function, it would already be in memory. We
4203 must exclude such variable because their DECL_RTL might be
4204 set to strange things such as virtual_stack_vars_rtx. */
4205 && ! DECL_FROM_INLINE (decl)
4206 && (
4207 #ifdef NON_SAVING_SETJMP
4208 /* If longjmp doesn't restore the registers,
4209 don't put anything in them. */
4210 NON_SAVING_SETJMP
4212 #endif
4213 ! DECL_REGISTER (decl)))
4214 put_var_into_stack (decl);
4215 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
4216 setjmp_protect (sub);
4219 /* Like the previous function, but for args instead of local variables. */
4221 void
4222 setjmp_protect_args ()
4224 register tree decl, sub;
4225 for (decl = DECL_ARGUMENTS (current_function_decl);
4226 decl; decl = TREE_CHAIN (decl))
4227 if ((TREE_CODE (decl) == VAR_DECL
4228 || TREE_CODE (decl) == PARM_DECL)
4229 && DECL_RTL (decl) != 0
4230 && GET_CODE (DECL_RTL (decl)) == REG
4231 && (
4232 /* If longjmp doesn't restore the registers,
4233 don't put anything in them. */
4234 #ifdef NON_SAVING_SETJMP
4235 NON_SAVING_SETJMP
4237 #endif
4238 ! DECL_REGISTER (decl)))
4239 put_var_into_stack (decl);
4242 /* Return the context-pointer register corresponding to DECL,
4243 or 0 if it does not need one. */
4246 lookup_static_chain (decl)
4247 tree decl;
4249 tree context = decl_function_context (decl);
4250 tree link;
4252 if (context == 0)
4253 return 0;
4255 /* We treat inline_function_decl as an alias for the current function
4256 because that is the inline function whose vars, types, etc.
4257 are being merged into the current function.
4258 See expand_inline_function. */
4259 if (context == current_function_decl || context == inline_function_decl)
4260 return virtual_stack_vars_rtx;
4262 for (link = context_display; link; link = TREE_CHAIN (link))
4263 if (TREE_PURPOSE (link) == context)
4264 return RTL_EXPR_RTL (TREE_VALUE (link));
4266 abort ();
4269 /* Convert a stack slot address ADDR for variable VAR
4270 (from a containing function)
4271 into an address valid in this function (using a static chain). */
4274 fix_lexical_addr (addr, var)
4275 rtx addr;
4276 tree var;
4278 rtx basereg;
4279 int displacement;
4280 tree context = decl_function_context (var);
4281 struct function *fp;
4282 rtx base = 0;
4284 /* If this is the present function, we need not do anything. */
4285 if (context == current_function_decl || context == inline_function_decl)
4286 return addr;
4288 for (fp = outer_function_chain; fp; fp = fp->next)
4289 if (fp->decl == context)
4290 break;
4292 if (fp == 0)
4293 abort ();
4295 /* Decode given address as base reg plus displacement. */
4296 if (GET_CODE (addr) == REG)
4297 basereg = addr, displacement = 0;
4298 else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
4299 basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
4300 else
4301 abort ();
4303 /* We accept vars reached via the containing function's
4304 incoming arg pointer and via its stack variables pointer. */
4305 if (basereg == fp->internal_arg_pointer)
4307 /* If reached via arg pointer, get the arg pointer value
4308 out of that function's stack frame.
4310 There are two cases: If a separate ap is needed, allocate a
4311 slot in the outer function for it and dereference it that way.
4312 This is correct even if the real ap is actually a pseudo.
4313 Otherwise, just adjust the offset from the frame pointer to
4314 compensate. */
4316 #ifdef NEED_SEPARATE_AP
4317 rtx addr;
4319 if (fp->arg_pointer_save_area == 0)
4320 fp->arg_pointer_save_area
4321 = assign_outer_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0, fp);
4323 addr = fix_lexical_addr (XEXP (fp->arg_pointer_save_area, 0), var);
4324 addr = memory_address (Pmode, addr);
4326 base = copy_to_reg (gen_rtx (MEM, Pmode, addr));
4327 #else
4328 displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
4329 base = lookup_static_chain (var);
4330 #endif
4333 else if (basereg == virtual_stack_vars_rtx)
4335 /* This is the same code as lookup_static_chain, duplicated here to
4336 avoid an extra call to decl_function_context. */
4337 tree link;
4339 for (link = context_display; link; link = TREE_CHAIN (link))
4340 if (TREE_PURPOSE (link) == context)
4342 base = RTL_EXPR_RTL (TREE_VALUE (link));
4343 break;
4347 if (base == 0)
4348 abort ();
4350 /* Use same offset, relative to appropriate static chain or argument
4351 pointer. */
4352 return plus_constant (base, displacement);
4355 /* Return the address of the trampoline for entering nested fn FUNCTION.
4356 If necessary, allocate a trampoline (in the stack frame)
4357 and emit rtl to initialize its contents (at entry to this function). */
4360 trampoline_address (function)
4361 tree function;
4363 tree link;
4364 tree rtlexp;
4365 rtx tramp;
4366 struct function *fp;
4367 tree fn_context;
4369 /* Find an existing trampoline and return it. */
4370 for (link = trampoline_list; link; link = TREE_CHAIN (link))
4371 if (TREE_PURPOSE (link) == function)
4372 return
4373 round_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0));
4375 for (fp = outer_function_chain; fp; fp = fp->next)
4376 for (link = fp->trampoline_list; link; link = TREE_CHAIN (link))
4377 if (TREE_PURPOSE (link) == function)
4379 tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
4380 function);
4381 return round_trampoline_addr (tramp);
4384 /* None exists; we must make one. */
4386 /* Find the `struct function' for the function containing FUNCTION. */
4387 fp = 0;
4388 fn_context = decl_function_context (function);
4389 if (fn_context != current_function_decl)
4390 for (fp = outer_function_chain; fp; fp = fp->next)
4391 if (fp->decl == fn_context)
4392 break;
4394 /* Allocate run-time space for this trampoline
4395 (usually in the defining function's stack frame). */
4396 #ifdef ALLOCATE_TRAMPOLINE
4397 tramp = ALLOCATE_TRAMPOLINE (fp);
4398 #else
4399 /* If rounding needed, allocate extra space
4400 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
4401 #ifdef TRAMPOLINE_ALIGNMENT
4402 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE + TRAMPOLINE_ALIGNMENT - 1)
4403 #else
4404 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
4405 #endif
4406 if (fp != 0)
4407 tramp = assign_outer_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0, fp);
4408 else
4409 tramp = assign_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0);
4410 #endif
4412 /* Record the trampoline for reuse and note it for later initialization
4413 by expand_function_end. */
4414 if (fp != 0)
4416 push_obstacks (fp->function_maybepermanent_obstack,
4417 fp->function_maybepermanent_obstack);
4418 rtlexp = make_node (RTL_EXPR);
4419 RTL_EXPR_RTL (rtlexp) = tramp;
4420 fp->trampoline_list = tree_cons (function, rtlexp, fp->trampoline_list);
4421 pop_obstacks ();
4423 else
4425 /* Make the RTL_EXPR node temporary, not momentary, so that the
4426 trampoline_list doesn't become garbage. */
4427 int momentary = suspend_momentary ();
4428 rtlexp = make_node (RTL_EXPR);
4429 resume_momentary (momentary);
4431 RTL_EXPR_RTL (rtlexp) = tramp;
4432 trampoline_list = tree_cons (function, rtlexp, trampoline_list);
4435 tramp = fix_lexical_addr (XEXP (tramp, 0), function);
4436 return round_trampoline_addr (tramp);
4439 /* Given a trampoline address,
4440 round it to multiple of TRAMPOLINE_ALIGNMENT. */
4442 static rtx
4443 round_trampoline_addr (tramp)
4444 rtx tramp;
4446 #ifdef TRAMPOLINE_ALIGNMENT
4447 /* Round address up to desired boundary. */
4448 rtx temp = gen_reg_rtx (Pmode);
4449 temp = expand_binop (Pmode, add_optab, tramp,
4450 GEN_INT (TRAMPOLINE_ALIGNMENT - 1),
4451 temp, 0, OPTAB_LIB_WIDEN);
4452 tramp = expand_binop (Pmode, and_optab, temp,
4453 GEN_INT (- TRAMPOLINE_ALIGNMENT),
4454 temp, 0, OPTAB_LIB_WIDEN);
4455 #endif
4456 return tramp;
4459 /* The functions identify_blocks and reorder_blocks provide a way to
4460 reorder the tree of BLOCK nodes, for optimizers that reshuffle or
4461 duplicate portions of the RTL code. Call identify_blocks before
4462 changing the RTL, and call reorder_blocks after. */
4464 /* Put all this function's BLOCK nodes into a vector, and return it.
4465 Also store in each NOTE for the beginning or end of a block
4466 the index of that block in the vector.
4467 The arguments are TOP_BLOCK, the top-level block of the function,
4468 and INSNS, the insn chain of the function. */
4470 tree *
4471 identify_blocks (top_block, insns)
4472 tree top_block;
4473 rtx insns;
4475 int n_blocks;
4476 tree *block_vector;
4477 int *block_stack;
4478 int depth = 0;
4479 int next_block_number = 0;
4480 int current_block_number = 0;
4481 rtx insn;
4483 if (top_block == 0)
4484 return 0;
4486 n_blocks = all_blocks (top_block, 0);
4487 block_vector = (tree *) xmalloc (n_blocks * sizeof (tree));
4488 block_stack = (int *) alloca (n_blocks * sizeof (int));
4490 all_blocks (top_block, block_vector);
4492 for (insn = insns; insn; insn = NEXT_INSN (insn))
4493 if (GET_CODE (insn) == NOTE)
4495 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
4497 block_stack[depth++] = current_block_number;
4498 current_block_number = next_block_number;
4499 NOTE_BLOCK_NUMBER (insn) = next_block_number++;
4501 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
4503 current_block_number = block_stack[--depth];
4504 NOTE_BLOCK_NUMBER (insn) = current_block_number;
4508 return block_vector;
4511 /* Given BLOCK_VECTOR which was returned by identify_blocks,
4512 and a revised instruction chain, rebuild the tree structure
4513 of BLOCK nodes to correspond to the new order of RTL.
4514 The new block tree is inserted below TOP_BLOCK.
4515 Returns the current top-level block. */
4517 tree
4518 reorder_blocks (block_vector, top_block, insns)
4519 tree *block_vector;
4520 tree top_block;
4521 rtx insns;
4523 tree current_block = top_block;
4524 rtx insn;
4526 if (block_vector == 0)
4527 return top_block;
4529 /* Prune the old tree away, so that it doesn't get in the way. */
4530 BLOCK_SUBBLOCKS (current_block) = 0;
4532 for (insn = insns; insn; insn = NEXT_INSN (insn))
4533 if (GET_CODE (insn) == NOTE)
4535 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
4537 tree block = block_vector[NOTE_BLOCK_NUMBER (insn)];
4538 /* If we have seen this block before, copy it. */
4539 if (TREE_ASM_WRITTEN (block))
4540 block = copy_node (block);
4541 BLOCK_SUBBLOCKS (block) = 0;
4542 TREE_ASM_WRITTEN (block) = 1;
4543 BLOCK_SUPERCONTEXT (block) = current_block;
4544 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
4545 BLOCK_SUBBLOCKS (current_block) = block;
4546 current_block = block;
4547 NOTE_SOURCE_FILE (insn) = 0;
4549 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
4551 BLOCK_SUBBLOCKS (current_block)
4552 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
4553 current_block = BLOCK_SUPERCONTEXT (current_block);
4554 NOTE_SOURCE_FILE (insn) = 0;
4558 return current_block;
4561 /* Reverse the order of elements in the chain T of blocks,
4562 and return the new head of the chain (old last element). */
4564 static tree
4565 blocks_nreverse (t)
4566 tree t;
4568 register tree prev = 0, decl, next;
4569 for (decl = t; decl; decl = next)
4571 next = BLOCK_CHAIN (decl);
4572 BLOCK_CHAIN (decl) = prev;
4573 prev = decl;
4575 return prev;
4578 /* Count the subblocks of BLOCK, and list them all into the vector VECTOR.
4579 Also clear TREE_ASM_WRITTEN in all blocks. */
4581 static int
4582 all_blocks (block, vector)
4583 tree block;
4584 tree *vector;
4586 int n_blocks = 1;
4587 tree subblocks;
4589 TREE_ASM_WRITTEN (block) = 0;
4590 /* Record this block. */
4591 if (vector)
4592 vector[0] = block;
4594 /* Record the subblocks, and their subblocks. */
4595 for (subblocks = BLOCK_SUBBLOCKS (block);
4596 subblocks; subblocks = BLOCK_CHAIN (subblocks))
4597 n_blocks += all_blocks (subblocks, vector ? vector + n_blocks : 0);
4599 return n_blocks;
4602 /* Build bytecode call descriptor for function SUBR. */
4605 bc_build_calldesc (subr)
4606 tree subr;
4608 tree calldesc = 0, arg;
4609 int nargs = 0;
4611 /* Build the argument description vector in reverse order. */
4612 DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
4613 nargs = 0;
4615 for (arg = DECL_ARGUMENTS (subr); arg; arg = TREE_CHAIN (arg))
4617 ++nargs;
4619 calldesc = tree_cons ((tree) 0, size_in_bytes (TREE_TYPE (arg)), calldesc);
4620 calldesc = tree_cons ((tree) 0, bc_runtime_type_code (TREE_TYPE (arg)), calldesc);
4623 DECL_ARGUMENTS (subr) = nreverse (DECL_ARGUMENTS (subr));
4625 /* Prepend the function's return type. */
4626 calldesc = tree_cons ((tree) 0,
4627 size_in_bytes (TREE_TYPE (TREE_TYPE (subr))),
4628 calldesc);
4630 calldesc = tree_cons ((tree) 0,
4631 bc_runtime_type_code (TREE_TYPE (TREE_TYPE (subr))),
4632 calldesc);
4634 /* Prepend the arg count. */
4635 calldesc = tree_cons ((tree) 0, build_int_2 (nargs, 0), calldesc);
4637 /* Output the call description vector and get its address. */
4638 calldesc = build_nt (CONSTRUCTOR, (tree) 0, calldesc);
4639 TREE_TYPE (calldesc) = build_array_type (integer_type_node,
4640 build_index_type (build_int_2 (nargs * 2, 0)));
4642 return output_constant_def (calldesc);
4646 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
4647 and initialize static variables for generating RTL for the statements
4648 of the function. */
4650 void
4651 init_function_start (subr, filename, line)
4652 tree subr;
4653 char *filename;
4654 int line;
4656 char *junk;
4658 if (output_bytecode)
4660 this_function_decl = subr;
4661 this_function_calldesc = bc_build_calldesc (subr);
4662 local_vars_size = 0;
4663 stack_depth = 0;
4664 max_stack_depth = 0;
4665 stmt_expr_depth = 0;
4666 return;
4669 init_stmt_for_function ();
4671 cse_not_expected = ! optimize;
4673 /* Caller save not needed yet. */
4674 caller_save_needed = 0;
4676 /* No stack slots have been made yet. */
4677 stack_slot_list = 0;
4679 /* There is no stack slot for handling nonlocal gotos. */
4680 nonlocal_goto_handler_slot = 0;
4681 nonlocal_goto_stack_level = 0;
4683 /* No labels have been declared for nonlocal use. */
4684 nonlocal_labels = 0;
4686 /* No function calls so far in this function. */
4687 function_call_count = 0;
4689 /* No parm regs have been allocated.
4690 (This is important for output_inline_function.) */
4691 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
4693 /* Initialize the RTL mechanism. */
4694 init_emit ();
4696 /* Initialize the queue of pending postincrement and postdecrements,
4697 and some other info in expr.c. */
4698 init_expr ();
4700 /* We haven't done register allocation yet. */
4701 reg_renumber = 0;
4703 init_const_rtx_hash_table ();
4705 current_function_name = (*decl_printable_name) (subr, &junk);
4707 /* Nonzero if this is a nested function that uses a static chain. */
4709 current_function_needs_context
4710 = (decl_function_context (current_function_decl) != 0);
4712 /* Set if a call to setjmp is seen. */
4713 current_function_calls_setjmp = 0;
4715 /* Set if a call to longjmp is seen. */
4716 current_function_calls_longjmp = 0;
4718 current_function_calls_alloca = 0;
4719 current_function_has_nonlocal_label = 0;
4720 current_function_has_nonlocal_goto = 0;
4721 current_function_contains_functions = 0;
4723 current_function_returns_pcc_struct = 0;
4724 current_function_returns_struct = 0;
4725 current_function_epilogue_delay_list = 0;
4726 current_function_uses_const_pool = 0;
4727 current_function_uses_pic_offset_table = 0;
4729 /* We have not yet needed to make a label to jump to for tail-recursion. */
4730 tail_recursion_label = 0;
4732 /* We haven't had a need to make a save area for ap yet. */
4734 arg_pointer_save_area = 0;
4736 /* No stack slots allocated yet. */
4737 frame_offset = 0;
4739 /* No SAVE_EXPRs in this function yet. */
4740 save_expr_regs = 0;
4742 /* No RTL_EXPRs in this function yet. */
4743 rtl_expr_chain = 0;
4745 /* We have not allocated any temporaries yet. */
4746 temp_slots = 0;
4747 temp_slot_level = 0;
4748 target_temp_slot_level = 0;
4750 /* Within function body, compute a type's size as soon it is laid out. */
4751 immediate_size_expand++;
4753 /* We haven't made any trampolines for this function yet. */
4754 trampoline_list = 0;
4756 init_pending_stack_adjust ();
4757 inhibit_defer_pop = 0;
4759 current_function_outgoing_args_size = 0;
4761 /* Initialize the insn lengths. */
4762 init_insn_lengths ();
4764 /* Prevent ever trying to delete the first instruction of a function.
4765 Also tell final how to output a linenum before the function prologue. */
4766 emit_line_note (filename, line);
4768 /* Make sure first insn is a note even if we don't want linenums.
4769 This makes sure the first insn will never be deleted.
4770 Also, final expects a note to appear there. */
4771 emit_note (NULL_PTR, NOTE_INSN_DELETED);
4773 /* Set flags used by final.c. */
4774 if (aggregate_value_p (DECL_RESULT (subr)))
4776 #ifdef PCC_STATIC_STRUCT_RETURN
4777 current_function_returns_pcc_struct = 1;
4778 #endif
4779 current_function_returns_struct = 1;
4782 /* Warn if this value is an aggregate type,
4783 regardless of which calling convention we are using for it. */
4784 if (warn_aggregate_return
4785 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
4786 warning ("function returns an aggregate");
4788 current_function_returns_pointer
4789 = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
4791 /* Indicate that we need to distinguish between the return value of the
4792 present function and the return value of a function being called. */
4793 rtx_equal_function_value_matters = 1;
4795 /* Indicate that we have not instantiated virtual registers yet. */
4796 virtuals_instantiated = 0;
4798 /* Indicate we have no need of a frame pointer yet. */
4799 frame_pointer_needed = 0;
4801 /* By default assume not varargs. */
4802 current_function_varargs = 0;
4805 /* Indicate that the current function uses extra args
4806 not explicitly mentioned in the argument list in any fashion. */
4808 void
4809 mark_varargs ()
4811 current_function_varargs = 1;
4814 /* Expand a call to __main at the beginning of a possible main function. */
4816 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
4817 #undef HAS_INIT_SECTION
4818 #define HAS_INIT_SECTION
4819 #endif
4821 void
4822 expand_main_function ()
4824 if (!output_bytecode)
4826 /* The zero below avoids a possible parse error */
4828 #if !defined (HAS_INIT_SECTION)
4829 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, NAME__MAIN), 0,
4830 VOIDmode, 0);
4831 #endif /* not HAS_INIT_SECTION */
4835 extern struct obstack permanent_obstack;
4837 /* Expand start of bytecode function. See comment at
4838 expand_function_start below for details. */
4840 void
4841 bc_expand_function_start (subr, parms_have_cleanups)
4842 tree subr;
4843 int parms_have_cleanups;
4845 char label[20], *name;
4846 static int nlab;
4847 tree thisarg;
4848 int argsz;
4850 if (TREE_PUBLIC (subr))
4851 bc_globalize_label (IDENTIFIER_POINTER (DECL_NAME (subr)));
4853 #ifdef DEBUG_PRINT_CODE
4854 fprintf (stderr, "\n<func %s>\n", IDENTIFIER_POINTER (DECL_NAME (subr)));
4855 #endif
4857 for (argsz = 0, thisarg = DECL_ARGUMENTS (subr); thisarg; thisarg = TREE_CHAIN (thisarg))
4859 if (DECL_RTL (thisarg))
4860 abort (); /* Should be NULL here I think. */
4861 else if (TREE_CONSTANT (DECL_SIZE (thisarg)))
4863 DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
4864 argsz += TREE_INT_CST_LOW (DECL_SIZE (thisarg));
4866 else
4868 /* Variable-sized objects are pointers to their storage. */
4869 DECL_RTL (thisarg) = bc_gen_rtx ((char *) 0, argsz, (struct bc_label *) 0);
4870 argsz += POINTER_SIZE;
4874 bc_begin_function (bc_xstrdup (IDENTIFIER_POINTER (DECL_NAME (subr))));
4876 ASM_GENERATE_INTERNAL_LABEL (label, "LX", nlab);
4878 ++nlab;
4879 name = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
4880 this_function_callinfo = bc_gen_rtx (name, 0, (struct bc_label *) 0);
4881 this_function_bytecode =
4882 bc_emit_trampoline (BYTECODE_LABEL (this_function_callinfo));
4886 /* Expand end of bytecode function. See details the comment of
4887 expand_function_end(), below. */
4889 void
4890 bc_expand_function_end ()
4892 char *ptrconsts;
4894 expand_null_return ();
4896 /* Emit any fixup code. This must be done before the call to
4897 to BC_END_FUNCTION (), since that will cause the bytecode
4898 segment to be finished off and closed. */
4900 expand_fixups (NULL_RTX);
4902 ptrconsts = bc_end_function ();
4904 bc_align_const (2 /* INT_ALIGN */);
4906 /* If this changes also make sure to change bc-interp.h! */
4908 bc_emit_const_labeldef (BYTECODE_LABEL (this_function_callinfo));
4909 bc_emit_const ((char *) &max_stack_depth, sizeof max_stack_depth);
4910 bc_emit_const ((char *) &local_vars_size, sizeof local_vars_size);
4911 bc_emit_const_labelref (this_function_bytecode, 0);
4912 bc_emit_const_labelref (ptrconsts, 0);
4913 bc_emit_const_labelref (BYTECODE_LABEL (this_function_calldesc), 0);
4917 /* Start the RTL for a new function, and set variables used for
4918 emitting RTL.
4919 SUBR is the FUNCTION_DECL node.
4920 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
4921 the function's parameters, which must be run at any return statement. */
4923 void
4924 expand_function_start (subr, parms_have_cleanups)
4925 tree subr;
4926 int parms_have_cleanups;
4928 register int i;
4929 tree tem;
4930 rtx last_ptr;
4932 if (output_bytecode)
4934 bc_expand_function_start (subr, parms_have_cleanups);
4935 return;
4938 /* Make sure volatile mem refs aren't considered
4939 valid operands of arithmetic insns. */
4940 init_recog_no_volatile ();
4942 /* If function gets a static chain arg, store it in the stack frame.
4943 Do this first, so it gets the first stack slot offset. */
4944 if (current_function_needs_context)
4946 last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
4948 #ifdef SMALL_REGISTER_CLASSES
4949 /* Delay copying static chain if it is not a register to avoid
4950 conflicts with regs used for parameters. */
4951 if (GET_CODE (static_chain_incoming_rtx) == REG)
4952 #endif
4953 emit_move_insn (last_ptr, static_chain_incoming_rtx);
4956 /* If the parameters of this function need cleaning up, get a label
4957 for the beginning of the code which executes those cleanups. This must
4958 be done before doing anything with return_label. */
4959 if (parms_have_cleanups)
4960 cleanup_label = gen_label_rtx ();
4961 else
4962 cleanup_label = 0;
4964 /* Make the label for return statements to jump to, if this machine
4965 does not have a one-instruction return and uses an epilogue,
4966 or if it returns a structure, or if it has parm cleanups. */
4967 #ifdef HAVE_return
4968 if (cleanup_label == 0 && HAVE_return
4969 && ! current_function_returns_pcc_struct
4970 && ! (current_function_returns_struct && ! optimize))
4971 return_label = 0;
4972 else
4973 return_label = gen_label_rtx ();
4974 #else
4975 return_label = gen_label_rtx ();
4976 #endif
4978 /* Initialize rtx used to return the value. */
4979 /* Do this before assign_parms so that we copy the struct value address
4980 before any library calls that assign parms might generate. */
4982 /* Decide whether to return the value in memory or in a register. */
4983 if (aggregate_value_p (DECL_RESULT (subr)))
4985 /* Returning something that won't go in a register. */
4986 register rtx value_address = 0;
4988 #ifdef PCC_STATIC_STRUCT_RETURN
4989 if (current_function_returns_pcc_struct)
4991 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
4992 value_address = assemble_static_space (size);
4994 else
4995 #endif
4997 /* Expect to be passed the address of a place to store the value.
4998 If it is passed as an argument, assign_parms will take care of
4999 it. */
5000 if (struct_value_incoming_rtx)
5002 value_address = gen_reg_rtx (Pmode);
5003 emit_move_insn (value_address, struct_value_incoming_rtx);
5006 if (value_address)
5008 DECL_RTL (DECL_RESULT (subr))
5009 = gen_rtx (MEM, DECL_MODE (DECL_RESULT (subr)), value_address);
5010 MEM_IN_STRUCT_P (DECL_RTL (DECL_RESULT (subr)))
5011 = AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
5014 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
5015 /* If return mode is void, this decl rtl should not be used. */
5016 DECL_RTL (DECL_RESULT (subr)) = 0;
5017 else if (parms_have_cleanups)
5019 /* If function will end with cleanup code for parms,
5020 compute the return values into a pseudo reg,
5021 which we will copy into the true return register
5022 after the cleanups are done. */
5024 enum machine_mode mode = DECL_MODE (DECL_RESULT (subr));
5026 #ifdef PROMOTE_FUNCTION_RETURN
5027 tree type = TREE_TYPE (DECL_RESULT (subr));
5028 int unsignedp = TREE_UNSIGNED (type);
5030 mode = promote_mode (type, mode, &unsignedp, 1);
5031 #endif
5033 DECL_RTL (DECL_RESULT (subr)) = gen_reg_rtx (mode);
5035 else
5036 /* Scalar, returned in a register. */
5038 #ifdef FUNCTION_OUTGOING_VALUE
5039 DECL_RTL (DECL_RESULT (subr))
5040 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
5041 #else
5042 DECL_RTL (DECL_RESULT (subr))
5043 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
5044 #endif
5046 /* Mark this reg as the function's return value. */
5047 if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG)
5049 REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1;
5050 /* Needed because we may need to move this to memory
5051 in case it's a named return value whose address is taken. */
5052 DECL_REGISTER (DECL_RESULT (subr)) = 1;
5056 /* Initialize rtx for parameters and local variables.
5057 In some cases this requires emitting insns. */
5059 assign_parms (subr, 0);
5061 #ifdef SMALL_REGISTER_CLASSES
5062 /* Copy the static chain now if it wasn't a register. The delay is to
5063 avoid conflicts with the parameter passing registers. */
5065 if (current_function_needs_context)
5066 if (GET_CODE (static_chain_incoming_rtx) != REG)
5067 emit_move_insn (last_ptr, static_chain_incoming_rtx);
5068 #endif
5070 /* The following was moved from init_function_start.
5071 The move is supposed to make sdb output more accurate. */
5072 /* Indicate the beginning of the function body,
5073 as opposed to parm setup. */
5074 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_BEG);
5076 /* If doing stupid allocation, mark parms as born here. */
5078 if (GET_CODE (get_last_insn ()) != NOTE)
5079 emit_note (NULL_PTR, NOTE_INSN_DELETED);
5080 parm_birth_insn = get_last_insn ();
5082 if (obey_regdecls)
5084 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
5085 use_variable (regno_reg_rtx[i]);
5087 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
5088 use_variable (current_function_internal_arg_pointer);
5091 /* Fetch static chain values for containing functions. */
5092 tem = decl_function_context (current_function_decl);
5093 /* If not doing stupid register allocation copy the static chain
5094 pointer into a psuedo. If we have small register classes, copy the
5095 value from memory if static_chain_incoming_rtx is a REG. If we do
5096 stupid register allocation, we use the stack address generated above. */
5097 if (tem && ! obey_regdecls)
5099 #ifdef SMALL_REGISTER_CLASSES
5100 /* If the static chain originally came in a register, put it back
5101 there, then move it out in the next insn. The reason for
5102 this peculiar code is to satisfy function integration. */
5103 if (GET_CODE (static_chain_incoming_rtx) == REG)
5104 emit_move_insn (static_chain_incoming_rtx, last_ptr);
5105 #endif
5107 last_ptr = copy_to_reg (static_chain_incoming_rtx);
5110 context_display = 0;
5111 while (tem)
5113 tree rtlexp = make_node (RTL_EXPR);
5115 RTL_EXPR_RTL (rtlexp) = last_ptr;
5116 context_display = tree_cons (tem, rtlexp, context_display);
5117 tem = decl_function_context (tem);
5118 if (tem == 0)
5119 break;
5120 /* Chain thru stack frames, assuming pointer to next lexical frame
5121 is found at the place we always store it. */
5122 #ifdef FRAME_GROWS_DOWNWARD
5123 last_ptr = plus_constant (last_ptr, - GET_MODE_SIZE (Pmode));
5124 #endif
5125 last_ptr = copy_to_reg (gen_rtx (MEM, Pmode,
5126 memory_address (Pmode, last_ptr)));
5128 /* If we are not optimizing, ensure that we know that this
5129 piece of context is live over the entire function. */
5130 if (! optimize)
5131 save_expr_regs = gen_rtx (EXPR_LIST, VOIDmode, last_ptr,
5132 save_expr_regs);
5135 /* After the display initializations is where the tail-recursion label
5136 should go, if we end up needing one. Ensure we have a NOTE here
5137 since some things (like trampolines) get placed before this. */
5138 tail_recursion_reentry = emit_note (NULL_PTR, NOTE_INSN_DELETED);
5140 /* Evaluate now the sizes of any types declared among the arguments. */
5141 for (tem = nreverse (get_pending_sizes ()); tem; tem = TREE_CHAIN (tem))
5142 expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode, 0);
5144 /* Make sure there is a line number after the function entry setup code. */
5145 force_next_line_note ();
5148 /* Generate RTL for the end of the current function.
5149 FILENAME and LINE are the current position in the source file.
5151 It is up to language-specific callers to do cleanups for parameters--
5152 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */
5154 void
5155 expand_function_end (filename, line, end_bindings)
5156 char *filename;
5157 int line;
5158 int end_bindings;
5160 register int i;
5161 tree link;
5163 static rtx initial_trampoline;
5165 if (output_bytecode)
5167 bc_expand_function_end ();
5168 return;
5171 #ifdef NON_SAVING_SETJMP
5172 /* Don't put any variables in registers if we call setjmp
5173 on a machine that fails to restore the registers. */
5174 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
5176 if (DECL_INITIAL (current_function_decl) != error_mark_node)
5177 setjmp_protect (DECL_INITIAL (current_function_decl));
5179 setjmp_protect_args ();
5181 #endif
5183 /* Save the argument pointer if a save area was made for it. */
5184 if (arg_pointer_save_area)
5186 rtx x = gen_move_insn (arg_pointer_save_area, virtual_incoming_args_rtx);
5187 emit_insn_before (x, tail_recursion_reentry);
5190 /* Initialize any trampolines required by this function. */
5191 for (link = trampoline_list; link; link = TREE_CHAIN (link))
5193 tree function = TREE_PURPOSE (link);
5194 rtx context = lookup_static_chain (function);
5195 rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
5196 rtx seq;
5198 /* First make sure this compilation has a template for
5199 initializing trampolines. */
5200 if (initial_trampoline == 0)
5202 end_temporary_allocation ();
5203 initial_trampoline
5204 = gen_rtx (MEM, BLKmode, assemble_trampoline_template ());
5205 resume_temporary_allocation ();
5208 /* Generate insns to initialize the trampoline. */
5209 start_sequence ();
5210 tramp = change_address (initial_trampoline, BLKmode,
5211 round_trampoline_addr (XEXP (tramp, 0)));
5212 emit_block_move (tramp, initial_trampoline, GEN_INT (TRAMPOLINE_SIZE),
5213 FUNCTION_BOUNDARY / BITS_PER_UNIT);
5214 INITIALIZE_TRAMPOLINE (XEXP (tramp, 0),
5215 XEXP (DECL_RTL (function), 0), context);
5216 seq = get_insns ();
5217 end_sequence ();
5219 /* Put those insns at entry to the containing function (this one). */
5220 emit_insns_before (seq, tail_recursion_reentry);
5223 #if 0 /* I think unused parms are legitimate enough. */
5224 /* Warn about unused parms. */
5225 if (warn_unused)
5227 rtx decl;
5229 for (decl = DECL_ARGUMENTS (current_function_decl);
5230 decl; decl = TREE_CHAIN (decl))
5231 if (! TREE_USED (decl) && TREE_CODE (decl) == VAR_DECL)
5232 warning_with_decl (decl, "unused parameter `%s'");
5234 #endif
5236 /* Delete handlers for nonlocal gotos if nothing uses them. */
5237 if (nonlocal_goto_handler_slot != 0 && !current_function_has_nonlocal_label)
5238 delete_handlers ();
5240 /* End any sequences that failed to be closed due to syntax errors. */
5241 while (in_sequence_p ())
5242 end_sequence ();
5244 /* Outside function body, can't compute type's actual size
5245 until next function's body starts. */
5246 immediate_size_expand--;
5248 /* If doing stupid register allocation,
5249 mark register parms as dying here. */
5251 if (obey_regdecls)
5253 rtx tem;
5254 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
5255 use_variable (regno_reg_rtx[i]);
5257 /* Likewise for the regs of all the SAVE_EXPRs in the function. */
5259 for (tem = save_expr_regs; tem; tem = XEXP (tem, 1))
5261 use_variable (XEXP (tem, 0));
5262 use_variable_after (XEXP (tem, 0), parm_birth_insn);
5265 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
5266 use_variable (current_function_internal_arg_pointer);
5269 clear_pending_stack_adjust ();
5270 do_pending_stack_adjust ();
5272 /* Mark the end of the function body.
5273 If control reaches this insn, the function can drop through
5274 without returning a value. */
5275 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_END);
5277 /* Output a linenumber for the end of the function.
5278 SDB depends on this. */
5279 emit_line_note_force (filename, line);
5281 /* Output the label for the actual return from the function,
5282 if one is expected. This happens either because a function epilogue
5283 is used instead of a return instruction, or because a return was done
5284 with a goto in order to run local cleanups, or because of pcc-style
5285 structure returning. */
5287 if (return_label)
5288 emit_label (return_label);
5290 /* C++ uses this. */
5291 if (end_bindings)
5292 expand_end_bindings (0, 0, 0);
5294 /* If we had calls to alloca, and this machine needs
5295 an accurate stack pointer to exit the function,
5296 insert some code to save and restore the stack pointer. */
5297 #ifdef EXIT_IGNORE_STACK
5298 if (! EXIT_IGNORE_STACK)
5299 #endif
5300 if (current_function_calls_alloca)
5302 rtx tem = 0;
5304 emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
5305 emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
5308 /* If scalar return value was computed in a pseudo-reg,
5309 copy that to the hard return register. */
5310 if (DECL_RTL (DECL_RESULT (current_function_decl)) != 0
5311 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG
5312 && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl)))
5313 >= FIRST_PSEUDO_REGISTER))
5315 rtx real_decl_result;
5317 #ifdef FUNCTION_OUTGOING_VALUE
5318 real_decl_result
5319 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
5320 current_function_decl);
5321 #else
5322 real_decl_result
5323 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
5324 current_function_decl);
5325 #endif
5326 REG_FUNCTION_VALUE_P (real_decl_result) = 1;
5327 emit_move_insn (real_decl_result,
5328 DECL_RTL (DECL_RESULT (current_function_decl)));
5329 emit_insn (gen_rtx (USE, VOIDmode, real_decl_result));
5332 /* If returning a structure, arrange to return the address of the value
5333 in a place where debuggers expect to find it.
5335 If returning a structure PCC style,
5336 the caller also depends on this value.
5337 And current_function_returns_pcc_struct is not necessarily set. */
5338 if (current_function_returns_struct
5339 || current_function_returns_pcc_struct)
5341 rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
5342 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
5343 #ifdef FUNCTION_OUTGOING_VALUE
5344 rtx outgoing
5345 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
5346 current_function_decl);
5347 #else
5348 rtx outgoing
5349 = FUNCTION_VALUE (build_pointer_type (type),
5350 current_function_decl);
5351 #endif
5353 /* Mark this as a function return value so integrate will delete the
5354 assignment and USE below when inlining this function. */
5355 REG_FUNCTION_VALUE_P (outgoing) = 1;
5357 emit_move_insn (outgoing, value_address);
5358 use_variable (outgoing);
5361 /* Output a return insn if we are using one.
5362 Otherwise, let the rtl chain end here, to drop through
5363 into the epilogue. */
5365 #ifdef HAVE_return
5366 if (HAVE_return)
5368 emit_jump_insn (gen_return ());
5369 emit_barrier ();
5371 #endif
5373 /* Fix up any gotos that jumped out to the outermost
5374 binding level of the function.
5375 Must follow emitting RETURN_LABEL. */
5377 /* If you have any cleanups to do at this point,
5378 and they need to create temporary variables,
5379 then you will lose. */
5380 expand_fixups (get_insns ());
5383 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
5385 static int *prologue;
5386 static int *epilogue;
5388 /* Create an array that records the INSN_UIDs of INSNS (either a sequence
5389 or a single insn). */
5391 static int *
5392 record_insns (insns)
5393 rtx insns;
5395 int *vec;
5397 if (GET_CODE (insns) == SEQUENCE)
5399 int len = XVECLEN (insns, 0);
5400 vec = (int *) oballoc ((len + 1) * sizeof (int));
5401 vec[len] = 0;
5402 while (--len >= 0)
5403 vec[len] = INSN_UID (XVECEXP (insns, 0, len));
5405 else
5407 vec = (int *) oballoc (2 * sizeof (int));
5408 vec[0] = INSN_UID (insns);
5409 vec[1] = 0;
5411 return vec;
5414 /* Determine how many INSN_UIDs in VEC are part of INSN. */
5416 static int
5417 contains (insn, vec)
5418 rtx insn;
5419 int *vec;
5421 register int i, j;
5423 if (GET_CODE (insn) == INSN
5424 && GET_CODE (PATTERN (insn)) == SEQUENCE)
5426 int count = 0;
5427 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
5428 for (j = 0; vec[j]; j++)
5429 if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == vec[j])
5430 count++;
5431 return count;
5433 else
5435 for (j = 0; vec[j]; j++)
5436 if (INSN_UID (insn) == vec[j])
5437 return 1;
5439 return 0;
5442 /* Generate the prologe and epilogue RTL if the machine supports it. Thread
5443 this into place with notes indicating where the prologue ends and where
5444 the epilogue begins. Update the basic block information when possible. */
5446 void
5447 thread_prologue_and_epilogue_insns (f)
5448 rtx f;
5450 #ifdef HAVE_prologue
5451 if (HAVE_prologue)
5453 rtx head, seq, insn;
5455 /* The first insn (a NOTE_INSN_DELETED) is followed by zero or more
5456 prologue insns and a NOTE_INSN_PROLOGUE_END. */
5457 emit_note_after (NOTE_INSN_PROLOGUE_END, f);
5458 seq = gen_prologue ();
5459 head = emit_insn_after (seq, f);
5461 /* Include the new prologue insns in the first block. Ignore them
5462 if they form a basic block unto themselves. */
5463 if (basic_block_head && n_basic_blocks
5464 && GET_CODE (basic_block_head[0]) != CODE_LABEL)
5465 basic_block_head[0] = NEXT_INSN (f);
5467 /* Retain a map of the prologue insns. */
5468 prologue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : head);
5470 else
5471 #endif
5472 prologue = 0;
5474 #ifdef HAVE_epilogue
5475 if (HAVE_epilogue)
5477 rtx insn = get_last_insn ();
5478 rtx prev = prev_nonnote_insn (insn);
5480 /* If we end with a BARRIER, we don't need an epilogue. */
5481 if (! (prev && GET_CODE (prev) == BARRIER))
5483 rtx tail, seq, tem;
5484 rtx first_use = 0;
5485 rtx last_use = 0;
5487 /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, the
5488 epilogue insns, the USE insns at the end of a function,
5489 the jump insn that returns, and then a BARRIER. */
5491 /* Move the USE insns at the end of a function onto a list. */
5492 while (prev
5493 && GET_CODE (prev) == INSN
5494 && GET_CODE (PATTERN (prev)) == USE)
5496 tem = prev;
5497 prev = prev_nonnote_insn (prev);
5499 NEXT_INSN (PREV_INSN (tem)) = NEXT_INSN (tem);
5500 PREV_INSN (NEXT_INSN (tem)) = PREV_INSN (tem);
5501 if (first_use)
5503 NEXT_INSN (tem) = first_use;
5504 PREV_INSN (first_use) = tem;
5506 first_use = tem;
5507 if (!last_use)
5508 last_use = tem;
5511 emit_barrier_after (insn);
5513 seq = gen_epilogue ();
5514 tail = emit_jump_insn_after (seq, insn);
5516 /* Insert the USE insns immediately before the return insn, which
5517 must be the first instruction before the final barrier. */
5518 if (first_use)
5520 tem = prev_nonnote_insn (get_last_insn ());
5521 NEXT_INSN (PREV_INSN (tem)) = first_use;
5522 PREV_INSN (first_use) = PREV_INSN (tem);
5523 PREV_INSN (tem) = last_use;
5524 NEXT_INSN (last_use) = tem;
5527 emit_note_after (NOTE_INSN_EPILOGUE_BEG, insn);
5529 /* Include the new epilogue insns in the last block. Ignore
5530 them if they form a basic block unto themselves. */
5531 if (basic_block_end && n_basic_blocks
5532 && GET_CODE (basic_block_end[n_basic_blocks - 1]) != JUMP_INSN)
5533 basic_block_end[n_basic_blocks - 1] = tail;
5535 /* Retain a map of the epilogue insns. */
5536 epilogue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : tail);
5537 return;
5540 #endif
5541 epilogue = 0;
5544 /* Reposition the prologue-end and epilogue-begin notes after instruction
5545 scheduling and delayed branch scheduling. */
5547 void
5548 reposition_prologue_and_epilogue_notes (f)
5549 rtx f;
5551 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
5552 /* Reposition the prologue and epilogue notes. */
5553 if (n_basic_blocks)
5555 rtx next, prev;
5556 int len;
5558 if (prologue)
5560 register rtx insn, note = 0;
5562 /* Scan from the beginning until we reach the last prologue insn.
5563 We apparently can't depend on basic_block_{head,end} after
5564 reorg has run. */
5565 for (len = 0; prologue[len]; len++)
5567 for (insn = f; len && insn; insn = NEXT_INSN (insn))
5569 if (GET_CODE (insn) == NOTE)
5571 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
5572 note = insn;
5574 else if ((len -= contains (insn, prologue)) == 0)
5576 /* Find the prologue-end note if we haven't already, and
5577 move it to just after the last prologue insn. */
5578 if (note == 0)
5580 for (note = insn; note = NEXT_INSN (note);)
5581 if (GET_CODE (note) == NOTE
5582 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
5583 break;
5585 next = NEXT_INSN (note);
5586 prev = PREV_INSN (note);
5587 if (prev)
5588 NEXT_INSN (prev) = next;
5589 if (next)
5590 PREV_INSN (next) = prev;
5591 add_insn_after (note, insn);
5596 if (epilogue)
5598 register rtx insn, note = 0;
5600 /* Scan from the end until we reach the first epilogue insn.
5601 We apparently can't depend on basic_block_{head,end} after
5602 reorg has run. */
5603 for (len = 0; epilogue[len]; len++)
5605 for (insn = get_last_insn (); len && insn; insn = PREV_INSN (insn))
5607 if (GET_CODE (insn) == NOTE)
5609 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
5610 note = insn;
5612 else if ((len -= contains (insn, epilogue)) == 0)
5614 /* Find the epilogue-begin note if we haven't already, and
5615 move it to just before the first epilogue insn. */
5616 if (note == 0)
5618 for (note = insn; note = PREV_INSN (note);)
5619 if (GET_CODE (note) == NOTE
5620 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
5621 break;
5623 next = NEXT_INSN (note);
5624 prev = PREV_INSN (note);
5625 if (prev)
5626 NEXT_INSN (prev) = next;
5627 if (next)
5628 PREV_INSN (next) = prev;
5629 add_insn_after (note, PREV_INSN (insn));
5634 #endif /* HAVE_prologue or HAVE_epilogue */